@pmate/chat-sdk 0.12.0-next.91 → 0.12.0-next.92
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.
|
@@ -52,7 +52,7 @@ type InboxLease = {
|
|
|
52
52
|
expiresAt: number;
|
|
53
53
|
};
|
|
54
54
|
export type InboxMessage = ChatReaderSocialMessage & {
|
|
55
|
-
seq
|
|
55
|
+
seq?: number;
|
|
56
56
|
recalled?: boolean;
|
|
57
57
|
};
|
|
58
58
|
type MessageRow = {
|
|
@@ -144,7 +144,7 @@ export declare class IndexedDbInbox {
|
|
|
144
144
|
recipients?: string[];
|
|
145
145
|
clientCreatedAt?: number;
|
|
146
146
|
serverCreatedAt: number;
|
|
147
|
-
seq
|
|
147
|
+
seq?: number;
|
|
148
148
|
}[]>;
|
|
149
149
|
conversationMessages(thread: string, teamId: string): Promise<{
|
|
150
150
|
recalled: boolean;
|
|
@@ -160,7 +160,7 @@ export declare class IndexedDbInbox {
|
|
|
160
160
|
recipients?: string[];
|
|
161
161
|
clientCreatedAt?: number;
|
|
162
162
|
serverCreatedAt: number;
|
|
163
|
-
seq
|
|
163
|
+
seq?: number;
|
|
164
164
|
}[]>;
|
|
165
165
|
conversationMessage(thread: string, teamId: string, id: string): Promise<{
|
|
166
166
|
sourceThreadId?: string;
|
|
@@ -176,7 +176,7 @@ export declare class IndexedDbInbox {
|
|
|
176
176
|
recipients?: string[];
|
|
177
177
|
clientCreatedAt?: number;
|
|
178
178
|
serverCreatedAt: number;
|
|
179
|
-
seq
|
|
179
|
+
seq?: number;
|
|
180
180
|
} | undefined>;
|
|
181
181
|
conversationChanges(thread: string, teamId: string, afterSeq: string, afterId?: string): Promise<{
|
|
182
182
|
changeSeq: string;
|
|
@@ -124,7 +124,7 @@ export class IndexedDbInbox {
|
|
|
124
124
|
switch (event.kind) {
|
|
125
125
|
case "messageAdded": {
|
|
126
126
|
const message = data, thread = message.threadId;
|
|
127
|
-
if (!thread || !message.messageId || !message.from || !Number.isSafeInteger(message.seq) || message.seq < 1 || !["dm", "group"].includes(message.threadKind))
|
|
127
|
+
if (!thread || !message.messageId || !message.from || typeof message.seq !== "number" || !Number.isSafeInteger(message.seq) || message.seq < 1 || !["dm", "group"].includes(message.threadKind))
|
|
128
128
|
throw new Error("INVALID_INBOX_MESSAGE");
|
|
129
129
|
if (message.from !== this.scope.profileId && !message.recipients?.includes(this.scope.profileId) && !(message.threadKind === "dm" && message.to === this.scope.profileId))
|
|
130
130
|
throw new Error("INBOX_MESSAGE_INACCESSIBLE");
|
|
@@ -133,7 +133,6 @@ export class IndexedDbInbox {
|
|
|
133
133
|
if (body?.kind === "group") {
|
|
134
134
|
await this.facts.put({ owner, kind: "groupControl", id: message.messageId, thread, value: data });
|
|
135
135
|
await this.facts.put({ owner, kind: "structure", id: thread, thread, value: { seq: event.inboxSeq } });
|
|
136
|
-
return thread;
|
|
137
136
|
}
|
|
138
137
|
if (basis || event.acceptedAt < windowStart)
|
|
139
138
|
return thread;
|
|
@@ -190,6 +189,18 @@ export class IndexedDbInbox {
|
|
|
190
189
|
if (!data.pairId || ![data.actorId, data.targetId].includes(this.scope.profileId))
|
|
191
190
|
throw new Error("INVALID_INBOX_RELATIONSHIP");
|
|
192
191
|
await this.facts.put({ owner, kind: event.kind, id: data.pairId, thread: data.threadId, value: data });
|
|
192
|
+
// Older relationship logs contain the invitation's identity, without a
|
|
193
|
+
// sequence append. Reconstruct that display item without inventing a read
|
|
194
|
+
// ordinal or replacing a later authoritative message with the same ID.
|
|
195
|
+
if (data.action === "friendRequest" && typeof data.messageId === "string" && !basis && event.acceptedAt >= windowStart) {
|
|
196
|
+
if (!data.threadId || !Number.isSafeInteger(data.createdAt))
|
|
197
|
+
throw new Error("INVALID_INBOX_INVITATION");
|
|
198
|
+
await this.threads.put({ owner, id: data.threadId, kind: "dm", teamId: data.teamId ?? undefined, targetId: data.targetId });
|
|
199
|
+
if (!await this.messages.get([owner, data.threadId, data.messageId])) {
|
|
200
|
+
const value = { appId: this.scope.appId, teamId: data.teamId ?? undefined, threadId: data.threadId, threadKind: "dm", messageId: data.messageId, from: data.actorId, to: data.targetId, recipients: [data.targetId], serverCreatedAt: data.createdAt, body: { kind: "contact", threadKind: "dm", action: "friendRequest", payload: { appId: this.scope.appId, ...(data.teamId ? { teamId: data.teamId } : {}) } } };
|
|
201
|
+
await this.messages.put({ owner, thread: data.threadId, id: data.messageId, acceptedAt: event.acceptedAt, time: data.createdAt, seq: 0, changeSeq: event.inboxSeq.padStart(19, "0"), root: "", recalled: false, value });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
193
204
|
return data.threadId;
|
|
194
205
|
}
|
|
195
206
|
default: throw new Error(`UNSUPPORTED_INBOX_EVENT:${event.kind}`);
|
|
@@ -230,6 +241,8 @@ export class IndexedDbInbox {
|
|
|
230
241
|
if (!thread)
|
|
231
242
|
continue;
|
|
232
243
|
const message = row.value, body = message.body;
|
|
244
|
+
if (body?.kind === "group" || row.seq < 1)
|
|
245
|
+
continue;
|
|
233
246
|
const mentions = body?.content?.mentions ?? body?.content?.content?.mentions ?? [];
|
|
234
247
|
const visible = body?.kind === undefined || ["message", "quote"].includes(body.kind) || body.kind === "contact" && ["friendRequest", "requestFriend"].includes(body.action);
|
|
235
248
|
thread.messages.push({ id: row.id, seq: row.seq, from: message.from, recipients: message.recipients ?? [], threadRootId: row.root || undefined, mentions: [...new Set(Array.isArray(mentions) ? mentions.filter(item => item && typeof item.id === "string" && (this.scope.appId !== "pmate:merry" || !["all", "所有人"].includes(item.name))).map(item => item.id) : [])].sort(), readPolicy: messageRequiresPlayback(message.body) ? "explicit" : "visible", recalled: row.recalled || !visible || body?.kind === "recall" || Boolean(body?.content?.recall), payload: null, readingControl: isReadingControl(message.body, this.scope.appId) });
|
package/package.json
CHANGED