@ai-matrx/messaging 0.1.0 → 0.1.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.
- package/CHANGELOG.md +23 -1
- package/dist/index.cjs +27 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +27 -14
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +27 -14
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +9 -0
- package/dist/react.d.ts +9 -0
- package/dist/react.js +27 -14
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.d.cts
CHANGED
|
@@ -672,6 +672,15 @@ interface MessagingStore {
|
|
|
672
672
|
ingestMany(messages: readonly Message[]): void;
|
|
673
673
|
removeMessage(conversationId: ConversationId, messageId: MessageId): void;
|
|
674
674
|
markConversationRead(id: ConversationId): void;
|
|
675
|
+
/**
|
|
676
|
+
* Move a conversation's preview + sort position to reflect a message, with NO
|
|
677
|
+
* refetch. Sending a message must not cost a conversation-list RPC — at a
|
|
678
|
+
* busy org that is one full page read per keystroke-burst, and the row's new
|
|
679
|
+
* state is entirely derivable from the message we already hold.
|
|
680
|
+
*/
|
|
681
|
+
applyLastMessage(message: Message, args?: {
|
|
682
|
+
incrementUnread?: boolean;
|
|
683
|
+
}): void;
|
|
675
684
|
setUnreadCount(id: ConversationId, count: number): void;
|
|
676
685
|
}
|
|
677
686
|
declare function createMessagingStore(): MessagingStore;
|
package/dist/react.d.ts
CHANGED
|
@@ -672,6 +672,15 @@ interface MessagingStore {
|
|
|
672
672
|
ingestMany(messages: readonly Message[]): void;
|
|
673
673
|
removeMessage(conversationId: ConversationId, messageId: MessageId): void;
|
|
674
674
|
markConversationRead(id: ConversationId): void;
|
|
675
|
+
/**
|
|
676
|
+
* Move a conversation's preview + sort position to reflect a message, with NO
|
|
677
|
+
* refetch. Sending a message must not cost a conversation-list RPC — at a
|
|
678
|
+
* busy org that is one full page read per keystroke-burst, and the row's new
|
|
679
|
+
* state is entirely derivable from the message we already hold.
|
|
680
|
+
*/
|
|
681
|
+
applyLastMessage(message: Message, args?: {
|
|
682
|
+
incrementUnread?: boolean;
|
|
683
|
+
}): void;
|
|
675
684
|
setUnreadCount(id: ConversationId, count: number): void;
|
|
676
685
|
}
|
|
677
686
|
declare function createMessagingStore(): MessagingStore;
|
package/dist/react.js
CHANGED
|
@@ -966,6 +966,29 @@ function createMessagingStore() {
|
|
|
966
966
|
});
|
|
967
967
|
emit();
|
|
968
968
|
},
|
|
969
|
+
applyLastMessage(message, args = {}) {
|
|
970
|
+
const existing = conversations.find(
|
|
971
|
+
(item) => item.conversation.id === message.conversationId
|
|
972
|
+
);
|
|
973
|
+
if (existing === void 0) return;
|
|
974
|
+
if (message.deliveryState === "sending" || message.deletedAt !== null) return;
|
|
975
|
+
if (existing.lastMessageAt !== null && message.createdAt < existing.lastMessageAt) return;
|
|
976
|
+
const isActive = activeConversationId === message.conversationId;
|
|
977
|
+
const shouldCount = args.incrementUnread === true && !isActive;
|
|
978
|
+
conversations = normalizeConversations(
|
|
979
|
+
conversations.map(
|
|
980
|
+
(item) => item.conversation.id === message.conversationId ? {
|
|
981
|
+
...item,
|
|
982
|
+
lastMessageContent: message.content,
|
|
983
|
+
lastMessageSenderId: message.senderId,
|
|
984
|
+
lastMessageAt: message.createdAt,
|
|
985
|
+
sortAt: message.createdAt,
|
|
986
|
+
unreadCount: shouldCount ? item.unreadCount + 1 : item.unreadCount
|
|
987
|
+
} : item
|
|
988
|
+
)
|
|
989
|
+
);
|
|
990
|
+
emit();
|
|
991
|
+
},
|
|
969
992
|
markConversationRead(id) {
|
|
970
993
|
conversations = conversations.map(
|
|
971
994
|
(item) => item.conversation.id === id ? { ...item, unreadCount: 0 } : item
|
|
@@ -1036,7 +1059,7 @@ function createMessagingEngine(options) {
|
|
|
1036
1059
|
onSent: (entry, message) => {
|
|
1037
1060
|
store.ingest(message);
|
|
1038
1061
|
broadcastMessage(message);
|
|
1039
|
-
|
|
1062
|
+
store.applyLastMessage(message);
|
|
1040
1063
|
void entry;
|
|
1041
1064
|
},
|
|
1042
1065
|
onChange: (entries) => {
|
|
@@ -1062,15 +1085,6 @@ function createMessagingEngine(options) {
|
|
|
1062
1085
|
function broadcastMessage(message) {
|
|
1063
1086
|
openChannels.get(message.conversationId)?.send(MESSAGING_EVENTS.message, message);
|
|
1064
1087
|
}
|
|
1065
|
-
async function refreshConversationRow(id) {
|
|
1066
|
-
try {
|
|
1067
|
-
const page = await repository.listConversations({ limit: conversationPageSize });
|
|
1068
|
-
const row = page.items.find((item) => item.conversation.id === id);
|
|
1069
|
-
if (row !== void 0) store.upsertConversation(row);
|
|
1070
|
-
} catch (error) {
|
|
1071
|
-
reportError(error, "refreshConversationRow");
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
1088
|
async function reloadInbox() {
|
|
1075
1089
|
const page = await repository.listConversations({ limit: conversationPageSize });
|
|
1076
1090
|
conversationCursor = page.nextCursor;
|
|
@@ -1121,10 +1135,9 @@ function createMessagingEngine(options) {
|
|
|
1121
1135
|
return;
|
|
1122
1136
|
}
|
|
1123
1137
|
store.ingest(message);
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
void refreshConversationRow(message.conversationId);
|
|
1138
|
+
const isMine = message.senderId === identity.userId;
|
|
1139
|
+
store.applyLastMessage(message, { incrementUnread: !isMine });
|
|
1140
|
+
if (!isMine) options.onIncoming?.(message);
|
|
1128
1141
|
}
|
|
1129
1142
|
},
|
|
1130
1143
|
{
|