@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.
Files changed (192) hide show
  1. package/dist/accessTokens/finders.js +5 -6
  2. package/dist/accessTokens/mutations.js +1 -1
  3. package/dist/accessTokens/tokens.js +8 -11
  4. package/dist/accounts/helpers.js +6 -2
  5. package/dist/accounts/mutations.js +13 -8
  6. package/dist/analytics/cache.js +3 -3
  7. package/dist/analytics/clicks.js +14 -22
  8. package/dist/analytics/compile.js +1 -2
  9. package/dist/analytics/dateRange.js +3 -5
  10. package/dist/analytics/jobs.js +3 -4
  11. package/dist/analytics/pdfReport.js +45 -61
  12. package/dist/analytics/privacy.js +1 -1
  13. package/dist/analytics/read.js +116 -135
  14. package/dist/analytics/report.d.ts +2 -1
  15. package/dist/analytics/report.js +2 -3
  16. package/dist/analytics/settings.js +3 -4
  17. package/dist/backups/index.js +13 -16
  18. package/dist/backups/metadata.js +1 -1
  19. package/dist/config/db.js +2 -4
  20. package/dist/config/defaults/community.js +1 -0
  21. package/dist/config/defaults/core.js +13 -8
  22. package/dist/config/defaults/logs.d.ts +4 -0
  23. package/dist/config/defaults/logs.js +5 -0
  24. package/dist/config/index.d.ts +9 -0
  25. package/dist/config/index.js +9 -11
  26. package/dist/db/explorer/query.js +9 -8
  27. package/dist/db/explorer/sql.js +8 -8
  28. package/dist/db/helpers.js +15 -5
  29. package/dist/db/migration/importCollections.js +15 -18
  30. package/dist/db/migration/shared.js +15 -35
  31. package/dist/db/pg/client.js +4 -7
  32. package/dist/db/pg/filters/index.js +1 -1
  33. package/dist/db/pg/filters/posts.d.ts +2 -0
  34. package/dist/db/pg/filters/posts.js +3 -1
  35. package/dist/db/pg/helpers.js +2 -14
  36. package/dist/db/pg/map/filters.js +8 -8
  37. package/dist/db/pg/map/helpers.js +5 -1
  38. package/dist/db/pg/map/index.js +46 -51
  39. package/dist/db/pg/map/mutations.js +56 -21
  40. package/dist/db/pg/map/registry.js +87 -50
  41. package/dist/db/pg/map/relations.js +67 -63
  42. package/dist/db/pg/map/search.js +15 -37
  43. package/dist/db/pg/mappers.js +13 -7
  44. package/dist/db/pg/migrate.js +2 -3
  45. package/dist/db/pg/queries/activity.js +2 -2
  46. package/dist/db/pg/queries/derived.js +8 -12
  47. package/dist/db/pg/schema/documents.js +119 -18
  48. package/dist/db/pg/schema/edges.js +7 -1
  49. package/dist/db/pg/schema/index.js +5 -1
  50. package/dist/db/pg/sql/0016_posts_search_vector_title_tags_path.sql +54 -0
  51. package/dist/db/pg/sql/meta/_journal.json +8 -1
  52. package/dist/db/replaceOrigin.js +1 -1
  53. package/dist/email/queueStats.js +8 -11
  54. package/dist/email/render.js +7 -4
  55. package/dist/email/send.js +19 -17
  56. package/dist/email/smtpTest.js +10 -6
  57. package/dist/errors/index.js +1 -1
  58. package/dist/events/once.js +2 -4
  59. package/dist/federation/activities.js +1 -2
  60. package/dist/groups/finders.d.ts +2 -2
  61. package/dist/groups/helpers.d.ts +6 -6
  62. package/dist/groups/helpers.js +1 -2
  63. package/dist/groups/mapping.d.ts +4 -4
  64. package/dist/groups/mutations.js +1 -1
  65. package/dist/hashtags/finders.js +2 -2
  66. package/dist/inviteLinks/mutations.js +2 -3
  67. package/dist/jams/export.js +5 -7
  68. package/dist/jams/finders.js +4 -1
  69. package/dist/jams/health.d.ts +6 -4
  70. package/dist/jams/health.js +15 -11
  71. package/dist/jams/helpers.d.ts +2 -2
  72. package/dist/jams/helpers.js +6 -2
  73. package/dist/jams/index.js +2 -2
  74. package/dist/jams/jobs.js +1 -2
  75. package/dist/jams/livekit.d.ts +2 -2
  76. package/dist/jams/livekit.js +8 -8
  77. package/dist/jams/mapping.d.ts +10 -10
  78. package/dist/jams/mutations.d.ts +2 -2
  79. package/dist/jams/recording.js +1 -1
  80. package/dist/jams/token.js +13 -17
  81. package/dist/jobs/index.js +7 -6
  82. package/dist/jobs/jobDetail.js +5 -6
  83. package/dist/jobs/jobLog.js +2 -3
  84. package/dist/lib/streams.js +4 -39
  85. package/dist/lib/zodDeepPartial.d.ts +1 -1
  86. package/dist/lib/zodDeepPartial.js +1 -1
  87. package/dist/log/index.d.ts +1 -0
  88. package/dist/log/index.js +14 -29
  89. package/dist/log/retention.d.ts +9 -0
  90. package/dist/log/retention.js +83 -0
  91. package/dist/log/retentionJobs.d.ts +17 -0
  92. package/dist/log/retentionJobs.js +50 -0
  93. package/dist/media/index.js +127 -4
  94. package/dist/media/jobs.js +1 -2
  95. package/dist/media/openpeeps/index.js +11 -46
  96. package/dist/media/processing.js +7 -4
  97. package/dist/media/streaming.js +5 -5
  98. package/dist/media/streamingCleanupJobs.js +1 -2
  99. package/dist/media/streamingJobs.js +3 -4
  100. package/dist/media/streamingPrewarm.js +7 -11
  101. package/dist/mediaAttachments/index.js +6 -2
  102. package/dist/mediaAttachments/mapping.d.ts +1 -1
  103. package/dist/notifications/defaultNotifications/announcement/index.js +15 -18
  104. package/dist/notifications/defaultNotifications/directMessage/index.js +9 -8
  105. package/dist/notifications/defaultNotifications/follow/index.js +14 -17
  106. package/dist/notifications/defaultNotifications/groupAdded/index.js +14 -17
  107. package/dist/notifications/defaultNotifications/groupMemberJoined/index.js +15 -18
  108. package/dist/notifications/defaultNotifications/groupMemberLeft/index.js +15 -18
  109. package/dist/notifications/defaultNotifications/jamModerator/index.js +27 -20
  110. package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
  111. package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
  112. package/dist/notifications/defaultNotifications/jamSpeaker/index.js +14 -18
  113. package/dist/notifications/defaultNotifications/jamStarted/index.js +18 -22
  114. package/dist/notifications/defaultNotifications/mention/index.js +20 -24
  115. package/dist/notifications/defaultNotifications/newGroupPost/index.js +9 -10
  116. package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
  117. package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
  118. package/dist/notifications/defaultNotifications/newProfile/index.js +14 -17
  119. package/dist/notifications/defaultNotifications/pollEnded/index.js +21 -21
  120. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +2 -3
  121. package/dist/notifications/defaultNotifications/pollVote/index.js +14 -17
  122. package/dist/notifications/defaultNotifications/reaction/index.js +18 -21
  123. package/dist/notifications/defaultNotifications/reply/index.js +21 -22
  124. package/dist/notifications/defaultNotifications/repost/index.js +16 -20
  125. package/dist/notifications/defaultNotifications/rsvp/index.js +24 -18
  126. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +20 -13
  127. package/dist/notifications/eventIcsAttachment.d.ts +6 -0
  128. package/dist/notifications/eventIcsAttachment.js +32 -0
  129. package/dist/notifications/fcmCredential.js +1 -1
  130. package/dist/notifications/finders.js +1 -1
  131. package/dist/notifications/helpers.d.ts +11 -1
  132. package/dist/notifications/helpers.js +38 -9
  133. package/dist/notifications/jobs.js +16 -7
  134. package/dist/notifications/mutations.js +13 -2
  135. package/dist/notifications/push.js +11 -16
  136. package/dist/performance/index.js +3 -3
  137. package/dist/plugins/helpers.js +3 -6
  138. package/dist/plugins/index.js +2 -3
  139. package/dist/plugins/install.js +31 -17
  140. package/dist/plugins/pluginAuth.js +3 -4
  141. package/dist/plugins/state.js +2 -3
  142. package/dist/posts/activity.d.ts +1 -1
  143. package/dist/posts/activity.js +2 -3
  144. package/dist/posts/contextClosure.js +1 -2
  145. package/dist/posts/conversationQueries.js +2 -4
  146. package/dist/posts/eventAgenda.js +12 -7
  147. package/dist/posts/eventOccurrences.js +2 -2
  148. package/dist/posts/finders.d.ts +46 -6
  149. package/dist/posts/finders.js +21 -9
  150. package/dist/posts/helpers/filters.js +2 -3
  151. package/dist/posts/helpers/index.d.ts +170 -18
  152. package/dist/posts/helpers/index.js +43 -27
  153. package/dist/posts/mapping.d.ts +616 -84
  154. package/dist/posts/mapping.js +60 -18
  155. package/dist/posts/mutations.d.ts +85 -9
  156. package/dist/posts/mutations.js +47 -34
  157. package/dist/posts/pollEnd.js +3 -6
  158. package/dist/posts/rsvpConfirmationEmail.js +18 -8
  159. package/dist/posts/threadPreview.js +1 -1
  160. package/dist/processingStats/queries.js +6 -7
  161. package/dist/profileSettings/cache.js +1 -2
  162. package/dist/profileSettings/mapping.d.ts +1 -0
  163. package/dist/profiles/activitySummary.js +23 -28
  164. package/dist/profiles/cache.js +15 -8
  165. package/dist/profiles/export.js +30 -39
  166. package/dist/profiles/finders.js +7 -5
  167. package/dist/profiles/mapping.d.ts +10 -10
  168. package/dist/profiles/mutations.js +3 -5
  169. package/dist/redis/connection.js +1 -1
  170. package/dist/reports/helpers.js +7 -3
  171. package/dist/reports/mapping.d.ts +1 -1
  172. package/dist/roles/mutations.js +20 -21
  173. package/dist/search/finders.js +15 -3
  174. package/dist/search/helpers.js +1 -1
  175. package/dist/sentry/index.js +9 -11
  176. package/dist/seo/index.d.ts +50 -0
  177. package/dist/seo/index.js +145 -0
  178. package/dist/seo/route.d.ts +18 -0
  179. package/dist/seo/route.js +19 -0
  180. package/dist/server/index.d.ts +1 -0
  181. package/dist/server/index.js +16 -11
  182. package/dist/server/status.js +6 -7
  183. package/dist/session/index.js +2 -2
  184. package/dist/stats/finders.js +13 -4
  185. package/dist/stats/helpers.js +4 -1
  186. package/dist/stats/mapping.d.ts +43 -5
  187. package/dist/stats/mapping.js +9 -2
  188. package/dist/stripe/cache.js +5 -6
  189. package/dist/stripe/connection.js +3 -4
  190. package/dist/stripe/helpers.js +15 -20
  191. package/package.json +5 -6
  192. package/LICENSE +0 -674
