@pmate/chat-sdk 0.12.0-next.30 → 0.12.0-next.31

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.
@@ -31,4 +31,4 @@ export * from "./messageReaders.js";
31
31
  export * from "./createChat.js";
32
32
  export * from "./conversationRead.js";
33
33
  export { projectConversationReading, type ReadingCandidate, type MessageReadingState, type ConversationReadingView } from "./conversationReading.js";
34
- export { projectMessageTimeline, type TimelineItem, type TimelineReaction } from "./messageTimeline.js";
34
+ export { projectMessageTimeline, type TimelineItem, type TimelineReaction, type TimelineReactionEvent } from "./messageTimeline.js";
@@ -2,6 +2,9 @@ import type { StoredMessage } from "./messageStore.js";
2
2
  import type { OutgoingMessage } from "./durableSender.js";
3
3
  import type { ChatRuntimeMessage } from "./protocol.js";
4
4
  import type { MessageReadingState } from "./conversationReading.js";
5
+ export type TimelineReactionEvent = Reaction & {
6
+ threadId: string;
7
+ };
5
8
  export type TimelineReaction = {
6
9
  emojiId: string;
7
10
  userIds: string[];
@@ -18,6 +21,16 @@ export type TimelineItem<T> = {
18
21
  message: T | undefined;
19
22
  reading?: MessageReadingState;
20
23
  reactions: readonly TimelineReaction[];
24
+ reactionEvents: readonly TimelineReactionEvent[];
25
+ };
26
+ type Reaction = {
27
+ id: string;
28
+ messageId: string;
29
+ from: string;
30
+ emojiId: string;
31
+ active: boolean;
32
+ revision: number;
33
+ timestamp: number;
21
34
  };
22
35
  /** Derives one display stream without copying bodies or creating another cache.
23
36
  * Outgoing rows retain their wire identity; indexed rows take precedence. */
@@ -31,3 +44,4 @@ export declare function projectMessageTimeline<T extends StoredMessage>(input: {
31
44
  reading: Readonly<Record<string, MessageReadingState>>;
32
45
  previous?: readonly TimelineItem<T>[];
33
46
  }): readonly TimelineItem<T>[];
47
+ export {};
@@ -74,6 +74,14 @@ export function projectMessageTimeline(input) {
74
74
  }
75
75
  }
76
76
  }
77
+ const groupedEvents = new Map();
78
+ for (const event of reactions.values()) {
79
+ const values = groupedEvents.get(event.messageId) ?? [];
80
+ values.push({ ...event, threadId: input.threadId });
81
+ groupedEvents.set(event.messageId, values);
82
+ }
83
+ for (const values of groupedEvents.values())
84
+ values.sort((a, b) => a.from < b.from ? -1 : a.from > b.from ? 1 : a.emojiId < b.emojiId ? -1 : a.emojiId > b.emojiId ? 1 : 0);
77
85
  const grouped = new Map();
78
86
  for (const event of reactions.values())
79
87
  if (event.active) {
@@ -93,11 +101,12 @@ export function projectMessageTimeline(input) {
93
101
  const mine = envelope.from === input.profileId, reading = input.reading[message.id];
94
102
  const withdrawn = Boolean(message.recalled || envelope.legacyDisplay?.recalled || envelope.from && recalled.get(message.id)?.has(envelope.from));
95
103
  const item = { id: message.id, threadId: message.threadId, timestamp: message.timestamp, from: envelope.from, mine, status: !mine && reading ? (reading.read ? "read" : status === "read" ? "sent" : status) : status, recalled: withdrawn,
96
- message: withdrawn ? undefined : message, reading, reactions: withdrawn ? [] : [...(grouped.get(message.id) ?? [])].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([emojiId, users]) => { const userIds = [...users].sort(); return { emojiId, userIds, mine: userIds.includes(input.profileId) }; }) };
104
+ message: withdrawn ? undefined : message, reading, reactionEvents: withdrawn ? [] : groupedEvents.get(message.id) ?? [], reactions: withdrawn ? [] : [...(grouped.get(message.id) ?? [])].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([emojiId, users]) => { const userIds = [...users].sort(); return { emojiId, userIds, mine: userIds.includes(input.profileId) }; }) };
97
105
  const old = previous.get(item.id);
98
106
  const sameReading = old?.reading === item.reading || old?.reading?.seq === item.reading?.seq && old?.reading?.read === item.reading?.read && old?.reading?.readPolicy === item.reading?.readPolicy;
99
107
  const sameReactions = old?.reactions.length === item.reactions.length && old.reactions.every((reaction, index) => { const next = item.reactions[index]; return reaction.emojiId === next.emojiId && reaction.mine === next.mine && reaction.userIds.length === next.userIds.length && reaction.userIds.every((user, i) => user === next.userIds[i]); });
100
- result.push(old && old.message === item.message && old.timestamp === item.timestamp && old.from === item.from && old.mine === item.mine && old.status === item.status && old.recalled === item.recalled && sameReading && sameReactions ? old : item);
108
+ const sameEvents = old?.reactionEvents.length === item.reactionEvents.length && old.reactionEvents.every((event, index) => { const next = item.reactionEvents[index]; return event.id === next.id && event.from === next.from && event.emojiId === next.emojiId && event.active === next.active && event.revision === next.revision && event.timestamp === next.timestamp && event.threadId === next.threadId && event.messageId === next.messageId; });
109
+ result.push(old && sameEvents && old.message === item.message && old.timestamp === item.timestamp && old.from === item.from && old.mine === item.mine && old.status === item.status && old.recalled === item.recalled && sameReading && sameReactions ? old : item);
101
110
  }
102
111
  result.sort((a, b) => a.timestamp - b.timestamp || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
103
112
  return input.previous?.length === result.length && result.every((item, index) => item === input.previous[index]) ? input.previous : result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/chat-sdk",
3
- "version": "0.12.0-next.30",
3
+ "version": "0.12.0-next.31",
4
4
  "description": "Cross-platform PMate chat input components, voice input primitives, and ASR helpers",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",