@openpeepshq/core 0.1.31 → 0.1.32

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 (69) hide show
  1. package/dist/analytics/clicks.d.ts +20 -0
  2. package/dist/analytics/clicks.js +194 -0
  3. package/dist/analytics/index.d.ts +1 -0
  4. package/dist/analytics/index.js +1 -0
  5. package/dist/analytics/metrics.d.ts +1 -0
  6. package/dist/analytics/metrics.js +5 -0
  7. package/dist/analytics/pdfReport.js +2 -1
  8. package/dist/analytics/read.js +51 -6
  9. package/dist/analytics/report.d.ts +31 -0
  10. package/dist/backups/index.js +7 -2
  11. package/dist/config/defaults/core.js +1 -0
  12. package/dist/config/index.d.ts +10 -0
  13. package/dist/db/pg/queries/derived.d.ts +5 -0
  14. package/dist/db/pg/queries/derived.js +21 -0
  15. package/dist/db/pg/schema/analytics.d.ts +76 -0
  16. package/dist/db/pg/schema/analytics.js +11 -1
  17. package/dist/db/pg/schema/edges.js +1 -1
  18. package/dist/db/pg/schema/index.d.ts +75 -0
  19. package/dist/db/pg/sql/0005_open_power_man.sql +9 -0
  20. package/dist/db/pg/sql/0006_fine_trish_tilby.sql +8 -0
  21. package/dist/db/pg/sql/meta/0004_snapshot.json +1 -1
  22. package/dist/db/pg/sql/meta/0005_snapshot.json +4179 -0
  23. package/dist/db/pg/sql/meta/0006_snapshot.json +4200 -0
  24. package/dist/db/pg/sql/meta/_journal.json +14 -0
  25. package/dist/db/replaceOrigin.d.ts +11 -0
  26. package/dist/db/replaceOrigin.js +110 -0
  27. package/dist/jams/helpers.d.ts +4 -4
  28. package/dist/jams/index.js +5 -1
  29. package/dist/jams/waitingRoom.d.ts +2 -0
  30. package/dist/jams/waitingRoom.js +13 -5
  31. package/dist/notifications/jobs.js +13 -2
  32. package/dist/plugins/helpers.d.ts +5 -2
  33. package/dist/plugins/helpers.js +21 -2
  34. package/dist/plugins/index.d.ts +1 -1
  35. package/dist/plugins/index.js +14 -10
  36. package/dist/posts/contextClosure.d.ts +2 -1
  37. package/dist/posts/contextClosure.js +6 -1
  38. package/dist/posts/conversationQueries.d.ts +23 -0
  39. package/dist/posts/conversationQueries.js +135 -0
  40. package/dist/posts/finders.d.ts +7 -5
  41. package/dist/posts/finders.js +24 -21
  42. package/dist/posts/helpers/index.d.ts +18 -18
  43. package/dist/posts/helpers/index.js +2 -2
  44. package/dist/posts/index.d.ts +1 -0
  45. package/dist/posts/index.js +1 -0
  46. package/dist/posts/mapping.d.ts +179 -0
  47. package/dist/posts/mapping.js +6 -6
  48. package/dist/posts/mutations.d.ts +3 -1
  49. package/dist/posts/mutations.js +27 -5
  50. package/dist/posts/unseenCounts.d.ts +10 -0
  51. package/dist/posts/unseenCounts.js +81 -0
  52. package/dist/profiles/cache.d.ts +2 -0
  53. package/dist/profiles/cache.js +19 -1
  54. package/dist/profiles/index.d.ts +1 -0
  55. package/dist/profiles/index.js +1 -0
  56. package/dist/profiles/mapping.d.ts +41 -0
  57. package/dist/profiles/mapping.js +24 -0
  58. package/dist/reports/helpers.js +2 -1
  59. package/dist/reports/mapping.js +6 -2
  60. package/dist/roles/mutations.d.ts +3 -3
  61. package/dist/roles/mutations.js +5 -3
  62. package/dist/server/index.d.ts +8 -0
  63. package/dist/session/index.d.ts +28 -0
  64. package/dist/session/index.js +79 -0
  65. package/dist/stats/finders.d.ts +220 -220
  66. package/dist/stats/mapping.d.ts +5 -5
  67. package/package.json +6 -6
  68. package/dist/db/replaceHostname.d.ts +0 -1
  69. package/dist/db/replaceHostname.js +0 -88
@@ -1,6 +1,6 @@
1
1
  import { allpeepDb, collectionInfos } from '../db/index.js';
