@openpeepshq/core 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backups/index.js +2 -2
- package/dist/config/index.d.ts +1 -0
- package/dist/jams/index.d.ts +14 -1
- package/dist/jams/index.js +75 -1
- package/dist/jams/mapping.d.ts +8 -8
- package/dist/jams/token.js +3 -0
- package/dist/jams/waitingRoom.d.ts +1 -1
- package/dist/jams/waitingRoom.js +19 -1
- package/dist/log/retention.js +2 -2
- package/dist/notifications/defaultNotifications/jamStarted/index.js +5 -40
- package/dist/notifications/defaultNotifications/jamStarted/recipients.d.ts +16 -0
- package/dist/notifications/defaultNotifications/jamStarted/recipients.js +119 -0
- package/dist/notifications/helpers.js +6 -0
- package/dist/notifications/push.js +14 -3
- package/dist/posts/finders.d.ts +2 -0
- package/dist/posts/helpers/index.d.ts +8 -0
- package/dist/posts/helpers/index.js +9 -3
- package/dist/posts/mapping.d.ts +28 -0
- package/dist/posts/mutations.d.ts +11 -3
- package/dist/posts/mutations.js +34 -10
- package/dist/server/index.d.ts +1 -0
- package/dist/stats/mapping.d.ts +2 -0
- package/package.json +6 -6
package/dist/backups/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { spawn } from 'node:child_process';
|
|
|
4
4
|
import { emptyDir } from 'fs-extra';
|
|
5
5
|
import { join, sep, isAbsolute } from 'node:path';
|
|
6
6
|
import { tmpdir } from 'node:os';
|
|
7
|
-
import
|
|
7
|
+
import { ZipArchive } from 'archiver';
|
|
8
8
|
import { extractWithNodeStreamZip } from './extractWithNodeStreamZip.js';
|
|
9
9
|
import { collectionInfos } from '../db/index.js';
|
|
10
10
|
import { communityConfig, config, defaultConfig } from '../config/index.js';
|
|
@@ -96,7 +96,7 @@ const hostnameFromServerHost = (host) => {
|
|
|
96
96
|
};
|
|
97
97
|
const zipDirectory = (sourceDir, zipPath) => new Promise((resolve, reject) => {
|
|
98
98
|
const output = createWriteStream(zipPath);
|
|
99
|
-
const archive =
|
|
99
|
+
const archive = new ZipArchive({ zlib: { level: 9 } });
|
|
100
100
|
output.on('close', () => resolve());
|
|
101
101
|
output.on('error', reject);
|
|
102
102
|
archive.on('error', reject);
|
package/dist/config/index.d.ts
CHANGED
package/dist/jams/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AuthorizationData, MuteParticipantRequest, PostWithMeta, Profile } from '@openpeepshq/common/types';
|
|
2
2
|
export { createJamToken, createJamEgressToken } from './token';
|
|
3
3
|
export { diagnoseLivekit, isLivekitConnected } from './health';
|
|
4
4
|
export { startRecording, stopRecording, startRtmpStream, stopRtmpStream, stopEgress, listParticipantIds, reclaimOrphanJamRoom, finishRecording, getJamRecordingUrl, getJamObserverPath, JAM_ROOM_EMPTY_TIMEOUT_SEC, JAM_ROOM_DEPARTURE_TIMEOUT_SEC, } from './livekit';
|
|
@@ -16,3 +16,16 @@ export declare const closeJam: (profile: Profile, jamEvent: PostWithMeta, recurr
|
|
|
16
16
|
export declare const muteParticipant: (jamId: string, data: MuteParticipantRequest, recurrenceId?: string) => Promise<{
|
|
17
17
|
success: boolean;
|
|
18
18
|
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Bans a removed profile from rejoining, evicts them now, and records the kick.
|
|
21
|
+
*
|
|
22
|
+
* (a) The ban persist happens before the eviction on purpose: the eviction is
|
|
23
|
+
* best-effort (its failure is swallowed below), but the ban is not — the
|
|
24
|
+
* profile must be locked out even if LiveKit is unreachable.
|
|
25
|
+
* (b) An already-banned target skips only the persist: the waiting-room
|
|
26
|
+
* admittance clear, the eviction attempt, and the `kicked` record still run,
|
|
27
|
+
* so a pending admittee is not left stranded.
|
|
28
|
+
*/
|
|
29
|
+
export declare const removeParticipant: (jamEvent: PostWithMeta, profileId: string, recurrenceId?: string) => Promise<void>;
|
|
30
|
+
/** Lifts a ban; the profile simply becomes able to rejoin again. */
|
|
31
|
+
export declare const liftJamBan: (jamEvent: PostWithMeta, profileId: string) => Promise<void>;
|
package/dist/jams/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { jamRoomName, postIdFromJamRoomName, uniquePostsById, } from '@openpeepshq/common/lib';
|
|
1
|
+
import { jamFromEvent, jamRoomName, postIdFromJamRoomName, uniquePostsById, } from '@openpeepshq/common/lib';
|
|
2
2
|
import { listParticipantIds, reclaimOrphanJamRoom, roomService, shouldReclaimJamRoom, stopRecording, stopRtmpStream, } from './livekit.js';
|
|
3
3
|
import { jamStateCache, LIVE_JAMS_CACHE_KEY, liveJamPostsCache } from './cache.js';
|
|
4
4
|
import { localInstanceDomain, parseRoomInstanceDomain } from './helpers.js';
|
|
5
5
|
import { findPost } from '../posts/index.js';
|
|
6
|
+
import { allpeepDb } from '../db/index.js';
|
|
6
7
|
import { createJamEvent } from './mutations.js';
|
|
8
|
+
import { postsMapping } from '../posts/mapping.js';
|
|
7
9
|
import { clearJamAdmittance } from './waitingRoom.js';
|
|
10
|
+
import { hub } from '../events/index.js';
|
|
8
11
|
import { uuidv7 } from 'uuidv7';
|
|
9
12
|
import { canReadPost } from '../posts/helpers/index.js';
|
|
10
13
|
import { capabilitiesConfig } from '../config/index.js';
|
|
@@ -27,6 +30,29 @@ const invalidateJamCaches = async (jamId) => {
|
|
|
27
30
|
liveJamPostsCache.del(LIVE_JAMS_CACHE_KEY).catch(() => undefined),
|
|
28
31
|
]);
|
|
29
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Shared persist-and-notify step for the two jam-config ban mutations
|
|
35
|
+
* ({@link removeParticipant} and {@link liftJamBan}): writes the jam's new
|
|
36
|
+
* `banned` list to the post, invalidates the live-jam caches, and re-broadcasts
|
|
37
|
+
* the fresh post to the moderators. Both paths must keep doing all three —
|
|
38
|
+
* dropping the cache invalidation here would be the drift this exists to
|
|
39
|
+
* prevent.
|
|
40
|
+
*/
|
|
41
|
+
const persistJamBannedList = async (jamEvent, jam, banned) => {
|
|
42
|
+
const { db } = await allpeepDb();
|
|
43
|
+
await postsMapping.update(db, jamEvent.id, {
|
|
44
|
+
data: {
|
|
45
|
+
...jamEvent.data,
|
|
46
|
+
type: 'event',
|
|
47
|
+
jam: { ...jam, banned },
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
const freshPost = await findPost(jamEvent.id);
|
|
51
|
+
await invalidateJamCaches(jamEvent.id);
|
|
52
|
+
if (freshPost) {
|
|
53
|
+
await hub.emit('postUpdated', freshPost, jam.moderators);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
30
56
|
const reclaimLocalOrphan = (post) => {
|
|
31
57
|
void reclaimOrphanJamRoom(post).then(() => invalidateJamCaches(post.id));
|
|
32
58
|
};
|
|
@@ -131,3 +157,51 @@ export const muteParticipant = async (jamId, data, recurrenceId) => {
|
|
|
131
157
|
}
|
|
132
158
|
return { success: result?.muted };
|
|
133
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Bans a removed profile from rejoining, evicts them now, and records the kick.
|
|
162
|
+
*
|
|
163
|
+
* (a) The ban persist happens before the eviction on purpose: the eviction is
|
|
164
|
+
* best-effort (its failure is swallowed below), but the ban is not — the
|
|
165
|
+
* profile must be locked out even if LiveKit is unreachable.
|
|
166
|
+
* (b) An already-banned target skips only the persist: the waiting-room
|
|
167
|
+
* admittance clear, the eviction attempt, and the `kicked` record still run,
|
|
168
|
+
* so a pending admittee is not left stranded.
|
|
169
|
+
*/
|
|
170
|
+
export const removeParticipant = async (jamEvent, profileId, recurrenceId) => {
|
|
171
|
+
const jam = jamFromEvent(jamEvent);
|
|
172
|
+
if (jam && !jam.banned?.includes(profileId)) {
|
|
173
|
+
await persistJamBannedList(jamEvent, jam, [
|
|
174
|
+
...(jam.banned ?? []),
|
|
175
|
+
profileId,
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
await clearJamAdmittance(jamEvent, recurrenceId, [profileId]);
|
|
179
|
+
const rs = await roomService();
|
|
180
|
+
if (rs !== undefined) {
|
|
181
|
+
try {
|
|
182
|
+
// LiveKit disconnects the participant with reason PARTICIPANT_REMOVED,
|
|
183
|
+
// which the client uses to show the removed-from-jam state.
|
|
184
|
+
await rs.removeParticipant(jamRoomName(jamEvent.id, recurrenceId), profileId);
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
// The participant may already have left the room; the ban persists.
|
|
188
|
+
log.debug(err, 'removeParticipant: LiveKit removal failed');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
await createJamEvent({
|
|
192
|
+
id: uuidv7(),
|
|
193
|
+
jamId: jamEvent.id,
|
|
194
|
+
type: 'kicked',
|
|
195
|
+
profileId,
|
|
196
|
+
recurrenceId,
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
/** Lifts a ban; the profile simply becomes able to rejoin again. */
|
|
200
|
+
export const liftJamBan = async (jamEvent, profileId) => {
|
|
201
|
+
const jam = jamFromEvent(jamEvent);
|
|
202
|
+
if (!jam?.banned?.includes(profileId)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const banned = jam.banned.filter((id) => id !== profileId);
|
|
206
|
+
await persistJamBannedList(jamEvent, jam, banned);
|
|
207
|
+
};
|
package/dist/jams/mapping.d.ts
CHANGED
|
@@ -7,37 +7,37 @@ type EdgeMetadata = {
|
|
|
7
7
|
export declare const jamEventsMapping: import("../db/pg/map").Mapping<{
|
|
8
8
|
id: string;
|
|
9
9
|
jamId: string;
|
|
10
|
-
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
10
|
+
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "kicked" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
11
11
|
profileId: string;
|
|
12
12
|
content?: string | undefined;
|
|
13
|
-
reaction?:
|
|
13
|
+
reaction?: string | undefined;
|
|
14
14
|
recurrenceId?: string | undefined;
|
|
15
15
|
}, JamEvent, JamEvent>;
|
|
16
16
|
export declare const jamSessionStartsMapping: import("../db/pg/map").Mapping<{
|
|
17
17
|
id: string;
|
|
18
18
|
jamId: string;
|
|
19
|
-
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
19
|
+
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "kicked" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
20
20
|
profileId: string;
|
|
21
21
|
content?: string | undefined;
|
|
22
|
-
reaction?:
|
|
22
|
+
reaction?: string | undefined;
|
|
23
23
|
recurrenceId?: string | undefined;
|
|
24
24
|
}, JamEvent, JamEvent>;
|
|
25
25
|
export declare const jamSessionClosesMapping: import("../db/pg/map").Mapping<{
|
|
26
26
|
id: string;
|
|
27
27
|
jamId: string;
|
|
28
|
-
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
28
|
+
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "kicked" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
29
29
|
profileId: string;
|
|
30
30
|
content?: string | undefined;
|
|
31
|
-
reaction?:
|
|
31
|
+
reaction?: string | undefined;
|
|
32
32
|
recurrenceId?: string | undefined;
|
|
33
33
|
}, JamEvent, JamEvent>;
|
|
34
34
|
export declare const jamParticipantsMapping: import("../db/pg/map").Mapping<{
|
|
35
35
|
id: string;
|
|
36
36
|
jamId: string;
|
|
37
|
-
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
37
|
+
type: "message" | "join" | "close" | "reaction" | "start" | "leave" | "kicked" | "recordStart" | "recordStop" | "streamStart" | "streamStop";
|
|
38
38
|
profileId: string;
|
|
39
39
|
content?: string | undefined;
|
|
40
|
-
reaction?:
|
|
40
|
+
reaction?: string | undefined;
|
|
41
41
|
recurrenceId?: string | undefined;
|
|
42
42
|
}, JamEvent, JamEvent>;
|
|
43
43
|
export declare const jamRecordingRelation: RelationWithMapping<PostWithMeta, JamRecording>;
|
package/dist/jams/token.js
CHANGED
|
@@ -71,6 +71,9 @@ export const createJamToken = async (event, profile, { external = false, recurre
|
|
|
71
71
|
if (joiner && isBlockedPair(joiner, event.profile?.id)) {
|
|
72
72
|
throw notFound({ errorKey: 'error.jamNotFound', parameters: { jamId } });
|
|
73
73
|
}
|
|
74
|
+
if (jam?.banned?.includes(profile.id)) {
|
|
75
|
+
throw forbidden({ errorKey: 'error.jamBanned' });
|
|
76
|
+
}
|
|
74
77
|
assertJamRsvpAllowed(event, profile, recurrenceId);
|
|
75
78
|
const rs = await roomService();
|
|
76
79
|
if (rs === undefined) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type JamWaitingRoomEntry, type PublicProfile, type PostWithMeta } from '@openpeepshq/common/types';
|
|
2
2
|
export declare const isAdmittedToJam: (event: PostWithMeta, profileId: string, recurrenceId?: string) => Promise<boolean>;
|
|
3
|
-
export declare const clearJamAdmittance: (event: PostWithMeta, recurrenceId?: string) => Promise<void>;
|
|
3
|
+
export declare const clearJamAdmittance: (event: PostWithMeta, recurrenceId?: string, onlyProfileIds?: string[]) => Promise<void>;
|
|
4
4
|
export declare const currentWaitingRoomWatch: (jamEvent: PostWithMeta, onChange: (waitingRoom: Record<string, JamWaitingRoomEntry>) => void | Promise<void>, recurrenceId?: string) => Promise<() => Promise<void>>;
|
|
5
5
|
export declare const admittanceWatch: (jamEvent: PostWithMeta, profileId: string, onToken: (token: string) => Promise<void> | void, recurrenceId?: string) => Promise<() => Promise<void>>;
|
|
6
6
|
export declare const joinWaitingRoom: (event: PostWithMeta, profile: PublicProfile, recurrenceId?: string) => Promise<void>;
|
package/dist/jams/waitingRoom.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jamRoomName } from '@openpeepshq/common/lib';
|
|
2
2
|
import { jamWaitingRoomEntrySchema, } from '@openpeepshq/common/types';
|
|
3
|
+
import { forbidden } from '../errors/index.js';
|
|
3
4
|
import { assertJamRsvpAllowed, createJamToken } from './token.js';
|
|
4
5
|
import { disconnect, getConnection, getSharedConnection, } from '../redis/connection.js';
|
|
5
6
|
import { getProfile } from '../profiles/index.js';
|
|
@@ -18,7 +19,17 @@ export const isAdmittedToJam = async (event, profileId, recurrenceId) => {
|
|
|
18
19
|
const conn = await getSharedConnection();
|
|
19
20
|
return Boolean(await conn.hExists(admittanceKey(event, recurrenceId), profileId));
|
|
20
21
|
};
|
|
21
|
-
export const clearJamAdmittance = async (event, recurrenceId) => {
|
|
22
|
+
export const clearJamAdmittance = async (event, recurrenceId, onlyProfileIds) => {
|
|
23
|
+
if (onlyProfileIds !== undefined) {
|
|
24
|
+
// Per-profile path: an explicit (possibly empty) id set must never fall
|
|
25
|
+
// through to the wipe-everything del() below, so `[]` is a no-op.
|
|
26
|
+
if (onlyProfileIds.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
await getSharedConnection().then((conn) =>
|
|
29
|
+
// ioredis flattens an array field at the protocol level.
|
|
30
|
+
conn.hDel(admittanceKey(event, recurrenceId), onlyProfileIds));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
22
33
|
await getSharedConnection().then((conn) => conn.del(admittanceKey(event, recurrenceId)));
|
|
23
34
|
};
|
|
24
35
|
export const currentWaitingRoomWatch = (jamEvent, onChange, recurrenceId) => currentWaitingRoom(jamEvent, recurrenceId)
|
|
@@ -53,6 +64,13 @@ export const admittanceWatch = (jamEvent, profileId, onToken, recurrenceId) => c
|
|
|
53
64
|
await disconnect(conn);
|
|
54
65
|
}));
|
|
55
66
|
export const joinWaitingRoom = async (event, profile, recurrenceId) => {
|
|
67
|
+
// A removed (banned) profile must not be able to queue at all — mirroring
|
|
68
|
+
// the `createJamToken` gate, so the refusal happens up front instead of at
|
|
69
|
+
// the moderator's later "admit" click.
|
|
70
|
+
const jam = event.data?.type === 'event' ? event.data?.jam : undefined;
|
|
71
|
+
if (jam?.banned?.includes(profile.id)) {
|
|
72
|
+
throw forbidden({ errorKey: 'error.jamBanned' });
|
|
73
|
+
}
|
|
56
74
|
assertJamRsvpAllowed(event, profile, recurrenceId);
|
|
57
75
|
const conn = await getSharedConnection();
|
|
58
76
|
const wrKey = waitingRoomKey(event, recurrenceId);
|
package/dist/log/retention.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createReadStream, createWriteStream } from 'node:fs';
|
|
2
2
|
import { readdir, rm, stat } from 'node:fs/promises';
|
|
3
3
|
import { basename, join } from 'node:path';
|
|
4
|
-
import
|
|
4
|
+
import { ZipArchive } from 'archiver';
|
|
5
5
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
6
6
|
/** Daily log file as written by the logger, e.g. `20261001.log`. */
|
|
7
7
|
const RAW_LOG_FILE = /^\d{8}\.log$/;
|
|
@@ -18,7 +18,7 @@ const fileExists = async (path) => {
|
|
|
18
18
|
};
|
|
19
19
|
const zipLogFile = (file, zipPath) => new Promise((resolve, reject) => {
|
|
20
20
|
const output = createWriteStream(zipPath);
|
|
21
|
-
const archive =
|
|
21
|
+
const archive = new ZipArchive({ zlib: { level: 9 } });
|
|
22
22
|
output.on('close', () => resolve());
|
|
23
23
|
output.on('error', reject);
|
|
24
24
|
archive.on('error', reject);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { listProfiles, listGroupMembers, findProfile, } from '@openpeepshq/core/profiles';
|
|
2
1
|
import { maybeCreateNotification } from '@openpeepshq/core/notifications';
|
|
3
2
|
import { getJamUrl, occurrenceForJamStart, profileName, } from '@openpeepshq/common/lib';
|
|
4
3
|
import { listJamStarts } from '../../../jams/finders.js';
|
|
5
4
|
import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
|
|
5
|
+
import { jamStartAudience } from './recipients.js';
|
|
6
6
|
// The start row is written in the same request, then the notification is
|
|
7
7
|
// queued. They are not linked by id, so match on time.
|
|
8
8
|
const START_MATCH_WINDOW_MS = 15 * 60 * 1000;
|
|
@@ -34,51 +34,16 @@ const eventHandler = async (...args) => {
|
|
|
34
34
|
if (!jam) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const notify = (recipientProfile) => maybeCreateNotification(recipientProfile, {
|
|
37
|
+
const notify = (recipientProfile, groupId) => maybeCreateNotification(recipientProfile, {
|
|
38
38
|
type: 'jamStarted',
|
|
39
39
|
fromProfileId: profile.id,
|
|
40
40
|
postId: post.id,
|
|
41
|
+
...(groupId ? { groupId } : {}),
|
|
41
42
|
...(recurrenceId ? { data: { recurrenceId } } : {}),
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
-
for (const recipientProfile of await listProfiles()) {
|
|
45
|
-
if (profile.id !== recipientProfile?.id) {
|
|
46
|
-
await notify(recipientProfile);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const recipients = new Set();
|
|
52
|
-
const skipRecipient = (recipient) => !profile ||
|
|
53
|
-
!recipient ||
|
|
54
|
-
profile.id === recipient?.id ||
|
|
55
|
-
recipients.has(recipient);
|
|
56
|
-
if (jam.moderators) {
|
|
57
|
-
for (const id of [...jam.moderators, ...(jam.speakers || [])]) {
|
|
58
|
-
const moderatorProfile = await findProfile(id);
|
|
59
|
-
if (skipRecipient(moderatorProfile))
|
|
60
|
-
continue;
|
|
61
|
-
recipients.add(moderatorProfile);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (post.audience) {
|
|
65
|
-
for (const audience of post.audience) {
|
|
66
|
-
const audienceProfile = await findProfile(audience?.id);
|
|
67
|
-
if (skipRecipient(audienceProfile))
|
|
68
|
-
continue;
|
|
69
|
-
recipients.add(audienceProfile);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (post.visibility === 'group' && post.group) {
|
|
73
|
-
for (const { profile: recipient } of await listGroupMembers(post.group)) {
|
|
74
|
-
const recipientProfile = await findProfile(recipient?.id);
|
|
75
|
-
if (skipRecipient(recipientProfile))
|
|
76
|
-
continue;
|
|
77
|
-
recipients.add(recipientProfile);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
44
|
+
const { profiles: recipients, groupId } = await jamStartAudience(profile, post, recurrenceId);
|
|
80
45
|
for (const recipientProfile of recipients) {
|
|
81
|
-
await notify(recipientProfile);
|
|
46
|
+
await notify(recipientProfile, groupId);
|
|
82
47
|
}
|
|
83
48
|
};
|
|
84
49
|
const expander = async (notification) => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PostWithMeta, ProfileWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
export interface JamStartAudience {
|
|
3
|
+
profiles: ProfileWithMeta[];
|
|
4
|
+
groupId?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Recipients for a "started a jam" alert. Community-wide jams (public/local)
|
|
8
|
+
* only broadcast when the creator opted in; group and direct jams notify
|
|
9
|
+
* their own audience and the designated moderators/speakers by default. The
|
|
10
|
+
* group notification level then applies: `off` silences the group's jams
|
|
11
|
+
* (including for designated moderators/speakers, which the delivery pipeline
|
|
12
|
+
* drops), `mostRelevant` keeps members with an RSVP (yes/maybe) to this event
|
|
13
|
+
* plus designated moderators/speakers, which the delivery pipeline defers to
|
|
14
|
+
* this handler for.
|
|
15
|
+
*/
|
|
16
|
+
export declare const jamStartAudience: (creator: ProfileWithMeta, post: PostWithMeta, recurrenceId: string | undefined) => Promise<JamStartAudience>;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { calculateEffectiveRsvps, occurrenceForJamStart, } from '@openpeepshq/common/lib';
|
|
2
|
+
import { findProfile, listProfiles, listGroupMembers, } from '@openpeepshq/core/profiles';
|
|
3
|
+
import { findProfileSettings } from '../../../profileSettings/index.js';
|
|
4
|
+
import { groupNotificationLevelFor } from '../../helpers.js';
|
|
5
|
+
const yesOrMaybe = (response) => response === 'yes' || response === 'tentative';
|
|
6
|
+
/** Effective (yes/maybe) RSVP profile ids for the jam occurrence being opened. */
|
|
7
|
+
const rsvpedProfileIds = (post, recurrenceId) => {
|
|
8
|
+
// `post.data` is narrowed to the event discriminant by the caller.
|
|
9
|
+
const occurrence = occurrenceForJamStart(post.data, {
|
|
10
|
+
recurrenceId,
|
|
11
|
+
});
|
|
12
|
+
return new Set(calculateEffectiveRsvps(post, occurrence?.recurrenceId)
|
|
13
|
+
.filter((rsvp) => yesOrMaybe(rsvp.response))
|
|
14
|
+
.map((rsvp) => rsvp.profile.id));
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Profiles the creator explicitly designated for the jam (moderators and
|
|
18
|
+
* speakers). They are offered to the audience builder unconditionally — the
|
|
19
|
+
* per-group level gate is applied later in the delivery pipeline
|
|
20
|
+
* (`maybeCreateNotification`), so a designated recipient whose group is `off`
|
|
21
|
+
* is still dropped there; at `mostRelevant` the pipeline defers to this
|
|
22
|
+
* handler for `jamStarted`, so a designated recipient passes. `known` is the
|
|
23
|
+
* set of audience profiles already loaded for this post, so a designated
|
|
24
|
+
* recipient who is also in the audience is not re-fetched; dedup against the
|
|
25
|
+
* accumulating audience happens in `jamStartAudience`'s `add`, which drops
|
|
26
|
+
* any profile already present.
|
|
27
|
+
*/
|
|
28
|
+
const designatedJamRecipients = async (jam, known) => {
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
const recipients = [];
|
|
31
|
+
for (const id of [...(jam.moderators ?? []), ...(jam.speakers ?? [])]) {
|
|
32
|
+
if (!id || seen.has(id))
|
|
33
|
+
continue;
|
|
34
|
+
seen.add(id);
|
|
35
|
+
const cached = known.get(id);
|
|
36
|
+
if (cached) {
|
|
37
|
+
recipients.push(cached);
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const profile = await findProfile(id);
|
|
41
|
+
if (profile)
|
|
42
|
+
recipients.push(profile);
|
|
43
|
+
}
|
|
44
|
+
return recipients;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Recipients for a "started a jam" alert. Community-wide jams (public/local)
|
|
48
|
+
* only broadcast when the creator opted in; group and direct jams notify
|
|
49
|
+
* their own audience and the designated moderators/speakers by default. The
|
|
50
|
+
* group notification level then applies: `off` silences the group's jams
|
|
51
|
+
* (including for designated moderators/speakers, which the delivery pipeline
|
|
52
|
+
* drops), `mostRelevant` keeps members with an RSVP (yes/maybe) to this event
|
|
53
|
+
* plus designated moderators/speakers, which the delivery pipeline defers to
|
|
54
|
+
* this handler for.
|
|
55
|
+
*/
|
|
56
|
+
export const jamStartAudience = async (creator, post, recurrenceId) => {
|
|
57
|
+
if (!post.data || post.data.type !== 'event')
|
|
58
|
+
return { profiles: [] };
|
|
59
|
+
const event = post.data;
|
|
60
|
+
const jam = event.jam;
|
|
61
|
+
if (!jam)
|
|
62
|
+
return { profiles: [] };
|
|
63
|
+
const groupId = post.group?.id;
|
|
64
|
+
if (['local', 'public'].includes(post.visibility)) {
|
|
65
|
+
if (!jam.notifyEveryone)
|
|
66
|
+
return { profiles: [] };
|
|
67
|
+
return {
|
|
68
|
+
profiles: (await listProfiles()).filter((candidate) => candidate && candidate.id !== creator.id),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
let audience = [];
|
|
72
|
+
if (post.visibility === 'group') {
|
|
73
|
+
if (!post.group)
|
|
74
|
+
return { profiles: [] };
|
|
75
|
+
for (const member of await listGroupMembers(post.group)) {
|
|
76
|
+
if (member.profile?.id)
|
|
77
|
+
audience.push(member.profile);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
for (const audienceEntry of post.audience ?? []) {
|
|
82
|
+
if (audienceEntry?.id)
|
|
83
|
+
audience.push(audienceEntry);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const profiles = [];
|
|
87
|
+
const add = (profile) => {
|
|
88
|
+
if (!profile || profile.id === creator.id)
|
|
89
|
+
return;
|
|
90
|
+
if (profiles.some((existing) => existing.id === profile.id))
|
|
91
|
+
return;
|
|
92
|
+
profiles.push(profile);
|
|
93
|
+
};
|
|
94
|
+
// Lazy: only members at `mostRelevant` consult the RSVP set. On the direct
|
|
95
|
+
// path the level is always `all` (no group), so it stays uncaptured — that
|
|
96
|
+
// holds because a post carrying `post.group` takes the group branch, so on
|
|
97
|
+
// the direct path `groupId` is undefined and `groupNotificationLevelFor`
|
|
98
|
+
// short-circuits to `all` before any level is looked up.
|
|
99
|
+
let rsvpedIds;
|
|
100
|
+
const hasRsvp = (profileId) => {
|
|
101
|
+
rsvpedIds ??= rsvpedProfileIds(post, recurrenceId);
|
|
102
|
+
return rsvpedIds.has(profileId);
|
|
103
|
+
};
|
|
104
|
+
for (const profile of audience) {
|
|
105
|
+
if (!profile || profile.id === creator.id)
|
|
106
|
+
continue;
|
|
107
|
+
const settings = await findProfileSettings(profile.id);
|
|
108
|
+
const level = groupNotificationLevelFor(settings, groupId);
|
|
109
|
+
if (level === 'off')
|
|
110
|
+
continue;
|
|
111
|
+
if (level === 'mostRelevant' && !hasRsvp(profile.id))
|
|
112
|
+
continue;
|
|
113
|
+
add(profile);
|
|
114
|
+
}
|
|
115
|
+
const loaded = new Map(audience.filter(Boolean).map((profile) => [profile.id, profile]));
|
|
116
|
+
for (const profile of await designatedJamRecipients(jam, loaded))
|
|
117
|
+
add(profile);
|
|
118
|
+
return { profiles, ...(groupId ? { groupId } : {}) };
|
|
119
|
+
};
|
|
@@ -16,6 +16,7 @@ const groupScopedNotificationTypes = [
|
|
|
16
16
|
'newGroupPost',
|
|
17
17
|
'groupMemberJoined',
|
|
18
18
|
'groupMemberLeft',
|
|
19
|
+
'jamStarted',
|
|
19
20
|
];
|
|
20
21
|
export const groupNotificationLevelFor = (profileSettings, groupId) => {
|
|
21
22
|
if (!groupId)
|
|
@@ -33,6 +34,11 @@ export const allowsGroupNotification = ({ level, type, followsAuthor, }) => {
|
|
|
33
34
|
if (level === 'off')
|
|
34
35
|
return false;
|
|
35
36
|
if (level === 'mostRelevant') {
|
|
37
|
+
// Jam-start alerts are RSVP-aware: the jamStarted handler only offers
|
|
38
|
+
// profiles with an effective RSVP, so anything reaching the gate counts
|
|
39
|
+
// as relevant.
|
|
40
|
+
if (type === 'jamStarted')
|
|
41
|
+
return true;
|
|
36
42
|
return type === 'newGroupPost' && followsAuthor;
|
|
37
43
|
}
|
|
38
44
|
return true;
|
|
@@ -6,7 +6,8 @@ import { logFailure, logStep } from '../jobs/index.js';
|
|
|
6
6
|
import { deletePushSubscription, listPushSubscriptionsByAccount, } from '../pushSubscriptions/index.js';
|
|
7
7
|
import { getNotificationStats } from './finders.js';
|
|
8
8
|
import { ApnsClient, Notification as IOSPushNotification } from 'apns2';
|
|
9
|
-
import
|
|
9
|
+
import { getApps } from 'firebase-admin/app';
|
|
10
|
+
import { getMessaging } from 'firebase-admin/messaging';
|
|
10
11
|
import { jwtUtil } from '../jwt/index.js';
|
|
11
12
|
import { uuidv7 } from 'uuidv7';
|
|
12
13
|
const log = logger('core:notifications:push');
|
|
@@ -27,6 +28,11 @@ const describeSubscription = (subscription) => {
|
|
|
27
28
|
return `web sub=${subscription.id} endpoint=${host}`;
|
|
28
29
|
}
|
|
29
30
|
case 'webhook':
|
|
31
|
+
// Intentionally prints the full URL: the webhook endpoint is the
|
|
32
|
+
// subscriber's own configured destination (their choice to expose), and
|
|
33
|
+
// shortening it would make delivery-failure logs impossible to
|
|
34
|
+
// correlate. The apn/fcm tokens below stay shortened because they are
|
|
35
|
+
// device credentials, not user-configured endpoints.
|
|
30
36
|
return `webhook sub=${subscription.id} url=${subscription.url}`;
|
|
31
37
|
case 'apn':
|
|
32
38
|
return `apn sub=${subscription.id} token=${shorten(subscription.apnToken)}`;
|
|
@@ -118,7 +124,7 @@ const sendAppFCMPushNotifications = async (subscriptions, payload, notification,
|
|
|
118
124
|
return;
|
|
119
125
|
const serializedPayload = JSON.stringify(payload);
|
|
120
126
|
const tokens = subscriptions.map((sub) => sub.fcmToken);
|
|
121
|
-
if (
|
|
127
|
+
if (getApps().length === 0) {
|
|
122
128
|
for (const subscription of subscriptions) {
|
|
123
129
|
await logFailure(jobLog, log, `FCM not initialized; skipping push to ${describeFcmTarget(account, subscription)}`);
|
|
124
130
|
}
|
|
@@ -129,7 +135,7 @@ const sendAppFCMPushNotifications = async (subscriptions, payload, notification,
|
|
|
129
135
|
}
|
|
130
136
|
let result;
|
|
131
137
|
try {
|
|
132
|
-
result = await
|
|
138
|
+
result = await getMessaging().sendEachForMulticast({
|
|
133
139
|
tokens,
|
|
134
140
|
data: { payload: serializedPayload },
|
|
135
141
|
apns: {
|
|
@@ -151,6 +157,11 @@ const sendAppFCMPushNotifications = async (subscriptions, payload, notification,
|
|
|
151
157
|
}
|
|
152
158
|
return;
|
|
153
159
|
}
|
|
160
|
+
// v14 surfaces per-token failures as `response.error` objects (firebase#3140).
|
|
161
|
+
// No extra v14-specific error mapping is intentionally added here:
|
|
162
|
+
// `formatErrorDetail` (jobLog) already extracts `code`/`statusCode`/`reason`
|
|
163
|
+
// from whatever error shape arrives, so v14's error codes reach the job log
|
|
164
|
+
// pre-formatted.
|
|
154
165
|
for (let i = 0; i < result.responses.length; i++) {
|
|
155
166
|
const response = result.responses[i];
|
|
156
167
|
const subscription = subscriptions[i];
|
package/dist/posts/finders.d.ts
CHANGED
|
@@ -145,10 +145,12 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
|
|
|
145
145
|
speakers?: string[] | undefined;
|
|
146
146
|
presenters?: string[] | undefined;
|
|
147
147
|
audience?: string[] | undefined;
|
|
148
|
+
banned?: string[] | undefined;
|
|
148
149
|
maxSpeakers?: number | undefined;
|
|
149
150
|
maxPresenters?: number | undefined;
|
|
150
151
|
maxAudience?: number | undefined;
|
|
151
152
|
waitingRoom?: boolean | undefined;
|
|
153
|
+
notifyEveryone?: boolean | undefined;
|
|
152
154
|
} | undefined;
|
|
153
155
|
physicalLocation?: {
|
|
154
156
|
text: string;
|
|
@@ -136,10 +136,12 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
|
|
|
136
136
|
speakers?: string[] | undefined;
|
|
137
137
|
presenters?: string[] | undefined;
|
|
138
138
|
audience?: string[] | undefined;
|
|
139
|
+
banned?: string[] | undefined;
|
|
139
140
|
maxSpeakers?: number | undefined;
|
|
140
141
|
maxPresenters?: number | undefined;
|
|
141
142
|
maxAudience?: number | undefined;
|
|
142
143
|
waitingRoom?: boolean | undefined;
|
|
144
|
+
notifyEveryone?: boolean | undefined;
|
|
143
145
|
} | undefined;
|
|
144
146
|
physicalLocation?: {
|
|
145
147
|
text: string;
|
|
@@ -370,10 +372,12 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
|
|
|
370
372
|
speakers?: string[] | undefined;
|
|
371
373
|
presenters?: string[] | undefined;
|
|
372
374
|
audience?: string[] | undefined;
|
|
375
|
+
banned?: string[] | undefined;
|
|
373
376
|
maxSpeakers?: number | undefined;
|
|
374
377
|
maxPresenters?: number | undefined;
|
|
375
378
|
maxAudience?: number | undefined;
|
|
376
379
|
waitingRoom?: boolean | undefined;
|
|
380
|
+
notifyEveryone?: boolean | undefined;
|
|
377
381
|
} | undefined;
|
|
378
382
|
physicalLocation?: {
|
|
379
383
|
text: string;
|
|
@@ -634,10 +638,12 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
|
|
|
634
638
|
speakers?: string[] | undefined;
|
|
635
639
|
presenters?: string[] | undefined;
|
|
636
640
|
audience?: string[] | undefined;
|
|
641
|
+
banned?: string[] | undefined;
|
|
637
642
|
maxSpeakers?: number | undefined;
|
|
638
643
|
maxPresenters?: number | undefined;
|
|
639
644
|
maxAudience?: number | undefined;
|
|
640
645
|
waitingRoom?: boolean | undefined;
|
|
646
|
+
notifyEveryone?: boolean | undefined;
|
|
641
647
|
} | undefined;
|
|
642
648
|
physicalLocation?: {
|
|
643
649
|
text: string;
|
|
@@ -868,10 +874,12 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
|
|
|
868
874
|
speakers?: string[] | undefined;
|
|
869
875
|
presenters?: string[] | undefined;
|
|
870
876
|
audience?: string[] | undefined;
|
|
877
|
+
banned?: string[] | undefined;
|
|
871
878
|
maxSpeakers?: number | undefined;
|
|
872
879
|
maxPresenters?: number | undefined;
|
|
873
880
|
maxAudience?: number | undefined;
|
|
874
881
|
waitingRoom?: boolean | undefined;
|
|
882
|
+
notifyEveryone?: boolean | undefined;
|
|
875
883
|
} | undefined;
|
|
876
884
|
physicalLocation?: {
|
|
877
885
|
text: string;
|
|
@@ -92,13 +92,19 @@ export const transformPost = async (post, currentProfile, options = {}) => {
|
|
|
92
92
|
? await Promise.all(post.entries.map(addProfileForEntry))
|
|
93
93
|
: [];
|
|
94
94
|
const entries = allEntries.filter((entry) => !isReactionHistoryEntry(entry.type));
|
|
95
|
-
//
|
|
96
|
-
//
|
|
95
|
+
// Legacy logs can carry malformed/empty reactions, so drop anything
|
|
96
|
+
// unusable before it can fail response validation. Reactions attached
|
|
97
|
+
// before a community removed them from its configured set (orphans) are
|
|
98
|
+
// intentionally kept — only new reactions are constrained by the write path.
|
|
97
99
|
const reactions = currentReactionsFromEntries(allEntries)
|
|
98
100
|
.filter((item) => isReactionType(item.reaction))
|
|
99
101
|
// Privacy boundary: hide reactions from blocked pairs (either direction),
|
|
100
102
|
// mirroring how blocked creators are tombstoned via withBlockTombstone.
|
|
101
|
-
.filter((item) => !currentProfile || !isBlockedPair(currentProfile, item.profile.id))
|
|
103
|
+
.filter((item) => !currentProfile || !isBlockedPair(currentProfile, item.profile.id))
|
|
104
|
+
.map((item) => ({
|
|
105
|
+
reaction: item.reaction,
|
|
106
|
+
profile: item.profile,
|
|
107
|
+
}));
|
|
102
108
|
const reposts = await leanRepostsFromWrappers(post.reposts);
|
|
103
109
|
const audience = post.audience
|
|
104
110
|
? (await Promise.all(post.audience.map((p) => loadPublicProfile(p.id)))).filter((profile) => !!profile)
|
package/dist/posts/mapping.d.ts
CHANGED
|
@@ -136,10 +136,12 @@ export declare const threadPreviewMappingForProfile: (profile?: {
|
|
|
136
136
|
speakers?: string[] | undefined;
|
|
137
137
|
presenters?: string[] | undefined;
|
|
138
138
|
audience?: string[] | undefined;
|
|
139
|
+
banned?: string[] | undefined;
|
|
139
140
|
maxSpeakers?: number | undefined;
|
|
140
141
|
maxPresenters?: number | undefined;
|
|
141
142
|
maxAudience?: number | undefined;
|
|
142
143
|
waitingRoom?: boolean | undefined;
|
|
144
|
+
notifyEveryone?: boolean | undefined;
|
|
143
145
|
} | undefined;
|
|
144
146
|
physicalLocation?: {
|
|
145
147
|
text: string;
|
|
@@ -382,10 +384,12 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
382
384
|
speakers?: string[] | undefined;
|
|
383
385
|
presenters?: string[] | undefined;
|
|
384
386
|
audience?: string[] | undefined;
|
|
387
|
+
banned?: string[] | undefined;
|
|
385
388
|
maxSpeakers?: number | undefined;
|
|
386
389
|
maxPresenters?: number | undefined;
|
|
387
390
|
maxAudience?: number | undefined;
|
|
388
391
|
waitingRoom?: boolean | undefined;
|
|
392
|
+
notifyEveryone?: boolean | undefined;
|
|
389
393
|
} | undefined;
|
|
390
394
|
physicalLocation?: {
|
|
391
395
|
text: string;
|
|
@@ -623,10 +627,12 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
623
627
|
speakers?: string[] | undefined;
|
|
624
628
|
presenters?: string[] | undefined;
|
|
625
629
|
audience?: string[] | undefined;
|
|
630
|
+
banned?: string[] | undefined;
|
|
626
631
|
maxSpeakers?: number | undefined;
|
|
627
632
|
maxPresenters?: number | undefined;
|
|
628
633
|
maxAudience?: number | undefined;
|
|
629
634
|
waitingRoom?: boolean | undefined;
|
|
635
|
+
notifyEveryone?: boolean | undefined;
|
|
630
636
|
} | undefined;
|
|
631
637
|
physicalLocation?: {
|
|
632
638
|
text: string;
|
|
@@ -868,10 +874,12 @@ export declare const postsWithReplyCountMapping: Mapping<{
|
|
|
868
874
|
speakers?: string[] | undefined;
|
|
869
875
|
presenters?: string[] | undefined;
|
|
870
876
|
audience?: string[] | undefined;
|
|
877
|
+
banned?: string[] | undefined;
|
|
871
878
|
maxSpeakers?: number | undefined;
|
|
872
879
|
maxPresenters?: number | undefined;
|
|
873
880
|
maxAudience?: number | undefined;
|
|
874
881
|
waitingRoom?: boolean | undefined;
|
|
882
|
+
notifyEveryone?: boolean | undefined;
|
|
875
883
|
} | undefined;
|
|
876
884
|
physicalLocation?: {
|
|
877
885
|
text: string;
|
|
@@ -1110,10 +1118,12 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1110
1118
|
speakers?: string[] | undefined;
|
|
1111
1119
|
presenters?: string[] | undefined;
|
|
1112
1120
|
audience?: string[] | undefined;
|
|
1121
|
+
banned?: string[] | undefined;
|
|
1113
1122
|
maxSpeakers?: number | undefined;
|
|
1114
1123
|
maxPresenters?: number | undefined;
|
|
1115
1124
|
maxAudience?: number | undefined;
|
|
1116
1125
|
waitingRoom?: boolean | undefined;
|
|
1126
|
+
notifyEveryone?: boolean | undefined;
|
|
1117
1127
|
} | undefined;
|
|
1118
1128
|
physicalLocation?: {
|
|
1119
1129
|
text: string;
|
|
@@ -1351,10 +1361,12 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1351
1361
|
speakers?: string[] | undefined;
|
|
1352
1362
|
presenters?: string[] | undefined;
|
|
1353
1363
|
audience?: string[] | undefined;
|
|
1364
|
+
banned?: string[] | undefined;
|
|
1354
1365
|
maxSpeakers?: number | undefined;
|
|
1355
1366
|
maxPresenters?: number | undefined;
|
|
1356
1367
|
maxAudience?: number | undefined;
|
|
1357
1368
|
waitingRoom?: boolean | undefined;
|
|
1369
|
+
notifyEveryone?: boolean | undefined;
|
|
1358
1370
|
} | undefined;
|
|
1359
1371
|
physicalLocation?: {
|
|
1360
1372
|
text: string;
|
|
@@ -1596,10 +1608,12 @@ export declare const postsWithReplyToCountMapping: Mapping<{
|
|
|
1596
1608
|
speakers?: string[] | undefined;
|
|
1597
1609
|
presenters?: string[] | undefined;
|
|
1598
1610
|
audience?: string[] | undefined;
|
|
1611
|
+
banned?: string[] | undefined;
|
|
1599
1612
|
maxSpeakers?: number | undefined;
|
|
1600
1613
|
maxPresenters?: number | undefined;
|
|
1601
1614
|
maxAudience?: number | undefined;
|
|
1602
1615
|
waitingRoom?: boolean | undefined;
|
|
1616
|
+
notifyEveryone?: boolean | undefined;
|
|
1603
1617
|
} | undefined;
|
|
1604
1618
|
physicalLocation?: {
|
|
1605
1619
|
text: string;
|
|
@@ -1838,10 +1852,12 @@ export declare const postsMapping: Mapping<{
|
|
|
1838
1852
|
speakers?: string[] | undefined;
|
|
1839
1853
|
presenters?: string[] | undefined;
|
|
1840
1854
|
audience?: string[] | undefined;
|
|
1855
|
+
banned?: string[] | undefined;
|
|
1841
1856
|
maxSpeakers?: number | undefined;
|
|
1842
1857
|
maxPresenters?: number | undefined;
|
|
1843
1858
|
maxAudience?: number | undefined;
|
|
1844
1859
|
waitingRoom?: boolean | undefined;
|
|
1860
|
+
notifyEveryone?: boolean | undefined;
|
|
1845
1861
|
} | undefined;
|
|
1846
1862
|
physicalLocation?: {
|
|
1847
1863
|
text: string;
|
|
@@ -2077,10 +2093,12 @@ export declare const postsAuthMapping: Mapping<{
|
|
|
2077
2093
|
speakers?: string[] | undefined;
|
|
2078
2094
|
presenters?: string[] | undefined;
|
|
2079
2095
|
audience?: string[] | undefined;
|
|
2096
|
+
banned?: string[] | undefined;
|
|
2080
2097
|
maxSpeakers?: number | undefined;
|
|
2081
2098
|
maxPresenters?: number | undefined;
|
|
2082
2099
|
maxAudience?: number | undefined;
|
|
2083
2100
|
waitingRoom?: boolean | undefined;
|
|
2101
|
+
notifyEveryone?: boolean | undefined;
|
|
2084
2102
|
} | undefined;
|
|
2085
2103
|
physicalLocation?: {
|
|
2086
2104
|
text: string;
|
|
@@ -2317,10 +2335,12 @@ export declare const postsMappingForProfile: (profile?: {
|
|
|
2317
2335
|
speakers?: string[] | undefined;
|
|
2318
2336
|
presenters?: string[] | undefined;
|
|
2319
2337
|
audience?: string[] | undefined;
|
|
2338
|
+
banned?: string[] | undefined;
|
|
2320
2339
|
maxSpeakers?: number | undefined;
|
|
2321
2340
|
maxPresenters?: number | undefined;
|
|
2322
2341
|
maxAudience?: number | undefined;
|
|
2323
2342
|
waitingRoom?: boolean | undefined;
|
|
2343
|
+
notifyEveryone?: boolean | undefined;
|
|
2324
2344
|
} | undefined;
|
|
2325
2345
|
physicalLocation?: {
|
|
2326
2346
|
text: string;
|
|
@@ -2557,10 +2577,12 @@ export declare const postContextMappingForProfile: (profile?: {
|
|
|
2557
2577
|
speakers?: string[] | undefined;
|
|
2558
2578
|
presenters?: string[] | undefined;
|
|
2559
2579
|
audience?: string[] | undefined;
|
|
2580
|
+
banned?: string[] | undefined;
|
|
2560
2581
|
maxSpeakers?: number | undefined;
|
|
2561
2582
|
maxPresenters?: number | undefined;
|
|
2562
2583
|
maxAudience?: number | undefined;
|
|
2563
2584
|
waitingRoom?: boolean | undefined;
|
|
2585
|
+
notifyEveryone?: boolean | undefined;
|
|
2564
2586
|
} | undefined;
|
|
2565
2587
|
physicalLocation?: {
|
|
2566
2588
|
text: string;
|
|
@@ -2796,10 +2818,12 @@ export declare const conversationLeavesMapping: Mapping<{
|
|
|
2796
2818
|
speakers?: string[] | undefined;
|
|
2797
2819
|
presenters?: string[] | undefined;
|
|
2798
2820
|
audience?: string[] | undefined;
|
|
2821
|
+
banned?: string[] | undefined;
|
|
2799
2822
|
maxSpeakers?: number | undefined;
|
|
2800
2823
|
maxPresenters?: number | undefined;
|
|
2801
2824
|
maxAudience?: number | undefined;
|
|
2802
2825
|
waitingRoom?: boolean | undefined;
|
|
2826
|
+
notifyEveryone?: boolean | undefined;
|
|
2803
2827
|
} | undefined;
|
|
2804
2828
|
physicalLocation?: {
|
|
2805
2829
|
text: string;
|
|
@@ -3036,10 +3060,12 @@ export declare const conversationLeavesMappingForProfile: (profile?: {
|
|
|
3036
3060
|
speakers?: string[] | undefined;
|
|
3037
3061
|
presenters?: string[] | undefined;
|
|
3038
3062
|
audience?: string[] | undefined;
|
|
3063
|
+
banned?: string[] | undefined;
|
|
3039
3064
|
maxSpeakers?: number | undefined;
|
|
3040
3065
|
maxPresenters?: number | undefined;
|
|
3041
3066
|
maxAudience?: number | undefined;
|
|
3042
3067
|
waitingRoom?: boolean | undefined;
|
|
3068
|
+
notifyEveryone?: boolean | undefined;
|
|
3043
3069
|
} | undefined;
|
|
3044
3070
|
physicalLocation?: {
|
|
3045
3071
|
text: string;
|
|
@@ -3274,10 +3300,12 @@ export declare const postIdsMapping: Mapping<{
|
|
|
3274
3300
|
speakers?: string[] | undefined;
|
|
3275
3301
|
presenters?: string[] | undefined;
|
|
3276
3302
|
audience?: string[] | undefined;
|
|
3303
|
+
banned?: string[] | undefined;
|
|
3277
3304
|
maxSpeakers?: number | undefined;
|
|
3278
3305
|
maxPresenters?: number | undefined;
|
|
3279
3306
|
maxAudience?: number | undefined;
|
|
3280
3307
|
waitingRoom?: boolean | undefined;
|
|
3308
|
+
notifyEveryone?: boolean | undefined;
|
|
3281
3309
|
} | undefined;
|
|
3282
3310
|
physicalLocation?: {
|
|
3283
3311
|
text: string;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { AuthorizationData, Answer, PostWithMeta, PostData, Profile, ProfileWithMeta, ReactionData, RsvpRequest, RsvpResponse } from '@openpeepshq/common/types';
|
|
1
|
+
import { AuthorizationData, Answer, PostWithMeta, PostData, Profile, ProfileWithMeta, ReactionData, Role, RsvpRequest, RsvpResponse } from '@openpeepshq/common/types';
|
|
2
2
|
import { PostDataUnion } from '@openpeepshq/common/types';
|
|
3
|
-
export declare const createPost: (data: PostDataUnion, profile: Profile
|
|
3
|
+
export declare const createPost: (data: PostDataUnion, profile: Profile & {
|
|
4
|
+
roles?: Role[];
|
|
5
|
+
}, postData: PostData, relations?: {
|
|
4
6
|
inReplyToId?: string | null;
|
|
5
7
|
repostId?: string;
|
|
6
8
|
audience?: Profile[] | null;
|
|
7
9
|
groupId?: string | null;
|
|
8
10
|
}) => Promise<PostWithMeta>;
|
|
9
|
-
export declare const updatePost: (post: PostWithMeta, profile: Profile
|
|
11
|
+
export declare const updatePost: (post: PostWithMeta, profile: Profile & {
|
|
12
|
+
roles?: Role[];
|
|
13
|
+
}, data: PostDataUnion) => Promise<PostWithMeta>;
|
|
10
14
|
export declare const reactToPost: (post: PostWithMeta, profile: Profile, data: ReactionData) => Promise<void>;
|
|
11
15
|
export declare const retractReaction: (post: PostWithMeta, profile: Profile, data: ReactionData) => Promise<import("../db/pg/map").WithId<({
|
|
12
16
|
type: "create";
|
|
@@ -133,10 +137,12 @@ export declare const retractReaction: (post: PostWithMeta, profile: Profile, dat
|
|
|
133
137
|
speakers?: string[] | undefined;
|
|
134
138
|
presenters?: string[] | undefined;
|
|
135
139
|
audience?: string[] | undefined;
|
|
140
|
+
banned?: string[] | undefined;
|
|
136
141
|
maxSpeakers?: number | undefined;
|
|
137
142
|
maxPresenters?: number | undefined;
|
|
138
143
|
maxAudience?: number | undefined;
|
|
139
144
|
waitingRoom?: boolean | undefined;
|
|
145
|
+
notifyEveryone?: boolean | undefined;
|
|
140
146
|
} | undefined;
|
|
141
147
|
physicalLocation?: {
|
|
142
148
|
text: string;
|
|
@@ -367,10 +373,12 @@ export declare const retractReaction: (post: PostWithMeta, profile: Profile, dat
|
|
|
367
373
|
speakers?: string[] | undefined;
|
|
368
374
|
presenters?: string[] | undefined;
|
|
369
375
|
audience?: string[] | undefined;
|
|
376
|
+
banned?: string[] | undefined;
|
|
370
377
|
maxSpeakers?: number | undefined;
|
|
371
378
|
maxPresenters?: number | undefined;
|
|
372
379
|
maxAudience?: number | undefined;
|
|
373
380
|
waitingRoom?: boolean | undefined;
|
|
381
|
+
notifyEveryone?: boolean | undefined;
|
|
374
382
|
} | undefined;
|
|
375
383
|
physicalLocation?: {
|
|
376
384
|
text: string;
|
package/dist/posts/mutations.js
CHANGED
|
@@ -13,7 +13,7 @@ import { profilesCache } from '../profiles/cache.js';
|
|
|
13
13
|
import { findOrCreateHashtag } from '../hashtags/index.js';
|
|
14
14
|
import { hub } from '../events/index.js';
|
|
15
15
|
import { listUnseenGroupPostIds } from './unseenCounts.js';
|
|
16
|
-
import { canManageEventRsvps, capacityRsvpDecision, eventDataForDbUpdate, getEffectiveRsvp, instanceRsvpIdsForProfile, isOneToOneDm, normalizeEventDataForSave, overlaySeriesRsvpEntries, participantIds, passThroughUndefined, rsvpCancelNotice, rsvpTargetsPastEvent, sameRecurrenceId, } from '@openpeepshq/common/lib';
|
|
16
|
+
import { canManageEventRsvps, capacityRsvpDecision, eventDataForDbUpdate, getEffectiveRsvp, instanceRsvpIdsForProfile, isOneToOneDm, normalizeEventDataForSave, overlaySeriesRsvpEntries, participantIds, passThroughUndefined, rsvpCancelNotice, rsvpTargetsPastEvent, sameRecurrenceId, withoutCommunityJamNotifyEveryone, } from '@openpeepshq/common/lib';
|
|
17
17
|
import { forbidden, notFound, unprocessableRequest } from '../errors/index.js';
|
|
18
18
|
import { areBlocked, hasBlockAmong } from '../profiles/blocks.js';
|
|
19
19
|
import { rebuildEventOccurrences, clearEventOccurrences, } from './eventOccurrences.js';
|
|
@@ -22,7 +22,11 @@ import { publishWaitlistPlans } from './waitlistOfferJobs.js';
|
|
|
22
22
|
import { capacitySyncTargets, syncCapacityOccurrences, withRsvpCapacityLock, } from './waitlist.js';
|
|
23
23
|
import { config } from '../config/index.js';
|
|
24
24
|
import { localObjectScalars } from '../federation/identity.js';
|
|
25
|
-
export const createPost = async (data,
|
|
25
|
+
export const createPost = async (data,
|
|
26
|
+
// Roles are present on server callers (`ensureLocalProfile`) and drive the
|
|
27
|
+
// broadcast-flag capability check; internal callers pass a plain Profile,
|
|
28
|
+
// for which the flag is stripped rather than broadcast.
|
|
29
|
+
profile, postData, relations = {}) => {
|
|
26
30
|
if (data.type === 'event') {
|
|
27
31
|
data = normalizeEventDataForSave(data);
|
|
28
32
|
}
|
|
@@ -59,6 +63,14 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
59
63
|
if (group) {
|
|
60
64
|
postData = { ...postData, visibility: 'group' };
|
|
61
65
|
}
|
|
66
|
+
// The broadcast flag survives only on community-wide posts created by a
|
|
67
|
+
// profile that can announce (same rule as the announce endpoint). Key off
|
|
68
|
+
// the post's own final visibility — the same field the notification handler
|
|
69
|
+
// reads — so a payload carrying `visibility: 'public'` plus a group can
|
|
70
|
+
// never keep a flag the jam-start path would treat as instance-wide.
|
|
71
|
+
if (data.type === 'event') {
|
|
72
|
+
data = withoutCommunityJamNotifyEveryone(data, postData.visibility, profile.roles);
|
|
73
|
+
}
|
|
62
74
|
const hashtags = extractHashtags(data);
|
|
63
75
|
const id = uuidv7();
|
|
64
76
|
const domain = (await config()).activityPub.defaultDomain;
|
|
@@ -122,7 +134,9 @@ export const createPost = async (data, profile, postData, relations = {}) => {
|
|
|
122
134
|
};
|
|
123
135
|
export const updatePost = async (post, profile, data) => {
|
|
124
136
|
const previousEvent = post.data?.type === 'event' ? post.data : undefined;
|
|
125
|
-
const normalized = data.type === 'event'
|
|
137
|
+
const normalized = data.type === 'event'
|
|
138
|
+
? withoutCommunityJamNotifyEveryone(normalizeEventDataForSave(data), post.visibility, profile.roles)
|
|
139
|
+
: data;
|
|
126
140
|
const dataForDb = normalized.type === 'event'
|
|
127
141
|
? eventDataForDbUpdate(previousEvent, normalized)
|
|
128
142
|
: normalized;
|
|
@@ -155,13 +169,23 @@ export const updatePost = async (post, profile, data) => {
|
|
|
155
169
|
hub.emit('postUpdated', newPost, previousEvent?.jam?.moderators ?? []);
|
|
156
170
|
return newPost;
|
|
157
171
|
};
|
|
158
|
-
export const reactToPost = async (post, profile, data) =>
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
172
|
+
export const reactToPost = async (post, profile, data) => {
|
|
173
|
+
// Idempotency: one reaction per emoji per profile. Tapping the same emoji
|
|
174
|
+
// twice (a second tab, a stale client, a client retry) must be a no-op —
|
|
175
|
+
// otherwise the entry is stored twice and each row fires `reactionCreated`,
|
|
176
|
+
// so the author gets a duplicate notification per extra tap. `post.reactions`
|
|
177
|
+
// is the latest-entry-per-(profile, emoji) view, already deduplicated.
|
|
178
|
+
const alreadyReacted = post.reactions.some((reaction) => reaction.profile.id === profile.id && reaction.reaction === data.reaction);
|
|
179
|
+
if (alreadyReacted)
|
|
180
|
+
return;
|
|
181
|
+
return allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
182
|
+
type: 'reaction',
|
|
183
|
+
data: { reaction: data.reaction },
|
|
184
|
+
}).then(() => hub.emit('reactionCreated', profile, post, {
|
|
185
|
+
type: 'reaction',
|
|
186
|
+
...data,
|
|
187
|
+
})));
|
|
188
|
+
};
|
|
165
189
|
export const retractReaction = async (post, profile, data) => allpeepDb().then(({ db }) => entryConnector(db, profile, post, {
|
|
166
190
|
type: 'unreaction',
|
|
167
191
|
data: { reaction: data.reaction },
|
package/dist/server/index.d.ts
CHANGED
package/dist/stats/mapping.d.ts
CHANGED
|
@@ -128,10 +128,12 @@ export declare const postsWithActivityScoreMapping: import("../db/pg/map").Mappi
|
|
|
128
128
|
speakers?: string[] | undefined;
|
|
129
129
|
presenters?: string[] | undefined;
|
|
130
130
|
audience?: string[] | undefined;
|
|
131
|
+
banned?: string[] | undefined;
|
|
131
132
|
maxSpeakers?: number | undefined;
|
|
132
133
|
maxPresenters?: number | undefined;
|
|
133
134
|
maxAudience?: number | undefined;
|
|
134
135
|
waitingRoom?: boolean | undefined;
|
|
136
|
+
notifyEveryone?: boolean | undefined;
|
|
135
137
|
} | undefined;
|
|
136
138
|
physicalLocation?: {
|
|
137
139
|
text: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"dependencies": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@keyv/redis": "^5.1.4",
|
|
9
9
|
"@sentry/node": "^10.78.0",
|
|
10
10
|
"apns2": "^12.2.0",
|
|
11
|
-
"archiver": "^
|
|
11
|
+
"archiver": "^8.0.0",
|
|
12
12
|
"bcrypt": "^5.1.1",
|
|
13
13
|
"bullmq": "^5.81.5",
|
|
14
14
|
"cache-manager": "^7.2.4",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"deepmerge-ts": "^8.0.2",
|
|
19
19
|
"dotenv": "^16.4.7",
|
|
20
20
|
"drizzle-orm": "^0.45.2",
|
|
21
|
-
"firebase-admin": "^
|
|
21
|
+
"firebase-admin": "^14.5.1",
|
|
22
22
|
"fluent-ffmpeg": "^2.1.3",
|
|
23
23
|
"fs-extra": "^11.3.0",
|
|
24
24
|
"html-to-text": "^9.0.5",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"type-fest": "^4.31.0",
|
|
38
38
|
"uuidv7": "^1.0.2",
|
|
39
39
|
"web-push": "^3.6.7",
|
|
40
|
-
"@openpeepshq/common": "0.
|
|
41
|
-
"@openpeepshq/i18n": "^0.13.0",
|
|
40
|
+
"@openpeepshq/common": "0.14.0",
|
|
42
41
|
"@openpeepshq/fetch-client": "^0.2.1",
|
|
42
|
+
"@openpeepshq/i18n": "^0.15.0",
|
|
43
43
|
"@openpeepshq/geocoder": "^0.1.2"
|
|
44
44
|
},
|
|
45
45
|
"main": "dist/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"/dist"
|
|
53
53
|
],
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@types/archiver": "^
|
|
55
|
+
"@types/archiver": "^8.0.0",
|
|
56
56
|
"@types/bcrypt": "^5.0.2",
|
|
57
57
|
"@types/express": "^5.0.6",
|
|
58
58
|
"@types/fluent-ffmpeg": "^2.1.27",
|