@pmate/chat-sdk 0.9.10 → 0.9.11
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/lib/runtime/readSync.js +12 -0
- package/package.json +1 -1
package/lib/runtime/readSync.js
CHANGED
|
@@ -47,7 +47,19 @@ export class ReadSyncClient {
|
|
|
47
47
|
async run() {
|
|
48
48
|
const { appId, profileId, persistence } = this.options;
|
|
49
49
|
const current = await this.loadLocal();
|
|
50
|
+
// Ordinary reads are monotonic: only the furthest position per thread needs
|
|
51
|
+
// sending. Keep every original operation in storage until the projection
|
|
52
|
+
// confirms it, and never rewrite an operation ID's payload during retries.
|
|
53
|
+
const latest = new Map();
|
|
50
54
|
for (const operation of current.pending) {
|
|
55
|
+
if (operation.explicitReadMessageIds.length || operation.readThroughSeq <= 0)
|
|
56
|
+
continue;
|
|
57
|
+
const previous = latest.get(operation.threadId);
|
|
58
|
+
if (!previous || operation.readThroughSeq > previous.readThroughSeq)
|
|
59
|
+
latest.set(operation.threadId, operation);
|
|
60
|
+
}
|
|
61
|
+
const outgoing = current.pending.filter(operation => operation.explicitReadMessageIds.length || operation.readThroughSeq <= 0 || latest.get(operation.threadId) === operation);
|
|
62
|
+
for (const operation of outgoing) {
|
|
51
63
|
const receipt = await this.request("/api/social/reading", {
|
|
52
64
|
method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ ...operation, appId, profileId }),
|
|
53
65
|
});
|