@openpeepshq/common 0.1.45 → 0.1.46
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/lib/capabilitiesHelpers.d.ts +9 -7
- package/dist/lib/capabilitiesHelpers.js +17 -2
- package/dist/lib/eventIcs.d.ts +17 -0
- package/dist/lib/eventIcs.js +82 -0
- package/dist/lib/eventRecurrence.d.ts +2 -0
- package/dist/lib/eventRecurrence.js +9 -4
- package/dist/lib/eventTime.d.ts +7 -0
- package/dist/lib/eventTime.js +16 -0
- package/dist/lib/federationHosts.d.ts +3 -0
- package/dist/lib/federationHosts.js +17 -0
- package/dist/lib/feedCursor.d.ts +14 -0
- package/dist/lib/feedCursor.js +22 -0
- package/dist/lib/feedFormat.d.ts +12 -0
- package/dist/lib/feedFormat.js +14 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.js +7 -0
- package/dist/lib/jamHelpers.d.ts +11 -2
- package/dist/lib/jamHelpers.js +37 -0
- package/dist/lib/legacyThemeRoot.d.ts +3 -0
- package/dist/lib/legacyThemeRoot.js +10 -0
- package/dist/lib/markdownHelpers.d.ts +8 -0
- package/dist/lib/markdownHelpers.js +32 -3
- package/dist/lib/postHelpers.d.ts +142 -3
- package/dist/lib/postHelpers.js +307 -4
- package/dist/lib/profileHelpers.d.ts +11 -0
- package/dist/lib/profileHelpers.js +31 -0
- package/dist/lib/reactions.d.ts +17 -0
- package/dist/lib/reactions.js +37 -0
- package/dist/lib/scopeHelpers.d.ts +31 -2
- package/dist/lib/scopeHelpers.js +37 -3
- package/dist/lib/ssoProviders.d.ts +72 -0
- package/dist/lib/ssoProviders.js +370 -0
- package/dist/lib/timeZone.d.ts +9 -0
- package/dist/lib/timeZone.js +44 -0
- package/dist/types/analytics.d.ts +20 -0
- package/dist/types/analytics.js +4 -0
- package/dist/types/api.d.ts +41799 -11853
- package/dist/types/api.js +52 -4
- package/dist/types/auth.d.ts +20 -6
- package/dist/types/capabilities.d.ts +15 -1
- package/dist/types/capabilities.js +51 -0
- package/dist/types/config.d.ts +96 -0
- package/dist/types/config.js +53 -4
- package/dist/types/db.d.ts +1155 -164
- package/dist/types/db.js +14 -0
- package/dist/types/export.d.ts +120 -0
- package/dist/types/export.js +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/internal.d.ts +2577 -524
- package/dist/types/internal.js +6 -0
- package/dist/types/models.d.ts +63 -7
- package/dist/types/models.js +39 -2
- package/dist/types/plugins.d.ts +22 -0
- package/dist/types/plugins.js +66 -0
- package/dist/types/roleDefaults.d.ts +31 -0
- package/dist/types/roleDefaults.js +110 -0
- package/dist/types/stats.d.ts +54606 -6065
- package/dist/types/stats.js +30 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.js +1 -3
- package/package.json +1 -1
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { Answer, AnswerWithPublicProfile, AuthorizationData, CapabilitiesConfig, Event, GroupWithMeta, PostType, PostDataUnion, PublicPost, PublicProfile, Thread, VisibilityType } from '../types';
|
|
1
|
+
import { Answer, AnswerWithPublicProfile, AuthorizationData, CapabilitiesConfig, Event, GroupWithMeta, PostType, PostDataUnion, PublicPost, PublicProfile, PublicRsvp, RSVP, Thread, VisibilityType } from '../types';
|
|
2
2
|
export declare const buildThreads: (posts: PublicPost[]) => Thread[];
|
|
3
|
+
export type ThreadPreviewPost = {
|
|
4
|
+
id: string;
|
|
5
|
+
createdAt: string;
|
|
6
|
+
inReplyToId?: string | null;
|
|
7
|
+
replyTo?: ThreadPreviewPost | null;
|
|
8
|
+
};
|
|
9
|
+
export type ThreadPreviewGroup = {
|
|
10
|
+
skippedAncestor: boolean;
|
|
11
|
+
ancestor?: ThreadPreviewPost;
|
|
12
|
+
posts: ThreadPreviewPost[];
|
|
13
|
+
};
|
|
14
|
+
export declare const buildThreadPreview: (rootId: string, replies: ThreadPreviewPost[]) => ThreadPreviewGroup[];
|
|
3
15
|
export declare const getReactionCount: (post: PublicPost) => Record<"👍", number>;
|
|
4
16
|
export declare const countVotes: (optionsCount: number, answers: Answer[]) => number[];
|
|
5
17
|
/** Fill blank poll choices with their placeholder label (e.g. "Option 1"). */
|
|
@@ -55,6 +67,10 @@ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?:
|
|
|
55
67
|
locked?: boolean | undefined;
|
|
56
68
|
bot?: boolean | undefined;
|
|
57
69
|
discoverable?: boolean | undefined;
|
|
70
|
+
roles?: {
|
|
71
|
+
key: string;
|
|
72
|
+
displayName: string;
|
|
73
|
+
}[] | undefined;
|
|
58
74
|
fields?: {
|
|
59
75
|
name: string;
|
|
60
76
|
value: string;
|
|
@@ -63,6 +79,8 @@ export declare const calculateEffectiveRsvps: (post: PublicPost, recurrenceId?:
|
|
|
63
79
|
followersCount: number;
|
|
64
80
|
followingCount: number;
|
|
65
81
|
} | undefined;
|
|
82
|
+
pinnedPostId?: string | undefined;
|
|
83
|
+
blockedByMe?: boolean | undefined;
|
|
66
84
|
};
|
|
67
85
|
createdAt: string;
|
|
68
86
|
recurrenceId?: string | undefined;
|
|
@@ -112,6 +130,10 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, rec
|
|
|
112
130
|
locked?: boolean | undefined;
|
|
113
131
|
bot?: boolean | undefined;
|
|
114
132
|
discoverable?: boolean | undefined;
|
|
133
|
+
roles?: {
|
|
134
|
+
key: string;
|
|
135
|
+
displayName: string;
|
|
136
|
+
}[] | undefined;
|
|
115
137
|
fields?: {
|
|
116
138
|
name: string;
|
|
117
139
|
value: string;
|
|
@@ -120,19 +142,120 @@ export declare const getEffectiveRsvp: (post: PublicPost, profileId: string, rec
|
|
|
120
142
|
followersCount: number;
|
|
121
143
|
followingCount: number;
|
|
122
144
|
} | undefined;
|
|
145
|
+
pinnedPostId?: string | undefined;
|
|
146
|
+
blockedByMe?: boolean | undefined;
|
|
123
147
|
};
|
|
124
148
|
createdAt: string;
|
|
125
149
|
recurrenceId?: string | undefined;
|
|
126
150
|
} | undefined;
|
|
127
151
|
export declare const countYesRsvps: (post: PublicPost, recurrenceId?: string) => number;
|
|
152
|
+
export declare const countSeriesYesRsvps: (post: PublicPost) => number;
|
|
153
|
+
/** Current roster: attending guests, plus organizer removals that can be restored. */
|
|
154
|
+
export declare const listedRsvps: (rsvps: PublicRsvp[]) => {
|
|
155
|
+
response: "no" | "yes" | "tentative" | "removed";
|
|
156
|
+
profile: {
|
|
157
|
+
id: string;
|
|
158
|
+
type: "local" | "guest" | "federated";
|
|
159
|
+
createdAt: string;
|
|
160
|
+
updatedAt: string;
|
|
161
|
+
handle: string;
|
|
162
|
+
memberships: {
|
|
163
|
+
group: {
|
|
164
|
+
handle: string;
|
|
165
|
+
capabilities: Record<string, {
|
|
166
|
+
add?: string[] | undefined;
|
|
167
|
+
remove?: string[] | undefined;
|
|
168
|
+
} | undefined>;
|
|
169
|
+
id: string;
|
|
170
|
+
createdAt: string;
|
|
171
|
+
updatedAt: string;
|
|
172
|
+
avatar?: string | null | undefined;
|
|
173
|
+
header?: string | null | undefined;
|
|
174
|
+
displayName?: string | undefined;
|
|
175
|
+
description?: string | undefined;
|
|
176
|
+
rules?: string | undefined;
|
|
177
|
+
pinnedPostId?: string | undefined;
|
|
178
|
+
discoverable?: boolean | undefined;
|
|
179
|
+
deletedAt?: string | null | undefined;
|
|
180
|
+
};
|
|
181
|
+
roles?: ("none" | "local" | "member" | "moderator" | "admin" | "owner" | "invited")[] | null | undefined;
|
|
182
|
+
}[] | undefined;
|
|
183
|
+
deletedAt?: string | null | undefined;
|
|
184
|
+
avatar?: string | null | undefined;
|
|
185
|
+
header?: string | null | undefined;
|
|
186
|
+
displayName?: string | undefined;
|
|
187
|
+
bio?: string | undefined;
|
|
188
|
+
location?: {
|
|
189
|
+
text: string;
|
|
190
|
+
coordinates?: {
|
|
191
|
+
lat: number;
|
|
192
|
+
lng: number;
|
|
193
|
+
alt?: number | undefined;
|
|
194
|
+
} | undefined;
|
|
195
|
+
} | undefined;
|
|
196
|
+
locked?: boolean | undefined;
|
|
197
|
+
bot?: boolean | undefined;
|
|
198
|
+
discoverable?: boolean | undefined;
|
|
199
|
+
roles?: {
|
|
200
|
+
key: string;
|
|
201
|
+
displayName: string;
|
|
202
|
+
}[] | undefined;
|
|
203
|
+
fields?: {
|
|
204
|
+
name: string;
|
|
205
|
+
value: string;
|
|
206
|
+
}[] | undefined;
|
|
207
|
+
profileStats?: {
|
|
208
|
+
followersCount: number;
|
|
209
|
+
followingCount: number;
|
|
210
|
+
} | undefined;
|
|
211
|
+
pinnedPostId?: string | undefined;
|
|
212
|
+
blockedByMe?: boolean | undefined;
|
|
213
|
+
};
|
|
214
|
+
createdAt: string;
|
|
215
|
+
recurrenceId?: string | undefined;
|
|
216
|
+
}[];
|
|
217
|
+
/** Set only when a member leaves an attending RSVP. A second "no" stays unset. */
|
|
218
|
+
export type RsvpCancelNotice = {
|
|
219
|
+
occurrenceIds: string[];
|
|
220
|
+
series: boolean;
|
|
221
|
+
};
|
|
222
|
+
export declare const isRsvpCancelNotice: (data: unknown) => data is RsvpCancelNotice;
|
|
223
|
+
export declare const rsvpCancelNotice: (post: PublicPost, profileId: string, response: PublicRsvp["response"], occurrenceIds?: string[]) => RsvpCancelNotice | undefined;
|
|
224
|
+
export type RsvpCancellation = {
|
|
225
|
+
profile: PublicRsvp['profile'];
|
|
226
|
+
recurrenceId?: string;
|
|
227
|
+
canceledAt: string;
|
|
228
|
+
series: boolean;
|
|
229
|
+
};
|
|
230
|
+
/** Attending → no transitions, newest first. Later re-RSVPs do not erase them. */
|
|
231
|
+
export declare const listRsvpCancellations: (post: PublicPost) => RsvpCancellation[];
|
|
232
|
+
export declare const rsvpCancelWhenLabels: (post: PublicPost, notice: RsvpCancelNotice) => {
|
|
233
|
+
series: boolean;
|
|
234
|
+
labels: string[];
|
|
235
|
+
};
|
|
236
|
+
export declare const instanceRsvpIdsForProfile: (post: PublicPost, profileId: string) => string[];
|
|
237
|
+
export declare const overlaySeriesRsvpEntries: (response: RSVP["response"], instanceIds: string[]) => RSVP[];
|
|
238
|
+
export declare const seriesYesBlockedByCapacity: (post: PublicPost, profileId: string, now?: Date) => boolean;
|
|
239
|
+
export declare const occurrenceHasCapacity: (post: PublicPost, recurrenceId?: string, profileId?: string) => boolean;
|
|
240
|
+
/** Series Register stays enabled while any upcoming date still has a seat. */
|
|
241
|
+
export declare const recurringEventHasOpenOccurrence: (post: PublicPost, profileId?: string, now?: Date) => boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Series-page RSVP for the Register/Cancel CTA: prefer the default/next date,
|
|
244
|
+
* then any attending instance so a partial RSVP still shows Cancel.
|
|
245
|
+
*/
|
|
246
|
+
export declare const displayRsvpForProfile: (post: PublicPost, profileId: string, options?: {
|
|
247
|
+
recurrenceId?: string;
|
|
248
|
+
lockToOccurrence?: boolean;
|
|
249
|
+
now?: Date;
|
|
250
|
+
}) => PublicRsvp | undefined;
|
|
128
251
|
export declare const isCapacityEvent: (event: Event) => boolean;
|
|
129
252
|
export declare const parseEventMaxAttendeesInput: (raw: string) => number | undefined;
|
|
130
253
|
export declare const withoutEventMaxAttendees: <T extends Event>(event: T) => T;
|
|
131
254
|
export declare const normalizeEventDataForSave: <T extends Event>(event: T) => T;
|
|
132
|
-
/**
|
|
255
|
+
/** Null capacity means it was cleared; strip for validation/output. */
|
|
133
256
|
export declare const normalizeEventDataFromDb: <T extends Event>(event: T) => T;
|
|
134
257
|
export declare const normalizePostDataFromDb: (data: PostDataUnion) => PostDataUnion;
|
|
135
|
-
/**
|
|
258
|
+
/** Nested `data` updates send null to remove maxAttendees. */
|
|
136
259
|
export type EventDbUpdate = Omit<Event, 'maxAttendees'> & {
|
|
137
260
|
maxAttendees?: number | null;
|
|
138
261
|
};
|
|
@@ -162,3 +285,19 @@ export type PostActionAvailability = {
|
|
|
162
285
|
* and reposts need create-*, likes need core-posts-react.
|
|
163
286
|
*/
|
|
164
287
|
export declare const getPostActionAvailability: (authData: AuthorizationData, post: PublicPost, config: CapabilitiesConfig) => PostActionAvailability;
|
|
288
|
+
/** Sentinel handle for block-hidden reply tombstones (no name/handle leak). */
|
|
289
|
+
export declare const HIDDEN_AUTHOR_HANDLE = "hidden";
|
|
290
|
+
export declare const toHiddenPost: <T extends {
|
|
291
|
+
data: PostDataUnion;
|
|
292
|
+
profile: PublicProfile;
|
|
293
|
+
}>(post: T) => T & {
|
|
294
|
+
hidden: true;
|
|
295
|
+
};
|
|
296
|
+
export declare const isHiddenPost: (post: {
|
|
297
|
+
hidden?: boolean;
|
|
298
|
+
}) => boolean;
|
|
299
|
+
export declare const isOneToOneWithBlocked: (post: Pick<PublicPost, "visibility" | "audience" | "profile"> & {
|
|
300
|
+
creatorId?: string;
|
|
301
|
+
}, viewer: {
|
|
302
|
+
id: string;
|
|
303
|
+
} | undefined | null, blockedIds?: Set<string> | string[]) => boolean;
|
package/dist/lib/postHelpers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { POLL_OPTION_MAX_LENGTH, visibilityTypeValues, } from '../types/index.js';
|
|
2
2
|
import { canModerateJam } from './jamHelpers.js';
|
|
3
|
-
import { sameRecurrenceId } from './eventRecurrence.js';
|
|
3
|
+
import { defaultRsvpRecurrenceId, effectiveEventTimes, isRecurringEvent, listRsvpOccurrences, normalizeRecurrenceId, sameRecurrenceId, } from './eventRecurrence.js';
|
|
4
|
+
import { formatEventWhen } from './eventTime.js';
|
|
4
5
|
import { checkGroupCapabilities, checkPostCapabilities, checkRoleCapabilities, } from './capabilitiesHelpers.js';
|
|
5
6
|
import { scopeMatches } from './scopeHelpers.js';
|
|
6
7
|
import { countBy, dateSorter, groupBy, transformValues } from './utils.js';
|
|
@@ -14,6 +15,77 @@ export const buildThreads = (posts) => posts
|
|
|
14
15
|
.filter((p) => !posts.find((p2) => p2.id === p.inReplyToId))
|
|
15
16
|
.map((post) => buildThread(post, posts))
|
|
16
17
|
.sort(dateSorter());
|
|
18
|
+
const parentIdOf = (post) => { var _a, _b; return (_a = post.inReplyToId) !== null && _a !== void 0 ? _a : (_b = post.replyTo) === null || _b === void 0 ? void 0 : _b.id; };
|
|
19
|
+
export const buildThreadPreview = (rootId, replies) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const sorted = [...replies].sort((a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id));
|
|
22
|
+
if (!sorted.length)
|
|
23
|
+
return [];
|
|
24
|
+
const ids = new Set(sorted.map((post) => post.id));
|
|
25
|
+
const parent = new Map(sorted.map((post) => [post.id, post.id]));
|
|
26
|
+
const find = (id) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const current = (_a = parent.get(id)) !== null && _a !== void 0 ? _a : id;
|
|
29
|
+
if (current !== id) {
|
|
30
|
+
const root = find(current);
|
|
31
|
+
parent.set(id, root);
|
|
32
|
+
return root;
|
|
33
|
+
}
|
|
34
|
+
return id;
|
|
35
|
+
};
|
|
36
|
+
const union = (a, b) => {
|
|
37
|
+
const ra = find(a);
|
|
38
|
+
const rb = find(b);
|
|
39
|
+
if (ra !== rb)
|
|
40
|
+
parent.set(ra, rb);
|
|
41
|
+
};
|
|
42
|
+
for (const post of sorted) {
|
|
43
|
+
const parentId = parentIdOf(post);
|
|
44
|
+
if (parentId && ids.has(parentId))
|
|
45
|
+
union(post.id, parentId);
|
|
46
|
+
}
|
|
47
|
+
const grouped = new Map();
|
|
48
|
+
for (const post of sorted) {
|
|
49
|
+
const key = find(post.id);
|
|
50
|
+
const list = (_a = grouped.get(key)) !== null && _a !== void 0 ? _a : [];
|
|
51
|
+
list.push(post);
|
|
52
|
+
grouped.set(key, list);
|
|
53
|
+
}
|
|
54
|
+
return [...grouped.values()]
|
|
55
|
+
.map((posts) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const start = (_a = posts.find((post) => {
|
|
58
|
+
const parentId = parentIdOf(post);
|
|
59
|
+
return !parentId || !ids.has(parentId);
|
|
60
|
+
})) !== null && _a !== void 0 ? _a : posts[0];
|
|
61
|
+
const ordered = [];
|
|
62
|
+
const used = new Set();
|
|
63
|
+
let current = start;
|
|
64
|
+
while (current && !used.has(current.id)) {
|
|
65
|
+
ordered.push(current);
|
|
66
|
+
used.add(current.id);
|
|
67
|
+
current = posts.find((post) => parentIdOf(post) === (current === null || current === void 0 ? void 0 : current.id) && !used.has(post.id));
|
|
68
|
+
}
|
|
69
|
+
for (const post of posts) {
|
|
70
|
+
if (!used.has(post.id))
|
|
71
|
+
ordered.push(post);
|
|
72
|
+
}
|
|
73
|
+
const startParentId = parentIdOf(start);
|
|
74
|
+
const ancestor = startParentId && startParentId !== rootId
|
|
75
|
+
? ((_b = start.replyTo) !== null && _b !== void 0 ? _b : undefined)
|
|
76
|
+
: undefined;
|
|
77
|
+
const skippedAncestor = !!(ancestor &&
|
|
78
|
+
ancestor.inReplyToId &&
|
|
79
|
+
ancestor.inReplyToId !== rootId);
|
|
80
|
+
return { skippedAncestor, ancestor, posts: ordered };
|
|
81
|
+
})
|
|
82
|
+
.sort((a, b) => {
|
|
83
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
84
|
+
const aKey = (_d = (_b = (_a = a.ancestor) === null || _a === void 0 ? void 0 : _a.createdAt) !== null && _b !== void 0 ? _b : (_c = a.posts[0]) === null || _c === void 0 ? void 0 : _c.createdAt) !== null && _d !== void 0 ? _d : '';
|
|
85
|
+
const bKey = (_h = (_f = (_e = b.ancestor) === null || _e === void 0 ? void 0 : _e.createdAt) !== null && _f !== void 0 ? _f : (_g = b.posts[0]) === null || _g === void 0 ? void 0 : _g.createdAt) !== null && _h !== void 0 ? _h : '';
|
|
86
|
+
return aKey.localeCompare(bKey);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
17
89
|
export const getReactionCount = (post) => {
|
|
18
90
|
return countBy(post.reactions, (r) => r.reaction);
|
|
19
91
|
};
|
|
@@ -68,14 +140,16 @@ const latestRsvpPerProfile = (rsvps, recurrenceId) => {
|
|
|
68
140
|
}
|
|
69
141
|
return true;
|
|
70
142
|
}
|
|
71
|
-
return
|
|
143
|
+
return true;
|
|
72
144
|
});
|
|
73
145
|
const rsvpsByProfile = groupBy(scoped, (r) => r.profile.id);
|
|
74
146
|
return Object.values(rsvpsByProfile).map((profileRsvps) => {
|
|
75
147
|
const instanceRsvps = recurrenceId
|
|
76
148
|
? profileRsvps.filter((rsvp) => sameRecurrenceId(rsvp.recurrenceId, recurrenceId))
|
|
77
149
|
: [];
|
|
78
|
-
const seriesRsvps =
|
|
150
|
+
const seriesRsvps = recurrenceId
|
|
151
|
+
? profileRsvps.filter((rsvp) => !rsvp.recurrenceId)
|
|
152
|
+
: profileRsvps;
|
|
79
153
|
const pool = recurrenceId && instanceRsvps.length > 0 ? instanceRsvps : seriesRsvps;
|
|
80
154
|
const sorted = pool.sort(dateSorter());
|
|
81
155
|
return sorted[sorted.length - 1];
|
|
@@ -84,6 +158,198 @@ const latestRsvpPerProfile = (rsvps, recurrenceId) => {
|
|
|
84
158
|
export const calculateEffectiveRsvps = (post, recurrenceId) => latestRsvpPerProfile(post.rsvps || [], recurrenceId).filter((rsvp) => !!rsvp);
|
|
85
159
|
export const getEffectiveRsvp = (post, profileId, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).find((r) => r.profile.id === profileId);
|
|
86
160
|
export const countYesRsvps = (post, recurrenceId) => calculateEffectiveRsvps(post, recurrenceId).filter((r) => r.response === 'yes').length;
|
|
161
|
+
export const countSeriesYesRsvps = (post) => {
|
|
162
|
+
var _a;
|
|
163
|
+
return ((_a = post.rsvps) !== null && _a !== void 0 ? _a : []).filter((r) => !r.recurrenceId && r.response === 'yes')
|
|
164
|
+
.length;
|
|
165
|
+
};
|
|
166
|
+
const attendingResponse = (response) => response === 'yes' || response === 'tentative';
|
|
167
|
+
/** Current roster: attending guests, plus organizer removals that can be restored. */
|
|
168
|
+
export const listedRsvps = (rsvps) => rsvps.filter((rsvp) => rsvp.response === 'yes' ||
|
|
169
|
+
rsvp.response === 'tentative' ||
|
|
170
|
+
rsvp.response === 'removed');
|
|
171
|
+
export const isRsvpCancelNotice = (data) => {
|
|
172
|
+
if (!data || typeof data !== 'object')
|
|
173
|
+
return false;
|
|
174
|
+
const notice = data;
|
|
175
|
+
return (typeof notice.series === 'boolean' &&
|
|
176
|
+
Array.isArray(notice.occurrenceIds) &&
|
|
177
|
+
notice.occurrenceIds.every((id) => typeof id === 'string'));
|
|
178
|
+
};
|
|
179
|
+
export const rsvpCancelNotice = (post, profileId, response, occurrenceIds) => {
|
|
180
|
+
var _a, _b;
|
|
181
|
+
if (response !== 'no')
|
|
182
|
+
return undefined;
|
|
183
|
+
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
184
|
+
if (!event)
|
|
185
|
+
return undefined;
|
|
186
|
+
if (occurrenceIds === null || occurrenceIds === void 0 ? void 0 : occurrenceIds.length) {
|
|
187
|
+
const canceled = occurrenceIds.filter((id) => { var _a; return attendingResponse((_a = getEffectiveRsvp(post, profileId, id)) === null || _a === void 0 ? void 0 : _a.response); });
|
|
188
|
+
if (!canceled.length)
|
|
189
|
+
return undefined;
|
|
190
|
+
return { occurrenceIds: canceled, series: false };
|
|
191
|
+
}
|
|
192
|
+
if (attendingResponse((_b = getEffectiveRsvp(post, profileId)) === null || _b === void 0 ? void 0 : _b.response)) {
|
|
193
|
+
return { occurrenceIds: [], series: isRecurringEvent(event) };
|
|
194
|
+
}
|
|
195
|
+
if (!event.recurrence)
|
|
196
|
+
return undefined;
|
|
197
|
+
const canceled = instanceRsvpIdsForProfile(post, profileId).filter((id) => { var _a; return attendingResponse((_a = getEffectiveRsvp(post, profileId, id)) === null || _a === void 0 ? void 0 : _a.response); });
|
|
198
|
+
if (!canceled.length)
|
|
199
|
+
return undefined;
|
|
200
|
+
return { occurrenceIds: canceled, series: false };
|
|
201
|
+
};
|
|
202
|
+
const instanceRsvpKey = (profileId, recurrenceId) => `${profileId}|${normalizeRecurrenceId(recurrenceId)}`;
|
|
203
|
+
/** Attending → no transitions, newest first. Later re-RSVPs do not erase them. */
|
|
204
|
+
export const listRsvpCancellations = (post) => {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
207
|
+
const recurring = event ? isRecurringEvent(event) : false;
|
|
208
|
+
const seriesResponse = new Map();
|
|
209
|
+
const instanceResponse = new Map();
|
|
210
|
+
const records = [];
|
|
211
|
+
for (const rsvp of [...((_b = post.rsvps) !== null && _b !== void 0 ? _b : [])].sort(dateSorter())) {
|
|
212
|
+
const profileId = rsvp.profile.id;
|
|
213
|
+
if (rsvp.response === 'no') {
|
|
214
|
+
if (rsvp.recurrenceId) {
|
|
215
|
+
const key = instanceRsvpKey(profileId, rsvp.recurrenceId);
|
|
216
|
+
const previous = instanceResponse.has(key)
|
|
217
|
+
? instanceResponse.get(key)
|
|
218
|
+
: seriesResponse.get(profileId);
|
|
219
|
+
if (attendingResponse(previous)) {
|
|
220
|
+
records.push({
|
|
221
|
+
profile: rsvp.profile,
|
|
222
|
+
recurrenceId: rsvp.recurrenceId,
|
|
223
|
+
canceledAt: rsvp.createdAt,
|
|
224
|
+
series: false,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else if (attendingResponse(seriesResponse.get(profileId))) {
|
|
229
|
+
records.push({
|
|
230
|
+
profile: rsvp.profile,
|
|
231
|
+
canceledAt: rsvp.createdAt,
|
|
232
|
+
series: recurring,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (rsvp.recurrenceId) {
|
|
237
|
+
instanceResponse.set(instanceRsvpKey(profileId, rsvp.recurrenceId), rsvp.response);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
seriesResponse.set(profileId, rsvp.response);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return records.reverse();
|
|
244
|
+
};
|
|
245
|
+
export const rsvpCancelWhenLabels = (post, notice) => {
|
|
246
|
+
var _a;
|
|
247
|
+
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
248
|
+
if (!event || notice.series)
|
|
249
|
+
return { series: notice.series, labels: [] };
|
|
250
|
+
const format = (start, end) => formatEventWhen(start, {
|
|
251
|
+
end,
|
|
252
|
+
timeZone: event.timeZone,
|
|
253
|
+
allDay: event.wholeDay,
|
|
254
|
+
});
|
|
255
|
+
if (!notice.occurrenceIds.length) {
|
|
256
|
+
return { series: false, labels: [format(event.start, event.end)] };
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
series: false,
|
|
260
|
+
labels: notice.occurrenceIds.map((id) => {
|
|
261
|
+
const times = effectiveEventTimes(event, id);
|
|
262
|
+
return format(times.start, times.end);
|
|
263
|
+
}),
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
export const instanceRsvpIdsForProfile = (post, profileId) => {
|
|
267
|
+
var _a;
|
|
268
|
+
const ids = new Set();
|
|
269
|
+
for (const rsvp of (_a = post.rsvps) !== null && _a !== void 0 ? _a : []) {
|
|
270
|
+
if (rsvp.profile.id !== profileId || !rsvp.recurrenceId)
|
|
271
|
+
continue;
|
|
272
|
+
ids.add(normalizeRecurrenceId(rsvp.recurrenceId));
|
|
273
|
+
}
|
|
274
|
+
return [...ids];
|
|
275
|
+
};
|
|
276
|
+
export const overlaySeriesRsvpEntries = (response, instanceIds) => [
|
|
277
|
+
{ response },
|
|
278
|
+
...instanceIds.map((recurrenceId) => ({ response, recurrenceId })),
|
|
279
|
+
];
|
|
280
|
+
export const seriesYesBlockedByCapacity = (post, profileId, now = new Date()) => {
|
|
281
|
+
var _a;
|
|
282
|
+
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
283
|
+
const maxAttendees = event === null || event === void 0 ? void 0 : event.maxAttendees;
|
|
284
|
+
if (!event || !maxAttendees || !event.recurrence)
|
|
285
|
+
return false;
|
|
286
|
+
const occurrences = listRsvpOccurrences(event, now);
|
|
287
|
+
// When there are no upcoming occurrences (e.g. a live jam whose current
|
|
288
|
+
// occurrence started before `now`), fall back to the series-level count.
|
|
289
|
+
if (occurrences.length === 0) {
|
|
290
|
+
const current = getEffectiveRsvp(post, profileId);
|
|
291
|
+
if ((current === null || current === void 0 ? void 0 : current.response) !== 'yes' &&
|
|
292
|
+
countSeriesYesRsvps(post) >= maxAttendees) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
return occurrences.some((occurrence) => {
|
|
298
|
+
const current = getEffectiveRsvp(post, profileId, occurrence.recurrenceId);
|
|
299
|
+
if ((current === null || current === void 0 ? void 0 : current.response) === 'yes')
|
|
300
|
+
return false;
|
|
301
|
+
return countYesRsvps(post, occurrence.recurrenceId) >= maxAttendees;
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
export const occurrenceHasCapacity = (post, recurrenceId, profileId) => {
|
|
305
|
+
var _a;
|
|
306
|
+
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
307
|
+
if (!(event === null || event === void 0 ? void 0 : event.maxAttendees))
|
|
308
|
+
return true;
|
|
309
|
+
if (profileId) {
|
|
310
|
+
const current = getEffectiveRsvp(post, profileId, recurrenceId);
|
|
311
|
+
if ((current === null || current === void 0 ? void 0 : current.response) === 'yes')
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
return countYesRsvps(post, recurrenceId) < event.maxAttendees;
|
|
315
|
+
};
|
|
316
|
+
/** Series Register stays enabled while any upcoming date still has a seat. */
|
|
317
|
+
export const recurringEventHasOpenOccurrence = (post, profileId, now = new Date()) => {
|
|
318
|
+
var _a;
|
|
319
|
+
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
320
|
+
if (!event)
|
|
321
|
+
return false;
|
|
322
|
+
if (!event.recurrence) {
|
|
323
|
+
return occurrenceHasCapacity(post, undefined, profileId);
|
|
324
|
+
}
|
|
325
|
+
return listRsvpOccurrences(event, now).some((occurrence) => occurrenceHasCapacity(post, occurrence.recurrenceId, profileId));
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Series-page RSVP for the Register/Cancel CTA: prefer the default/next date,
|
|
329
|
+
* then any attending instance so a partial RSVP still shows Cancel.
|
|
330
|
+
*/
|
|
331
|
+
export const displayRsvpForProfile = (post, profileId, options) => {
|
|
332
|
+
var _a;
|
|
333
|
+
const event = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' ? post.data : undefined;
|
|
334
|
+
const scopedId = (options === null || options === void 0 ? void 0 : options.lockToOccurrence)
|
|
335
|
+
? options.recurrenceId
|
|
336
|
+
: event
|
|
337
|
+
? defaultRsvpRecurrenceId(event, options === null || options === void 0 ? void 0 : options.recurrenceId, options === null || options === void 0 ? void 0 : options.now)
|
|
338
|
+
: options === null || options === void 0 ? void 0 : options.recurrenceId;
|
|
339
|
+
const scoped = getEffectiveRsvp(post, profileId, scopedId);
|
|
340
|
+
if (options === null || options === void 0 ? void 0 : options.lockToOccurrence)
|
|
341
|
+
return scoped;
|
|
342
|
+
if (scoped && scoped.response !== 'no')
|
|
343
|
+
return scoped;
|
|
344
|
+
if (event === null || event === void 0 ? void 0 : event.recurrence) {
|
|
345
|
+
for (const occurrence of listRsvpOccurrences(event, options === null || options === void 0 ? void 0 : options.now)) {
|
|
346
|
+
const instance = getEffectiveRsvp(post, profileId, occurrence.recurrenceId);
|
|
347
|
+
if (instance && instance.response !== 'no')
|
|
348
|
+
return instance;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return scoped;
|
|
352
|
+
};
|
|
87
353
|
export const isCapacityEvent = (event) => !!event.maxAttendees;
|
|
88
354
|
export const parseEventMaxAttendeesInput = (raw) => {
|
|
89
355
|
const trimmed = raw.trim();
|
|
@@ -105,7 +371,7 @@ export const normalizeEventDataForSave = (event) => {
|
|
|
105
371
|
}
|
|
106
372
|
return { ...event, maxAttendees: Math.trunc(maxAttendees) };
|
|
107
373
|
};
|
|
108
|
-
/**
|
|
374
|
+
/** Null capacity means it was cleared; strip for validation/output. */
|
|
109
375
|
export const normalizeEventDataFromDb = (event) => {
|
|
110
376
|
if (event.maxAttendees != null) {
|
|
111
377
|
return event;
|
|
@@ -200,3 +466,40 @@ export const getPostActionAvailability = (authData, post, config) => {
|
|
|
200
466
|
: canCreatePost(authData, post.type, post.visibility);
|
|
201
467
|
return { canReply, canRepost, canReact };
|
|
202
468
|
};
|
|
469
|
+
/** Sentinel handle for block-hidden reply tombstones (no name/handle leak). */
|
|
470
|
+
export const HIDDEN_AUTHOR_HANDLE = 'hidden';
|
|
471
|
+
export const toHiddenPost = (post) => ({
|
|
472
|
+
...post,
|
|
473
|
+
hidden: true,
|
|
474
|
+
data: {
|
|
475
|
+
...post.data,
|
|
476
|
+
...('content' in post.data ? { content: '' } : {}),
|
|
477
|
+
},
|
|
478
|
+
profile: {
|
|
479
|
+
...post.profile,
|
|
480
|
+
displayName: undefined,
|
|
481
|
+
handle: HIDDEN_AUTHOR_HANDLE,
|
|
482
|
+
avatar: null,
|
|
483
|
+
header: null,
|
|
484
|
+
bio: undefined,
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
export const isHiddenPost = (post) => !!post.hidden;
|
|
488
|
+
const participantIds = (post) => {
|
|
489
|
+
var _a, _b, _c;
|
|
490
|
+
const ids = new Set(((_a = post.audience) !== null && _a !== void 0 ? _a : []).map((member) => member.id).filter(Boolean));
|
|
491
|
+
const creatorId = (_b = post.creatorId) !== null && _b !== void 0 ? _b : (_c = post.profile) === null || _c === void 0 ? void 0 : _c.id;
|
|
492
|
+
if (creatorId)
|
|
493
|
+
ids.add(creatorId);
|
|
494
|
+
return ids;
|
|
495
|
+
};
|
|
496
|
+
export const isOneToOneWithBlocked = (post, viewer, blockedIds) => {
|
|
497
|
+
if (!viewer || post.visibility !== 'direct')
|
|
498
|
+
return false;
|
|
499
|
+
const blocked = blockedIds instanceof Set ? blockedIds : new Set(blockedIds !== null && blockedIds !== void 0 ? blockedIds : []);
|
|
500
|
+
if (!blocked.size)
|
|
501
|
+
return false;
|
|
502
|
+
const others = participantIds(post);
|
|
503
|
+
others.delete(viewer.id);
|
|
504
|
+
return others.size === 1 && blocked.has([...others][0]);
|
|
505
|
+
};
|
|
@@ -39,3 +39,14 @@ export declare const sortProfiles: (profiles: PublicProfile[]) => PublicProfile[
|
|
|
39
39
|
export declare const isStripeActive: (sub: StripeSubscriptionData | undefined | null) => boolean;
|
|
40
40
|
export declare const getStripeCustomerId: (profileSettings: ProfileSettings) => string | undefined;
|
|
41
41
|
export declare const isOwnerProfile: (profile: ProfileWithMeta) => boolean;
|
|
42
|
+
type BlockIdProfile = {
|
|
43
|
+
blockingIds?: string[] | null;
|
|
44
|
+
blockedByIds?: string[] | null;
|
|
45
|
+
};
|
|
46
|
+
export declare const blockedPairIds: (profile?: BlockIdProfile | null) => string[];
|
|
47
|
+
export declare const isBlockedPair: (profile: BlockIdProfile | undefined | null, otherId: string | undefined | null) => boolean;
|
|
48
|
+
export declare const viewerBlockedTarget: (profile: BlockIdProfile | undefined | null, otherId: string | undefined | null) => boolean;
|
|
49
|
+
export declare const targetBlockedViewer: (profile: BlockIdProfile | undefined | null, otherId: string | undefined | null) => boolean;
|
|
50
|
+
export declare const sharesControllingAccount: (a: Pick<ProfileWithMeta, "controllers">, b: Pick<ProfileWithMeta, "controllers">) => boolean;
|
|
51
|
+
export declare const toBlockedProfileStub: (profile: Pick<ProfileWithMeta, "id" | "type" | "createdAt" | "updatedAt" | "handle" | "displayName">) => PublicProfile;
|
|
52
|
+
export {};
|
|
@@ -28,6 +28,8 @@ export const toPublicDeletedProfile = (profile) => ({
|
|
|
28
28
|
memberships: [],
|
|
29
29
|
fields: undefined,
|
|
30
30
|
profileStats: undefined,
|
|
31
|
+
pinnedPostId: undefined,
|
|
32
|
+
roles: [],
|
|
31
33
|
});
|
|
32
34
|
export const anonymizeProfileIfDeleted = (profile) => {
|
|
33
35
|
if (!profile)
|
|
@@ -58,6 +60,9 @@ export const toDeletedProfileWithMeta = (profile) => ({
|
|
|
58
60
|
controllers: [],
|
|
59
61
|
memberships: [],
|
|
60
62
|
profileStats: { followersCount: 0, followingCount: 0 },
|
|
63
|
+
blockingIds: [],
|
|
64
|
+
blockedByIds: [],
|
|
65
|
+
followedHashtags: [],
|
|
61
66
|
});
|
|
62
67
|
/** Tombstone a `ProfileWithMeta` only when it is soft-deleted. */
|
|
63
68
|
export const tombstoneProfileWithMetaIfDeleted = (profile) => profile && isDeletedProfile(profile)
|
|
@@ -102,3 +107,29 @@ export const getStripeCustomerId = (profileSettings) => { var _a; return (_a = p
|
|
|
102
107
|
export const isOwnerProfile = (profile) => {
|
|
103
108
|
return profile === null || profile === void 0 ? void 0 : profile.roles.some((role) => role.key === 'owner');
|
|
104
109
|
};
|
|
110
|
+
export const blockedPairIds = (profile) => {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
return [
|
|
113
|
+
...new Set([
|
|
114
|
+
...((_a = profile === null || profile === void 0 ? void 0 : profile.blockingIds) !== null && _a !== void 0 ? _a : []),
|
|
115
|
+
...((_b = profile === null || profile === void 0 ? void 0 : profile.blockedByIds) !== null && _b !== void 0 ? _b : []),
|
|
116
|
+
]),
|
|
117
|
+
];
|
|
118
|
+
};
|
|
119
|
+
export const isBlockedPair = (profile, otherId) => !!otherId && blockedPairIds(profile).includes(otherId);
|
|
120
|
+
export const viewerBlockedTarget = (profile, otherId) => { var _a; return !!otherId && ((_a = profile === null || profile === void 0 ? void 0 : profile.blockingIds) !== null && _a !== void 0 ? _a : []).includes(otherId); };
|
|
121
|
+
export const targetBlockedViewer = (profile, otherId) => { var _a; return !!otherId && ((_a = profile === null || profile === void 0 ? void 0 : profile.blockedByIds) !== null && _a !== void 0 ? _a : []).includes(otherId); };
|
|
122
|
+
export const sharesControllingAccount = (a, b) => {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
const otherIds = new Set(((_a = b.controllers) !== null && _a !== void 0 ? _a : []).map((account) => account.id));
|
|
125
|
+
return ((_b = a.controllers) !== null && _b !== void 0 ? _b : []).some((account) => otherIds.has(account.id));
|
|
126
|
+
};
|
|
127
|
+
export const toBlockedProfileStub = (profile) => ({
|
|
128
|
+
id: profile.id,
|
|
129
|
+
type: profile.type,
|
|
130
|
+
createdAt: profile.createdAt,
|
|
131
|
+
updatedAt: profile.updatedAt,
|
|
132
|
+
handle: profile.handle,
|
|
133
|
+
displayName: profile.displayName,
|
|
134
|
+
blockedByMe: true,
|
|
135
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const AP_LIKE_REACTION = "\uD83D\uDC4D";
|
|
2
|
+
export declare const AP_DISLIKE_REACTION = "\uD83D\uDC4E";
|
|
3
|
+
export declare const activityPubActivityForReaction: (reaction: string) => "Like" | "Dislike" | null;
|
|
4
|
+
export type ReactionLogEntry = {
|
|
5
|
+
type: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
data?: unknown;
|
|
8
|
+
profile: {
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Latest reaction/unreaction per (profile, emoji) wins. */
|
|
13
|
+
export declare const currentReactionsFromEntries: <T extends ReactionLogEntry>(entries: readonly T[]) => Array<{
|
|
14
|
+
reaction: string;
|
|
15
|
+
profile: T["profile"];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const isReactionHistoryEntry: (type: string) => type is "reaction" | "unreaction";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const AP_LIKE_REACTION = '👍';
|
|
2
|
+
export const AP_DISLIKE_REACTION = '👎';
|
|
3
|
+
export const activityPubActivityForReaction = (reaction) => {
|
|
4
|
+
if (reaction === AP_LIKE_REACTION)
|
|
5
|
+
return 'Like';
|
|
6
|
+
if (reaction === AP_DISLIKE_REACTION)
|
|
7
|
+
return 'Dislike';
|
|
8
|
+
return null;
|
|
9
|
+
};
|
|
10
|
+
const reactionFromData = (data) => {
|
|
11
|
+
if (!data || typeof data !== 'object' || !('reaction' in data)) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const reaction = data.reaction;
|
|
15
|
+
return typeof reaction === 'string' && reaction.length > 0
|
|
16
|
+
? reaction
|
|
17
|
+
: undefined;
|
|
18
|
+
};
|
|
19
|
+
/** Latest reaction/unreaction per (profile, emoji) wins. */
|
|
20
|
+
export const currentReactionsFromEntries = (entries) => {
|
|
21
|
+
const latest = new Map();
|
|
22
|
+
const sorted = [...entries].filter((entry) => entry.type === 'reaction' || entry.type === 'unreaction');
|
|
23
|
+
sorted.sort((a, b) => (a.createdAt < b.createdAt ? -1 : 1));
|
|
24
|
+
for (const entry of sorted) {
|
|
25
|
+
const reaction = reactionFromData(entry.data);
|
|
26
|
+
if (!reaction)
|
|
27
|
+
continue;
|
|
28
|
+
latest.set(`${entry.profile.id}\0${reaction}`, { entry, reaction });
|
|
29
|
+
}
|
|
30
|
+
return [...latest.values()]
|
|
31
|
+
.filter(({ entry }) => entry.type === 'reaction')
|
|
32
|
+
.map(({ entry, reaction }) => ({
|
|
33
|
+
reaction,
|
|
34
|
+
profile: entry.profile,
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
export const isReactionHistoryEntry = (type) => type === 'reaction' || type === 'unreaction';
|