applesauce-common 5.2.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/casts/_circular-import.d.ts +7 -0
- package/dist/casts/_circular-import.js +9 -0
- package/dist/casts/article.d.ts +1 -1
- package/dist/casts/badge-award.d.ts +24 -0
- package/dist/casts/badge-award.js +39 -0
- package/dist/casts/badge.d.ts +19 -0
- package/dist/casts/badge.js +48 -0
- package/dist/casts/bookmarks.d.ts +5 -5
- package/dist/casts/cast.d.ts +1 -30
- package/dist/casts/cast.js +2 -67
- package/dist/casts/comment.d.ts +5 -5
- package/dist/casts/emoji-pack.d.ts +11 -0
- package/dist/casts/emoji-pack.js +25 -0
- package/dist/casts/favorite-emojis.d.ts +25 -0
- package/dist/casts/favorite-emojis.js +62 -0
- package/dist/casts/file-metadata.d.ts +22 -0
- package/dist/casts/file-metadata.js +55 -0
- package/dist/casts/groups.d.ts +1 -1
- package/dist/casts/index.d.ts +7 -0
- package/dist/casts/index.js +7 -0
- package/dist/casts/mutes.d.ts +1 -1
- package/dist/casts/note.d.ts +7 -7
- package/dist/casts/profile-badges.d.ts +28 -0
- package/dist/casts/profile-badges.js +59 -0
- package/dist/casts/reaction.d.ts +1 -1
- package/dist/casts/relay-lists.d.ts +1 -1
- package/dist/casts/relay-monitor.d.ts +1 -1
- package/dist/casts/report.d.ts +2 -2
- package/dist/casts/share.d.ts +2 -2
- package/dist/casts/stream.d.ts +9 -9
- package/dist/casts/torrent.d.ts +3 -3
- package/dist/casts/trusted-assertions.d.ts +144 -0
- package/dist/casts/trusted-assertions.js +281 -0
- package/dist/casts/user.d.ts +22 -40
- package/dist/casts/user.js +105 -161
- package/dist/casts/zap-goal.d.ts +2 -2
- package/dist/casts/zap.d.ts +4 -4
- package/dist/factories/app-data.d.ts +13 -0
- package/dist/factories/app-data.js +20 -0
- package/dist/factories/badge-award.d.ts +25 -0
- package/dist/factories/badge-award.js +41 -0
- package/dist/factories/badge.d.ts +32 -0
- package/dist/factories/badge.js +50 -0
- package/dist/factories/blocked-relays.d.ts +10 -0
- package/dist/factories/blocked-relays.js +16 -0
- package/dist/factories/blossom-server-list.d.ts +19 -0
- package/dist/factories/blossom-server-list.js +36 -0
- package/dist/factories/bookmark-list.d.ts +23 -0
- package/dist/factories/bookmark-list.js +45 -0
- package/dist/factories/bookmark-set.d.ts +25 -0
- package/dist/factories/bookmark-set.js +51 -0
- package/dist/factories/calendar-event.d.ts +88 -0
- package/dist/factories/calendar-event.js +175 -0
- package/dist/factories/calendar-rsvp.d.ts +22 -0
- package/dist/factories/calendar-rsvp.js +35 -0
- package/dist/factories/calendar.d.ts +20 -0
- package/dist/factories/calendar.js +36 -0
- package/dist/factories/code-snippet.d.ts +65 -0
- package/dist/factories/code-snippet.js +100 -0
- package/dist/factories/comment.d.ts +26 -0
- package/dist/factories/comment.js +49 -0
- package/dist/factories/contacts.d.ts +19 -0
- package/dist/factories/contacts.js +36 -0
- package/dist/factories/dm-relays.d.ts +10 -0
- package/dist/factories/dm-relays.js +16 -0
- package/dist/factories/favorite-relays.d.ts +16 -0
- package/dist/factories/favorite-relays.js +31 -0
- package/dist/factories/file-metadata.d.ts +54 -0
- package/dist/factories/file-metadata.js +92 -0
- package/dist/factories/follow-set.d.ts +12 -0
- package/dist/factories/follow-set.js +22 -0
- package/dist/factories/gift-wrap.d.ts +17 -0
- package/dist/factories/gift-wrap.js +21 -0
- package/dist/factories/group-management.d.ts +63 -0
- package/dist/factories/group-management.js +147 -0
- package/dist/factories/group.d.ts +35 -0
- package/dist/factories/group.js +69 -0
- package/dist/factories/highlight.d.ts +33 -0
- package/dist/factories/highlight.js +49 -0
- package/dist/factories/index.d.ts +41 -0
- package/dist/factories/index.js +41 -0
- package/dist/factories/legacy-message.d.ts +10 -0
- package/dist/factories/legacy-message.js +19 -0
- package/dist/factories/list.d.ts +56 -0
- package/dist/factories/list.js +120 -0
- package/dist/factories/live-stream.d.ts +48 -0
- package/dist/factories/live-stream.js +90 -0
- package/dist/factories/mute-list.d.ts +27 -0
- package/dist/factories/mute-list.js +57 -0
- package/dist/factories/note.d.ts +38 -0
- package/dist/factories/note.js +66 -0
- package/dist/factories/picture-post.d.ts +28 -0
- package/dist/factories/picture-post.js +46 -0
- package/dist/factories/pin-list.d.ts +14 -0
- package/dist/factories/pin-list.js +24 -0
- package/dist/factories/poll-response.d.ts +36 -0
- package/dist/factories/poll-response.js +46 -0
- package/dist/factories/poll.d.ts +35 -0
- package/dist/factories/poll.js +48 -0
- package/dist/factories/profile-badges.d.ts +31 -0
- package/dist/factories/profile-badges.js +52 -0
- package/dist/factories/reaction.d.ts +22 -0
- package/dist/factories/reaction.js +37 -0
- package/dist/factories/relay-set.d.ts +12 -0
- package/dist/factories/relay-set.js +22 -0
- package/dist/factories/search-relays.d.ts +10 -0
- package/dist/factories/search-relays.js +16 -0
- package/dist/factories/share.d.ts +26 -0
- package/dist/factories/share.js +44 -0
- package/dist/factories/stream-chat-message.d.ts +22 -0
- package/dist/factories/stream-chat-message.js +31 -0
- package/dist/factories/torrent.d.ts +57 -0
- package/dist/factories/torrent.js +93 -0
- package/dist/factories/wrapped-message.d.ts +22 -0
- package/dist/factories/wrapped-message.js +39 -0
- package/dist/factories/zap-goal.d.ts +35 -0
- package/dist/factories/zap-goal.js +49 -0
- package/dist/factories/zap-request.d.ts +28 -0
- package/dist/factories/zap-request.js +55 -0
- package/dist/factories/zap.d.ts +13 -0
- package/dist/factories/zap.js +21 -0
- package/dist/helpers/badge-award.d.ts +15 -0
- package/dist/helpers/badge-award.js +32 -0
- package/dist/helpers/badge.d.ts +27 -0
- package/dist/helpers/badge.js +59 -0
- package/dist/helpers/blossom.d.ts +29 -1
- package/dist/helpers/blossom.js +64 -7
- package/dist/helpers/emoji-pack.d.ts +43 -0
- package/dist/helpers/emoji-pack.js +108 -0
- package/dist/helpers/emoji.d.ts +0 -4
- package/dist/helpers/emoji.js +0 -16
- package/dist/helpers/file-metadata.d.ts +18 -13
- package/dist/helpers/file-metadata.js +10 -4
- package/dist/helpers/groups.d.ts +1 -0
- package/dist/helpers/groups.js +3 -2
- package/dist/helpers/hashtag.d.ts +1 -0
- package/dist/helpers/hashtag.js +3 -3
- package/dist/helpers/index.d.ts +7 -2
- package/dist/helpers/index.js +7 -2
- package/dist/helpers/lists.d.ts +8 -0
- package/dist/helpers/lists.js +27 -5
- package/dist/helpers/picture-post.d.ts +2 -2
- package/dist/helpers/profile-badges.d.ts +23 -0
- package/dist/helpers/profile-badges.js +51 -0
- package/dist/helpers/trusted-assertions.d.ts +81 -0
- package/dist/helpers/trusted-assertions.js +161 -0
- package/dist/helpers/zap.d.ts +8 -2
- package/dist/helpers/zap.js +31 -26
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.js +1 -1
- package/dist/observable/chainable.d.ts +1 -36
- package/dist/observable/chainable.js +2 -72
- package/dist/operations/app-data.d.ts +8 -3
- package/dist/operations/app-data.js +9 -4
- package/dist/operations/badge-award.d.ts +17 -0
- package/dist/operations/badge-award.js +30 -0
- package/dist/operations/badge.d.ts +22 -0
- package/dist/operations/badge.js +54 -0
- package/dist/operations/blossom.d.ts +1 -1
- package/dist/operations/calendar-event.d.ts +1 -1
- package/dist/operations/calendar-rsvp.d.ts +1 -1
- package/dist/operations/calendar.d.ts +1 -1
- package/dist/operations/channel.d.ts +1 -1
- package/dist/operations/client.d.ts +1 -1
- package/dist/operations/client.js +2 -2
- package/dist/operations/code-snippet.d.ts +27 -0
- package/dist/operations/code-snippet.js +63 -0
- package/dist/operations/comment.d.ts +7 -3
- package/dist/operations/comment.js +8 -4
- package/dist/operations/file-metadata.d.ts +38 -4
- package/dist/operations/file-metadata.js +105 -19
- package/dist/operations/geohash.d.ts +1 -1
- package/dist/operations/gift-wrap.d.ts +19 -7
- package/dist/operations/gift-wrap.js +36 -26
- package/dist/operations/group.d.ts +1 -1
- package/dist/operations/hashtags.d.ts +1 -1
- package/dist/operations/highlight.d.ts +1 -1
- package/dist/operations/highlight.js +5 -5
- package/dist/operations/index.d.ts +7 -1
- package/dist/operations/index.js +7 -1
- package/dist/operations/legacy-message.d.ts +1 -1
- package/dist/operations/list.d.ts +1 -1
- package/dist/operations/live-stream.d.ts +7 -3
- package/dist/operations/live-stream.js +9 -5
- package/dist/operations/media-attachment.d.ts +3 -3
- package/dist/operations/note.d.ts +10 -4
- package/dist/operations/note.js +14 -8
- package/dist/operations/picture-post.d.ts +1 -1
- package/dist/operations/poll-response.d.ts +1 -1
- package/dist/operations/poll-response.js +1 -1
- package/dist/operations/poll.d.ts +1 -1
- package/dist/operations/profile-badges.d.ts +26 -0
- package/dist/operations/profile-badges.js +150 -0
- package/dist/operations/reaction.d.ts +8 -3
- package/dist/operations/reaction.js +10 -5
- package/dist/operations/share.d.ts +8 -3
- package/dist/operations/share.js +10 -5
- package/dist/operations/stream.d.ts +1 -1
- package/dist/operations/tag/bookmarks.d.ts +1 -1
- package/dist/operations/torrent.d.ts +1 -1
- package/dist/operations/wrapped-message.d.ts +1 -1
- package/dist/operations/zap-goal.d.ts +1 -1
- package/dist/operations/zap-request.d.ts +22 -0
- package/dist/operations/zap-request.js +40 -0
- package/dist/operations/zap-split.d.ts +8 -4
- package/dist/operations/zap-split.js +10 -6
- package/dist/operations/zap.d.ts +12 -0
- package/dist/operations/zap.js +34 -0
- package/package.json +12 -11
- package/dist/blueprints/__register__.d.ts +0 -7
- package/dist/blueprints/__register__.js +0 -8
- package/dist/blueprints/app-data.d.ts +0 -5
- package/dist/blueprints/app-data.js +0 -10
- package/dist/blueprints/calendar.d.ts +0 -5
- package/dist/blueprints/calendar.js +0 -7
- package/dist/blueprints/channels.d.ts +0 -6
- package/dist/blueprints/channels.js +0 -13
- package/dist/blueprints/comment.d.ts +0 -13
- package/dist/blueprints/comment.js +0 -15
- package/dist/blueprints/delete.d.ts +0 -9
- package/dist/blueprints/delete.js +0 -14
- package/dist/blueprints/file-metadata.d.ts +0 -8
- package/dist/blueprints/file-metadata.js +0 -11
- package/dist/blueprints/follow-set.d.ts +0 -11
- package/dist/blueprints/follow-set.js +0 -21
- package/dist/blueprints/gift-wrap.d.ts +0 -5
- package/dist/blueprints/gift-wrap.js +0 -6
- package/dist/blueprints/group-mangement.d.ts +0 -25
- package/dist/blueprints/group-mangement.js +0 -40
- package/dist/blueprints/group.d.ts +0 -9
- package/dist/blueprints/group.js +0 -17
- package/dist/blueprints/highlight.d.ts +0 -20
- package/dist/blueprints/highlight.js +0 -12
- package/dist/blueprints/index.d.ts +0 -25
- package/dist/blueprints/index.js +0 -26
- package/dist/blueprints/legacy-message.d.ts +0 -7
- package/dist/blueprints/legacy-message.js +0 -29
- package/dist/blueprints/live-stream.d.ts +0 -6
- package/dist/blueprints/live-stream.js +0 -9
- package/dist/blueprints/note.d.ts +0 -16
- package/dist/blueprints/note.js +0 -30
- package/dist/blueprints/picture-post.d.ts +0 -12
- package/dist/blueprints/picture-post.js +0 -17
- package/dist/blueprints/poll.d.ts +0 -41
- package/dist/blueprints/poll.js +0 -33
- package/dist/blueprints/profile.d.ts +0 -3
- package/dist/blueprints/profile.js +0 -7
- package/dist/blueprints/reaction.d.ts +0 -10
- package/dist/blueprints/reaction.js +0 -14
- package/dist/blueprints/share.d.ts +0 -12
- package/dist/blueprints/share.js +0 -25
- package/dist/blueprints/stream.d.ts +0 -6
- package/dist/blueprints/stream.js +0 -7
- package/dist/blueprints/torrent.d.ts +0 -30
- package/dist/blueprints/torrent.js +0 -29
- package/dist/blueprints/wrapped-message.d.ts +0 -20
- package/dist/blueprints/wrapped-message.js +0 -64
- package/dist/blueprints/zap-goal.d.ts +0 -16
- package/dist/blueprints/zap-goal.js +0 -12
- package/dist/register.d.ts +0 -2
- package/dist/register.js +0 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { withImmediateValueOrDefault } from "applesauce-core";
|
|
2
|
+
import { User } from "applesauce-core/casts";
|
|
3
|
+
import { combineLatest, map } from "rxjs";
|
|
4
|
+
import { compareProfileBadgeEvents, getProfileBadgeSlots, isValidProfileBadges, LEGACY_PROFILE_BADGES_IDENTIFIER, LEGACY_PROFILE_BADGES_KIND, PROFILE_BADGES_KIND, } from "../helpers/profile-badges.js";
|
|
5
|
+
import { castEventStream } from "../observable/cast-stream.js";
|
|
6
|
+
import { BadgeAward } from "./badge-award.js";
|
|
7
|
+
import { Badge } from "./badge.js";
|
|
8
|
+
import { EventCast } from "./cast.js";
|
|
9
|
+
export class ProfileBadges extends EventCast {
|
|
10
|
+
#slots;
|
|
11
|
+
constructor(event, store) {
|
|
12
|
+
if (!isValidProfileBadges(event))
|
|
13
|
+
throw new Error("Invalid profile badges event");
|
|
14
|
+
super(event, store);
|
|
15
|
+
this.#slots = getProfileBadgeSlots(event);
|
|
16
|
+
}
|
|
17
|
+
/** Returns the array of all slot pointers */
|
|
18
|
+
get slots() {
|
|
19
|
+
return this.#slots;
|
|
20
|
+
}
|
|
21
|
+
/** returns number of slots */
|
|
22
|
+
get count() {
|
|
23
|
+
return this.#slots.length;
|
|
24
|
+
}
|
|
25
|
+
/** Gets and array of all badges in all slots */
|
|
26
|
+
get badges$() {
|
|
27
|
+
return this.$$ref("badges$", () => {
|
|
28
|
+
return combineLatest(
|
|
29
|
+
// For each slot, fetch badge event
|
|
30
|
+
this.#slots.map((_slot, index) => this.slot$(index)));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** Gets the badge and award at a given slot index */
|
|
34
|
+
slot$(index = 0) {
|
|
35
|
+
return this.$$ref(`slot:${index}`, (store) => {
|
|
36
|
+
const badge$ = store
|
|
37
|
+
.event(this.#slots[index].badge)
|
|
38
|
+
.pipe(castEventStream(Badge, store), withImmediateValueOrDefault(undefined));
|
|
39
|
+
const award$ = store
|
|
40
|
+
.event(this.#slots[index].award)
|
|
41
|
+
.pipe(castEventStream(BadgeAward, store), withImmediateValueOrDefault(undefined));
|
|
42
|
+
return combineLatest([badge$, award$]).pipe(map(([badge, award]) => ({ badge, award })));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
Object.defineProperty(User.prototype, "profileBadges$", {
|
|
47
|
+
get() {
|
|
48
|
+
return this.$$ref("profileBadges$", (store) => combineLatest([
|
|
49
|
+
store.replaceable({ kind: PROFILE_BADGES_KIND, pubkey: this.pubkey }),
|
|
50
|
+
store.replaceable({
|
|
51
|
+
kind: LEGACY_PROFILE_BADGES_KIND,
|
|
52
|
+
pubkey: this.pubkey,
|
|
53
|
+
identifier: LEGACY_PROFILE_BADGES_IDENTIFIER,
|
|
54
|
+
}),
|
|
55
|
+
]).pipe(map(([modern, legacy]) => compareProfileBadgeEvents(modern, legacy)), castEventStream(ProfileBadges, store)));
|
|
56
|
+
},
|
|
57
|
+
configurable: true,
|
|
58
|
+
enumerable: false,
|
|
59
|
+
});
|
package/dist/casts/reaction.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ export declare class Reaction extends EventCast<KnownEvent<7>> {
|
|
|
13
13
|
/** Get the pointer (event or address) for the event being reacted to */
|
|
14
14
|
get pointer(): import("nostr-tools/nip19").EventPointer | import("nostr-tools/nip19").AddressPointer | undefined;
|
|
15
15
|
/** Get the event that this reaction is reacting to */
|
|
16
|
-
get reactedTo$(): import("
|
|
16
|
+
get reactedTo$(): import("applesauce-core").ChainableObservable<NostrEvent | undefined>;
|
|
17
17
|
}
|
|
@@ -10,7 +10,7 @@ declare class RelayListBase<T extends KnownEvent<typeof FAVORITE_RELAYS_KIND | t
|
|
|
10
10
|
/** The hidden relays in the relay list */
|
|
11
11
|
get hidden(): string[];
|
|
12
12
|
/** An observable that updates when the hidden relays are unlocked */
|
|
13
|
-
get hidden$(): import("
|
|
13
|
+
get hidden$(): import("applesauce-core").ChainableObservable<string[]>;
|
|
14
14
|
/** Whether the relay list has hidden relays */
|
|
15
15
|
get hasHidden(): boolean;
|
|
16
16
|
/** Whether the relay list is unlocked */
|
|
@@ -17,5 +17,5 @@ export declare class RelayMonitor extends EventCast<RelayMonitorAnnouncementEven
|
|
|
17
17
|
/** Gets the geohash from this monitor announcement (NIP-52 geohash) */
|
|
18
18
|
get geohash(): string | undefined;
|
|
19
19
|
/** Get the status of a relay from this monitor */
|
|
20
|
-
relayStatus(relay: string): import("
|
|
20
|
+
relayStatus(relay: string): import("applesauce-core/observable/chainable").ChainableObservable<RelayDiscovery | undefined>;
|
|
21
21
|
}
|
package/dist/casts/report.d.ts
CHANGED
|
@@ -18,11 +18,11 @@ export declare class Report extends EventCast<KnownEvent<typeof REPORT_KIND>> {
|
|
|
18
18
|
/** Get the pubkey of the user being reported */
|
|
19
19
|
get reportedPubkey(): string | undefined;
|
|
20
20
|
/** Get the User being reported */
|
|
21
|
-
get reportedUser(): import("
|
|
21
|
+
get reportedUser(): import("applesauce-core/casts").User | undefined;
|
|
22
22
|
/** Get the event ID being reported (for event reports) */
|
|
23
23
|
get reportedEventId(): string | undefined;
|
|
24
24
|
/** Get the event being reported (for event reports) */
|
|
25
|
-
get reportedEvent$(): import("
|
|
25
|
+
get reportedEvent$(): import("applesauce-core").ChainableObservable<NostrEvent | undefined>;
|
|
26
26
|
/** Get the blob hashes being reported (for event reports with x tags) */
|
|
27
27
|
get blobs(): string[] | undefined;
|
|
28
28
|
/** Get the server URLs for blob reports */
|
package/dist/casts/share.d.ts
CHANGED
|
@@ -10,6 +10,6 @@ export declare class Share extends EventCast<ShareEvent> {
|
|
|
10
10
|
get sharedAddressPointer(): import("nostr-tools/nip19").AddressPointer | undefined;
|
|
11
11
|
get sharedEventPointer(): import("nostr-tools/nip19").EventPointer;
|
|
12
12
|
get sharedPointer(): import("nostr-tools/nip19").EventPointer | import("nostr-tools/nip19").AddressPointer;
|
|
13
|
-
get shared$(): import("
|
|
14
|
-
get reactions$(): import("
|
|
13
|
+
get shared$(): import("applesauce-core").ChainableObservable<NostrEvent | undefined>;
|
|
14
|
+
get reactions$(): import("applesauce-core").ChainableObservable<Reaction[]>;
|
|
15
15
|
}
|
package/dist/casts/stream.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export declare class Stream extends EventCast<KnownEvent<kinds.LiveEvent>> {
|
|
|
12
12
|
get summary(): string | undefined;
|
|
13
13
|
get image(): string | undefined;
|
|
14
14
|
get status(): StreamStatus;
|
|
15
|
-
get host(): import("
|
|
16
|
-
get participants(): import("
|
|
15
|
+
get host(): import("applesauce-core/casts").User;
|
|
16
|
+
get participants(): import("applesauce-core/casts").User[];
|
|
17
17
|
get goalPointer(): EventPointer | undefined;
|
|
18
18
|
get streamingURLs(): string[];
|
|
19
19
|
get streamingVideos(): string[];
|
|
@@ -26,18 +26,18 @@ export declare class Stream extends EventCast<KnownEvent<kinds.LiveEvent>> {
|
|
|
26
26
|
get maxViewers(): number | undefined;
|
|
27
27
|
get hashtags(): string[];
|
|
28
28
|
/** An observable of all zaps on this stream */
|
|
29
|
-
get zaps$(): import("
|
|
30
|
-
get shares$(): import("
|
|
29
|
+
get zaps$(): import("applesauce-core").ChainableObservable<Zap[]>;
|
|
30
|
+
get shares$(): import("applesauce-core").ChainableObservable<Share[]>;
|
|
31
31
|
/** An observable of all chat messages for this stream */
|
|
32
|
-
get chat$(): import("
|
|
32
|
+
get chat$(): import("applesauce-core").ChainableObservable<StreamChatMessage[]>;
|
|
33
33
|
/** An observable of the goal event if this stream has a goal */
|
|
34
|
-
get goal$(): import("
|
|
34
|
+
get goal$(): import("applesauce-core").ChainableObservable<NostrEvent | undefined>;
|
|
35
35
|
}
|
|
36
36
|
/** A cast for a stream chat message */
|
|
37
37
|
export declare class StreamChatMessage extends EventCast<StreamChatMessageEvent> {
|
|
38
38
|
constructor(event: NostrEvent, store: CastRefEventStore);
|
|
39
39
|
get stream(): import("nostr-tools/nip19").AddressPointer;
|
|
40
|
-
get stream$(): import("
|
|
41
|
-
get zaps$(): import("
|
|
42
|
-
get reactions$(): import("
|
|
40
|
+
get stream$(): import("applesauce-core").ChainableObservable<Stream | undefined>;
|
|
41
|
+
get zaps$(): import("applesauce-core").ChainableObservable<Zap[]>;
|
|
42
|
+
get reactions$(): import("applesauce-core").ChainableObservable<NostrEvent[]>;
|
|
43
43
|
}
|
package/dist/casts/torrent.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare class Torrent extends EventCast<TorrentEvent> {
|
|
|
25
25
|
/** The magnet link for the torrent, built from the info hash, trackers, and title */
|
|
26
26
|
get magnetLink(): string | undefined;
|
|
27
27
|
/** Gets the NIP-22 comments to this event */
|
|
28
|
-
get comments$(): import("
|
|
29
|
-
get zaps$(): import("
|
|
30
|
-
get reactions$(): import("
|
|
28
|
+
get comments$(): import("applesauce-core").ChainableObservable<Comment[]>;
|
|
29
|
+
get zaps$(): import("applesauce-core").ChainableObservable<Zap[]>;
|
|
30
|
+
get reactions$(): import("applesauce-core").ChainableObservable<Reaction[]>;
|
|
31
31
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { NostrEvent } from "applesauce-core/helpers";
|
|
2
|
+
import { HiddenContentSigner } from "applesauce-core/helpers/hidden-content";
|
|
3
|
+
import { TrustedProvider, TrustedProviderListEvent, UserAssertionEvent } from "../helpers/trusted-assertions.js";
|
|
4
|
+
import { CastRefEventStore, EventCast, PubkeyCast } from "./cast.js";
|
|
5
|
+
/** A cast for a service provider pubkey that publishes NIP-85 assertion events */
|
|
6
|
+
export declare class AssertionProvider extends PubkeyCast {
|
|
7
|
+
/** @internal Per-class singleton cache used by castPubkey */
|
|
8
|
+
static cache: Map<string, AssertionProvider>;
|
|
9
|
+
/** Relay hints declared for this provider in the trusted provider list */
|
|
10
|
+
get providerRelays(): string[];
|
|
11
|
+
/** Returns the relays to use when querying this provider's assertion events */
|
|
12
|
+
get relays$(): import("rxjs").Observable<string[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Returns an observable of the assertion event published by this provider
|
|
15
|
+
* about the given user pubkey. Uses $$ref for caching.
|
|
16
|
+
*/
|
|
17
|
+
getUserAssertion(pubkey: string): import("applesauce-core/observable").ChainableObservable<UserAssertion | undefined>;
|
|
18
|
+
getUserRank(pubkey: string): import("rxjs").Observable<number | undefined>;
|
|
19
|
+
getUserFollowerCount(pubkey: string): import("rxjs").Observable<number | undefined>;
|
|
20
|
+
getUserPostCount(pubkey: string): import("rxjs").Observable<number | undefined>;
|
|
21
|
+
getUserReplyCount(pubkey: string): import("rxjs").Observable<number | undefined>;
|
|
22
|
+
getUserReactionsCount(pubkey: string): import("rxjs").Observable<number | undefined>;
|
|
23
|
+
getUserZapsReceived(pubkey: string): import("rxjs").Observable<{
|
|
24
|
+
count: number | undefined;
|
|
25
|
+
amount: number | undefined;
|
|
26
|
+
avgPerDay: number | undefined;
|
|
27
|
+
} | undefined>;
|
|
28
|
+
getUserZapsSent(pubkey: string): import("rxjs").Observable<{
|
|
29
|
+
count: number | undefined;
|
|
30
|
+
amount: number | undefined;
|
|
31
|
+
avgPerDay: number | undefined;
|
|
32
|
+
} | undefined>;
|
|
33
|
+
getUserReportsReceived(pubkey: string): import("rxjs").Observable<number | undefined>;
|
|
34
|
+
getUserReportsSent(pubkey: string): import("rxjs").Observable<number | undefined>;
|
|
35
|
+
getUserTopics(pubkey: string): import("rxjs").Observable<string[] | undefined>;
|
|
36
|
+
getUserActivityWindow(pubkey: string): import("rxjs").Observable<{
|
|
37
|
+
start: number | undefined;
|
|
38
|
+
end: number | undefined;
|
|
39
|
+
} | undefined>;
|
|
40
|
+
getUserFirstPostTime(pubkey: string): import("rxjs").Observable<Date | undefined>;
|
|
41
|
+
}
|
|
42
|
+
/** Cast a kind 10040 event to a TrustedProviderList */
|
|
43
|
+
export declare class TrustedProviderList extends EventCast<TrustedProviderListEvent> {
|
|
44
|
+
#private;
|
|
45
|
+
constructor(event: NostrEvent, store: CastRefEventStore);
|
|
46
|
+
/** All publicly declared providers (from tags) */
|
|
47
|
+
get publicProviders(): TrustedProvider[];
|
|
48
|
+
/** Hidden providers if the event has been unlocked, otherwise undefined */
|
|
49
|
+
get hiddenProviders(): TrustedProvider[] | undefined;
|
|
50
|
+
/** Observable that updates when hidden providers become available (after unlock) */
|
|
51
|
+
get hiddenProviders$(): import("applesauce-core/observable").ChainableObservable<TrustedProvider[] | undefined>;
|
|
52
|
+
/** Whether this list has an encrypted hidden providers section */
|
|
53
|
+
get hasHidden(): boolean;
|
|
54
|
+
/** Whether the hidden providers have been unlocked */
|
|
55
|
+
get unlocked(): boolean;
|
|
56
|
+
/** Decrypt and unlock the hidden providers */
|
|
57
|
+
unlock(signer: HiddenContentSigner): Promise<TrustedProvider[]>;
|
|
58
|
+
/** Providers trusted for user rank (0–100) */
|
|
59
|
+
get userRank$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
60
|
+
/** Providers trusted for user follower count */
|
|
61
|
+
get userFollowers$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
62
|
+
/** Providers trusted for user first post timestamp */
|
|
63
|
+
get userFirstCreatedAt$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
64
|
+
/** Providers trusted for user post count */
|
|
65
|
+
get userPostCount$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
66
|
+
/** Providers trusted for user reply count */
|
|
67
|
+
get userReplyCount$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
68
|
+
/** Providers trusted for user reactions count */
|
|
69
|
+
get userReactionsCount$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
70
|
+
/** Providers trusted for zap amount received */
|
|
71
|
+
get userZapAmountReceived$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
72
|
+
/** Providers trusted for zap amount sent */
|
|
73
|
+
get userZapAmountSent$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
74
|
+
/** Providers trusted for zap count received */
|
|
75
|
+
get userZapCountReceived$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
76
|
+
/** Providers trusted for zap count sent */
|
|
77
|
+
get userZapCountSent$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
78
|
+
/** Providers trusted for average daily zap amount received */
|
|
79
|
+
get userZapAvgAmountDayReceived$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
80
|
+
/** Providers trusted for average daily zap amount sent */
|
|
81
|
+
get userZapAvgAmountDaySent$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
82
|
+
/** Providers trusted for reports received count */
|
|
83
|
+
get userReportsReceived$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
84
|
+
/** Providers trusted for reports sent count */
|
|
85
|
+
get userReportsSent$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
86
|
+
/** Providers trusted for user common topics */
|
|
87
|
+
get userTopics$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
88
|
+
/** Providers trusted for user activity hours start */
|
|
89
|
+
get userActivityHoursStart$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
90
|
+
/** Providers trusted for user activity hours end */
|
|
91
|
+
get userActivityHoursEnd$(): import("applesauce-core/observable").ChainableObservable<AssertionProvider[]>;
|
|
92
|
+
}
|
|
93
|
+
/** Cast a kind 30382 event to a UserAssertion */
|
|
94
|
+
export declare class UserAssertion extends EventCast<UserAssertionEvent> {
|
|
95
|
+
constructor(event: NostrEvent, store: CastRefEventStore);
|
|
96
|
+
/** The pubkey of the user being evaluated */
|
|
97
|
+
get subjectPubkey(): string;
|
|
98
|
+
/** Observable of the {@link User} cast for the subject of this assertion */
|
|
99
|
+
get subject$(): import("applesauce-core/observable").ChainableObservable<import("applesauce-core/casts").User>;
|
|
100
|
+
/** The {@link AssertionProvider} that published this assertion */
|
|
101
|
+
get provider(): AssertionProvider;
|
|
102
|
+
/** User rank score (0–100) */
|
|
103
|
+
get rank(): number | undefined;
|
|
104
|
+
/** Follower count */
|
|
105
|
+
get followerCount(): number | undefined;
|
|
106
|
+
/** Unix timestamp of the user's first post */
|
|
107
|
+
get firstCreatedAt(): number | undefined;
|
|
108
|
+
/** Total post count */
|
|
109
|
+
get postCount(): number | undefined;
|
|
110
|
+
/** Total reply count */
|
|
111
|
+
get replyCount(): number | undefined;
|
|
112
|
+
/** Total reactions count */
|
|
113
|
+
get reactionsCount(): number | undefined;
|
|
114
|
+
/** Zap statistics for zaps received by this user */
|
|
115
|
+
get zapsReceived(): {
|
|
116
|
+
count: number | undefined;
|
|
117
|
+
amount: number | undefined;
|
|
118
|
+
avgPerDay: number | undefined;
|
|
119
|
+
};
|
|
120
|
+
/** Zap statistics for zaps sent by this user */
|
|
121
|
+
get zapsSent(): {
|
|
122
|
+
count: number | undefined;
|
|
123
|
+
amount: number | undefined;
|
|
124
|
+
avgPerDay: number | undefined;
|
|
125
|
+
};
|
|
126
|
+
/** Number of reports this user has received */
|
|
127
|
+
get reportsReceived(): number | undefined;
|
|
128
|
+
/** Number of reports this user has sent */
|
|
129
|
+
get reportsSent(): number | undefined;
|
|
130
|
+
/** Common topics associated with this user */
|
|
131
|
+
get topics(): string[];
|
|
132
|
+
/** UTC hour range during which this user is generally active */
|
|
133
|
+
get activityWindow(): {
|
|
134
|
+
start: number | undefined;
|
|
135
|
+
end: number | undefined;
|
|
136
|
+
};
|
|
137
|
+
/** Date of the user's first post, or undefined if not provided */
|
|
138
|
+
get firstPostTime(): Date | undefined;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Convenience function to get all AssertionProvider instances for a specific
|
|
142
|
+
* assertion type directly from a provider list event.
|
|
143
|
+
*/
|
|
144
|
+
export declare function castTrustedProviders(event: NostrEvent, kind: number, tag: string, store: CastRefEventStore): AssertionProvider[];
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { hasHiddenContent } from "applesauce-core/helpers/hidden-content";
|
|
2
|
+
import { mergeRelaySets } from "applesauce-core/helpers/relays";
|
|
3
|
+
import { watchEventUpdates } from "applesauce-core/observable";
|
|
4
|
+
import { combineLatest, map, of, switchMap } from "rxjs";
|
|
5
|
+
import { getAssertionActivityHoursEnd, getAssertionActivityHoursStart, getAssertionFirstCreatedAt, getAssertionFollowerCount, getAssertionPostCount, getAssertionReactionsCount, getAssertionRank, getAssertionReplyCount, getAssertionReportsReceived, getAssertionReportsSent, getAssertionSubject, getAssertionTopics, getAssertionZapAmountReceived, getAssertionZapAmountSent, getAssertionZapAvgAmountDayReceived, getAssertionZapAvgAmountDaySent, getAssertionZapCountReceived, getAssertionZapCountSent, getAllProviders, getHiddenProviders, getPublicProviders, isHiddenProvidersUnlocked, isValidTrustedProviderList, isValidUserAssertion, unlockHiddenProviders, USER_ASSERTION_KIND, } from "../helpers/trusted-assertions.js";
|
|
6
|
+
import { castEventStream } from "../observable/cast-stream.js";
|
|
7
|
+
import { castPubkey, EventCast, PubkeyCast } from "./cast.js";
|
|
8
|
+
import { castUser } from "./user.js";
|
|
9
|
+
// ─── AssertionProvider ───────────────────────────────────────────────────────
|
|
10
|
+
/** A cast for a service provider pubkey that publishes NIP-85 assertion events */
|
|
11
|
+
export class AssertionProvider extends PubkeyCast {
|
|
12
|
+
/** @internal Per-class singleton cache used by castPubkey */
|
|
13
|
+
static cache = new Map();
|
|
14
|
+
/** Relay hints declared for this provider in the trusted provider list */
|
|
15
|
+
get providerRelays() {
|
|
16
|
+
return this.pointer.relays ?? [];
|
|
17
|
+
}
|
|
18
|
+
/** Returns the relays to use when querying this provider's assertion events */
|
|
19
|
+
get relays$() {
|
|
20
|
+
return castUser(this.pubkey, this.store).outboxes$.pipe(map((outboxes) => mergeRelaySets(this.providerRelays, outboxes)));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns an observable of the assertion event published by this provider
|
|
24
|
+
* about the given user pubkey. Uses $$ref for caching.
|
|
25
|
+
*/
|
|
26
|
+
getUserAssertion(pubkey) {
|
|
27
|
+
return this.$$ref(`user-assertion:${pubkey}`, (store) => this.relays$.pipe(switchMap((relays) => store
|
|
28
|
+
.addressable({
|
|
29
|
+
kind: USER_ASSERTION_KIND,
|
|
30
|
+
pubkey: this.pubkey,
|
|
31
|
+
identifier: pubkey,
|
|
32
|
+
relays: relays.length > 0 ? relays : undefined,
|
|
33
|
+
})
|
|
34
|
+
.pipe(castEventStream(UserAssertion, store)))));
|
|
35
|
+
}
|
|
36
|
+
// ── Convenience metric observables ──────────────────────────────────────
|
|
37
|
+
getUserRank(pubkey) {
|
|
38
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.rank));
|
|
39
|
+
}
|
|
40
|
+
getUserFollowerCount(pubkey) {
|
|
41
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.followerCount));
|
|
42
|
+
}
|
|
43
|
+
getUserPostCount(pubkey) {
|
|
44
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.postCount));
|
|
45
|
+
}
|
|
46
|
+
getUserReplyCount(pubkey) {
|
|
47
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.replyCount));
|
|
48
|
+
}
|
|
49
|
+
getUserReactionsCount(pubkey) {
|
|
50
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.reactionsCount));
|
|
51
|
+
}
|
|
52
|
+
getUserZapsReceived(pubkey) {
|
|
53
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.zapsReceived));
|
|
54
|
+
}
|
|
55
|
+
getUserZapsSent(pubkey) {
|
|
56
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.zapsSent));
|
|
57
|
+
}
|
|
58
|
+
getUserReportsReceived(pubkey) {
|
|
59
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.reportsReceived));
|
|
60
|
+
}
|
|
61
|
+
getUserReportsSent(pubkey) {
|
|
62
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.reportsSent));
|
|
63
|
+
}
|
|
64
|
+
getUserTopics(pubkey) {
|
|
65
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.topics));
|
|
66
|
+
}
|
|
67
|
+
getUserActivityWindow(pubkey) {
|
|
68
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.activityWindow));
|
|
69
|
+
}
|
|
70
|
+
getUserFirstPostTime(pubkey) {
|
|
71
|
+
return this.getUserAssertion(pubkey).pipe(map((a) => a?.firstPostTime));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// ─── Helper to map TrustedProvider entries to AssertionProvider instances ───
|
|
75
|
+
function toAssertionProviders(providers, store) {
|
|
76
|
+
return providers.map((p) => castPubkey({ pubkey: p.servicePubkey, relays: p.relay ? [p.relay] : undefined }, AssertionProvider, store));
|
|
77
|
+
}
|
|
78
|
+
// ─── TrustedProviderList ─────────────────────────────────────────────────────
|
|
79
|
+
/** Cast a kind 10040 event to a TrustedProviderList */
|
|
80
|
+
export class TrustedProviderList extends EventCast {
|
|
81
|
+
constructor(event, store) {
|
|
82
|
+
if (!isValidTrustedProviderList(event))
|
|
83
|
+
throw new Error("Invalid trusted provider list");
|
|
84
|
+
super(event, store);
|
|
85
|
+
}
|
|
86
|
+
// ── Raw provider accessors ────────────────────────────────────────────────
|
|
87
|
+
/** All publicly declared providers (from tags) */
|
|
88
|
+
get publicProviders() {
|
|
89
|
+
return getPublicProviders(this.event);
|
|
90
|
+
}
|
|
91
|
+
/** Hidden providers if the event has been unlocked, otherwise undefined */
|
|
92
|
+
get hiddenProviders() {
|
|
93
|
+
return getHiddenProviders(this.event);
|
|
94
|
+
}
|
|
95
|
+
/** Observable that updates when hidden providers become available (after unlock) */
|
|
96
|
+
get hiddenProviders$() {
|
|
97
|
+
return this.$$ref("hiddenProviders$", (store) => of(this.event).pipe(watchEventUpdates(store), map((event) => (event ? getHiddenProviders(event) : undefined))));
|
|
98
|
+
}
|
|
99
|
+
/** Whether this list has an encrypted hidden providers section */
|
|
100
|
+
get hasHidden() {
|
|
101
|
+
return hasHiddenContent(this.event);
|
|
102
|
+
}
|
|
103
|
+
/** Whether the hidden providers have been unlocked */
|
|
104
|
+
get unlocked() {
|
|
105
|
+
return isHiddenProvidersUnlocked(this.event);
|
|
106
|
+
}
|
|
107
|
+
/** Decrypt and unlock the hidden providers */
|
|
108
|
+
unlock(signer) {
|
|
109
|
+
return unlockHiddenProviders(this.event, signer);
|
|
110
|
+
}
|
|
111
|
+
// ── Internal: combine public + hidden providers reactively ───────────────
|
|
112
|
+
#allProviders$() {
|
|
113
|
+
return combineLatest([of(this.publicProviders), this.hiddenProviders$]).pipe(map(([pub, hidden]) => [...pub, ...(hidden ?? [])]));
|
|
114
|
+
}
|
|
115
|
+
#providersFor$(kind, tag) {
|
|
116
|
+
return this.$$ref(`providers:${kind}:${tag}`, (store) => this.#allProviders$().pipe(map((all) => toAssertionProviders(all.filter((p) => p.kind === kind && p.tag === tag), store))));
|
|
117
|
+
}
|
|
118
|
+
// ── Kind 30382 (User assertion) provider observables ─────────────────────
|
|
119
|
+
/** Providers trusted for user rank (0–100) */
|
|
120
|
+
get userRank$() {
|
|
121
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "rank");
|
|
122
|
+
}
|
|
123
|
+
/** Providers trusted for user follower count */
|
|
124
|
+
get userFollowers$() {
|
|
125
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "followers");
|
|
126
|
+
}
|
|
127
|
+
/** Providers trusted for user first post timestamp */
|
|
128
|
+
get userFirstCreatedAt$() {
|
|
129
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "first_created_at");
|
|
130
|
+
}
|
|
131
|
+
/** Providers trusted for user post count */
|
|
132
|
+
get userPostCount$() {
|
|
133
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "post_cnt");
|
|
134
|
+
}
|
|
135
|
+
/** Providers trusted for user reply count */
|
|
136
|
+
get userReplyCount$() {
|
|
137
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "reply_cnt");
|
|
138
|
+
}
|
|
139
|
+
/** Providers trusted for user reactions count */
|
|
140
|
+
get userReactionsCount$() {
|
|
141
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "reactions_cnt");
|
|
142
|
+
}
|
|
143
|
+
/** Providers trusted for zap amount received */
|
|
144
|
+
get userZapAmountReceived$() {
|
|
145
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "zap_amt_recd");
|
|
146
|
+
}
|
|
147
|
+
/** Providers trusted for zap amount sent */
|
|
148
|
+
get userZapAmountSent$() {
|
|
149
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "zap_amt_sent");
|
|
150
|
+
}
|
|
151
|
+
/** Providers trusted for zap count received */
|
|
152
|
+
get userZapCountReceived$() {
|
|
153
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "zap_cnt_recd");
|
|
154
|
+
}
|
|
155
|
+
/** Providers trusted for zap count sent */
|
|
156
|
+
get userZapCountSent$() {
|
|
157
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "zap_cnt_sent");
|
|
158
|
+
}
|
|
159
|
+
/** Providers trusted for average daily zap amount received */
|
|
160
|
+
get userZapAvgAmountDayReceived$() {
|
|
161
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "zap_avg_amt_day_recd");
|
|
162
|
+
}
|
|
163
|
+
/** Providers trusted for average daily zap amount sent */
|
|
164
|
+
get userZapAvgAmountDaySent$() {
|
|
165
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "zap_avg_amt_day_sent");
|
|
166
|
+
}
|
|
167
|
+
/** Providers trusted for reports received count */
|
|
168
|
+
get userReportsReceived$() {
|
|
169
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "reports_cnt_recd");
|
|
170
|
+
}
|
|
171
|
+
/** Providers trusted for reports sent count */
|
|
172
|
+
get userReportsSent$() {
|
|
173
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "reports_cnt_sent");
|
|
174
|
+
}
|
|
175
|
+
/** Providers trusted for user common topics */
|
|
176
|
+
get userTopics$() {
|
|
177
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "t");
|
|
178
|
+
}
|
|
179
|
+
/** Providers trusted for user activity hours start */
|
|
180
|
+
get userActivityHoursStart$() {
|
|
181
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "active_hours_start");
|
|
182
|
+
}
|
|
183
|
+
/** Providers trusted for user activity hours end */
|
|
184
|
+
get userActivityHoursEnd$() {
|
|
185
|
+
return this.#providersFor$(USER_ASSERTION_KIND, "active_hours_end");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// ─── UserAssertion ───────────────────────────────────────────────────────────
|
|
189
|
+
/** Cast a kind 30382 event to a UserAssertion */
|
|
190
|
+
export class UserAssertion extends EventCast {
|
|
191
|
+
constructor(event, store) {
|
|
192
|
+
if (!isValidUserAssertion(event))
|
|
193
|
+
throw new Error("Invalid user assertion");
|
|
194
|
+
super(event, store);
|
|
195
|
+
}
|
|
196
|
+
/** The pubkey of the user being evaluated */
|
|
197
|
+
get subjectPubkey() {
|
|
198
|
+
return getAssertionSubject(this.event);
|
|
199
|
+
}
|
|
200
|
+
/** Observable of the {@link User} cast for the subject of this assertion */
|
|
201
|
+
get subject$() {
|
|
202
|
+
return this.$$ref("subject$", () => of(castUser(this.subjectPubkey, this.store)));
|
|
203
|
+
}
|
|
204
|
+
/** The {@link AssertionProvider} that published this assertion */
|
|
205
|
+
get provider() {
|
|
206
|
+
return castPubkey(this.event.pubkey, AssertionProvider, this.store);
|
|
207
|
+
}
|
|
208
|
+
// ── Assertion metrics ────────────────────────────────────────────────────
|
|
209
|
+
/** User rank score (0–100) */
|
|
210
|
+
get rank() {
|
|
211
|
+
return getAssertionRank(this.event);
|
|
212
|
+
}
|
|
213
|
+
/** Follower count */
|
|
214
|
+
get followerCount() {
|
|
215
|
+
return getAssertionFollowerCount(this.event);
|
|
216
|
+
}
|
|
217
|
+
/** Unix timestamp of the user's first post */
|
|
218
|
+
get firstCreatedAt() {
|
|
219
|
+
return getAssertionFirstCreatedAt(this.event);
|
|
220
|
+
}
|
|
221
|
+
/** Total post count */
|
|
222
|
+
get postCount() {
|
|
223
|
+
return getAssertionPostCount(this.event);
|
|
224
|
+
}
|
|
225
|
+
/** Total reply count */
|
|
226
|
+
get replyCount() {
|
|
227
|
+
return getAssertionReplyCount(this.event);
|
|
228
|
+
}
|
|
229
|
+
/** Total reactions count */
|
|
230
|
+
get reactionsCount() {
|
|
231
|
+
return getAssertionReactionsCount(this.event);
|
|
232
|
+
}
|
|
233
|
+
/** Zap statistics for zaps received by this user */
|
|
234
|
+
get zapsReceived() {
|
|
235
|
+
return {
|
|
236
|
+
count: getAssertionZapCountReceived(this.event),
|
|
237
|
+
amount: getAssertionZapAmountReceived(this.event),
|
|
238
|
+
avgPerDay: getAssertionZapAvgAmountDayReceived(this.event),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** Zap statistics for zaps sent by this user */
|
|
242
|
+
get zapsSent() {
|
|
243
|
+
return {
|
|
244
|
+
count: getAssertionZapCountSent(this.event),
|
|
245
|
+
amount: getAssertionZapAmountSent(this.event),
|
|
246
|
+
avgPerDay: getAssertionZapAvgAmountDaySent(this.event),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/** Number of reports this user has received */
|
|
250
|
+
get reportsReceived() {
|
|
251
|
+
return getAssertionReportsReceived(this.event);
|
|
252
|
+
}
|
|
253
|
+
/** Number of reports this user has sent */
|
|
254
|
+
get reportsSent() {
|
|
255
|
+
return getAssertionReportsSent(this.event);
|
|
256
|
+
}
|
|
257
|
+
/** Common topics associated with this user */
|
|
258
|
+
get topics() {
|
|
259
|
+
return getAssertionTopics(this.event);
|
|
260
|
+
}
|
|
261
|
+
/** UTC hour range during which this user is generally active */
|
|
262
|
+
get activityWindow() {
|
|
263
|
+
return {
|
|
264
|
+
start: getAssertionActivityHoursStart(this.event),
|
|
265
|
+
end: getAssertionActivityHoursEnd(this.event),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
/** Date of the user's first post, or undefined if not provided */
|
|
269
|
+
get firstPostTime() {
|
|
270
|
+
const ts = getAssertionFirstCreatedAt(this.event);
|
|
271
|
+
return ts !== undefined ? new Date(ts * 1000) : undefined;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// ─── castTrustedProviders helper ─────────────────────────────────────────────
|
|
275
|
+
/**
|
|
276
|
+
* Convenience function to get all AssertionProvider instances for a specific
|
|
277
|
+
* assertion type directly from a provider list event.
|
|
278
|
+
*/
|
|
279
|
+
export function castTrustedProviders(event, kind, tag, store) {
|
|
280
|
+
return toAssertionProviders(getAllProviders(event).filter((p) => p.kind === kind && p.tag === tag), store);
|
|
281
|
+
}
|