applesauce-common 0.0.0-next-20251209200210 → 0.0.0-next-20251231055351
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/README.md +45 -4
- package/dist/blueprints/__register__.d.ts +7 -0
- package/dist/blueprints/__register__.js +8 -0
- package/dist/blueprints/comment.d.ts +3 -2
- 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/blueprints/torrent.d.ts +7 -0
- package/dist/blueprints/torrent.js +5 -1
- package/dist/casts/article.d.ts +19 -0
- package/dist/casts/article.js +47 -0
- package/dist/casts/bookmarks.d.ts +35 -0
- package/dist/casts/bookmarks.js +91 -0
- package/dist/casts/cast.d.ts +30 -0
- package/dist/casts/cast.js +67 -0
- package/dist/casts/comment.d.ts +18 -0
- package/dist/casts/comment.js +54 -0
- package/dist/casts/groups.d.ts +19 -0
- package/dist/casts/groups.js +43 -0
- package/dist/casts/index.d.ts +18 -0
- package/dist/casts/index.js +18 -0
- package/dist/casts/mutes.d.ts +23 -0
- package/dist/casts/mutes.js +54 -0
- package/dist/casts/note.d.ts +25 -0
- package/dist/casts/note.js +76 -0
- package/dist/casts/profile.d.ts +24 -0
- package/dist/casts/profile.js +52 -0
- package/dist/casts/reaction.d.ts +17 -0
- package/dist/casts/reaction.js +46 -0
- package/dist/casts/relay-discovery.d.ts +29 -0
- package/dist/casts/relay-discovery.js +54 -0
- package/dist/casts/relay-lists.d.ts +33 -0
- package/dist/casts/relay-lists.js +72 -0
- package/dist/casts/relay-monitor.d.ts +21 -0
- package/dist/casts/relay-monitor.js +41 -0
- package/dist/casts/report.d.ts +31 -0
- package/dist/casts/report.js +74 -0
- package/dist/casts/share.d.ts +15 -0
- package/dist/casts/share.js +34 -0
- package/dist/casts/stream.d.ts +43 -0
- package/dist/casts/stream.js +116 -0
- package/dist/casts/torrent.d.ts +31 -0
- package/dist/casts/torrent.js +62 -0
- package/dist/casts/user.d.ts +40 -0
- package/dist/casts/user.js +181 -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/calendar-event.d.ts +7 -1
- package/dist/helpers/calendar-event.js +8 -10
- package/dist/helpers/channels.d.ts +1 -1
- package/dist/helpers/channels.js +5 -8
- package/dist/helpers/comment.d.ts +3 -1
- package/dist/helpers/comment.js +12 -2
- package/dist/helpers/encrypted-content-cache.js +23 -25
- package/dist/helpers/external-id.d.ts +32 -0
- package/dist/helpers/external-id.js +85 -0
- package/dist/helpers/file-metadata.d.ts +1 -4
- package/dist/helpers/file-metadata.js +1 -4
- package/dist/helpers/gift-wrap.js +11 -5
- package/dist/helpers/groups.d.ts +129 -7
- package/dist/helpers/groups.js +317 -15
- 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/reports.d.ts +4 -1
- package/dist/helpers/reports.js +14 -10
- 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/blossom.d.ts +2 -2
- package/dist/models/blossom.js +1 -1
- package/dist/models/bookmarks.d.ts +3 -5
- package/dist/models/bookmarks.js +2 -10
- package/dist/models/channels.js +3 -9
- package/dist/models/comments.d.ts +3 -2
- package/dist/models/comments.js +19 -1
- 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/comment.d.ts +3 -2
- package/dist/operations/comment.js +19 -5
- 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/operations/torrent.d.ts +2 -0
- package/dist/operations/torrent.js +4 -0
- 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.d.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
-
import {
|
|
2
|
+
import { HiddenContentSigner } from "applesauce-core/helpers/hidden-content";
|
|
3
3
|
export declare const GROUPS_LIST_KIND = 10009;
|
|
4
4
|
export declare const GROUP_MESSAGE_KIND = 9;
|
|
5
|
+
export declare const GROUP_METADATA_KIND = 39000;
|
|
6
|
+
export declare const GROUP_ADMINS_KIND = 39001;
|
|
7
|
+
export declare const GROUP_MEMBERS_KIND = 39002;
|
|
8
|
+
export declare const GROUP_ROLES_KIND = 39003;
|
|
9
|
+
export declare const JOIN_REQUEST_KIND = 9021;
|
|
10
|
+
export declare const LEAVE_REQUEST_KIND = 9022;
|
|
11
|
+
export declare const PUT_USER_KIND = 9000;
|
|
12
|
+
export declare const REMOVE_USER_KIND = 9001;
|
|
13
|
+
export declare const EDIT_METADATA_KIND = 9002;
|
|
14
|
+
export declare const DELETE_EVENT_KIND = 9005;
|
|
15
|
+
export declare const CREATE_GROUP_KIND = 9007;
|
|
16
|
+
export declare const DELETE_GROUP_KIND = 9008;
|
|
17
|
+
export declare const CREATE_INVITE_KIND = 9009;
|
|
5
18
|
/** NIP-29 group pointer */
|
|
6
19
|
export type GroupPointer = {
|
|
7
20
|
/** the id of the group */
|
|
@@ -18,16 +31,125 @@ export declare function encodeGroupPointer(pointer: GroupPointer): string;
|
|
|
18
31
|
export declare const GroupsPublicSymbol: unique symbol;
|
|
19
32
|
export declare const GroupsHiddenSymbol: unique symbol;
|
|
20
33
|
/** gets a {@link GroupPointer} from a "h" tag if it has a relay hint */
|
|
21
|
-
export declare function getGroupPointerFromHTag(tag: string[]): GroupPointer | undefined;
|
|
34
|
+
export declare function getGroupPointerFromHTag(tag: string[], hint?: string): GroupPointer | undefined;
|
|
22
35
|
/** gets a {@link GroupPointer} from a "group" tag */
|
|
23
36
|
export declare function getGroupPointerFromGroupTag(tag: string[]): GroupPointer;
|
|
24
37
|
/** Returns all the public groups from a k:10009 list */
|
|
25
38
|
export declare function getPublicGroups(bookmark: NostrEvent): GroupPointer[];
|
|
39
|
+
/** Type for unlocked groups */
|
|
40
|
+
export type UnlockedGroups = {
|
|
41
|
+
[GroupsHiddenSymbol]: GroupPointer[];
|
|
42
|
+
};
|
|
26
43
|
/** Returns all the hidden groups from a k:10009 list */
|
|
27
|
-
export declare function getHiddenGroups(bookmark:
|
|
44
|
+
export declare function getHiddenGroups<T extends NostrEvent & UnlockedGroups>(bookmark: T): GroupPointer[];
|
|
45
|
+
export declare function getHiddenGroups<T extends NostrEvent>(bookmark: T): GroupPointer[] | undefined;
|
|
46
|
+
/** Checks if the hidden groups are unlocked */
|
|
47
|
+
export declare function isHiddenGroupsUnlocked<T extends NostrEvent>(bookmark: T): bookmark is T & UnlockedGroups;
|
|
48
|
+
/** Unlocks the hidden groups on a groups event */
|
|
49
|
+
export declare function unlockHiddenGroups(bookmark: NostrEvent, signer: HiddenContentSigner): Promise<GroupPointer[]>;
|
|
50
|
+
/** Gets a {@link GroupPointer} from a group event by reading the "h" tag */
|
|
51
|
+
export declare function getGroupPointer(event: NostrEvent, relay?: string): GroupPointer | undefined;
|
|
52
|
+
/** Gets the group id from a group event by reading the "h" tag */
|
|
53
|
+
export declare function getGroupId(event: NostrEvent): string | undefined;
|
|
28
54
|
/** Gets a {@link GroupPointer} from a kind 39000 group metadata event */
|
|
29
55
|
export declare function getGroupPointerFromMetadata(event: NostrEvent, relay: string): GroupPointer | undefined;
|
|
30
|
-
/**
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
56
|
+
/** Group metadata structure from kind 39000 */
|
|
57
|
+
export type GroupMetadata = {
|
|
58
|
+
id: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
picture?: string;
|
|
61
|
+
about?: string;
|
|
62
|
+
isPublic: boolean;
|
|
63
|
+
isPrivate: boolean;
|
|
64
|
+
isOpen: boolean;
|
|
65
|
+
isClosed: boolean;
|
|
66
|
+
};
|
|
67
|
+
/** Group admin with roles from kind 39001 */
|
|
68
|
+
export type GroupAdmin = {
|
|
69
|
+
pubkey: string;
|
|
70
|
+
roles: string[];
|
|
71
|
+
};
|
|
72
|
+
/** Group role definition from kind 39003 */
|
|
73
|
+
export type GroupRole = {
|
|
74
|
+
name: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
};
|
|
77
|
+
/** Join request event information (kind 9021) */
|
|
78
|
+
export type GroupJoinRequestInfo = {
|
|
79
|
+
groupId: string;
|
|
80
|
+
reason?: string;
|
|
81
|
+
inviteCode?: string;
|
|
82
|
+
};
|
|
83
|
+
/** Leave request event information (kind 9022) */
|
|
84
|
+
export type GroupLeaveRequestInfo = {
|
|
85
|
+
groupId: string;
|
|
86
|
+
reason?: string;
|
|
87
|
+
};
|
|
88
|
+
/** Put user event information (kind 9000) */
|
|
89
|
+
export type GroupPutUserInfo = {
|
|
90
|
+
groupId: string;
|
|
91
|
+
pubkey: string;
|
|
92
|
+
roles?: string[];
|
|
93
|
+
reason?: string;
|
|
94
|
+
};
|
|
95
|
+
/** Remove user event information (kind 9001) */
|
|
96
|
+
export type GroupRemoveUserInfo = {
|
|
97
|
+
groupId: string;
|
|
98
|
+
pubkey: string;
|
|
99
|
+
reason?: string;
|
|
100
|
+
};
|
|
101
|
+
/** Edit metadata event information (kind 9002) */
|
|
102
|
+
export type GroupEditMetadataInfo = {
|
|
103
|
+
groupId: string;
|
|
104
|
+
metadataFields: Partial<GroupMetadata>;
|
|
105
|
+
reason?: string;
|
|
106
|
+
};
|
|
107
|
+
/** Delete event information (kind 9005) */
|
|
108
|
+
export type GroupDeleteEventInfo = {
|
|
109
|
+
groupId: string;
|
|
110
|
+
eventId: string;
|
|
111
|
+
reason?: string;
|
|
112
|
+
};
|
|
113
|
+
/** Create group event information (kind 9007) */
|
|
114
|
+
export type GroupCreateGroupInfo = {
|
|
115
|
+
groupId: string;
|
|
116
|
+
reason?: string;
|
|
117
|
+
};
|
|
118
|
+
/** Delete group event information (kind 9008) */
|
|
119
|
+
export type GroupDeleteGroupInfo = {
|
|
120
|
+
groupId: string;
|
|
121
|
+
reason?: string;
|
|
122
|
+
};
|
|
123
|
+
/** Create invite event information (kind 9009) */
|
|
124
|
+
export type GroupCreateInviteInfo = {
|
|
125
|
+
groupId: string;
|
|
126
|
+
reason?: string;
|
|
127
|
+
};
|
|
128
|
+
/** Gets group metadata from a kind 39000 event */
|
|
129
|
+
export declare function getGroupMetadata(event: NostrEvent): GroupMetadata | undefined;
|
|
130
|
+
/** Gets group admins from a kind 39001 event */
|
|
131
|
+
export declare function getGroupAdmins(event: NostrEvent): GroupAdmin[] | undefined;
|
|
132
|
+
/** Gets group members from a kind 39002 event */
|
|
133
|
+
export declare function getGroupMembers(event: NostrEvent): string[] | undefined;
|
|
134
|
+
/** Gets group roles from a kind 39003 event */
|
|
135
|
+
export declare function getGroupRoles(event: NostrEvent): GroupRole[] | undefined;
|
|
136
|
+
/** Gets join request information from a kind 9021 event */
|
|
137
|
+
export declare function getGroupJoinRequestInfo(event: NostrEvent): GroupJoinRequestInfo | undefined;
|
|
138
|
+
/** Gets leave request information from a kind 9022 event */
|
|
139
|
+
export declare function getGroupLeaveRequestInfo(event: NostrEvent): GroupLeaveRequestInfo | undefined;
|
|
140
|
+
/** Gets put user event information from a kind 9000 event */
|
|
141
|
+
export declare function getGroupPutUserInfo(event: NostrEvent): GroupPutUserInfo | undefined;
|
|
142
|
+
/** Gets remove user event information from a kind 9001 event */
|
|
143
|
+
export declare function getGroupRemoveUserInfo(event: NostrEvent): GroupRemoveUserInfo | undefined;
|
|
144
|
+
/** Gets edit metadata event information from a kind 9002 event */
|
|
145
|
+
export declare function getGroupEditMetadataInfo(event: NostrEvent): GroupEditMetadataInfo | undefined;
|
|
146
|
+
/** Gets delete event information from a kind 9005 event */
|
|
147
|
+
export declare function getGroupDeleteEventInfo(event: NostrEvent): GroupDeleteEventInfo | undefined;
|
|
148
|
+
/** Gets create group event information from a kind 9007 event */
|
|
149
|
+
export declare function getGroupCreateGroupInfo(event: NostrEvent): GroupCreateGroupInfo | undefined;
|
|
150
|
+
/** Gets delete group event information from a kind 9008 event */
|
|
151
|
+
export declare function getGroupDeleteGroupInfo(event: NostrEvent): GroupDeleteGroupInfo | undefined;
|
|
152
|
+
/** Gets create invite event information from a kind 9009 event */
|
|
153
|
+
export declare function getGroupCreateInviteInfo(event: NostrEvent): GroupCreateInviteInfo | undefined;
|
|
154
|
+
/** Checks group membership status from kind 9000/9001 events */
|
|
155
|
+
export declare function checkGroupMembership(events: NostrEvent[], pubkey: string): boolean | undefined;
|
package/dist/helpers/groups.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
import { getOrComputeCachedValue } from "applesauce-core/helpers
|
|
1
|
+
import { getOrComputeCachedValue, notifyEventUpdate } from "applesauce-core/helpers";
|
|
2
2
|
import { getReplaceableIdentifier, getTagValue } from "applesauce-core/helpers/event";
|
|
3
|
-
import { getHiddenTags } from "applesauce-core/helpers/hidden-tags";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { getHiddenTags, isHiddenTagsUnlocked, unlockHiddenTags } from "applesauce-core/helpers/hidden-tags";
|
|
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 };
|
|
@@ -40,14 +56,53 @@ export function getGroupPointerFromGroupTag(tag) {
|
|
|
40
56
|
export function getPublicGroups(bookmark) {
|
|
41
57
|
return getOrComputeCachedValue(bookmark, GroupsPublicSymbol, () => processTags(bookmark.tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag));
|
|
42
58
|
}
|
|
43
|
-
/** Returns all the hidden groups from a k:10009 list */
|
|
44
59
|
export function getHiddenGroups(bookmark) {
|
|
60
|
+
if (GroupsHiddenSymbol in bookmark)
|
|
61
|
+
return bookmark[GroupsHiddenSymbol];
|
|
45
62
|
return getOrComputeCachedValue(bookmark, GroupsHiddenSymbol, () => {
|
|
63
|
+
//get hidden tags
|
|
46
64
|
const tags = getHiddenTags(bookmark);
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
if (!tags)
|
|
66
|
+
return undefined;
|
|
67
|
+
// parse groups from hidden tags
|
|
68
|
+
const groups = processTags(tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag);
|
|
69
|
+
// set cached value
|
|
70
|
+
Reflect.set(bookmark, GroupsHiddenSymbol, groups);
|
|
71
|
+
return groups;
|
|
49
72
|
});
|
|
50
73
|
}
|
|
74
|
+
/** Checks if the hidden groups are unlocked */
|
|
75
|
+
export function isHiddenGroupsUnlocked(bookmark) {
|
|
76
|
+
return isHiddenTagsUnlocked(bookmark) && (GroupsHiddenSymbol in bookmark || getHiddenGroups(bookmark) !== undefined);
|
|
77
|
+
}
|
|
78
|
+
/** Unlocks the hidden groups on a groups event */
|
|
79
|
+
export async function unlockHiddenGroups(bookmark, signer) {
|
|
80
|
+
if (isHiddenGroupsUnlocked(bookmark))
|
|
81
|
+
return bookmark[GroupsHiddenSymbol];
|
|
82
|
+
// unlock hidden tags
|
|
83
|
+
await unlockHiddenTags(bookmark, signer);
|
|
84
|
+
// get hidden groups
|
|
85
|
+
const groups = getHiddenGroups(bookmark);
|
|
86
|
+
if (!groups)
|
|
87
|
+
throw new Error("Failed to unlock hidden groups");
|
|
88
|
+
// notify event store
|
|
89
|
+
notifyEventUpdate(bookmark);
|
|
90
|
+
return groups;
|
|
91
|
+
}
|
|
92
|
+
/** Gets a {@link GroupPointer} from a group event by reading the "h" tag */
|
|
93
|
+
export function getGroupPointer(event, relay) {
|
|
94
|
+
const hTag = event.tags.find((t) => t[0] === "h");
|
|
95
|
+
if (!hTag)
|
|
96
|
+
return undefined;
|
|
97
|
+
return getGroupPointerFromHTag(hTag, relay);
|
|
98
|
+
}
|
|
99
|
+
/** Gets the group id from a group event by reading the "h" tag */
|
|
100
|
+
export function getGroupId(event) {
|
|
101
|
+
const hTag = event.tags.find((t) => t[0] === "h");
|
|
102
|
+
if (!hTag)
|
|
103
|
+
return undefined;
|
|
104
|
+
return hTag[1];
|
|
105
|
+
}
|
|
51
106
|
/** Gets a {@link GroupPointer} from a kind 39000 group metadata event */
|
|
52
107
|
export function getGroupPointerFromMetadata(event, relay) {
|
|
53
108
|
// Use the "d" tag for the group ID and the provided relay
|
|
@@ -59,11 +114,258 @@ export function getGroupPointerFromMetadata(event, relay) {
|
|
|
59
114
|
name: name,
|
|
60
115
|
};
|
|
61
116
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
117
|
+
// Symbols for caching parsed data
|
|
118
|
+
const GroupMetadataSymbol = Symbol.for("group-metadata");
|
|
119
|
+
const GroupAdminsSymbol = Symbol.for("group-admins");
|
|
120
|
+
const GroupMembersSymbol = Symbol.for("group-members");
|
|
121
|
+
const GroupRolesSymbol = Symbol.for("group-roles");
|
|
122
|
+
const JoinRequestSymbol = Symbol.for("join-request");
|
|
123
|
+
const LeaveRequestSymbol = Symbol.for("leave-request");
|
|
124
|
+
const PutUserSymbol = Symbol.for("put-user");
|
|
125
|
+
const RemoveUserSymbol = Symbol.for("remove-user");
|
|
126
|
+
const EditMetadataSymbol = Symbol.for("edit-metadata");
|
|
127
|
+
const DeleteEventSymbol = Symbol.for("delete-event");
|
|
128
|
+
const CreateGroupSymbol = Symbol.for("create-group");
|
|
129
|
+
const DeleteGroupSymbol = Symbol.for("delete-group");
|
|
130
|
+
const CreateInviteSymbol = Symbol.for("create-invite");
|
|
131
|
+
/** Gets group metadata from a kind 39000 event */
|
|
132
|
+
export function getGroupMetadata(event) {
|
|
133
|
+
if (event.kind !== GROUP_METADATA_KIND)
|
|
134
|
+
return undefined;
|
|
135
|
+
return getOrComputeCachedValue(event, GroupMetadataSymbol, () => {
|
|
136
|
+
const id = getReplaceableIdentifier(event) || "_";
|
|
137
|
+
const name = getTagValue(event, "name");
|
|
138
|
+
const picture = getTagValue(event, "picture");
|
|
139
|
+
const about = getTagValue(event, "about");
|
|
140
|
+
const publicTag = event.tags.find((t) => t[0] === "public");
|
|
141
|
+
const privateTag = event.tags.find((t) => t[0] === "private");
|
|
142
|
+
const openTag = event.tags.find((t) => t[0] === "open");
|
|
143
|
+
const closedTag = event.tags.find((t) => t[0] === "closed");
|
|
144
|
+
return {
|
|
145
|
+
id,
|
|
146
|
+
name,
|
|
147
|
+
picture,
|
|
148
|
+
about,
|
|
149
|
+
isPublic: !!publicTag,
|
|
150
|
+
isPrivate: !!privateTag,
|
|
151
|
+
isOpen: !!openTag,
|
|
152
|
+
isClosed: !!closedTag,
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** Gets group admins from a kind 39001 event */
|
|
157
|
+
export function getGroupAdmins(event) {
|
|
158
|
+
if (event.kind !== GROUP_ADMINS_KIND)
|
|
159
|
+
return undefined;
|
|
160
|
+
return getOrComputeCachedValue(event, GroupAdminsSymbol, () => {
|
|
161
|
+
const adminsMap = new Map();
|
|
162
|
+
for (const tag of event.tags) {
|
|
163
|
+
if (tag[0] === "p" && tag[1]) {
|
|
164
|
+
const pubkey = tag[1];
|
|
165
|
+
const roles = tag.slice(2).filter((r) => r.length > 0);
|
|
166
|
+
if (adminsMap.has(pubkey)) {
|
|
167
|
+
const existingRoles = adminsMap.get(pubkey);
|
|
168
|
+
adminsMap.set(pubkey, [...new Set([...existingRoles, ...roles])]);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
adminsMap.set(pubkey, roles);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return Array.from(adminsMap.entries()).map(([pubkey, roles]) => ({
|
|
176
|
+
pubkey,
|
|
177
|
+
roles,
|
|
178
|
+
}));
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/** Gets group members from a kind 39002 event */
|
|
182
|
+
export function getGroupMembers(event) {
|
|
183
|
+
if (event.kind !== GROUP_MEMBERS_KIND)
|
|
184
|
+
return undefined;
|
|
185
|
+
return getOrComputeCachedValue(event, GroupMembersSymbol, () => {
|
|
186
|
+
return event.tags.filter((t) => t[0] === "p" && t[1]).map((t) => t[1]);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/** Gets group roles from a kind 39003 event */
|
|
190
|
+
export function getGroupRoles(event) {
|
|
191
|
+
if (event.kind !== GROUP_ROLES_KIND)
|
|
192
|
+
return undefined;
|
|
193
|
+
return getOrComputeCachedValue(event, GroupRolesSymbol, () => {
|
|
194
|
+
return event.tags
|
|
195
|
+
.filter((t) => t[0] === "role" && t[1])
|
|
196
|
+
.map((t) => ({
|
|
197
|
+
name: t[1],
|
|
198
|
+
description: t[2],
|
|
199
|
+
}));
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/** Gets join request information from a kind 9021 event */
|
|
203
|
+
export function getGroupJoinRequestInfo(event) {
|
|
204
|
+
if (event.kind !== JOIN_REQUEST_KIND)
|
|
205
|
+
return undefined;
|
|
206
|
+
return getOrComputeCachedValue(event, JoinRequestSymbol, () => {
|
|
207
|
+
const groupId = getGroupId(event);
|
|
208
|
+
if (!groupId)
|
|
209
|
+
return undefined;
|
|
210
|
+
return {
|
|
211
|
+
groupId,
|
|
212
|
+
reason: event.content || undefined,
|
|
213
|
+
inviteCode: getTagValue(event, "code"),
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/** Gets leave request information from a kind 9022 event */
|
|
218
|
+
export function getGroupLeaveRequestInfo(event) {
|
|
219
|
+
if (event.kind !== LEAVE_REQUEST_KIND)
|
|
220
|
+
return undefined;
|
|
221
|
+
return getOrComputeCachedValue(event, LeaveRequestSymbol, () => {
|
|
222
|
+
const groupId = getGroupId(event);
|
|
223
|
+
if (!groupId)
|
|
224
|
+
return undefined;
|
|
225
|
+
return {
|
|
226
|
+
groupId,
|
|
227
|
+
reason: event.content || undefined,
|
|
228
|
+
};
|
|
229
|
+
});
|
|
65
230
|
}
|
|
66
|
-
/**
|
|
67
|
-
export function
|
|
68
|
-
|
|
231
|
+
/** Gets put user event information from a kind 9000 event */
|
|
232
|
+
export function getGroupPutUserInfo(event) {
|
|
233
|
+
if (event.kind !== PUT_USER_KIND)
|
|
234
|
+
return undefined;
|
|
235
|
+
return getOrComputeCachedValue(event, PutUserSymbol, () => {
|
|
236
|
+
const groupId = getGroupId(event);
|
|
237
|
+
const pubkey = getTagValue(event, "p");
|
|
238
|
+
if (!groupId || !pubkey)
|
|
239
|
+
return undefined;
|
|
240
|
+
const roles = event.tags.filter((t) => t[0] === "p" && t.length > 2).flatMap((t) => t.slice(2));
|
|
241
|
+
return {
|
|
242
|
+
groupId,
|
|
243
|
+
pubkey,
|
|
244
|
+
roles: roles.length > 0 ? roles : undefined,
|
|
245
|
+
reason: event.content || undefined,
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/** Gets remove user event information from a kind 9001 event */
|
|
250
|
+
export function getGroupRemoveUserInfo(event) {
|
|
251
|
+
if (event.kind !== REMOVE_USER_KIND)
|
|
252
|
+
return undefined;
|
|
253
|
+
return getOrComputeCachedValue(event, RemoveUserSymbol, () => {
|
|
254
|
+
const groupId = getGroupId(event);
|
|
255
|
+
const pubkey = getTagValue(event, "p");
|
|
256
|
+
if (!groupId || !pubkey)
|
|
257
|
+
return undefined;
|
|
258
|
+
return {
|
|
259
|
+
groupId,
|
|
260
|
+
pubkey,
|
|
261
|
+
reason: event.content || undefined,
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/** Gets edit metadata event information from a kind 9002 event */
|
|
266
|
+
export function getGroupEditMetadataInfo(event) {
|
|
267
|
+
if (event.kind !== EDIT_METADATA_KIND)
|
|
268
|
+
return undefined;
|
|
269
|
+
return getOrComputeCachedValue(event, EditMetadataSymbol, () => {
|
|
270
|
+
const groupId = getGroupId(event);
|
|
271
|
+
if (!groupId)
|
|
272
|
+
return undefined;
|
|
273
|
+
const metadataFields = {};
|
|
274
|
+
const name = getTagValue(event, "name");
|
|
275
|
+
const picture = getTagValue(event, "picture");
|
|
276
|
+
const about = getTagValue(event, "about");
|
|
277
|
+
const publicTag = event.tags.find((t) => t[0] === "public");
|
|
278
|
+
const privateTag = event.tags.find((t) => t[0] === "private");
|
|
279
|
+
const openTag = event.tags.find((t) => t[0] === "open");
|
|
280
|
+
const closedTag = event.tags.find((t) => t[0] === "closed");
|
|
281
|
+
if (name !== undefined)
|
|
282
|
+
metadataFields.name = name;
|
|
283
|
+
if (picture !== undefined)
|
|
284
|
+
metadataFields.picture = picture;
|
|
285
|
+
if (about !== undefined)
|
|
286
|
+
metadataFields.about = about;
|
|
287
|
+
if (publicTag)
|
|
288
|
+
metadataFields.isPublic = true;
|
|
289
|
+
if (privateTag)
|
|
290
|
+
metadataFields.isPrivate = true;
|
|
291
|
+
if (openTag)
|
|
292
|
+
metadataFields.isOpen = true;
|
|
293
|
+
if (closedTag)
|
|
294
|
+
metadataFields.isClosed = true;
|
|
295
|
+
return {
|
|
296
|
+
groupId,
|
|
297
|
+
metadataFields,
|
|
298
|
+
reason: event.content || undefined,
|
|
299
|
+
};
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
/** Gets delete event information from a kind 9005 event */
|
|
303
|
+
export function getGroupDeleteEventInfo(event) {
|
|
304
|
+
if (event.kind !== DELETE_EVENT_KIND)
|
|
305
|
+
return undefined;
|
|
306
|
+
return getOrComputeCachedValue(event, DeleteEventSymbol, () => {
|
|
307
|
+
const groupId = getGroupId(event);
|
|
308
|
+
const eventId = getTagValue(event, "e");
|
|
309
|
+
if (!groupId || !eventId)
|
|
310
|
+
return undefined;
|
|
311
|
+
return {
|
|
312
|
+
groupId,
|
|
313
|
+
eventId,
|
|
314
|
+
reason: event.content || undefined,
|
|
315
|
+
};
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/** Gets create group event information from a kind 9007 event */
|
|
319
|
+
export function getGroupCreateGroupInfo(event) {
|
|
320
|
+
if (event.kind !== CREATE_GROUP_KIND)
|
|
321
|
+
return undefined;
|
|
322
|
+
return getOrComputeCachedValue(event, CreateGroupSymbol, () => {
|
|
323
|
+
const groupId = getGroupId(event);
|
|
324
|
+
if (!groupId)
|
|
325
|
+
return undefined;
|
|
326
|
+
return {
|
|
327
|
+
groupId,
|
|
328
|
+
reason: event.content || undefined,
|
|
329
|
+
};
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/** Gets delete group event information from a kind 9008 event */
|
|
333
|
+
export function getGroupDeleteGroupInfo(event) {
|
|
334
|
+
if (event.kind !== DELETE_GROUP_KIND)
|
|
335
|
+
return undefined;
|
|
336
|
+
return getOrComputeCachedValue(event, DeleteGroupSymbol, () => {
|
|
337
|
+
const groupId = getGroupId(event);
|
|
338
|
+
if (!groupId)
|
|
339
|
+
return undefined;
|
|
340
|
+
return {
|
|
341
|
+
groupId,
|
|
342
|
+
reason: event.content || undefined,
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
/** Gets create invite event information from a kind 9009 event */
|
|
347
|
+
export function getGroupCreateInviteInfo(event) {
|
|
348
|
+
if (event.kind !== CREATE_INVITE_KIND)
|
|
349
|
+
return undefined;
|
|
350
|
+
return getOrComputeCachedValue(event, CreateInviteSymbol, () => {
|
|
351
|
+
const groupId = getGroupId(event);
|
|
352
|
+
if (!groupId)
|
|
353
|
+
return undefined;
|
|
354
|
+
return {
|
|
355
|
+
groupId,
|
|
356
|
+
reason: event.content || undefined,
|
|
357
|
+
};
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
/** Checks group membership status from kind 9000/9001 events */
|
|
361
|
+
export function checkGroupMembership(events, pubkey) {
|
|
362
|
+
// Filter to only membership-related events
|
|
363
|
+
const membershipEvents = events.filter((e) => (e.kind === PUT_USER_KIND || e.kind === REMOVE_USER_KIND) && getTagValue(e, "p") === pubkey);
|
|
364
|
+
if (membershipEvents.length === 0)
|
|
365
|
+
return undefined;
|
|
366
|
+
// Sort by created_at descending to get the latest event
|
|
367
|
+
const sorted = membershipEvents.sort((a, b) => b.created_at - a.created_at);
|
|
368
|
+
const latest = sorted[0];
|
|
369
|
+
// Latest event determines membership status
|
|
370
|
+
return latest.kind === PUT_USER_KIND;
|
|
69
371
|
}
|
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);
|