@@ -18,14 +18,13 @@ const log = logger('app:media:streamingPrewarm');
18
18
  * being created right now?" semantics.
19
19
  */
20
20
  export const ensureStreamingJob = async (storageId) => {
21
- var _a;
22
21
  // Refresh the last-access marker so the daily cleanup job doesn't evict a
23
22
  // stream that someone just expressed interest in. Fire-and-forget and
24
23
  // debounced; safe to call from many sites.
25
24
  void recordStreamAccess(storageId);
26
25
  const existing = await getStreamStatus(storageId);
27
26
  if (existing) {
28
- return Object.assign({ storageId }, existing);
27
+ return { storageId, ...existing };
29
28
  }
30
29
  // Create the directory before enqueueing so any subsequent caller hitting
31
30
  // this code path immediately observes `processing` via `getStreamStatus`
@@ -42,7 +41,7 @@ export const ensureStreamingJob = async (storageId) => {
42
41
  // next POST will report it as `processing`.
43
42
  await queue.remove(jobId).catch(() => undefined);
44
43
  await queue.add('transcode', { storageId }, { jobId });
45
- return (_a = (await buildStream(storageId))) !== null && _a !== void 0 ? _a : { storageId, status: 'processing' };
44
+ return (await buildStream(storageId)) ?? { storageId, status: 'processing' };
46
45
  };
47
46
  /**
48
47
  * Pre-warms HLS streams for any local-storage-hosted videos in the given
@@ -50,7 +49,6 @@ export const ensureStreamingJob = async (storageId) => {
50
49
  * skipped.
51
50
  */
52
51
  const prewarmVideoAttachments = async (attachments, context) => {
53
- var _a;
54
52
  for (const attachment of attachments) {
55
53
  if (!attachment || attachment.type !== 'video' || !attachment.url) {
56
54
  continue;
@@ -66,7 +64,7 @@ const prewarmVideoAttachments = async (attachments, context) => {
66
64
  }
67
65
  catch (e) {
68
66
  // A single bad attachment shouldn't block prewarming siblings.
69
- log.warn(`Failed to prewarm HLS for ${context} attachment ${(_a = attachment.url) !== null && _a !== void 0 ? _a : '?'}: ${e.message}`);
67
+ log.warn(`Failed to prewarm HLS for ${context} attachment ${attachment.url ?? '?'}: ${e.message}`);
70
68
  }
71
69
  }
72
70
  };
@@ -76,12 +74,11 @@ const prewarmVideoAttachments = async (attachments, context) => {
76
74
  * play them the transcoded ladder is already (or nearly) ready.
77
75
  */
78
76
  export const prewarmPostStreams = async (rawPost) => {
79
- var _a, _b;
80
77
  const post = rawPost;
81
- const attachments = (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.attachments;
78
+ const attachments = post?.data?.attachments;
82
79
  if (!attachments || attachments.length === 0)
83
80
  return;
84
- await prewarmVideoAttachments(attachments, `post ${(_b = post === null || post === void 0 ? void 0 : post.id) !== null && _b !== void 0 ? _b : '?'}`);
81
+ await prewarmVideoAttachments(attachments, `post ${post?.id ?? '?'}`);
85
82
  };
86
83
  /**
87
84
  * Pre-warms HLS for a completed jam recording's video attachment as soon as
@@ -89,12 +86,11 @@ export const prewarmPostStreams = async (rawPost) => {
89
86
  * recording post.
90
87
  */
91
88
  export const prewarmJamRecordingStream = async (rawRecording) => {
92
- var _a;
93
89
  const recording = rawRecording;
94
- const attachment = recording === null || recording === void 0 ? void 0 : recording.attachment;
90
+ const attachment = recording?.attachment;
95
91
  if (!attachment)
96
92
  return;
97
- await prewarmVideoAttachments([attachment], `jam recording ${(_a = recording === null || recording === void 0 ? void 0 : recording.id) !== null && _a !== void 0 ? _a : '?'}`);
93
+ await prewarmVideoAttachments([attachment], `jam recording ${recording?.id ?? '?'}`);
98
94
  };
99
95
  /**
100
96
  * Registers event handlers that pre-warm HLS streams for post videos and
@@ -7,6 +7,10 @@ const setUrlToCurrentHost = async (url) => {
7
7
  parsedUrl.host = (await config()).server.host;
8
8
  return parsedUrl.toString();
9
9
  };
10
- export const convertUrls = async (data) => (Object.assign(Object.assign({}, data), { url: await setUrlToCurrentHost(data.url), previewUrl: data.previewUrl
10
+ export const convertUrls = async (data) => ({
11
+ ...data,
12
+ url: await setUrlToCurrentHost(data.url),
13
+ previewUrl: data.previewUrl
11
14
  ? await setUrlToCurrentHost(data.previewUrl)
12
- : null }));
15
+ : null,
16
+ });
@@ -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?: "ready" | "failed" | "processing" | undefined;
19
+ status?: "failed" | "ready" | "processing" | undefined;
20
20
  error?: string | undefined;
21
21
  }, MediaAttachment, MediaAttachment>;
@@ -7,7 +7,7 @@ import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
7
7
  const eventHandler = async (data) => {
8
8
  const post = data;
9
9
  for (const recipientProfile of await listProfiles()) {
10
- if (post.profile.id !== (recipientProfile === null || recipientProfile === void 0 ? void 0 : recipientProfile.id)) {
10
+ if (post.profile.id !== recipientProfile?.id) {
11
11
  await maybeCreateNotification(recipientProfile, {
12
12
  type: 'announcement',
13
13
  postId: post.id,
@@ -16,23 +16,20 @@ const eventHandler = async (data) => {
16
16
  }
17
17
  }
18
18
  };
19
- const pushRenderer = async (notification) => {
20
- var _a, _b, _c, _d;
21
- return ({
22
- title: `${profileName((_a = notification.post) === null || _a === void 0 ? void 0 : _a.profile)} posted an announcement`,
23
- options: {
24
- body: (_c = (_b = notification.post) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.content,
25
- icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
26
- actions: [
27
- {
28
- action: `goto:/posts/${(_d = notification.post) === null || _d === void 0 ? void 0 : _d.id}`,
29
- title: 'Go to announcement',
30
- },
31
- ],
32
- },
33
- invalidateQueries: [PUSH_INVALIDATE.posts],
34
- });
35
- };
19
+ const pushRenderer = async (notification) => ({
20
+ title: `${profileName(notification.post?.profile)} posted an announcement`,
21
+ options: {
22
+ body: notification.post?.data?.content,
23
+ icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
24
+ actions: [
25
+ {
26
+ action: `goto:/posts/${notification.post?.id}`,
27
+ title: 'Go to announcement',
28
+ },
29
+ ],
30
+ },
31
+ invalidateQueries: [PUSH_INVALIDATE.posts],
32
+ });
36
33
  export default {
37
34
  type: 'announcement',
38
35
  event: 'postAnnounced',
@@ -5,9 +5,8 @@ import { getConversationByEnd } from '@openpeepshq/core/posts';
5
5
  import { communityConfig } from '../../../config/index.js';
6
6
  import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
7
7
  const eventHandler = async (data) => {
8
- var _a;
9
8
  const post = data;
10
- if (((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event')
9
+ if (post.data?.type === 'event')
11
10
  return;
12
11
  if (post.visibility === 'direct' && post.audience) {
13
12
  for (const recipientProfile of post.audience) {
@@ -22,12 +21,11 @@ const eventHandler = async (data) => {
22
21
  }
23
22
  };
24
23
  const pushRenderer = async (notification) => {
25
- var _a, _b, _c;
26
- const path = `/conversations/${(_a = notification.data.conversationStart) === null || _a === void 0 ? void 0 : _a.id}`;
24
+ const path = `/conversations/${notification.data.conversationStart?.id}`;
27
25
  return {
28
26
  title: `${profileName(notification.senderProfile)} sent you a direct message`,
29
27
  options: {
30
- body: (_c = (_b = notification.post) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.content,
28
+ body: notification.post?.data?.content,
31
29
  icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
32
30
  data: {
33
31
  url: path,
@@ -47,17 +45,20 @@ const pushRenderer = async (notification) => {
47
45
  };
48
46
  const expander = async (notification) => {
49
47
  const { post, recipientProfile } = notification;
50
- const previousPost = post === null || post === void 0 ? void 0 : post.replyTo;
48
+ const previousPost = post?.replyTo;
51
49
  const conversationStart = post &&
52
50
  recipientProfile &&
53
51
  (await getConversationByEnd(post, {
54
52
  profile: recipientProfile,
55
53
  scopes: [],
56
54
  }))[0];
57
- return Object.assign(Object.assign({}, notification), { data: {
55
+ return {
56
+ ...notification,
57
+ data: {
58
58
  conversationStart,
59
59
  previousPost,
60
- } });
60
+ },
61
+ };
61
62
  };
62
63
  export default {
63
64
  type: 'directMessage',
@@ -11,21 +11,18 @@ export default {
11
11
  type: 'follow',
12
12
  fromProfileId: follower.id,
13
13
  }),
14
- pushRenderer: async (notification) => {
15
- var _a, _b;
16
- return ({
17
- title: `${profileName(notification.senderProfile)} followed you`,
18
- options: {
19
- body: truncateText(markdownPlainText((_a = notification.senderProfile) === null || _a === void 0 ? void 0 : _a.bio)),
20
- icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
21
- actions: [
22
- {
23
- action: `goto:/@${(_b = notification.senderProfile) === null || _b === void 0 ? void 0 : _b.handle}`,
24
- title: 'View Profile',
25
- },
26
- ],
27
- },
28
- invalidateQueries: [PUSH_INVALIDATE.profiles],
29
- });
30
- },
14
+ pushRenderer: async (notification) => ({
15
+ title: `${profileName(notification.senderProfile)} followed you`,
16
+ options: {
17
+ body: truncateText(markdownPlainText(notification.senderProfile?.bio)),
18
+ icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
19
+ actions: [
20
+ {
21
+ action: `goto:/@${notification.senderProfile?.handle}`,
22
+ title: 'View Profile',
23
+ },
24
+ ],
25
+ },
26
+ invalidateQueries: [PUSH_INVALIDATE.profiles],
27
+ }),
31
28
  };
@@ -13,21 +13,18 @@ export default {
13
13
  groupId: group.id,
14
14
  });
15
15
  },
16
- pushRenderer: async (notification) => {
17
- var _a;
18
- return ({
19
- title: `You've been added to ${groupName(notification.group)}`,
20
- options: {
21
- body: 'Welcome to the group!',
22
- icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
23
- actions: [
24
- {
25
- action: `goto:/groups/@${(_a = notification.group) === null || _a === void 0 ? void 0 : _a.handle}`,
26
- title: 'View Group',
27
- },
28
- ],
29
- },
30
- invalidateQueries: [PUSH_INVALIDATE.groups],
31
- });
32
- },
16
+ pushRenderer: async (notification) => ({
17
+ title: `You've been added to ${groupName(notification.group)}`,
18
+ options: {
19
+ body: 'Welcome to the group!',
20
+ icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
21
+ actions: [
22
+ {
23
+ action: `goto:/groups/@${notification.group?.handle}`,
24
+ title: 'View Group',
25
+ },
26
+ ],
27
+ },
28
+ invalidateQueries: [PUSH_INVALIDATE.groups],
29
+ }),
33
30
  };
@@ -9,7 +9,7 @@ export default {
9
9
  eventHandler: async (...args) => {
10
10
  const [group, profile] = args;
11
11
  for (const groupAdmin of await listGroupMembers(group).then((members) => members
12
- .filter((m) => { var _a, _b; return ((_a = m.roles) === null || _a === void 0 ? void 0 : _a.includes('owner')) || ((_b = m.roles) === null || _b === void 0 ? void 0 : _b.includes('admin')); })
12
+ .filter((m) => m.roles?.includes('owner') || m.roles?.includes('admin'))
13
13
  .map((m) => m.profile))) {
14
14
  await maybeCreateNotification(groupAdmin, {
15
15
  type: 'groupMemberJoined',
@@ -18,21 +18,18 @@ export default {
18
18
  });
19
19
  }
20
20
  },
21
- pushRenderer: async (notification) => {
22
- var _a;
23
- return ({
24
- title: `New member ${profileName(notification.senderProfile)} joined ${groupName(notification.group)}`,
25
- options: {
26
- body: "Let's welcome them!",
27
- icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
28
- actions: [
29
- {
30
- action: `goto:/@${(_a = notification.senderProfile) === null || _a === void 0 ? void 0 : _a.handle}`,
31
- title: 'View Profile',
32
- },
33
- ],
34
- },
35
- invalidateQueries: [PUSH_INVALIDATE.groups],
36
- });
37
- },
21
+ pushRenderer: async (notification) => ({
22
+ title: `New member ${profileName(notification.senderProfile)} joined ${groupName(notification.group)}`,
23
+ options: {
24
+ body: "Let's welcome them!",
25
+ icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
26
+ actions: [
27
+ {
28
+ action: `goto:/@${notification.senderProfile?.handle}`,
29
+ title: 'View Profile',
30
+ },
31
+ ],
32
+ },
33
+ invalidateQueries: [PUSH_INVALIDATE.groups],
34
+ }),
38
35
  };
@@ -9,7 +9,7 @@ export default {
9
9
  eventHandler: async (...args) => {
10
10
  const [group, profile] = args;
11
11
  for (const groupAdmin of await listGroupMembers(group).then((members) => members
12
- .filter((m) => { var _a, _b; return ((_a = m.roles) === null || _a === void 0 ? void 0 : _a.includes('owner')) || ((_b = m.roles) === null || _b === void 0 ? void 0 : _b.includes('admin')); })
12
+ .filter((m) => m.roles?.includes('owner') || m.roles?.includes('admin'))
13
13
  .map((m) => m.profile))) {
14
14
  await maybeCreateNotification(groupAdmin, {
15
15
  type: 'groupMemberLeft',
@@ -18,21 +18,18 @@ export default {
18
18
  });
19
19
  }
20
20
  },
21
- pushRenderer: async (notification) => {
22
- var _a;
23
- return ({
24
- title: `Group member ${profileName(notification.senderProfile)} exited ${groupName(notification.group)}`,
25
- options: {
26
- body: "They're no longer a member of the group.",
27
- icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
28
- actions: [
29
- {
30
- action: `goto:/groups/@${(_a = notification.group) === null || _a === void 0 ? void 0 : _a.handle}`,
31
- title: 'View Group',
32
- },
33
- ],
34
- },
35
- invalidateQueries: [PUSH_INVALIDATE.groups],
36
- });
37
- },
21
+ pushRenderer: async (notification) => ({
22
+ title: `Group member ${profileName(notification.senderProfile)} exited ${groupName(notification.group)}`,
23
+ options: {
24
+ body: "They're no longer a member of the group.",
25
+ icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
26
+ actions: [
27
+ {
28
+ action: `goto:/groups/@${notification.group?.handle}`,
29
+ title: 'View Group',
30
+ },
31
+ ],
32
+ },
33
+ invalidateQueries: [PUSH_INVALIDATE.groups],
34
+ }),
38
35
  };
@@ -2,37 +2,44 @@ 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
- const eventHandler = async (eventData) => {
8
- var _a, _b;
9
- const post = eventData;
10
- const jam = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = post.data) === null || _b === void 0 ? void 0 : _b.jam);
11
- if (!jam) {
12
- return;
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
+ });
13
21
  }
14
- if (jam.moderators)
15
- for (const profileId of jam.moderators) {
16
- const profile = await findProfile(profileId);
17
- if (profile && post.profile.id !== profileId) {
18
- await maybeCreateNotification(profile, {
19
- type: 'jamModerator',
20
- fromProfileId: post.profile.id,
21
- postId: post.id,
22
- });
23
- }
24
- }
25
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);
26
34
  const pushRenderer = async (notification) => {
27
- var _a, _b;
28
35
  const { t } = await initI18nEmailContext();
29
36
  return {
30
37
  title: `${profileName(notification.senderProfile)} invited you to moderate a jam`,
31
38
  options: {
32
- body: ((_a = notification.post) === null || _a === void 0 ? void 0 : _a.data).name,
39
+ body: (notification.post?.data).name,
33
40
  actions: [
34
41
  {
35
- action: `goto:/posts/${(_b = notification.post) === null || _b === void 0 ? void 0 : _b.id}`,
42
+ action: `goto:/posts/${notification.post?.id}`,
36
43
  title: t('emails.jamModerator.cta'),
37
44
  },
38
45
  ],
@@ -0,0 +1,2 @@
1
+ /** Moderators who should get an invite: not the creator, and not already invited. */
2
+ export declare const jamModeratorsToNotify: (moderatorIds: string[] | undefined, creatorId: string, alreadyInvited?: readonly string[]) => string[];
@@ -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
+ };
@@ -4,9 +4,8 @@ import { maybeCreateNotification } from '@openpeepshq/core/notifications';
4
4
  import { profileName } from '@openpeepshq/common/lib';
5
5
  import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
6
6
  const eventHandler = async (eventData) => {
7
- var _a, _b;
8
7
  const post = eventData;
9
- const jam = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = post.data) === null || _b === void 0 ? void 0 : _b.jam);
8
+ const jam = post.data?.type === 'event' && post.data?.jam;
10
9
  if (!jam) {
11
10
  return;
12
11
  }
@@ -22,22 +21,19 @@ const eventHandler = async (eventData) => {
22
21
  }
23
22
  }
24
23
  };
