@chat-leo/chatleolib 0.0.0-stage → 2.0.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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +69 -2
  3. package/dist/ChatLeoWorker.d.ts +83 -0
  4. package/dist/ChatLeoWorker.d.ts.map +1 -0
  5. package/dist/ChatLeoWorker.js +255 -0
  6. package/dist/ChatLeoWorker.js.map +1 -0
  7. package/dist/ChatRoom.d.ts +121 -0
  8. package/dist/ChatRoom.d.ts.map +1 -0
  9. package/dist/ChatRoom.js +416 -0
  10. package/dist/ChatRoom.js.map +1 -0
  11. package/dist/ChatStore.d.ts +252 -0
  12. package/dist/ChatStore.d.ts.map +1 -0
  13. package/dist/ChatStore.js +774 -0
  14. package/dist/ChatStore.js.map +1 -0
  15. package/dist/JwtUtils.d.ts +39 -0
  16. package/dist/JwtUtils.d.ts.map +1 -0
  17. package/dist/JwtUtils.js +89 -0
  18. package/dist/JwtUtils.js.map +1 -0
  19. package/dist/Outbox.d.ts +68 -0
  20. package/dist/Outbox.d.ts.map +1 -0
  21. package/dist/Outbox.js +253 -0
  22. package/dist/Outbox.js.map +1 -0
  23. package/dist/UploadManager.d.ts +80 -0
  24. package/dist/UploadManager.d.ts.map +1 -0
  25. package/dist/UploadManager.js +204 -0
  26. package/dist/UploadManager.js.map +1 -0
  27. package/dist/chatleo-push-sw.js +149 -0
  28. package/dist/chatleo-push-sw.js.map +1 -0
  29. package/dist/index.d.ts +236 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.esm.js +8526 -0
  32. package/dist/index.esm.js.map +1 -0
  33. package/dist/index.js +8535 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/index.umd.js +8541 -0
  36. package/dist/index.umd.js.map +1 -0
  37. package/dist/push/PushService.d.ts +32 -0
  38. package/dist/push/PushService.d.ts.map +1 -0
  39. package/dist/push/PushService.js +215 -0
  40. package/dist/push/PushService.js.map +1 -0
  41. package/dist/push-sw/index.d.ts +9 -0
  42. package/dist/push-sw/index.d.ts.map +1 -0
  43. package/dist/push-sw/index.js +142 -0
  44. package/dist/push-sw/index.js.map +1 -0
  45. package/dist/push-sw/standalone.d.ts +2 -0
  46. package/dist/push-sw/standalone.d.ts.map +1 -0
  47. package/dist/push-sw/standalone.js +3 -0
  48. package/dist/push-sw/standalone.js.map +1 -0
  49. package/dist/transport/SocketIoTransport.d.ts +37 -0
  50. package/dist/transport/SocketIoTransport.d.ts.map +1 -0
  51. package/dist/transport/SocketIoTransport.js +209 -0
  52. package/dist/transport/SocketIoTransport.js.map +1 -0
  53. package/dist/transport/WsV2Transport.d.ts +109 -0
  54. package/dist/transport/WsV2Transport.d.ts.map +1 -0
  55. package/dist/transport/WsV2Transport.js +604 -0
  56. package/dist/transport/WsV2Transport.js.map +1 -0
  57. package/dist/transport/discovery.d.ts +43 -0
  58. package/dist/transport/discovery.d.ts.map +1 -0
  59. package/dist/transport/discovery.js +87 -0
  60. package/dist/transport/discovery.js.map +1 -0
  61. package/dist/transport/factory.d.ts +38 -0
  62. package/dist/transport/factory.d.ts.map +1 -0
  63. package/dist/transport/factory.js +79 -0
  64. package/dist/transport/factory.js.map +1 -0
  65. package/dist/transport/index.d.ts +7 -0
  66. package/dist/transport/index.d.ts.map +1 -0
  67. package/dist/transport/index.js +5 -0
  68. package/dist/transport/index.js.map +1 -0
  69. package/dist/transport/types.d.ts +174 -0
  70. package/dist/transport/types.d.ts.map +1 -0
  71. package/dist/transport/types.js +35 -0
  72. package/dist/transport/types.js.map +1 -0
  73. package/dist/transport/util.d.ts +8 -0
  74. package/dist/transport/util.d.ts.map +1 -0
  75. package/dist/transport/util.js +33 -0
  76. package/dist/transport/util.js.map +1 -0
  77. package/dist/types/shared.d.ts +281 -0
  78. package/dist/types/shared.d.ts.map +1 -0
  79. package/dist/types/shared.js +2 -0
  80. package/dist/types/shared.js.map +1 -0
  81. package/dist/types/uploads.d.ts +14 -0
  82. package/dist/types/uploads.d.ts.map +1 -0
  83. package/dist/types/uploads.js +3 -0
  84. package/dist/types/uploads.js.map +1 -0
  85. package/package.json +70 -3
