applesauce-common 5.2.0 → 6.0.1
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 +40 -0
- package/dist/factories/note.js +74 -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,147 @@
|
|
|
1
|
+
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { setContent } from "applesauce-core/operations/content";
|
|
3
|
+
import { CREATE_GROUP_KIND, CREATE_INVITE_KIND, DELETE_EVENT_KIND, DELETE_GROUP_KIND, EDIT_METADATA_KIND, JOIN_REQUEST_KIND, LEAVE_REQUEST_KIND, PUT_USER_KIND, REMOVE_USER_KIND, } from "../helpers/groups.js";
|
|
4
|
+
import { addPreviousRefs, setDeleteEventTags, setEditMetadataTags, setGroupPointer, setJoinRequestTags, setLeaveRequestTags, setPutUserTags, setRemoveUserTags, } from "../operations/group.js";
|
|
5
|
+
// Join Request Factory
|
|
6
|
+
export class GroupJoinRequestFactory extends EventFactory {
|
|
7
|
+
static create(group, reason, inviteCode) {
|
|
8
|
+
const factory = new GroupJoinRequestFactory((res) => res(blankEventTemplate(JOIN_REQUEST_KIND)))
|
|
9
|
+
.group(group)
|
|
10
|
+
.joinRequest(group, inviteCode);
|
|
11
|
+
return reason ? factory.content(reason) : factory;
|
|
12
|
+
}
|
|
13
|
+
group(pointer) {
|
|
14
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
15
|
+
}
|
|
16
|
+
joinRequest(group, inviteCode) {
|
|
17
|
+
return this.chain((draft) => setJoinRequestTags(group, inviteCode)(draft));
|
|
18
|
+
}
|
|
19
|
+
/** Sets the reason for the join request */
|
|
20
|
+
reason(text) {
|
|
21
|
+
return this.chain((draft) => setContent(text)(draft));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Leave Request Factory
|
|
25
|
+
export class GroupLeaveRequestFactory extends EventFactory {
|
|
26
|
+
static create(group, reason) {
|
|
27
|
+
const factory = new GroupLeaveRequestFactory((res) => res(blankEventTemplate(LEAVE_REQUEST_KIND)))
|
|
28
|
+
.group(group)
|
|
29
|
+
.leaveRequest(group);
|
|
30
|
+
return reason ? factory.content(reason) : factory;
|
|
31
|
+
}
|
|
32
|
+
group(pointer) {
|
|
33
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
34
|
+
}
|
|
35
|
+
leaveRequest(group) {
|
|
36
|
+
return this.chain((draft) => setLeaveRequestTags(group)(draft));
|
|
37
|
+
}
|
|
38
|
+
/** Sets the reason for the leave request */
|
|
39
|
+
reason(text) {
|
|
40
|
+
return this.chain((draft) => setContent(text)(draft));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Put User Factory
|
|
44
|
+
export class PutUserFactory extends EventFactory {
|
|
45
|
+
static create(group, pubkey, roles) {
|
|
46
|
+
return new PutUserFactory((res) => res(blankEventTemplate(PUT_USER_KIND))).group(group).user(pubkey, roles);
|
|
47
|
+
}
|
|
48
|
+
group(pointer) {
|
|
49
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
50
|
+
}
|
|
51
|
+
user(pubkey, roles) {
|
|
52
|
+
return this.chain((draft) => setPutUserTags(pubkey, roles)(draft));
|
|
53
|
+
}
|
|
54
|
+
previous(events) {
|
|
55
|
+
return this.chain((draft) => addPreviousRefs(events)(draft));
|
|
56
|
+
}
|
|
57
|
+
reason(text) {
|
|
58
|
+
return this.chain((draft) => setContent(text)(draft));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Remove User Factory
|
|
62
|
+
export class RemoveUserFactory extends EventFactory {
|
|
63
|
+
static create(group, pubkey) {
|
|
64
|
+
return new RemoveUserFactory((res) => res(blankEventTemplate(REMOVE_USER_KIND))).group(group).user(pubkey);
|
|
65
|
+
}
|
|
66
|
+
group(pointer) {
|
|
67
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
68
|
+
}
|
|
69
|
+
user(pubkey) {
|
|
70
|
+
return this.chain((draft) => setRemoveUserTags(pubkey)(draft));
|
|
71
|
+
}
|
|
72
|
+
previous(events) {
|
|
73
|
+
return this.chain((draft) => addPreviousRefs(events)(draft));
|
|
74
|
+
}
|
|
75
|
+
reason(text) {
|
|
76
|
+
return this.chain((draft) => setContent(text)(draft));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Edit Metadata Factory
|
|
80
|
+
export class EditGroupMetadataFactory extends EventFactory {
|
|
81
|
+
static create(group, metadata) {
|
|
82
|
+
return new EditGroupMetadataFactory((res) => res(blankEventTemplate(EDIT_METADATA_KIND)))
|
|
83
|
+
.group(group)
|
|
84
|
+
.metadata(metadata);
|
|
85
|
+
}
|
|
86
|
+
group(pointer) {
|
|
87
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
88
|
+
}
|
|
89
|
+
metadata(metadata) {
|
|
90
|
+
return this.chain((draft) => setEditMetadataTags(metadata)(draft));
|
|
91
|
+
}
|
|
92
|
+
previous(events) {
|
|
93
|
+
return this.chain((draft) => addPreviousRefs(events)(draft));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Delete Event Factory
|
|
97
|
+
export class DeleteGroupEventFactory extends EventFactory {
|
|
98
|
+
static create(group, eventId) {
|
|
99
|
+
return new DeleteGroupEventFactory((res) => res(blankEventTemplate(DELETE_EVENT_KIND))).group(group).event(eventId);
|
|
100
|
+
}
|
|
101
|
+
group(pointer) {
|
|
102
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
103
|
+
}
|
|
104
|
+
/** Sets the event to delete — accepts an event ID string, a NostrEvent, or an EventPointer */
|
|
105
|
+
event(eventId) {
|
|
106
|
+
const id = typeof eventId === "string" ? eventId : eventId.id;
|
|
107
|
+
return this.chain((draft) => setDeleteEventTags(id)(draft));
|
|
108
|
+
}
|
|
109
|
+
previous(events) {
|
|
110
|
+
return this.chain((draft) => addPreviousRefs(events)(draft));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Create Group Factory
|
|
114
|
+
export class CreateGroupFactory extends EventFactory {
|
|
115
|
+
static create(groupId, metadata) {
|
|
116
|
+
return new CreateGroupFactory((res) => res(blankEventTemplate(CREATE_GROUP_KIND)))
|
|
117
|
+
.groupId(groupId)
|
|
118
|
+
.metadata(metadata);
|
|
119
|
+
}
|
|
120
|
+
groupId(id) {
|
|
121
|
+
return this.chain((draft) => setGroupPointer({ id, relay: "" })(draft));
|
|
122
|
+
}
|
|
123
|
+
metadata(metadata) {
|
|
124
|
+
return this.chain((draft) => setEditMetadataTags(metadata)(draft));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Delete Group Factory
|
|
128
|
+
export class DeleteGroupFactory extends EventFactory {
|
|
129
|
+
static create(group) {
|
|
130
|
+
return new DeleteGroupFactory((res) => res(blankEventTemplate(DELETE_GROUP_KIND))).group(group);
|
|
131
|
+
}
|
|
132
|
+
group(pointer) {
|
|
133
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
134
|
+
}
|
|
135
|
+
previous(events) {
|
|
136
|
+
return this.chain((draft) => addPreviousRefs(events)(draft));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Create Invite Factory
|
|
140
|
+
export class CreateGroupInviteFactory extends EventFactory {
|
|
141
|
+
static create(group) {
|
|
142
|
+
return new CreateGroupInviteFactory((res) => res(blankEventTemplate(CREATE_INVITE_KIND))).group(group);
|
|
143
|
+
}
|
|
144
|
+
group(pointer) {
|
|
145
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { TextContentOptions } from "applesauce-core/operations/content";
|
|
4
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
5
|
+
import { GROUP_MESSAGE_KIND, GROUP_THREAD_KIND, GroupPointer } from "../helpers/groups.js";
|
|
6
|
+
export type GroupMessageTemplate = KnownEventTemplate<typeof GROUP_MESSAGE_KIND>;
|
|
7
|
+
export type GroupThreadTemplate = KnownEventTemplate<typeof GROUP_THREAD_KIND>;
|
|
8
|
+
export declare class GroupMessageFactory extends EventFactory<typeof GROUP_MESSAGE_KIND, GroupMessageTemplate> {
|
|
9
|
+
static create(group: GroupPointer, content: string): GroupMessageFactory;
|
|
10
|
+
group(pointer: GroupPointer): this;
|
|
11
|
+
text(content: string, options?: TextContentOptions): this;
|
|
12
|
+
previous(events: NostrEvent[]): this;
|
|
13
|
+
/** Sets the "e" reply tag pointing to a parent group message */
|
|
14
|
+
replyTo(parent: NostrEvent): this;
|
|
15
|
+
meta(options: MetaTagOptions): this;
|
|
16
|
+
/** Creates a reply to a group message */
|
|
17
|
+
static reply(group: GroupPointer, parent: NostrEvent, content: string): GroupMessageFactory;
|
|
18
|
+
}
|
|
19
|
+
/** A factory class for building NIP-29 group thread events (kind 11) */
|
|
20
|
+
export declare class GroupThreadFactory extends EventFactory<typeof GROUP_THREAD_KIND, GroupThreadTemplate> {
|
|
21
|
+
/** Creates a new group thread event */
|
|
22
|
+
static create(group: GroupPointer, title: string, content: string): GroupThreadFactory;
|
|
23
|
+
/** Sets the NIP-29 group pointer "h" tag */
|
|
24
|
+
group(pointer: GroupPointer): this;
|
|
25
|
+
/** Sets the thread title */
|
|
26
|
+
title(title: string): this;
|
|
27
|
+
/** Sets the text content */
|
|
28
|
+
text(content: string, options?: TextContentOptions): this;
|
|
29
|
+
/** Adds a hashtag "t" tag to the thread */
|
|
30
|
+
addHashtag(hashtag: string): this;
|
|
31
|
+
/** Adds multiple hashtags as "t" tags */
|
|
32
|
+
hashtags(hashtags: string[]): this;
|
|
33
|
+
/** Sets meta tags */
|
|
34
|
+
meta(options: MetaTagOptions): this;
|
|
35
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { setShortTextContent } from "applesauce-core/operations/content";
|
|
3
|
+
import { setMetaTags } from "applesauce-core/operations/event";
|
|
4
|
+
import { includeNameValueTag, includeSingletonTag } from "applesauce-core/operations/tags";
|
|
5
|
+
import { GROUP_MESSAGE_KIND, GROUP_THREAD_KIND } from "../helpers/groups.js";
|
|
6
|
+
import { addPreviousRefs, setGroupPointer } from "../operations/group.js";
|
|
7
|
+
import { addHashtag, includeHashtags } from "../operations/hashtags.js";
|
|
8
|
+
export class GroupMessageFactory extends EventFactory {
|
|
9
|
+
static create(group, content) {
|
|
10
|
+
return new GroupMessageFactory((res) => res(blankEventTemplate(GROUP_MESSAGE_KIND))).group(group).text(content);
|
|
11
|
+
}
|
|
12
|
+
group(pointer) {
|
|
13
|
+
return this.chain((draft) => setGroupPointer(pointer)(draft));
|
|
14
|
+
}
|
|
15
|
+
text(content, options) {
|
|
16
|
+
return this.chain((draft) => setShortTextContent(content, options)(draft));
|
|
17
|
+
}
|
|
18
|
+
previous(events) {
|
|
19
|
+
return this.chain((draft) => addPreviousRefs(events)(draft));
|
|
20
|
+
}
|
|
21
|
+
/** Sets the "e" reply tag pointing to a parent group message */
|
|
22
|
+
replyTo(parent) {
|
|
23
|
+
return this.chain(includeNameValueTag(["e", parent.id]));
|
|
24
|
+
}
|
|
25
|
+
meta(options) {
|
|
26
|
+
return this.chain((draft) => setMetaTags(options)(draft));
|
|
27
|
+
}
|
|
28
|
+
/** Creates a reply to a group message */
|
|
29
|
+
static reply(group, parent, content) {
|
|
30
|
+
return new GroupMessageFactory((res) => res(blankEventTemplate(GROUP_MESSAGE_KIND)))
|
|
31
|
+
.group(group)
|
|
32
|
+
.replyTo(parent)
|
|
33
|
+
.text(content);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** A factory class for building NIP-29 group thread events (kind 11) */
|
|
37
|
+
export class GroupThreadFactory extends EventFactory {
|
|
38
|
+
/** Creates a new group thread event */
|
|
39
|
+
static create(group, title, content) {
|
|
40
|
+
return new GroupThreadFactory((res) => res(blankEventTemplate(GROUP_THREAD_KIND)))
|
|
41
|
+
.group(group)
|
|
42
|
+
.title(title)
|
|
43
|
+
.text(content);
|
|
44
|
+
}
|
|
45
|
+
/** Sets the NIP-29 group pointer "h" tag */
|
|
46
|
+
group(pointer) {
|
|
47
|
+
return this.chain(setGroupPointer(pointer));
|
|
48
|
+
}
|
|
49
|
+
/** Sets the thread title */
|
|
50
|
+
title(title) {
|
|
51
|
+
return this.chain(includeSingletonTag(["title", title]));
|
|
52
|
+
}
|
|
53
|
+
/** Sets the text content */
|
|
54
|
+
text(content, options) {
|
|
55
|
+
return this.chain(setShortTextContent(content, options));
|
|
56
|
+
}
|
|
57
|
+
/** Adds a hashtag "t" tag to the thread */
|
|
58
|
+
addHashtag(hashtag) {
|
|
59
|
+
return this.chain(addHashtag(hashtag));
|
|
60
|
+
}
|
|
61
|
+
/** Adds multiple hashtags as "t" tags */
|
|
62
|
+
hashtags(hashtags) {
|
|
63
|
+
return this.chain(includeHashtags(hashtags));
|
|
64
|
+
}
|
|
65
|
+
/** Sets meta tags */
|
|
66
|
+
meta(options) {
|
|
67
|
+
return this.chain(setMetaTags(options));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import { MetaTagOptions } from "applesauce-core/operations/event";
|
|
5
|
+
import { HighlightAttribution } from "../helpers/index.js";
|
|
6
|
+
import { ZapOptions } from "../operations/zap-split.js";
|
|
7
|
+
export type HighlightTemplate = KnownEventTemplate<kinds.Highlights>;
|
|
8
|
+
export type HighlightBlueprintOptions = MetaTagOptions & ZapOptions & {
|
|
9
|
+
context?: string;
|
|
10
|
+
comment?: string;
|
|
11
|
+
attributions?: HighlightAttribution[];
|
|
12
|
+
alt?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare class HighlightFactory extends EventFactory<kinds.Highlights, HighlightTemplate> {
|
|
15
|
+
/** Creates a new highlight factory from content and source */
|
|
16
|
+
static create(content: string, source: NostrEvent | AddressPointer | string, options?: HighlightBlueprintOptions): HighlightFactory;
|
|
17
|
+
/** Sets the content of the highlight */
|
|
18
|
+
highlight(content: string): this;
|
|
19
|
+
/** Sets the source event that was highlighted using an 'e' tag */
|
|
20
|
+
source(source: NostrEvent | AddressPointer | string): this;
|
|
21
|
+
/** Adds a single attribution for the highlight */
|
|
22
|
+
addAttribution(attribution: HighlightAttribution): this;
|
|
23
|
+
/** Sets multiple attributions at once for the highlight */
|
|
24
|
+
attributions(attrs: HighlightAttribution[]): this;
|
|
25
|
+
/** Sets the surrounding context for the highlight */
|
|
26
|
+
context(context: string): this;
|
|
27
|
+
/** Sets the comment for the highlight */
|
|
28
|
+
comment(comment: string): this;
|
|
29
|
+
/** Sets the zap split for the highlight */
|
|
30
|
+
zapSplit(options: ZapOptions): this;
|
|
31
|
+
/** Sets the meta tags for the highlight */
|
|
32
|
+
meta(options: MetaTagOptions): this;
|
|
33
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// highlight.ts
|
|
2
|
+
import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
|
|
3
|
+
import { kinds } from "applesauce-core/helpers";
|
|
4
|
+
import { setMetaTags } from "applesauce-core/operations/event";
|
|
5
|
+
import { addAttribution, setAttributions, setComment, setContext, setHighlightContent, setSource, } from "../operations/highlight.js";
|
|
6
|
+
import { setZapSplit } from "../operations/zap-split.js";
|
|
7
|
+
export class HighlightFactory extends EventFactory {
|
|
8
|
+
/** Creates a new highlight factory from content and source */
|
|
9
|
+
static create(content, source, options) {
|
|
10
|
+
let factory = new HighlightFactory((res) => res(blankEventTemplate(kinds.Highlights)))
|
|
11
|
+
.highlight(content)
|
|
12
|
+
.source(source);
|
|
13
|
+
if (options)
|
|
14
|
+
factory = factory.meta(options);
|
|
15
|
+
return factory;
|
|
16
|
+
}
|
|
17
|
+
/** Sets the content of the highlight */
|
|
18
|
+
highlight(content) {
|
|
19
|
+
return this.chain(setHighlightContent(content));
|
|
20
|
+
}
|
|
21
|
+
/** Sets the source event that was highlighted using an 'e' tag */
|
|
22
|
+
source(source) {
|
|
23
|
+
return this.chain(setSource(source));
|
|
24
|
+
}
|
|
25
|
+
/** Adds a single attribution for the highlight */
|
|
26
|
+
addAttribution(attribution) {
|
|
27
|
+
return this.chain(addAttribution(attribution));
|
|
28
|
+
}
|
|
29
|
+
/** Sets multiple attributions at once for the highlight */
|
|
30
|
+
attributions(attrs) {
|
|
31
|
+
return this.chain(setAttributions(attrs));
|
|
32
|
+
}
|
|
33
|
+
/** Sets the surrounding context for the highlight */
|
|
34
|
+
context(context) {
|
|
35
|
+
return this.chain(setContext(context));
|
|
36
|
+
}
|
|
37
|
+
/** Sets the comment for the highlight */
|
|
38
|
+
comment(comment) {
|
|
39
|
+
return this.chain(setComment(comment));
|
|
40
|
+
}
|
|
41
|
+
/** Sets the zap split for the highlight */
|
|
42
|
+
zapSplit(options) {
|
|
43
|
+
return this.chain(setZapSplit(options, undefined));
|
|
44
|
+
}
|
|
45
|
+
/** Sets the meta tags for the highlight */
|
|
46
|
+
meta(options) {
|
|
47
|
+
return this.chain(setMetaTags(options));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export * from "./note.js";
|
|
2
|
+
export * from "./reaction.js";
|
|
3
|
+
export * from "./comment.js";
|
|
4
|
+
export * from "./share.js";
|
|
5
|
+
export * from "./poll.js";
|
|
6
|
+
export * from "./poll-response.js";
|
|
7
|
+
export * from "./torrent.js";
|
|
8
|
+
export * from "./highlight.js";
|
|
9
|
+
export * from "./calendar.js";
|
|
10
|
+
export * from "./gift-wrap.js";
|
|
11
|
+
export * from "./group.js";
|
|
12
|
+
export * from "./group-management.js";
|
|
13
|
+
export * from "./legacy-message.js";
|
|
14
|
+
export * from "./wrapped-message.js";
|
|
15
|
+
export * from "./app-data.js";
|
|
16
|
+
export * from "./zap-goal.js";
|
|
17
|
+
export * from "./zap-request.js";
|
|
18
|
+
export * from "./zap.js";
|
|
19
|
+
export * from "./code-snippet.js";
|
|
20
|
+
export * from "./contacts.js";
|
|
21
|
+
export * from "./mute-list.js";
|
|
22
|
+
export * from "./pin-list.js";
|
|
23
|
+
export * from "./bookmark-list.js";
|
|
24
|
+
export * from "./bookmark-set.js";
|
|
25
|
+
export * from "./blocked-relays.js";
|
|
26
|
+
export * from "./search-relays.js";
|
|
27
|
+
export * from "./favorite-relays.js";
|
|
28
|
+
export * from "./dm-relays.js";
|
|
29
|
+
export * from "./blossom-server-list.js";
|
|
30
|
+
export * from "./follow-set.js";
|
|
31
|
+
export * from "./relay-set.js";
|
|
32
|
+
export * from "./list.js";
|
|
33
|
+
export * from "./stream-chat-message.js";
|
|
34
|
+
export * from "./calendar-event.js";
|
|
35
|
+
export * from "./live-stream.js";
|
|
36
|
+
export * from "./calendar-rsvp.js";
|
|
37
|
+
export * from "./file-metadata.js";
|
|
38
|
+
export * from "./picture-post.js";
|
|
39
|
+
export * from "./badge.js";
|
|
40
|
+
export * from "./badge-award.js";
|
|
41
|
+
export * from "./profile-badges.js";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export * from "./note.js";
|
|
2
|
+
export * from "./reaction.js";
|
|
3
|
+
export * from "./comment.js";
|
|
4
|
+
export * from "./share.js";
|
|
5
|
+
export * from "./poll.js";
|
|
6
|
+
export * from "./poll-response.js";
|
|
7
|
+
export * from "./torrent.js";
|
|
8
|
+
export * from "./highlight.js";
|
|
9
|
+
export * from "./calendar.js";
|
|
10
|
+
export * from "./gift-wrap.js";
|
|
11
|
+
export * from "./group.js";
|
|
12
|
+
export * from "./group-management.js";
|
|
13
|
+
export * from "./legacy-message.js";
|
|
14
|
+
export * from "./wrapped-message.js";
|
|
15
|
+
export * from "./app-data.js";
|
|
16
|
+
export * from "./zap-goal.js";
|
|
17
|
+
export * from "./zap-request.js";
|
|
18
|
+
export * from "./zap.js";
|
|
19
|
+
export * from "./code-snippet.js";
|
|
20
|
+
export * from "./contacts.js";
|
|
21
|
+
export * from "./mute-list.js";
|
|
22
|
+
export * from "./pin-list.js";
|
|
23
|
+
export * from "./bookmark-list.js";
|
|
24
|
+
export * from "./bookmark-set.js";
|
|
25
|
+
export * from "./blocked-relays.js";
|
|
26
|
+
export * from "./search-relays.js";
|
|
27
|
+
export * from "./favorite-relays.js";
|
|
28
|
+
export * from "./dm-relays.js";
|
|
29
|
+
export * from "./blossom-server-list.js";
|
|
30
|
+
export * from "./follow-set.js";
|
|
31
|
+
export * from "./relay-set.js";
|
|
32
|
+
export * from "./list.js";
|
|
33
|
+
export * from "./stream-chat-message.js";
|
|
34
|
+
export * from "./calendar-event.js";
|
|
35
|
+
export * from "./live-stream.js";
|
|
36
|
+
export * from "./calendar-rsvp.js";
|
|
37
|
+
export * from "./file-metadata.js";
|
|
38
|
+
export * from "./picture-post.js";
|
|
39
|
+
export * from "./badge.js";
|
|
40
|
+
export * from "./badge-award.js";
|
|
41
|
+
export * from "./profile-badges.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { kinds, KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
export type LegacyMessageTemplate = KnownEventTemplate<kinds.EncryptedDirectMessage>;
|
|
4
|
+
export type LegacyMessageBlueprintOptions = {};
|
|
5
|
+
export declare class LegacyMessageFactory extends EventFactory<kinds.EncryptedDirectMessage, LegacyMessageTemplate> {
|
|
6
|
+
static create(recipient: string, message: string): LegacyMessageFactory;
|
|
7
|
+
static reply(parent: NostrEvent, recipient: string, message: string): LegacyMessageFactory;
|
|
8
|
+
/** Sets the parent message "e" tag for NIP-04 reply threading */
|
|
9
|
+
replyTo(parent: NostrEvent | string): this;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventFactory, blankEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { kinds } from "applesauce-core/helpers";
|
|
3
|
+
import { setMessageParent } from "../operations/legacy-message.js";
|
|
4
|
+
export class LegacyMessageFactory extends EventFactory {
|
|
5
|
+
static create(recipient, message) {
|
|
6
|
+
return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage))).encryptedContent(recipient, message, "nip04");
|
|
7
|
+
}
|
|
8
|
+
static reply(parent, recipient, message) {
|
|
9
|
+
if (parent.kind !== kinds.EncryptedDirectMessage)
|
|
10
|
+
throw new Error("Parent must be a legacy message (kind 4)");
|
|
11
|
+
return new LegacyMessageFactory((res) => res(blankEventTemplate(kinds.EncryptedDirectMessage)))
|
|
12
|
+
.encryptedContent(recipient, message, "nip04")
|
|
13
|
+
.replyTo(parent);
|
|
14
|
+
}
|
|
15
|
+
/** Sets the parent message "e" tag for NIP-04 reply threading */
|
|
16
|
+
replyTo(parent) {
|
|
17
|
+
return this.chain(setMessageParent(parent));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EventFactory } from "applesauce-core/factories";
|
|
2
|
+
import { KnownEventTemplate, NostrEvent } from "applesauce-core/helpers";
|
|
3
|
+
import { AddressPointer, EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
4
|
+
/** A factory class for modifying any NIP-51 list event (kind-agnostic) */
|
|
5
|
+
export declare class ListFactory<K extends number = number, T extends KnownEventTemplate<K> = KnownEventTemplate<K>> extends EventFactory<K, T> {
|
|
6
|
+
/** Creates a new list factory from an existing list event */
|
|
7
|
+
static modify(event: NostrEvent): ListFactory;
|
|
8
|
+
/** Sets or removes the title of the list */
|
|
9
|
+
title(title: string | null): this;
|
|
10
|
+
/** Sets or removes the description of the list */
|
|
11
|
+
description(description: string | null): this;
|
|
12
|
+
/** Sets or removes the image of the list */
|
|
13
|
+
image(image: string | null): this;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A base factory class for NIP-51 lists that contain relay URLs.
|
|
17
|
+
* Provides `addRelay` and `removeRelay` methods in addition to `title`, `description`, and `image`.
|
|
18
|
+
*/
|
|
19
|
+
export declare class NIP51RelayListFactory<K extends number = number, T extends KnownEventTemplate<K> = KnownEventTemplate<K>> extends ListFactory<K, T> {
|
|
20
|
+
/** Adds a relay URL to the list's public tags */
|
|
21
|
+
addRelay(relay: string | string[], hidden?: boolean): this;
|
|
22
|
+
/** Removes a relay URL from the list */
|
|
23
|
+
removeRelay(relay: string | string[], hidden?: boolean): this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A base factory class for NIP-51 lists that contain user pubkeys (profile pointers).
|
|
27
|
+
* Provides `addUser` and `removeUser` methods in addition to `title`, `description`, and `image`.
|
|
28
|
+
*/
|
|
29
|
+
export declare class NIP51UserListFactory<K extends number = number, T extends KnownEventTemplate<K> = KnownEventTemplate<K>> extends ListFactory<K, T> {
|
|
30
|
+
/** Adds one or more pubkeys (or ProfilePointers) to the list */
|
|
31
|
+
addUser(pubkey: string | ProfilePointer | (string | ProfilePointer)[], hidden?: boolean): this;
|
|
32
|
+
/** Removes one or more pubkeys (or ProfilePointers) from the list */
|
|
33
|
+
removeUser(pubkey: string | ProfilePointer | (string | ProfilePointer)[], hidden?: boolean): this;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A base factory class for NIP-51 lists that contain event / address pointers.
|
|
37
|
+
* Provides `addItem` and `removeItem` methods in addition to `title`, `description`, and `image`.
|
|
38
|
+
*/
|
|
39
|
+
export declare class NIP51ItemListFactory<K extends number = number, T extends KnownEventTemplate<K> = KnownEventTemplate<K>> extends ListFactory<K, T> {
|
|
40
|
+
/** Adds an event (by id or EventPointer) to the list */
|
|
41
|
+
addEventItem(id: string | EventPointer | NostrEvent, hidden?: boolean): this;
|
|
42
|
+
/** Removes an event (by id or EventPointer) from the list */
|
|
43
|
+
removeEventItem(id: string | EventPointer, hidden?: boolean): this;
|
|
44
|
+
/** Adds an addressable event (by AddressPointer or NostrEvent) to the list */
|
|
45
|
+
addAddressItem(address: string | AddressPointer | NostrEvent, hidden?: boolean): this;
|
|
46
|
+
/** Removes an addressable event (by AddressPointer or NostrEvent) from the list */
|
|
47
|
+
removeAddressItem(address: string | AddressPointer | NostrEvent, hidden?: boolean): this;
|
|
48
|
+
/** Adds a URL "r" tag item to the list */
|
|
49
|
+
addUrlItem(url: string, hidden?: boolean): this;
|
|
50
|
+
/** Removes a URL "r" tag item from the list */
|
|
51
|
+
removeUrlItem(url: string, hidden?: boolean): this;
|
|
52
|
+
/** Adds a hashtag "t" tag item to the list */
|
|
53
|
+
addHashtagItem(hashtag: string, hidden?: boolean): this;
|
|
54
|
+
/** Removes a hashtag "t" tag item from the list */
|
|
55
|
+
removeHashtagItem(hashtag: string, hidden?: boolean): this;
|
|
56
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { EventFactory, toEventTemplate } from "applesauce-core/factories";
|
|
2
|
+
import { addAddressPointerTag, addEventPointerTag, addNameValueTag, addProfilePointerTag, removeAddressPointerTag, removeEventPointerTag, removeNameValueTag, removeProfilePointerTag, removeSingletonTag, setSingletonTag, } from "applesauce-core/operations/tag/common";
|
|
3
|
+
import { addRelayTag, removeRelayTag } from "applesauce-core/operations/tag/relay";
|
|
4
|
+
/** A factory class for modifying any NIP-51 list event (kind-agnostic) */
|
|
5
|
+
export class ListFactory extends EventFactory {
|
|
6
|
+
/** Creates a new list factory from an existing list event */
|
|
7
|
+
static modify(event) {
|
|
8
|
+
return new ListFactory((res) => res(toEventTemplate(event)));
|
|
9
|
+
}
|
|
10
|
+
/** Sets or removes the title of the list */
|
|
11
|
+
title(title) {
|
|
12
|
+
return title === null
|
|
13
|
+
? this.modifyPublicTags(removeSingletonTag("title"))
|
|
14
|
+
: this.modifyPublicTags(setSingletonTag(["title", title], true));
|
|
15
|
+
}
|
|
16
|
+
/** Sets or removes the description of the list */
|
|
17
|
+
description(description) {
|
|
18
|
+
return description === null
|
|
19
|
+
? this.modifyPublicTags(removeSingletonTag("description"))
|
|
20
|
+
: this.modifyPublicTags(setSingletonTag(["description", description], true));
|
|
21
|
+
}
|
|
22
|
+
/** Sets or removes the image of the list */
|
|
23
|
+
image(image) {
|
|
24
|
+
return image === null
|
|
25
|
+
? this.modifyPublicTags(removeSingletonTag("image"))
|
|
26
|
+
: this.modifyPublicTags(setSingletonTag(["image", image], true));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A base factory class for NIP-51 lists that contain relay URLs.
|
|
31
|
+
* Provides `addRelay` and `removeRelay` methods in addition to `title`, `description`, and `image`.
|
|
32
|
+
*/
|
|
33
|
+
export class NIP51RelayListFactory extends ListFactory {
|
|
34
|
+
/** Adds a relay URL to the list's public tags */
|
|
35
|
+
addRelay(relay, hidden = false) {
|
|
36
|
+
const relays = Array.isArray(relay) ? relay : [relay];
|
|
37
|
+
return hidden
|
|
38
|
+
? this.modifyHiddenTags(...relays.map((r) => addRelayTag(r)))
|
|
39
|
+
: this.modifyPublicTags(...relays.map((r) => addRelayTag(r)));
|
|
40
|
+
}
|
|
41
|
+
/** Removes a relay URL from the list */
|
|
42
|
+
removeRelay(relay, hidden = false) {
|
|
43
|
+
const relays = Array.isArray(relay) ? relay : [relay];
|
|
44
|
+
return hidden
|
|
45
|
+
? this.modifyHiddenTags(...relays.map((r) => removeRelayTag(r)))
|
|
46
|
+
: this.modifyPublicTags(...relays.map((r) => removeRelayTag(r)));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A base factory class for NIP-51 lists that contain user pubkeys (profile pointers).
|
|
51
|
+
* Provides `addUser` and `removeUser` methods in addition to `title`, `description`, and `image`.
|
|
52
|
+
*/
|
|
53
|
+
export class NIP51UserListFactory extends ListFactory {
|
|
54
|
+
/** Adds one or more pubkeys (or ProfilePointers) to the list */
|
|
55
|
+
addUser(pubkey, hidden = false) {
|
|
56
|
+
const pubkeys = Array.isArray(pubkey) ? pubkey : [pubkey];
|
|
57
|
+
return hidden
|
|
58
|
+
? this.modifyHiddenTags(...pubkeys.map((p) => addProfilePointerTag(p)))
|
|
59
|
+
: this.modifyPublicTags(...pubkeys.map((p) => addProfilePointerTag(p)));
|
|
60
|
+
}
|
|
61
|
+
/** Removes one or more pubkeys (or ProfilePointers) from the list */
|
|
62
|
+
removeUser(pubkey, hidden = false) {
|
|
63
|
+
const pubkeys = Array.isArray(pubkey) ? pubkey : [pubkey];
|
|
64
|
+
return hidden
|
|
65
|
+
? this.modifyHiddenTags(...pubkeys.map((p) => removeProfilePointerTag(p)))
|
|
66
|
+
: this.modifyPublicTags(...pubkeys.map((p) => removeProfilePointerTag(p)));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A base factory class for NIP-51 lists that contain event / address pointers.
|
|
71
|
+
* Provides `addItem` and `removeItem` methods in addition to `title`, `description`, and `image`.
|
|
72
|
+
*/
|
|
73
|
+
export class NIP51ItemListFactory extends ListFactory {
|
|
74
|
+
/** Adds an event (by id or EventPointer) to the list */
|
|
75
|
+
addEventItem(id, hidden = false) {
|
|
76
|
+
return hidden ? this.modifyHiddenTags(addEventPointerTag(id)) : this.modifyPublicTags(addEventPointerTag(id));
|
|
77
|
+
}
|
|
78
|
+
/** Removes an event (by id or EventPointer) from the list */
|
|
79
|
+
removeEventItem(id, hidden = false) {
|
|
80
|
+
return hidden ? this.modifyHiddenTags(removeEventPointerTag(id)) : this.modifyPublicTags(removeEventPointerTag(id));
|
|
81
|
+
}
|
|
82
|
+
/** Adds an addressable event (by AddressPointer or NostrEvent) to the list */
|
|
83
|
+
addAddressItem(address, hidden = false) {
|
|
84
|
+
return hidden
|
|
85
|
+
? this.modifyHiddenTags(addAddressPointerTag(address))
|
|
86
|
+
: this.modifyPublicTags(addAddressPointerTag(address));
|
|
87
|
+
}
|
|
88
|
+
/** Removes an addressable event (by AddressPointer or NostrEvent) from the list */
|
|
89
|
+
removeAddressItem(address, hidden = false) {
|
|
90
|
+
return hidden
|
|
91
|
+
? this.modifyHiddenTags(removeAddressPointerTag(address))
|
|
92
|
+
: this.modifyPublicTags(removeAddressPointerTag(address));
|
|
93
|
+
}
|
|
94
|
+
/** Adds a URL "r" tag item to the list */
|
|
95
|
+
addUrlItem(url, hidden = false) {
|
|
96
|
+
return hidden
|
|
97
|
+
? this.modifyHiddenTags(addNameValueTag(["r", url], true))
|
|
98
|
+
: this.modifyPublicTags(addNameValueTag(["r", url], true));
|
|
99
|
+
}
|
|
100
|
+
/** Removes a URL "r" tag item from the list */
|
|
101
|
+
removeUrlItem(url, hidden = false) {
|
|
102
|
+
return hidden
|
|
103
|
+
? this.modifyHiddenTags(removeNameValueTag(["r", url]))
|
|
104
|
+
: this.modifyPublicTags(removeNameValueTag(["r", url]));
|
|
105
|
+
}
|
|
106
|
+
/** Adds a hashtag "t" tag item to the list */
|
|
107
|
+
addHashtagItem(hashtag, hidden = false) {
|
|
108
|
+
const cleanTag = (hashtag.startsWith("#") ? hashtag.slice(1) : hashtag).toLocaleLowerCase();
|
|
109
|
+
return hidden
|
|
110
|
+
? this.modifyHiddenTags(addNameValueTag(["t", cleanTag], true))
|
|
111
|
+
: this.modifyPublicTags(addNameValueTag(["t", cleanTag], true));
|
|
112
|
+
}
|
|
113
|
+
/** Removes a hashtag "t" tag item from the list */
|
|
114
|
+
removeHashtagItem(hashtag, hidden = false) {
|
|
115
|
+
const cleanTag = (hashtag.startsWith("#") ? hashtag.slice(1) : hashtag).toLocaleLowerCase();
|
|
116
|
+
return hidden
|
|
117
|
+
? this.modifyHiddenTags(removeNameValueTag(["t", cleanTag]))
|
|
118
|
+
: this.modifyPublicTags(removeNameValueTag(["t", cleanTag]));
|
|
119
|
+
}
|
|
120
|
+
}
|