@openpeepshq/core 0.1.35 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/accounts/mutations.js +9 -0
  2. package/dist/analytics/report.d.ts +1 -1
  3. package/dist/config/defaults/logs.d.ts +4 -0
  4. package/dist/config/defaults/logs.js +5 -0
  5. package/dist/config/index.d.ts +3 -328
  6. package/dist/db/explorer/index.d.ts +1 -1
  7. package/dist/db/explorer/index.js +1 -1
  8. package/dist/db/pg/filters/posts.js +1 -1
  9. package/dist/db/pg/map/registry.js +3 -2
  10. package/dist/groups/finders.d.ts +2 -2
  11. package/dist/groups/helpers.d.ts +6 -6
  12. package/dist/groups/mapping.d.ts +4 -4
  13. package/dist/jams/export.d.ts +2 -0
  14. package/dist/jams/export.js +5 -0
  15. package/dist/jams/finders.d.ts +1 -0
  16. package/dist/jams/finders.js +1 -0
  17. package/dist/jams/health.d.ts +23 -0
  18. package/dist/jams/health.js +79 -7
  19. package/dist/jams/helpers.d.ts +2 -2
  20. package/dist/jams/index.d.ts +1 -1
  21. package/dist/jams/index.js +10 -3
  22. package/dist/jams/livekit.d.ts +2 -2
  23. package/dist/jams/mapping.d.ts +10 -10
  24. package/dist/jams/mutations.d.ts +2 -2
  25. package/dist/jams/token.js +6 -2
  26. package/dist/jams/waitingRoom.js +3 -1
  27. package/dist/log/index.d.ts +1 -0
  28. package/dist/log/index.js +1 -0
  29. package/dist/log/retention.d.ts +9 -0
  30. package/dist/log/retention.js +83 -0
  31. package/dist/log/retentionJobs.d.ts +17 -0
  32. package/dist/log/retentionJobs.js +50 -0
  33. package/dist/media/garbageCollection.d.ts +109 -0
  34. package/dist/media/garbageCollection.js +603 -0
  35. package/dist/media/garbageCollectionJobs.d.ts +14 -0
  36. package/dist/media/garbageCollectionJobs.js +55 -0
  37. package/dist/media/index.d.ts +2 -0
  38. package/dist/media/index.js +91 -12
  39. package/dist/media/streaming.d.ts +2 -0
  40. package/dist/media/streaming.js +8 -0
  41. package/dist/mediaAttachments/mapping.d.ts +1 -1
  42. package/dist/notifications/defaultNotifications/index.js +2 -0
  43. package/dist/notifications/defaultNotifications/jamModerator/index.js +25 -16
  44. package/dist/notifications/defaultNotifications/jamModerator/recipients.d.ts +2 -0
  45. package/dist/notifications/defaultNotifications/jamModerator/recipients.js +5 -0
  46. package/dist/notifications/defaultNotifications/jamStarted/index.d.ts +1 -0
  47. package/dist/notifications/defaultNotifications/jamStarted/index.js +61 -13
  48. package/dist/notifications/defaultNotifications/newGroupPost/index.js +3 -3
  49. package/dist/notifications/defaultNotifications/newGroupPost/recipients.d.ts +5 -0
  50. package/dist/notifications/defaultNotifications/newGroupPost/recipients.js +23 -0
  51. package/dist/notifications/defaultNotifications/waitlistOffer/index.d.ts +24 -0
  52. package/dist/notifications/defaultNotifications/waitlistOffer/index.js +40 -0
  53. package/dist/notifications/eventIcsAttachment.d.ts +6 -0
  54. package/dist/notifications/eventIcsAttachment.js +32 -0
  55. package/dist/notifications/helpers.d.ts +11 -1
  56. package/dist/notifications/helpers.js +26 -0
  57. package/dist/notifications/index.d.ts +1 -1
  58. package/dist/notifications/index.js +1 -1
  59. package/dist/notifications/jobs.js +6 -0
  60. package/dist/notifications/mutations.js +9 -1
  61. package/dist/plugins/pluginAuth.js +1 -0
  62. package/dist/posts/activity.d.ts +1 -1
  63. package/dist/posts/activity.js +1 -1
  64. package/dist/posts/conversationQueries.d.ts +31 -0
  65. package/dist/posts/conversationQueries.js +150 -24
  66. package/dist/posts/eventAgenda.js +4 -2
  67. package/dist/posts/finders.d.ts +15 -6
  68. package/dist/posts/finders.js +23 -3
  69. package/dist/posts/helpers/index.d.ts +34 -26
  70. package/dist/posts/helpers/index.js +6 -0
  71. package/dist/posts/index.d.ts +3 -1
  72. package/dist/posts/index.js +3 -1
  73. package/dist/posts/mapping.d.ts +112 -98
  74. package/dist/posts/mutations.d.ts +24 -18
  75. package/dist/posts/mutations.js +222 -72
  76. package/dist/posts/rsvpExport.d.ts +47 -0
  77. package/dist/posts/rsvpExport.js +178 -0
  78. package/dist/posts/unseenCounts.d.ts +6 -0
  79. package/dist/posts/unseenCounts.js +51 -1
  80. package/dist/posts/waitlist.d.ts +13 -0
  81. package/dist/posts/waitlist.js +75 -0
  82. package/dist/posts/waitlistOfferJobs.d.ts +10 -0
  83. package/dist/posts/waitlistOfferJobs.js +91 -0
  84. package/dist/profileSettings/mapping.d.ts +1 -0
  85. package/dist/profiles/index.js +6 -1
  86. package/dist/profiles/mapping.d.ts +10 -10
  87. package/dist/reports/mapping.d.ts +1 -1
  88. package/dist/server/index.d.ts +1 -0
  89. package/dist/stats/mapping.d.ts +7 -6
  90. package/dist/stripe/connection.js +1 -1
  91. package/dist/stripe/helpers.js +7 -3
  92. package/package.json +11 -10
