applesauce-common 5.1.0 → 5.2.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/user.d.ts +2 -0
- package/dist/casts/user.js +9 -0
- package/dist/helpers/emoji.d.ts +4 -1
- package/dist/helpers/emoji.js +9 -5
- package/dist/models/thread.d.ts +1 -1
- package/dist/models/thread.js +23 -7
- package/package.json +3 -3
package/dist/casts/user.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export declare class User {
|
|
|
33
33
|
get searchRelays$(): ChainableObservable<import("./relay-lists.js").SearchRelays | undefined>;
|
|
34
34
|
get blockedRelays$(): ChainableObservable<import("./relay-lists.js").BlockedRelays | undefined>;
|
|
35
35
|
get directMessageRelays$(): ChainableObservable<string[] | undefined>;
|
|
36
|
+
/** Get the users kind 10063 Blossom servers list */
|
|
37
|
+
get blossomServers$(): ChainableObservable<URL[] | undefined>;
|
|
36
38
|
/** Gets the users list of NIP-29 groups */
|
|
37
39
|
get groups$(): ChainableObservable<import("./groups.js").GroupsList | undefined>;
|
|
38
40
|
/** Get the latest live stream for the user */
|
package/dist/casts/user.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isEvent, isHexKey, kinds, nprofileEncode, npubEncode, } from "applesauce-core/helpers";
|
|
2
2
|
import { combineLatest, defer, from, map, ReplaySubject, share, switchMap, tap, } from "rxjs";
|
|
3
|
+
import { BLOSSOM_SERVER_LIST_KIND, getBlossomServersFromList } from "../helpers/blossom.js";
|
|
3
4
|
import { GROUPS_LIST_KIND } from "../helpers/groups.js";
|
|
4
5
|
import { getRelaysFromList } from "../helpers/lists.js";
|
|
5
6
|
import { FAVORITE_RELAYS_KIND } from "../helpers/relay-list.js";
|
|
@@ -147,6 +148,14 @@ export class User {
|
|
|
147
148
|
.replaceable({ kind: kinds.DirectMessageRelaysList, pubkey: this.pubkey, relays: outboxes })
|
|
148
149
|
.pipe(map((event) => event && getRelaysFromList(event))))));
|
|
149
150
|
}
|
|
151
|
+
/** Get the users kind 10063 Blossom servers list */
|
|
152
|
+
get blossomServers$() {
|
|
153
|
+
return this.$$ref("blossomServers$", (store) => this.outboxes$.pipe(
|
|
154
|
+
// Fetch the blossom servers list event from the outboxes
|
|
155
|
+
switchMap((outboxes) => store
|
|
156
|
+
.replaceable({ kind: BLOSSOM_SERVER_LIST_KIND, pubkey: this.pubkey, relays: outboxes })
|
|
157
|
+
.pipe(map((event) => event && getBlossomServersFromList(event))))));
|
|
158
|
+
}
|
|
150
159
|
/** Gets the users list of NIP-29 groups */
|
|
151
160
|
get groups$() {
|
|
152
161
|
return this.$$ref("groups$", (store) => combineLatest([Circular.Groups, this.outboxes$]).pipe(switchMap(([{ GroupsList }, outboxes]) => store
|
package/dist/helpers/emoji.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
2
3
|
export type Emoji = {
|
|
3
4
|
/** The emoji shortcode (without the ::) */
|
|
4
5
|
shortcode: string;
|
|
5
6
|
/** The URL to the emoji image */
|
|
6
7
|
url: string;
|
|
8
|
+
/** The NIP-01 "a" tag address of the emoji pack this emoji belongs to */
|
|
9
|
+
address?: AddressPointer;
|
|
7
10
|
};
|
|
8
11
|
/** Gets an "emoji" tag that matches an emoji code */
|
|
9
12
|
export declare function getEmojiTag(tags: {
|
|
10
13
|
tags: string[][];
|
|
11
|
-
} | string[][], code: string): ["emoji", string, string] | undefined;
|
|
14
|
+
} | string[][], code: string): ["emoji", string, string, ...string[]] | undefined;
|
|
12
15
|
/** Gets an emoji for a shortcode from an array of tags or event */
|
|
13
16
|
export declare function getEmojiFromTags(event: {
|
|
14
17
|
tags: string[][];
|
package/dist/helpers/emoji.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getTagValue } from "applesauce-core/helpers/event";
|
|
2
|
+
import { parseReplaceableAddress } from "applesauce-core/helpers/pointers";
|
|
2
3
|
/** Gets an "emoji" tag that matches an emoji code */
|
|
3
4
|
export function getEmojiTag(tags, code) {
|
|
4
5
|
code = code.replace(/^:|:$/g, "").toLowerCase();
|
|
@@ -9,10 +10,8 @@ export function getEmojiFromTags(event, code) {
|
|
|
9
10
|
const tag = getEmojiTag(event, code);
|
|
10
11
|
if (!tag)
|
|
11
12
|
return undefined;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
url: tag[2],
|
|
15
|
-
};
|
|
13
|
+
const address = tag[3] ? parseReplaceableAddress(tag[3]) : undefined;
|
|
14
|
+
return address ? { shortcode: tag[1], url: tag[2], address } : { shortcode: tag[1], url: tag[2] };
|
|
16
15
|
}
|
|
17
16
|
/** Returns the name of a NIP-30 emoji pack */
|
|
18
17
|
export function getPackName(pack) {
|
|
@@ -22,7 +21,12 @@ export function getPackName(pack) {
|
|
|
22
21
|
export function getEmojis(pack) {
|
|
23
22
|
return pack.tags
|
|
24
23
|
.filter((t) => t[0] === "emoji" && t[1] && t[2])
|
|
25
|
-
.map((t) =>
|
|
24
|
+
.map((t) => {
|
|
25
|
+
const address = t[3] ? parseReplaceableAddress(t[3]) : undefined;
|
|
26
|
+
return address
|
|
27
|
+
? { shortcode: t[1], url: t[2], address }
|
|
28
|
+
: { shortcode: t[1], url: t[2] };
|
|
29
|
+
});
|
|
26
30
|
}
|
|
27
31
|
/** Returns the custom emoji for a reaction event */
|
|
28
32
|
export function getReactionEmoji(event) {
|
package/dist/models/thread.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type ThreadModelOptions = {
|
|
|
24
24
|
/** A model that returns a NIP-10 thread of events */
|
|
25
25
|
export declare function ThreadModel(root: string | AddressPointer | EventPointer, opts?: ThreadModelOptions): Model<Thread>;
|
|
26
26
|
/** A model that gets all legacy and NIP-10, and NIP-22 replies for an event */
|
|
27
|
-
export declare function RepliesModel(event: NostrEvent, overrideKinds?: number[]): Model<NostrEvent[]>;
|
|
27
|
+
export declare function RepliesModel(event: NostrEvent | EventPointer | AddressPointer, overrideKinds?: number[]): Model<NostrEvent[]>;
|
|
28
28
|
declare module "applesauce-core/event-store" {
|
|
29
29
|
interface EventModels {
|
|
30
30
|
/** Subscribe to a thread */
|
package/dist/models/thread.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventModels } from "applesauce-core/event-store";
|
|
2
2
|
import { buildCommonEventRelationFilters } from "applesauce-core/helpers";
|
|
3
3
|
import { getEventUID, kinds } from "applesauce-core/helpers/event";
|
|
4
|
-
import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer, } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import { eventMatchesPointer, getReplaceableAddressFromPointer, isAddressPointer, isEventPointer, isAddressPointerSame, isEventPointerSame, } from "applesauce-core/helpers/pointers";
|
|
5
5
|
import { map } from "rxjs/operators";
|
|
6
6
|
import { COMMENT_KIND, getCommentReplyPointer } from "../helpers/comment.js";
|
|
7
7
|
import { getNip10References } from "../helpers/threading.js";
|
|
@@ -74,20 +74,36 @@ export function RepliesModel(event, overrideKinds) {
|
|
|
74
74
|
if (reply.kind === kinds.ShortTextNote) {
|
|
75
75
|
// Check if a NIP-10 reply is a direct reply to this event
|
|
76
76
|
const refs = getNip10References(reply);
|
|
77
|
-
|
|
78
|
-
if (!
|
|
77
|
+
// Ingore if event is not replying to anything
|
|
78
|
+
if (!refs.reply)
|
|
79
79
|
return false;
|
|
80
|
-
|
|
80
|
+
// If the input was provided as an event pointer, test the reply.e
|
|
81
|
+
if (isEventPointer(event))
|
|
82
|
+
return refs.reply?.e && isEventPointerSame(event, refs.reply.e);
|
|
83
|
+
// If the input was provided as an address pointer, test the reply.a
|
|
84
|
+
else if (isAddressPointer(event))
|
|
85
|
+
return refs.reply?.a && isAddressPointerSame(event, refs.reply.a);
|
|
86
|
+
// Else test the reply against the event
|
|
87
|
+
else
|
|
88
|
+
return eventMatchesPointer(event, refs.reply?.a || refs.reply?.e);
|
|
81
89
|
}
|
|
82
90
|
else if (reply.kind === COMMENT_KIND) {
|
|
83
91
|
// Check if a NIP-22 reply is a direct reply to this event
|
|
84
92
|
const pointer = getCommentReplyPointer(reply);
|
|
85
93
|
if (!pointer)
|
|
86
94
|
return false;
|
|
87
|
-
|
|
95
|
+
// Ignore external pointers
|
|
96
|
+
if (pointer.type === "external")
|
|
97
|
+
return true;
|
|
98
|
+
// Input is an event pointer, check if they match
|
|
99
|
+
if (isEventPointer(event))
|
|
100
|
+
return pointer.type === "event" ? isEventPointerSame(event, pointer) : false;
|
|
101
|
+
// Input is an address pointer, check if they match
|
|
102
|
+
else if (isAddressPointer(event))
|
|
103
|
+
return pointer.type === "address" ? isAddressPointerSame(event, pointer) : false;
|
|
104
|
+
// Else test the reply against the event
|
|
105
|
+
else
|
|
88
106
|
return eventMatchesPointer(event, pointer);
|
|
89
|
-
else if (pointer.type === "event")
|
|
90
|
-
return pointer.id === event.id;
|
|
91
107
|
}
|
|
92
108
|
return false;
|
|
93
109
|
})));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-common",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Common NIP-specific helpers and models for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@scure/base": "^1.2.4",
|
|
86
|
-
"applesauce-core": "^5.
|
|
86
|
+
"applesauce-core": "^5.2.0",
|
|
87
87
|
"hash-sum": "^2.0.0",
|
|
88
88
|
"light-bolt11-decoder": "^3.2.0",
|
|
89
89
|
"rxjs": "^7.8.1"
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@types/debug": "^4.1.12",
|
|
95
95
|
"@types/hash-sum": "^1.0.2",
|
|
96
96
|
"@types/node": "^22.19.1",
|
|
97
|
-
"ajv": "^8.
|
|
97
|
+
"ajv": "^8.18.0",
|
|
98
98
|
"ajv-formats": "^3.0.1",
|
|
99
99
|
"nostr-tools": "^2.19",
|
|
100
100
|
"rimraf": "^6.0.1",
|