@openpeepshq/core 0.1.33 → 0.1.34

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 (213) hide show
  1. package/dist/accounts/mutations.js +33 -35
  2. package/dist/analytics/compile.js +16 -10
  3. package/dist/analytics/read.js +52 -9
  4. package/dist/analytics/report.d.ts +20 -0
  5. package/dist/backups/index.js +75 -15
  6. package/dist/backups/metadata.d.ts +2 -3
  7. package/dist/backups/metadata.js +6 -2
  8. package/dist/config/defaults/capabilities.js +13 -2
  9. package/dist/config/defaults/community.js +7 -3
  10. package/dist/config/defaults/core.d.ts +1 -1
  11. package/dist/config/defaults/core.js +3 -0
  12. package/dist/config/index.d.ts +21 -0
  13. package/dist/config/index.js +7 -1
  14. package/dist/db/helpers.d.ts +1 -0
  15. package/dist/db/helpers.js +11 -3
  16. package/dist/db/index.d.ts +1 -1
  17. package/dist/db/index.js +1 -0
  18. package/dist/db/init.js +2 -3
  19. package/dist/db/migration/importCollections.d.ts +14 -9
  20. package/dist/db/migration/importCollections.js +114 -164
  21. package/dist/db/migration/shared.d.ts +2 -33
  22. package/dist/db/migration/shared.js +2 -52
  23. package/dist/db/pg/collections.d.ts +2 -2
  24. package/dist/db/pg/collections.js +2 -2
  25. package/dist/db/pg/filters/posts.d.ts +10 -0
  26. package/dist/db/pg/filters/posts.js +28 -4
  27. package/dist/db/pg/filters/profiles.d.ts +1 -0
  28. package/dist/db/pg/filters/profiles.js +2 -1
  29. package/dist/db/pg/map/filters.js +32 -2
  30. package/dist/db/pg/map/mutations.js +13 -8
  31. package/dist/db/pg/map/registry.d.ts +5 -0
  32. package/dist/db/pg/map/registry.js +64 -24
  33. package/dist/db/pg/map/relations.js +9 -5
  34. package/dist/db/pg/migrate.d.ts +1 -2
  35. package/dist/db/pg/migrate.js +6 -6
  36. package/dist/db/pg/queries/activity.js +3 -3
  37. package/dist/db/pg/queries/sorts.d.ts +1 -0
  38. package/dist/db/pg/queries/sorts.js +4 -0
  39. package/dist/db/pg/schema/documents.d.ts +279 -41
  40. package/dist/db/pg/schema/documents.js +21 -8
  41. package/dist/db/pg/schema/edges.d.ts +116 -7
  42. package/dist/db/pg/schema/edges.js +2 -1
  43. package/dist/db/pg/schema/index.d.ts +362 -15
  44. package/dist/db/pg/sql/0010_user_group_membership_roles.sql +16 -0
  45. package/dist/db/pg/sql/0011_drop_data_migrations.sql +1 -0
  46. package/dist/db/pg/sql/0012_posts_last_activity_at.sql +5 -0
  47. package/dist/db/pg/sql/0013_add_blocks_edge.sql +12 -0
  48. package/dist/db/pg/sql/0014_federation_datamodel.sql +59 -0
  49. package/dist/db/pg/sql/0015_profile_hashtags.sql +12 -0
  50. package/dist/db/pg/sql/meta/{0009_snapshot.json → 0015_snapshot.json} +291 -36
  51. package/dist/db/pg/sql/meta/_journal.json +43 -1
  52. package/dist/email/render.js +11 -3
  53. package/dist/events/index.d.ts +4 -0
  54. package/dist/events/index.js +1 -0
  55. package/dist/federation/activities.d.ts +17 -0
  56. package/dist/federation/activities.js +26 -0
  57. package/dist/federation/identity.d.ts +16 -0
  58. package/dist/federation/identity.js +52 -0
  59. package/dist/federation/index.d.ts +4 -0
  60. package/dist/federation/index.js +3 -0
  61. package/dist/federation/profiles.d.ts +3 -0
  62. package/dist/federation/profiles.js +14 -0
  63. package/dist/groups/finders.d.ts +2 -1
  64. package/dist/groups/helpers.d.ts +18 -0
  65. package/dist/groups/mapping.d.ts +4 -2
  66. package/dist/hashtags/finders.d.ts +6 -3
  67. package/dist/hashtags/finders.js +2 -0
  68. package/dist/hashtags/helpers.d.ts +8 -0
  69. package/dist/hashtags/helpers.js +4 -0
  70. package/dist/hashtags/index.d.ts +2 -0
  71. package/dist/hashtags/index.js +2 -0
  72. package/dist/hashtags/mutations.d.ts +3 -0
  73. package/dist/hashtags/mutations.js +13 -1
  74. package/dist/i18n/index.d.ts +1 -1
  75. package/dist/i18n/index.js +3 -1
  76. package/dist/i18n/pluginLocales.d.ts +6 -0
  77. package/dist/i18n/pluginLocales.js +15 -0
  78. package/dist/jams/export.d.ts +19 -0
  79. package/dist/jams/export.js +60 -0
  80. package/dist/jams/health.d.ts +8 -0
  81. package/dist/jams/health.js +46 -0
  82. package/dist/jams/helpers.d.ts +2 -2
  83. package/dist/jams/index.d.ts +2 -0
  84. package/dist/jams/index.js +23 -16
  85. package/dist/jams/jobs.js +1 -1
  86. package/dist/jams/livekit.d.ts +49 -4
  87. package/dist/jams/livekit.js +56 -39
  88. package/dist/jams/mapping.d.ts +3 -3
  89. package/dist/jams/mutations.d.ts +1 -1
  90. package/dist/jams/recording.d.ts +10 -0
  91. package/dist/jams/recording.js +32 -0
  92. package/dist/jams/token.d.ts +13 -1
  93. package/dist/jams/token.js +18 -7
  94. package/dist/jams/waitingRoom.js +1 -1
  95. package/dist/jobs/index.d.ts +1 -0
  96. package/dist/jobs/index.js +6 -1
  97. package/dist/jobs/jobDetail.js +1 -6
  98. package/dist/media/index.d.ts +1 -1
  99. package/dist/media/index.js +23 -8
  100. package/dist/media/processing.js +18 -7
  101. package/dist/notifications/defaultNotifications/follow/index.js +2 -2
  102. package/dist/notifications/defaultNotifications/index.js +4 -0
  103. package/dist/notifications/defaultNotifications/newGroupPost/index.js +12 -6
  104. package/dist/notifications/defaultNotifications/pollEnded/index.d.ts +19 -0
  105. package/dist/notifications/defaultNotifications/pollEnded/index.js +39 -0
  106. package/dist/notifications/defaultNotifications/pollEnded/recipients.d.ts +3 -0
  107. package/dist/notifications/defaultNotifications/pollEnded/recipients.js +18 -0
  108. package/dist/notifications/defaultNotifications/rsvp/index.d.ts +6 -1
  109. package/dist/notifications/defaultNotifications/rsvp/index.js +7 -0
  110. package/dist/notifications/defaultNotifications/rsvpCanceled/index.d.ts +24 -0
  111. package/dist/notifications/defaultNotifications/rsvpCanceled/index.js +75 -0
  112. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.d.ts +4 -0
  113. package/dist/notifications/defaultNotifications/rsvpCanceled/recipients.js +11 -0
  114. package/dist/notifications/jobs.js +3 -1
  115. package/dist/notifications/mutations.js +4 -0
  116. package/dist/plugins/index.js +37 -1
  117. package/dist/plugins/install.d.ts +28 -9
  118. package/dist/plugins/install.js +281 -49
  119. package/dist/plugins/pluginAuth.d.ts +1 -1
  120. package/dist/plugins/pluginAuth.js +10 -6
  121. package/dist/posts/activity.d.ts +9 -0
  122. package/dist/posts/activity.js +35 -0
  123. package/dist/posts/contextClosure.d.ts +1 -9
  124. package/dist/posts/contextClosure.js +15 -44
  125. package/dist/posts/conversationQueries.d.ts +7 -0
  126. package/dist/posts/conversationQueries.js +76 -2
  127. package/dist/posts/eventAgenda.d.ts +1 -0
  128. package/dist/posts/eventAgenda.js +10 -4
  129. package/dist/posts/eventOccurrenceJobs.js +7 -2
  130. package/dist/posts/eventOccurrences.d.ts +6 -0
  131. package/dist/posts/eventOccurrences.js +21 -0
  132. package/dist/posts/finders.d.ts +15 -8
  133. package/dist/posts/finders.js +67 -18
  134. package/dist/posts/helpers/filters.js +13 -8
  135. package/dist/posts/helpers/index.d.ts +27 -14
  136. package/dist/posts/helpers/index.js +34 -14
  137. package/dist/posts/index.d.ts +5 -2
  138. package/dist/posts/index.js +5 -2
  139. package/dist/posts/mapping.d.ts +216 -13
  140. package/dist/posts/mapping.js +14 -13
  141. package/dist/posts/mutations.d.ts +440 -3
  142. package/dist/posts/mutations.js +155 -32
  143. package/dist/posts/pollEnd.d.ts +3 -0
  144. package/dist/posts/pollEnd.js +7 -0
  145. package/dist/posts/pollEndJobs.d.ts +8 -0
  146. package/dist/posts/pollEndJobs.js +49 -0
  147. package/dist/posts/replyClosure.d.ts +10 -0
  148. package/dist/posts/replyClosure.js +43 -0
  149. package/dist/posts/rsvpConfirmationEmail.js +14 -16
  150. package/dist/posts/threadPreview.d.ts +8 -0
  151. package/dist/posts/threadPreview.js +44 -0
  152. package/dist/posts/unseenCounts.js +4 -1
  153. package/dist/profileSettings/cache.js +22 -5
  154. package/dist/profileSettings/mapping.d.ts +2 -0
  155. package/dist/profiles/activityQueries.d.ts +5 -0
  156. package/dist/profiles/activityQueries.js +85 -0
  157. package/dist/profiles/activitySummary.d.ts +3 -0
  158. package/dist/profiles/activitySummary.js +87 -0
  159. package/dist/profiles/blocks.d.ts +12 -0
  160. package/dist/profiles/blocks.js +73 -0
  161. package/dist/profiles/cache.d.ts +1 -0
  162. package/dist/profiles/cache.js +19 -6
  163. package/dist/profiles/finders.d.ts +2 -1
  164. package/dist/profiles/finders.js +8 -3
  165. package/dist/profiles/helpers.d.ts +2 -0
  166. package/dist/profiles/index.d.ts +2 -0
  167. package/dist/profiles/index.js +2 -0
  168. package/dist/profiles/mapping.d.ts +10 -5
  169. package/dist/profiles/mapping.js +13 -1
  170. package/dist/profiles/mutations.d.ts +8 -4
  171. package/dist/profiles/mutations.js +31 -2
  172. package/dist/redis/connection.d.ts +2 -0
  173. package/dist/redis/connection.js +25 -6
  174. package/dist/roles/index.d.ts +1 -1
  175. package/dist/roles/index.js +1 -1
  176. package/dist/roles/mapping.d.ts +1 -0
  177. package/dist/roles/mutations.js +86 -3
  178. package/dist/search/mapping.d.ts +1 -1
  179. package/dist/search/mapping.js +6 -2
  180. package/dist/server/index.d.ts +18 -0
  181. package/dist/server/index.js +24 -12
  182. package/dist/server/stablePublicServerInfo.d.ts +17 -0
  183. package/dist/server/stablePublicServerInfo.js +37 -0
  184. package/dist/server/status.d.ts +25 -0
  185. package/dist/server/status.js +98 -0
  186. package/dist/stats/finders.d.ts +1 -17681
  187. package/dist/stats/finders.js +9 -5
  188. package/dist/stats/mapping.d.ts +0 -1
  189. package/dist/stats/mapping.js +0 -3
  190. package/package.json +4 -5
  191. package/dist/db/migration/detect.d.ts +0 -3
  192. package/dist/db/migration/detect.js +0 -33
  193. package/dist/db/migration/importPostgres.d.ts +0 -3
  194. package/dist/db/migration/importPostgres.js +0 -18
  195. package/dist/db/migration/transform.d.ts +0 -20
  196. package/dist/db/migration/transform.js +0 -232
  197. package/dist/db/migration/validate.d.ts +0 -18
  198. package/dist/db/migration/validate.js +0 -69
  199. package/dist/db/pg/sql/meta/0000_snapshot.json +0 -3380
  200. package/dist/db/pg/sql/meta/0004_snapshot.json +0 -4114
  201. package/dist/db/pg/sql/meta/0005_snapshot.json +0 -4179
  202. package/dist/db/pg/sql/meta/0006_snapshot.json +0 -4200
  203. package/dist/db/pg/sql/meta/0007_snapshot.json +0 -4179
  204. package/dist/mastodon/index.d.ts +0 -4
  205. package/dist/mastodon/index.js +0 -51
  206. package/dist/mastodon/types.d.ts +0 -7579
  207. package/dist/mastodon/types.js +0 -523
  208. package/dist/mastodon/typescript.d.ts +0 -1578
  209. package/dist/mastodon/typescript.js +0 -1
  210. package/dist/migration/index.d.ts +0 -4
  211. package/dist/migration/index.js +0 -4
  212. package/dist/roles/defaults.d.ts +0 -2
  213. package/dist/roles/defaults.js +0 -95
