polfan-server-js-client 0.2.92 → 0.2.94
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/workspace.xml +70 -48
- package/build/index.cjs.js +234 -131
- 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 +2 -3
- package/build/types/state-tracker/MessagesManager.d.ts +13 -5
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +4 -0
- package/build/types/types/src/index.d.ts +3 -4
- package/build/types/types/src/schemes/FollowedTopic.d.ts +4 -0
- package/build/types/types/src/schemes/commands/GetMessages.d.ts +1 -0
- package/build/types/types/src/schemes/commands/UpdateFollowedTopic.d.ts +6 -0
- package/package.json +1 -1
- package/src/AbstractChatClient.ts +2 -4
- package/src/state-tracker/MessagesManager.ts +141 -22
- package/src/state-tracker/TopicHistoryWindow.ts +50 -1
- package/src/types/src/index.ts +4 -5
- package/src/types/src/schemes/FollowedTopic.ts +5 -0
- package/src/types/src/schemes/commands/GetMessages.ts +1 -0
- package/src/types/src/schemes/commands/UpdateFollowedTopic.ts +7 -0
- package/tests/history-window.test.ts +84 -1
- package/tsconfig.json +16 -16
- package/src/types/src/schemes/commands/UnfollowTopic.ts +0 -5
|
@@ -18,12 +18,32 @@ const messages: SimpleMessage[] = [
|
|
|
18
18
|
];
|
|
19
19
|
|
|
20
20
|
class TestableHistoryWindow extends TraversableRemoteCollection<SimpleMessage> {
|
|
21
|
+
declare protected internalState: TraversableRemoteCollection<SimpleMessage>['internalState'] & {
|
|
22
|
+
traverseLock: boolean,
|
|
23
|
+
};
|
|
24
|
+
|
|
21
25
|
public createMirror(): TraversableRemoteCollection<SimpleMessage> {
|
|
22
26
|
throw new Error('Method not implemented.');
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
public constructor() {
|
|
26
30
|
super('id');
|
|
31
|
+
this.internalState.traverseLock = false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public async setTraverseLock(lock: boolean): Promise<void> {
|
|
35
|
+
this.internalState.traverseLock = lock;
|
|
36
|
+
|
|
37
|
+
if (lock && (this.state !== WindowState.LIVE && this.state !== WindowState.LATEST)) {
|
|
38
|
+
await super.resetToLatest();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public async jumpTo(id: string): Promise<void> {
|
|
43
|
+
if (this.internalState.traverseLock) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
return super.jumpTo(id);
|
|
27
47
|
}
|
|
28
48
|
|
|
29
49
|
public simulateNewMessageReceived(): void {
|
|
@@ -49,6 +69,18 @@ class TestableHistoryWindow extends TraversableRemoteCollection<SimpleMessage> {
|
|
|
49
69
|
return messages.slice(after + 1, after + 4);
|
|
50
70
|
}
|
|
51
71
|
|
|
72
|
+
protected async fetchItemsAround(id: string): Promise<SimpleMessage[] | null> {
|
|
73
|
+
const numericId = parseInt(id, 10);
|
|
74
|
+
const item = messages.find(m => m.id === numericId);
|
|
75
|
+
if (!item) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const index = messages.indexOf(item);
|
|
79
|
+
const start = Math.max(0, index - Math.floor(this.fetchLimit / 2));
|
|
80
|
+
const end = Math.min(messages.length, index + Math.ceil(this.fetchLimit / 2));
|
|
81
|
+
return messages.slice(start, end);
|
|
82
|
+
}
|
|
83
|
+
|
|
52
84
|
protected async fetchItemsBefore(): Promise<SimpleMessage[]> {
|
|
53
85
|
const before = this.getAt(0)?.id;
|
|
54
86
|
if (before === undefined) {
|
|
@@ -177,6 +209,57 @@ test('history window - reset to latest', async () => {
|
|
|
177
209
|
[7,8,9].forEach(id => expect(window.items.map(item => item.id)).toContain(id));
|
|
178
210
|
});
|
|
179
211
|
|
|
212
|
+
test('history window - jump to message', async () => {
|
|
213
|
+
const window = new TestableHistoryWindow();
|
|
214
|
+
window.limit = 5;
|
|
215
|
+
window.fetchLimit = 3;
|
|
216
|
+
|
|
217
|
+
await window.resetToLatest(); // [7,8,9]
|
|
218
|
+
await window.jumpTo('2'); // [1,2,3]
|
|
219
|
+
|
|
220
|
+
expect(window.state).toEqual(WindowState.PAST);
|
|
221
|
+
expect(window.items).toHaveLength(3);
|
|
222
|
+
[1,2,3].forEach(id => expect(window.items.map(item => item.id)).toContain(id));
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('history window - jump to message already in window', async () => {
|
|
226
|
+
const window = new TestableHistoryWindow();
|
|
227
|
+
window.limit = 5;
|
|
228
|
+
window.fetchLimit = 3;
|
|
229
|
+
|
|
230
|
+
await window.resetToLatest(); // [7,8,9]
|
|
231
|
+
const itemsBeforeJump = window.items;
|
|
232
|
+
await window.jumpTo('8');
|
|
233
|
+
|
|
234
|
+
expect(window.items).toEqual(itemsBeforeJump);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('history window - jump to non-existent message', async () => {
|
|
238
|
+
const window = new TestableHistoryWindow();
|
|
239
|
+
window.limit = 5;
|
|
240
|
+
window.fetchLimit = 3;
|
|
241
|
+
|
|
242
|
+
await window.resetToLatest(); // [7,8,9]
|
|
243
|
+
const itemsBeforeJump = window.items;
|
|
244
|
+
await window.jumpTo('99'); // non-existent
|
|
245
|
+
|
|
246
|
+
expect(window.items).toEqual(itemsBeforeJump);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('history window - jump to message with traverseLock', async () => {
|
|
250
|
+
const window = new TestableHistoryWindow();
|
|
251
|
+
window.limit = 5;
|
|
252
|
+
window.fetchLimit = 3;
|
|
253
|
+
|
|
254
|
+
await window.resetToLatest(); // [7,8,9]
|
|
255
|
+
await window.setTraverseLock(true);
|
|
256
|
+
await window.jumpTo('2');
|
|
257
|
+
|
|
258
|
+
expect(window.state).toEqual(WindowState.LATEST);
|
|
259
|
+
expect(window.items).toHaveLength(3);
|
|
260
|
+
[7,8,9].forEach(id => expect(window.items.map(item => item.id)).toContain(id));
|
|
261
|
+
});
|
|
262
|
+
|
|
180
263
|
test('history window - trim messages window to limit', async () => {
|
|
181
264
|
const window = new TestableHistoryWindow();
|
|
182
265
|
window.limit = 5;
|
|
@@ -284,4 +367,4 @@ test('history window - high/low watermark limit (retainRatio)', async () => {
|
|
|
284
367
|
expect(window.items).toHaveLength(3);
|
|
285
368
|
[7, 8, 9].forEach(id => expect(window.items.map(item => item.id)).toContain(id));
|
|
286
369
|
expect(window.state).toEqual(WindowState.LATEST);
|
|
287
|
-
});
|
|
370
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"noImplicitAny": true,
|
|
4
|
-
"outDir": "build/types",
|
|
5
|
-
"module": "esnext",
|
|
6
|
-
"target": "
|
|
7
|
-
"allowJs": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"emitDeclarationOnly": true,
|
|
11
|
-
"suppressImplicitAnyIndexErrors": true,
|
|
12
|
-
"lib": ["es2018", "dom"],
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"],
|
|
16
|
-
"exclude": ["src/**/tests"],
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"noImplicitAny": true,
|
|
4
|
+
"outDir": "build/types",
|
|
5
|
+
"module": "esnext",
|
|
6
|
+
"target": "es2015",
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"emitDeclarationOnly": true,
|
|
11
|
+
"suppressImplicitAnyIndexErrors": true,
|
|
12
|
+
"lib": ["es2018", "dom"],
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"],
|
|
16
|
+
"exclude": ["src/**/tests"],
|
|
17
17
|
}
|