@@ -1,4 +1,5 @@
1
1
  import { jwtUtil } from '../jwt/index.js';
2
+ /* eslint-enable @typescript-eslint/no-namespace */
2
3
  /**
3
4
  * Express middleware that verifies the `Authorization: Bearer <token>` header
4
5
  * and attaches `{ pluginProfile }` to the request if valid.
@@ -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 and reactions on any descendant bump the original/root post. */
8
+ /** Replies on any descendant bump the original/root post. */
9
9
  export declare const bumpConversationActivity: (db: PgDb, postId: string) => Promise<void>;
@@ -27,7 +27,7 @@ export const touchPostActivity = async (db, postId) => {
27
27
  WHERE id = ${postId}::uuid
28
28
  `);
29
29
  };
30
- /** Replies and reactions on any descendant bump the original/root post. */
30
+ /** Replies on any descendant bump the original/root post. */
31
31
  export const bumpConversationActivity = async (db, postId) => {
32
32
  const rootId = await findReplyRootId(db, postId);
33
33
  await touchPostActivity(db, rootId);
@@ -13,6 +13,14 @@ export declare const findLatestThreadPostId: (rootId: string) => Promise<string>
13
13
  * they are the same). Avoids walking full ancestor chains.
14
14
  */
15
15
  export declare const listConversationPreviews: (authData: AuthorizationData) => Promise<PostWithMeta[][]>;
16
+ /**
17
+ * Collapse 1:1 previews sharing a participant pair into one entry
18
+ * [oldest root, newest leaf] so a conversation with several roots lists
19
+ * once. The oldest root (min uuidv7) is the pair's stable conversation id;
20
+ * it must match the key the unseen counts are merged under. Other
21
+ * conversations pass through. Result is ordered newest-leaf first.
22
+ */
23
+ export declare const mergeOneToOnePreviews: (conversations: PostWithMeta[][]) => PostWithMeta[][];
16
24
  /**
17
25
  * Archived conversations: threads the profile has left — detected by posts
18
26
  * they authored but are no longer in the audience of. Returns
@@ -27,4 +35,27 @@ export declare const listLeftConversations: (authData: AuthorizationData) => Pro
27
35
  export declare const getConversationThread: (root: PostWithMeta, authData: AuthorizationData, { limit }?: {
28
36
  limit?: number;
29
37
  }) => Promise<PostWithMeta[]>;
38
+ /**
39
+ * All post ids in the 1:1 conversation between two profiles, oldest first:
40
+ * every post of the pair, plus their reply descendants (e.g. system "left"
41
+ * posts, whose participants are only the remaining participant and which
42
+ * are reachable as descendants only). Ids are uuidv7, so ordering is
43
+ * chronological.
44
+ */
45
+ export declare const listOneToOneConversationPostIds: (db: PgDb, profileAId: string, profileBId: string) => Promise<string[]>;
46
+ /**
47
+ * Per root of a 1:1 conversation: the root id and that thread's newest post
48
+ * (leaf). Used to terminate every root's thread on leave.
49
+ */
50
+ export declare const listOneToOneConversationRootLeaves: (db: PgDb, profileAId: string, profileBId: string) => Promise<Array<{
51
+ rootId: string;
52
+ leafId: string;
53
+ }>>;
54
+ /**
55
+ * Merged 1:1 conversation: every message for the pair across all roots,
56
+ * oldest first. Any post of the conversation (typically the root in the URL)
57
+ * resolves to the same list. Capped like {@link getConversationThread}:
58
+ * the oldest message plus the newest CONTEXT_NODE_CAP others.
59
+ */
60
+ export declare const getOneToOneConversation: (post: PostWithMeta, authData: AuthorizationData) => Promise<PostWithMeta[]>;
30
61
  export {};
@@ -1,5 +1,5 @@
1
1
  import { sql } from 'drizzle-orm';
2
- import { blockedPairIds, getUniqueBy, isOneToOneWithBlocked, toHiddenPost, } from '@openpeepshq/common/lib';
2
+ import { blockedPairIds, isOneToOneDm, isOneToOneWithBlocked, participantIds, 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';
@@ -113,17 +113,53 @@ export const listConversationPreviews = async (authData) => {
113
113
  const ids = [...new Set(pairs.flatMap((pair) => [pair.rootId, pair.leafId]))];
114
114
  const byId = await hydrateLeanPostsByIds(authData, ids);
115
115
  const blocked = new Set(blockedPairIds(profile));
116
- return getUniqueBy(pairs
117
- .map(({ rootId, leafId }) => {
118
- const root = byId.get(rootId);
119
- const leaf = byId.get(leafId);
120
- if (!root || !leaf)
121
- return null;
122
- if (isOneToOneWithBlocked(root, profile, blocked))
123
- return null;
124
- return rootId === leafId ? [root] : [root, leaf];
125
- })
126
- .filter((conversation) => !!conversation), (conversation) => conversation[0].id);
116
+ return mergeOneToOnePreviews(conversationPreviewsFromPairs(pairs, byId, profile, blocked));
117
+ };
118
+ const conversationPreviewsFromPairs = (pairs, byId, profile, blocked) => 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);
129
+ const oneToOnePairKey = (post) => [...participantIds(post)].sort().join(',');
130
+ const byIdAsc = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
131
+ /**
132
+ * Collapse 1:1 previews sharing a participant pair into one entry
133
+ * [oldest root, newest leaf] so a conversation with several roots lists
134
+ * once. The oldest root (min uuidv7) is the pair's stable conversation id;
135
+ * it must match the key the unseen counts are merged under. Other
136
+ * conversations pass through. Result is ordered newest-leaf first.
137
+ */
138
+ export const mergeOneToOnePreviews = (conversations) => {
139
+ const merged = [];
140
+ const byPair = new Map();
141
+ for (const conversation of conversations) {
142
+ const root = conversation[0];
143
+ if (!isOneToOneDm(root)) {
144
+ merged.push(conversation);
145
+ continue;
146
+ }
147
+ const pairKey = oneToOnePairKey(root);
148
+ const entries = byPair.get(pairKey) ?? [];
149
+ entries.push(conversation);
150
+ byPair.set(pairKey, entries);
151
+ }
152
+ for (const entries of byPair.values()) {
153
+ const root = entries
154
+ .map((conversation) => conversation[0])
155
+ .sort(byIdAsc)[0];
156
+ const leaf = entries
157
+ .map((conversation) => conversation[conversation.length - 1])
158
+ .sort(byIdAsc)
159
+ .at(-1);
160
+ merged.push(root.id === leaf.id ? [root] : [root, leaf]);
161
+ }
162
+ return merged.sort((a, b) => byIdAsc(b[b.length - 1], a[a.length - 1]));
127
163
  };
128
164
  /**
129
165
  * Archived conversations: threads the profile has left — detected by posts
@@ -175,17 +211,7 @@ export const listLeftConversations = async (authData) => {
175
211
  const ids = [...new Set(pairs.flatMap((pair) => [pair.rootId, pair.leafId]))];
176
212
  const byId = await hydrateLeanPostsByIds(authData, ids);
177
213
  const blocked = new Set(blockedPairIds(profile));
178
- return getUniqueBy(pairs
179
- .map(({ rootId, leafId }) => {
180
- const root = byId.get(rootId);
181
- const leaf = byId.get(leafId);
182
- if (!root || !leaf)
183
- return null;
184
- if (isOneToOneWithBlocked(root, profile, blocked))
185
- return null;
186
- return rootId === leafId ? [root] : [root, leaf];
187
- })
188
- .filter((conversation) => !!conversation), (conversation) => conversation[0].id);
214
+ return mergeOneToOnePreviews(conversationPreviewsFromPairs(pairs, byId, profile, blocked));
189
215
  };
190
216
  /**
191
217
  * Conversation detail: root plus newest capped descendants (lean mapping +
@@ -202,6 +228,106 @@ export const getConversationThread = async (root, authData, { limit = CONTEXT_NO
202
228
  const ordered = newestIds
203
229
  .map((id) => byId.get(id))
204
230
  .filter((post) => !!post)
205
- .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
231
+ .sort(byIdAsc);
206
232
  return [root, ...ordered.filter((post) => post.id !== root.id)];
207
233
  };
234
+ /**
235
+ * Non-deleted direct post whose participants (audience ∪ creator) are
236
+ * exactly the pair — tolerates legacy rows where the creator is not in the
237
+ * audience edge set.
238
+ */
239
+ const oneToOnePairPost = (profileAId, profileBId) => sql `
240
+ p.visibility = 'direct'
241
+ AND p.deleted_at IS NULL
242
+ AND NOT EXISTS (
243
+ SELECT 1 FROM audience a
244
+ WHERE a.from_id = p.id::text
245
+ AND a.to_id <> ${profileAId}
246
+ AND a.to_id <> ${profileBId}
247
+ )
248
+ AND (p.creator_id = ${profileAId} OR EXISTS (
249
+ SELECT 1 FROM audience a
250
+ WHERE a.from_id = p.id::text AND a.to_id = ${profileAId}
251
+ ))
252
+ AND (p.creator_id = ${profileBId} OR EXISTS (
253
+ SELECT 1 FROM audience a
254
+ WHERE a.from_id = p.id::text AND a.to_id = ${profileBId}
255
+ ))
256
+ `;
257
+ /**
258
+ * All post ids in the 1:1 conversation between two profiles, oldest first:
259
+ * every post of the pair, plus their reply descendants (e.g. system "left"
260
+ * posts, whose participants are only the remaining participant and which
261
+ * are reachable as descendants only). Ids are uuidv7, so ordering is
262
+ * chronological.
263
+ */
264
+ export const listOneToOneConversationPostIds = async (db, profileAId, profileBId) => {
265
+ const result = (await db.execute(sql `
266
+ WITH RECURSIVE start AS (
267
+ SELECT p.id::text AS id
268
+ FROM posts p
269
+ WHERE ${oneToOnePairPost(profileAId, profileBId)}
270
+ ),
271
+ walk AS (
272
+ SELECT id FROM start
273
+ UNION ALL
274
+ SELECT rt.from_id::text
275
+ FROM reply_to rt
276
+ INNER JOIN walk ON rt.to_id = walk.id
277
+ )
278
+ SELECT DISTINCT id FROM walk
279
+ ORDER BY id
280
+ `));
281
+ return result.rows.map((row) => row.id);
282
+ };
283
+ /**
284
+ * Per root of a 1:1 conversation: the root id and that thread's newest post
285
+ * (leaf). Used to terminate every root's thread on leave.
286
+ */
287
+ export const listOneToOneConversationRootLeaves = async (db, profileAId, profileBId) => {
288
+ const result = (await db.execute(sql `
289
+ WITH RECURSIVE start AS (
290
+ SELECT p.id::text AS root_id, p.id::text AS node_id
291
+ FROM posts p
292
+ WHERE ${oneToOnePairPost(profileAId, profileBId)}
293
+ AND NOT EXISTS (
294
+ SELECT 1 FROM reply_to rt
295
+ WHERE rt.from_id = p.id::text
296
+ )
297
+ ),
298
+ walk AS (
299
+ SELECT root_id, node_id FROM start
300
+ UNION ALL
301
+ SELECT walk.root_id, rt.from_id::text
302
+ FROM reply_to rt
303
+ INNER JOIN walk ON rt.to_id = walk.node_id
304
+ )
305
+ SELECT DISTINCT ON (root_id) root_id, node_id AS leaf_id
306
+ FROM walk
307
+ ORDER BY root_id, node_id DESC
308
+ `));
309
+ return result.rows.map((row) => ({
310
+ rootId: row.root_id,
311
+ leafId: row.leaf_id,
312
+ }));
313
+ };
314
+ /**
315
+ * Merged 1:1 conversation: every message for the pair across all roots,
316
+ * oldest first. Any post of the conversation (typically the root in the URL)
317
+ * resolves to the same list. Capped like {@link getConversationThread}:
318
+ * the oldest message plus the newest CONTEXT_NODE_CAP others.
319
+ */
320
+ export const getOneToOneConversation = async (post, authData) => {
321
+ const { db } = await allpeepDb();
322
+ const [profileAId, profileBId] = [...participantIds(post)];
323
+ const ids = await listOneToOneConversationPostIds(db, profileAId, profileBId);
324
+ if (ids.length === 0)
325
+ return [];
326
+ const capped = ids.length > CONTEXT_NODE_CAP + 1
327
+ ? [ids[0], ...ids.slice(-CONTEXT_NODE_CAP)]
328
+ : ids;
329
+ const byId = await hydrateLeanPostsByIds(authData, [...new Set(capped)]);
330
+ return capped
331
+ .map((id) => byId.get(id))
332
+ .filter((message) => !!message);
333
+ };
@@ -1,4 +1,4 @@
1
- import { notInArray, and, asc, desc, eq, gt, isNotNull, isNull, lte, or, sql, } from 'drizzle-orm';
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
- return or(gt(start, now), and(isNotNull(end), gt(end, now)));
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.
@@ -44,7 +44,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
44
44
  };
45
45
  description?: string | undefined;
46
46
  blurhash?: string | undefined;
47
- status?: "failed" | "processing" | "ready" | undefined;
47
+ status?: "failed" | "ready" | "processing" | undefined;
48
48
  error?: string | undefined;
49
49
  }[] | undefined;
50
50
  customEmojis?: {
@@ -81,7 +81,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
81
81
  };
82
82
  description?: string | undefined;
83
83
  blurhash?: string | undefined;
84
- status?: "failed" | "processing" | "ready" | undefined;
84
+ status?: "failed" | "ready" | "processing" | undefined;
85
85
  error?: string | undefined;
86
86
  }[] | undefined;
87
87
  customEmojis?: {
@@ -119,7 +119,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
119
119
  };
120
120
  description?: string | undefined;
121
121
  blurhash?: string | undefined;
122
- status?: "failed" | "processing" | "ready" | undefined;
122
+ status?: "failed" | "ready" | "processing" | undefined;
123
123
  error?: string | undefined;
124
124
  }[] | undefined;
125
125
  customEmojis?: {
@@ -135,6 +135,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
135
135
  image?: string | undefined;
136
136
  end?: string | undefined;
137
137
  maxAttendees?: number | undefined;
138
+ waitlistOfferMinutes?: number | undefined;
138
139
  attendeeListPublic?: boolean | undefined;
139
140
  moderators?: string[] | undefined;
140
141
  jam?: {
@@ -201,7 +202,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
201
202
  };
202
203
  description?: string | undefined;
203
204
  blurhash?: string | undefined;
204
- status?: "failed" | "processing" | "ready" | undefined;
205
+ status?: "failed" | "ready" | "processing" | undefined;
205
206
  error?: string | undefined;
206
207
  }[] | undefined;
207
208
  customEmojis?: {
@@ -217,7 +218,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
217
218
  } | {
218
219
  type: "resource";
219
220
  title: string;
220
- resourceKind: "link" | "file" | "video" | "gallery" | "audio";
221
+ resourceKind: "file" | "link" | "video" | "gallery" | "audio";
221
222
  content?: string | undefined;
222
223
  sensitive?: boolean | undefined;
223
224
  spoilerText?: string | undefined;
@@ -238,7 +239,7 @@ export declare const baseEventsFeed: (profile?: ProfileWithMeta) => Mapping<{
238
239
  };
239
240
  description?: string | undefined;
240
241
  blurhash?: string | undefined;
241
- status?: "failed" | "processing" | "ready" | undefined;
242
+ status?: "failed" | "ready" | "processing" | undefined;
242
243
  error?: string | undefined;
243
244
  }[] | undefined;
244
245
  customEmojis?: {
@@ -361,7 +362,15 @@ export declare const listPastGroupEventsFeed: (authData: AuthorizationData, grou
361
362
  }) => Promise<PostWithMeta[]>;
362
363
  export declare const reposts: (post: PostWithMeta, authData: AuthorizationData) => Promise<PostWithMeta[]>;
363
364
  export declare const getConversationByEnd: (post: PostWithMeta, authData: AuthorizationData) => Promise<PostWithMeta[]>;
365
+ /**
366
+ * 1:1 conversations can span several roots (new messages to the same person,
367
+ * federated posts): answer with the merged conversation across all roots so
368
+ * any root — or even the system "left" post — of the pair resolves to the
369
+ * same view. Group conversations stay per root.
370
+ */
364
371
  export declare const getConversationByStart: (post: PostWithMeta, authData: AuthorizationData) => Promise<PostWithMeta[]>;
372
+ /** Newest post across all roots of a 1:1 conversation (uuidv7-ordered). */
373
+ export declare const findLatestOneToOnePostId: (post: PostWithMeta) => Promise<string>;
365
374
  /** Full ancestor/descendant trees for post detail (CTE + lean mapping). */
366
375
  export declare const getPostContext: (post: PostWithMeta, authData: AuthorizationData) => Promise<{
367
376
  ancestors: PostWithMeta[];
@@ -1,5 +1,5 @@
1
1
  import { parseFeedFormat } from '@openpeepshq/common';
2
- import { blockedPairIds, isBlockedPair } from '@openpeepshq/common/lib';
2
+ import { blockedPairIds, isBlockedPair, isOneToOneDm, participantIds, } from '@openpeepshq/common/lib';
3
3
  import { allpeepDb, collectionInfos } from '../db/index.js';
4
4
  import { edgeFilters, postFilters } from '../db/pg/filters/index.js';
5
5
  import { contextRelation, conversationLeavesMappingForProfile, postContextMappingForProfile, postsAuthMapping, postsMappingForProfile, repostsOfPostRelationForProfile, postIdsMapping, } from './mapping.js';
@@ -13,7 +13,7 @@ import { profilesMapping } from '../profiles/mapping.js';
13
13
  import { CONTEXT_NODE_CAP, loadReplyContextPosts } from './contextClosure.js';
14
14
  import { withSpan } from '../performance/index.js';
15
15
  import { queryUnseenPostCounts } from './unseenCounts.js';
16
- import { getConversationThread } from './conversationQueries.js';
16
+ import { getConversationThread, getOneToOneConversation, listOneToOneConversationPostIds, } from './conversationQueries.js';
17
17
  import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
18
18
  import { listEventAgenda } from './eventAgenda.js';
19
19
  /**
@@ -285,7 +285,27 @@ export const listPastGroupEventsFeed = async (authData, groupId, { offset, limit
285
285
  };
286
286
  export const reposts = async (post, authData) => toFilteredPostsList(postsMappingForProfile(authData.profile).relationsFrom(post, repostsOfPostRelationForProfile(authData.profile)), { authData });
287
287
  export const getConversationByEnd = async (post, authData) => ancestors(authData, post, 9999, sortOldestFirst(postsMappingForProfile(authData.profile))).then((conversation) => [...conversation, post]);
288
- export const getConversationByStart = async (post, authData) => getConversationThread(post, authData);
288
+ /**
289
+ * 1:1 conversations can span several roots (new messages to the same person,
290
+ * federated posts): answer with the merged conversation across all roots so
291
+ * any root — or even the system "left" post — of the pair resolves to the
292
+ * same view. Group conversations stay per root.
293
+ */
294
+ export const getConversationByStart = async (post, authData) => {
295
+ if (isOneToOneDm(post)) {
296
+ const conversation = await getOneToOneConversation(post, authData);
297
+ if (conversation.length > 0)
298
+ return conversation;
299
+ }
300
+ return getConversationThread(post, authData);
301
+ };
302
+ /** Newest post across all roots of a 1:1 conversation (uuidv7-ordered). */
303
+ export const findLatestOneToOnePostId = async (post) => {
304
+ const { db } = await allpeepDb();
305
+ const [profileAId, profileBId] = [...participantIds(post)];
306
+ const ids = await listOneToOneConversationPostIds(db, profileAId, profileBId);
307
+ return ids[ids.length - 1] ?? post.id;
308
+ };
289
309
  /** Full ancestor/descendant trees for post detail (CTE + lean mapping). */
290
310
  export const getPostContext = async (post, authData) => {
291
311
  const mapping = sortOldestFirst(postContextMappingForProfile(authData.profile));