@@ -1,5 +1,5 @@
1
1
  import { sql } from 'drizzle-orm';
2
- import { getUniqueBy } from '@openpeepshq/common/lib';
2
+ import { blockedPairIds, getUniqueBy, isOneToOneWithBlocked, toHiddenPost, } from '@openpeepshq/common/lib';
3
3
  import { allpeepDb } from '../db/index.js';
4
4
  import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
5
5
  import { capabilitiesConfig } from '../config/index.js';
@@ -76,6 +76,7 @@ export const findLatestThreadPostId = async (rootId) => {
76
76
  return (_b = (_a = result.rows[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : rootId;
77
77
  };
78
78
  const hydrateLeanPostsByIds = async (authData, ids) => {
79
+ var _a, _b;
79
80
  if (!ids.length)
80
81
  return new Map();
81
82
  const { db } = await allpeepDb();
@@ -84,9 +85,17 @@ const hydrateLeanPostsByIds = async (authData, ids) => {
84
85
  const hydrated = (await hydrateMapData(db, mapData, rows));
85
86
  const config = await capabilitiesConfig();
86
87
  const readable = canReadPost(config, authData);
88
+ const pair = new Set(blockedPairIds(authData.profile));
87
89
  const byId = new Map();
88
90
  for (const post of hydrated) {
89
- const transformed = await transformPost(post, authData.profile);
91
+ const transformed = await transformPost(post, authData.profile, {
92
+ embedThreadPreview: false,
93
+ });
94
+ const creatorId = (_a = transformed.creatorId) !== null && _a !== void 0 ? _a : (_b = transformed.profile) === null || _b === void 0 ? void 0 : _b.id;
95
+ if (creatorId && pair.has(creatorId)) {
96
+ byId.set(transformed.id, toHiddenPost(transformed));
97
+ continue;
98
+ }
90
99
  if (readable(transformed))
91
100
  byId.set(transformed.id, transformed);
92
101
  }
@@ -105,12 +114,77 @@ export const listConversationPreviews = async (authData) => {
105
114
  const pairs = await listConversationRootLeafPairs(db, profile.id);
106
115
  const ids = [...new Set(pairs.flatMap((pair) => [pair.rootId, pair.leafId]))];
107
116
  const byId = await hydrateLeanPostsByIds(authData, ids);
117
+ const blocked = new Set(blockedPairIds(profile));
118
+ return getUniqueBy(pairs
119
+ .map(({ rootId, leafId }) => {
120
+ const root = byId.get(rootId);
121
+ const leaf = byId.get(leafId);
122
+ if (!root || !leaf)
123
+ return null;
124
+ if (isOneToOneWithBlocked(root, profile, blocked))
125
+ return null;
126
+ return rootId === leafId ? [root] : [root, leaf];
127
+ })
128
+ .filter((conversation) => !!conversation), (conversation) => conversation[0].id);
129
+ };
130
+ /**
131
+ * Archived conversations: threads the profile has left — detected by posts
132
+ * they authored but are no longer in the audience of. Returns
133
+ * [root, lastReadablePost] per conversation so the user can still find and
134
+ * view the conversation history after leaving.
135
+ */
136
+ export const listLeftConversations = async (authData) => {
137
+ const profile = authData.profile;
138
+ if (!profile) {
139
+ throw new Error('AuthorizationData.profile is required');
140
+ }
141
+ const { db } = await allpeepDb();
142
+ const result = (await db.execute(sql `
143
+ WITH left_posts AS (
144
+ SELECT p.id AS left_id, rt.to_id AS parent_id
145
+ FROM posts p
146
+ INNER JOIN reply_to rt ON rt.from_id = p.id
147
+ WHERE p.creator_id = ${profile.id}
148
+ AND p.deleted_at IS NULL
149
+ AND NOT EXISTS (
150
+ SELECT 1 FROM audience a
151
+ WHERE a.from_id = p.id AND a.to_id = p.creator_id
152
+ )
153
+ ),
154
+ walk AS (
155
+ SELECT lp.left_id AS conv_id, lp.parent_id AS leaf_id,
156
+ lp.parent_id AS node_id, 0 AS depth
157
+ FROM left_posts lp
158
+ UNION ALL
159
+ SELECT walk.conv_id, walk.leaf_id, rt.to_id, walk.depth + 1
160
+ FROM reply_to rt
161
+ INNER JOIN walk ON rt.from_id = walk.node_id
162
+ WHERE walk.depth < 9999
163
+ ),
164
+ roots AS (
165
+ SELECT DISTINCT ON (conv_id) conv_id, node_id AS root_id, leaf_id
166
+ FROM walk
167
+ ORDER BY conv_id, depth DESC
168
+ )
169
+ SELECT root_id, leaf_id FROM roots ORDER BY leaf_id DESC
170
+ `));
171
+ const pairs = result.rows.map((row) => ({
172
+ rootId: row.root_id,
173
+ leafId: row.leaf_id,
174
+ }));
175
+ if (pairs.length === 0)
176
+ return [];
177
+ const ids = [...new Set(pairs.flatMap((pair) => [pair.rootId, pair.leafId]))];
178
+ const byId = await hydrateLeanPostsByIds(authData, ids);
179
+ const blocked = new Set(blockedPairIds(profile));
108
180
  return getUniqueBy(pairs
109
181
  .map(({ rootId, leafId }) => {
110
182
  const root = byId.get(rootId);
111
183
  const leaf = byId.get(leafId);
112
184
  if (!root || !leaf)
113
185
  return null;
186
+ if (isOneToOneWithBlocked(root, profile, blocked))
187
+ return null;
114
188
  return rootId === leafId ? [root] : [root, leaf];
115
189
  })
116
190
  .filter((conversation) => !!conversation), (conversation) => conversation[0].id);
@@ -17,6 +17,7 @@ export type EventAgendaQueryArgs = {
17
17
  mine?: boolean;
18
18
  groupId?: string;
19
19
  profileId?: string;
20
+ excludeCreatorIds?: string[];
20
21
  };
21
22
  export declare const eventAgendaOccurrenceQuery: (db: Pick<PgDb, "select" | "selectDistinctOn">, args: EventAgendaQueryArgs) => Omit<import("drizzle-orm/pg-core").PgSelectBase<"event_agenda", {
22
23
  postId: import("drizzle-orm/pg-core").PgColumn<{
@@ -1,4 +1,4 @@
1
- import { and, asc, desc, eq, gt, gte, isNotNull, isNull, lte, or, sql, } from 'drizzle-orm';
1
+ import { notInArray, and, asc, desc, eq, gt, 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';
@@ -10,6 +10,7 @@ import { postHasYesOrMaybeRsvpExpr } from '../db/pg/queries/index.js';
10
10
  import { postFilters } from '../db/pg/filters/index.js';
11
11
  import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
12
12
  import { postsMappingForProfile } from './mapping.js';
13
+ import { blockedPairIds } from '@openpeepshq/common/lib';
13
14
  const occurrenceTimeFilter = (window, now) => {
14
15
  const start = eventOccurrences.start;
15
16
  const end = eventOccurrences.end;
@@ -17,11 +18,12 @@ const occurrenceTimeFilter = (window, now) => {
17
18
  return or(gt(start, now), and(isNotNull(end), gt(end, now)));
18
19
  }
19
20
  if (window === 'current') {
20
- return and(lte(start, now), or(isNull(end), gte(end, now)));
21
+ // A missing end is treated as a one-hour event, not an infinite one.
22
+ return and(lte(start, now), sql `COALESCE(${end}, ${start} + interval '1 hour') >= ${now}`);
21
23
  }
22
- return sql `COALESCE(${end}, ${start}) < ${now}`;
24
+ return sql `COALESCE(${end}, ${start} + interval '1 hour') < ${now}`;
23
25
  };
24
- const eventAgendaConditions = ({ window, now, jamOnly, mine, groupId, profileId, }) => {
26
+ const eventAgendaConditions = ({ window, now, jamOnly, mine, groupId, profileId, excludeCreatorIds, }) => {
25
27
  const conditions = [
26
28
  isNull(posts.deletedAt),
27
29
  eq(posts.type, 'event'),
@@ -37,6 +39,9 @@ const eventAgendaConditions = ({ window, now, jamOnly, mine, groupId, profileId,
37
39
  if (groupId) {
38
40
  conditions.push(sql `EXISTS (SELECT 1 FROM ${postGroups} WHERE ${postGroups.fromId} = ${posts.id}::text AND ${postGroups.toId} = ${groupId})`);
39
41
  }
42
+ if (excludeCreatorIds === null || excludeCreatorIds === void 0 ? void 0 : excludeCreatorIds.length) {
43
+ conditions.push(notInArray(posts.creatorId, excludeCreatorIds));
44
+ }
40
45
  return conditions;
41
46
  };
42
47
  // One row per event: a daily series would otherwise fill the first page.
@@ -101,6 +106,7 @@ export const listEventAgenda = async (authData, window, { offset = 0, limit = 10
101
106
  mine,
102
107
  groupId,
103
108
  profileId: (_a = authData.profile) === null || _a === void 0 ? void 0 : _a.id,
109
+ excludeCreatorIds: blockedPairIds(authData.profile),
104
110
  });
105
111
  const postsById = await loadPostsByIds([...new Set(rows.map((row) => row.postId))], authData);
106
112
  return rows.flatMap((row) => {
@@ -1,14 +1,15 @@
1
1
  import { queueAndWorker } from '../jobs/index.js';
2
2
  import { logger } from '../log/index.js';
3
- import { rebuildRecurringEventOccurrences } from './eventOccurrences.js';
3
+ import { backfillMissingEventOccurrences, rebuildRecurringEventOccurrences, } from './eventOccurrences.js';
4
4
  const log = logger('app:posts:eventOccurrences');
5
5
  const QUEUE_NAME = 'event-occurrences';
6
6
  const SCHEDULER_ID = 'event-occurrences-daily';
7
7
  const JOB_NAME = 'rebuild-recurring';
8
8
  export const EVENT_OCCURRENCE_CRON = '0 4 * * *';
9
9
  const [eventOccurrenceQueue, eventOccurrenceWorker] = queueAndWorker(QUEUE_NAME, async () => {
10
+ const backfilled = await backfillMissingEventOccurrences();
10
11
  const rebuilt = await rebuildRecurringEventOccurrences();
11
- log.info(`Rebuilt occurrence index for ${rebuilt} recurring events`);
12
+ log.info(`Backfilled ${backfilled} events missing an occurrence index; rebuilt ${rebuilt} recurring events`);
12
13
  }, {
13
14
  defaultJobOptions: {
14
15
  removeOnComplete: { count: 10 },
@@ -19,5 +20,9 @@ export const ensureEventOccurrenceSchedule = async () => {
19
20
  const queue = eventOccurrenceQueue();
20
21
  await queue.upsertJobScheduler(SCHEDULER_ID, { pattern: EVENT_OCCURRENCE_CRON }, { name: JOB_NAME, data: { type: 'rebuild' } });
21
22
  log.info(`Event occurrence schedule registered: cron="${EVENT_OCCURRENCE_CRON}"`);
23
+ const backfilled = await backfillMissingEventOccurrences();
24
+ if (backfilled > 0) {
25
+ log.info(`Backfilled occurrence index for ${backfilled} events`);
26
+ }
22
27
  };
23
28
  export { eventOccurrenceQueue, eventOccurrenceWorker };
@@ -1,4 +1,10 @@
1
1
  import type { Event } from '@openpeepshq/common/types';
2
2
  export declare const rebuildEventOccurrences: (postId: string, event: Event) => Promise<void>;
3
3
  export declare const clearEventOccurrences: (postId: string) => Promise<void>;
4
+ /**
5
+ * JSONL restores bring posts back without `event_occurrences`. The agenda
6
+ * reads only that index, so a restored community would show no events until
7
+ * each one is edited. Recurring series are rebuilt by the daily job.
8
+ */
9
+ export declare const backfillMissingEventOccurrences: () => Promise<number>;
4
10
  export declare const rebuildRecurringEventOccurrences: () => Promise<number>;
@@ -22,6 +22,27 @@ export const clearEventOccurrences = async (postId) => {
22
22
  const db = await database();
23
23
  await db.delete(eventOccurrences).where(eq(eventOccurrences.postId, postId));
24
24
  };
25
+ /**
26
+ * JSONL restores bring posts back without `event_occurrences`. The agenda
27
+ * reads only that index, so a restored community would show no events until
28
+ * each one is edited. Recurring series are rebuilt by the daily job.
29
+ */
30
+ export const backfillMissingEventOccurrences = async () => {
31
+ const db = await database();
32
+ const rows = await db
33
+ .select({ id: posts.id, body: posts.body })
34
+ .from(posts)
35
+ .where(and(eq(posts.type, 'event'), isNull(posts.deletedAt), sql `NOT EXISTS (SELECT 1 FROM ${eventOccurrences} WHERE ${eventOccurrences.postId} = ${posts.id})`));
36
+ let rebuilt = 0;
37
+ for (const row of rows) {
38
+ const event = row.body;
39
+ if ((event === null || event === void 0 ? void 0 : event.type) !== 'event' || !event.start)
40
+ continue;
41
+ await rebuildEventOccurrences(row.id, event);
42
+ rebuilt += 1;
43
+ }
44
+ return rebuilt;
45
+ };
25
46
  export const rebuildRecurringEventOccurrences = async () => {
26
47
  const db = await database();
27
48
  const rows = await db
@@ -11,7 +11,7 @@ export declare const replies: (authData: AuthorizationData, post: PostWithMeta)
11
11
  export declare const baseListPosts: ({ start, profile, }: {
12
12
  start?: string;
13
13
  profile?: ProfileWithMeta;
14
- }) => Mapping<DbPost>;
14
+ }) => Mapping<DbPost, import("../db/pg/map").WithId<DbPost>, import("../db/pg/map").WithId<DbPost>>;
15
15
  export declare const baseFeed: ({ start, sort, profile, }: {
16
16
  start?: string;
17
17
  sort?: ObjectSort;
@@ -222,41 +222,48 @@ export declare const listPosts: (authData: AuthorizationData, { start, limit, fi
222
222
  filter?: PgFilter<DbBasePost>;
223
223
  }) => Promise<PostWithMeta[]>;
224
224
  export declare const listConversationLeaves: (authData: AuthorizationData) => Promise<PostWithMeta[]>;
225
- export declare const listPostsByProfile: (authData: AuthorizationData, requestedProfile: ProfileWithMeta, { start, limit, filter, }?: {
225
+ export declare const listPostsByProfile: (authData: AuthorizationData, requestedProfile: ProfileWithMeta, { start, limit, filter, format, }?: {
226
226
  start?: string;
227
227
  limit?: number;
228
228
  filter?: PgFilter<DbBasePost>;
229
+ format?: string | null;
229
230
  }) => Promise<PostWithMeta[]>;
230
- export declare const listBookmarkedPosts: (authData: AuthorizationData, requestedProfile: ProfileWithMeta, { start, limit, filter, }?: {
231
+ export declare const listBookmarkedPosts: (authData: AuthorizationData, requestedProfile: ProfileWithMeta, { start, limit, filter, format, }?: {
231
232
  start?: string;
232
233
  limit?: number;
233
234
  filter?: PgFilter<DbBasePost>;
235
+ format?: string | null;
234
236
  }) => Promise<PostWithMeta[]>;
235
237
  export declare const listBookmarkedPostIds: (requestedProfile: ProfileWithMeta) => Promise<string[]>;
236
238
  export declare const getUnseenPostCounts: (authData: AuthorizationData) => Promise<UnseenPostCounts>;
237
- export declare const listPostsByType: (authData: AuthorizationData, type: PostType, { start, limit, filter, }?: {
239
+ export declare const listPostsByType: (authData: AuthorizationData, type: PostType, { start, limit, filter, format, }?: {
238
240
  start?: string;
239
241
  limit?: number;
240
242
  filter?: PgFilter<DbBasePost>;
243
+ format?: string | null;
241
244
  }) => Promise<PostWithMeta[]>;
242
- export declare const listPostsByTag: (authData: AuthorizationData, tag: string, { start, limit, filter, }?: {
245
+ export declare const listPostsByTag: (authData: AuthorizationData, tag: string, { start, limit, filter, format, }?: {
243
246
  start?: string;
244
247
  limit?: number;
245
248
  filter?: PgFilter<DbBasePost>;
249
+ format?: string | null;
246
250
  }) => Promise<PostWithMeta[]>;
247
- export declare const listPostsByGroup: (authData: AuthorizationData, groupId: string, { start, limit, filter, sort: _sort, }?: {
251
+ export declare const listPostsByGroup: (authData: AuthorizationData, groupId: string, { start, limit, filter, sort, format, }?: {
248
252
  start?: string;
249
253
  limit?: number;
250
254
  filter?: PgFilter<DbBasePost>;
251
255
  sort?: ObjectSort;
256
+ format?: string | null;
252
257
  }) => Promise<PostWithMeta[]>;
253
- export declare const listLocalFeed: (authData: AuthorizationData, { start, limit }?: {
258
+ export declare const listLocalFeed: (authData: AuthorizationData, { start, limit, format, }?: {
254
259
  start?: string;
255
260
  limit?: number;
261
+ format?: string | null;
256
262
  }) => Promise<PostWithMeta[]>;
257
- export declare const listMyFeed: (authData: AuthorizationData, { start, limit }?: {
263
+ export declare const listMyFeed: (authData: AuthorizationData, { start, limit, format, }?: {
258
264
  start?: string;
259
265
  limit?: number;
266
+ format?: string | null;
260
267
  }) => Promise<PostWithMeta[]>;
261
268
  export declare const listUpcomingEventsFeed: (authData: AuthorizationData, { offset, limit, jamOnly, mine, }?: {
262
269
  offset?: number;
@@ -1,8 +1,10 @@
1
+ import { parseFeedFormat } from '@openpeepshq/common';
2
+ import { blockedPairIds, isBlockedPair } from '@openpeepshq/common/lib';
1
3
  import { allpeepDb, collectionInfos } from '../db/index.js';
2
4
  import { edgeFilters, postFilters } from '../db/pg/filters/index.js';
3
5
  import { contextRelation, conversationLeavesMappingForProfile, postContextMappingForProfile, postsAuthMapping, postsMappingForProfile, repostsOfPostRelationForProfile, postIdsMapping, } from './mapping.js';
4
6
  import { audienceConnectionFinder, localFeedFilter, mentionsConnectionFinder, myFeedFilter, myFeedGroupMembershipFilter, toFilteredPostsList, transformPost, } from './helpers/index.js';
5
- import { addQuerySort, addStart, sortOldestFirst } from '../db/helpers.js';
7
+ import { addActivityStart, addQuerySort, addStart, sortOldestFirst, } from '../db/helpers.js';
6
8
  import { sorts } from '../db/pg/queries/index.js';
7
9
  import { findHashtagByTag, hashtagsMapping } from '../hashtags/index.js';
8
10
  import { findGroup } from '../groups/finders.js';
@@ -27,11 +29,19 @@ const requireProfile = (authData) => {
27
29
  }
28
30
  return authData.profile;
29
31
  };
32
+ const hideBlockedAuthorPost = (post, profile) => {
33
+ var _a, _b;
34
+ if (!post)
35
+ return undefined;
36
+ const creatorId = (_a = post.creatorId) !== null && _a !== void 0 ? _a : (_b = post.profile) === null || _b === void 0 ? void 0 : _b.id;
37
+ return isBlockedPair(profile, creatorId) ? undefined : post;
38
+ };
30
39
  export const findPost = async (id, authData) => {
31
40
  const profile = authData === null || authData === void 0 ? void 0 : authData.profile;
32
41
  return allpeepDb()
33
42
  .then(({ db }) => postsMappingForProfile(profile).find(db, id))
34
- .then((post) => (post ? transformPost(post, profile) : undefined));
43
+ .then((post) => (post ? transformPost(post, profile) : undefined))
44
+ .then((post) => hideBlockedAuthorPost(post, profile));
35
45
  };
36
46
  /** Lean post load for capability checks (no nested reply/repost). */
37
47
  export const findPostsForAuth = async (ids, authData) => {
@@ -47,7 +57,7 @@ export const findPostsForAuth = async (ids, authData) => {
47
57
  return [transformed.id, transformed];
48
58
  })));
49
59
  return ids
50
- .map((id) => byId.get(id))
60
+ .map((id) => hideBlockedAuthorPost(byId.get(id), profile))
51
61
  .filter((post) => !!post);
52
62
  };
53
63
  export const postContext = async (authData, id, depth, direction, contextMapping) => {
@@ -58,12 +68,26 @@ export const postContext = async (authData, id, depth, direction, contextMapping
58
68
  export const descendents = async (authData, post, depth, contextMapping) => postContext(authData, post.id, depth, 'descendents', contextMapping);
59
69
  export const ancestors = async (authData, post, depth, contextMapping) => postContext(authData, post.id, depth, 'ancestors', contextMapping);
60
70
  export const replies = async (authData, post) => descendents(authData, post, 1);
61
- export const baseListPosts = ({ start, profile, }) => addStart(postsMappingForProfile(profile), start);
71
+ export const baseListPosts = ({ start, profile, }) => addStart(postsMappingForProfile(profile), start).filter(postFilters.notCreatorIn(blockedPairIds(profile)));
62
72
  export const baseFeed = ({ start, sort, profile, }) => addQuerySort(baseListPosts({ start, profile }).filter(postFilters.notDirect()), sort);
73
+ /**
74
+ * Community / my / group timelines: original posts (and reposts) only,
75
+ * ordered by last conversation activity. Replies stay nested on the post
76
+ * detail thread so the same conversation is not repeated as standalone
77
+ * feed items.
78
+ */
79
+ const timelineFeed = ({ start, sort, profile, }) => addQuerySort(addActivityStart(postsMappingForProfile(profile)
80
+ .filter(postFilters.notDirect())
81
+ .filter(postFilters.notReply())
82
+ .filter(postFilters.notCreatorIn(blockedPairIds(profile))), start), sort);
83
+ const conversationFeed = ({ start, sort, profile, format, }) => parseFeedFormat(format) === 'linear'
84
+ ? baseFeed({ start, sort, profile })
85
+ : timelineFeed({ start, sort, profile });
63
86
  export const baseEventsFeed = (profile) => {
64
87
  const mapping = postsMappingForProfile(profile)
65
88
  .sort(sorts.eventStartAsc)
66
- .filter({ matches: { type: 'event' } });
89
+ .filter({ matches: { type: 'event' } })
90
+ .filter(postFilters.notCreatorIn(blockedPairIds(profile)));
67
91
  return mapping;
68
92
  };
69
93
  export const listPosts = async (authData, { start, limit = 100, filter, } = {
@@ -79,7 +103,7 @@ export const listConversationLeaves = async (authData) => withSpan('conversation
79
103
  .sort(sorts.createdAtDesc)
80
104
  .data(),
81
105
  }), { authData, limit: 9999 }));
82
- export const listPostsByProfile = async (authData, requestedProfile, { start, limit = 100, filter, } = {
106
+ export const listPostsByProfile = async (authData, requestedProfile, { start, limit = 100, filter, format, } = {
83
107
  limit: 100,
84
108
  }) => toFilteredPostsList(profilesMapping.relationsFrom(requestedProfile, {
85
109
  alias: 'posts',
@@ -88,11 +112,15 @@ export const listPostsByProfile = async (authData, requestedProfile, { start, li
88
112
  edgeFilter: edgeFilters.entryType('create'),
89
113
  skipEdge: true,
90
114
  cardinality: 'many',
91
- mapping: baseFeed({ start, profile: authData.profile })
115
+ mapping: conversationFeed({
116
+ start,
117
+ profile: authData.profile,
118
+ format,
119
+ })
92
120
  .filter(filter)
93
121
  .data(),
94
122
  }), { authData, limit });
95
- export const listBookmarkedPosts = async (authData, requestedProfile, { start, limit = 100, filter, } = {
123
+ export const listBookmarkedPosts = async (authData, requestedProfile, { start, limit = 100, filter, format, } = {
96
124
  limit: 100,
97
125
  }) => toFilteredPostsList(profilesMapping.relationsFrom(requestedProfile, {
98
126
  alias: 'posts',
@@ -100,7 +128,11 @@ export const listBookmarkedPosts = async (authData, requestedProfile, { start, l
100
128
  direction: 'OUTBOUND',
101
129
  skipEdge: true,
102
130
  cardinality: 'many',
103
- mapping: baseFeed({ start, profile: authData.profile })
131
+ mapping: conversationFeed({
132
+ start,
133
+ profile: authData.profile,
134
+ format,
135
+ })
104
136
  .filter(filter)
105
137
  .data(),
106
138
  }), { authData, limit });
@@ -126,12 +158,12 @@ export const getUnseenPostCounts = async (authData) => withSpan('unseen.counts',
126
158
  const { db } = await allpeepDb();
127
159
  return queryUnseenPostCounts(db, profile.id, groupIds);
128
160
  });
129
- export const listPostsByType = async (authData, type, { start, limit = 100, filter, } = {
161
+ export const listPostsByType = async (authData, type, { start, limit = 100, filter, format, } = {
130
162
  limit: 100,
131
- }) => toFilteredPostsList(baseFeed({ start, profile: authData.profile })
163
+ }) => toFilteredPostsList(conversationFeed({ start, profile: authData.profile, format })
132
164
  .filter(filter)
133
165
  .filter({ matches: { type } }), { authData, limit });
134
- export const listPostsByTag = async (authData, tag, { start, limit = 100, filter, } = {
166
+ export const listPostsByTag = async (authData, tag, { start, limit = 100, filter, format, } = {
135
167
  limit: 100,
136
168
  }) => {
137
169
  const hashtag = await findHashtagByTag(tag);
@@ -144,12 +176,16 @@ export const listPostsByTag = async (authData, tag, { start, limit = 100, filter
144
176
  direction: 'INBOUND',
145
177
  cardinality: 'many',
146
178
  skipEdge: true,
147
- mapping: baseFeed({ start, profile: authData.profile })
179
+ mapping: conversationFeed({
180
+ start,
181
+ profile: authData.profile,
182
+ format,
183
+ })
148
184
  .filter(filter)
149
185
  .data(),
150
186
  }), { authData, limit });
151
187
  };
152
- export const listPostsByGroup = async (authData, groupId, { start, limit = 100, filter, sort: _sort, } = { limit: 100 }) => withSpan('feed.group', async () => {
188
+ export const listPostsByGroup = async (authData, groupId, { start, limit = 100, filter, sort, format, } = { limit: 100 }) => withSpan('feed.group', async () => {
153
189
  const group = await findGroup(groupId);
154
190
  if (!group) {
155
191
  return [];
@@ -160,15 +196,28 @@ export const listPostsByGroup = async (authData, groupId, { start, limit = 100,
160
196
  direction: 'INBOUND',
161
197
  skipEdge: true,
162
198
  cardinality: 'many',
163
- mapping: baseFeed({ start, profile: authData.profile })
199
+ mapping: conversationFeed({
200
+ start,
201
+ profile: authData.profile,
202
+ format,
203
+ sort,
204
+ })
164
205
  .filter(filter)
165
206
  .data(),
166
207
  }), { authData, limit });
167
208
  });
168
- export const listLocalFeed = async (authData, { start, limit = 100 } = { limit: 100 }) => withSpan('feed.local', () => toFilteredPostsList(baseFeed({ start, profile: authData.profile }).filter(localFeedFilter()), { authData, limit }));
169
- export const listMyFeed = async (authData, { start, limit = 100 } = { limit: 100 }) => {
209
+ export const listLocalFeed = async (authData, { start, limit = 100, format, } = {
210
+ limit: 100,
211
+ }) => withSpan('feed.local', () => toFilteredPostsList(conversationFeed({
212
+ start,
213
+ profile: authData.profile,
214
+ format,
215
+ }).filter(localFeedFilter()), { authData, limit }));
216
+ export const listMyFeed = async (authData, { start, limit = 100, format, } = {
217
+ limit: 100,
218
+ }) => {
170
219
  const profile = requireProfile(authData);
171
- return withSpan('feed.my', () => toFilteredPostsList(baseFeed({ start, profile }).filter(myFeedFilter(profile)), { authData, limit, filters: [myFeedGroupMembershipFilter(profile)] }));
220
+ return withSpan('feed.my', () => toFilteredPostsList(conversationFeed({ start, profile, format }).filter(myFeedFilter(profile)), { authData, limit, filters: [myFeedGroupMembershipFilter(profile)] }));
172
221
  };
173
222
  export const listUpcomingEventsFeed = async (authData, { offset, limit = 100, jamOnly, mine, } = {
174
223
  limit: 100,
@@ -15,14 +15,19 @@ export const followFilter = (profile) => ({
15
15
  creatorId: f.id,
16
16
  })),
17
17
  });
18
- export const myFeedFilter = (profile) => ({
19
- operator: '||',
20
- predicates: [
21
- ownPostsFilter(profile),
22
- groupPostVisibilityQueryFilter,
23
- followFilter(profile),
24
- ],
25
- });
18
+ export const myFeedFilter = (profile) => {
19
+ var _a, _b;
20
+ const hashtagFilterResult = postFilters.hasAnyHashtag((_b = (_a = profile.followedHashtags) === null || _a === void 0 ? void 0 : _a.map((h) => h.id)) !== null && _b !== void 0 ? _b : []);
21
+ return {
22
+ operator: '||',
23
+ predicates: [
24
+ ownPostsFilter(profile),
25
+ groupPostVisibilityQueryFilter,
26
+ followFilter(profile),
27
+ ...(hashtagFilterResult ? [hashtagFilterResult] : []),
28
+ ],
29
+ };
30
+ };
26
31
  export const myFeedGroupMembershipFilter = (profile) => (post) => post.visibility !== 'group' ||
27
32
  (!!post.group &&
28
33
  profile.memberships.some((m) => { var _a; return m.group.id === ((_a = post.group) === null || _a === void 0 ? void 0 : _a.id); }));
@@ -1,4 +1,4 @@
1
- import { AuthorizationData, PostWithMeta, PostDataUnion, Profile, Post, Hashtag, MentionWithPublicProfile, DbPost } from '@openpeepshq/common/types';
1
+ import { AuthorizationData, PostWithMeta, PostDataUnion, Profile, Post, Hashtag, ProfileWithMeta, MentionWithPublicProfile, DbPost } from '@openpeepshq/common/types';
2
2
  import type { PgQueryResult } from '../../db/pg/map/types';
3
3
  import { ObjectFilter } from '../../db/types';
4
4
  export declare const isDirect: (post: PostWithMeta) => boolean;
@@ -415,6 +415,18 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
415
415
  response: "removed" | "no" | "yes" | "tentative";
416
416
  recurrenceId?: string | undefined;
417
417
  };
418
+ } | {
419
+ type: "reaction";
420
+ data: {
421
+ reaction: string;
422
+ };
423
+ uri?: string | undefined;
424
+ } | {
425
+ type: "unreaction";
426
+ data: {
427
+ reaction: string;
428
+ };
429
+ uri?: string | undefined;
418
430
  }) & {
419
431
  id?: string;
420
432
  }) => Promise<import("../../db/pg/map").WithId<({
@@ -821,6 +833,18 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
821
833
  response: "removed" | "no" | "yes" | "tentative";
822
834
  recurrenceId?: string | undefined;
823
835
  };
836
+ } | {
837
+ type: "reaction";
838
+ data: {
839
+ reaction: string;
840
+ };
841
+ uri?: string | undefined;
842
+ } | {
843
+ type: "unreaction";
844
+ data: {
845
+ reaction: string;
846
+ };
847
+ uri?: string | undefined;
824
848
  }) & {
825
849
  _from: string;
826
850
  _to: string;
@@ -888,17 +912,6 @@ export declare const repostConnector: (db: import("../../db").PgDb, from: Post,
888
912
  _from: string;
889
913
  _to: string;
890
914
  }>>;
891
- export declare const reactionConnector: (db: import("../../db").PgDb, from: Profile, to: Post, data?: {
892
- reaction: "👍";
893
- } & {
894
- id?: string;
895
- }) => Promise<import("../../db/pg/map").WithId<{
896
- reaction: "👍";
897
- } & {
898
- _from: string;
899
- _to: string;
900
- }>>;
901
- export declare const reactionDisconnector: (db: import("../../db").PgDb, from: Profile, to: Post) => Promise<void>;
902
915
  export declare const bookmarkConnector: (db: import("../../db").PgDb, from: Profile, to: Post, data?: object & {
903
916
  id?: string;
904
917
  }) => Promise<import("../../db/pg/map").WithId<object & {
@@ -912,8 +925,8 @@ export declare const postSeenConnector: (db: import("../../db").PgDb, from: Prof
912
925
  _from: string;
913
926
  _to: string;
914
927
  }>>;
915
- export declare const transformPost: (post: DbPost, currentProfile?: {
916
- id: string;
928
+ export declare const transformPost: (post: DbPost, currentProfile?: ProfileWithMeta, options?: {
929
+ embedThreadPreview?: boolean;
917
930
  }) => Promise<PostWithMeta>;
918
931
  export declare const toFilteredPostsList: (queryResult: PgQueryResult<DbPost>, options: {
919
932
  authData: AuthorizationData;