25
- const pushRenderer = async (notification) => {
26
- var _a, _b;
27
- return ({
28
- title: `${profileName(notification.senderProfile)} invited you to speak at a jam`,
29
- options: {
30
- body: ((_a = notification.post) === null || _a === void 0 ? void 0 : _a.data).name,
31
- actions: [
32
- {
33
- action: `goto:/events/${(_b = notification.post) === null || _b === void 0 ? void 0 : _b.id}/jam`,
34
- title: 'Join Jam',
35
- },
36
- ],
37
- },
38
- invalidateQueries: [PUSH_INVALIDATE.posts],
39
- });
40
- };
24
+ const pushRenderer = async (notification) => ({
25
+ title: `${profileName(notification.senderProfile)} invited you to speak at a jam`,
26
+ options: {
27
+ body: (notification.post?.data).name,
28
+ actions: [
29
+ {
30
+ action: `goto:/events/${notification.post?.id}/jam`,
31
+ title: 'Join Jam',
32
+ },
33
+ ],
34
+ },
35
+ invalidateQueries: [PUSH_INVALIDATE.posts],
36
+ });
41
37
  export default {
42
38
  event: 'postCreated',
43
39
  type: 'jamSpeaker',
@@ -3,15 +3,14 @@ import { maybeCreateNotification } from '@openpeepshq/core/notifications';
3
3
  import { profileName } from '@openpeepshq/common/lib';
4
4
  import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
5
5
  const eventHandler = async (...args) => {
6
- var _a, _b;
7
6
  const [profile, post] = args;
8
- const jam = ((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event' && ((_b = post.data) === null || _b === void 0 ? void 0 : _b.jam);
7
+ const jam = post.data?.type === 'event' && post.data?.jam;
9
8
  if (!jam) {
10
9
  return;
11
10
  }
12
11
  if (['local', 'public'].includes(post.visibility)) {
13
12
  for (const recipientProfile of await listProfiles()) {
14
- if (profile.id !== (recipientProfile === null || recipientProfile === void 0 ? void 0 : recipientProfile.id)) {
13
+ if (profile.id !== recipientProfile?.id) {
15
14
  await maybeCreateNotification(recipientProfile, {
16
15
  type: 'jamStarted',
17
16
  fromProfileId: profile.id,
@@ -24,7 +23,7 @@ const eventHandler = async (...args) => {
24
23
  const recipients = new Set();
25
24
  const skipRecipient = (recipient) => !profile ||
26
25
  !recipient ||
27
- profile.id === (recipient === null || recipient === void 0 ? void 0 : recipient.id) ||
26
+ profile.id === recipient?.id ||
28
27
  recipients.has(recipient);
29
28
  if (jam.moderators) {
30
29
  for (const id of [...jam.moderators, ...(jam.speakers || [])]) {
@@ -36,7 +35,7 @@ const eventHandler = async (...args) => {
36
35
  }
37
36
  if (post.audience) {
38
37
  for (const audience of post.audience) {
39
- const audienceProfile = await findProfile(audience === null || audience === void 0 ? void 0 : audience.id);
38
+ const audienceProfile = await findProfile(audience?.id);
40
39
  if (skipRecipient(audienceProfile))
41
40
  continue;
42
41
  recipients.add(audienceProfile);
@@ -44,7 +43,7 @@ const eventHandler = async (...args) => {
44
43
  }
45
44
  if (post.visibility === 'group' && post.group) {
46
45
  for (const { profile: recipient } of await listGroupMembers(post.group)) {
47
- const recipientProfile = await findProfile(recipient === null || recipient === void 0 ? void 0 : recipient.id);
46
+ const recipientProfile = await findProfile(recipient?.id);
48
47
  if (skipRecipient(recipientProfile))
49
48
  continue;
50
49
  recipients.add(recipientProfile);
@@ -58,22 +57,19 @@ const eventHandler = async (...args) => {
58
57
  });
59
58
  }
60
59
  };
61
- const pushRenderer = async (notification) => {
62
- var _a, _b, _c;
63
- return ({
64
- title: `${profileName(notification.senderProfile)} started a jam`,
65
- options: {
66
- body: (_b = (_a = notification.post) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.name,
67
- actions: [
68
- {
69
- action: `goto:/events/${(_c = notification.post) === null || _c === void 0 ? void 0 : _c.id}/jam`,
70
- title: 'Join Jam',
71
- },
72
- ],
73
- },
74
- invalidateQueries: [PUSH_INVALIDATE.posts],
75
- });
76
- };
60
+ const pushRenderer = async (notification) => ({
61
+ title: `${profileName(notification.senderProfile)} started a jam`,
62
+ options: {
63
+ body: notification.post?.data?.name,
64
+ actions: [
65
+ {
66
+ action: `goto:/events/${notification.post?.id}/jam`,
67
+ title: 'Join Jam',
68
+ },
69
+ ],
70
+ },
71
+ invalidateQueries: [PUSH_INVALIDATE.posts],
72
+ });
77
73
  export default {
78
74
  event: 'jamStarted',
79
75
  type: 'jamStarted',
@@ -7,16 +7,15 @@ import { getProfileAvatar, profileName } from '@openpeepshq/common/lib';
7
7
  import { communityConfig } from '../../../config/index.js';
8
8
  import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
9
9
  const getMentionedProfiles = async (post) => {
10
- var _a, _b;
11
10
  const byId = new Map();
12
- for (const mention of (_a = post.mentions) !== null && _a !== void 0 ? _a : []) {
11
+ for (const mention of post.mentions ?? []) {
13
12
  const profile = mention.profile;
14
- if (profile === null || profile === void 0 ? void 0 : profile.id) {
13
+ if (profile?.id) {
15
14
  byId.set(profile.id, profile);
16
15
  }
17
16
  }
18
17
  if (byId.size === 0) {
19
- for (const handle of extractMentionHandles((_b = post.data) === null || _b === void 0 ? void 0 : _b.content)) {
18
+ for (const handle of extractMentionHandles(post.data?.content)) {
20
19
  const profile = await findProfileByHandle(handle);
21
20
  if (profile) {
22
21
  byId.set(profile.id, profile);
@@ -30,9 +29,8 @@ export default {
30
29
  event: 'postCreated',
31
30
  defaultSettings: notificationAll,
32
31
  eventHandler: async (data) => {
33
- var _a, _b;
34
32
  const post = data;
35
- if (((_a = post.data) === null || _a === void 0 ? void 0 : _a.type) === 'event') {
33
+ if (post.data?.type === 'event') {
36
34
  return;
37
35
  }
38
36
  if (post.visibility === 'direct') {
@@ -45,7 +43,8 @@ export default {
45
43
  let replyTargetProfileId;
46
44
  if (post.inReplyToId) {
47
45
  const repliedPost = await findPost(post.inReplyToId);
48
- replyTargetProfileId = (_b = repliedPost === null || repliedPost === void 0 ? void 0 : repliedPost.profile) === null || _b === void 0 ? void 0 : _b.id;
46
+ replyTargetProfileId = repliedPost?.profile
47
+ ?.id;
49
48
  }
50
49
  const notified = new Set();
51
50
  for (const mentionedProfile of mentionedProfiles) {
@@ -69,21 +68,18 @@ export default {
69
68
  }
70
69
  }
71
70
  },
72
- pushRenderer: async (notification) => {
73
- var _a, _b, _c;
74
- return ({
75
- title: `${profileName(notification.senderProfile)} mentioned you`,
76
- options: {
77
- body: (_b = (_a = notification.post) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.content,
78
- icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
79
- actions: [
80
- {
81
- action: `goto:/posts/${(_c = notification.post) === null || _c === void 0 ? void 0 : _c.id}`,
82
- title: 'Go to post',
83
- },
84
- ],
85
- },
86
- invalidateQueries: [PUSH_INVALIDATE.posts],
87
- });
88
- },
71
+ pushRenderer: async (notification) => ({
72
+ title: `${profileName(notification.senderProfile)} mentioned you`,
73
+ options: {
74
+ body: notification.post?.data?.content,
75
+ icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
76
+ actions: [
77
+ {
78
+ action: `goto:/posts/${notification.post?.id}`,
79
+ title: 'Go to post',
80
+ },
81
+ ],
82
+ },
83
+ invalidateQueries: [PUSH_INVALIDATE.posts],
84
+ }),
89
85
  };