applesauce-common 0.0.0-next-20251209200210 → 0.0.0-next-20251220152312
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/blueprints/__register__.d.ts +6 -0
- package/dist/blueprints/__register__.js +7 -0
- package/dist/blueprints/group-mangement.d.ts +25 -0
- package/dist/blueprints/group-mangement.js +40 -0
- package/dist/blueprints/index.d.ts +1 -0
- package/dist/blueprints/index.js +1 -0
- package/dist/casts/article.d.ts +17 -0
- package/dist/casts/article.js +41 -0
- package/dist/casts/bookmarks.d.ts +35 -0
- package/dist/casts/bookmarks.js +79 -0
- package/dist/casts/cast.d.ts +30 -0
- package/dist/casts/cast.js +67 -0
- package/dist/casts/comment.d.ts +16 -0
- package/dist/casts/comment.js +49 -0
- package/dist/casts/index.d.ts +12 -0
- package/dist/casts/index.js +12 -0
- package/dist/casts/mutes.d.ts +23 -0
- package/dist/casts/mutes.js +54 -0
- package/dist/casts/note.d.ts +17 -0
- package/dist/casts/note.js +46 -0
- package/dist/casts/profile.d.ts +16 -0
- package/dist/casts/profile.js +40 -0
- package/dist/casts/relay-lists.d.ts +33 -0
- package/dist/casts/relay-lists.js +72 -0
- package/dist/casts/share.d.ts +13 -0
- package/dist/casts/share.js +28 -0
- package/dist/casts/stream.d.ts +43 -0
- package/dist/casts/stream.js +116 -0
- package/dist/casts/user.d.ts +38 -0
- package/dist/casts/user.js +169 -0
- package/dist/casts/zap.d.ts +17 -0
- package/dist/casts/zap.js +47 -0
- package/dist/helpers/bookmark.d.ts +18 -17
- package/dist/helpers/bookmark.js +36 -49
- package/dist/helpers/encrypted-content-cache.js +23 -25
- package/dist/helpers/gift-wrap.js +11 -5
- package/dist/helpers/groups.d.ts +118 -6
- package/dist/helpers/groups.js +287 -10
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/lists.d.ts +0 -1
- package/dist/helpers/lists.js +4 -5
- package/dist/helpers/mute.d.ts +14 -11
- package/dist/helpers/mute.js +9 -4
- package/dist/helpers/relay-list.d.ts +14 -0
- package/dist/helpers/relay-list.js +18 -0
- package/dist/helpers/stream-chat.d.ts +4 -1
- package/dist/helpers/stream-chat.js +4 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/__register__.d.ts +5 -0
- package/dist/models/__register__.js +6 -0
- package/dist/models/bookmarks.d.ts +3 -5
- package/dist/models/bookmarks.js +2 -10
- package/dist/models/index.d.ts +3 -1
- package/dist/models/index.js +4 -1
- package/dist/models/mutes.d.ts +5 -5
- package/dist/models/{relays.js → relay-lists.js} +2 -1
- package/dist/models/shares.d.ts +3 -0
- package/dist/models/shares.js +5 -0
- package/dist/models/thread.js +30 -24
- package/dist/observable/cast-stream.d.ts +8 -0
- package/dist/observable/cast-stream.js +29 -0
- package/dist/observable/chainable.d.ts +50 -0
- package/dist/observable/chainable.js +79 -0
- package/dist/observable/index.d.ts +2 -0
- package/dist/observable/index.js +2 -0
- package/dist/operations/group.d.ts +14 -1
- package/dist/operations/group.js +42 -4
- package/dist/operations/index.d.ts +1 -1
- package/dist/operations/index.js +1 -1
- package/dist/operations/tag/bookmarks.d.ts +3 -2
- package/dist/operations/tag/bookmarks.js +34 -14
- package/dist/register.d.ts +2 -11
- package/dist/register.js +2 -11
- package/package.json +12 -2
- package/dist/helpers/mailboxes.d.ts +0 -7
- package/dist/helpers/mailboxes.js +0 -49
- /package/dist/models/{relays.d.ts → relay-lists.d.ts} +0 -0
package/dist/helpers/groups.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
2
|
import { getReplaceableIdentifier, getTagValue } from "applesauce-core/helpers/event";
|
|
3
3
|
import { getHiddenTags } from "applesauce-core/helpers/hidden-tags";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { processTags } from "applesauce-core/helpers/tags";
|
|
5
|
+
import { normalizeURL } from "applesauce-core/helpers/url";
|
|
6
6
|
export const GROUPS_LIST_KIND = 10009;
|
|
7
7
|
export const GROUP_MESSAGE_KIND = 9;
|
|
8
|
+
// NIP-29 Group event kinds
|
|
9
|
+
export const GROUP_METADATA_KIND = 39000;
|
|
10
|
+
export const GROUP_ADMINS_KIND = 39001;
|
|
11
|
+
export const GROUP_MEMBERS_KIND = 39002;
|
|
12
|
+
export const GROUP_ROLES_KIND = 39003;
|
|
13
|
+
export const JOIN_REQUEST_KIND = 9021;
|
|
14
|
+
export const LEAVE_REQUEST_KIND = 9022;
|
|
15
|
+
export const PUT_USER_KIND = 9000;
|
|
16
|
+
export const REMOVE_USER_KIND = 9001;
|
|
17
|
+
export const EDIT_METADATA_KIND = 9002;
|
|
18
|
+
export const DELETE_EVENT_KIND = 9005;
|
|
19
|
+
export const CREATE_GROUP_KIND = 9007;
|
|
20
|
+
export const DELETE_GROUP_KIND = 9008;
|
|
21
|
+
export const CREATE_INVITE_KIND = 9009;
|
|
8
22
|
/** decodes a group identifier into a group pointer object */
|
|
9
23
|
export function decodeGroupPointer(str) {
|
|
10
24
|
let [relay, id] = str.split("'");
|
|
@@ -25,8 +39,10 @@ export function encodeGroupPointer(pointer) {
|
|
|
25
39
|
export const GroupsPublicSymbol = Symbol.for("groups-public");
|
|
26
40
|
export const GroupsHiddenSymbol = Symbol.for("groups-hidden");
|
|
27
41
|
/** gets a {@link GroupPointer} from a "h" tag if it has a relay hint */
|
|
28
|
-
export function getGroupPointerFromHTag(tag) {
|
|
29
|
-
|
|
42
|
+
export function getGroupPointerFromHTag(tag, hint) {
|
|
43
|
+
let [_, id, relay] = tag;
|
|
44
|
+
if (!relay && hint)
|
|
45
|
+
relay = hint;
|
|
30
46
|
if (!id || !relay)
|
|
31
47
|
return undefined;
|
|
32
48
|
return { id, relay };
|
|
@@ -48,6 +64,20 @@ export function getHiddenGroups(bookmark) {
|
|
|
48
64
|
processTags(bookmark.tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag));
|
|
49
65
|
});
|
|
50
66
|
}
|
|
67
|
+
/** Gets a {@link GroupPointer} from a group event by reading the "h" tag */
|
|
68
|
+
export function getGroupPointer(event, relay) {
|
|
69
|
+
const hTag = event.tags.find((t) => t[0] === "h");
|
|
70
|
+
if (!hTag)
|
|
71
|
+
return undefined;
|
|
72
|
+
return getGroupPointerFromHTag(hTag, relay);
|
|
73
|
+
}
|
|
74
|
+
/** Gets the group id from a group event by reading the "h" tag */
|
|
75
|
+
export function getGroupId(event) {
|
|
76
|
+
const hTag = event.tags.find((t) => t[0] === "h");
|
|
77
|
+
if (!hTag)
|
|
78
|
+
return undefined;
|
|
79
|
+
return hTag[1];
|
|
80
|
+
}
|
|
51
81
|
/** Gets a {@link GroupPointer} from a kind 39000 group metadata event */
|
|
52
82
|
export function getGroupPointerFromMetadata(event, relay) {
|
|
53
83
|
// Use the "d" tag for the group ID and the provided relay
|
|
@@ -59,11 +89,258 @@ export function getGroupPointerFromMetadata(event, relay) {
|
|
|
59
89
|
name: name,
|
|
60
90
|
};
|
|
61
91
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
92
|
+
// Symbols for caching parsed data
|
|
93
|
+
const GroupMetadataSymbol = Symbol.for("group-metadata");
|
|
94
|
+
const GroupAdminsSymbol = Symbol.for("group-admins");
|
|
95
|
+
const GroupMembersSymbol = Symbol.for("group-members");
|
|
96
|
+
const GroupRolesSymbol = Symbol.for("group-roles");
|
|
97
|
+
const JoinRequestSymbol = Symbol.for("join-request");
|
|
98
|
+
const LeaveRequestSymbol = Symbol.for("leave-request");
|
|
99
|
+
const PutUserSymbol = Symbol.for("put-user");
|
|
100
|
+
const RemoveUserSymbol = Symbol.for("remove-user");
|
|
101
|
+
const EditMetadataSymbol = Symbol.for("edit-metadata");
|
|
102
|
+
const DeleteEventSymbol = Symbol.for("delete-event");
|
|
103
|
+
const CreateGroupSymbol = Symbol.for("create-group");
|
|
104
|
+
const DeleteGroupSymbol = Symbol.for("delete-group");
|
|
105
|
+
const CreateInviteSymbol = Symbol.for("create-invite");
|
|
106
|
+
/** Gets group metadata from a kind 39000 event */
|
|
107
|
+
export function getGroupMetadata(event) {
|
|
108
|
+
if (event.kind !== GROUP_METADATA_KIND)
|
|
109
|
+
return undefined;
|
|
110
|
+
return getOrComputeCachedValue(event, GroupMetadataSymbol, () => {
|
|
111
|
+
const id = getReplaceableIdentifier(event) || "_";
|
|
112
|
+
const name = getTagValue(event, "name");
|
|
113
|
+
const picture = getTagValue(event, "picture");
|
|
114
|
+
const about = getTagValue(event, "about");
|
|
115
|
+
const publicTag = event.tags.find((t) => t[0] === "public");
|
|
116
|
+
const privateTag = event.tags.find((t) => t[0] === "private");
|
|
117
|
+
const openTag = event.tags.find((t) => t[0] === "open");
|
|
118
|
+
const closedTag = event.tags.find((t) => t[0] === "closed");
|
|
119
|
+
return {
|
|
120
|
+
id,
|
|
121
|
+
name,
|
|
122
|
+
picture,
|
|
123
|
+
about,
|
|
124
|
+
isPublic: !!publicTag,
|
|
125
|
+
isPrivate: !!privateTag,
|
|
126
|
+
isOpen: !!openTag,
|
|
127
|
+
isClosed: !!closedTag,
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/** Gets group admins from a kind 39001 event */
|
|
132
|
+
export function getGroupAdmins(event) {
|
|
133
|
+
if (event.kind !== GROUP_ADMINS_KIND)
|
|
134
|
+
return undefined;
|
|
135
|
+
return getOrComputeCachedValue(event, GroupAdminsSymbol, () => {
|
|
136
|
+
const adminsMap = new Map();
|
|
137
|
+
for (const tag of event.tags) {
|
|
138
|
+
if (tag[0] === "p" && tag[1]) {
|
|
139
|
+
const pubkey = tag[1];
|
|
140
|
+
const roles = tag.slice(2).filter((r) => r.length > 0);
|
|
141
|
+
if (adminsMap.has(pubkey)) {
|
|
142
|
+
const existingRoles = adminsMap.get(pubkey);
|
|
143
|
+
adminsMap.set(pubkey, [...new Set([...existingRoles, ...roles])]);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
adminsMap.set(pubkey, roles);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return Array.from(adminsMap.entries()).map(([pubkey, roles]) => ({
|
|
151
|
+
pubkey,
|
|
152
|
+
roles,
|
|
153
|
+
}));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** Gets group members from a kind 39002 event */
|
|
157
|
+
export function getGroupMembers(event) {
|
|
158
|
+
if (event.kind !== GROUP_MEMBERS_KIND)
|
|
159
|
+
return undefined;
|
|
160
|
+
return getOrComputeCachedValue(event, GroupMembersSymbol, () => {
|
|
161
|
+
return event.tags.filter((t) => t[0] === "p" && t[1]).map((t) => t[1]);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** Gets group roles from a kind 39003 event */
|
|
165
|
+
export function getGroupRoles(event) {
|
|
166
|
+
if (event.kind !== GROUP_ROLES_KIND)
|
|
167
|
+
return undefined;
|
|
168
|
+
return getOrComputeCachedValue(event, GroupRolesSymbol, () => {
|
|
169
|
+
return event.tags
|
|
170
|
+
.filter((t) => t[0] === "role" && t[1])
|
|
171
|
+
.map((t) => ({
|
|
172
|
+
name: t[1],
|
|
173
|
+
description: t[2],
|
|
174
|
+
}));
|
|
175
|
+
});
|
|
65
176
|
}
|
|
66
|
-
/**
|
|
67
|
-
export function
|
|
68
|
-
|
|
177
|
+
/** Gets join request information from a kind 9021 event */
|
|
178
|
+
export function getGroupJoinRequestInfo(event) {
|
|
179
|
+
if (event.kind !== JOIN_REQUEST_KIND)
|
|
180
|
+
return undefined;
|
|
181
|
+
return getOrComputeCachedValue(event, JoinRequestSymbol, () => {
|
|
182
|
+
const groupId = getGroupId(event);
|
|
183
|
+
if (!groupId)
|
|
184
|
+
return undefined;
|
|
185
|
+
return {
|
|
186
|
+
groupId,
|
|
187
|
+
reason: event.content || undefined,
|
|
188
|
+
inviteCode: getTagValue(event, "code"),
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/** Gets leave request information from a kind 9022 event */
|
|
193
|
+
export function getGroupLeaveRequestInfo(event) {
|
|
194
|
+
if (event.kind !== LEAVE_REQUEST_KIND)
|
|
195
|
+
return undefined;
|
|
196
|
+
return getOrComputeCachedValue(event, LeaveRequestSymbol, () => {
|
|
197
|
+
const groupId = getGroupId(event);
|
|
198
|
+
if (!groupId)
|
|
199
|
+
return undefined;
|
|
200
|
+
return {
|
|
201
|
+
groupId,
|
|
202
|
+
reason: event.content || undefined,
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/** Gets put user event information from a kind 9000 event */
|
|
207
|
+
export function getGroupPutUserInfo(event) {
|
|
208
|
+
if (event.kind !== PUT_USER_KIND)
|
|
209
|
+
return undefined;
|
|
210
|
+
return getOrComputeCachedValue(event, PutUserSymbol, () => {
|
|
211
|
+
const groupId = getGroupId(event);
|
|
212
|
+
const pubkey = getTagValue(event, "p");
|
|
213
|
+
if (!groupId || !pubkey)
|
|
214
|
+
return undefined;
|
|
215
|
+
const roles = event.tags.filter((t) => t[0] === "p" && t.length > 2).flatMap((t) => t.slice(2));
|
|
216
|
+
return {
|
|
217
|
+
groupId,
|
|
218
|
+
pubkey,
|
|
219
|
+
roles: roles.length > 0 ? roles : undefined,
|
|
220
|
+
reason: event.content || undefined,
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/** Gets remove user event information from a kind 9001 event */
|
|
225
|
+
export function getGroupRemoveUserInfo(event) {
|
|
226
|
+
if (event.kind !== REMOVE_USER_KIND)
|
|
227
|
+
return undefined;
|
|
228
|
+
return getOrComputeCachedValue(event, RemoveUserSymbol, () => {
|
|
229
|
+
const groupId = getGroupId(event);
|
|
230
|
+
const pubkey = getTagValue(event, "p");
|
|
231
|
+
if (!groupId || !pubkey)
|
|
232
|
+
return undefined;
|
|
233
|
+
return {
|
|
234
|
+
groupId,
|
|
235
|
+
pubkey,
|
|
236
|
+
reason: event.content || undefined,
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/** Gets edit metadata event information from a kind 9002 event */
|
|
241
|
+
export function getGroupEditMetadataInfo(event) {
|
|
242
|
+
if (event.kind !== EDIT_METADATA_KIND)
|
|
243
|
+
return undefined;
|
|
244
|
+
return getOrComputeCachedValue(event, EditMetadataSymbol, () => {
|
|
245
|
+
const groupId = getGroupId(event);
|
|
246
|
+
if (!groupId)
|
|
247
|
+
return undefined;
|
|
248
|
+
const metadataFields = {};
|
|
249
|
+
const name = getTagValue(event, "name");
|
|
250
|
+
const picture = getTagValue(event, "picture");
|
|
251
|
+
const about = getTagValue(event, "about");
|
|
252
|
+
const publicTag = event.tags.find((t) => t[0] === "public");
|
|
253
|
+
const privateTag = event.tags.find((t) => t[0] === "private");
|
|
254
|
+
const openTag = event.tags.find((t) => t[0] === "open");
|
|
255
|
+
const closedTag = event.tags.find((t) => t[0] === "closed");
|
|
256
|
+
if (name !== undefined)
|
|
257
|
+
metadataFields.name = name;
|
|
258
|
+
if (picture !== undefined)
|
|
259
|
+
metadataFields.picture = picture;
|
|
260
|
+
if (about !== undefined)
|
|
261
|
+
metadataFields.about = about;
|
|
262
|
+
if (publicTag)
|
|
263
|
+
metadataFields.isPublic = true;
|
|
264
|
+
if (privateTag)
|
|
265
|
+
metadataFields.isPrivate = true;
|
|
266
|
+
if (openTag)
|
|
267
|
+
metadataFields.isOpen = true;
|
|
268
|
+
if (closedTag)
|
|
269
|
+
metadataFields.isClosed = true;
|
|
270
|
+
return {
|
|
271
|
+
groupId,
|
|
272
|
+
metadataFields,
|
|
273
|
+
reason: event.content || undefined,
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/** Gets delete event information from a kind 9005 event */
|
|
278
|
+
export function getGroupDeleteEventInfo(event) {
|
|
279
|
+
if (event.kind !== DELETE_EVENT_KIND)
|
|
280
|
+
return undefined;
|
|
281
|
+
return getOrComputeCachedValue(event, DeleteEventSymbol, () => {
|
|
282
|
+
const groupId = getGroupId(event);
|
|
283
|
+
const eventId = getTagValue(event, "e");
|
|
284
|
+
if (!groupId || !eventId)
|
|
285
|
+
return undefined;
|
|
286
|
+
return {
|
|
287
|
+
groupId,
|
|
288
|
+
eventId,
|
|
289
|
+
reason: event.content || undefined,
|
|
290
|
+
};
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/** Gets create group event information from a kind 9007 event */
|
|
294
|
+
export function getGroupCreateGroupInfo(event) {
|
|
295
|
+
if (event.kind !== CREATE_GROUP_KIND)
|
|
296
|
+
return undefined;
|
|
297
|
+
return getOrComputeCachedValue(event, CreateGroupSymbol, () => {
|
|
298
|
+
const groupId = getGroupId(event);
|
|
299
|
+
if (!groupId)
|
|
300
|
+
return undefined;
|
|
301
|
+
return {
|
|
302
|
+
groupId,
|
|
303
|
+
reason: event.content || undefined,
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/** Gets delete group event information from a kind 9008 event */
|
|
308
|
+
export function getGroupDeleteGroupInfo(event) {
|
|
309
|
+
if (event.kind !== DELETE_GROUP_KIND)
|
|
310
|
+
return undefined;
|
|
311
|
+
return getOrComputeCachedValue(event, DeleteGroupSymbol, () => {
|
|
312
|
+
const groupId = getGroupId(event);
|
|
313
|
+
if (!groupId)
|
|
314
|
+
return undefined;
|
|
315
|
+
return {
|
|
316
|
+
groupId,
|
|
317
|
+
reason: event.content || undefined,
|
|
318
|
+
};
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/** Gets create invite event information from a kind 9009 event */
|
|
322
|
+
export function getGroupCreateInviteInfo(event) {
|
|
323
|
+
if (event.kind !== CREATE_INVITE_KIND)
|
|
324
|
+
return undefined;
|
|
325
|
+
return getOrComputeCachedValue(event, CreateInviteSymbol, () => {
|
|
326
|
+
const groupId = getGroupId(event);
|
|
327
|
+
if (!groupId)
|
|
328
|
+
return undefined;
|
|
329
|
+
return {
|
|
330
|
+
groupId,
|
|
331
|
+
reason: event.content || undefined,
|
|
332
|
+
};
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
/** Checks group membership status from kind 9000/9001 events */
|
|
336
|
+
export function checkGroupMembership(events, pubkey) {
|
|
337
|
+
// Filter to only membership-related events
|
|
338
|
+
const membershipEvents = events.filter((e) => (e.kind === PUT_USER_KIND || e.kind === REMOVE_USER_KIND) && getTagValue(e, "p") === pubkey);
|
|
339
|
+
if (membershipEvents.length === 0)
|
|
340
|
+
return undefined;
|
|
341
|
+
// Sort by created_at descending to get the latest event
|
|
342
|
+
const sorted = membershipEvents.sort((a, b) => b.created_at - a.created_at);
|
|
343
|
+
const latest = sorted[0];
|
|
344
|
+
// Latest event determines membership status
|
|
345
|
+
return latest.kind === PUT_USER_KIND;
|
|
69
346
|
}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -19,7 +19,6 @@ export * from "./highlight.js";
|
|
|
19
19
|
export * from "./legacy-messages.js";
|
|
20
20
|
export * from "./lists.js";
|
|
21
21
|
export * from "./lnurl.js";
|
|
22
|
-
export * from "./mailboxes.js";
|
|
23
22
|
export * from "./messages.js";
|
|
24
23
|
export * from "./mute.js";
|
|
25
24
|
export * from "./picture-post.js";
|
|
@@ -35,3 +34,4 @@ export * from "./torrent.js";
|
|
|
35
34
|
export * from "./user-status.js";
|
|
36
35
|
export * from "./wrapped-messages.js";
|
|
37
36
|
export * from "./zap.js";
|
|
37
|
+
export * from "./relay-list.js";
|
package/dist/helpers/index.js
CHANGED
|
@@ -19,7 +19,6 @@ export * from "./highlight.js";
|
|
|
19
19
|
export * from "./legacy-messages.js";
|
|
20
20
|
export * from "./lists.js";
|
|
21
21
|
export * from "./lnurl.js";
|
|
22
|
-
export * from "./mailboxes.js";
|
|
23
22
|
export * from "./messages.js";
|
|
24
23
|
export * from "./mute.js";
|
|
25
24
|
export * from "./picture-post.js";
|
|
@@ -35,3 +34,4 @@ export * from "./torrent.js";
|
|
|
35
34
|
export * from "./user-status.js";
|
|
36
35
|
export * from "./wrapped-messages.js";
|
|
37
36
|
export * from "./zap.js";
|
|
37
|
+
export * from "./relay-list.js";
|
package/dist/helpers/lists.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { AddressPointer, EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
3
|
-
export declare const FAVORITE_RELAYS_KIND = 10012;
|
|
4
3
|
export type ReadListTags = "public" | "hidden" | "all";
|
|
5
4
|
/** Returns all the tags of a list or set */
|
|
6
5
|
export declare function getListTags(list: NostrEvent, type?: ReadListTags): string[][];
|
package/dist/helpers/lists.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { getReplaceableIdentifier, isAddressableKind, isReplaceable, isReplaceableKind, } from "applesauce-core/helpers/event";
|
|
2
2
|
import { getHiddenTags } from "applesauce-core/helpers/hidden-tags";
|
|
3
|
-
import { getAddressPointerForEvent, getAddressPointerFromATag,
|
|
4
|
-
import {
|
|
3
|
+
import { getAddressPointerForEvent, getAddressPointerFromATag, getEventPointerFromETag, getProfilePointerFromPTag, getReplaceableAddressFromPointer, } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import { relaySet } from "applesauce-core/helpers/relays";
|
|
5
5
|
import { isATag, isETag, isPTag, processTags } from "applesauce-core/helpers/tags";
|
|
6
|
-
export const FAVORITE_RELAYS_KIND = 10012;
|
|
7
6
|
/** Returns all the tags of a list or set */
|
|
8
7
|
export function getListTags(list, type) {
|
|
9
8
|
switch (type) {
|
|
9
|
+
default:
|
|
10
10
|
case "public":
|
|
11
11
|
return list.tags;
|
|
12
12
|
case "hidden":
|
|
13
13
|
return getHiddenTags(list) ?? [];
|
|
14
|
-
default:
|
|
15
14
|
case "all":
|
|
16
15
|
return [...(getHiddenTags(list) ?? []), ...list.tags];
|
|
17
16
|
}
|
|
@@ -91,7 +90,7 @@ export function getProfilePointersFromList(list, type) {
|
|
|
91
90
|
* @param type - Which types of tags to read
|
|
92
91
|
*/
|
|
93
92
|
export function getRelaysFromList(list, type) {
|
|
94
|
-
return
|
|
93
|
+
return relaySet(processTags(getListTags(list, type), (t) => (t[0] === "relay" ? t[1] : undefined)));
|
|
95
94
|
}
|
|
96
95
|
/** Returns if an event is a valid list or set */
|
|
97
96
|
export function isValidList(event) {
|
package/dist/helpers/mute.d.ts
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
1
|
+
import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { HiddenContentSigner } from "applesauce-core/helpers/hidden-content";
|
|
3
|
+
export type MuteListEvent = KnownEvent<typeof kinds.Mutelist>;
|
|
4
|
+
/** Validates that an event is a valid mute list */
|
|
5
|
+
export declare function isValidMuteList(event: NostrEvent): event is MuteListEvent;
|
|
3
6
|
export declare const MutePublicSymbol: unique symbol;
|
|
4
7
|
export declare const MuteHiddenSymbol: unique symbol;
|
|
5
8
|
/** Type for unlocked mute events */
|
|
6
9
|
export type UnlockedMutes = {
|
|
7
|
-
[MuteHiddenSymbol]:
|
|
10
|
+
[MuteHiddenSymbol]: MutedThings;
|
|
8
11
|
};
|
|
9
|
-
export type
|
|
12
|
+
export type MutedThings = {
|
|
10
13
|
pubkeys: Set<string>;
|
|
11
14
|
threads: Set<string>;
|
|
12
15
|
hashtags: Set<string>;
|
|
13
16
|
words: Set<string>;
|
|
14
17
|
};
|
|
15
18
|
/** Merges any number of mute sets */
|
|
16
|
-
export declare function mergeMutes(...mutes:
|
|
19
|
+
export declare function mergeMutes(...mutes: MutedThings[]): MutedThings;
|
|
17
20
|
/** Parses mute tags */
|
|
18
|
-
export declare function parseMutedTags(tags: string[][]):
|
|
21
|
+
export declare function parseMutedTags(tags: string[][]): MutedThings;
|
|
19
22
|
/** Returns muted things */
|
|
20
|
-
export declare function getMutedThings(mute: NostrEvent):
|
|
23
|
+
export declare function getMutedThings(mute: NostrEvent): MutedThings;
|
|
21
24
|
/** Returns only the public muted things from a mute event */
|
|
22
|
-
export declare function getPublicMutedThings(mute: NostrEvent):
|
|
25
|
+
export declare function getPublicMutedThings(mute: NostrEvent): MutedThings;
|
|
23
26
|
/** Checks if the hidden mutes are unlocked */
|
|
24
27
|
export declare function isHiddenMutesUnlocked<T extends NostrEvent>(mute: T): mute is T & UnlockedMutes;
|
|
25
28
|
/** Returns the hidden muted content if the event is unlocked */
|
|
26
|
-
export declare function getHiddenMutedThings<T extends NostrEvent & UnlockedMutes>(mute: T):
|
|
27
|
-
export declare function getHiddenMutedThings<T extends NostrEvent>(mute: T):
|
|
29
|
+
export declare function getHiddenMutedThings<T extends NostrEvent & UnlockedMutes>(mute: T): MutedThings;
|
|
30
|
+
export declare function getHiddenMutedThings<T extends NostrEvent>(mute: T): MutedThings | undefined;
|
|
28
31
|
/** Unlocks the hidden mutes */
|
|
29
|
-
export declare function unlockHiddenMutes(mute: NostrEvent, signer: HiddenContentSigner): Promise<
|
|
32
|
+
export declare function unlockHiddenMutes(mute: NostrEvent, signer: HiddenContentSigner): Promise<MutedThings>;
|
|
30
33
|
/** Creates a RegExp for matching muted words */
|
|
31
34
|
export declare function createMutedWordsRegExp(mutedWords: string[]): RegExp;
|
|
32
35
|
/** Returns true if the event matches the mutes */
|
|
33
|
-
export declare function matchMutes(mutes:
|
|
36
|
+
export declare function matchMutes(mutes: MutedThings, event: NostrEvent): boolean;
|
package/dist/helpers/mute.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
2
|
import { kinds, notifyEventUpdate } from "applesauce-core/helpers/event";
|
|
3
|
-
import { isETag, isPTag, isTTag } from "applesauce-core/helpers/tags";
|
|
4
3
|
import { getIndexableTags } from "applesauce-core/helpers/filter";
|
|
4
|
+
import { isETag, isPTag, isTTag } from "applesauce-core/helpers/tags";
|
|
5
5
|
import { getHiddenTags, isHiddenTagsUnlocked, unlockHiddenTags } from "applesauce-core/helpers/hidden-tags";
|
|
6
6
|
import { getNip10References } from "./threading.js";
|
|
7
|
+
/** Validates that an event is a valid mute list */
|
|
8
|
+
export function isValidMuteList(event) {
|
|
9
|
+
return event.kind === kinds.Mutelist;
|
|
10
|
+
}
|
|
7
11
|
export const MutePublicSymbol = Symbol.for("mute-public");
|
|
8
12
|
export const MuteHiddenSymbol = Symbol.for("mute-hidden");
|
|
9
13
|
/** Merges any number of mute sets */
|
|
@@ -43,10 +47,11 @@ export function getPublicMutedThings(mute) {
|
|
|
43
47
|
}
|
|
44
48
|
/** Checks if the hidden mutes are unlocked */
|
|
45
49
|
export function isHiddenMutesUnlocked(mute) {
|
|
46
|
-
|
|
50
|
+
// No need for try catch or proactivly parsing here since it only depends on hidden tags
|
|
51
|
+
return MuteHiddenSymbol in mute || isHiddenTagsUnlocked(mute);
|
|
47
52
|
}
|
|
48
53
|
export function getHiddenMutedThings(mute) {
|
|
49
|
-
if (
|
|
54
|
+
if (MuteHiddenSymbol in mute)
|
|
50
55
|
return mute[MuteHiddenSymbol];
|
|
51
56
|
// get hidden tags
|
|
52
57
|
const tags = getHiddenTags(mute);
|
|
@@ -60,7 +65,7 @@ export function getHiddenMutedThings(mute) {
|
|
|
60
65
|
}
|
|
61
66
|
/** Unlocks the hidden mutes */
|
|
62
67
|
export async function unlockHiddenMutes(mute, signer) {
|
|
63
|
-
if (
|
|
68
|
+
if (MuteHiddenSymbol in mute)
|
|
64
69
|
return mute[MuteHiddenSymbol];
|
|
65
70
|
// Unlock hidden tags
|
|
66
71
|
await unlockHiddenTags(mute, signer);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
export declare const FAVORITE_RELAYS_KIND = 10012;
|
|
3
|
+
export type FavoriteRelaysListEvent = KnownEvent<typeof FAVORITE_RELAYS_KIND>;
|
|
4
|
+
export type SearchRelaysListEvent = KnownEvent<typeof kinds.SearchRelaysList>;
|
|
5
|
+
export type BlockedRelaysListEvent = KnownEvent<typeof kinds.BlockedRelaysList>;
|
|
6
|
+
export type DMRelaysListEvent = KnownEvent<typeof kinds.DirectMessageRelaysList>;
|
|
7
|
+
/** Validates that an event is a valid favorite relays list (kind 10012) */
|
|
8
|
+
export declare function isValidFavoriteRelaysList(event: NostrEvent): event is FavoriteRelaysListEvent;
|
|
9
|
+
/** Validates that an event is a valid search relays list (kind 10007) */
|
|
10
|
+
export declare function isValidSearchRelaysList(event: NostrEvent): event is SearchRelaysListEvent;
|
|
11
|
+
/** Validates that an event is a valid blocked relays list (kind 10006) */
|
|
12
|
+
export declare function isValidBlockedRelaysList(event: NostrEvent): event is BlockedRelaysListEvent;
|
|
13
|
+
/** Validates that an event is a valid DM relays list (kind 10050) */
|
|
14
|
+
export declare function isValidDirectMessageRelaysList(event: NostrEvent): event is DMRelaysListEvent;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
2
|
+
export const FAVORITE_RELAYS_KIND = 10012;
|
|
3
|
+
/** Validates that an event is a valid favorite relays list (kind 10012) */
|
|
4
|
+
export function isValidFavoriteRelaysList(event) {
|
|
5
|
+
return event.kind === FAVORITE_RELAYS_KIND;
|
|
6
|
+
}
|
|
7
|
+
/** Validates that an event is a valid search relays list (kind 10007) */
|
|
8
|
+
export function isValidSearchRelaysList(event) {
|
|
9
|
+
return event.kind === kinds.SearchRelaysList;
|
|
10
|
+
}
|
|
11
|
+
/** Validates that an event is a valid blocked relays list (kind 10006) */
|
|
12
|
+
export function isValidBlockedRelaysList(event) {
|
|
13
|
+
return event.kind === kinds.BlockedRelaysList;
|
|
14
|
+
}
|
|
15
|
+
/** Validates that an event is a valid DM relays list (kind 10050) */
|
|
16
|
+
export function isValidDirectMessageRelaysList(event) {
|
|
17
|
+
return event.kind === kinds.DirectMessageRelaysList;
|
|
18
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
1
|
+
import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
export type StreamChatMessageEvent = KnownEvent<kinds.LiveChatMessage>;
|
|
4
|
+
export declare function isValidStreamChatMessage(event: NostrEvent): event is StreamChatMessageEvent;
|
|
3
5
|
/** Returns the pointer to the stream chat message stream */
|
|
6
|
+
export declare function getStreamChatMessageStream(message: StreamChatMessageEvent): AddressPointer;
|
|
4
7
|
export declare function getStreamChatMessageStream(message: NostrEvent): AddressPointer | undefined;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { kinds } from "applesauce-core/helpers/event";
|
|
1
2
|
import { getAddressPointerFromATag } from "applesauce-core/helpers/pointers";
|
|
2
3
|
import { isATag } from "applesauce-core/helpers/tags";
|
|
3
|
-
|
|
4
|
+
export function isValidStreamChatMessage(event) {
|
|
5
|
+
return event.kind === kinds.LiveChatMessage && getStreamChatMessageStream(event) !== undefined;
|
|
6
|
+
}
|
|
4
7
|
export function getStreamChatMessageStream(message) {
|
|
5
8
|
const tag = message.tags.find(isATag);
|
|
6
9
|
if (!tag)
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export * as Models from "./models/index.js";
|
|
|
3
3
|
export * as Operations from "./operations/index.js";
|
|
4
4
|
export * as Blueprints from "./blueprints/index.js";
|
|
5
5
|
export * as Observable from "./observable/index.js";
|
|
6
|
+
export * as Casts from "./casts/index.js";
|
|
6
7
|
import "./register.js";
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,6 @@ export * as Models from "./models/index.js";
|
|
|
3
3
|
export * as Operations from "./operations/index.js";
|
|
4
4
|
export * as Blueprints from "./blueprints/index.js";
|
|
5
5
|
export * as Observable from "./observable/index.js";
|
|
6
|
+
export * as Casts from "./casts/index.js";
|
|
6
7
|
// Register the common models and blueprints with the event store and event factory
|
|
7
8
|
import "./register.js";
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Model } from "applesauce-core/event-store";
|
|
2
|
-
import {
|
|
2
|
+
import { BookmarkPointer } from "../helpers/bookmark.js";
|
|
3
3
|
/** A model that returns all the bookmarks of a user */
|
|
4
|
-
export declare function UserBookmarkModel(pubkey: string): Model<
|
|
5
|
-
/** A model that returns all the public bookmarks of a user */
|
|
6
|
-
export declare function UserPublicBookmarkModel(pubkey: string): Model<Bookmarks | undefined>;
|
|
4
|
+
export declare function UserBookmarkModel(pubkey: string): Model<BookmarkPointer[] | undefined>;
|
|
7
5
|
/** A model that returns all the hidden bookmarks of a user */
|
|
8
|
-
export declare function UserHiddenBookmarkModel(pubkey: string): Model<
|
|
6
|
+
export declare function UserHiddenBookmarkModel(pubkey: string): Model<BookmarkPointer[] | null | undefined>;
|
package/dist/models/bookmarks.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { kinds } from "applesauce-core/helpers/event";
|
|
2
2
|
import { watchEventUpdates } from "applesauce-core/observable";
|
|
3
3
|
import { map } from "rxjs/operators";
|
|
4
|
-
import { getBookmarks, getHiddenBookmarks
|
|
4
|
+
import { getBookmarks, getHiddenBookmarks } from "../helpers/bookmark.js";
|
|
5
5
|
/** A model that returns all the bookmarks of a user */
|
|
6
6
|
export function UserBookmarkModel(pubkey) {
|
|
7
|
-
return (events) => events.replaceable(kinds.
|
|
8
|
-
// listen for event updates (hidden tags unlocked)
|
|
9
|
-
watchEventUpdates(events),
|
|
10
|
-
// Get all bookmarks
|
|
11
|
-
map((event) => event && getBookmarks(event)));
|
|
12
|
-
}
|
|
13
|
-
/** A model that returns all the public bookmarks of a user */
|
|
14
|
-
export function UserPublicBookmarkModel(pubkey) {
|
|
15
|
-
return (events) => events.replaceable(kinds.Mutelist, pubkey).pipe(map((event) => event && getPublicBookmarks(event)));
|
|
7
|
+
return (events) => events.replaceable(kinds.BookmarkList, pubkey).pipe(map((event) => event && getBookmarks(event)));
|
|
16
8
|
}
|
|
17
9
|
/** A model that returns all the hidden bookmarks of a user */
|
|
18
10
|
export function UserHiddenBookmarkModel(pubkey) {
|
package/dist/models/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export * from "./user-status.js";
|
|
|
12
12
|
export * from "./wrapped-messages.js";
|
|
13
13
|
export * from "./zaps.js";
|
|
14
14
|
export * from "./gift-wrap.js";
|
|
15
|
-
export * from "./
|
|
15
|
+
export * from "./relay-lists.js";
|
|
16
16
|
export * from "./stream.js";
|
|
17
|
+
export * from "./shares.js";
|
|
18
|
+
export * from "applesauce-core/models";
|
|
17
19
|
import "../register.js";
|
package/dist/models/index.js
CHANGED
|
@@ -12,7 +12,10 @@ export * from "./user-status.js";
|
|
|
12
12
|
export * from "./wrapped-messages.js";
|
|
13
13
|
export * from "./zaps.js";
|
|
14
14
|
export * from "./gift-wrap.js";
|
|
15
|
-
export * from "./
|
|
15
|
+
export * from "./relay-lists.js";
|
|
16
16
|
export * from "./stream.js";
|
|
17
|
+
export * from "./shares.js";
|
|
18
|
+
// Export all models from core
|
|
19
|
+
export * from "applesauce-core/models";
|
|
17
20
|
// Register the common models with the event store
|
|
18
21
|
import "../register.js";
|
package/dist/models/mutes.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Model } from "applesauce-core/event-store";
|
|
2
2
|
import { ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
3
3
|
import { type Observable } from "rxjs";
|
|
4
|
-
import {
|
|
4
|
+
import { MutedThings } from "../helpers/mute.js";
|
|
5
5
|
/** A model that returns all a users muted things */
|
|
6
|
-
export declare function MuteModel(user: string | ProfilePointer): Model<
|
|
6
|
+
export declare function MuteModel(user: string | ProfilePointer): Model<MutedThings | undefined>;
|
|
7
7
|
/** A model that returns all a users public muted things */
|
|
8
|
-
export declare function PublicMuteModel(pubkey: string): Model<
|
|
8
|
+
export declare function PublicMuteModel(pubkey: string): Model<MutedThings | undefined>;
|
|
9
9
|
/** A model that returns all a users hidden muted things */
|
|
10
|
-
export declare function HiddenMuteModel(pubkey: string): Model<
|
|
10
|
+
export declare function HiddenMuteModel(pubkey: string): Model<MutedThings | null | undefined>;
|
|
11
11
|
declare module "applesauce-core/event-store" {
|
|
12
12
|
interface EventModels {
|
|
13
13
|
/** Subscribe to a users mutes */
|
|
14
|
-
mutes(user: string | ProfilePointer): Observable<
|
|
14
|
+
mutes(user: string | ProfilePointer): Observable<MutedThings | undefined>;
|
|
15
15
|
}
|
|
16
16
|
}
|