@openpeepshq/core 0.4.11 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,6 +58,7 @@ export declare const communityConfig: () => Promise<{
58
58
  contactEmail?: string | undefined;
59
59
  privacyPolicy?: string | undefined;
60
60
  termsAndConditions?: string | undefined;
61
+ bugReportUrl?: string | undefined;
61
62
  };
62
63
  content: {
63
64
  aboutPage?: string | undefined;
@@ -1,11 +1,15 @@
1
+ import type { ExpandedNotification } from '@openpeepshq/common/types';
1
2
  declare const _default: {
2
3
  type: string;
3
4
  event: string;
4
- pushRenderer: (notification: import("@openpeepshq/common").ExpandedNotification) => Promise<{
5
+ pushRenderer: (notification: ExpandedNotification) => Promise<{
5
6
  title: string;
6
7
  options: {
7
8
  body: string | undefined;
8
9
  icon: string;
10
+ data: {
11
+ url: string;
12
+ };
9
13
  actions: {
10
14
  action: string;
11
15
  title: string;
@@ -13,6 +17,7 @@ declare const _default: {
13
17
  };
14
18
  invalidateQueries: string[][];
15
19
  }>;
20
+ expander: (notification: ExpandedNotification) => Promise<ExpandedNotification>;
16
21
  eventHandler: (...eventData: unknown[]) => Promise<void>;
17
22
  };
18
23
  export default _default;
@@ -1,40 +1,75 @@
1
1
  import { findProfile } from '@openpeepshq/core/profiles';
2
2
  import { maybeCreateNotification } from '@openpeepshq/core/notifications';
3
3
  import { getProfileAvatar, profileName } from '@openpeepshq/common/lib';
4
+ import { getConversationByEnd } from '@openpeepshq/core/posts';
4
5
  import { communityConfig } from '../../../config/index.js';
5
6
  import { PUSH_INVALIDATE } from '../../pushInvalidation.js';
6
- export default {
7
- type: 'reaction',
8
- event: 'reactionCreated',
9
- pushRenderer: async (notification) => ({
7
+ const pushRenderer = async (notification) => {
8
+ const reaction = notification.data.reaction;
9
+ const direct = notification.post?.visibility === 'direct';
10
+ const path = direct
11
+ ? `/conversations/${notification.data
12
+ .conversationStart?.id}`
13
+ : `/posts/${notification.post?.id}`;
14
+ return {
10
15
  title: profileName(notification.senderProfile) +
11
16
  ' reacted with ' +
12
- notification.data.reaction +
13
- ' to your post',
17
+ reaction +
18
+ (direct ? ' to your message' : ' to your post'),
14
19
  options: {
15
- body: notification.post?.data?.content,
20
+ // DM content is never previewed in notifications.
21
+ body: direct ? undefined : notification.post?.data?.content,
16
22
  icon: getProfileAvatar(notification.senderProfile, await communityConfig()),
23
+ data: { url: path },
17
24
  actions: [
18
25
  {
19
- action: `goto:/posts/${notification.post?.id}`,
20
- title: 'Go to post',
26
+ action: `goto:${path}`,
27
+ title: direct ? 'Go to thread' : 'Go to post',
21
28
  },
22
29
  ],
23
30
  },
24
- invalidateQueries: [PUSH_INVALIDATE.posts],
25
- }),
26
- eventHandler: async (...eventData) => {
27
- const [profile, post, data] = eventData;
28
- const recipientProfile = await findProfile(post.profile.id);
29
- if (recipientProfile && recipientProfile?.id !== profile.id) {
30
- await maybeCreateNotification(recipientProfile, {
31
- type: 'reaction',
32
- fromProfileId: profile.id,
33
- postId: post.id,
34
- data: {
35
- reaction: data.reaction,
36
- },
37
- });
38
- }
39
- },
31
+ // DM threads are cached under `conversations` keys; feed posts only
32
+ // need `posts` invalidated.
33
+ invalidateQueries: [
34
+ PUSH_INVALIDATE.posts,
35
+ ...(direct ? [PUSH_INVALIDATE.conversations] : []),
36
+ ],
37
+ };
38
+ };
39
+ const expander = async (notification) => {
40
+ const post = notification.post;
41
+ if (!post || post.visibility !== 'direct')
42
+ return notification;
43
+ const conversationStart = (await getConversationByEnd(post, {
44
+ profile: notification.recipientProfile,
45
+ scopes: [],
46
+ }))[0];
47
+ return {
48
+ ...notification,
49
+ data: {
50
+ ...notification.data,
51
+ conversationStart,
52
+ },
53
+ };
54
+ };
55
+ const eventHandler = async (...eventData) => {
56
+ const [profile, post, data] = eventData;
57
+ const recipientProfile = await findProfile(post.profile.id);
58
+ if (recipientProfile && recipientProfile?.id !== profile.id) {
59
+ await maybeCreateNotification(recipientProfile, {
60
+ type: 'reaction',
61
+ fromProfileId: profile.id,
62
+ postId: post.id,
63
+ data: {
64
+ reaction: data.reaction,
65
+ },
66
+ });
67
+ }
68
+ };
69
+ export default {
70
+ type: 'reaction',
71
+ event: 'reactionCreated',
72
+ pushRenderer,
73
+ expander,
74
+ eventHandler,
40
75
  };
@@ -373,6 +373,13 @@ export declare const getConversationByStart: (post: PostWithMeta, authData: Auth
373
373
  }) => Promise<PostWithMeta[]>;
374
374
  /** Newest post across all roots of a 1:1 conversation (uuidv7-ordered). */
375
375
  export declare const findLatestOneToOnePostId: (post: PostWithMeta) => Promise<string>;
376
+ /**
377
+ * Newest post of the conversation containing `post`; its audience defines
378
+ * the current participants. Leavers stay in the audience of older posts but
379
+ * are excluded from this one. 1:1 conversations span all roots of the pair,
380
+ * group conversations stay within `post`'s thread.
381
+ */
382
+ export declare const findLatestConversationPost: (post: PostWithMeta, authData: AuthorizationData) => Promise<PostWithMeta | undefined>;
376
383
  /** Full ancestor/descendant trees for post detail (CTE + lean mapping). */
377
384
  export declare const getPostContext: (post: PostWithMeta, authData: AuthorizationData) => Promise<{
378
385
  ancestors: PostWithMeta[];
@@ -13,7 +13,8 @@ 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, getOneToOneConversation, listOneToOneConversationPostIds, } from './conversationQueries.js';
16
+ import { findLatestThreadPostId, getConversationThread, getOneToOneConversation, listOneToOneConversationPostIds, } from './conversationQueries.js';
17
+ import { findReplyRootId } from './activity.js';
17
18
  import { fetchRowsByIds, hydrateMapData } from '../db/pg/map/relations.js';
18
19
  import { listEventAgenda } from './eventAgenda.js';
19
20
  /**
@@ -306,6 +307,22 @@ export const findLatestOneToOnePostId = async (post) => {
306
307
  const ids = await listOneToOneConversationPostIds(db, profileAId, profileBId);
307
308
  return ids[ids.length - 1] ?? post.id;
308
309
  };
310
+ /**
311
+ * Newest post of the conversation containing `post`; its audience defines
312
+ * the current participants. Leavers stay in the audience of older posts but
313
+ * are excluded from this one. 1:1 conversations span all roots of the pair,
314
+ * group conversations stay within `post`'s thread.
315
+ */
316
+ export const findLatestConversationPost = async (post, authData) => {
317
+ const { db } = await allpeepDb();
318
+ const lastPostId = isOneToOneDm(post)
319
+ ? await findLatestOneToOnePostId(post)
320
+ : await findLatestThreadPostId(await findReplyRootId(db, post.id));
321
+ if (lastPostId === post.id)
322
+ return post;
323
+ const [lastPost] = await findPostsForAuth([lastPostId], authData);
324
+ return lastPost;
325
+ };
309
326
  /** Full ancestor/descendant trees for post detail (CTE + lean mapping). */
310
327
  export const getPostContext = async (post, authData) => {
311
328
  const mapping = sortOldestFirst(postContextMappingForProfile(authData.profile));
@@ -59,6 +59,7 @@ export declare const serverInfo: () => Promise<{
59
59
  contactEmail?: string | undefined;
60
60
  privacyPolicy?: string | undefined;
61
61
  termsAndConditions?: string | undefined;
62
+ bugReportUrl?: string | undefined;
62
63
  };
63
64
  content: {
64
65
  aboutPage?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/core",
3
- "version": "0.4.11",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "dependencies": {
@@ -37,10 +37,10 @@
37
37
  "type-fest": "^4.31.0",
38
38
  "uuidv7": "^1.0.2",
39
39
  "web-push": "^3.6.7",
40
- "@openpeepshq/common": "0.5.12",
40
+ "@openpeepshq/common": "0.6.0",
41
41
  "@openpeepshq/geocoder": "^0.1.2",
42
42
  "@openpeepshq/fetch-client": "^0.2.1",
43
- "@openpeepshq/i18n": "^0.4.11"
43
+ "@openpeepshq/i18n": "^0.5.0"
44
44
  },
45
45
  "main": "dist/index.js",
46
46
  "types": "dist/index.d.ts",