2
2
  import { edgeFilters, postFilters } from '../db/pg/filters/index.js';
3
- import { contextRelation, conversationLeavesMappingForProfile, postContextMappingForProfile, postsMappingForProfile, repostsOfPostRelationForProfile, postIdsMapping, } from './mapping.js';
3
+ import { contextRelation, conversationLeavesMappingForProfile, postContextMappingForProfile, postsAuthMapping, postsMappingForProfile, repostsOfPostRelationForProfile, postIdsMapping, } from './mapping.js';
4
4
  import { audienceConnectionFinder, currentEventsFilter, jamFilter, localFeedFilter, mentionsConnectionFinder, myEventsFilter, myFeedFilter, myFeedGroupMembershipFilter, pastEventsFilter, toFilteredPostsList, transformPost, upcomingEventsFilter, } from './helpers/index.js';
5
5
  import { addQuerySort, addStart, sortOldestFirst } from '../db/helpers.js';
6
6
  import { sorts } from '../db/pg/queries/index.js';
@@ -10,6 +10,9 @@ import { groupsMapping } from '../groups/mapping.js';
10
10
  import { profilesMapping } from '../profiles/mapping.js';
11
11
  import { CONTEXT_NODE_CAP, loadReplyContextPosts } from './contextClosure.js';
12
12
  import { withSpan } from '../performance/index.js';
13
+ import { queryUnseenPostCounts } from './unseenCounts.js';
14
+ import { getConversationThread } from './conversationQueries.js';
15
+ import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
13
16
  /**
14
17
  * Throws if the given `authData` does not include a profile.
15
18
  *
@@ -29,6 +32,23 @@ export const findPost = async (id, authData) => {
29
32
  .then(({ db }) => postsMappingForProfile(profile).find(db, id))
30
33
  .then((post) => (post ? transformPost(post, profile) : undefined));
31
34
  };
35
+ /** Lean post load for capability checks (no nested reply/repost). */
36
+ export const findPostsForAuth = async (ids, authData) => {
37
+ if (ids.length === 0)
38
+ return [];
39
+ const profile = authData === null || authData === void 0 ? void 0 : authData.profile;
40
+ const { db } = await allpeepDb();
41
+ const mapData = postsAuthMapping.data();
42
+ const rows = await fetchRowsByIds(db, mapData.collection, ids, mapData.softDelete);
43
+ const hydrated = (await hydrateMapData(db, mapData, rows));
44
+ const byId = new Map(await Promise.all(hydrated.map(async (post) => {
45
+ const transformed = await transformPost(post, profile);
46
+ return [transformed.id, transformed];
47
+ })));
48
+ return ids
49
+ .map((id) => byId.get(id))
50
+ .filter((post) => !!post);
51
+ };
32
52
  export const postContext = async (authData, id, depth, direction, contextMapping) => {
33
53
  const profile = authData.profile;
34
54
  const mapping = postsMappingForProfile(profile);
@@ -102,25 +122,8 @@ export const getUnseenPostCounts = async (authData) => withSpan('unseen.counts',
102
122
  const groupIds = profile.memberships
103
123
  .map((membership) => membership.group.id)
104
124
  .filter((groupId) => typeof groupId === 'string');
105
- const groupCounts = Object.fromEntries(groupIds.map((groupId) => [groupId, 0]));
106
- await Promise.all(groupIds.map(async (groupId) => {
107
- const posts = await listPostsByGroup(authData, groupId, {
108
- limit: 9999,
109
- });
110
- groupCounts[groupId] = posts.filter((post) => post.seen === false && post.profile.id !== profile.id).length;
111
- }));
112
- const conversations = await Promise.all((await listConversationLeaves(authData)).map((post) => getConversationByEnd(post, authData)));
113
- const uniqueConversations = Array.from(new Map(conversations
114
- .filter((conversation) => conversation[0])
115
- .map((conversation) => [conversation[0].id, conversation])).values());
116
- const direct = Object.fromEntries(uniqueConversations
117
- .map((conversation) => {
118
- const conversationId = conversation[0].id;
119
- const unread = conversation.filter((post) => post.seen === false && post.profile.id !== profile.id).length;
120
- return [conversationId, unread];
121
- })
122
- .filter(([, unread]) => unread > 0));
123
- return { groups: groupCounts, direct };
125
+ const { db } = await allpeepDb();
126
+ return queryUnseenPostCounts(db, profile.id, groupIds);
124
127
  });
