@openpeepshq/core 0.1.34 → 0.2.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/accessTokens/finders.js +5 -6
- package/dist/accessTokens/mutations.js +1 -1
- package/dist/accessTokens/tokens.js +8 -11
- package/dist/accounts/helpers.js +6 -2
- package/dist/accounts/mutations.js +13 -8
- package/dist/analytics/cache.js +3 -3
- package/dist/analytics/clicks.js +14 -22
- package/dist/analytics/compile.js +1 -2
- package/dist/analytics/dateRange.js +3 -5
- package/dist/analytics/jobs.js +3 -4
- package/dist/analytics/pdfReport.js +45 -61
- package/dist/analytics/privacy.js +1 -1
- package/dist/analytics/read.js +116 -135
- package/dist/analytics/report.d.ts +2 -1
- package/dist/analytics/report.js +2 -3
- package/dist/analytics/settings.js +3 -4
- package/dist/backups/index.js +13 -16
- package/dist/backups/metadata.js +1 -1
- package/dist/config/db.js +2 -4
- package/dist/config/defaults/community.js +1 -0
- package/dist/config/defaults/core.js +13 -8
- package/dist/config/defaults/logs.d.ts +4 -0
- package/dist/config/defaults/logs.js +5 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.js +9 -11
- package/dist/db/explorer/query.js +9 -8
- package/dist/db/explorer/sql.js +8 -8
- package/dist/db/helpers.js +15 -5
- package/dist/db/migration/importCollections.js +15 -18
- package/dist/db/migration/shared.js +15 -35
- package/dist/db/pg/client.js +4 -7
- package/dist/db/pg/filters/index.js +1 -1
- package/dist/db/pg/filters/posts.d.ts +2 -0
- package/dist/db/pg/filters/posts.js +3 -1
- package/dist/db/pg/helpers.js +2 -14
- package/dist/db/pg/map/filters.js +8 -8
- package/dist/db/pg/map/helpers.js +5 -1
- package/dist/db/pg/map/index.js +46 -51
- package/dist/db/pg/map/mutations.js +56 -21
- package/dist/db/pg/map/registry.js +87 -50
- package/dist/db/pg/map/relations.js +67 -63
- package/dist/db/pg/map/search.js +15 -37
- package/dist/db/pg/mappers.js +13 -7
- package/dist/db/pg/migrate.js +2 -3
- package/dist/db/pg/queries/activity.js +2 -2
- package/dist/db/pg/queries/derived.js +8 -12
- package/dist/db/pg/schema/documents.js +119 -18
- package/dist/db/pg/schema/edges.js +7 -1
- package/dist/db/pg/schema/index.js +5 -1
- package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
- package/dist/db/pg/sql/meta/_journal.json +8 -1
- package/dist/db/replaceOrigin.js +1 -1
- package/dist/email/queueStats.js +8 -11
- package/dist/email/render.js +7 -4
- package/dist/email/send.js +19 -17
- package/dist/email/smtpTest.js +10 -6
- package/dist/errors/index.js +1 -1
- package/dist/events/once.js +2 -4
- package/dist/federation/activities.js +1 -2
- package/dist/groups/finders.d.ts +2 -2
- package/dist/groups/helpers.d.ts +6 -6
- package/dist/groups/helpers.js +1 -2
- package/dist/groups/mapping.d.ts +4 -4
- package/dist/groups/mutations.js +1 -1
- package/dist/hashtags/finders.js +2 -2
- package/dist/inviteLinks/mutations.js +2 -3
- package/dist/jams/export.js +5 -7
- package/dist/jams/finders.js +4 -1
- package/dist/jams/health.d.ts +6 -4
- package/dist/jams/health.js +15 -11
- package/dist/jams/helpers.d.ts +2 -2
- package/dist/jams/helpers.js +6 -2
- package/dist/jams/index.js +2 -2
- package/dist/jams/jobs.js +1 -2
- package/dist/jams/livekit.d.ts +2 -2
- package/dist/jams/livekit.js +8 -8
- package/dist/jams/mapping.d.ts +10 -10
- package/dist/jams/mutations.d.ts +2 -2
- package/dist/jams/recording.js +1 -1
- package/dist/jams/token.js +13 -17
- package/dist/jobs/index.js +7 -6
- package/dist/jobs/jobDetail.js +5 -6
- package/dist/jobs/jobLog.js +2 -3
- package/dist/lib/streams.js +4 -39
- package/dist/lib/zodDeepPartial.d.ts +1 -1
- package/dist/lib/zodDeepPartial.js +1 -1
- package/dist/log/index.d.ts +1 -0
- package/dist/log/index.js +14 -29
- 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/index.js +127 -4
- package/dist/media/jobs.js +1 -2
- package/dist/media/openpeeps/index.js +11 -46
- package/dist/media/processing.js +7 -4
- package/dist/media/streaming.js +5 -5
- package/dist/media/streamingCleanupJobs.js +1 -2
- package/dist/media/streamingJobs.js +3 -4
- package/dist/media/streamingPrewarm.js +7 -11
- package/dist/mediaAttachments/index.js +6 -2
- package/dist/mediaAttachments/mapping.d.ts +1 -1
- package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
- package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
- package/dist/notifications/defaultNotifications/follow/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
- package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
- package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
- package/dist/notifications/defaultNotifications/jamModerator/index.js +27 -20
- package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
- package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
- package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
- package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
- package/dist/notifications/defaultNotifications/mention/index.js +20 -24
- package/dist/notifications/defaultNotifications/newGroupPost/index.js +9 -10
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
- package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
- package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
- package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
- package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
- package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
- package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
- package/dist/notifications/defaultNotifications/reply/index.js +21 -22
- package/dist/notifications/defaultNotifications/repost/index.js +16 -20
- package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
- package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
- package/dist/notifications/eventIcsAttachment.d.ts +6 -0
- package/dist/notifications/eventIcsAttachment.js +32 -0
- package/dist/notifications/fcmCredential.js +1 -1
- package/dist/notifications/finders.js +1 -1
- package/dist/notifications/helpers.d.ts +11 -1
- package/dist/notifications/helpers.js +38 -9
- package/dist/notifications/jobs.js +16 -7
- package/dist/notifications/mutations.js +13 -2
- package/dist/notifications/push.js +11 -16
- package/dist/performance/index.js +3 -3
- package/dist/plugins/helpers.js +3 -6
- package/dist/plugins/index.js +2 -3
- package/dist/plugins/install.js +31 -17
- package/dist/plugins/pluginAuth.js +3 -4
- package/dist/plugins/state.js +2 -3
- package/dist/posts/activity.d.ts +1 -1
- package/dist/posts/activity.js +2 -3
- package/dist/posts/contextClosure.js +1 -2
- package/dist/posts/conversationQueries.js +2 -4
- package/dist/posts/eventAgenda.js +12 -7
- package/dist/posts/eventOccurrences.js +2 -2
- package/dist/posts/finders.d.ts +46 -6
- package/dist/posts/finders.js +21 -9
- package/dist/posts/helpers/filters.js +2 -3
- package/dist/posts/helpers/index.d.ts +170 -18
- package/dist/posts/helpers/index.js +43 -27
- package/dist/posts/mapping.d.ts +616 -84
- package/dist/posts/mapping.js +60 -18
- package/dist/posts/mutations.d.ts +85 -9
- package/dist/posts/mutations.js +47 -34
- package/dist/posts/pollEnd.js +3 -6
- package/dist/posts/rsvpConfirmationEmail.js +18 -8
- package/dist/posts/threadPreview.js +1 -1
- package/dist/processingStats/queries.js +6 -7
- package/dist/profileSettings/cache.js +1 -2
- package/dist/profileSettings/mapping.d.ts +1 -0
- package/dist/profiles/activitySummary.js +23 -28
- package/dist/profiles/cache.js +15 -8
- package/dist/profiles/export.js +30 -39
- package/dist/profiles/finders.js +7 -5
- package/dist/profiles/mapping.d.ts +10 -10
- package/dist/profiles/mutations.js +3 -5
- package/dist/redis/connection.js +1 -1
- package/dist/reports/helpers.js +7 -3
- package/dist/reports/mapping.d.ts +1 -1
- package/dist/roles/mutations.js +20 -21
- package/dist/search/finders.js +15 -3
- package/dist/search/helpers.js +1 -1
- package/dist/sentry/index.js +9 -11
- package/dist/seo/index.d.ts +50 -0
- package/dist/seo/index.js +145 -0
- package/dist/seo/route.d.ts +18 -0
- package/dist/seo/route.js +19 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +16 -11
- package/dist/server/status.js +6 -7
- package/dist/session/index.js +2 -2
- package/dist/stats/finders.js +13 -4
- package/dist/stats/helpers.js +4 -1
- package/dist/stats/mapping.d.ts +43 -5
- package/dist/stats/mapping.js +9 -2
- package/dist/stripe/cache.js +5 -6
- package/dist/stripe/connection.js +3 -4
- package/dist/stripe/helpers.js +15 -20
- package/package.json +5 -6
- package/LICENSE +0 -674
|
@@ -8,23 +8,52 @@ import { getProfile } from '../profiles/cache.js';
|
|
|
8
8
|
import { transformPost } from '../posts/index.js';
|
|
9
9
|
import { notificationHandlers } from './handlers.js';
|
|
10
10
|
export const baseListNotifications = (profile) => notificationsMapping.filter(notificationFilters.forProfile(profile.id));
|
|
11
|
-
export const notificationSettings = (profileSettings, type) =>
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export const notificationSettings = (profileSettings, type) => profileSettings?.notifications?.[type] ??
|
|
12
|
+
defaultNotificationTypes.find((t) => t.type === type)?.defaultSettings ??
|
|
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;
|
|
14
39
|
};
|
|
15
40
|
export const expandNotification = async (notification) => {
|
|
16
|
-
|
|
17
|
-
|
|
41
|
+
const intermediateNotification = {
|
|
42
|
+
...notification,
|
|
18
43
|
// Include soft-deleted senders so anonymizeProfileIfDeleted can tombstone
|
|
19
44
|
// them; otherwise fromProfileId resolves to undefined and the UI falls
|
|
20
45
|
// back to an uninterpolated "{{profileName}} …" string.
|
|
21
46
|
senderProfile: notification.fromProfileId
|
|
22
47
|
? anonymizeProfileIfDeleted(await getProfile(notification.fromProfileId, true))
|
|
23
|
-
: undefined,
|
|
48
|
+
: undefined,
|
|
49
|
+
post: notification.post
|
|
24
50
|
? await transformPost(notification.post)
|
|
25
|
-
: undefined,
|
|
26
|
-
|
|
27
|
-
|
|
51
|
+
: undefined,
|
|
52
|
+
recipientProfile: (await getProfile(notification.profileId)),
|
|
53
|
+
};
|
|
54
|
+
return ((await notificationHandlers
|
|
55
|
+
.get(notification.type)
|
|
56
|
+
?.expander?.(intermediateNotification)) || intermediateNotification);
|
|
28
57
|
};
|
|
29
58
|
const baseStatNotificationsMapping = (profile) => unexpandedNotificationsMapping.filter(notificationFilters.forProfile(profile.id));
|
|
30
59
|
export const unseenNotifications = (profile) => allpeepDb().then(({ db }) => baseStatNotificationsMapping(profile)
|
|
@@ -10,14 +10,15 @@ 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
|
-
var _a, _b;
|
|
16
17
|
const notification = job.data;
|
|
17
18
|
const jobLog = jobLogger(job);
|
|
18
19
|
await logStep(jobLog, log, `Processing notification ${notification.id} (type=${notification.type}) ` +
|
|
19
20
|
`for profile ${notification.recipientProfile.id} ` +
|
|
20
|
-
`(attempt ${job.attemptsMade + 1}/${
|
|
21
|
+
`(attempt ${job.attemptsMade + 1}/${job.opts.attempts ?? 1})`);
|
|
21
22
|
const profile = await findProfile(notification.recipientProfile.id);
|
|
22
23
|
if (!profile) {
|
|
23
24
|
await logFailure(jobLog, log, `Profile ${notification.recipientProfile.id} not found; skipping notification ${notification.id}`);
|
|
@@ -31,6 +32,9 @@ const [notificationQueue, notificationWorker] = queueAndWorker('process-notifica
|
|
|
31
32
|
const { push, email } = notificationSettings(profileSettings, notification.type);
|
|
32
33
|
const accounts = await findByProfile(profile);
|
|
33
34
|
const mailer = await emailService();
|
|
35
|
+
const eventAttachment = email
|
|
36
|
+
? eventIcsEmailAttachment(notification, await serverRootUrl())
|
|
37
|
+
: undefined;
|
|
34
38
|
const notificationStats = await getNotificationStats(profile);
|
|
35
39
|
await logStep(jobLog, log, `Resolved ${accounts.length} account(s) for profile ${profile.id}; ` +
|
|
36
40
|
`delivery channels: email=${email} push=${push}`);
|
|
@@ -42,9 +46,13 @@ const [notificationQueue, notificationWorker] = queueAndWorker('process-notifica
|
|
|
42
46
|
await mailer.send({
|
|
43
47
|
template: `notification-${notification.type}`,
|
|
44
48
|
to: account.email,
|
|
45
|
-
locals:
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
locals: {
|
|
50
|
+
...notification,
|
|
51
|
+
...(profileSettings.timeZone
|
|
52
|
+
? { timeZone: profileSettings.timeZone }
|
|
53
|
+
: {}),
|
|
54
|
+
},
|
|
55
|
+
...(eventAttachment ? { attachments: [eventAttachment] } : {}),
|
|
48
56
|
});
|
|
49
57
|
await logStep(jobLog, log, `Queued email notification to ${account.email}`);
|
|
50
58
|
}
|
|
@@ -54,8 +62,9 @@ const [notificationQueue, notificationWorker] = queueAndWorker('process-notifica
|
|
|
54
62
|
}
|
|
55
63
|
if (push) {
|
|
56
64
|
try {
|
|
57
|
-
const pushNotification = await
|
|
58
|
-
.get(notification.type)
|
|
65
|
+
const pushNotification = await notificationHandlers
|
|
66
|
+
.get(notification.type)
|
|
67
|
+
?.pushRenderer(notification);
|
|
59
68
|
if (pushNotification && !sessionPublished) {
|
|
60
69
|
sessionPublished = true;
|
|
61
70
|
await publishSessionEvent(profile.id, {
|
|
@@ -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,9 +34,20 @@ 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
|
-
const notificationData =
|
|
47
|
+
const notificationData = {
|
|
48
|
+
...data,
|
|
49
|
+
profileId: profile.id,
|
|
50
|
+
};
|
|
40
51
|
const notification = await allpeepDb().then(({ db }) => notificationsMapping.create(db, notificationData));
|
|
41
52
|
const expandedNotification = await expandNotification(notification);
|
|
42
53
|
await hub.emit('notificationCreated', expandedNotification);
|
|
@@ -21,7 +21,7 @@ const describeSubscription = (subscription) => {
|
|
|
21
21
|
try {
|
|
22
22
|
host = new URL(subscription.endpoint).host;
|
|
23
23
|
}
|
|
24
|
-
catch
|
|
24
|
+
catch {
|
|
25
25
|
// keep 'unknown'
|
|
26
26
|
}
|
|
27
27
|
return `web sub=${subscription.id} endpoint=${host}`;
|
|
@@ -82,14 +82,11 @@ const sendAppIOSPushNotifications = async (subscriptions, payload, notification,
|
|
|
82
82
|
return;
|
|
83
83
|
const serializedPayload = JSON.stringify(payload);
|
|
84
84
|
const { iosClient, Notification } = await getIOSPushClient();
|
|
85
|
-
const notifications = subscriptions.map(({ apnToken }) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
data: { payload: serializedPayload },
|
|
91
|
-
});
|
|
92
|
-
});
|
|
85
|
+
const notifications = subscriptions.map(({ apnToken }) => new Notification(apnToken, {
|
|
86
|
+
badge: Number(notification?.options?.badge || '1'),
|
|
87
|
+
alert: notification?.title,
|
|
88
|
+
data: { payload: serializedPayload },
|
|
89
|
+
}));
|
|
93
90
|
await logStep(jobLog, log, `Sending APNs push to ${subscriptions.length} device(s)`);
|
|
94
91
|
let results;
|
|
95
92
|
try {
|
|
@@ -117,7 +114,6 @@ const sendAppIOSPushNotifications = async (subscriptions, payload, notification,
|
|
|
117
114
|
};
|
|
118
115
|
const describeFcmTarget = (account, subscription) => `account ${account.id} (${account.email}); ${describeSubscription(subscription)}`;
|
|
119
116
|
const sendAppFCMPushNotifications = async (subscriptions, payload, notification, account, jobLog) => {
|
|
120
|
-
var _a, _b;
|
|
121
117
|
if (subscriptions.length === 0)
|
|
122
118
|
return;
|
|
123
119
|
const serializedPayload = JSON.stringify(payload);
|
|
@@ -142,8 +138,8 @@ const sendAppFCMPushNotifications = async (subscriptions, payload, notification,
|
|
|
142
138
|
contentAvailable: true,
|
|
143
139
|
priority: 'high',
|
|
144
140
|
alert: notification.title,
|
|
145
|
-
badge: Number(
|
|
146
|
-
data:
|
|
141
|
+
badge: Number(notification?.options?.badge || '1'),
|
|
142
|
+
data: notification?.options?.data,
|
|
147
143
|
},
|
|
148
144
|
},
|
|
149
145
|
},
|
|
@@ -200,12 +196,11 @@ export const doPush = async (notification, notificationStats, account, jobLog) =
|
|
|
200
196
|
await logStep(jobLog, log, `Sending web push to ${describeSubscription(subscription)}`);
|
|
201
197
|
await sendWebPushNotification(subscription, payloadData)
|
|
202
198
|
.then(async (result) => {
|
|
203
|
-
var _a;
|
|
204
199
|
if (result && result.statusCode >= 400) {
|
|
205
200
|
await logFailure(jobLog, log, `web push to ${describeSubscription(subscription)} returned status ${result.statusCode}`);
|
|
206
201
|
return;
|
|
207
202
|
}
|
|
208
|
-
await logStep(jobLog, log, `Web push delivered to ${describeSubscription(subscription)} (status ${
|
|
203
|
+
await logStep(jobLog, log, `Web push delivered to ${describeSubscription(subscription)} (status ${result?.statusCode ?? 'n/a'})`);
|
|
209
204
|
})
|
|
210
205
|
.catch(async (error) => {
|
|
211
206
|
await logFailure(jobLog, log, `web push to ${describeSubscription(subscription)} failed; removing dead subscription`, error);
|
|
@@ -239,7 +234,7 @@ export const sendTestPushNotification = async (account, profile, subscriptionKey
|
|
|
239
234
|
const subscriptions = await listPushSubscriptionsByAccount(account);
|
|
240
235
|
const webSubscription = subscriptions
|
|
241
236
|
.filter((s) => s.type === 'web')
|
|
242
|
-
.find((s) =>
|
|
237
|
+
.find((s) => s?.keys?.auth === subscriptionKey);
|
|
243
238
|
if (webSubscription) {
|
|
244
239
|
await sendWebPushNotification(webSubscription, payload)
|
|
245
240
|
.catch(async (error) => {
|
|
@@ -248,7 +243,7 @@ export const sendTestPushNotification = async (account, profile, subscriptionKey
|
|
|
248
243
|
throw error;
|
|
249
244
|
})
|
|
250
245
|
.then((r) => {
|
|
251
|
-
if (!
|
|
246
|
+
if (!r?.statusCode || r.statusCode >= 400)
|
|
252
247
|
log.error(r);
|
|
253
248
|
});
|
|
254
249
|
return;
|
|
@@ -15,7 +15,7 @@ export const dbTimingEnabled = () => process.env.PERF_DB_TIMING === '1' || proce
|
|
|
15
15
|
const SLOW_REQUEST_BUFFER_SIZE = 100;
|
|
16
16
|
const slowRequests = [];
|
|
17
17
|
export const recordSlowRequest = (record) => {
|
|
18
|
-
slowRequests.unshift(
|
|
18
|
+
slowRequests.unshift({ ...record, at: new Date().toISOString() });
|
|
19
19
|
if (slowRequests.length > SLOW_REQUEST_BUFFER_SIZE) {
|
|
20
20
|
slowRequests.length = SLOW_REQUEST_BUFFER_SIZE;
|
|
21
21
|
}
|
|
@@ -36,7 +36,7 @@ export const withSpan = async (name, fn, attributes) => Sentry.startSpan({ name,
|
|
|
36
36
|
finally {
|
|
37
37
|
const durationMs = performance.now() - start;
|
|
38
38
|
if (durationMs >= slowSpanMs()) {
|
|
39
|
-
log.warn(
|
|
39
|
+
log.warn({ name, durationMs, ...attributes }, 'slow span');
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
});
|
|
@@ -47,7 +47,7 @@ export const truncateSql = (sqlText, max = 240) => {
|
|
|
47
47
|
if (sqlText && typeof sqlText === 'object' && 'text' in sqlText) {
|
|
48
48
|
return truncateSql(sqlText.text, max);
|
|
49
49
|
}
|
|
50
|
-
return String(sqlText
|
|
50
|
+
return String(sqlText ?? '');
|
|
51
51
|
}
|
|
52
52
|
const compact = sqlText.replace(/\s+/g, ' ').trim();
|
|
53
53
|
return compact.length > max ? `${compact.slice(0, max)}…` : compact;
|
package/dist/plugins/helpers.js
CHANGED
|
@@ -2,10 +2,8 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { logger } from '../log/index.js';
|
|
4
4
|
const log = logger('core:plugins');
|
|
5
|
-
export const isPluginEnabled = (info) =>
|
|
6
|
-
|
|
7
|
-
return ((_a = info.openpeeps) === null || _a === void 0 ? void 0 : _a.enabled) !== false;
|
|
8
|
-
};
|
|
5
|
+
export const isPluginEnabled = (info) => info.openpeeps
|
|
6
|
+
?.enabled !== false;
|
|
9
7
|
export const sortByDependencies = (pluginInfos) => {
|
|
10
8
|
const pluginKeys = pluginInfos.map(([key]) => key);
|
|
11
9
|
const packageNameToKey = new Map(pluginInfos
|
|
@@ -69,13 +67,12 @@ export const enumeratePluginInfos = async (pluginsPath) => {
|
|
|
69
67
|
// root `package.json`'s `openpeeps.plugins` array (paths relative to the repo
|
|
70
68
|
// root), keeping example/demo plugins opt-in.
|
|
71
69
|
export const enumerateReferencedPluginInfos = (rootPackageJsonPath) => {
|
|
72
|
-
var _a, _b;
|
|
73
70
|
if (!fs.existsSync(rootPackageJsonPath)) {
|
|
74
71
|
return [];
|
|
75
72
|
}
|
|
76
73
|
const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf-8'));
|
|
77
74
|
const repoRoot = path.dirname(rootPackageJsonPath);
|
|
78
|
-
return (
|
|
75
|
+
return (rootPackageJson.openpeeps?.plugins ?? []).map((relativePath) => {
|
|
79
76
|
const pluginPath = path.join(repoRoot, relativePath);
|
|
80
77
|
const key = path.join('examples', path.basename(pluginPath));
|
|
81
78
|
const info = JSON.parse(fs.readFileSync(path.join(pluginPath, 'package.json'), 'utf-8'));
|
package/dist/plugins/index.js
CHANGED
|
@@ -50,9 +50,8 @@ export const initializePlugins = async () => {
|
|
|
50
50
|
log.error(e, 'Plugin self-heal failed; continuing without it.');
|
|
51
51
|
}
|
|
52
52
|
const loadPlugin = async (key, info, pluginPath) => {
|
|
53
|
-
var _a, _b;
|
|
54
53
|
const [namespace, name] = key.split('/');
|
|
55
|
-
const displayName = typeof
|
|
54
|
+
const displayName = typeof info?.config?.displayName === 'string'
|
|
56
55
|
? info.config.displayName
|
|
57
56
|
: key;
|
|
58
57
|
const plugin = {
|
|
@@ -65,7 +64,7 @@ export const initializePlugins = async () => {
|
|
|
65
64
|
// DB override (set via the admin toggle) takes precedence over the
|
|
66
65
|
// static `openpeeps.enabled` package.json gate; a missing override
|
|
67
66
|
// falls back to the static gate.
|
|
68
|
-
const enabled =
|
|
67
|
+
const enabled = stateOverrides[key] ?? isPluginEnabled(info);
|
|
69
68
|
if (!enabled) {
|
|
70
69
|
log.info(`Skipping disabled plugin "${displayName}" (key: ${key}).`);
|
|
71
70
|
plugin.status = 'disabled';
|
package/dist/plugins/install.js
CHANGED
|
@@ -11,21 +11,23 @@ import { eq } from 'drizzle-orm';
|
|
|
11
11
|
import { setPluginEnabledOverride } from './state.js';
|
|
12
12
|
const log = logger('core:plugins:install');
|
|
13
13
|
const requireFromHost = createRequire(new URL('../../package.json', import.meta.url));
|
|
14
|
-
const MAX_COMMAND_OUTPUT =
|
|
14
|
+
const MAX_COMMAND_OUTPUT = 16_000;
|
|
15
15
|
const INSTALLED_PLUGINS_KEY = 'openpeeps-installed-plugins';
|
|
16
16
|
export const getInstalledPlugins = async () => {
|
|
17
|
-
var _a, _b;
|
|
18
17
|
const { db } = await allpeepDb();
|
|
19
18
|
const rows = await db
|
|
20
19
|
.select()
|
|
21
20
|
.from(configs)
|
|
22
21
|
.where(eq(configs.key, INSTALLED_PLUGINS_KEY))
|
|
23
22
|
.limit(1);
|
|
24
|
-
return
|
|
23
|
+
return rows[0]?.body ?? {};
|
|
25
24
|
};
|
|
26
25
|
const setInstalledPlugin = async (pluginKey, source, requiresAuth, installedBy) => {
|
|
27
26
|
const installed = await getInstalledPlugins();
|
|
28
|
-
const body =
|
|
27
|
+
const body = {
|
|
28
|
+
...installed,
|
|
29
|
+
[pluginKey]: { source, requiresAuth, installedAt: nowIso(), installedBy },
|
|
30
|
+
};
|
|
29
31
|
const ts = nowIso();
|
|
30
32
|
const { db } = await allpeepDb();
|
|
31
33
|
await db
|
|
@@ -57,7 +59,17 @@ const removeInstalledPlugin = async (pluginKey) => {
|
|
|
57
59
|
const runCommand = (command, args, cwd, environment = {}) => new Promise((resolve) => {
|
|
58
60
|
const child = spawn(command, args, {
|
|
59
61
|
cwd,
|
|
60
|
-
env:
|
|
62
|
+
env: {
|
|
63
|
+
HOME: process.env.HOME,
|
|
64
|
+
LANG: process.env.LANG,
|
|
65
|
+
LC_ALL: process.env.LC_ALL,
|
|
66
|
+
NODE_EXTRA_CA_CERTS: process.env.NODE_EXTRA_CA_CERTS,
|
|
67
|
+
PATH: process.env.PATH,
|
|
68
|
+
SSL_CERT_DIR: process.env.SSL_CERT_DIR,
|
|
69
|
+
SSL_CERT_FILE: process.env.SSL_CERT_FILE,
|
|
70
|
+
TMPDIR: process.env.TMPDIR,
|
|
71
|
+
...environment,
|
|
72
|
+
},
|
|
61
73
|
shell: false,
|
|
62
74
|
});
|
|
63
75
|
let stdout = '';
|
|
@@ -69,7 +81,7 @@ const runCommand = (command, args, cwd, environment = {}) => new Promise((resolv
|
|
|
69
81
|
stderr += chunk.toString();
|
|
70
82
|
});
|
|
71
83
|
child.on('close', (exitCode) => {
|
|
72
|
-
resolve({ exitCode: exitCode
|
|
84
|
+
resolve({ exitCode: exitCode ?? 1, stdout, stderr });
|
|
73
85
|
});
|
|
74
86
|
child.on('error', (err) => {
|
|
75
87
|
resolve({ exitCode: 1, stdout, stderr: String(err) });
|
|
@@ -157,7 +169,7 @@ const resolveHostPackage = async (name) => {
|
|
|
157
169
|
return current;
|
|
158
170
|
}
|
|
159
171
|
}
|
|
160
|
-
catch
|
|
172
|
+
catch {
|
|
161
173
|
// Keep walking toward the filesystem root.
|
|
162
174
|
}
|
|
163
175
|
const parent = path.dirname(current);
|
|
@@ -173,7 +185,7 @@ export const linkHostPeerDependencies = async (installDir, names) => {
|
|
|
173
185
|
try {
|
|
174
186
|
resolved = await resolveHostPackage(name);
|
|
175
187
|
}
|
|
176
|
-
catch
|
|
188
|
+
catch {
|
|
177
189
|
return {
|
|
178
190
|
success: false,
|
|
179
191
|
error: `Host does not provide peer dependency "${name}".`,
|
|
@@ -187,11 +199,10 @@ export const linkHostPeerDependencies = async (installDir, names) => {
|
|
|
187
199
|
return { success: true };
|
|
188
200
|
};
|
|
189
201
|
const writeNpmConfig = async (tempDir, auth) => {
|
|
190
|
-
var _a;
|
|
191
202
|
if (!auth) {
|
|
192
203
|
return {};
|
|
193
204
|
}
|
|
194
|
-
const registry = new URL(
|
|
205
|
+
const registry = new URL(auth.registry ?? 'https://registry.npmjs.org/');
|
|
195
206
|
const registryUrl = registry.toString().replace(/\/?$/, '/');
|
|
196
207
|
const authPath = registry.pathname.replace(/\/?$/, '/');
|
|
197
208
|
const configPath = path.join(tempDir, '.npmrc');
|
|
@@ -245,7 +256,6 @@ const writeGitAuth = async (tempDir, auth) => {
|
|
|
245
256
|
};
|
|
246
257
|
};
|
|
247
258
|
export const installPlugin = async (source, installedBy, options) => {
|
|
248
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
249
259
|
const pluginsDir = await getPluginDir();
|
|
250
260
|
const label = sourceLabel(source);
|
|
251
261
|
const secrets = sourceSecrets(source);
|
|
@@ -300,8 +310,13 @@ export const installPlugin = async (source, installedBy, options) => {
|
|
|
300
310
|
// Read package.json to determine namespace/name
|
|
301
311
|
const pkgJsonRaw = await fs.readFile(path.join(installDir, 'package.json'), 'utf-8');
|
|
302
312
|
const pkgJson = JSON.parse(pkgJsonRaw);
|
|
303
|
-
const namespace =
|
|
304
|
-
|
|
313
|
+
const namespace = pkgJson.openpeeps?.namespace ??
|
|
314
|
+
pkgJson.name?.split('/')[0]?.replace(/^@/, '') ??
|
|
315
|
+
'custom';
|
|
316
|
+
const name = pkgJson.openpeeps?.name ??
|
|
317
|
+
pkgJson.name?.split('/')[1] ??
|
|
318
|
+
pkgJson.name?.replace(/^@[^/]+\//, '') ??
|
|
319
|
+
'plugin';
|
|
305
320
|
const pluginKey = `${namespace}/${name}`;
|
|
306
321
|
const destDir = path.join(pluginsDir, namespace, name);
|
|
307
322
|
// Check if already exists in the plugins dir (built-in)
|
|
@@ -324,7 +339,7 @@ export const installPlugin = async (source, installedBy, options) => {
|
|
|
324
339
|
}
|
|
325
340
|
}
|
|
326
341
|
// Build the plugin if it has a build script
|
|
327
|
-
if (
|
|
342
|
+
if (pkgJson.scripts?.build) {
|
|
328
343
|
log.info(`Building plugin ${pluginKey}...`);
|
|
329
344
|
const buildDeps = await runCommand('npm', ['install', '--omit=peer'], installDir, npmEnvironment);
|
|
330
345
|
if (buildDeps.exitCode !== 0) {
|
|
@@ -356,7 +371,7 @@ export const installPlugin = async (source, installedBy, options) => {
|
|
|
356
371
|
await fs.rm(destDir, { recursive: true, force: true });
|
|
357
372
|
await fs.cp(installDir, destDir, { recursive: true });
|
|
358
373
|
await setInstalledPlugin(pluginKey, label, secrets.length > 0, installedBy);
|
|
359
|
-
if (options
|
|
374
|
+
if (options?.selfHeal) {
|
|
360
375
|
// Re-downloading an already-reviewed plugin keeps its enabled state.
|
|
361
376
|
log.info(`Self-healed plugin ${pluginKey} (re-downloaded from ${label}).`);
|
|
362
377
|
}
|
|
@@ -409,7 +424,6 @@ export const uninstallPlugin = async (pluginKey, uninstalledBy) => {
|
|
|
409
424
|
* still unavailable after the attempt.
|
|
410
425
|
*/
|
|
411
426
|
export const selfHealInstalledPlugins = async () => {
|
|
412
|
-
var _a;
|
|
413
427
|
const installed = await getInstalledPlugins();
|
|
414
428
|
const pluginsDir = await getPluginDir();
|
|
415
429
|
const failures = {};
|
|
@@ -438,7 +452,7 @@ export const selfHealInstalledPlugins = async () => {
|
|
|
438
452
|
selfHeal: true,
|
|
439
453
|
});
|
|
440
454
|
if (!result.success) {
|
|
441
|
-
log.error(new Error(
|
|
455
|
+
log.error(new Error(result.error ?? 'unknown error'), `Self-heal failed for plugin ${pluginKey}.`);
|
|
442
456
|
failures[pluginKey] = `Automatic re-download failed: ${result.error}`;
|
|
443
457
|
}
|
|
444
458
|
}
|
|
@@ -17,7 +17,6 @@ import { jwtUtil } from '../jwt/index.js';
|
|
|
17
17
|
* stronger guarantees or the handle should perform their own lookup.
|
|
18
18
|
*/
|
|
19
19
|
export const ensurePluginAuth = () => async (req, res, next) => {
|
|
20
|
-
var _a;
|
|
21
20
|
// Express 5's RequestHandler type requires `void | Promise<void>` — never
|
|
22
21
|
// `return res...`, which types as `Promise<Response>` and fails overload
|
|
23
22
|
// resolution wherever this middleware is passed to router.post/get/etc.
|
|
@@ -34,15 +33,15 @@ export const ensurePluginAuth = () => async (req, res, next) => {
|
|
|
34
33
|
try {
|
|
35
34
|
const jwt = await jwtUtil();
|
|
36
35
|
const verified = await jwt.verify(token);
|
|
37
|
-
const payload = verified
|
|
38
|
-
if (!
|
|
36
|
+
const payload = verified?.payload;
|
|
37
|
+
if (!payload?.identities?.profile) {
|
|
39
38
|
res.status(401).json({ success: false, message: 'Invalid token' });
|
|
40
39
|
return;
|
|
41
40
|
}
|
|
42
41
|
req.pluginProfile = { id: payload.identities.profile };
|
|
43
42
|
next();
|
|
44
43
|
}
|
|
45
|
-
catch
|
|
44
|
+
catch {
|
|
46
45
|
res.status(401).json({ success: false, message: 'Unauthorized' });
|
|
47
46
|
}
|
|
48
47
|
};
|
package/dist/plugins/state.js
CHANGED
|
@@ -8,16 +8,15 @@ import { nowIso } from '../db/pg/mappers.js';
|
|
|
8
8
|
// one — this is a small, boot-time-read key/value document, not a relation.
|
|
9
9
|
const PLUGIN_STATE_KEY = 'openpeeps-plugin-state';
|
|
10
10
|
export const getPluginStateOverrides = () => allpeepDb().then(async ({ db }) => {
|
|
11
|
-
var _a, _b;
|
|
12
11
|
const rows = await db
|
|
13
12
|
.select()
|
|
14
13
|
.from(configs)
|
|
15
14
|
.where(eq(configs.key, PLUGIN_STATE_KEY))
|
|
16
15
|
.limit(1);
|
|
17
|
-
return
|
|
16
|
+
return rows[0]?.body ?? {};
|
|
18
17
|
});
|
|
19
18
|
export const setPluginEnabledOverride = (pluginKey, enabled) => getPluginStateOverrides().then((overrides) => {
|
|
20
|
-
const body =
|
|
19
|
+
const body = { ...overrides, [pluginKey]: enabled };
|
|
21
20
|
const ts = nowIso();
|
|
22
21
|
return allpeepDb().then(({ db }) => db
|
|
23
22
|
.insert(configs)
|
package/dist/posts/activity.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import type { PgDb } from '../db/pg/client';
|
|
|
5
5
|
export declare const findReplyRootId: (db: PgDb, postId: string) => Promise<string>;
|
|
6
6
|
/** Bump conversation ordering without changing `created_at` or `updated_at`. */
|
|
7
7
|
export declare const touchPostActivity: (db: PgDb, postId: string) => Promise<void>;
|
|
8
|
-
/** Replies
|
|
8
|
+
/** Replies on any descendant bump the original/root post. */
|
|
9
9
|
export declare const bumpConversationActivity: (db: PgDb, postId: string) => Promise<void>;
|
package/dist/posts/activity.js
CHANGED
|
@@ -3,7 +3,6 @@ import { sql } from 'drizzle-orm';
|
|
|
3
3
|
* Walk outbound `reply_to` until there is no parent. A root post is itself.
|
|
4
4
|
*/
|
|
5
5
|
export const findReplyRootId = async (db, postId) => {
|
|
6
|
-
var _a, _b;
|
|
7
6
|
const result = (await db.execute(sql `
|
|
8
7
|
WITH RECURSIVE walk AS (
|
|
9
8
|
SELECT ${postId}::text AS node_id, 0 AS depth
|
|
@@ -18,7 +17,7 @@ export const findReplyRootId = async (db, postId) => {
|
|
|
18
17
|
ORDER BY depth DESC
|
|
19
18
|
LIMIT 1
|
|
20
19
|
`));
|
|
21
|
-
return
|
|
20
|
+
return result.rows[0]?.node_id ?? postId;
|
|
22
21
|
};
|
|
23
22
|
/** Bump conversation ordering without changing `created_at` or `updated_at`. */
|
|
24
23
|
export const touchPostActivity = async (db, postId) => {
|
|
@@ -28,7 +27,7 @@ export const touchPostActivity = async (db, postId) => {
|
|
|
28
27
|
WHERE id = ${postId}::uuid
|
|
29
28
|
`);
|
|
30
29
|
};
|
|
31
|
-
/** Replies
|
|
30
|
+
/** Replies on any descendant bump the original/root post. */
|
|
32
31
|
export const bumpConversationActivity = async (db, postId) => {
|
|
33
32
|
const rootId = await findReplyRootId(db, postId);
|
|
34
33
|
await touchPostActivity(db, rootId);
|
|
@@ -8,7 +8,6 @@ import { CONTEXT_NODE_CAP, collectReplyClosureIds } from './replyClosure.js';
|
|
|
8
8
|
export { CONTEXT_NODE_CAP, collectReplyClosureIds } from './replyClosure.js';
|
|
9
9
|
/** Load and hydrate posts in a reply closure, then ACL-filter + transform. */
|
|
10
10
|
export const loadReplyContextPosts = async (authData, startId, direction, mapping, { maxDepth = 9999, limit = CONTEXT_NODE_CAP, } = {}) => {
|
|
11
|
-
var _a, _b;
|
|
12
11
|
const { db } = await allpeepDb();
|
|
13
12
|
const mapData = mapping.data();
|
|
14
13
|
const ids = await collectReplyClosureIds(db, startId, direction, {
|
|
@@ -28,7 +27,7 @@ export const loadReplyContextPosts = async (authData, startId, direction, mappin
|
|
|
28
27
|
const transformed = await transformPost(post, authData.profile, {
|
|
29
28
|
embedThreadPreview: false,
|
|
30
29
|
});
|
|
31
|
-
const creatorId =
|
|
30
|
+
const creatorId = transformed.creatorId ?? transformed.profile?.id;
|
|
32
31
|
if (creatorId && pair.has(creatorId)) {
|
|
33
32
|
if (direction === 'descendents') {
|
|
34
33
|
posts.push(toHiddenPost(transformed));
|
|
@@ -55,7 +55,6 @@ export const listConversationRootLeafPairs = async (db, profileId) => {
|
|
|
55
55
|
};
|
|
56
56
|
/** Newest post id in a reply thread (root included); uuidv7-ordered. */
|
|
57
57
|
export const findLatestThreadPostId = async (rootId) => {
|
|
58
|
-
var _a, _b;
|
|
59
58
|
const { db } = await allpeepDb();
|
|
60
59
|
const result = (await db.execute(sql `
|
|
61
60
|
WITH RECURSIVE t AS (
|
|
@@ -73,10 +72,9 @@ export const findLatestThreadPostId = async (rootId) => {
|
|
|
73
72
|
ORDER BY id DESC
|
|
74
73
|
LIMIT 1
|
|
75
74
|
`));
|
|
76
|
-
return
|
|
75
|
+
return result.rows[0]?.id ?? rootId;
|
|
77
76
|
};
|
|
78
77
|
const hydrateLeanPostsByIds = async (authData, ids) => {
|
|
79
|
-
var _a, _b;
|
|
80
78
|
if (!ids.length)
|
|
81
79
|
return new Map();
|
|
82
80
|
const { db } = await allpeepDb();
|
|
@@ -91,7 +89,7 @@ const hydrateLeanPostsByIds = async (authData, ids) => {
|
|
|
91
89
|
const transformed = await transformPost(post, authData.profile, {
|
|
92
90
|
embedThreadPreview: false,
|
|
93
91
|
});
|
|
94
|
-
const creatorId =
|
|
92
|
+
const creatorId = transformed.creatorId ?? transformed.profile?.id;
|
|
95
93
|
if (creatorId && pair.has(creatorId)) {
|
|
96
94
|
byId.set(transformed.id, toHiddenPost(transformed));
|
|
97
95
|
continue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { notInArray, and, asc, desc, eq,
|
|
1
|
+
import { notInArray, and, asc, desc, eq, isNotNull, isNull, lte, or, sql, } from 'drizzle-orm';
|
|
2
2
|
import { canReadPost } from './helpers/filters.js';
|
|
3
3
|
import { transformPost } from './helpers/index.js';
|
|
4
4
|
import { allpeepDb } from '../db/index.js';
|
|
@@ -15,7 +15,9 @@ const occurrenceTimeFilter = (window, now) => {
|
|
|
15
15
|
const start = eventOccurrences.start;
|
|
16
16
|
const end = eventOccurrences.end;
|
|
17
17
|
if (window === 'upcoming') {
|
|
18
|
-
|
|
18
|
+
// Still this occurrence until it ends. A missing end counts as one hour,
|
|
19
|
+
// same as the current and past windows.
|
|
20
|
+
return sql `COALESCE(${end}, ${start} + interval '1 hour') >= ${now}`;
|
|
19
21
|
}
|
|
20
22
|
if (window === 'current') {
|
|
21
23
|
// A missing end is treated as a one-hour event, not an infinite one.
|
|
@@ -39,7 +41,7 @@ const eventAgendaConditions = ({ window, now, jamOnly, mine, groupId, profileId,
|
|
|
39
41
|
if (groupId) {
|
|
40
42
|
conditions.push(sql `EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text AND ${postGroups.toId} = ${groupId})`);
|
|
41
43
|
}
|
|
42
|
-
if (excludeCreatorIds
|
|
44
|
+
if (excludeCreatorIds?.length) {
|
|
43
45
|
conditions.push(notInArray(posts.creatorId, excludeCreatorIds));
|
|
44
46
|
}
|
|
45
47
|
return conditions;
|
|
@@ -94,7 +96,6 @@ const loadPostsByIds = async (ids, authData) => {
|
|
|
94
96
|
.map((post) => [post.id, post]));
|
|
95
97
|
};
|
|
96
98
|
export const listEventAgenda = async (authData, window, { offset = 0, limit = 100, jamOnly = false, mine = false, groupId, } = {}) => {
|
|
97
|
-
var _a;
|
|
98
99
|
const { db } = await allpeepDb();
|
|
99
100
|
const now = new Date().toISOString();
|
|
100
101
|
const rows = await eventAgendaOccurrenceQuery(db, {
|
|
@@ -105,7 +106,7 @@ export const listEventAgenda = async (authData, window, { offset = 0, limit = 10
|
|
|
105
106
|
jamOnly,
|
|
106
107
|
mine,
|
|
107
108
|
groupId,
|
|
108
|
-
profileId:
|
|
109
|
+
profileId: authData.profile?.id,
|
|
109
110
|
excludeCreatorIds: blockedPairIds(authData.profile),
|
|
110
111
|
});
|
|
111
112
|
const postsById = await loadPostsByIds([...new Set(rows.map((row) => row.postId))], authData);
|
|
@@ -119,8 +120,12 @@ export const listEventAgenda = async (authData, window, { offset = 0, limit = 10
|
|
|
119
120
|
if (!occurrenceRecurrenceId || !occurrenceStart)
|
|
120
121
|
return [];
|
|
121
122
|
return [
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
{
|
|
124
|
+
...post,
|
|
125
|
+
occurrenceRecurrenceId,
|
|
126
|
+
occurrenceStart,
|
|
127
|
+
...(occurrenceEnd ? { occurrenceEnd } : {}),
|
|
128
|
+
},
|
|
124
129
|
];
|
|
125
130
|
});
|
|
126
131
|
};
|