polfan-server-js-client 0.2.108 → 0.2.110
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/.idea/shelf/Uncommitted_changes_before_Checkout_at_26_07_2026_21_26_[Changes]/shelved.patch +174 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_26_07_2026_21_26__Changes_.xml +4 -0
- package/.idea/workspace.xml +16 -16
- package/build/index.cjs.js +113 -521
- package/build/index.cjs.js.map +1 -1
- package/build/index.umd.js +1 -1
- package/build/index.umd.js.map +1 -1
- package/build/types/AbstractChatClient.d.ts +0 -10
- package/build/types/IndexedObjectCollection.d.ts +0 -8
- package/build/types/WebSocketChatClient.d.ts +1 -17
- package/build/types/state-tracker/FollowedTopicsManager.d.ts +1 -18
- package/build/types/state-tracker/RoomMessagesHistory.d.ts +0 -12
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +2 -2
- package/package.json +1 -1
- package/src/AbstractChatClient.ts +0 -22
- package/src/IndexedObjectCollection.ts +0 -31
- package/src/WebSocketChatClient.ts +7 -63
- package/src/state-tracker/AsyncUtils.ts +0 -11
- package/src/state-tracker/EmoticonsManager.ts +3 -7
- package/src/state-tracker/FollowedTopicsManager.ts +14 -55
- package/src/state-tracker/MessagesManager.ts +2 -21
- package/src/state-tracker/PermissionsManager.ts +1 -5
- package/src/state-tracker/RelationshipsManager.ts +5 -5
- package/src/state-tracker/RoomMessagesHistory.ts +1 -41
- package/src/state-tracker/RoomsManager.ts +4 -21
- package/src/state-tracker/SpacesManager.ts +8 -35
- package/src/state-tracker/TopicHistoryWindow.ts +4 -4
- package/src/state-tracker/UsersManager.ts +1 -3
- package/tests/collections.test.ts +0 -92
- package/tests/pending-commands.test.ts +0 -171
- package/tests/state-reconnect.test.ts +0 -257
|
@@ -14,16 +14,6 @@ export declare abstract class AbstractChatClient<AdditionalEvents extends ExtraE
|
|
|
14
14
|
protected createPromiseFromCommandEnvelope<CommandT extends keyof CommandsMap>(envelope: Envelope<CommandRequest<CommandT>>): Promise<CommandResult<CommandResponse<CommandT>>>;
|
|
15
15
|
protected handleIncomingEnvelope(envelope: Envelope): void;
|
|
16
16
|
protected handleEnvelopeSendError(envelope: Envelope, error: any): void;
|
|
17
|
-
/**
|
|
18
|
-
* Reject every command that is still waiting for a response.
|
|
19
|
-
*
|
|
20
|
-
* Call this whenever the transport can no longer deliver an answer (the
|
|
21
|
-
* connection dropped). The server will never reply to those commands, so
|
|
22
|
-
* leaving them pending would hang every caller awaiting them forever -
|
|
23
|
-
* including cached lookups in the state tracker, which would then keep a
|
|
24
|
-
* view stuck on a loader even after a successful reconnect.
|
|
25
|
-
*/
|
|
26
|
-
protected failAwaitingResponses(error: any): void;
|
|
27
17
|
}
|
|
28
18
|
export type CommandResult<ResultT> = {
|
|
29
19
|
data?: ResultT;
|
|
@@ -51,14 +51,6 @@ export declare class ObservableIndexedObjectCollection<ItemT, EventMapT extends
|
|
|
51
51
|
set(...items: ItemT[]): void;
|
|
52
52
|
delete(...ids: string[]): void;
|
|
53
53
|
deleteAll(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Bring the collection to exactly match the provided items: upsert every
|
|
56
|
-
* provided item and remove any existing item whose id is not present in the
|
|
57
|
-
* provided set. Emits at most a single `change` event describing both the
|
|
58
|
-
* set and the deleted ids, so bound consumers can update in place without
|
|
59
|
-
* ever observing an intermediate empty state (unlike deleteAll + set).
|
|
60
|
-
*/
|
|
61
|
-
reconcile(...items: ItemT[]): void;
|
|
62
54
|
createMirror(): ObservableIndexedObjectCollection<ItemT, EventMapT>;
|
|
63
55
|
on<EventName extends keyof EventMapT & string>(eventName: EventName, handler: EventHandler<EventMapT[EventName]>): this;
|
|
64
56
|
once<EventName extends keyof EventMapT & string>(eventName: EventName, handler: EventHandler<EventMapT[EventName]>): this;
|
|
@@ -45,13 +45,7 @@ export declare class WebSocketChatClient extends AbstractChatClient<Pick<WebSock
|
|
|
45
45
|
protected sendQueue: Envelope[];
|
|
46
46
|
protected connectingTimeoutId: any;
|
|
47
47
|
protected authenticated: boolean;
|
|
48
|
-
protected authenticatedResolvers: [() => void, (error: Error) => void]
|
|
49
|
-
/**
|
|
50
|
-
* Pending promise returned by connect(). Kept until the client is either
|
|
51
|
-
* authenticated or gives up, so that an automatic reconnect settles the
|
|
52
|
-
* original caller instead of stranding it on a superseded promise.
|
|
53
|
-
*/
|
|
54
|
-
protected connectPromise: Promise<void> | null;
|
|
48
|
+
protected authenticatedResolvers: [() => void, (error: Error) => void];
|
|
55
49
|
protected pingMonitorInterval?: NodeJS.Timeout;
|
|
56
50
|
protected inFlightPingTimeout: NodeJS.Timeout;
|
|
57
51
|
protected lastReceivedMessageAt?: number;
|
|
@@ -63,16 +57,6 @@ export declare class WebSocketChatClient extends AbstractChatClient<Pick<WebSock
|
|
|
63
57
|
private sendEnvelope;
|
|
64
58
|
private onMessage;
|
|
65
59
|
private onClose;
|
|
66
|
-
/**
|
|
67
|
-
* Resolve (or reject, when an error is given) a pending connect() promise.
|
|
68
|
-
* No-op when there is nothing pending.
|
|
69
|
-
*/
|
|
70
|
-
private settleConnect;
|
|
71
|
-
/**
|
|
72
|
-
* Reject every command that has not been answered yet - both the ones still
|
|
73
|
-
* waiting in the send queue and the ones already sent to the server.
|
|
74
|
-
*/
|
|
75
|
-
private failPendingCommands;
|
|
76
60
|
private sendFromQueue;
|
|
77
61
|
private triggerConnectionTimeout;
|
|
78
62
|
private isConnectingWsState;
|
|
@@ -8,6 +8,7 @@ interface EventMap {
|
|
|
8
8
|
export interface UnreadSummary {
|
|
9
9
|
mentionCount: number;
|
|
10
10
|
unreadTopicCount: number;
|
|
11
|
+
unreadRoomCount: number;
|
|
11
12
|
isUnread: boolean;
|
|
12
13
|
}
|
|
13
14
|
export declare class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
@@ -16,11 +17,6 @@ export declare class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
16
17
|
private readonly followedTopicsPromises;
|
|
17
18
|
private readonly deferredSession;
|
|
18
19
|
private readonly summariesCache;
|
|
19
|
-
/**
|
|
20
|
-
* Rooms whose cached followed-topics are stale after a reconnect and must
|
|
21
|
-
* be refetched (and reconciled in place) the next time they are accessed.
|
|
22
|
-
*/
|
|
23
|
-
private readonly staleRooms;
|
|
24
20
|
constructor(tracker: ChatStateTracker);
|
|
25
21
|
/**
|
|
26
22
|
* Cache followed topics for all joined rooms in a space and fetch them in bulk if necessary.
|
|
@@ -65,19 +61,6 @@ export declare class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
65
61
|
private invalidateUnreadSummaries;
|
|
66
62
|
private invalidateUnreadSummariesForRooms;
|
|
67
63
|
private updateLocallyFollowedTopicOnNewMessage;
|
|
68
|
-
/**
|
|
69
|
-
* Reconcile the followed-topics collection for a single room to exactly
|
|
70
|
-
* match the provided list (upsert present, drop absent) without emitting an
|
|
71
|
-
* intermediate empty state, and clear its stale marker. Does not touch the
|
|
72
|
-
* unread summaries cache - callers decide how to invalidate it.
|
|
73
|
-
*/
|
|
74
|
-
private applyRoomFollowedTopics;
|
|
75
|
-
/**
|
|
76
|
-
* Reconcile a batch of rooms from a single bulk GetFollowedTopics response.
|
|
77
|
-
* Rooms with no followed topics in the response are reconciled to empty, so
|
|
78
|
-
* topics unfollowed/removed during the downtime are correctly dropped.
|
|
79
|
-
*/
|
|
80
|
-
private reconcileRoomsFollowedTopics;
|
|
81
64
|
private setFollowedTopicsArray;
|
|
82
65
|
private clearRoomFollowedTopicsStructures;
|
|
83
66
|
}
|
|
@@ -13,18 +13,6 @@ export declare class RoomMessagesHistory {
|
|
|
13
13
|
* @param peek If true, do not create a cache for this topic and do not allow it to collect new messages.
|
|
14
14
|
*/
|
|
15
15
|
getMessagesWindow(topicId: string, peek?: boolean): Promise<TopicHistoryWindow | undefined>;
|
|
16
|
-
/**
|
|
17
|
-
* Re-synchronise this room's history after a reconnect without discarding
|
|
18
|
-
* the existing window objects (which would blank the UI and, for ephemeral
|
|
19
|
-
* rooms, permanently drop live-only history).
|
|
20
|
-
*
|
|
21
|
-
* The window bindings are preserved; only windows that the application had
|
|
22
|
-
* actually pulled to the latest page (state === LATEST) are refreshed, with
|
|
23
|
-
* a single resetToLatest instead of a chain of catch-up requests. Windows
|
|
24
|
-
* that were never pulled (LIVE) or belong to an ephemeral room are left
|
|
25
|
-
* untouched so their in-memory context survives the reconnect.
|
|
26
|
-
*/
|
|
27
|
-
resync(room: Room): Promise<void>;
|
|
28
16
|
private handleRoomUpdated;
|
|
29
17
|
private handleNewTopic;
|
|
30
18
|
private handleTopicDeleted;
|
|
@@ -64,7 +64,7 @@ export declare abstract class TraversableRemoteCollection<ItemT, EventMapT exten
|
|
|
64
64
|
get hasLatest(): boolean;
|
|
65
65
|
get hasOldest(): boolean;
|
|
66
66
|
abstract createMirror(): TraversableRemoteCollection<ItemT, EventMapT>;
|
|
67
|
-
resetToLatest(
|
|
67
|
+
resetToLatest(): Promise<void>;
|
|
68
68
|
fetchPrevious(): Promise<void>;
|
|
69
69
|
fetchNext(): Promise<void>;
|
|
70
70
|
jumpTo(id: string): Promise<void>;
|
|
@@ -99,7 +99,7 @@ export declare class TopicHistoryWindow extends TraversableRemoteCollection<Mess
|
|
|
99
99
|
createMirror(): TopicHistoryWindow;
|
|
100
100
|
get isTraverseLocked(): boolean;
|
|
101
101
|
setTraverseLock(lock: boolean): Promise<void>;
|
|
102
|
-
resetToLatest(
|
|
102
|
+
resetToLatest(): Promise<void>;
|
|
103
103
|
fetchNext(): Promise<void>;
|
|
104
104
|
fetchPrevious(): Promise<void>;
|
|
105
105
|
jumpTo(id: string): Promise<void>;
|
package/package.json
CHANGED
|
@@ -165,28 +165,6 @@ export abstract class AbstractChatClient<AdditionalEvents extends ExtraEventMap
|
|
|
165
165
|
this.awaitingResponse.get(envelope.ref)[1](error);
|
|
166
166
|
this.awaitingResponse.delete(envelope.ref);
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Reject every command that is still waiting for a response.
|
|
171
|
-
*
|
|
172
|
-
* Call this whenever the transport can no longer deliver an answer (the
|
|
173
|
-
* connection dropped). The server will never reply to those commands, so
|
|
174
|
-
* leaving them pending would hang every caller awaiting them forever -
|
|
175
|
-
* including cached lookups in the state tracker, which would then keep a
|
|
176
|
-
* view stuck on a loader even after a successful reconnect.
|
|
177
|
-
*/
|
|
178
|
-
protected failAwaitingResponses(error: any): void {
|
|
179
|
-
if (! this.awaitingResponse.size) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const pending = Array.from(this.awaitingResponse.values());
|
|
184
|
-
this.awaitingResponse.clear();
|
|
185
|
-
|
|
186
|
-
for (const [, reject] of pending) {
|
|
187
|
-
reject(error);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
168
|
}
|
|
191
169
|
|
|
192
170
|
export type CommandResult<ResultT> = {data?: ResultT, error?: ErrorType};
|
|
@@ -226,37 +226,6 @@ export class ObservableIndexedObjectCollection<
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
/**
|
|
230
|
-
* Bring the collection to exactly match the provided items: upsert every
|
|
231
|
-
* provided item and remove any existing item whose id is not present in the
|
|
232
|
-
* provided set. Emits at most a single `change` event describing both the
|
|
233
|
-
* set and the deleted ids, so bound consumers can update in place without
|
|
234
|
-
* ever observing an intermediate empty state (unlike deleteAll + set).
|
|
235
|
-
*/
|
|
236
|
-
public reconcile(...items: ItemT[]) {
|
|
237
|
-
const incomingIds = new Set(items.map(item => this.getId(item)));
|
|
238
|
-
const deletedItems: string[] = [];
|
|
239
|
-
|
|
240
|
-
for (const existing of this.items) {
|
|
241
|
-
const id = this.getId(existing);
|
|
242
|
-
if (! incomingIds.has(id)) {
|
|
243
|
-
deletedItems.push(id);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (! items.length && ! deletedItems.length) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
this._items.delete(...deletedItems);
|
|
252
|
-
super.set(...items);
|
|
253
|
-
|
|
254
|
-
this.eventTarget.emit('change', {
|
|
255
|
-
setItems: items.map(item => this.getId(item)),
|
|
256
|
-
deletedItems,
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
|
|
260
229
|
public createMirror(): ObservableIndexedObjectCollection<ItemT, EventMapT> {
|
|
261
230
|
const copy = new ObservableIndexedObjectCollection<ItemT, EventMapT>(this.id);
|
|
262
231
|
copy.eventTarget = this.eventTarget;
|
|
@@ -48,13 +48,7 @@ export class WebSocketChatClient extends AbstractChatClient<Pick<WebSocketEventM
|
|
|
48
48
|
protected sendQueue: Envelope[] = [];
|
|
49
49
|
protected connectingTimeoutId: any;
|
|
50
50
|
protected authenticated: boolean;
|
|
51
|
-
protected authenticatedResolvers: [() => void, (error: Error) => void]
|
|
52
|
-
/**
|
|
53
|
-
* Pending promise returned by connect(). Kept until the client is either
|
|
54
|
-
* authenticated or gives up, so that an automatic reconnect settles the
|
|
55
|
-
* original caller instead of stranding it on a superseded promise.
|
|
56
|
-
*/
|
|
57
|
-
protected connectPromise: Promise<void> | null = null;
|
|
51
|
+
protected authenticatedResolvers: [() => void, (error: Error) => void];
|
|
58
52
|
protected pingMonitorInterval?: NodeJS.Timeout;
|
|
59
53
|
protected inFlightPingTimeout: NodeJS.Timeout;
|
|
60
54
|
protected lastReceivedMessageAt?: number;
|
|
@@ -73,14 +67,9 @@ export class WebSocketChatClient extends AbstractChatClient<Pick<WebSocketEventM
|
|
|
73
67
|
|
|
74
68
|
public async connect(): Promise<void> {
|
|
75
69
|
if (this.isOpenWsState() || this.isConnectingWsState()) {
|
|
76
|
-
return
|
|
70
|
+
return;
|
|
77
71
|
}
|
|
78
72
|
|
|
79
|
-
// Reuse the promise of an attempt that has not settled yet (an
|
|
80
|
-
// automatic reconnect), so the caller that started connecting is
|
|
81
|
-
// resolved by whichever attempt eventually authenticates.
|
|
82
|
-
this.connectPromise ??= new Promise<void>((...args) => this.authenticatedResolvers = args);
|
|
83
|
-
|
|
84
73
|
const params = new URLSearchParams(this.options.queryParams ?? {});
|
|
85
74
|
params.set('token', this.options.token);
|
|
86
75
|
|
|
@@ -92,12 +81,11 @@ export class WebSocketChatClient extends AbstractChatClient<Pick<WebSocketEventM
|
|
|
92
81
|
this.options.connectingTimeoutMs ?? 10000
|
|
93
82
|
);
|
|
94
83
|
this.authenticated = false;
|
|
95
|
-
|
|
96
|
-
return this.connectPromise;
|
|
84
|
+
return new Promise((...args) => this.authenticatedResolvers = args);
|
|
97
85
|
}
|
|
98
86
|
|
|
99
87
|
public disconnect(): void {
|
|
100
|
-
this.
|
|
88
|
+
this.sendQueue = [];
|
|
101
89
|
this.ws?.close(1000); // Normal closure
|
|
102
90
|
this.ws = null;
|
|
103
91
|
}
|
|
@@ -145,11 +133,11 @@ export class WebSocketChatClient extends AbstractChatClient<Pick<WebSocketEventM
|
|
|
145
133
|
this.authenticated = isAuthenticated;
|
|
146
134
|
if (isAuthenticated) {
|
|
147
135
|
this.startConnectionMonitor();
|
|
148
|
-
this.
|
|
136
|
+
this.authenticatedResolvers[0]();
|
|
149
137
|
this.emit(this.Event.connect);
|
|
150
138
|
this.sendFromQueue();
|
|
151
139
|
} else {
|
|
152
|
-
this.
|
|
140
|
+
this.authenticatedResolvers[1](envelope.data);
|
|
153
141
|
}
|
|
154
142
|
}
|
|
155
143
|
}
|
|
@@ -158,54 +146,12 @@ export class WebSocketChatClient extends AbstractChatClient<Pick<WebSocketEventM
|
|
|
158
146
|
this.stopConnectionMonitor();
|
|
159
147
|
clearTimeout(this.connectingTimeoutId);
|
|
160
148
|
const reconnect = event.code !== 1000; // Connection was closed because of error
|
|
161
|
-
|
|
162
|
-
// The server can no longer answer anything that was queued or in
|
|
163
|
-
// flight, so settle those promises instead of leaving them pending.
|
|
164
|
-
this.failPendingCommands(new Error('Connection closed before the command was answered'));
|
|
165
|
-
|
|
166
149
|
if (reconnect) {
|
|
167
|
-
// Keep a pending connect() promise unsettled - the retry below is
|
|
168
|
-
// expected to authenticate and will resolve it.
|
|
169
150
|
void this.connect();
|
|
170
|
-
} else {
|
|
171
|
-
this.settleConnect(new Error('Connection closed before authentication'));
|
|
172
151
|
}
|
|
173
|
-
|
|
174
152
|
this.emit(this.Event.disconnect, reconnect);
|
|
175
153
|
}
|
|
176
154
|
|
|
177
|
-
/**
|
|
178
|
-
* Resolve (or reject, when an error is given) a pending connect() promise.
|
|
179
|
-
* No-op when there is nothing pending.
|
|
180
|
-
*/
|
|
181
|
-
private settleConnect(error?: any): void {
|
|
182
|
-
const resolvers = this.authenticatedResolvers;
|
|
183
|
-
|
|
184
|
-
this.authenticatedResolvers = null;
|
|
185
|
-
this.connectPromise = null;
|
|
186
|
-
|
|
187
|
-
if (! resolvers) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
error ? resolvers[1](error) : resolvers[0]();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Reject every command that has not been answered yet - both the ones still
|
|
196
|
-
* waiting in the send queue and the ones already sent to the server.
|
|
197
|
-
*/
|
|
198
|
-
private failPendingCommands(error: Error): void {
|
|
199
|
-
const queued = this.sendQueue;
|
|
200
|
-
this.sendQueue = [];
|
|
201
|
-
|
|
202
|
-
for (const envelope of queued) {
|
|
203
|
-
this.handleEnvelopeSendError(envelope, error);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
this.failAwaitingResponses(error);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
155
|
private sendFromQueue(): void {
|
|
210
156
|
// Send awaiting data to server
|
|
211
157
|
let lastDelay = 0;
|
|
@@ -252,9 +198,7 @@ export class WebSocketChatClient extends AbstractChatClient<Pick<WebSocketEventM
|
|
|
252
198
|
this.ws.close(3000); // Service Restart (reconnect)
|
|
253
199
|
}, this.options.ping.pongBackTimeoutMs);
|
|
254
200
|
|
|
255
|
-
|
|
256
|
-
// in flight; onClose already handles that, so just stop waiting.
|
|
257
|
-
this.send('Ping', {}).catch(() => undefined).then(() => {
|
|
201
|
+
this.send('Ping', {}).then(() => {
|
|
258
202
|
clearTimeout(this.inFlightPingTimeout);
|
|
259
203
|
this.inFlightPingTimeout = undefined;
|
|
260
204
|
});
|
|
@@ -14,17 +14,6 @@ export class PromiseRegistry {
|
|
|
14
14
|
|
|
15
15
|
public register<T = any>(promise: Promise<T>, key: string): void {
|
|
16
16
|
this.promises.set([key, promise]);
|
|
17
|
-
|
|
18
|
-
// Never cache a failed lookup: drop it so the next access retries
|
|
19
|
-
// instead of replaying the same rejection forever (a request issued
|
|
20
|
-
// while the client was offline would otherwise poison the key). The
|
|
21
|
-
// handler also keeps the cached promise from surfacing as an unhandled
|
|
22
|
-
// rejection - callers still receive the rejection from their own await.
|
|
23
|
-
promise.catch(() => {
|
|
24
|
-
if (this.promises.get(key) === promise) {
|
|
25
|
-
this.promises.delete(key);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
17
|
}
|
|
29
18
|
|
|
30
19
|
public registerByFunction(fn: () => Promise<any>, key: string): void {
|
|
@@ -44,10 +44,8 @@ export class EmoticonsManager {
|
|
|
44
44
|
this.list.set([spaceId, new ObservableIndexedObjectCollection<Emoticon>('id')]);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// adds new ones without blanking a bound (visible) collection.
|
|
50
|
-
this.list.get(spaceId).reconcile(...event.emoticons);
|
|
47
|
+
const collection = this.list.get(spaceId);
|
|
48
|
+
collection.set(...event.emoticons);
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
private handleNewEmoticon(ev: NewEmoticon): void {
|
|
@@ -65,9 +63,7 @@ export class EmoticonsManager {
|
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
private handleSession(): void {
|
|
68
|
-
|
|
69
|
-
// pickers); just drop the fetch guards so the next access refetches and
|
|
70
|
-
// reconciles them in place.
|
|
66
|
+
this.list.deleteAll();
|
|
71
67
|
this.emoticonsPromises.forgetAll();
|
|
72
68
|
}
|
|
73
69
|
}
|
|
@@ -20,6 +20,7 @@ interface EventMap {
|
|
|
20
20
|
export interface UnreadSummary {
|
|
21
21
|
mentionCount: number;
|
|
22
22
|
unreadTopicCount: number;
|
|
23
|
+
unreadRoomCount: number;
|
|
23
24
|
isUnread: boolean;
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -29,12 +30,6 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
29
30
|
private readonly deferredSession = new DeferredTask();
|
|
30
31
|
private readonly summariesCache = new Map<string, UnreadSummary>();
|
|
31
32
|
|
|
32
|
-
/**
|
|
33
|
-
* Rooms whose cached followed-topics are stale after a reconnect and must
|
|
34
|
-
* be refetched (and reconciled in place) the next time they are accessed.
|
|
35
|
-
*/
|
|
36
|
-
private readonly staleRooms = new Set<string>();
|
|
37
|
-
|
|
38
33
|
public constructor(private tracker: ChatStateTracker) {
|
|
39
34
|
super();
|
|
40
35
|
|
|
@@ -69,8 +64,8 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
69
64
|
return;
|
|
70
65
|
}
|
|
71
66
|
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
67
|
+
const isAlreadyCached = roomIds.every(roomId => this.followedTopics.has(roomId));
|
|
68
|
+
if (isAlreadyCached) {
|
|
74
69
|
return;
|
|
75
70
|
}
|
|
76
71
|
|
|
@@ -81,7 +76,7 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
81
76
|
const result = await this.tracker.client.send('GetFollowedTopics', {location: {spaceId}});
|
|
82
77
|
if (result.error) throw result.error;
|
|
83
78
|
|
|
84
|
-
this.
|
|
79
|
+
this.setFollowedTopicsArray(roomIds, result.data.followedTopics);
|
|
85
80
|
}, spaceRegistryKey);
|
|
86
81
|
}
|
|
87
82
|
|
|
@@ -97,7 +92,7 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
97
92
|
return undefined;
|
|
98
93
|
}
|
|
99
94
|
|
|
100
|
-
if (! this.followedTopics.has(roomId)
|
|
95
|
+
if (! this.followedTopics.has(roomId)) {
|
|
101
96
|
if (this.followedTopicsPromises.notExist(roomId)) {
|
|
102
97
|
this.followedTopicsPromises.registerByFunction(async () => {
|
|
103
98
|
const result = await this.tracker.client.send('GetFollowedTopics', {location: {roomId}});
|
|
@@ -106,8 +101,7 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
106
101
|
throw result.error;
|
|
107
102
|
}
|
|
108
103
|
|
|
109
|
-
this.
|
|
110
|
-
this.invalidateUnreadSummaries(roomId);
|
|
104
|
+
this.setFollowedTopicsArray([roomId], result.data.followedTopics);
|
|
111
105
|
}, roomId);
|
|
112
106
|
}
|
|
113
107
|
|
|
@@ -175,6 +169,7 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
175
169
|
|
|
176
170
|
let mentionCount = 0;
|
|
177
171
|
let unreadTopicCount = 0;
|
|
172
|
+
let unreadRoomCount = 0;
|
|
178
173
|
|
|
179
174
|
for (const roomId of roomIds) {
|
|
180
175
|
const collection = await this.getForRoom(roomId);
|
|
@@ -183,12 +178,17 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
183
178
|
continue;
|
|
184
179
|
}
|
|
185
180
|
|
|
181
|
+
let isRoomUnreadCount = false;
|
|
186
182
|
for (const topic of collection.items) {
|
|
187
183
|
if (targetTopicId && topic.location.topicId !== targetTopicId) {
|
|
188
184
|
continue;
|
|
189
185
|
}
|
|
190
186
|
|
|
191
187
|
if (topic.isUnread) {
|
|
188
|
+
if (!isRoomUnreadCount) {
|
|
189
|
+
unreadRoomCount++;
|
|
190
|
+
isRoomUnreadCount = true;
|
|
191
|
+
}
|
|
192
192
|
unreadTopicCount++;
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -196,7 +196,7 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
const result = { mentionCount, unreadTopicCount, isUnread: unreadTopicCount > 0 };
|
|
199
|
+
const result = { mentionCount, unreadTopicCount, unreadRoomCount, isUnread: unreadTopicCount > 0 };
|
|
200
200
|
this.summariesCache.set(cacheKey, result);
|
|
201
201
|
|
|
202
202
|
return result;
|
|
@@ -212,13 +212,7 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
private handleSession(ev: Session): void {
|
|
215
|
-
|
|
216
|
-
// that would otherwise blank on reconnect), but mark them stale and drop
|
|
217
|
-
// the fetch guards so the next access/caching refetches and reconciles
|
|
218
|
-
// them in place.
|
|
219
|
-
for (const roomId of this.followedTopics.items.keys()) {
|
|
220
|
-
this.staleRooms.add(roomId);
|
|
221
|
-
}
|
|
215
|
+
this.followedTopics.deleteAll();
|
|
222
216
|
this.followedTopicsPromises.forgetAll();
|
|
223
217
|
this.invalidateUnreadSummaries();
|
|
224
218
|
this.deferredSession.resolve();
|
|
@@ -370,40 +364,6 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
370
364
|
this.invalidateUnreadSummaries(ev.message.location.roomId, ev.message.location.topicId);
|
|
371
365
|
}
|
|
372
366
|
|
|
373
|
-
/**
|
|
374
|
-
* Reconcile the followed-topics collection for a single room to exactly
|
|
375
|
-
* match the provided list (upsert present, drop absent) without emitting an
|
|
376
|
-
* intermediate empty state, and clear its stale marker. Does not touch the
|
|
377
|
-
* unread summaries cache - callers decide how to invalidate it.
|
|
378
|
-
*/
|
|
379
|
-
private applyRoomFollowedTopics(roomId: string, followedTopics: FollowedTopic[]): void {
|
|
380
|
-
if (! this.followedTopics.has(roomId)) {
|
|
381
|
-
this.followedTopics.set([roomId, new ObservableIndexedObjectCollection<FollowedTopic>(
|
|
382
|
-
followedTopic => followedTopic.location.topicId
|
|
383
|
-
)]);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
this.followedTopics.get(roomId).reconcile(...followedTopics);
|
|
387
|
-
this.staleRooms.delete(roomId);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Reconcile a batch of rooms from a single bulk GetFollowedTopics response.
|
|
392
|
-
* Rooms with no followed topics in the response are reconciled to empty, so
|
|
393
|
-
* topics unfollowed/removed during the downtime are correctly dropped.
|
|
394
|
-
*/
|
|
395
|
-
private reconcileRoomsFollowedTopics(roomIds: string[], followedTopics: FollowedTopic[]): void {
|
|
396
|
-
const roomToTopics: {[roomId: string]: FollowedTopic[]} = {};
|
|
397
|
-
|
|
398
|
-
followedTopics.forEach(followedTopic => {
|
|
399
|
-
(roomToTopics[followedTopic.location.roomId] ??= []).push(followedTopic);
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
roomIds.forEach(roomId => this.applyRoomFollowedTopics(roomId, roomToTopics[roomId] ?? []));
|
|
403
|
-
|
|
404
|
-
this.invalidateUnreadSummariesForRooms(roomIds);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
367
|
private setFollowedTopicsArray(roomIds: string[], followedTopics: FollowedTopic[]): void {
|
|
408
368
|
const roomToTopics: {[roomId: string]: FollowedTopic[]} = {};
|
|
409
369
|
|
|
@@ -431,7 +391,6 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
431
391
|
private clearRoomFollowedTopicsStructures(roomId: string): void {
|
|
432
392
|
this.followedTopics.delete(roomId);
|
|
433
393
|
this.followedTopicsPromises.forget(roomId);
|
|
434
|
-
this.staleRooms.delete(roomId);
|
|
435
394
|
this.invalidateUnreadSummaries(roomId);
|
|
436
395
|
}
|
|
437
396
|
}
|
|
@@ -71,27 +71,8 @@ export class MessagesManager {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
private handleSession(ev: Session): void {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// Drop histories only for rooms that no longer exist server-side.
|
|
77
|
-
for (const roomId of Array.from(this.roomHistories.items.keys())) {
|
|
78
|
-
if (! stateRoomIds.has(roomId)) {
|
|
79
|
-
this.roomHistories.delete(roomId);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Keep existing histories (preserving loaded messages and, crucially,
|
|
84
|
-
// live-only ephemeral history), create histories for newly joined
|
|
85
|
-
// rooms, and resync survivors against the fresh room snapshot.
|
|
86
|
-
for (const room of ev.state.rooms) {
|
|
87
|
-
const history = this.roomHistories.get(room.id);
|
|
88
|
-
if (history) {
|
|
89
|
-
void history.resync(room);
|
|
90
|
-
} else {
|
|
91
|
-
this.createHistoryForNewRoom(room);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
74
|
+
this.roomHistories.deleteAll();
|
|
75
|
+
ev.state.rooms.forEach(room => this.createHistoryForNewRoom(room));
|
|
95
76
|
this.deferredSession.resolve();
|
|
96
77
|
}
|
|
97
78
|
}
|
|
@@ -308,11 +308,7 @@ export class PermissionsManager extends EventTarget<PermissionsManagerEventMap>
|
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
private handleSession(ev: Session): void {
|
|
311
|
-
|
|
312
|
-
// overwrites (getOverwrites refetches and upserts on the next access),
|
|
313
|
-
// and notify consumers to recompute so bound permission UI is never
|
|
314
|
-
// left showing stale results after a reconnect.
|
|
311
|
+
this.overwrites.deleteAll();
|
|
315
312
|
this.overwritesPromises.forgetAll();
|
|
316
|
-
this.emit('change');
|
|
317
313
|
}
|
|
318
314
|
}
|
|
@@ -43,9 +43,10 @@ export class RelationshipsManager {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
private handleRelationships(ev: Relationships): void {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
this.relationships.deleteAll();
|
|
47
|
+
ev.relationships.forEach(relationship => {
|
|
48
|
+
this.relationships.set(relationship);
|
|
49
|
+
});
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
private handleNewRelationship(ev: NewRelationship): void {
|
|
@@ -61,8 +62,7 @@ export class RelationshipsManager {
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
private handleSession(): void {
|
|
64
|
-
// Keep the (possibly bound) collection; just drop the fetch guard so the
|
|
65
|
-
// next get() refetches and reconciles it in place.
|
|
66
65
|
this.promises.forgetAll();
|
|
66
|
+
this.relationships.deleteAll();
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ChatStateTracker} from "./ChatStateTracker";
|
|
2
2
|
import {NewTopic, Room, RoomUpdated, Topic, TopicDeleted} from "../types/src";
|
|
3
3
|
import {IndexedCollection,} from "../IndexedObjectCollection";
|
|
4
|
-
import {TopicHistoryWindow
|
|
4
|
+
import {TopicHistoryWindow} from "./TopicHistoryWindow";
|
|
5
5
|
|
|
6
6
|
export class RoomMessagesHistory {
|
|
7
7
|
private historyWindows = new IndexedCollection<string, TopicHistoryWindow>();
|
|
@@ -39,46 +39,6 @@ export class RoomMessagesHistory {
|
|
|
39
39
|
return this.historyWindows.get(topicId);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* Re-synchronise this room's history after a reconnect without discarding
|
|
44
|
-
* the existing window objects (which would blank the UI and, for ephemeral
|
|
45
|
-
* rooms, permanently drop live-only history).
|
|
46
|
-
*
|
|
47
|
-
* The window bindings are preserved; only windows that the application had
|
|
48
|
-
* actually pulled to the latest page (state === LATEST) are refreshed, with
|
|
49
|
-
* a single resetToLatest instead of a chain of catch-up requests. Windows
|
|
50
|
-
* that were never pulled (LIVE) or belong to an ephemeral room are left
|
|
51
|
-
* untouched so their in-memory context survives the reconnect.
|
|
52
|
-
*/
|
|
53
|
-
public async resync(room: Room): Promise<void> {
|
|
54
|
-
this.room = room;
|
|
55
|
-
this.updateTraverseLock(room);
|
|
56
|
-
|
|
57
|
-
if (this.room.defaultTopic) {
|
|
58
|
-
this.createHistoryWindowForTopic(this.room.defaultTopic);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
for (const [, window] of Array.from(this.historyWindows.items)) {
|
|
62
|
-
try {
|
|
63
|
-
await window.setTraverseLock(this.traverseLock);
|
|
64
|
-
|
|
65
|
-
// Ephemeral history lives only in memory (the server does not
|
|
66
|
-
// persist it), so never refetch/replace it on reconnect.
|
|
67
|
-
if (this.traverseLock) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (window.state === WindowState.LATEST) {
|
|
72
|
-
await window.resetToLatest(true);
|
|
73
|
-
}
|
|
74
|
-
} catch (_e) {
|
|
75
|
-
// Best effort: the connection can drop again mid-resync. The
|
|
76
|
-
// window keeps its current content and stays usable, so the
|
|
77
|
-
// application can refresh it on demand.
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
42
|
private async handleRoomUpdated(ev: RoomUpdated): Promise<void> {
|
|
83
43
|
if (this.room.id === ev.room.id) {
|
|
84
44
|
this.room = ev.room;
|