125
128
  export const listPostsByType = async (authData, type, { start, limit = 100, filter, } = {
126
129
  limit: 100,
@@ -239,7 +242,7 @@ export const listPastGroupEventsFeed = async (authData, groupId, { offset, limit
239
242
  }), { authData, limit, offset });
240
243
  export const reposts = async (post, authData) => toFilteredPostsList(postsMappingForProfile(authData.profile).relationsFrom(post, repostsOfPostRelationForProfile(authData.profile)), { authData });
241
244
  export const getConversationByEnd = async (post, authData) => ancestors(authData, post, 9999, sortOldestFirst(postsMappingForProfile(authData.profile))).then((conversation) => [...conversation, post]);
242
- export const getConversationByStart = async (post, authData) => descendents(authData, post, 9999, sortOldestFirst(postsMappingForProfile(authData.profile))).then((conversation) => [post, ...conversation]);
245
+ export const getConversationByStart = async (post, authData) => getConversationThread(post, authData);
243
246
  /** Full ancestor/descendant trees for post detail (CTE + lean mapping). */
244
247
  export const getPostContext = async (post, authData) => {
245
248
  const mapping = sortOldestFirst(postContextMappingForProfile(authData.profile));
@@ -35,7 +35,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
35
35
  };
36
36
  description?: string | undefined;
37
37
  blurhash?: string | undefined;
38
- status?: "ready" | "failed" | "processing" | undefined;
38
+ status?: "failed" | "processing" | "ready" | undefined;
39
39
  error?: string | undefined;
40
40
  }[] | undefined;
41
41
  customEmojis?: {
@@ -72,7 +72,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
72
72
  };
73
73
  description?: string | undefined;
74
74
  blurhash?: string | undefined;
75
- status?: "ready" | "failed" | "processing" | undefined;
75
+ status?: "failed" | "processing" | "ready" | undefined;
76
76
  error?: string | undefined;
77
77
  }[] | undefined;
78
78
  customEmojis?: {
@@ -110,7 +110,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
110
110
  };
111
111
  description?: string | undefined;
112
112
  blurhash?: string | undefined;
113
- status?: "ready" | "failed" | "processing" | undefined;
113
+ status?: "failed" | "processing" | "ready" | undefined;
114
114
  error?: string | undefined;
115
115
  }[] | undefined;
116
116
  customEmojis?: {
@@ -171,7 +171,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
171
171
  };
172
172
  description?: string | undefined;
173
173
  blurhash?: string | undefined;
174
- status?: "ready" | "failed" | "processing" | undefined;
174
+ status?: "failed" | "processing" | "ready" | undefined;
175
175
  error?: string | undefined;
176
176
  }[] | undefined;
177
177
  customEmojis?: {
@@ -209,7 +209,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
209
209
  };
210
210
  description?: string | undefined;
211
211
  blurhash?: string | undefined;
212
- status?: "ready" | "failed" | "processing" | undefined;
212
+ status?: "failed" | "processing" | "ready" | undefined;
213
213
  error?: string | undefined;
214
214
  }[] | undefined;
215
215
  customEmojis?: {
@@ -246,7 +246,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
246
246
  };
247
247
  description?: string | undefined;
248
248
  blurhash?: string | undefined;
249
- status?: "ready" | "failed" | "processing" | undefined;
249
+ status?: "failed" | "processing" | "ready" | undefined;
250
250
  error?: string | undefined;
251
251
  }[] | undefined;
252
252
  customEmojis?: {
@@ -284,7 +284,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
284
284
  };
285
285
  description?: string | undefined;
286
286
  blurhash?: string | undefined;
287
- status?: "ready" | "failed" | "processing" | undefined;
287
+ status?: "failed" | "processing" | "ready" | undefined;
288
288
  error?: string | undefined;
289
289
  }[] | undefined;
290
290
  customEmojis?: {
@@ -345,7 +345,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
345
345
  };
346
346
  description?: string | undefined;
347
347
  blurhash?: string | undefined;
348
- status?: "ready" | "failed" | "processing" | undefined;
348
+ status?: "failed" | "processing" | "ready" | undefined;
349
349
  error?: string | undefined;
350
350
  }[] | undefined;
351
351
  customEmojis?: {
@@ -370,7 +370,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
370
370
  } | {
371
371
  type: "rsvp";
372
372
  data: {
373
- response: "no" | "yes" | "tentative" | "removed";
373
+ response: "removed" | "no" | "yes" | "tentative";
374
374
  };
375
375
  }) & {
376
376
  id?: string;
@@ -398,7 +398,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
398
398
  };
