@openpeepshq/core 0.1.35 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accounts/mutations.js +9 -0
- package/dist/analytics/report.d.ts +1 -1
- package/dist/config/defaults/logs.d.ts +4 -0
- package/dist/config/defaults/logs.js +5 -0
- package/dist/config/index.d.ts +3 -328
- package/dist/db/explorer/index.d.ts +1 -1
- package/dist/db/explorer/index.js +1 -1
- package/dist/db/pg/filters/posts.js +1 -1
- package/dist/db/pg/map/registry.js +3 -2
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/jams/export.d.ts +2 -0
- package/dist/jams/export.js +5 -0
- package/dist/jams/finders.d.ts +1 -0
- package/dist/jams/finders.js +1 -0
- package/dist/jams/health.d.ts +23 -0
- package/dist/jams/health.js +79 -7
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/index.d.ts +1 -1
- package/dist/jams/index.js +10 -3
- package/dist/jams/livekit.d.ts +2 -2
- package/dist/jams/mapping.d.ts +10 -10
- package/dist/jams/mutations.d.ts +2 -2
- package/dist/jams/token.js +6 -2
- package/dist/jams/waitingRoom.js +3 -1
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.js +1 -0
- package/dist/log/retention.d.ts +9 -0
- package/dist/log/retention.js +83 -0
- package/dist/log/retentionJobs.d.ts +17 -0
- package/dist/log/retentionJobs.js +50 -0
- package/dist/media/garbageCollection.d.ts +109 -0
- package/dist/media/garbageCollection.js +603 -0
- package/dist/media/garbageCollectionJobs.d.ts +14 -0
- package/dist/media/garbageCollectionJobs.js +55 -0
- package/dist/media/index.d.ts +2 -0
- package/dist/media/index.js +91 -12
- package/dist/media/streaming.d.ts +2 -0
- package/dist/media/streaming.js +8 -0
- package/dist/mediaAttachments/mapping.d.ts +1 -1
- package/dist/notifications/defaultNotifications/index.js +2 -0
- package/dist/notifications/defaultNotifications/jamModerator/index.js +25 -16
- package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
- package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +1 -0
- package/dist/notifications/defaultNotifications/jamStarted/index.js +61 -13
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +3 -3
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
- package/dist/notifications/defaultNotifications/waitlistOffer/index.d.ts +24 -0
- package/dist/notifications/defaultNotifications/waitlistOffer/index.js +40 -0
- package/dist/notifications/eventIcsAttachment.d.ts +6 -0
- package/dist/notifications/eventIcsAttachment.js +32 -0
- package/dist/notifications/helpers.d.ts +11 -1
- package/dist/notifications/helpers.js +26 -0
- package/dist/notifications/index.d.ts +1 -1
- package/dist/notifications/index.js +1 -1
- package/dist/notifications/jobs.js +6 -0
- package/dist/notifications/mutations.js +9 -1
- package/dist/plugins/pluginAuth.js +1 -0
- package/dist/posts/activity.d.ts +1 -1
- package/dist/posts/activity.js +1 -1
- package/dist/posts/conversationQueries.d.ts +31 -0
- package/dist/posts/conversationQueries.js +150 -24
- package/dist/posts/eventAgenda.js +4 -2
- package/dist/posts/finders.d.ts +15 -6
- package/dist/posts/finders.js +23 -3
- package/dist/posts/helpers/index.d.ts +34 -26
- package/dist/posts/helpers/index.js +6 -0
- package/dist/posts/index.d.ts +3 -1
- package/dist/posts/index.js +3 -1
- package/dist/posts/mapping.d.ts +112 -98
- package/dist/posts/mutations.d.ts +24 -18
- package/dist/posts/mutations.js +222 -72
- package/dist/posts/rsvpExport.d.ts +47 -0
- package/dist/posts/rsvpExport.js +178 -0
- package/dist/posts/unseenCounts.d.ts +6 -0
- package/dist/posts/unseenCounts.js +51 -1
- package/dist/posts/waitlist.d.ts +13 -0
- package/dist/posts/waitlist.js +75 -0
- package/dist/posts/waitlistOfferJobs.d.ts +10 -0
- package/dist/posts/waitlistOfferJobs.js +91 -0
- package/dist/profileSettings/mapping.d.ts +1 -0
- package/dist/profiles/index.js +6 -1
- package/dist/profiles/mapping.d.ts +10 -10
- package/dist/reports/mapping.d.ts +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/stats/mapping.d.ts +7 -6
- package/dist/stripe/connection.js +1 -1
- package/dist/stripe/helpers.js +7 -3
- package/package.json +11 -10
package/dist/media/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import fs from 'node:fs/promises';
|
|
|
8
8
|
import { createReadStream, createWriteStream } from 'node:fs';
|
|
9
9
|
import { Readable } from 'node:stream';
|
|
10
10
|
import { pipeline } from 'node:stream/promises';
|
|
11
|
+
import { spawn } from 'node:child_process';
|
|
11
12
|
import { getTheme, randomString } from '@openpeepshq/common/lib';
|
|
12
13
|
import { logger } from '../log/index.js';
|
|
13
14
|
import { hub } from '../events/index.js';
|
|
@@ -130,17 +131,75 @@ const escapeXml = (value) => value
|
|
|
130
131
|
.replace(/</g, '<')
|
|
131
132
|
.replace(/>/g, '>')
|
|
132
133
|
.replace(/"/g, '"');
|
|
133
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Render the first page of a PDF to a WebP thumbnail via sharp. The prebuilt
|
|
136
|
+
* sharp binary bundles poppler, so PDF decoding is available without any extra
|
|
137
|
+
* system packages on Linux/musl (Alpine) and glibc.
|
|
138
|
+
*/
|
|
139
|
+
const createPdfPreview = async (inputPath) => {
|
|
134
140
|
const outputPath = join(tmpdir(), `preview-${randomString(16)}.webp`);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
await sharp(inputPath, { density: 150, pages: 1 })
|
|
142
|
+
.resize(previewMaxWidth)
|
|
143
|
+
.webp({ quality: 80 })
|
|
144
|
+
.toFile(outputPath);
|
|
145
|
+
return { path: outputPath, mimetype: 'image/webp' };
|
|
146
|
+
};
|
|
147
|
+
const OFFICE_DOC_EXTENSIONS = new Set([
|
|
148
|
+
'.docx',
|
|
149
|
+
'.doc',
|
|
150
|
+
'.xlsx',
|
|
151
|
+
'.xls',
|
|
152
|
+
'.pptx',
|
|
153
|
+
'.ppt',
|
|
154
|
+
'.odt',
|
|
155
|
+
'.ods',
|
|
156
|
+
'.odp',
|
|
157
|
+
]);
|
|
158
|
+
const isOfficeDocument = (originalName) => OFFICE_DOC_EXTENSIONS.has(path.extname(originalName).toLowerCase());
|
|
159
|
+
/**
|
|
160
|
+
* Convert an office document (docx/xlsx/pptx/etc.) to PDF using LibreOffice in
|
|
161
|
+
* headless mode. Returns the path to the generated PDF inside a temp directory
|
|
162
|
+
* the caller is responsible for cleaning up.
|
|
163
|
+
*/
|
|
164
|
+
const convertOfficeToPdf = async (inputPath, originalName) => {
|
|
165
|
+
const outputDir = join(tmpdir(), `office-${randomString(16)}`);
|
|
166
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
167
|
+
await new Promise((resolve, reject) => {
|
|
168
|
+
const proc = spawn('libreoffice', [
|
|
169
|
+
'--headless',
|
|
170
|
+
'--no-first-run',
|
|
171
|
+
'--nofirstwizard',
|
|
172
|
+
'--norestore',
|
|
173
|
+
'--nologging',
|
|
174
|
+
'--convert-to',
|
|
175
|
+
'pdf',
|
|
176
|
+
'--outdir',
|
|
177
|
+
outputDir,
|
|
178
|
+
inputPath,
|
|
179
|
+
], { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
180
|
+
let stderr = '';
|
|
181
|
+
proc.stderr?.setEncoding('utf8');
|
|
182
|
+
proc.stderr?.on('data', (chunk) => {
|
|
183
|
+
stderr += chunk;
|
|
184
|
+
});
|
|
185
|
+
proc.on('error', (err) => {
|
|
186
|
+
reject(err.code === 'ENOENT' ? new Error('libreoffice binary not found') : err);
|
|
187
|
+
});
|
|
188
|
+
proc.on('close', (code) => {
|
|
189
|
+
if (code === 0) {
|
|
190
|
+
resolve();
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
reject(new Error(`libreoffice conversion failed (exit ${code}): ${stderr}`));
|
|
194
|
+
}
|
|
195
|
+
});
|
|
143
196
|
});
|
|
197
|
+
const files = await fs.readdir(outputDir);
|
|
198
|
+
const pdfFile = files.find((f) => f.endsWith('.pdf'));
|
|
199
|
+
if (!pdfFile) {
|
|
200
|
+
throw new Error(`libreoffice did not produce a PDF for ${originalName}`);
|
|
201
|
+
}
|
|
202
|
+
return join(outputDir, pdfFile);
|
|
144
203
|
};
|
|
145
204
|
const createDocumentCardPreview = async (originalName) => {
|
|
146
205
|
const ext = (path.extname(originalName).replace('.', '') || 'FILE')
|
|
@@ -166,12 +225,30 @@ const createFilePreview = async (inputPath, mimetype, originalName) => {
|
|
|
166
225
|
return await createPdfPreview(inputPath);
|
|
167
226
|
}
|
|
168
227
|
catch {
|
|
169
|
-
//
|
|
228
|
+
// sharp PDF support may be missing; fall back to card preview below.
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (isOfficeDocument(originalName)) {
|
|
232
|
+
let pdfPath;
|
|
233
|
+
try {
|
|
234
|
+
pdfPath = await convertOfficeToPdf(inputPath, originalName);
|
|
235
|
+
return await createPdfPreview(pdfPath);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
239
|
+
log.warn(`Office document preview failed for ${originalName}: ${message}`);
|
|
240
|
+
}
|
|
241
|
+
finally {
|
|
242
|
+
if (pdfPath) {
|
|
243
|
+
await fs
|
|
244
|
+
.rm(path.dirname(pdfPath), { recursive: true, force: true })
|
|
245
|
+
.catch(() => undefined);
|
|
246
|
+
}
|
|
170
247
|
}
|
|
171
248
|
}
|
|
172
249
|
return createDocumentCardPreview(originalName);
|
|
173
250
|
};
|
|
174
|
-
const
|
|
251
|
+
const _getMediaDuration = (filePath) => new Promise((resolve, reject) => {
|
|
175
252
|
ffmpeg.ffprobe(filePath, (err, metadata) => {
|
|
176
253
|
if (err) {
|
|
177
254
|
reject(err);
|
|
@@ -291,7 +368,7 @@ const createVideoPreview = async (inputPath) => {
|
|
|
291
368
|
}
|
|
292
369
|
catch (error) {
|
|
293
370
|
await cleanup();
|
|
294
|
-
reject(new Error(`Error handling output file: ${error.message}`));
|
|
371
|
+
reject(new Error(`Error handling output file: ${error instanceof Error ? error.message : String(error)}`));
|
|
295
372
|
}
|
|
296
373
|
})
|
|
297
374
|
.on('error', async (error) => {
|
|
@@ -307,3 +384,5 @@ export * from './streaming.js';
|
|
|
307
384
|
export * from './streamingJobs.js';
|
|
308
385
|
export * from './streamingCleanupJobs.js';
|
|
309
386
|
export * from './streamingPrewarm.js';
|
|
387
|
+
export * from './garbageCollection.js';
|
|
388
|
+
export * from './garbageCollectionJobs.js';
|
|
@@ -53,6 +53,8 @@ export declare const ensureStreamDir: (storageId: string) => Promise<string>;
|
|
|
53
53
|
*/
|
|
54
54
|
export declare const recordStreamAccess: (storageId: string) => Promise<void>;
|
|
55
55
|
export declare const getStreamLastAccess: (storageId: string) => Promise<number | null>;
|
|
56
|
+
/** Drop the playback record for a source file that no longer exists. */
|
|
57
|
+
export declare const forgetStreamAccess: (storageId: string) => Promise<void>;
|
|
56
58
|
export interface CleanupResult {
|
|
57
59
|
deleted: string[];
|
|
58
60
|
kept: number;
|
package/dist/media/streaming.js
CHANGED
|
@@ -188,6 +188,14 @@ export const getStreamLastAccess = async (storageId) => {
|
|
|
188
188
|
const score = await conn.zScore(STREAM_ACCESS_KEY, storageId);
|
|
189
189
|
return typeof score === 'number' ? score : null;
|
|
190
190
|
};
|
|
191
|
+
/** Drop the playback record for a source file that no longer exists. */
|
|
192
|
+
export const forgetStreamAccess = async (storageId) => {
|
|
193
|
+
lastAccessWriteCache.delete(storageId);
|
|
194
|
+
if (!isValidStorageId(storageId))
|
|
195
|
+
return;
|
|
196
|
+
const conn = await getSharedConnection();
|
|
197
|
+
await conn.zRem(STREAM_ACCESS_KEY, storageId);
|
|
198
|
+
};
|
|
191
199
|
/**
|
|
192
200
|
* Deletes every stream directory whose Redis-recorded last-access time is
|
|
193
201
|
* older than `maxAgeMs`, or which has no Redis entry at all. A missing entry
|
|
@@ -16,6 +16,6 @@ export declare const mediaAttachmentsMapping: import("../db/pg/map").Mapping<{
|
|
|
16
16
|
};
|
|
17
17
|
description?: string | undefined;
|
|
18
18
|
blurhash?: string | undefined;
|
|
19
|
-
status?: "
|
|
19
|
+
status?: "failed" | "ready" | "processing" | undefined;
|
|
20
20
|
error?: string | undefined;
|
|
21
21
|
}, MediaAttachment, MediaAttachment>;
|
|
@@ -18,6 +18,7 @@ import { default as pollEnded } from './pollEnded/index.js';
|
|
|
18
18
|
import { default as newGroupPost } from './newGroupPost/index.js';
|
|
19
19
|
import { default as rsvp } from './rsvp/index.js';
|
|
20
20
|
import { default as rsvpCanceled } from './rsvpCanceled/index.js';
|
|
21
|
+
import { default as waitlistOffer } from './waitlistOffer/index.js';
|
|
21
22
|
const defaultNotificationsHandlers = [
|
|
22
23
|
announcement,
|
|
23
24
|
directMessage,
|
|
@@ -38,6 +39,7 @@ const defaultNotificationsHandlers = [
|
|
|
38
39
|
newGroupPost,
|
|
39
40
|
rsvp,
|
|
40
41
|
rsvpCanceled,
|
|
42
|
+
waitlistOffer,
|
|
41
43
|
];
|
|
42
44
|
export const defaultNotificationTypes = defaultNotificationsHandlers.map((handler) => pick(handler, 'type', 'requiredCapabilities', 'defaultSettings'));
|
|
43
45
|
export const registerDefaultNotifications = async () => {
|
|
@@ -2,26 +2,35 @@ import { notificationAll, } from '@openpeepshq/common/types';
|
|
|
2
2
|
import { findProfile } from '@openpeepshq/core/profiles';
|
|
3
3
|
import { maybeCreateNotification } from '@openpeepshq/core/notifications';
|
|
4
4
|
import { profileName } from '@openpeepshq/common/lib';
|
|
5
|
+
import { hub } from '../../../events/index.js';
|
|
5
6
|
import { initI18nEmailContext } from '../../../i18n/index.js';
|
|
6
7
|
import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const jam = post.data?.type === 'event'
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import { jamModeratorsToNotify } from './recipients.js';
|
|
9
|
+
const notifyModerators = async (post, alreadyInvited) => {
|
|
10
|
+
const jam = post.data?.type === 'event' ? post.data.jam : undefined;
|
|
11
|
+
const profileIds = jamModeratorsToNotify(jam?.moderators, post.profile.id, alreadyInvited);
|
|
12
|
+
for (const profileId of profileIds) {
|
|
13
|
+
const profile = await findProfile(profileId);
|
|
14
|
+
if (!profile)
|
|
15
|
+
continue;
|
|
16
|
+
await maybeCreateNotification(profile, {
|
|
17
|
+
type: 'jamModerator',
|
|
18
|
+
fromProfileId: post.profile.id,
|
|
19
|
+
postId: post.id,
|
|
20
|
+
});
|
|
12
21
|
}
|
|
13
|
-
if (jam.moderators)
|
|
14
|
-
for (const profileId of jam.moderators) {
|
|
15
|
-
const profile = await findProfile(profileId);
|
|
16
|
-
if (profile && post.profile.id !== profileId) {
|
|
17
|
-
await maybeCreateNotification(profile, {
|
|
18
|
-
type: 'jamModerator',
|
|
19
|
-
fromProfileId: post.profile.id,
|
|
20
|
-
postId: post.id,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
22
|
};
|
|
23
|
+
const eventHandler = async (eventData) => {
|
|
24
|
+
await notifyModerators(eventData, []);
|
|
25
|
+
};
|
|
26
|
+
/** Second arg is the moderator id list from before this save. */
|
|
27
|
+
const updatedHandler = async (postArg, previousArg) => {
|
|
28
|
+
const previous = Array.isArray(previousArg)
|
|
29
|
+
? previousArg.filter((id) => typeof id === 'string')
|
|
30
|
+
: [];
|
|
31
|
+
await notifyModerators(postArg, previous);
|
|
32
|
+
};
|
|
33
|
+
hub.once('postUpdated', updatedHandler);
|
|
25
34
|
const pushRenderer = async (notification) => {
|
|
26
35
|
const { t } = await initI18nEmailContext();
|
|
27
36
|
return {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Moderators who should get an invite: not the creator, and not already invited. */
|
|
2
|
+
export const jamModeratorsToNotify = (moderatorIds, creatorId, alreadyInvited = []) => {
|
|
3
|
+
const skip = new Set([creatorId, ...alreadyInvited]);
|
|
4
|
+
return [...new Set(moderatorIds ?? [])].filter((id) => id && !skip.has(id));
|
|
5
|
+
};
|
|
@@ -3,6 +3,7 @@ declare const _default: {
|
|
|
3
3
|
event: string;
|
|
4
4
|
type: string;
|
|
5
5
|
eventHandler: (...args: unknown[]) => Promise<void>;
|
|
6
|
+
expander: (notification: ExpandedNotification) => Promise<ExpandedNotification>;
|
|
6
7
|
pushRenderer: (notification: ExpandedNotification) => Promise<{
|
|
7
8
|
title: string;
|
|
8
9
|
options: {
|
|
@@ -1,21 +1,49 @@
|
|
|
1
1
|
import { listProfiles, listGroupMembers, findProfile, } from '@openpeepshq/core/profiles';
|
|
2
2
|
import { maybeCreateNotification } from '@openpeepshq/core/notifications';
|
|
3
|
-
import { profileName } from '@openpeepshq/common/lib';
|
|
3
|
+
import { getJamUrl, occurrenceForJamStart, profileName, } from '@openpeepshq/common/lib';
|
|
4
|
+
import { listJamStarts } from '../../../jams/finders.js';
|
|
4
5
|
import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
|
|
6
|
+
// The start row is written in the same request, then the notification is
|
|
7
|
+
// queued. They are not linked by id, so match on time.
|
|
8
|
+
const START_MATCH_WINDOW_MS = 15 * 60 * 1000;
|
|
9
|
+
const storedRecurrenceId = (data) => {
|
|
10
|
+
if (!data || typeof data !== 'object' || !('recurrenceId' in data)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const recurrenceId = data.recurrenceId;
|
|
14
|
+
return typeof recurrenceId === 'string' ? recurrenceId : undefined;
|
|
15
|
+
};
|
|
16
|
+
const recurrenceIdFromStart = async (postId, at) => {
|
|
17
|
+
const target = at.getTime();
|
|
18
|
+
let closest;
|
|
19
|
+
for (const start of await listJamStarts(postId)) {
|
|
20
|
+
if (!start.recurrenceId)
|
|
21
|
+
continue;
|
|
22
|
+
const delta = Math.abs(new Date(start.createdAt).getTime() - target);
|
|
23
|
+
if (!closest || delta < closest.delta) {
|
|
24
|
+
closest = { recurrenceId: start.recurrenceId, delta };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!closest || closest.delta > START_MATCH_WINDOW_MS)
|
|
28
|
+
return undefined;
|
|
29
|
+
return closest.recurrenceId;
|
|
30
|
+
};
|
|
5
31
|
const eventHandler = async (...args) => {
|
|
6
|
-
const [profile, post] = args;
|
|
32
|
+
const [profile, post, recurrenceId] = args;
|
|
7
33
|
const jam = post.data?.type === 'event' && post.data?.jam;
|
|
8
34
|
if (!jam) {
|
|
9
35
|
return;
|
|
10
36
|
}
|
|
37
|
+
const notify = (recipientProfile) => maybeCreateNotification(recipientProfile, {
|
|
38
|
+
type: 'jamStarted',
|
|
39
|
+
fromProfileId: profile.id,
|
|
40
|
+
postId: post.id,
|
|
41
|
+
...(recurrenceId ? { data: { recurrenceId } } : {}),
|
|
42
|
+
});
|
|
11
43
|
if (['local', 'public'].includes(post.visibility)) {
|
|
12
44
|
for (const recipientProfile of await listProfiles()) {
|
|
13
45
|
if (profile.id !== recipientProfile?.id) {
|
|
14
|
-
await
|
|
15
|
-
type: 'jamStarted',
|
|
16
|
-
fromProfileId: profile.id,
|
|
17
|
-
postId: post.id,
|
|
18
|
-
});
|
|
46
|
+
await notify(recipientProfile);
|
|
19
47
|
}
|
|
20
48
|
}
|
|
21
49
|
return;
|
|
@@ -50,12 +78,31 @@ const eventHandler = async (...args) => {
|
|
|
50
78
|
}
|
|
51
79
|
}
|
|
52
80
|
for (const recipientProfile of recipients) {
|
|
53
|
-
await
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
81
|
+
await notify(recipientProfile);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const expander = async (notification) => {
|
|
85
|
+
const post = notification.post;
|
|
86
|
+
if (!post || post.data?.type !== 'event' || !post.data.recurrence) {
|
|
87
|
+
return notification;
|
|
58
88
|
}
|
|
89
|
+
const at = new Date(notification.createdAt);
|
|
90
|
+
const occurrence = occurrenceForJamStart(post.data, {
|
|
91
|
+
recurrenceId: storedRecurrenceId(notification.data) ??
|
|
92
|
+
(await recurrenceIdFromStart(post.id, at)),
|
|
93
|
+
at,
|
|
94
|
+
});
|
|
95
|
+
if (!occurrence)
|
|
96
|
+
return notification;
|
|
97
|
+
return {
|
|
98
|
+
...notification,
|
|
99
|
+
post: {
|
|
100
|
+
...post,
|
|
101
|
+
occurrenceRecurrenceId: occurrence.recurrenceId,
|
|
102
|
+
occurrenceStart: occurrence.start,
|
|
103
|
+
...(occurrence.end ? { occurrenceEnd: occurrence.end } : {}),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
59
106
|
};
|
|
60
107
|
const pushRenderer = async (notification) => ({
|
|
61
108
|
title: `${profileName(notification.senderProfile)} started a jam`,
|
|
@@ -63,7 +110,7 @@ const pushRenderer = async (notification) => ({
|
|
|
63
110
|
body: notification.post?.data?.name,
|
|
64
111
|
actions: [
|
|
65
112
|
{
|
|
66
|
-
action: `goto
|
|
113
|
+
action: `goto:${getJamUrl(notification.post?.id ?? '', undefined, notification.post?.occurrenceRecurrenceId)}`,
|
|
67
114
|
title: 'Join Jam',
|
|
68
115
|
},
|
|
69
116
|
],
|
|
@@ -74,5 +121,6 @@ export default {
|
|
|
74
121
|
event: 'jamStarted',
|
|
75
122
|
type: 'jamStarted',
|
|
76
123
|
eventHandler,
|
|
124
|
+
expander,
|
|
77
125
|
pushRenderer,
|
|
78
126
|
};
|
|
@@ -4,15 +4,15 @@ import { maybeCreateNotification } from '@openpeepshq/core/notifications';
|
|
|
4
4
|
import { getGroupAvatar, profileName } from '@openpeepshq/common/lib';
|
|
5
5
|
import { communityConfig } from '../../../config/index.js';
|
|
6
6
|
import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
|
|
7
|
+
import { newGroupPostRecipients } from './recipients.js';
|
|
7
8
|
const eventHandler = async (data) => {
|
|
8
9
|
const post = data;
|
|
9
10
|
if (!post.group) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
12
13
|
const group = post.group;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
.filter((profile) => post.profile.id !== profile.id))) {
|
|
14
|
+
const members = (await listGroupMembers(group)).map((m) => m.profile);
|
|
15
|
+
for (const groupMember of newGroupPostRecipients(post, members)) {
|
|
16
16
|
await maybeCreateNotification(groupMember, {
|
|
17
17
|
type: 'newGroupPost',
|
|
18
18
|
fromProfileId: post.profile.id,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PostWithMeta } from '@openpeepshq/common/types';
|
|
2
|
+
/** Group members to notify. Skips the author and anyone already notified of the reply. */
|
|
3
|
+
export declare const newGroupPostRecipients: <T extends {
|
|
4
|
+
id: string;
|
|
5
|
+
}>(post: PostWithMeta, members: T[]) => T[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parent author already gets a reply notification for this post.
|
|
3
|
+
* Event replies and direct posts do not create one, so they still
|
|
4
|
+
* receive the group notification.
|
|
5
|
+
*/
|
|
6
|
+
const replyNotificationRecipientId = (post) => {
|
|
7
|
+
if (post.data?.type === 'event' || post.visibility === 'direct') {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (!post.inReplyToId) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const parentAuthorId = post.replyTo?.profile?.id ?? post.replyTo?.creatorId;
|
|
14
|
+
if (!parentAuthorId || parentAuthorId === post.profile.id) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return parentAuthorId;
|
|
18
|
+
};
|
|
19
|
+
/** Group members to notify. Skips the author and anyone already notified of the reply. */
|
|
20
|
+
export const newGroupPostRecipients = (post, members) => {
|
|
21
|
+
const parentAuthorId = replyNotificationRecipientId(post);
|
|
22
|
+
return members.filter((member) => member.id !== post.profile.id && member.id !== parentAuthorId);
|
|
23
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ExpandedNotification } from '@openpeepshq/common/types';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
type: string;
|
|
4
|
+
event: string;
|
|
5
|
+
defaultSettings: {
|
|
6
|
+
readonly create: true;
|
|
7
|
+
readonly push: true;
|
|
8
|
+
readonly email: true;
|
|
9
|
+
};
|
|
10
|
+
eventHandler: () => Promise<void>;
|
|
11
|
+
pushRenderer: (notification: ExpandedNotification) => Promise<{
|
|
12
|
+
title: string;
|
|
13
|
+
options: {
|
|
14
|
+
body: string;
|
|
15
|
+
icon: string;
|
|
16
|
+
actions: {
|
|
17
|
+
action: string;
|
|
18
|
+
title: string;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
invalidateQueries: string[][];
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { notificationAll, } from '@openpeepshq/common/types';
|
|
2
|
+
import { getProfileAvatar, isWaitlistOfferNotice, waitlistClaimPath, } from '@openpeepshq/common/lib';
|
|
3
|
+
import { communityConfig } from '../../../config/index.js';
|
|
4
|
+
import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
|
|
5
|
+
const eventHandler = async () => { };
|
|
6
|
+
const pushRenderer = async (notification) => {
|
|
7
|
+
const notice = isWaitlistOfferNotice(notification.data)
|
|
8
|
+
? notification.data
|
|
9
|
+
: undefined;
|
|
10
|
+
const eventName = notification.post?.data?.type === 'event'
|
|
11
|
+
? notification.post.data.name?.trim()
|
|
12
|
+
: undefined;
|
|
13
|
+
const path = notification.post
|
|
14
|
+
? waitlistClaimPath(notification.post.id, notice?.recurrenceId)
|
|
15
|
+
: '/notifications';
|
|
16
|
+
return {
|
|
17
|
+
title: 'A spot opened',
|
|
18
|
+
options: {
|
|
19
|
+
body: eventName
|
|
20
|
+
? `Claim your spot at ${eventName}`
|
|
21
|
+
: 'Claim your spot before the offer expires',
|
|
22
|
+
icon: getProfileAvatar(notification.senderProfile ?? notification.post?.profile, await communityConfig()),
|
|
23
|
+
actions: [
|
|
24
|
+
{
|
|
25
|
+
action: `goto:${path}`,
|
|
26
|
+
title: 'Claim spot',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
invalidateQueries: [PUSH_INVALIDATE.posts],
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export default {
|
|
34
|
+
type: 'waitlistOffer',
|
|
35
|
+
// Created directly when a seat is offered. The handler exists for push/email.
|
|
36
|
+
event: 'waitlistOffer',
|
|
37
|
+
defaultSettings: notificationAll,
|
|
38
|
+
eventHandler,
|
|
39
|
+
pushRenderer,
|
|
40
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { EmailAttachment, ExpandedNotification } from '@openpeepshq/common/types';
|
|
2
|
+
/**
|
|
3
|
+
* Calendar file so a notification email about an event can be added to a
|
|
4
|
+
* calendar. Non-event notifications return undefined.
|
|
5
|
+
*/
|
|
6
|
+
export declare const eventIcsEmailAttachment: (notification: ExpandedNotification, rootUrl: string) => EmailAttachment | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { buildEventIcs } from '@openpeepshq/common/lib';
|
|
2
|
+
const isEventPost = (post) => post?.type === 'event' && post.data?.type === 'event';
|
|
3
|
+
/** The event this notification is about: the post itself, or the post it reposts. */
|
|
4
|
+
const eventPostOf = (notification) => {
|
|
5
|
+
const post = notification.post;
|
|
6
|
+
if (!post)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (isEventPost(post))
|
|
9
|
+
return post;
|
|
10
|
+
if (isEventPost(post.repost))
|
|
11
|
+
return post.repost;
|
|
12
|
+
return undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Calendar file so a notification email about an event can be added to a
|
|
16
|
+
* calendar. Non-event notifications return undefined.
|
|
17
|
+
*/
|
|
18
|
+
export const eventIcsEmailAttachment = (notification, rootUrl) => {
|
|
19
|
+
const post = eventPostOf(notification);
|
|
20
|
+
if (!post)
|
|
21
|
+
return undefined;
|
|
22
|
+
const ics = buildEventIcs(post, {
|
|
23
|
+
postUrl: `${rootUrl}/posts/${post.id}`,
|
|
24
|
+
});
|
|
25
|
+
if (!ics)
|
|
26
|
+
return undefined;
|
|
27
|
+
return {
|
|
28
|
+
filename: 'event.ics',
|
|
29
|
+
content: ics,
|
|
30
|
+
contentType: 'text/calendar; method=PUBLISH; charset=utf-8',
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { NotificationData, ProfileWithMeta, ProfileNotificationSettings, ExpandedNotification, DbNotification, ProfileSettings } from '@openpeepshq/common/types';
|
|
1
|
+
import { NotificationData, ProfileWithMeta, ProfileNotificationSettings, ExpandedNotification, DbNotification, ProfileSettings, GroupNotificationLevel } from '@openpeepshq/common/types';
|
|
2
2
|
import type { Mapping } from '../db/pg/map';
|
|
3
3
|
export declare const baseListNotifications: (profile: ProfileWithMeta) => Mapping<NotificationData, DbNotification>;
|
|
4
4
|
export declare const notificationSettings: (profileSettings: ProfileSettings, type: NotificationData["type"]) => ProfileNotificationSettings;
|
|
5
|
+
export declare const groupNotificationLevelFor: (profileSettings: ProfileSettings | undefined, groupId?: string | null) => GroupNotificationLevel;
|
|
6
|
+
/**
|
|
7
|
+
* `mostRelevant` keeps posts from people the member follows. Membership
|
|
8
|
+
* changes are only included at `all` — there is no separate relevance rank.
|
|
9
|
+
*/
|
|
10
|
+
export declare const allowsGroupNotification: ({ level, type, followsAuthor, }: {
|
|
11
|
+
level: GroupNotificationLevel;
|
|
12
|
+
type: string;
|
|
13
|
+
followsAuthor: boolean;
|
|
14
|
+
}) => boolean;
|
|
5
15
|
export declare const expandNotification: (notification: DbNotification) => Promise<ExpandedNotification>;
|
|
6
16
|
export declare const unseenNotifications: (profile: ProfileWithMeta) => Promise<number>;
|
|
7
17
|
export declare const unreadNotifications: (profile: ProfileWithMeta) => Promise<number>;
|
|
@@ -11,6 +11,32 @@ export const baseListNotifications = (profile) => notificationsMapping.filter(no
|
|
|
11
11
|
export const notificationSettings = (profileSettings, type) => profileSettings?.notifications?.[type] ??
|
|
12
12
|
defaultNotificationTypes.find((t) => t.type === type)?.defaultSettings ??
|
|
13
13
|
notificationDefaults;
|
|
14
|
+
/** Group events a member can quiet without changing account-wide settings. */
|
|
15
|
+
const groupScopedNotificationTypes = [
|
|
16
|
+
'newGroupPost',
|
|
17
|
+
'groupMemberJoined',
|
|
18
|
+
'groupMemberLeft',
|
|
19
|
+
];
|
|
20
|
+
export const groupNotificationLevelFor = (profileSettings, groupId) => {
|
|
21
|
+
if (!groupId)
|
|
22
|
+
return 'all';
|
|
23
|
+
return profileSettings?.groupNotificationLevels?.[groupId] ?? 'all';
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* `mostRelevant` keeps posts from people the member follows. Membership
|
|
27
|
+
* changes are only included at `all` — there is no separate relevance rank.
|
|
28
|
+
*/
|
|
29
|
+
export const allowsGroupNotification = ({ level, type, followsAuthor, }) => {
|
|
30
|
+
if (!groupScopedNotificationTypes.includes(type)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
if (level === 'off')
|
|
34
|
+
return false;
|
|
35
|
+
if (level === 'mostRelevant') {
|
|
36
|
+
return type === 'newGroupPost' && followsAuthor;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
14
40
|
export const expandNotification = async (notification) => {
|
|
15
41
|
const intermediateNotification = {
|
|
16
42
|
...notification,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { maybeCreateNotification } from './mutations';
|
|
2
2
|
export { registerDefaultNotifications, defaultNotificationTypes, } from './defaultNotifications';
|
|
3
|
-
export { registerNotificationHandler, notificationHandlers
|
|
3
|
+
export { registerNotificationHandler, notificationHandlers } from './handlers';
|
|
4
4
|
export { notificationSettings } from './helpers';
|
|
5
5
|
export { sendTestPushNotification } from './push';
|
|
6
6
|
export { notificationQueue, notificationWorker } from './jobs';
|
|
@@ -6,7 +6,7 @@ import { initializeFirebase } from './firebase.js';
|
|
|
6
6
|
import { notificationQueue } from './jobs.js';
|
|
7
7
|
export { maybeCreateNotification } from './mutations.js';
|
|
8
8
|
export { registerDefaultNotifications, defaultNotificationTypes, } from './defaultNotifications/index.js';
|
|
9
|
-
export { registerNotificationHandler, notificationHandlers
|
|
9
|
+
export { registerNotificationHandler, notificationHandlers } from './handlers.js';
|
|
10
10
|
export { notificationSettings } from './helpers.js';
|
|
11
11
|
export { sendTestPushNotification } from './push.js';
|
|
12
12
|
export { notificationQueue, notificationWorker } from './jobs.js';
|
|
@@ -10,6 +10,8 @@ import { getNotificationStats } from './finders.js';
|
|
|
10
10
|
import { findProfileSettings } from '../profileSettings/index.js';
|
|
11
11
|
import { logger } from '../log/index.js';
|
|
12
12
|
import { publishSessionEvent } from '../session/index.js';
|
|
13
|
+
import { serverRootUrl } from '../server/index.js';
|
|
14
|
+
import { eventIcsEmailAttachment } from './eventIcsAttachment.js';
|
|
13
15
|
const log = logger('core:notifications:worker');
|
|
14
16
|
const [notificationQueue, notificationWorker] = queueAndWorker('process-notification', async (job) => {
|
|
15
17
|
const notification = job.data;
|
|
@@ -30,6 +32,9 @@ const [notificationQueue, notificationWorker] = queueAndWorker('process-notifica
|
|
|
30
32
|
const { push, email } = notificationSettings(profileSettings, notification.type);
|
|
31
33
|
const accounts = await findByProfile(profile);
|
|
32
34
|
const mailer = await emailService();
|
|
35
|
+
const eventAttachment = email
|
|
36
|
+
? eventIcsEmailAttachment(notification, await serverRootUrl())
|
|
37
|
+
: undefined;
|
|
33
38
|
const notificationStats = await getNotificationStats(profile);
|
|
34
39
|
await logStep(jobLog, log, `Resolved ${accounts.length} account(s) for profile ${profile.id}; ` +
|
|
35
40
|
`delivery channels: email=${email} push=${push}`);
|
|
@@ -47,6 +52,7 @@ const [notificationQueue, notificationWorker] = queueAndWorker('process-notifica
|
|
|
47
52
|
? { timeZone: profileSettings.timeZone }
|
|
48
53
|
: {}),
|
|
49
54
|
},
|
|
55
|
+
...(eventAttachment ? { attachments: [eventAttachment] } : {}),
|
|
50
56
|
});
|
|
51
57
|
await logStep(jobLog, log, `Queued email notification to ${account.email}`);
|
|
52
58
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { notificationsMapping } from './mapping.js';
|
|
2
2
|
import { allpeepDb } from '../db/index.js';
|
|
3
3
|
import { notificationFilters } from '../db/pg/filters/index.js';
|
|
4
|
-
import { baseListNotifications, expandNotification, notificationSettings, } from './helpers.js';
|
|
4
|
+
import { allowsGroupNotification, baseListNotifications, expandNotification, groupNotificationLevelFor, notificationSettings, } from './helpers.js';
|
|
5
5
|
import { hub } from '../events/index.js';
|
|
6
6
|
import { findProfile } from '../profiles/index.js';
|
|
7
7
|
import { isBlockedPair } from '@openpeepshq/common/lib';
|
|
@@ -34,6 +34,14 @@ export const maybeCreateNotification = async (profile, data) => {
|
|
|
34
34
|
log.error(`profileSettings ${profile.id} not found`);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
+
const followsAuthor = (fullProfile.following ?? []).some((followed) => followed.id === data.fromProfileId);
|
|
38
|
+
if (!allowsGroupNotification({
|
|
39
|
+
level: groupNotificationLevelFor(profileSettings, data.groupId),
|
|
40
|
+
type,
|
|
41
|
+
followsAuthor,
|
|
42
|
+
})) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
37
45
|
const settings = notificationSettings(profileSettings, type);
|
|
38
46
|
if (settings.create) {
|
|
39
47
|
const notificationData = {
|