polfan-server-js-client 0.2.3 → 0.2.7
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/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/.idea/workspace.xml +401 -177
- package/README.md +22 -2
- package/babel.config.js +4 -5
- package/build/index.cjs.js +4595 -1816
- 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 +14 -2
- package/build/types/FilesClient.d.ts +7 -6
- package/build/types/IndexedObjectCollection.d.ts +4 -3
- package/build/types/Permissions.d.ts +4 -0
- package/build/types/WebSocketChatClient.d.ts +23 -0
- package/build/types/state-tracker/ChatStateTracker.d.ts +5 -0
- package/build/types/state-tracker/RelationshipsManager.d.ts +15 -0
- package/build/types/state-tracker/RoomMessagesHistory.d.ts +2 -0
- package/build/types/state-tracker/SpacesManager.d.ts +1 -0
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +23 -6
- package/build/types/state-tracker/UsersManager.d.ts +3 -1
- package/build/types/types/src/index.d.ts +14 -3
- package/build/types/types/src/schemes/Emoticon.d.ts +1 -0
- package/build/types/types/src/schemes/Message.d.ts +1 -1
- package/build/types/types/src/schemes/Room.d.ts +2 -0
- package/build/types/types/src/schemes/RoomHistory.d.ts +5 -0
- package/build/types/types/src/schemes/RoomMember.d.ts +3 -0
- package/build/types/types/src/schemes/RoomSummary.d.ts +1 -0
- package/build/types/types/src/schemes/SpaceSummary.d.ts +1 -0
- package/build/types/types/src/schemes/User.d.ts +2 -2
- package/build/types/types/src/schemes/UserRelationship.d.ts +6 -0
- package/build/types/types/src/schemes/commands/CreateMessage.d.ts +2 -0
- package/build/types/types/src/schemes/commands/CreateRelationship.d.ts +5 -0
- package/build/types/types/src/schemes/commands/CreateTopic.d.ts +5 -2
- package/build/types/types/src/schemes/commands/DeleteRelationship.d.ts +5 -0
- package/build/types/types/src/schemes/commands/GetRelationships.d.ts +2 -0
- package/build/types/types/src/schemes/commands/Ping.d.ts +2 -0
- package/build/types/types/src/schemes/commands/UpdateRoom.d.ts +2 -0
- package/build/types/types/src/schemes/commands/UpdateRoomMember.d.ts +7 -0
- package/build/types/types/src/schemes/commands/UpdateSpaceMember.d.ts +5 -0
- package/build/types/types/src/schemes/events/NewRelationship.d.ts +4 -0
- package/build/types/types/src/schemes/events/Pong.d.ts +2 -0
- package/build/types/types/src/schemes/events/RelationshipDeleted.d.ts +4 -0
- package/build/types/types/src/schemes/events/Relationships.d.ts +4 -0
- package/build/types/types/src/schemes/events/RoomSummaryUpdated.d.ts +7 -0
- package/build/types/types/src/schemes/events/Session.d.ts +1 -0
- package/package.json +15 -28
- package/src/AbstractChatClient.ts +30 -4
- package/src/FilesClient.ts +26 -13
- package/src/IndexedObjectCollection.ts +26 -10
- package/src/Permissions.ts +1 -0
- package/src/WebSocketChatClient.ts +92 -14
- package/src/state-tracker/ChatStateTracker.ts +22 -6
- package/src/state-tracker/EmoticonsManager.ts +6 -4
- package/src/state-tracker/MessagesManager.ts +3 -4
- package/src/state-tracker/RelationshipsManager.ts +68 -0
- package/src/state-tracker/RoomMessagesHistory.ts +20 -3
- package/src/state-tracker/RoomsManager.ts +38 -8
- package/src/state-tracker/SpacesManager.ts +28 -1
- package/src/state-tracker/TopicHistoryWindow.ts +92 -32
- package/src/state-tracker/UsersManager.ts +16 -6
- package/src/types/src/index.ts +30 -5
- package/src/types/src/schemes/Emoticon.ts +1 -0
- package/src/types/src/schemes/Message.ts +1 -1
- package/src/types/src/schemes/Room.ts +2 -0
- package/src/types/src/schemes/RoomHistory.ts +6 -0
- package/src/types/src/schemes/RoomMember.ts +3 -0
- package/src/types/src/schemes/RoomSummary.ts +1 -0
- package/src/types/src/schemes/SpaceSummary.ts +1 -0
- package/src/types/src/schemes/User.ts +2 -2
- package/src/types/src/schemes/UserRelationship.ts +8 -0
- package/src/types/src/schemes/commands/CreateMessage.ts +2 -0
- package/src/types/src/schemes/commands/CreateRelationship.ts +6 -0
- package/src/types/src/schemes/commands/CreateTopic.ts +6 -2
- package/src/types/src/schemes/commands/DeleteRelationship.ts +6 -0
- package/src/types/src/schemes/commands/GetRelationships.ts +3 -0
- package/src/types/src/schemes/commands/Ping.ts +3 -0
- package/src/types/src/schemes/commands/UpdateRoom.ts +2 -0
- package/src/types/src/schemes/commands/UpdateRoomMember.ts +7 -0
- package/src/types/src/schemes/commands/UpdateSpaceMember.ts +5 -0
- package/src/types/src/schemes/events/NewRelationship.ts +5 -0
- package/src/types/src/schemes/events/Pong.ts +3 -0
- package/src/types/src/schemes/events/RelationshipDeleted.ts +5 -0
- package/src/types/src/schemes/events/Relationships.ts +5 -0
- package/src/types/src/schemes/events/RoomSummaryUpdated.ts +8 -0
- package/src/types/src/schemes/events/Session.ts +1 -0
- package/tests/history-window.test.ts +6 -1
- package/webpack.config.browser.js +2 -24
- package/webpack.config.node.js +2 -14
- package/.eslintignore +0 -0
- package/.eslintrc.json +0 -0
- package/src/types/src/schemes/commands/SetCustomNick.ts +0 -5
|
@@ -174,6 +174,7 @@ export class RoomsManager {
|
|
|
174
174
|
const newMember = ev.member;
|
|
175
175
|
const user = member.spaceMember?.user ?? member.user;
|
|
176
176
|
|
|
177
|
+
// Preserving user object, because it's not included in event
|
|
177
178
|
if (newMember.spaceMember) {
|
|
178
179
|
newMember.spaceMember.user = user;
|
|
179
180
|
} else {
|
|
@@ -214,7 +215,9 @@ export class RoomsManager {
|
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
private handleRoomUpdated(ev: RoomUpdated): void {
|
|
217
|
-
this.list.
|
|
218
|
+
if (this.list.has(ev.room.id)) {
|
|
219
|
+
this.list.set(ev.room);
|
|
220
|
+
}
|
|
218
221
|
}
|
|
219
222
|
|
|
220
223
|
private handleRoomDeleted(ev: RoomDeleted): void {
|
|
@@ -246,7 +249,14 @@ export class RoomsManager {
|
|
|
246
249
|
// because GetMembers are not supported for PM rooms.
|
|
247
250
|
this.handleRoomMembers({
|
|
248
251
|
id: room.id,
|
|
249
|
-
members: room.recipients.map(user => ({
|
|
252
|
+
members: room.recipients.map(user => ({
|
|
253
|
+
user,
|
|
254
|
+
spaceMember: null,
|
|
255
|
+
roles: null,
|
|
256
|
+
customColor: null,
|
|
257
|
+
customNick: null,
|
|
258
|
+
extras: '',
|
|
259
|
+
})),
|
|
250
260
|
});
|
|
251
261
|
this.membersPromises.register(Promise.resolve(), room.id);
|
|
252
262
|
}
|
|
@@ -295,6 +305,7 @@ export class RoomsManager {
|
|
|
295
305
|
}
|
|
296
306
|
|
|
297
307
|
private handleUserUpdated(ev: UserUpdated): void {
|
|
308
|
+
// Update room members users
|
|
298
309
|
this.members.items.forEach((members) => {
|
|
299
310
|
const member = members.get(ev.user.id);
|
|
300
311
|
|
|
@@ -313,18 +324,37 @@ export class RoomsManager {
|
|
|
313
324
|
|
|
314
325
|
members.set(newMember);
|
|
315
326
|
});
|
|
327
|
+
|
|
328
|
+
// Update recipients users
|
|
329
|
+
const newRooms: Room[] = [];
|
|
330
|
+
this.list.items.forEach(room => {
|
|
331
|
+
if (room.recipients?.some(user => user.id === ev.user.id)) {
|
|
332
|
+
room.recipients = room.recipients.map(user => user.id === ev.user.id ? ev.user : user);
|
|
333
|
+
newRooms.push({...room});
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
this.list.set(...newRooms);
|
|
316
337
|
}
|
|
317
338
|
|
|
318
339
|
private handleNewMessage(ev: NewMessage): void {
|
|
319
340
|
const topics = this.topics.get(ev.message.location.roomId);
|
|
320
341
|
const topic = topics?.get(ev.message.location.topicId);
|
|
321
342
|
|
|
322
|
-
if (topic) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
343
|
+
if (!topic) {
|
|
344
|
+
return; // No topic found, nothing to update
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const newTopic = {
|
|
348
|
+
...topic,
|
|
349
|
+
messageCount: topic.messageCount + 1,
|
|
350
|
+
lastMessage: ev.message,
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
topics.set(newTopic);
|
|
354
|
+
const room = this.list.get(ev.message.location.roomId);
|
|
355
|
+
|
|
356
|
+
if (room.defaultTopic?.id === ev.message.location.topicId) {
|
|
357
|
+
this.list.set({ ...room, defaultTopic: newTopic });
|
|
328
358
|
}
|
|
329
359
|
}
|
|
330
360
|
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
RoleUpdated,
|
|
9
9
|
RoomDeleted,
|
|
10
10
|
RoomSummary,
|
|
11
|
+
RoomSummaryUpdated,
|
|
11
12
|
RoomUpdated,
|
|
12
13
|
Session,
|
|
13
14
|
Space,
|
|
@@ -48,6 +49,7 @@ export class SpacesManager {
|
|
|
48
49
|
this.tracker.client.on('SpaceMemberLeft', ev => this.handleSpaceMemberLeft(ev));
|
|
49
50
|
this.tracker.client.on('SpaceMembers', ev => this.handleSpaceMembers(ev));
|
|
50
51
|
this.tracker.client.on('SpaceRooms', ev => this.handleSpaceRooms(ev));
|
|
52
|
+
this.tracker.client.on('RoomSummaryUpdated', ev => this.handleRoomSummaryUpdated(ev));
|
|
51
53
|
this.tracker.client.on('SpaceMemberUpdated', ev => this.handleSpaceMemberUpdated(ev));
|
|
52
54
|
this.tracker.client.on('UserUpdated', ev => this.handleUserUpdated(ev));
|
|
53
55
|
this.tracker.client.on('NewRole', ev => this.handleNewRole(ev));
|
|
@@ -229,12 +231,37 @@ export class SpacesManager {
|
|
|
229
231
|
}
|
|
230
232
|
|
|
231
233
|
private handleSpaceRooms(ev: SpaceRooms): void {
|
|
232
|
-
if (!
|
|
234
|
+
if (!this.rooms.has(ev.id)) {
|
|
233
235
|
this.rooms.set([ev.id, new ObservableIndexedObjectCollection('id', ev.summaries)]);
|
|
234
236
|
ev.summaries.forEach(summary => this.roomIdToSpaceId.set([summary.id, ev.id]));
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
239
|
|
|
240
|
+
private async handleRoomSummaryUpdated(ev: RoomSummaryUpdated): Promise<void> {
|
|
241
|
+
const spaceId = this.roomIdToSpaceId.get(ev.summary.id);
|
|
242
|
+
const summariesPromise = this.roomsPromises.get(spaceId);
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Update summary only if the list was already loaded.
|
|
246
|
+
* RoomSummaryUpdated event has a partial summary, so we need to update the existing summary by merging it.
|
|
247
|
+
*/
|
|
248
|
+
if (spaceId && summariesPromise) {
|
|
249
|
+
await summariesPromise;
|
|
250
|
+
|
|
251
|
+
const summaries = this.rooms.get(spaceId);
|
|
252
|
+
const oldSummary = summaries.get(ev.summary.id);
|
|
253
|
+
let newSummary: RoomSummary;
|
|
254
|
+
|
|
255
|
+
if (oldSummary) {
|
|
256
|
+
newSummary = {...oldSummary, ...ev.summary};
|
|
257
|
+
} else {
|
|
258
|
+
newSummary = ev.summary;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
summaries.set(newSummary);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
238
265
|
private handleSpaceMemberUpdated(ev: SpaceMemberUpdated): void {
|
|
239
266
|
if (this.members.has(ev.spaceId)) {
|
|
240
267
|
const members = this.members.get(ev.spaceId);
|
|
@@ -31,60 +31,80 @@ export abstract class TraversableRemoteCollection<T> extends ObservableIndexedOb
|
|
|
31
31
|
* Current mode od collection window. To change mode, call one of available fetch methods.
|
|
32
32
|
*/
|
|
33
33
|
public get state(): WindowState {
|
|
34
|
-
return this.
|
|
34
|
+
return this.internalState.current;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
protected internalState: {
|
|
38
|
+
current: WindowState,
|
|
39
|
+
ongoing?: WindowState,
|
|
40
|
+
limit: number | null,
|
|
41
|
+
oldestId: string | null,
|
|
42
|
+
} = {
|
|
43
|
+
current: WindowState.LIVE,
|
|
44
|
+
ongoing: undefined,
|
|
45
|
+
limit: 50,
|
|
46
|
+
oldestId: null,
|
|
47
|
+
};
|
|
48
|
+
|
|
37
49
|
/**
|
|
38
50
|
* Maximum numer of items stored in window.
|
|
39
51
|
* Null for unlimited.
|
|
40
52
|
*/
|
|
41
|
-
public limit: number | null
|
|
53
|
+
public get limit(): number | null {
|
|
54
|
+
return this.internalState.limit;
|
|
55
|
+
}
|
|
42
56
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Maximum numer of items stored in window.
|
|
59
|
+
* Null for unlimited.
|
|
60
|
+
*/
|
|
61
|
+
public set limit(value: number | null) {
|
|
62
|
+
this.internalState.limit = value;
|
|
63
|
+
}
|
|
46
64
|
|
|
47
65
|
public get hasLatest(): boolean {
|
|
48
66
|
return [WindowState.LATEST, WindowState.LIVE].includes(this.state);
|
|
49
67
|
}
|
|
50
68
|
|
|
51
69
|
public get hasOldest(): boolean {
|
|
52
|
-
return this.state === WindowState.OLDEST || this.oldestId !== null && this.has(this.oldestId);
|
|
70
|
+
return this.state === WindowState.OLDEST || this.internalState.oldestId !== null && this.has(this.internalState.oldestId);
|
|
53
71
|
}
|
|
54
72
|
|
|
73
|
+
public abstract createMirror(): TraversableRemoteCollection<T>;
|
|
74
|
+
|
|
55
75
|
public async resetToLatest(): Promise<void> {
|
|
56
|
-
if (this.
|
|
76
|
+
if (this.internalState.ongoing || this.internalState.current === WindowState.LATEST) {
|
|
57
77
|
return;
|
|
58
78
|
}
|
|
59
79
|
|
|
60
|
-
this.
|
|
80
|
+
this.internalState.ongoing = WindowState.LATEST;
|
|
61
81
|
|
|
62
82
|
let result;
|
|
63
83
|
|
|
64
84
|
try {
|
|
65
85
|
result = await this.fetchLatestItems();
|
|
66
86
|
} finally {
|
|
67
|
-
this.
|
|
87
|
+
this.internalState.ongoing = undefined;
|
|
68
88
|
}
|
|
69
89
|
|
|
70
90
|
this.deleteAll();
|
|
71
91
|
this.addItems(result, 'tail');
|
|
72
|
-
this.
|
|
92
|
+
this.internalState.current = WindowState.LATEST;
|
|
73
93
|
}
|
|
74
94
|
|
|
75
95
|
public async fetchPrevious(): Promise<void> {
|
|
76
|
-
if (this.
|
|
96
|
+
if (this.internalState.ongoing || this.hasOldest) {
|
|
77
97
|
return;
|
|
78
98
|
}
|
|
79
99
|
|
|
80
|
-
this.
|
|
100
|
+
this.internalState.ongoing = WindowState.PAST;
|
|
81
101
|
|
|
82
102
|
let result;
|
|
83
103
|
|
|
84
104
|
try {
|
|
85
105
|
result = await this.fetchItemsBefore();
|
|
86
106
|
} finally {
|
|
87
|
-
this.
|
|
107
|
+
this.internalState.ongoing = undefined;
|
|
88
108
|
}
|
|
89
109
|
|
|
90
110
|
if (! result) {
|
|
@@ -93,13 +113,13 @@ export abstract class TraversableRemoteCollection<T> extends ObservableIndexedOb
|
|
|
93
113
|
|
|
94
114
|
if (! result.length) {
|
|
95
115
|
const firstItem = this.getAt(0);
|
|
96
|
-
this.oldestId = firstItem ? this.getId(firstItem) : null;
|
|
116
|
+
this.internalState.oldestId = firstItem ? this.getId(firstItem) : null;
|
|
97
117
|
|
|
98
118
|
await this.refreshFetchedState();
|
|
99
119
|
|
|
100
120
|
// LATEST state has priority over OLDEST
|
|
101
|
-
if (this.
|
|
102
|
-
this.
|
|
121
|
+
if (this.internalState.current === WindowState.PAST) {
|
|
122
|
+
this.internalState.current = WindowState.OLDEST;
|
|
103
123
|
}
|
|
104
124
|
|
|
105
125
|
return;
|
|
@@ -110,18 +130,18 @@ export abstract class TraversableRemoteCollection<T> extends ObservableIndexedOb
|
|
|
110
130
|
}
|
|
111
131
|
|
|
112
132
|
public async fetchNext(): Promise<void> {
|
|
113
|
-
if (this.
|
|
133
|
+
if (this.internalState.ongoing || this.hasLatest) {
|
|
114
134
|
return;
|
|
115
135
|
}
|
|
116
136
|
|
|
117
|
-
this.
|
|
137
|
+
this.internalState.ongoing = WindowState.PAST;
|
|
118
138
|
|
|
119
139
|
let result;
|
|
120
140
|
|
|
121
141
|
try {
|
|
122
142
|
result = await this.fetchItemsAfter();
|
|
123
143
|
} finally {
|
|
124
|
-
this.
|
|
144
|
+
this.internalState.ongoing = undefined;
|
|
125
145
|
}
|
|
126
146
|
|
|
127
147
|
if (! result) {
|
|
@@ -145,7 +165,7 @@ export abstract class TraversableRemoteCollection<T> extends ObservableIndexedOb
|
|
|
145
165
|
protected abstract isLatestItemLoaded(): Promise<boolean>;
|
|
146
166
|
|
|
147
167
|
protected async refreshFetchedState(): Promise<void> {
|
|
148
|
-
this.
|
|
168
|
+
this.internalState.current = (await this.isLatestItemLoaded()) ? WindowState.LATEST : WindowState.PAST;
|
|
149
169
|
}
|
|
150
170
|
|
|
151
171
|
protected addItems(newItems: T[], to: 'head' | 'tail'): void {
|
|
@@ -187,14 +207,64 @@ export class TopicHistoryWindow extends TraversableRemoteCollection<Message> {
|
|
|
187
207
|
*/
|
|
188
208
|
public readonly WindowState: typeof WindowState = WindowState;
|
|
189
209
|
|
|
210
|
+
declare protected internalState: typeof TraversableRemoteCollection<Message>['prototype']['internalState'] & {
|
|
211
|
+
traverseLock: boolean,
|
|
212
|
+
};
|
|
213
|
+
|
|
190
214
|
public constructor(
|
|
191
215
|
private roomId: string,
|
|
192
216
|
private topicId: string,
|
|
193
217
|
private tracker: ChatStateTracker,
|
|
218
|
+
bindEvents: boolean = true,
|
|
194
219
|
) {
|
|
195
220
|
super('id');
|
|
196
|
-
|
|
197
|
-
this.
|
|
221
|
+
|
|
222
|
+
this.internalState.traverseLock = false;
|
|
223
|
+
|
|
224
|
+
if (bindEvents) {
|
|
225
|
+
this.tracker.client.on('NewMessage', ev => this.handleNewMessage(ev));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
public createMirror(): TopicHistoryWindow {
|
|
230
|
+
const copy = new TopicHistoryWindow(this.roomId, this.topicId, this.tracker, false);
|
|
231
|
+
copy.eventTarget = this.eventTarget;
|
|
232
|
+
copy._items = this._items;
|
|
233
|
+
copy.internalState = this.internalState;
|
|
234
|
+
return copy;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public get isTraverseLocked(): boolean {
|
|
238
|
+
return this.internalState.traverseLock;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public async setTraverseLock(lock: boolean): Promise<void> {
|
|
242
|
+
this.internalState.traverseLock = lock;
|
|
243
|
+
|
|
244
|
+
if (lock && (this.state !== WindowState.LIVE && this.state !== WindowState.LATEST)) {
|
|
245
|
+
await super.resetToLatest();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
public async resetToLatest(): Promise<void> {
|
|
250
|
+
if (this.internalState.traverseLock) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
return super.resetToLatest();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public async fetchNext(): Promise<void> {
|
|
257
|
+
if (this.internalState.traverseLock) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
return super.fetchNext();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public async fetchPrevious(): Promise<void> {
|
|
264
|
+
if (this.internalState.traverseLock) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
return super.fetchPrevious();
|
|
198
268
|
}
|
|
199
269
|
|
|
200
270
|
/**
|
|
@@ -220,16 +290,6 @@ export class TopicHistoryWindow extends TraversableRemoteCollection<Message> {
|
|
|
220
290
|
}
|
|
221
291
|
}
|
|
222
292
|
|
|
223
|
-
private handleSession(ev: Session): void {
|
|
224
|
-
const rooms = ev.state.rooms;
|
|
225
|
-
|
|
226
|
-
if (rooms.find(room => room.id === this.roomId)) {
|
|
227
|
-
this.resetToLatest();
|
|
228
|
-
} else {
|
|
229
|
-
this.deleteAll();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
293
|
protected async fetchItemsAfter(): Promise<Message[] | null> {
|
|
234
294
|
const afterId = this.getAt(this.length - 1)?.id;
|
|
235
295
|
|
|
@@ -2,8 +2,11 @@ import {ChatStateTracker} from "./ChatStateTracker";
|
|
|
2
2
|
import {ObservableIndexedObjectCollection} from "../IndexedObjectCollection";
|
|
3
3
|
import {RoomMember, Session, SpaceMember, User} from "../types/src";
|
|
4
4
|
import {extractUserFromMember} from "./functions";
|
|
5
|
+
import {EventTarget} from "../EventTarget";
|
|
5
6
|
|
|
6
7
|
export class UsersManager {
|
|
8
|
+
public readonly onlineStatus = new EventTarget();
|
|
9
|
+
|
|
7
10
|
private readonly users: ObservableIndexedObjectCollection<User> = new ObservableIndexedObjectCollection('id');
|
|
8
11
|
|
|
9
12
|
public constructor(private tracker: ChatStateTracker) {
|
|
@@ -26,15 +29,22 @@ export class UsersManager {
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
private handleMembers(members: (RoomMember | SpaceMember)[]): void {
|
|
29
|
-
this.
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private handleUsers(users: User[]): void {
|
|
33
|
-
this.users.set(...users);
|
|
32
|
+
this.handleUsers(members.map(extractUserFromMember));
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
private handleSession(session: Session): void {
|
|
37
36
|
this.users.deleteAll();
|
|
38
|
-
this.
|
|
37
|
+
this.handleUsers([session.user]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private handleUsers(users: User[]): void {
|
|
41
|
+
users.forEach(newUser => {
|
|
42
|
+
const oldUser = this.users.get(newUser.id);
|
|
43
|
+
if (oldUser && oldUser.online !== newUser.online) {
|
|
44
|
+
this.onlineStatus.emit('change', newUser);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
this.users.set(...users);
|
|
39
49
|
}
|
|
40
50
|
}
|
package/src/types/src/index.ts
CHANGED
|
@@ -57,7 +57,7 @@ import {LeaveRoom} from "./schemes/commands/LeaveRoom";
|
|
|
57
57
|
import {CreateRoom} from "./schemes/commands/CreateRoom";
|
|
58
58
|
import {DeleteRoom} from "./schemes/commands/DeleteRoom";
|
|
59
59
|
import {GetRoomMembers} from "./schemes/commands/GetRoomMembers";
|
|
60
|
-
import {CreateTopic} from "./schemes/commands/CreateTopic";
|
|
60
|
+
import {CreateTopic, CreateTopicInitialMessage} from "./schemes/commands/CreateTopic";
|
|
61
61
|
import {DeleteTopic} from "./schemes/commands/DeleteTopic";
|
|
62
62
|
import {CreateMessage} from "./schemes/commands/CreateMessage";
|
|
63
63
|
import {UpdateRole} from "./schemes/commands/UpdateRole";
|
|
@@ -111,12 +111,23 @@ import {GetClientData} from "./schemes/commands/GetClientData";
|
|
|
111
111
|
import {SetClientData} from "./schemes/commands/SetClientData";
|
|
112
112
|
import {ClientData} from "./schemes/events/ClientData";
|
|
113
113
|
import {RoomStream, RoomStreamType} from "./schemes/RoomStream";
|
|
114
|
+
import {RoomHistory, RoomHistoryMode} from "./schemes/RoomHistory";
|
|
114
115
|
import {GetRoomSummary} from "./schemes/commands/GetRoomSummary";
|
|
115
116
|
import {GetSpaceSummary} from "./schemes/commands/GetSpaceSummary";
|
|
116
117
|
import {SpaceFlag} from "./schemes/Space";
|
|
117
118
|
import {SpaceSummary as SpaceSummaryEvent} from "./schemes/events/SpaceSummary";
|
|
118
119
|
import {RoomSummary as RoomSummaryEvent} from "./schemes/events/RoomSummary";
|
|
119
|
-
import {
|
|
120
|
+
import {UpdateSpaceMember} from "./schemes/commands/UpdateSpaceMember";
|
|
121
|
+
import {NewRelationship} from "./schemes/events/NewRelationship";
|
|
122
|
+
import {RelationshipDeleted} from "./schemes/events/RelationshipDeleted";
|
|
123
|
+
import {UserRelationship, UserRelationshipType} from "./schemes/UserRelationship";
|
|
124
|
+
import {DeleteRelationship} from "./schemes/commands/DeleteRelationship";
|
|
125
|
+
import {Relationships} from "./schemes/events/Relationships";
|
|
126
|
+
import {CreateRelationship} from "./schemes/commands/CreateRelationship";
|
|
127
|
+
import {RoomSummaryUpdated} from "./schemes/events/RoomSummaryUpdated";
|
|
128
|
+
import {UpdateRoomMember} from "./schemes/commands/UpdateRoomMember";
|
|
129
|
+
import {Ping} from "./schemes/commands/Ping";
|
|
130
|
+
import {Pong} from "./schemes/events/Pong";
|
|
120
131
|
|
|
121
132
|
export {
|
|
122
133
|
// objects
|
|
@@ -128,6 +139,10 @@ export {
|
|
|
128
139
|
Room,
|
|
129
140
|
RoomFlag,
|
|
130
141
|
RoomType,
|
|
142
|
+
RoomStream,
|
|
143
|
+
RoomStreamType,
|
|
144
|
+
RoomHistory,
|
|
145
|
+
RoomHistoryMode,
|
|
131
146
|
RoomMember,
|
|
132
147
|
RoomSummary,
|
|
133
148
|
RoomSummaryExtras,
|
|
@@ -146,8 +161,9 @@ export {
|
|
|
146
161
|
PermissionOverwritesTarget,
|
|
147
162
|
BanObject,
|
|
148
163
|
LeaveReason,
|
|
149
|
-
|
|
150
|
-
|
|
164
|
+
UserRelationship,
|
|
165
|
+
UserRelationshipType,
|
|
166
|
+
CreateTopicInitialMessage,
|
|
151
167
|
// events
|
|
152
168
|
Bye,
|
|
153
169
|
Error,
|
|
@@ -197,6 +213,11 @@ export {
|
|
|
197
213
|
ClientData,
|
|
198
214
|
SpaceSummaryEvent,
|
|
199
215
|
RoomSummaryEvent,
|
|
216
|
+
NewRelationship,
|
|
217
|
+
RelationshipDeleted,
|
|
218
|
+
Relationships,
|
|
219
|
+
RoomSummaryUpdated,
|
|
220
|
+
Pong,
|
|
200
221
|
// commands
|
|
201
222
|
AssignRole,
|
|
202
223
|
GetMessages,
|
|
@@ -247,5 +268,9 @@ export {
|
|
|
247
268
|
SetClientData,
|
|
248
269
|
GetSpaceSummary,
|
|
249
270
|
GetRoomSummary,
|
|
250
|
-
|
|
271
|
+
UpdateSpaceMember,
|
|
272
|
+
CreateRelationship,
|
|
273
|
+
DeleteRelationship,
|
|
274
|
+
UpdateRoomMember,
|
|
275
|
+
Ping,
|
|
251
276
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {User} from "./User";
|
|
2
2
|
import {ChatLocation} from "./ChatLocation";
|
|
3
3
|
|
|
4
|
-
export type MessageType = 'Text'|'RoomJoin'|'RoomLeave'|'SpaceJoin'|'SpaceLeave'|'TopicChange'|'CustomNickChange';
|
|
4
|
+
export type MessageType = 'Text'|'RoomJoin'|'RoomLeave'|'SpaceJoin'|'SpaceLeave'|'TopicChange'|'CustomNickChange'|'Ephemeral';
|
|
5
5
|
|
|
6
6
|
export interface MessageAuthor {
|
|
7
7
|
user: User;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {Topic} from "./Topic";
|
|
2
2
|
import {User} from "./User";
|
|
3
3
|
import {RoomStream} from "./RoomStream";
|
|
4
|
+
import {RoomHistory} from "./RoomHistory";
|
|
4
5
|
|
|
5
6
|
export type RoomType = 'Text' | 'ClassicText' | 'Pm';
|
|
6
7
|
|
|
@@ -19,4 +20,5 @@ export interface Room {
|
|
|
19
20
|
recipients: User[] | null;
|
|
20
21
|
flags: number;
|
|
21
22
|
stream: RoomStream | null;
|
|
23
|
+
history: RoomHistory | null;
|
|
22
24
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {ChatLocation} from "../ChatLocation";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
export interface CreateTopicInitialMessage {
|
|
4
|
+
content?: string;
|
|
5
|
+
attachments?: string[];
|
|
6
|
+
}
|
|
3
7
|
|
|
4
8
|
export interface CreateTopic {
|
|
5
9
|
location: ChatLocation;
|
|
6
10
|
name: string;
|
|
7
11
|
refMessageId?: string;
|
|
8
|
-
initialMessage?:
|
|
12
|
+
initialMessage?: CreateTopicInitialMessage;
|
|
9
13
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {RoomStream} from "../RoomStream";
|
|
2
|
+
import {RoomHistory} from "../RoomHistory";
|
|
2
3
|
|
|
3
4
|
export interface UpdateRoom {
|
|
4
5
|
id: string;
|
|
@@ -6,4 +7,5 @@ export interface UpdateRoom {
|
|
|
6
7
|
description?: string;
|
|
7
8
|
flags?: number;
|
|
8
9
|
stream?: RoomStream | null;
|
|
10
|
+
history?: RoomHistory;
|
|
9
11
|
}
|