399
399
  description?: string | undefined;
400
400
  blurhash?: string | undefined;
401
- status?: "ready" | "failed" | "processing" | undefined;
401
+ status?: "failed" | "processing" | "ready" | undefined;
402
402
  error?: string | undefined;
403
403
  }[] | undefined;
404
404
  customEmojis?: {
@@ -435,7 +435,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
435
435
  };
436
436
  description?: string | undefined;
437
437
  blurhash?: string | undefined;
438
- status?: "ready" | "failed" | "processing" | undefined;
438
+ status?: "failed" | "processing" | "ready" | undefined;
439
439
  error?: string | undefined;
440
440
  }[] | undefined;
441
441
  customEmojis?: {
@@ -473,7 +473,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
473
473
  };
474
474
  description?: string | undefined;
475
475
  blurhash?: string | undefined;
476
- status?: "ready" | "failed" | "processing" | undefined;
476
+ status?: "failed" | "processing" | "ready" | undefined;
477
477
  error?: string | undefined;
478
478
  }[] | undefined;
479
479
  customEmojis?: {
@@ -534,7 +534,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
534
534
  };
535
535
  description?: string | undefined;
536
536
  blurhash?: string | undefined;
537
- status?: "ready" | "failed" | "processing" | undefined;
537
+ status?: "failed" | "processing" | "ready" | undefined;
538
538
  error?: string | undefined;
539
539
  }[] | undefined;
540
540
  customEmojis?: {
@@ -572,7 +572,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
572
572
  };
573
573
  description?: string | undefined;
574
574
  blurhash?: string | undefined;
575
- status?: "ready" | "failed" | "processing" | undefined;
575
+ status?: "failed" | "processing" | "ready" | undefined;
576
576
  error?: string | undefined;
577
577
  }[] | undefined;
578
578
  customEmojis?: {
@@ -609,7 +609,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
609
609
  };
610
610
  description?: string | undefined;
611
611
  blurhash?: string | undefined;
612
- status?: "ready" | "failed" | "processing" | undefined;
612
+ status?: "failed" | "processing" | "ready" | undefined;
613
613
  error?: string | undefined;
614
614
  }[] | undefined;
615
615
  customEmojis?: {
@@ -647,7 +647,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
647
647
  };
648
648
  description?: string | undefined;
649
649
  blurhash?: string | undefined;
650
- status?: "ready" | "failed" | "processing" | undefined;
650
+ status?: "failed" | "processing" | "ready" | undefined;
651
651
  error?: string | undefined;
652
652
  }[] | undefined;
653
653
  customEmojis?: {
@@ -708,7 +708,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
708
708
  };
709
709
  description?: string | undefined;
710
710
  blurhash?: string | undefined;
711
- status?: "ready" | "failed" | "processing" | undefined;
711
+ status?: "failed" | "processing" | "ready" | undefined;
712
712
  error?: string | undefined;
713
713
  }[] | undefined;