@@ -0,0 +1,416 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _ChatRoom_instances, _ChatRoom_messages, _ChatRoom_participants, _ChatRoom_name, _ChatRoom_localId, _ChatRoom_isReadOnly, _ChatRoom_byId, _ChatRoom_byClientId, _ChatRoom_seqs, _ChatRoom_minSeq, _ChatRoom_maxSeq, _ChatRoom_serverLastSeq, _ChatRoom_contiguousSeq, _ChatRoom_lastReadSeq, _ChatRoom_getUserResolver, _ChatRoom_insert, _ChatRoom_matchLegacyEcho, _ChatRoom_merge, _ChatRoom_index, _ChatRoom_reindex, _ChatRoom_trackSeq, _ChatRoom_untrackSeq, _ChatRoom_sort, _ChatRoom_compare;
13
+ /**
14
+ * @class ChatRoom
15
+ * @extends EventTarget
16
+ * @description This class represents a single chat room. It manages the messages and participants
17
+ * for the room and dispatches events when participants are added or messages are received.
18
+ *
19
+ * Messages are kept sorted by `seq` (when both sides have one), otherwise by `created_at`.
20
+ * Duplicates are removed by `id` and by the local sender's `client_id`. The room also tracks the
21
+ * last contiguous `seq` it holds so the client can resume synchronisation and detect gaps.
22
+ */
23
+ export class ChatRoom extends EventTarget {
24
+ /**
25
+ * @constructor
26
+ * @param {string} id - The unique identifier for the room.
27
+ * @param {string} _name - The name of the room.
28
+ * @param {RoomType} type - The type of the room (e.g., 'DirectMessage', 'Group').
29
+ * @param {string[]} _participants - An array of user IDs for the participants in the room.
30
+ * @param {string} _localId - The ID of the local user.
31
+ */
32
+ constructor(id, _name, type, _participants, _localId, _isReadOnly = false, _unreadCount = 0) {
33
+ super();
34
+ _ChatRoom_instances.add(this);
35
+ this.id = id;
36
+ this.type = type;
37
+ _ChatRoom_messages.set(this, void 0);
38
+ _ChatRoom_participants.set(this, void 0);
39
+ _ChatRoom_name.set(this, void 0);
40
+ _ChatRoom_localId.set(this, void 0);
41
+ _ChatRoom_isReadOnly.set(this, void 0);
42
+ _ChatRoom_byId.set(this, new Map());
43
+ _ChatRoom_byClientId.set(this, new Map());
44
+ _ChatRoom_seqs.set(this, new Set());
45
+ _ChatRoom_minSeq.set(this, void 0);
46
+ _ChatRoom_maxSeq.set(this, 0);
47
+ _ChatRoom_serverLastSeq.set(this, 0);
48
+ _ChatRoom_contiguousSeq.set(this, 0);
49
+ _ChatRoom_lastReadSeq.set(this, void 0);
50
+ this.unreadCount = 0;
51
+ this.notificationLevel = 'all';
52
+ _ChatRoom_getUserResolver.set(this, undefined);
53
+ __classPrivateFieldSet(this, _ChatRoom_name, _name, "f");
54
+ __classPrivateFieldSet(this, _ChatRoom_messages, new Array(), "f");
55
+ __classPrivateFieldSet(this, _ChatRoom_participants, Array.from(_participants), "f");
56
+ __classPrivateFieldSet(this, _ChatRoom_localId, _localId, "f");
57
+ __classPrivateFieldSet(this, _ChatRoom_isReadOnly, _isReadOnly, "f");
58
+ this.unreadCount = _unreadCount;
59
+ this.notificationLevel = 'all';
60
+ console.debug(`ChatRoom`, { _participants });
61
+ }
62
+ /**
63
+ * @method setUsernameResolver
64
+ * @description Sets a function that can be used to resolve a user's profile from their ID. This is used to get the display name for direct message rooms.
65
+ * @param {function} resolver - A function that takes a user ID and returns a `UserProfile` object or `undefined`.
66
+ */
67
+ setUsernameResolver(resolver) {
68
+ __classPrivateFieldSet(this, _ChatRoom_getUserResolver, resolver, "f");
69
+ }
70
+ /**
71
+ * @method fromRoomSummary
72
+ * @description A static factory method that creates a new `ChatRoom` instance from a `RoomSummary` object.
73
+ * @param {RoomSummary} summary - The `RoomSummary` object containing the room's data.
74
+ * @param {string} localId - The ID of the local user.
75
+ * @returns {ChatRoom} A new `ChatRoom` instance.
76
+ */
77
+ static fromRoomSummary(summary, localId) {
78
+ var _a, _b, _c;
79
+ const room = new ChatRoom(summary.id, summary.name, summary.room_type, (_a = summary.participants) !== null && _a !== void 0 ? _a : [], localId, (_b = summary.is_read_only) !== null && _b !== void 0 ? _b : false, (_c = summary.unread_count) !== null && _c !== void 0 ? _c : 0);
80
+ room.setServerMeta({
81
+ lastSeq: summary.last_seq,
82
+ lastReadSeq: summary.last_read_seq,
83
+ });
84
+ if (summary.notification_level)
85
+ room.notificationLevel = summary.notification_level;
86
+ return room;
87
+ }
88
+ /**
89
+ * @method includes
90
+ * @description Checks if a given user ID is a participant in the room.
91
+ * @param {string} participant - The user ID to check.
92
+ * @returns {boolean} `true` if the user is a participant, `false` otherwise.
93
+ */
94
+ includes(participant) {
95
+ return __classPrivateFieldGet(this, _ChatRoom_participants, "f").includes(participant);
96
+ }
97
+ /**
98
+ * @method addParticipant
99
+ * @description Adds a new participant to the room and dispatches a `participantAdded` event.
100
+ * @param {string} participant - The user ID of the participant to add.
101
+ */
102
+ addParticipant(participant) {
103
+ __classPrivateFieldGet(this, _ChatRoom_participants, "f").push(participant);
104
+ this.dispatchEvent(new CustomEvent('participantAdded', { detail: { participant } }));
105
+ }
106
+ /**
107
+ * @method addMessage
108
+ * @description Adds a single message to the room's message list and dispatches a `messageAdded`
109
+ * (or `messageUpdated` when an echo/ack merged into a local message).
110
+ */
111
+ addMessage(msg, isLive = false) {
112
+ const result = __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_insert).call(this, msg, isLive);
113
+ if (result.added) {
114
+ this.dispatchEvent(new CustomEvent('messageAdded', { detail: { roomId: this.id, message: result.message } }));
115
+ }
116
+ else if (result.updated) {
117
+ this.dispatchEvent(new CustomEvent('messageUpdated', { detail: { roomId: this.id, message: result.message } }));
118
+ }
119
+ return result.message;
120
+ }
121
+ /**
122
+ * @method addMessages
123
+ * @description Adds an array of messages (history, sync or a page of older messages). Dispatches
124
+ * one event for the whole batch so the UI does not re-render per message.
125
+ */
126
+ addMessages(msgs, isLive = false) {
127
+ let added = false;
128
+ let updated = false;
129
+ for (const msg of msgs) {
130
+ const result = __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_insert).call(this, msg, isLive);
131
+ added || (added = result.added);
132
+ updated || (updated = result.updated);
133
+ }
134
+ if (added) {
135
+ this.dispatchEvent(new CustomEvent('messageAdded', { detail: { roomId: this.id, messages: msgs } }));
136
+ }
137
+ if (updated) {
138
+ this.dispatchEvent(new CustomEvent('messageUpdated', { detail: { roomId: this.id, messages: msgs } }));
139
+ }
140
+ }
141
+ /**
142
+ * @method ackMessage
143
+ * @description Marks a pending local message as delivered and takes the server `id`, `seq` and
144
+ * `created_at`. Safe to call after the broadcast already arrived (matched by `client_id`).
145
+ */
146
+ ackMessage(clientId, ack) {
147
+ const msg = __classPrivateFieldGet(this, _ChatRoom_byClientId, "f").get(clientId);
148
+ if (!msg)
149
+ return;
150
+ const oldId = msg.id;
151
+ if (ack.id)
152
+ msg.id = ack.id;
153
+ if (typeof ack.seq === 'number')
154
+ msg.seq = ack.seq;
155
+ if (ack.createdAt)
156
+ msg.created_at = ack.createdAt;
157
+ msg.delivery = 'sent';
158
+ delete msg.error;
159
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_reindex).call(this, msg, oldId);
160
+ if (typeof ack.seq === 'number') {
161
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_trackSeq).call(this, ack.seq);
162
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_sort).call(this);
163
+ }
164
+ this.dispatchEvent(new CustomEvent('messageUpdated', { detail: { roomId: this.id, message: msg } }));
165
+ }
166
+ /** Marks a local message as permanently failed and stores the reason. */
167
+ failMessage(clientId, reason) {
168
+ const msg = __classPrivateFieldGet(this, _ChatRoom_byClientId, "f").get(clientId);
169
+ if (!msg)
170
+ return;
171
+ msg.delivery = 'failed';
172
+ msg.error = reason;
173
+ this.dispatchEvent(new CustomEvent('messageUpdated', { detail: { roomId: this.id, message: msg } }));
174
+ }
175
+ /** Puts a failed local message back into the outbox (state becomes `pending`). */
176
+ markMessagePending(clientId) {
177
+ const msg = __classPrivateFieldGet(this, _ChatRoom_byClientId, "f").get(clientId);
178
+ if (!msg)
179
+ return;
180
+ msg.delivery = 'pending';
181
+ delete msg.error;
182
+ this.dispatchEvent(new CustomEvent('messageUpdated', { detail: { roomId: this.id, message: msg } }));
183
+ }
184
+ /** Removes a local message that was discarded by the user. */
185
+ removeMessageByClientId(clientId) {
186
+ const msg = __classPrivateFieldGet(this, _ChatRoom_byClientId, "f").get(clientId);
187
+ if (!msg)
188
+ return;
189
+ const index = __classPrivateFieldGet(this, _ChatRoom_messages, "f").indexOf(msg);
190
+ if (index >= 0)
191
+ __classPrivateFieldGet(this, _ChatRoom_messages, "f").splice(index, 1);
192
+ if (msg.id)
193
+ __classPrivateFieldGet(this, _ChatRoom_byId, "f").delete(msg.id);
194
+ __classPrivateFieldGet(this, _ChatRoom_byClientId, "f").delete(clientId);
195
+ if (typeof msg.seq === 'number')
196
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_untrackSeq).call(this, msg.seq);
197
+ this.dispatchEvent(new CustomEvent('messageRemoved', { detail: { roomId: this.id, clientId } }));
198
+ }
199
+ markAsRead(seq) {
200
+ this.unreadCount = 0;
201
+ const marker = seq !== null && seq !== void 0 ? seq : __classPrivateFieldGet(this, _ChatRoom_maxSeq, "f");
202
+ this.dispatchEvent(new CustomEvent('roomRead', { detail: { roomId: this.id, seq: marker > 0 ? marker : undefined } }));
203
+ }
204
+ /** Applies a read marker from another device without reporting it back to the server. */
205
+ applyRemoteRead(seq) {
206
+ var _a, _b;
207
+ if (typeof seq === 'number') {
208
+ __classPrivateFieldSet(this, _ChatRoom_lastReadSeq, Math.max((_a = __classPrivateFieldGet(this, _ChatRoom_lastReadSeq, "f")) !== null && _a !== void 0 ? _a : 0, seq), "f");
209
+ this.unreadCount = Math.max(0, this.serverLastSeq - ((_b = __classPrivateFieldGet(this, _ChatRoom_lastReadSeq, "f")) !== null && _b !== void 0 ? _b : 0));
210
+ }
211
+ else {
212
+ this.unreadCount = 0;
213
+ }
214
+ this.dispatchEvent(new CustomEvent('roomRead', { detail: { roomId: this.id, seq: __classPrivateFieldGet(this, _ChatRoom_lastReadSeq, "f"), remote: true } }));
215
+ }
216
+ /** Confirms a marker this client sent; does not dispatch `roomRead` (avoids a feedback loop). */
217
+ confirmRead(seq) {
218
+ var _a;
219
+ __classPrivateFieldSet(this, _ChatRoom_lastReadSeq, Math.max((_a = __classPrivateFieldGet(this, _ChatRoom_lastReadSeq, "f")) !== null && _a !== void 0 ? _a : 0, seq), "f");
220
+ this.unreadCount = 0;
221
+ this.dispatchEvent(new CustomEvent('unreadCountChanged', { detail: { roomId: this.id, unreadCount: 0 } }));
222
+ }
223
+ setNotificationLevel(level) {
224
+ if (this.notificationLevel === level)
225
+ return;
226
+ this.notificationLevel = level;
227
+ this.dispatchEvent(new CustomEvent('notificationLevelChanged', { detail: { roomId: this.id, level } }));
228
+ }
229
+ setUnreadCount(count) {
230
+ const next = Math.max(0, count);
231
+ if (this.unreadCount === next)
232
+ return;
233
+ this.unreadCount = next;
234
+ this.dispatchEvent(new CustomEvent('unreadCountChanged', { detail: { roomId: this.id, unreadCount: next } }));
235
+ }
236
+ /** Applies server-side room metadata from a room list or sync response. */
237
+ setServerMeta(meta) {
238
+ var _a;
239
+ if (typeof meta.lastSeq === 'number' && meta.lastSeq > __classPrivateFieldGet(this, _ChatRoom_serverLastSeq, "f")) {
240
+ // The server knows about messages this client has not loaded yet. The sync cursor stays at
241
+ // the highest seq actually held so those messages are fetched.
242
+ __classPrivateFieldSet(this, _ChatRoom_serverLastSeq, meta.lastSeq, "f");
243
+ }
244
+ if (typeof meta.lastReadSeq === 'number') {
245
+ __classPrivateFieldSet(this, _ChatRoom_lastReadSeq, Math.max((_a = __classPrivateFieldGet(this, _ChatRoom_lastReadSeq, "f")) !== null && _a !== void 0 ? _a : 0, meta.lastReadSeq), "f");
246
+ }
247
+ if (typeof meta.unreadCount === 'number')
248
+ this.setUnreadCount(meta.unreadCount);
249
+ }
250
+ get isReadOnly() {
251
+ return __classPrivateFieldGet(this, _ChatRoom_isReadOnly, "f");
252
+ }
253
+ get name() {
254
+ var _a, _b, _c;
255
+ // console.log('Getting name', this.#name, this.#participants);
256
+ if (this.type === 'DirectMessage') {
257
+ const userId = __classPrivateFieldGet(this, _ChatRoom_participants, "f").filter(p => p !== __classPrivateFieldGet(this, _ChatRoom_localId, "f")).join('');
258
+ return (_c = (_b = (_a = __classPrivateFieldGet(this, _ChatRoom_getUserResolver, "f")) === null || _a === void 0 ? void 0 : _a.call(this, userId)) === null || _b === void 0 ? void 0 : _b.display_name) !== null && _c !== void 0 ? _c : userId;
259
+ }
260
+ return __classPrivateFieldGet(this, _ChatRoom_name, "f");
261
+ }
262
+ get participantIds() {
263
+ return __classPrivateFieldGet(this, _ChatRoom_participants, "f");
264
+ }
265
+ get participantIdsWithoutSelf() {
266
+ return __classPrivateFieldGet(this, _ChatRoom_participants, "f").filter(p => p !== __classPrivateFieldGet(this, _ChatRoom_localId, "f"));
267
+ }
268
+ get messages() {
269
+ return __classPrivateFieldGet(this, _ChatRoom_messages, "f");
270
+ }
271
+ /** Highest `seq` held locally (0 when nothing sequenced is loaded). */
272
+ get lastSeq() {
273
+ return __classPrivateFieldGet(this, _ChatRoom_maxSeq, "f");
274
+ }
275
+ /** Highest `seq` the server reported for this room (may be ahead of what is loaded). */
276
+ get serverLastSeq() {
277
+ return Math.max(__classPrivateFieldGet(this, _ChatRoom_serverLastSeq, "f"), __classPrivateFieldGet(this, _ChatRoom_maxSeq, "f"));
278
+ }
279
+ /** Highest `seq` such that every sequence from the loaded range up to it is present. */
280
+ get contiguousSeq() {
281
+ return __classPrivateFieldGet(this, _ChatRoom_contiguousSeq, "f");
282
+ }
283
+ get lastReadSeq() {
284
+ return __classPrivateFieldGet(this, _ChatRoom_lastReadSeq, "f");
285
+ }
286
+ /** Lowest `seq` currently held, used for scroll-back paging. */
287
+ get oldestSeq() {
288
+ return __classPrivateFieldGet(this, _ChatRoom_minSeq, "f");
289
+ }
290
+ /** Oldest `created_at` held, used for scroll-back against legacy servers. */
291
+ get oldestCreatedAt() {
292
+ var _a;
293
+ return (_a = __classPrivateFieldGet(this, _ChatRoom_messages, "f")[0]) === null || _a === void 0 ? void 0 : _a.created_at;
294
+ }
295
+ /** True when `seq` is beyond the contiguous range and the missing range must be fetched. */
296
+ hasGapBefore(seq) {
297
+ return __classPrivateFieldGet(this, _ChatRoom_contiguousSeq, "f") > 0 && seq > __classPrivateFieldGet(this, _ChatRoom_contiguousSeq, "f") + 1;
298
+ }
299
+ }
300
+ _ChatRoom_messages = new WeakMap(), _ChatRoom_participants = new WeakMap(), _ChatRoom_name = new WeakMap(), _ChatRoom_localId = new WeakMap(), _ChatRoom_isReadOnly = new WeakMap(), _ChatRoom_byId = new WeakMap(), _ChatRoom_byClientId = new WeakMap(), _ChatRoom_seqs = new WeakMap(), _ChatRoom_minSeq = new WeakMap(), _ChatRoom_maxSeq = new WeakMap(), _ChatRoom_serverLastSeq = new WeakMap(), _ChatRoom_contiguousSeq = new WeakMap(), _ChatRoom_lastReadSeq = new WeakMap(), _ChatRoom_getUserResolver = new WeakMap(), _ChatRoom_instances = new WeakSet(), _ChatRoom_insert = function _ChatRoom_insert(msg, isLive) {
301
+ const byClient = msg.client_id ? __classPrivateFieldGet(this, _ChatRoom_byClientId, "f").get(msg.client_id) : undefined;
302
+ if (byClient)
303
+ return __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_merge).call(this, byClient, msg);
304
+ if (msg.id) {
305
+ const byId = __classPrivateFieldGet(this, _ChatRoom_byId, "f").get(msg.id);
306
+ if (byId)
307
+ return __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_merge).call(this, byId, msg);
308
+ }
309
+ const legacy = __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_matchLegacyEcho).call(this, msg);
310
+ if (legacy)
311
+ return __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_merge).call(this, legacy, msg);
312
+ __classPrivateFieldGet(this, _ChatRoom_messages, "f").push(msg);
313
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_sort).call(this);
314
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_index).call(this, msg);
315
+ if (typeof msg.seq === 'number')
316
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_trackSeq).call(this, msg.seq);
317
+ if (isLive && msg.sender_id !== __classPrivateFieldGet(this, _ChatRoom_localId, "f"))
318
+ this.unreadCount += 1;
319
+ return { message: msg, added: true, updated: false };
320
+ }, _ChatRoom_matchLegacyEcho = function _ChatRoom_matchLegacyEcho(msg) {
321
+ if (msg.client_id || msg.sender_id !== __classPrivateFieldGet(this, _ChatRoom_localId, "f"))
322
+ return undefined;
323
+ return __classPrivateFieldGet(this, _ChatRoom_messages, "f").find(m => m.sender_id === __classPrivateFieldGet(this, _ChatRoom_localId, "f")
324
+ && !!m.client_id
325
+ && typeof m.seq !== 'number'
326
+ && m.content_type === msg.content_type
327
+ && m.content_body === msg.content_body
328
+ && (m.delivery === 'pending' || m.delivery === 'sent'));
329
+ }, _ChatRoom_merge = function _ChatRoom_merge(existing, incoming) {
330
+ var _a, _b, _c, _d, _e;
331
+ const oldId = existing.id;
332
+ existing.id = incoming.id || existing.id;
333
+ if (typeof incoming.seq === 'number')
334
+ existing.seq = incoming.seq;
335
+ if (incoming.created_at)
336
+ existing.created_at = incoming.created_at;
337
+ existing.sender_id = (_a = incoming.sender_id) !== null && _a !== void 0 ? _a : existing.sender_id;
338
+ existing.parent_message_id = (_b = incoming.parent_message_id) !== null && _b !== void 0 ? _b : existing.parent_message_id;
339
+ existing.content_type = (_c = incoming.content_type) !== null && _c !== void 0 ? _c : existing.content_type;
340
+ existing.content_body = (_d = incoming.content_body) !== null && _d !== void 0 ? _d : existing.content_body;
341
+ existing.attachment_details = (_e = incoming.attachment_details) !== null && _e !== void 0 ? _e : existing.attachment_details;
342
+ if (typeof incoming.sender_kind !== 'undefined')
343
+ existing.sender_kind = incoming.sender_kind;
344
+ if (incoming.mentions)
345
+ existing.mentions = incoming.mentions;
346
+ // A broadcast proves the server accepted the message; recover a local entry that was marked
347
+ // failed because its ack was lost.
348
+ if (existing.delivery === 'failed' && incoming.id) {
349
+ existing.delivery = 'sent';
350
+ delete existing.error;
351
+ }
352
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_reindex).call(this, existing, oldId);
353
+ if (typeof incoming.seq === 'number') {
354
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_trackSeq).call(this, incoming.seq);
355
+ __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_sort).call(this);
356
+ }
357
+ return { message: existing, added: false, updated: true };
358
+ }, _ChatRoom_index = function _ChatRoom_index(msg) {
359
+ if (msg.id)
360
+ __classPrivateFieldGet(this, _ChatRoom_byId, "f").set(msg.id, msg);
361
+ if (msg.client_id)
362
+ __classPrivateFieldGet(this, _ChatRoom_byClientId, "f").set(msg.client_id, msg);
363
+ }, _ChatRoom_reindex = function _ChatRoom_reindex(msg, oldId) {
364
+ if (oldId && oldId !== msg.id)
365
+ __classPrivateFieldGet(this, _ChatRoom_byId, "f").delete(oldId);
366
+ if (msg.id)
367
+ __classPrivateFieldGet(this, _ChatRoom_byId, "f").set(msg.id, msg);
368
+ if (msg.client_id)
369
+ __classPrivateFieldGet(this, _ChatRoom_byClientId, "f").set(msg.client_id, msg);
370
+ }, _ChatRoom_trackSeq = function _ChatRoom_trackSeq(seq) {
371
+ if (__classPrivateFieldGet(this, _ChatRoom_seqs, "f").has(seq))
372
+ return;
373
+ const oldMin = __classPrivateFieldGet(this, _ChatRoom_minSeq, "f");
374
+ __classPrivateFieldGet(this, _ChatRoom_seqs, "f").add(seq);
375
+ __classPrivateFieldSet(this, _ChatRoom_minSeq, oldMin === undefined ? seq : Math.min(oldMin, seq), "f");
376
+ if (seq > __classPrivateFieldGet(this, _ChatRoom_maxSeq, "f"))
377
+ __classPrivateFieldSet(this, _ChatRoom_maxSeq, seq, "f");
378
+ if (__classPrivateFieldGet(this, _ChatRoom_contiguousSeq, "f") === 0) {
379
+ __classPrivateFieldSet(this, _ChatRoom_contiguousSeq, seq, "f");
380
+ }
381
+ else if (seq === __classPrivateFieldGet(this, _ChatRoom_contiguousSeq, "f") + 1) {
382
+ while (__classPrivateFieldGet(this, _ChatRoom_seqs, "f").has(__classPrivateFieldGet(this, _ChatRoom_contiguousSeq, "f") + 1))
383
+ __classPrivateFieldSet(this, _ChatRoom_contiguousSeq, __classPrivateFieldGet(this, _ChatRoom_contiguousSeq, "f") + 1, "f");
384
+ }
385
+ else if (seq < __classPrivateFieldGet(this, _ChatRoom_contiguousSeq, "f")) {
386
+ // A message loaded below the previously known range: only extend the contiguous range when
387
+ // it closes the gap to the old minimum (or starts it).
388
+ if (oldMin === undefined || seq < oldMin - 1)
389
+ __classPrivateFieldSet(this, _ChatRoom_contiguousSeq, seq, "f");
390
+ }
391
+ }, _ChatRoom_untrackSeq = function _ChatRoom_untrackSeq(seq) {
392
+ __classPrivateFieldGet(this, _ChatRoom_seqs, "f").delete(seq);
393
+ if (!__classPrivateFieldGet(this, _ChatRoom_seqs, "f").size) {
394
+ __classPrivateFieldSet(this, _ChatRoom_minSeq, undefined, "f");
395
+ __classPrivateFieldSet(this, _ChatRoom_maxSeq, 0, "f");
396
+ __classPrivateFieldSet(this, _ChatRoom_contiguousSeq, 0, "f");
397
+ return;
398
+ }
399
+ const sorted = Array.from(__classPrivateFieldGet(this, _ChatRoom_seqs, "f")).sort((a, b) => a - b);
400
+ __classPrivateFieldSet(this, _ChatRoom_minSeq, sorted[0], "f");
401
+ __classPrivateFieldSet(this, _ChatRoom_maxSeq, sorted[sorted.length - 1], "f");
402
+ let contiguous = __classPrivateFieldGet(this, _ChatRoom_minSeq, "f");
403
+ while (__classPrivateFieldGet(this, _ChatRoom_seqs, "f").has(contiguous + 1))
404
+ contiguous += 1;
405
+ __classPrivateFieldSet(this, _ChatRoom_contiguousSeq, contiguous, "f");
406
+ }, _ChatRoom_sort = function _ChatRoom_sort() {
407
+ __classPrivateFieldGet(this, _ChatRoom_messages, "f").sort((a, b) => __classPrivateFieldGet(this, _ChatRoom_instances, "m", _ChatRoom_compare).call(this, a, b));
408
+ }, _ChatRoom_compare = function _ChatRoom_compare(a, b) {
409
+ if (typeof a.seq === 'number' && typeof b.seq === 'number')
410
+ return a.seq - b.seq;
411
+ if (typeof a.seq !== 'number' && typeof b.seq !== 'number') {
412
+ return Date.parse(a.created_at) - Date.parse(b.created_at);
413
+ }
414
+ return typeof a.seq === 'number' ? -1 : 1;
415
+ };
416
+ //# sourceMappingURL=ChatRoom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatRoom.js","sourceRoot":"","sources":["../src/ChatRoom.ts"],"names":[],"mappings":";;;;;;;;;;;;AAUA;;;;;;;;;GASG;AACH,MAAM,OAAO,QAAS,SAAQ,WAAW;IAkBvC;;;;;;;OAOG;IACH,YACkB,EAAU,EAC1B,KAAa,EACN,IAAc,EACrB,aAAuB,EACvB,QAAgB,EAChB,cAAuB,KAAK,EAC5B,eAAuB,CAAC;QAExB,KAAK,EAAE,CAAC;;QARQ,OAAE,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