polfan-server-js-client 0.1.97 → 0.1.99
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.
|
@@ -6,22 +6,35 @@ export declare class MessagesManager {
|
|
|
6
6
|
private tracker;
|
|
7
7
|
private readonly list;
|
|
8
8
|
private readonly followedTopics;
|
|
9
|
+
private readonly followedTopicsPromises;
|
|
9
10
|
constructor(tracker: ChatStateTracker);
|
|
10
11
|
/**
|
|
11
12
|
* Get collection of the messages written in topic.
|
|
12
13
|
*/
|
|
13
14
|
get(location: ChatLocation): Promise<ObservableIndexedObjectCollection<Message> | undefined>;
|
|
14
15
|
/**
|
|
15
|
-
* Cache
|
|
16
|
-
* Then you can get
|
|
16
|
+
* Cache followed topics for all joined rooms in a space and fetch them in bulk if necessary.
|
|
17
|
+
* Then you can get them using getRoomFollowedTopics().
|
|
17
18
|
* @see getRoomFollowedTopics
|
|
18
19
|
*/
|
|
19
20
|
cacheSpaceFollowedTopic(spaceId: string): Promise<void>;
|
|
20
21
|
/**
|
|
21
|
-
* Get ack reports for the given room.
|
|
22
|
-
* @
|
|
22
|
+
* Get ack reports for the given room.
|
|
23
|
+
* @return Undefined if you are not in the room, collection otherwise.
|
|
23
24
|
*/
|
|
24
25
|
getRoomFollowedTopics(roomId: string): Promise<ObservableIndexedObjectCollection<FollowedTopic> | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Batch acknowledge all missed messages from any topics in given room.
|
|
28
|
+
*/
|
|
29
|
+
ackRoomFollowedTopics(roomId: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Calculate missed messages from any topic in given room.
|
|
32
|
+
* @return Undefined if you are not in room, stats object otherwise.
|
|
33
|
+
*/
|
|
34
|
+
calculateRoomMissedMessages(roomId: string): Promise<{
|
|
35
|
+
missed: number;
|
|
36
|
+
missedMore: boolean;
|
|
37
|
+
} | undefined>;
|
|
25
38
|
/**
|
|
26
39
|
* For internal use. If you want to delete the message, execute a proper command on client object.
|
|
27
40
|
* @internal
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
IndexedCollection,
|
|
17
17
|
ObservableIndexedObjectCollection
|
|
18
18
|
} from "../IndexedObjectCollection";
|
|
19
|
+
import {PromiseRegistry} from "./AsyncUtils";
|
|
19
20
|
|
|
20
21
|
export const getCombinedId = (location: ChatLocation) => (location.roomId ?? '') + (location.topicId ?? '');
|
|
21
22
|
|
|
@@ -23,6 +24,7 @@ export class MessagesManager {
|
|
|
23
24
|
// Temporary not lazy loaded; server must implement GetTopicMessages command.
|
|
24
25
|
private readonly list = new IndexedCollection<string, ObservableIndexedObjectCollection<Message>>();
|
|
25
26
|
private readonly followedTopics = new IndexedCollection<string, ObservableIndexedObjectCollection<FollowedTopic>>();
|
|
27
|
+
private readonly followedTopicsPromises = new PromiseRegistry();
|
|
26
28
|
|
|
27
29
|
public constructor(private tracker: ChatStateTracker) {
|
|
28
30
|
this.tracker.client.on('Session', ev => this.handleSession(ev));
|
|
@@ -45,8 +47,8 @@ export class MessagesManager {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/**
|
|
48
|
-
* Cache
|
|
49
|
-
* Then you can get
|
|
50
|
+
* Cache followed topics for all joined rooms in a space and fetch them in bulk if necessary.
|
|
51
|
+
* Then you can get them using getRoomFollowedTopics().
|
|
50
52
|
* @see getRoomFollowedTopics
|
|
51
53
|
*/
|
|
52
54
|
public async cacheSpaceFollowedTopic(spaceId: string): Promise<void> {
|
|
@@ -65,8 +67,8 @@ export class MessagesManager {
|
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/**
|
|
68
|
-
* Get ack reports for the given room.
|
|
69
|
-
* @
|
|
70
|
+
* Get ack reports for the given room.
|
|
71
|
+
* @return Undefined if you are not in the room, collection otherwise.
|
|
70
72
|
*/
|
|
71
73
|
public async getRoomFollowedTopics(roomId: string): Promise<ObservableIndexedObjectCollection<FollowedTopic> | undefined> {
|
|
72
74
|
if (! (await this.tracker.rooms.get()).has(roomId)) {
|
|
@@ -74,18 +76,64 @@ export class MessagesManager {
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
if (! this.followedTopics.has(roomId)) {
|
|
77
|
-
|
|
79
|
+
if (this.followedTopicsPromises.notExist(roomId)) {
|
|
80
|
+
this.followedTopicsPromises.registerByFunction(async () => {
|
|
81
|
+
const result = await this.tracker.client.send('GetFollowedTopics', {location: {roomId}});
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
if (result.error) {
|
|
84
|
+
throw result.error;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.setFollowedTopicsArray(result.data.followedTopics);
|
|
88
|
+
}, roomId);
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
this.
|
|
91
|
+
await this.followedTopicsPromises.get(roomId);
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
return this.followedTopics.get(roomId);
|
|
87
95
|
}
|
|
88
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Batch acknowledge all missed messages from any topics in given room.
|
|
99
|
+
*/
|
|
100
|
+
public async ackRoomFollowedTopics(roomId: string): Promise<void> {
|
|
101
|
+
const collection = await this.getRoomFollowedTopics(roomId);
|
|
102
|
+
|
|
103
|
+
if (! collection) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (const followedTopic of collection.items) {
|
|
108
|
+
if (followedTopic.missed) {
|
|
109
|
+
await this.tracker.client.send('Ack', {location: followedTopic.location});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Calculate missed messages from any topic in given room.
|
|
116
|
+
* @return Undefined if you are not in room, stats object otherwise.
|
|
117
|
+
*/
|
|
118
|
+
public async calculateRoomMissedMessages(roomId: string): Promise<{missed: number, missedMore: boolean} | undefined> {
|
|
119
|
+
const collection = await this.getRoomFollowedTopics(roomId);
|
|
120
|
+
|
|
121
|
+
if (! collection) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let missed: number = 0, missedMore: boolean = false;
|
|
126
|
+
|
|
127
|
+
for (const followedTopic of collection.items) {
|
|
128
|
+
missed += followedTopic.missed ?? followedTopic.missedMoreThan ?? 0;
|
|
129
|
+
if (followedTopic.missedMoreThan) {
|
|
130
|
+
missedMore = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {missed, missedMore};
|
|
135
|
+
}
|
|
136
|
+
|
|
89
137
|
/**
|
|
90
138
|
* For internal use. If you want to delete the message, execute a proper command on client object.
|
|
91
139
|
* @internal
|