714
714
  customEmojis?: {
@@ -733,7 +733,7 @@ export declare const entryConnector: (db: import("../../db").PgDb, from: Profile
733
733
  } | {
734
734
  type: "rsvp";
735
735
  data: {
736
- response: "no" | "yes" | "tentative" | "removed";
736
+ response: "removed" | "no" | "yes" | "tentative";
737
737
  };
738
738
  }) & {
739
739
  _from: string;
@@ -1,11 +1,11 @@
1
1
  import { hashtagRegex, normalizeHashtagTag, handleRegex, } from '@openpeepshq/common/types';
2
2
  import { findProfileByHandle } from '../../profiles/finders.js';
3
+ import { getPublicProfile } from '../../profiles/cache.js';
3
4
  import { composeFilters, connectionFinder, connector, disconnector, filterAndTransform, } from '../../db/helpers.js';
4
5
  import { allpeepDb, collectionInfos } from '../../db/index.js';
5
6
  import { capabilitiesConfig } from '../../config/index.js';
6
7
  import { canReadPost } from './filters.js';
7
8
  import { anonymizeProfileIfDeleted, normalizePostDataFromDb, } from '@openpeepshq/common/lib';
8
- import { getProfile } from '../../profiles/cache.js';
9
9
  export const isDirect = (post) => post.visibility === 'direct';
10
10
  export const isPrivate = (post) => post.visibility === 'private';
11
11
  export const isUnlisted = (post) => post.visibility === 'unlisted';
@@ -66,7 +66,7 @@ export const reactionDisconnector = disconnector(collectionInfos.profilesCollect
66
66
  export const bookmarkConnector = connector(collectionInfos.profilesCollection, collectionInfos.postsCollection, collectionInfos.bookmarksCollection);
67
67
  export const bookmarkDisconnector = disconnector(collectionInfos.profilesCollection, collectionInfos.postsCollection, collectionInfos.bookmarksCollection);
68
68
  export const postSeenConnector = connector(collectionInfos.profilesCollection, collectionInfos.postsCollection, collectionInfos.postSeenCollection);
69
- const loadPublicProfile = async (profileId, ignoreSoftDelete = false) => anonymizeProfileIfDeleted(await getProfile(profileId, ignoreSoftDelete));
69
+ const loadPublicProfile = async (profileId, ignoreSoftDelete = false) => anonymizeProfileIfDeleted(await getPublicProfile(profileId, ignoreSoftDelete));
70
70
  const addProfileForEntry = async (rawEntry) => (Object.assign(Object.assign({}, rawEntry), {
71
71
  // ignoreSoftDelete: authorship must survive account removal
72
72
  profile: (await loadPublicProfile(rawEntry.profile.id, true)) }));
@@ -2,5 +2,6 @@ export * from './finders';
2
2
  export * from './mutations';
3
3
  export * from './mapping';
4
4
  export { CONTEXT_NODE_CAP, collectReplyClosureIds, loadReplyContextPosts, } from './contextClosure';
5
+ export { listConversationPreviews, getConversationThread, findLatestThreadPostId, } from './conversationQueries';
5
6
  export * from './helpers';
6
7
  export { registerRsvpConfirmationEmail } from './rsvpConfirmationEmail';
@@ -2,5 +2,6 @@ export * from './finders.js';
2
2
  export * from './mutations.js';
3
3
  export * from './mapping.js';
4
4
  export { CONTEXT_NODE_CAP, collectReplyClosureIds, loadReplyContextPosts, } from './contextClosure.js';
5
+ export { listConversationPreviews, getConversationThread, findLatestThreadPostId, } from './conversationQueries.js';
5
6
  export * from './helpers/index.js';
6
7
  export { registerRsvpConfirmationEmail } from './rsvpConfirmationEmail.js';
@@ -1284,6 +1284,185 @@ export declare const postsMapping: Mapping<{
1284
1284
  title?: string | undefined;
1285
1285
  } | undefined;
1286
1286
  }, DbPost, DbPost>;
1287
+ /** Auth / mark-seen: post graph without nested replyTo/repost hydrate. */
1288
+ export declare const postsAuthMapping: Mapping<{
1289
+ type: "note" | "question" | "event" | "article";
1290
+ visibility: "direct" | "group" | "local" | "report" | "public" | "unlisted" | "private";
1291
+ creatorId: string;
1292
+ capabilitiesNeeded?: string[] | undefined;
1293
+ data?: {
1294
+ type: "note";
1295
+ content?: string | undefined;
1296
+ sensitive?: boolean | undefined;
1297
+ spoilerText?: string | undefined;
1298
+ attachments?: {
1299
+ type: string;
1300
+ url: string;
1301
+ previewUrl: string | null;
1302
+ textUrl: null;
1303
+ filename: string;
1304
+ meta: {
1305
+ usage?: string | undefined;
1306
+ focus?: {
1307
+ x: number;
1308
+ y: number;
1309
+ } | undefined;
1310
+ mimetype?: string | undefined;
1311
+ size?: number | undefined;
1312
+ };
1313
+ description?: string | undefined;
1314
+ blurhash?: string | undefined;
1315
+ status?: "ready" | "failed" | "processing" | undefined;
1316
+ error?: string | undefined;
1317
+ }[] | undefined;
1318
+ customEmojis?: {
1319
+ shortcode: string;
1320
+ url: string;
1321
+ staticUrl: string;
1322
+ visibleInPicker: boolean;
1323
+ category: string;
1324
+ }[] | undefined;
1325
+ language?: string | undefined;
1326
+ } | {
1327
+ type: "question";
1328
+ options: {
1329
+ content: string;
1330
+ type: "note";
1331
+ }[];
1332
+ content?: string | undefined;
1333
+ sensitive?: boolean | undefined;
1334
+ spoilerText?: string | undefined;
1335
+ attachments?: {
1336
+ type: string;
1337
+ url: string;
1338
+ previewUrl: string | null;
1339
+ textUrl: null;
1340
+ filename: string;
1341
+ meta: {
1342
+ usage?: string | undefined;
1343
+ focus?: {
1344
+ x: number;
1345
+ y: number;
1346
+ } | undefined;
1347
+ mimetype?: string | undefined;
1348
+ size?: number | undefined;
1349
+ };
1350
+ description?: string | undefined;
1351
+ blurhash?: string | undefined;
1352
+ status?: "ready" | "failed" | "processing" | undefined;
1353
+ error?: string | undefined;
1354
+ }[] | undefined;
1355
+ customEmojis?: {
1356
+ shortcode: string;
1357
+ url: string;
1358
+ staticUrl: string;
1359
+ visibleInPicker: boolean;
1360
+ category: string;
1361
+ }[] | undefined;
1362
+ language?: string | undefined;
1363
+ multiple?: boolean | undefined;
1364
+ votersVisible?: boolean | undefined;
1365
+ expiresAt?: string | undefined;
1366
+ } | {
1367
+ type: "event";
1368
+ start: string;
1369
+ wholeDay: boolean;
1370
+ content?: string | undefined;
1371
+ sensitive?: boolean | undefined;
1372
+ spoilerText?: string | undefined;
1373
+ attachments?: {
1374
+ type: string;
1375
+ url: string;
1376
+ previewUrl: string | null;
1377
+ textUrl: null;
1378
+ filename: string;
1379
+ meta: {
1380
+ usage?: string | undefined;
1381
+ focus?: {
1382
+ x: number;
1383
+ y: number;
1384
+ } | undefined;
1385
+ mimetype?: string | undefined;
1386
+ size?: number | undefined;
1387
+ };
1388
+ description?: string | undefined;
1389
+ blurhash?: string | undefined;
1390
+ status?: "ready" | "failed" | "processing" | undefined;
1391
+ error?: string | undefined;
1392
+ }[] | undefined;
1393
+ customEmojis?: {
1394
+ shortcode: string;
1395
+ url: string;
1396
+ staticUrl: string;
1397
+ visibleInPicker: boolean;
1398
+ category: string;
1399
+ }[] | undefined;
1400
+ language?: string | undefined;
1401
+ name?: string | undefined;
1402
+ timeZone?: string | undefined;
1403
+ image?: string | undefined;
1404
+ end?: string | undefined;
1405
+ maxAttendees?: number | undefined;
1406
+ attendeeListPublic?: boolean | undefined;
1407
+ moderators?: string[] | undefined;
1408
+ jam?: {
1409
+ moderators: string[];
1410
+ videoEnabled: boolean;
1411
+ type: "video-call";
1412
+ speakers?: string[] | undefined;
1413
+ presenters?: string[] | undefined;
1414
+ audience?: string[] | undefined;
1415
+ maxSpeakers?: number | undefined;
1416
+ maxPresenters?: number | undefined;
1417
+ maxAudience?: number | undefined;
1418
+ waitingRoom?: boolean | undefined;
1419
+ } | undefined;
1420
+ physicalLocation?: {
1421
+ text: string;
1422
+ coordinates?: {
1423
+ lat: number;
1424
+ lng: number;
1425
+ alt?: number | undefined;
1426
+ } | undefined;
1427
+ } | undefined;
1428
+ url?: string | undefined;
1429
+ } | {
1430
+ type: "article";
1431
+ content?: string | undefined;
1432
+ sensitive?: boolean | undefined;
1433
+ spoilerText?: string | undefined;
1434
+ attachments?: {
1435
+ type: string;
1436
+ url: string;
1437
+ previewUrl: string | null;
1438
+ textUrl: null;
1439
+ filename: string;
1440
+ meta: {
1441
+ usage?: string | undefined;
1442
+ focus?: {
1443
+ x: number;
1444
+ y: number;
1445
+ } | undefined;
1446
+ mimetype?: string | undefined;
1447
+ size?: number | undefined;
1448
+ };
1449
+ description?: string | undefined;
1450
+ blurhash?: string | undefined;
1451
+ status?: "ready" | "failed" | "processing" | undefined;
1452
+ error?: string | undefined;
1453
+ }[] | undefined;
1454
+ customEmojis?: {
1455
+ shortcode: string;
1456
+ url: string;
1457
+ staticUrl: string;
1458
+ visibleInPicker: boolean;
1459
+ category: string;
1460
+ }[] | undefined;
1461
+ language?: string | undefined;
1462
+ image?: string | undefined;
1463
+ title?: string | undefined;
1464
+ } | undefined;
1465
+ }, DbPost, DbPost>;
1287
1466
  export declare const postsMappingForProfile: (profile?: {
1288
1467
  id: string;
1289
1468
  }) => Mapping<{
@@ -3,10 +3,6 @@ import { postFilters } from '../db/pg/filters/index.js';
3
3
  import { postDerived } from '../db/pg/queries/index.js';
4
4
  import { collectionInfos } from '../db/index.js';
5
5
  import { groupsMapping } from '../groups/mapping.js';
6
- const seenByCurrentProfileDerivedProperty = (profile) => ({
7
- alias: 'seen',
8
- resolve: postDerived.seen(profile === null || profile === void 0 ? void 0 : profile.id),
9
- });
10
6
  const seenBatchByCurrentProfileDerivedProperty = (profile) => postDerived.seenBatch(profile === null || profile === void 0 ? void 0 : profile.id);
11
7
  export const entriesRelation = {
12
8
  alias: 'entries',
@@ -118,7 +114,7 @@ const basePostMapData = Object.assign(Object.assign({}, preFilterMapData), { pos
118
114
  ] });
119
115
  const basePostMapDataForProfile = (profile) => (Object.assign(Object.assign({}, basePostMapData), { postFilterDerivedProperties: [
120
116
  ...(basePostMapData.postFilterDerivedProperties || []),
121
- seenByCurrentProfileDerivedProperty(profile),
117
+ seenBatchByCurrentProfileDerivedProperty(profile),
122
118
  ] }));
123
119
  const replyPostMapData = Object.assign(Object.assign({}, preFilterMapData), { postFilterRelations: [entriesRelation] });
124
120
  const replyToRelation = {
@@ -177,14 +173,18 @@ export const postsMapping = map(Object.assign(Object.assign({}, basePostMapData)
177
173
  repostRelation,
178
174
  replyToRelation,
179
175
  ] }));
176
+ /** Auth / mark-seen: post graph without nested replyTo/repost hydrate. */
177
+ export const postsAuthMapping = map(Object.assign(Object.assign({}, basePostMapData), { postFilterRelations: basePostFilterRelations }));
180
178
  export const postsMappingForProfile = (profile) => map(Object.assign(Object.assign({}, basePostMapDataForProfile(profile)), { postFilterRelations: [
181
179
  ...basePostFilterRelations,
182
180
  repostRelationForProfile(profile),
183
181
  replyToRelation,
184
182
  ] }));
185
- /** Lean mapping for post detail context — skips audience + nested repost. */
183
+ /** Lean mapping for post detail context — skips nested repost. Audience is
184
+ * required so direct replies stay readable to the thread's recipients. */
186
185
  const contextPostFilterRelations = [
187
186
  entriesRelation,
187
+ audienceRelation,
188
188
  groupRelation,
189
189
  replyCountRelation,
190
190
  repostCountRelation,
@@ -11,7 +11,9 @@ export declare const reactToPost: (post: PostWithMeta, profile: Profile, data: R
11
11
  export declare const retractReaction: (post: PostWithMeta, profile: Profile) => Promise<void>;
12
12
  export declare const bookmarkPost: (post: PostWithMeta, profile: Profile) => Promise<void>;
13
13
  export declare const unbookmarkPost: (post: PostWithMeta, profile: Profile) => Promise<void>;
14
- export declare const markPostsSeen: (posts: PostWithMeta[], profile: Profile) => Promise<void>;
14
+ export declare const markPostsSeen: (posts: {
15
+ id: string;
16
+ }[], profile: Profile) => Promise<void>;
15
17
  export declare const markGroupPostsSeen: (authData: AuthorizationData, groupId: string) => Promise<void>;
16
18
  export declare const deletePost: (post: PostWithMeta, profile: Profile) => Promise<import("@openpeepshq/common").DbPost | undefined>;
17
19
  export declare const vote: (profile: Profile, post: PostWithMeta, data: Answer) => Promise<void>;
@@ -1,5 +1,8 @@
1
1
  import { allpeepDb } from '../db/index.js';
2
- import { audienceConnector, bookmarkConnector, bookmarkDisconnector, entryConnector, extractHashtags, groupConnector, hashtagConnector, hashtagDisconnector, mentionConnector, postSeenConnector, reactionConnector, reactionDisconnector, replyConnector, repostConnector, resolveMentionsForPost, transformPost, } from './helpers/index.js';
2
+ import { uuidv7 } from 'uuidv7';
3
+ import { nowIso } from '../db/pg/mappers.js';
4
+ import { postSeen } from '../db/pg/schema/edges.js';
5
+ import { audienceConnector, bookmarkConnector, bookmarkDisconnector, entryConnector, extractHashtags, groupConnector, hashtagConnector, hashtagDisconnector, mentionConnector, reactionConnector, reactionDisconnector, replyConnector, repostConnector, resolveMentionsForPost, transformPost, } from './helpers/index.js';
3
6
  import { postsMapping, repostRelation } from './mapping.js';
4
7
  import { findGroup } from '../groups/finders.js';
5
8
  import { findOrCreateHashtag } from '../hashtags/index.js';
@@ -8,6 +11,7 @@ import { listPostsByGroup } from './finders.js';
8
11
  import { canManageEventRsvps, countYesRsvps, eventDataForDbUpdate, getEffectiveRsvp, normalizeEventDataForSave, passThroughUndefined, } from '@openpeepshq/common/lib';
9
12
  import { forbidden, unprocessableRequest } from '../errors/index.js';
10
13
  export const createPost = async (data, profile, postData, relations = {}) => {
14
+ var _a;
11
15
  if (data.type === 'event') {
12
16
  data = normalizeEventDataForSave(data);
13
17
  }
@@ -53,9 +57,12 @@ export const createPost = async (data, profile, postData, relations = {}) => {
53
57
  if (mentions.length) {
54
58
  await Promise.all(mentions.map(async (mention) => mentionConnector(db, post, mention.profile, { text: mention.text })));
55
59
  }
56
- if (relations.audience) {
57
- await Promise.all(relations.audience.map(async (profile) => {
58
- await audienceConnector(db, post, profile);
60
+ const audienceToLink = ((_a = relations.audience) === null || _a === void 0 ? void 0 : _a.length)
61
+ ? relations.audience
62
+ : repliedToPost === null || repliedToPost === void 0 ? void 0 : repliedToPost.audience;
63
+ if (audienceToLink === null || audienceToLink === void 0 ? void 0 : audienceToLink.length) {
64
+ await Promise.all(audienceToLink.map(async (member) => {
65
+ await audienceConnector(db, post, member);
59
66
  }));
60
67
  }
61
68
  const newPost = await postsMapping.find(db, post.id);
@@ -95,8 +102,23 @@ export const retractReaction = async (post, profile) => allpeepDb().then(({ db }
95
102
  export const bookmarkPost = async (post, profile) => allpeepDb().then(({ db }) => bookmarkConnector(db, profile, post).then(() => hub.emit('bookmarkCreated', profile, post)));
96
103
  export const unbookmarkPost = async (post, profile) => allpeepDb().then(({ db }) => bookmarkDisconnector(db, profile, post));
97
104
  export const markPostsSeen = async (posts, profile) => {
105
+ if (posts.length === 0)
106
+ return;
98
107
  const { db } = await allpeepDb();
99
- await Promise.all(posts.map((post) => postSeenConnector(db, profile, post)));
108
+ const ts = nowIso();
109
+ await db
110
+ .insert(postSeen)
111
+ .values(posts.map((post) => ({
112
+ id: uuidv7(),
113
+ fromId: profile.id,
114
+ toId: post.id,
115
+ body: {},
116
+ createdAt: ts,
117
+ updatedAt: ts,
118
+ })))
119
+ .onConflictDoNothing({
120
+ target: [postSeen.fromId, postSeen.toId],
121
+ });
100
122
  };
101
123
  export const markGroupPostsSeen = async (authData, groupId) => {
102
124
  if (!authData.profile) {
@@ -0,0 +1,10 @@
1
+ import type { UnseenPostCounts } from '@openpeepshq/common/types';
2
+ import type { PgDb } from '../db/pg/client';
3
+ /** Group unseen counts via anti-join (no post hydration). */
4
+ export declare const countUnseenGroupPosts: (db: PgDb, profileId: string, groupIds: string[]) => Promise<Record<string, number>>;
5
+ /**
6
+ * Direct-message unread counts keyed by conversation root.
7
+ * Walks reply_to to roots without hydrating posts.
8
+ */
9
+ export declare const countUnseenDirectPosts: (db: PgDb, profileId: string) => Promise<Record<string, number>>;
10
+ export declare const queryUnseenPostCounts: (db: PgDb, profileId: string, groupIds: string[]) => Promise<UnseenPostCounts>;