@devanachat/sdk 0.8.1 → 0.10.0
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/CHANGELOG.md +68 -4
- package/build/index.cjs.js +194 -95
- package/build/index.cjs.js.map +1 -1
- package/build/index.mjs +191 -95
- package/build/index.mjs.map +1 -1
- package/build/index.umd.js +1 -1
- package/build/index.umd.js.map +1 -1
- package/build/types/AbstractChatClient.d.ts +4 -2
- package/build/types/Permissions.d.ts +4 -0
- package/build/types/index.d.ts +3 -3
- package/build/types/protocol/index.d.ts +6 -3
- package/build/types/protocol/schemes/Emoticon.d.ts +2 -3
- package/build/types/protocol/schemes/Entitlements.d.ts +2 -1
- package/build/types/protocol/schemes/Message.d.ts +1 -1
- package/build/types/protocol/schemes/PmParticipant.d.ts +8 -0
- package/build/types/protocol/schemes/Reaction.d.ts +2 -0
- package/build/types/protocol/schemes/Room.d.ts +3 -0
- package/build/types/protocol/schemes/commands/CreateEmoticon.d.ts +1 -1
- package/build/types/protocol/schemes/commands/GetEmoticons.d.ts +1 -0
- package/build/types/protocol/schemes/commands/GetIgnoredRooms.d.ts +2 -0
- package/build/types/protocol/schemes/commands/LeaveRoom.d.ts +1 -0
- package/build/types/protocol/schemes/events/EmoticonDeleted.d.ts +1 -1
- package/build/types/protocol/schemes/events/Emoticons.d.ts +1 -1
- package/build/types/protocol/schemes/events/Error.d.ts +5 -0
- package/build/types/protocol/schemes/events/IgnoredRooms.d.ts +4 -0
- package/build/types/state-tracker/EmoticonsManager.d.ts +1 -1
- package/build/types/state-tracker/RoomsManager.d.ts +2 -1
- package/build/types/state-tracker/StateSnapshot.d.ts +2 -5
- package/build/types/state-tracker/UsersManager.d.ts +7 -1
- package/build/types/state-tracker/functions.d.ts +12 -1
- package/package.json +1 -1
package/build/index.mjs
CHANGED
|
@@ -1075,10 +1075,12 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1075
1075
|
value
|
|
1076
1076
|
});
|
|
1077
1077
|
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1078
|
+
|
|
1079
|
+
// Not `{[ev.messageId]: _, ...rest}` - Babel's loose object rest drops the key when the binding is unused (babel/babel#18196)
|
|
1080
|
+
const myReactions = {
|
|
1081
|
+
...this.internalState.myReactions
|
|
1082
|
+
};
|
|
1083
|
+
delete myReactions[ev.messageId];
|
|
1082
1084
|
if (own.length) {
|
|
1083
1085
|
myReactions[ev.messageId] = own;
|
|
1084
1086
|
}
|
|
@@ -1901,7 +1903,7 @@ let UserStatus = /*#__PURE__*/function (UserStatus) {
|
|
|
1901
1903
|
/**
|
|
1902
1904
|
* Version of the {@link StateSnapshot} format. A snapshot of any other version is rejected on import.
|
|
1903
1905
|
*/
|
|
1904
|
-
const STATE_SNAPSHOT_VERSION =
|
|
1906
|
+
const STATE_SNAPSHOT_VERSION = 2;
|
|
1905
1907
|
|
|
1906
1908
|
/**
|
|
1907
1909
|
* Plain, JSON-serializable copy of the state tracked by {@link ChatStateTracker}, made to restore the state at the
|
|
@@ -1971,6 +1973,9 @@ function hasId(value) {
|
|
|
1971
1973
|
function isUser(value) {
|
|
1972
1974
|
return hasId(value);
|
|
1973
1975
|
}
|
|
1976
|
+
function isPmParticipant(value) {
|
|
1977
|
+
return isObject(value) && isUser(value.user) && typeof value.flags === 'number';
|
|
1978
|
+
}
|
|
1974
1979
|
function isRole(value) {
|
|
1975
1980
|
return hasId(value) && typeof value.priority === 'number';
|
|
1976
1981
|
}
|
|
@@ -1987,7 +1992,7 @@ function isFullMessage(value) {
|
|
|
1987
1992
|
return hasId(value) && isObject(value.location) && isString(value.location.roomId) && isString(value.location.topicId) && isObject(value.author) && isUser(value.author.user) && Array.isArray(value.reactions);
|
|
1988
1993
|
}
|
|
1989
1994
|
function isRoom(value) {
|
|
1990
|
-
return hasId(value) && isString(value.type) && (value.spaceId === null || isString(value.spaceId)) && (value.defaultTopic === null || isTopic(value.defaultTopic)) && (value.recipients === null || isArrayOf(value.recipients, isUser)) && isObject(value.history) && isString(value.history.mode);
|
|
1995
|
+
return hasId(value) && isString(value.type) && (value.spaceId === null || isString(value.spaceId)) && (value.defaultTopic === null || isTopic(value.defaultTopic)) && (value.participants === null || isArrayOf(value.participants, isPmParticipant)) && (value.recipients === null || isArrayOf(value.recipients, isUser)) && isObject(value.history) && isString(value.history.mode);
|
|
1991
1996
|
}
|
|
1992
1997
|
function isSpaceRooms(value) {
|
|
1993
1998
|
return isObject(value) && isString(value.spaceId) && isArrayOf(value.summaries, hasId);
|
|
@@ -2016,12 +2021,84 @@ function isRoomMember(value) {
|
|
|
2016
2021
|
function isRoomMembers(value) {
|
|
2017
2022
|
return isObject(value) && isString(value.roomId) && isArrayOf(value.members, isRoomMember);
|
|
2018
2023
|
}
|
|
2024
|
+
;// ./src/protocol/schemes/PmParticipant.ts
|
|
2025
|
+
let PmParticipantFlag = /*#__PURE__*/function (PmParticipantFlag) {
|
|
2026
|
+
PmParticipantFlag[PmParticipantFlag["IgnoresRoom"] = 1] = "IgnoresRoom";
|
|
2027
|
+
return PmParticipantFlag;
|
|
2028
|
+
}({});
|
|
2029
|
+
;// ./src/state-tracker/functions.ts
|
|
2030
|
+
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* @return New objects of the other roles whose priority has to move; the given roles are left intact.
|
|
2034
|
+
*/
|
|
2035
|
+
function reorderRolesOnPriorityUpdate(allRoles, oldRole, updatedRole) {
|
|
2036
|
+
// If the priority has changed, adjust the rest of roles
|
|
2037
|
+
const increased = updatedRole.priority - oldRole.priority > 0;
|
|
2038
|
+
const decreased = !increased;
|
|
2039
|
+
const changedRoles = [];
|
|
2040
|
+
allRoles.forEach(role => {
|
|
2041
|
+
if (role.id === updatedRole.id) {
|
|
2042
|
+
// Skip the updated role
|
|
2043
|
+
return;
|
|
2044
|
+
}
|
|
2045
|
+
if (increased && oldRole.priority <= role.priority) {
|
|
2046
|
+
changedRoles.push({
|
|
2047
|
+
...role,
|
|
2048
|
+
priority: role.priority - 1
|
|
2049
|
+
});
|
|
2050
|
+
}
|
|
2051
|
+
if (decreased && updatedRole.priority <= role.priority) {
|
|
2052
|
+
changedRoles.push({
|
|
2053
|
+
...role,
|
|
2054
|
+
priority: role.priority + 1
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
});
|
|
2058
|
+
return changedRoles;
|
|
2059
|
+
}
|
|
2060
|
+
function extractUserFromMember(member) {
|
|
2061
|
+
return member.user ?? member.spaceMember?.user;
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
/**
|
|
2065
|
+
* Whether the room is a private group conversation - 3 or more participants, including the ones ignoring it.
|
|
2066
|
+
*/
|
|
2067
|
+
function isGroupPm(room) {
|
|
2068
|
+
return room.type === 'Pm' && (room.participants?.length ?? 0) >= 3;
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
/**
|
|
2072
|
+
* Participants of a private conversation taking part in it: without the ones ignoring it and without the user
|
|
2073
|
+
* `meId`. Empty for notes and for rooms of spaces.
|
|
2074
|
+
*/
|
|
2075
|
+
function getPmPeers(room, meId) {
|
|
2076
|
+
return getActivePmParticipants(room).filter(participant => participant.user.id !== meId);
|
|
2077
|
+
}
|
|
2078
|
+
function getActivePmParticipants(room) {
|
|
2079
|
+
return (room.participants ?? []).filter(participant => !(participant.flags & PmParticipantFlag.IgnoresRoom));
|
|
2080
|
+
}
|
|
2081
|
+
function isSameUser(a, b) {
|
|
2082
|
+
const keys = Object.keys(a);
|
|
2083
|
+
if (keys.length !== Object.keys(b).length) {
|
|
2084
|
+
return false;
|
|
2085
|
+
}
|
|
2086
|
+
return keys.every(key => {
|
|
2087
|
+
const valueA = a[key];
|
|
2088
|
+
const valueB = b[key];
|
|
2089
|
+
if (Array.isArray(valueA) && Array.isArray(valueB)) {
|
|
2090
|
+
return valueA.length === valueB.length && valueA.every((item, index) => item === valueB[index]);
|
|
2091
|
+
}
|
|
2092
|
+
return valueA === valueB;
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2019
2095
|
;// ./src/state-tracker/RoomsManager.ts
|
|
2020
2096
|
|
|
2021
2097
|
|
|
2022
2098
|
|
|
2023
2099
|
|
|
2024
2100
|
|
|
2101
|
+
|
|
2025
2102
|
class RoomsManager {
|
|
2026
2103
|
messages;
|
|
2027
2104
|
followedTopics;
|
|
@@ -2111,7 +2188,15 @@ class RoomsManager {
|
|
|
2111
2188
|
const promise = this.tracker.client.send('GetTopics', {
|
|
2112
2189
|
roomId,
|
|
2113
2190
|
topicIds: idsToFetch
|
|
2114
|
-
}).then(result =>
|
|
2191
|
+
}).then(result => {
|
|
2192
|
+
const topics = this.topics.get(roomId);
|
|
2193
|
+
if (topics) {
|
|
2194
|
+
topics.set(...result.data.topics);
|
|
2195
|
+
} else {
|
|
2196
|
+
// A room not joined yet has nowhere to keep them - let them be fetched again once it is.
|
|
2197
|
+
this.topicsPromises.forget(...idsToFetch.map(topicId => roomId + topicId));
|
|
2198
|
+
}
|
|
2199
|
+
});
|
|
2115
2200
|
idsToFetch.forEach(topicId => this.topicsPromises.register(promise, roomId + topicId));
|
|
2116
2201
|
}
|
|
2117
2202
|
for (const topicId of tryToFetchTopicIds) {
|
|
@@ -2142,9 +2227,13 @@ class RoomsManager {
|
|
|
2142
2227
|
* @internal
|
|
2143
2228
|
*/
|
|
2144
2229
|
_exportRooms() {
|
|
2145
|
-
return this.list.items.map(room => room.
|
|
2230
|
+
return this.list.items.map(room => room.participants ? {
|
|
2146
2231
|
...room,
|
|
2147
|
-
|
|
2232
|
+
participants: room.participants.map(participant => ({
|
|
2233
|
+
...participant,
|
|
2234
|
+
user: withoutPresence(participant.user)
|
|
2235
|
+
})),
|
|
2236
|
+
recipients: room.recipients?.map(withoutPresence) ?? null
|
|
2148
2237
|
} : room);
|
|
2149
2238
|
}
|
|
2150
2239
|
|
|
@@ -2196,7 +2285,7 @@ class RoomsManager {
|
|
|
2196
2285
|
}
|
|
2197
2286
|
|
|
2198
2287
|
/**
|
|
2199
|
-
* Members of private conversations are not exported - they are made of the
|
|
2288
|
+
* Members of private conversations are not exported - they are made of the participants of the room.
|
|
2200
2289
|
* @internal
|
|
2201
2290
|
*/
|
|
2202
2291
|
_exportMembers(roomIds, limit) {
|
|
@@ -2322,6 +2411,9 @@ class RoomsManager {
|
|
|
2322
2411
|
}
|
|
2323
2412
|
const members = this.members.get(ev.roomId);
|
|
2324
2413
|
const member = members.get(ev.userId);
|
|
2414
|
+
if (!member) {
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2325
2417
|
const user = member.spaceMember?.user ?? member.user;
|
|
2326
2418
|
|
|
2327
2419
|
// Preserving user object, because it's not included in event
|
|
@@ -2366,6 +2458,7 @@ class RoomsManager {
|
|
|
2366
2458
|
handleRoomUpdated(ev) {
|
|
2367
2459
|
if (this.list.has(ev.room.id)) {
|
|
2368
2460
|
this.list.set(ev.room);
|
|
2461
|
+
this.setPmMembers(ev.room);
|
|
2369
2462
|
}
|
|
2370
2463
|
}
|
|
2371
2464
|
handleRoomDeleted(ev) {
|
|
@@ -2389,27 +2482,39 @@ class RoomsManager {
|
|
|
2389
2482
|
if (room.defaultTopic) {
|
|
2390
2483
|
this.addJoinedRoomTopics(room.id, room.defaultTopic);
|
|
2391
2484
|
}
|
|
2392
|
-
|
|
2393
|
-
// Treat PM recipients as normal room members.
|
|
2394
|
-
// We are registering fake promise in `memberPromises`
|
|
2395
|
-
// because GetMembers are not supported for PM rooms.
|
|
2396
|
-
this.handleRoomMembers({
|
|
2397
|
-
id: room.id,
|
|
2398
|
-
members: room.recipients.map(user => ({
|
|
2399
|
-
user,
|
|
2400
|
-
spaceMember: null,
|
|
2401
|
-
roles: null,
|
|
2402
|
-
customColor: null,
|
|
2403
|
-
customNick: null,
|
|
2404
|
-
customAvatar: null,
|
|
2405
|
-
extras: ''
|
|
2406
|
-
}))
|
|
2407
|
-
});
|
|
2408
|
-
this.membersPromises.register(Promise.resolve(), room.id);
|
|
2409
|
-
}
|
|
2485
|
+
this.setPmMembers(room);
|
|
2410
2486
|
}
|
|
2411
2487
|
this.list.set(...rooms);
|
|
2412
2488
|
}
|
|
2489
|
+
setPmMembers(room) {
|
|
2490
|
+
if (room.type !== 'Pm' || !room.participants) {
|
|
2491
|
+
return;
|
|
2492
|
+
}
|
|
2493
|
+
const current = this.members.get(room.id);
|
|
2494
|
+
const members = getActivePmParticipants(room).map(({
|
|
2495
|
+
user
|
|
2496
|
+
}) => {
|
|
2497
|
+
const member = current?.get(user.id);
|
|
2498
|
+
return member && isSameUser(member.user, user) ? member : {
|
|
2499
|
+
user,
|
|
2500
|
+
spaceMember: null,
|
|
2501
|
+
roles: null,
|
|
2502
|
+
customColor: null,
|
|
2503
|
+
customNick: null,
|
|
2504
|
+
customAvatar: null,
|
|
2505
|
+
extras: ''
|
|
2506
|
+
};
|
|
2507
|
+
});
|
|
2508
|
+
if (current?.length === members.length && members.every(member => current.get(member.user.id) === member)) {
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
this.handleRoomMembers({
|
|
2512
|
+
id: room.id,
|
|
2513
|
+
members
|
|
2514
|
+
});
|
|
2515
|
+
// GetRoomMembers is not supported for private conversations
|
|
2516
|
+
this.membersPromises.register(Promise.resolve(), room.id);
|
|
2517
|
+
}
|
|
2413
2518
|
handleRoomLeft(ev) {
|
|
2414
2519
|
this.deleteRoom(ev.id);
|
|
2415
2520
|
}
|
|
@@ -2473,13 +2578,17 @@ class RoomsManager {
|
|
|
2473
2578
|
});
|
|
2474
2579
|
});
|
|
2475
2580
|
|
|
2476
|
-
// Update
|
|
2581
|
+
// Update users of private conversation participants
|
|
2477
2582
|
const newRooms = [];
|
|
2478
2583
|
this.list.items.forEach(room => {
|
|
2479
|
-
if (room.
|
|
2584
|
+
if (room.participants?.some(participant => participant.user.id === ev.user.id)) {
|
|
2480
2585
|
newRooms.push({
|
|
2481
2586
|
...room,
|
|
2482
|
-
|
|
2587
|
+
participants: room.participants.map(participant => participant.user.id === ev.user.id ? {
|
|
2588
|
+
...participant,
|
|
2589
|
+
user: ev.user
|
|
2590
|
+
} : participant),
|
|
2591
|
+
recipients: room.recipients?.map(user => user.id === ev.user.id ? ev.user : user) ?? null
|
|
2483
2592
|
});
|
|
2484
2593
|
}
|
|
2485
2594
|
});
|
|
@@ -2531,38 +2640,6 @@ class RoomsManager {
|
|
|
2531
2640
|
}
|
|
2532
2641
|
}
|
|
2533
2642
|
}
|
|
2534
|
-
;// ./src/state-tracker/functions.ts
|
|
2535
|
-
/**
|
|
2536
|
-
* @return New objects of the other roles whose priority has to move; the given roles are left intact.
|
|
2537
|
-
*/
|
|
2538
|
-
function reorderRolesOnPriorityUpdate(allRoles, oldRole, updatedRole) {
|
|
2539
|
-
// If the priority has changed, adjust the rest of roles
|
|
2540
|
-
const increased = updatedRole.priority - oldRole.priority > 0;
|
|
2541
|
-
const decreased = !increased;
|
|
2542
|
-
const changedRoles = [];
|
|
2543
|
-
allRoles.forEach(role => {
|
|
2544
|
-
if (role.id === updatedRole.id) {
|
|
2545
|
-
// Skip the updated role
|
|
2546
|
-
return;
|
|
2547
|
-
}
|
|
2548
|
-
if (increased && oldRole.priority <= role.priority) {
|
|
2549
|
-
changedRoles.push({
|
|
2550
|
-
...role,
|
|
2551
|
-
priority: role.priority - 1
|
|
2552
|
-
});
|
|
2553
|
-
}
|
|
2554
|
-
if (decreased && updatedRole.priority <= role.priority) {
|
|
2555
|
-
changedRoles.push({
|
|
2556
|
-
...role,
|
|
2557
|
-
priority: role.priority + 1
|
|
2558
|
-
});
|
|
2559
|
-
}
|
|
2560
|
-
});
|
|
2561
|
-
return changedRoles;
|
|
2562
|
-
}
|
|
2563
|
-
function extractUserFromMember(member) {
|
|
2564
|
-
return member.user ?? member.spaceMember?.user;
|
|
2565
|
-
}
|
|
2566
2643
|
;// ./src/state-tracker/SpacesManager.ts
|
|
2567
2644
|
|
|
2568
2645
|
|
|
@@ -3015,6 +3092,10 @@ class Permissions {
|
|
|
3015
3092
|
SearchMessages: {
|
|
3016
3093
|
value: 1 << 25,
|
|
3017
3094
|
maxLayer: Layer.Room
|
|
3095
|
+
},
|
|
3096
|
+
UseExternalEmoticons: {
|
|
3097
|
+
value: 1 << 26,
|
|
3098
|
+
maxLayer: Layer.Room
|
|
3018
3099
|
}
|
|
3019
3100
|
};
|
|
3020
3101
|
static getNames() {
|
|
@@ -3308,7 +3389,6 @@ class PermissionsManager extends EventTarget {
|
|
|
3308
3389
|
;// ./src/state-tracker/EmoticonsManager.ts
|
|
3309
3390
|
|
|
3310
3391
|
|
|
3311
|
-
const GLOBAL_KEY = 'global';
|
|
3312
3392
|
class EmoticonsManager {
|
|
3313
3393
|
list = new IndexedCollection();
|
|
3314
3394
|
emoticonsPromises = new PromiseRegistry();
|
|
@@ -3321,8 +3401,7 @@ class EmoticonsManager {
|
|
|
3321
3401
|
this.tracker.client.on('Session', () => this.handleSession());
|
|
3322
3402
|
}
|
|
3323
3403
|
async get(spaceId) {
|
|
3324
|
-
|
|
3325
|
-
if (this.emoticonsPromises.notExist(key)) {
|
|
3404
|
+
if (this.emoticonsPromises.notExist(spaceId)) {
|
|
3326
3405
|
this.emoticonsPromises.registerByFunction(async () => {
|
|
3327
3406
|
const result = await this.tracker.client.send('GetEmoticons', {
|
|
3328
3407
|
spaceId
|
|
@@ -3331,10 +3410,10 @@ class EmoticonsManager {
|
|
|
3331
3410
|
throw result.error;
|
|
3332
3411
|
}
|
|
3333
3412
|
this.handleEmoticons(result.data);
|
|
3334
|
-
},
|
|
3413
|
+
}, spaceId);
|
|
3335
3414
|
}
|
|
3336
|
-
await this.emoticonsPromises.get(
|
|
3337
|
-
return this.list.get(
|
|
3415
|
+
await this.emoticonsPromises.get(spaceId);
|
|
3416
|
+
return this.list.get(spaceId);
|
|
3338
3417
|
}
|
|
3339
3418
|
|
|
3340
3419
|
/**
|
|
@@ -3342,8 +3421,8 @@ class EmoticonsManager {
|
|
|
3342
3421
|
* @internal
|
|
3343
3422
|
*/
|
|
3344
3423
|
_exportEmoticons() {
|
|
3345
|
-
return Array.from(this.list.items).map(([
|
|
3346
|
-
spaceId
|
|
3424
|
+
return Array.from(this.list.items).map(([spaceId, emoticons]) => ({
|
|
3425
|
+
spaceId,
|
|
3347
3426
|
emoticons: emoticons.items
|
|
3348
3427
|
}));
|
|
3349
3428
|
}
|
|
@@ -3358,17 +3437,19 @@ class EmoticonsManager {
|
|
|
3358
3437
|
spaceId,
|
|
3359
3438
|
emoticons
|
|
3360
3439
|
} of snapshots) {
|
|
3361
|
-
|
|
3440
|
+
// TODO(emoticons-compat): snapshots written before the global emoticons were gone still hold them under
|
|
3441
|
+
// null - drop the comment once no such snapshot can be left on a device (the check itself stays).
|
|
3442
|
+
if (!joinedSpaceIds.has(spaceId)) {
|
|
3362
3443
|
continue;
|
|
3363
3444
|
}
|
|
3364
3445
|
this.handleEmoticons({
|
|
3365
3446
|
location: {
|
|
3366
|
-
spaceId
|
|
3447
|
+
spaceId
|
|
3367
3448
|
},
|
|
3368
3449
|
emoticons
|
|
3369
3450
|
});
|
|
3370
3451
|
// Served from the snapshot until the session invalidates it.
|
|
3371
|
-
this.emoticonsPromises.register(Promise.resolve(), spaceId
|
|
3452
|
+
this.emoticonsPromises.register(Promise.resolve(), spaceId);
|
|
3372
3453
|
}
|
|
3373
3454
|
}
|
|
3374
3455
|
|
|
@@ -3377,13 +3458,19 @@ class EmoticonsManager {
|
|
|
3377
3458
|
* @internal
|
|
3378
3459
|
*/
|
|
3379
3460
|
_forgetSpacesExcept(spaceIds) {
|
|
3380
|
-
const keptKeys = new Set(
|
|
3461
|
+
const keptKeys = new Set(spaceIds);
|
|
3381
3462
|
const removedKeys = Array.from(this.list.items.keys()).filter(key => !keptKeys.has(key));
|
|
3382
3463
|
this.list.delete(...removedKeys);
|
|
3383
3464
|
this.emoticonsPromises.forget(...removedKeys);
|
|
3384
3465
|
}
|
|
3385
3466
|
handleEmoticons(event) {
|
|
3386
|
-
|
|
3467
|
+
// A selection by ids has no location.
|
|
3468
|
+
// TODO(emoticons-compat): one without a space is the always empty list of the gone global emoticons, sent
|
|
3469
|
+
// until the server stops answering old clients that way.
|
|
3470
|
+
const spaceId = event.location?.spaceId;
|
|
3471
|
+
if (!spaceId) {
|
|
3472
|
+
return;
|
|
3473
|
+
}
|
|
3387
3474
|
if (!this.list.has(spaceId)) {
|
|
3388
3475
|
this.list.set([spaceId, new ObservableIndexedObjectCollection('id')]);
|
|
3389
3476
|
}
|
|
@@ -3394,11 +3481,11 @@ class EmoticonsManager {
|
|
|
3394
3481
|
this.list.get(spaceId).reconcile(...event.emoticons);
|
|
3395
3482
|
}
|
|
3396
3483
|
handleNewEmoticon(ev) {
|
|
3397
|
-
const collection = this.list.get(ev.emoticon.spaceId
|
|
3484
|
+
const collection = this.list.get(ev.emoticon.spaceId);
|
|
3398
3485
|
collection?.set(ev.emoticon);
|
|
3399
3486
|
}
|
|
3400
3487
|
handleEmoticonDeleted(ev) {
|
|
3401
|
-
const collection = this.list.get(ev.spaceId
|
|
3488
|
+
const collection = this.list.get(ev.spaceId);
|
|
3402
3489
|
collection?.delete(ev.emoticonId);
|
|
3403
3490
|
}
|
|
3404
3491
|
handleSpaceDeleted(event) {
|
|
@@ -3428,6 +3515,9 @@ class UsersManager {
|
|
|
3428
3515
|
tracker.client.on('RoomMembers', event => this.handleMembers(event.members));
|
|
3429
3516
|
tracker.client.on('Messages', event => this.handleUsers(event.messages.map(message => message.author.user)));
|
|
3430
3517
|
tracker.client.on('NewMessage', event => this.handleUsers([event.message.author.user]));
|
|
3518
|
+
tracker.client.on('RoomJoined', event => this.handleRooms([event.room]));
|
|
3519
|
+
tracker.client.on('RoomUpdated', event => this.handleRooms([event.room]));
|
|
3520
|
+
tracker.client.on('IgnoredRooms', event => this.handleRooms(event.rooms));
|
|
3431
3521
|
tracker.client.on('Session', event => this.handleSession(event));
|
|
3432
3522
|
}
|
|
3433
3523
|
|
|
@@ -3445,14 +3535,31 @@ class UsersManager {
|
|
|
3445
3535
|
_importUser(user) {
|
|
3446
3536
|
this.handleUsers([user]);
|
|
3447
3537
|
}
|
|
3538
|
+
|
|
3539
|
+
/**
|
|
3540
|
+
* For internal use.
|
|
3541
|
+
* @internal
|
|
3542
|
+
*/
|
|
3543
|
+
_importRooms(rooms) {
|
|
3544
|
+
this.handleRooms(rooms);
|
|
3545
|
+
}
|
|
3448
3546
|
handleMembers(members) {
|
|
3449
3547
|
this.handleUsers(members.map(extractUserFromMember));
|
|
3450
3548
|
}
|
|
3549
|
+
handleRooms(rooms) {
|
|
3550
|
+
const users = new Map();
|
|
3551
|
+
for (const room of rooms) {
|
|
3552
|
+
for (const participant of room.participants ?? []) {
|
|
3553
|
+
users.set(participant.user.id, participant.user);
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
this.handleUsers([...users.values()]);
|
|
3557
|
+
}
|
|
3451
3558
|
handleSession(session) {
|
|
3452
3559
|
// Keep the "seen users" cache across reconnects so bound user lists do
|
|
3453
|
-
// not blank out
|
|
3454
|
-
// entries are refreshed as member/message collections refetch.
|
|
3560
|
+
// not blank out. Stale entries are refreshed as member/message collections refetch.
|
|
3455
3561
|
this.handleUsers([session.user]);
|
|
3562
|
+
this.handleRooms(session.state.rooms);
|
|
3456
3563
|
}
|
|
3457
3564
|
|
|
3458
3565
|
/**
|
|
@@ -3474,20 +3581,6 @@ class UsersManager {
|
|
|
3474
3581
|
this.users.set(...changedUsers);
|
|
3475
3582
|
}
|
|
3476
3583
|
}
|
|
3477
|
-
function isSameUser(a, b) {
|
|
3478
|
-
const keys = Object.keys(a);
|
|
3479
|
-
if (keys.length !== Object.keys(b).length) {
|
|
3480
|
-
return false;
|
|
3481
|
-
}
|
|
3482
|
-
return keys.every(key => {
|
|
3483
|
-
const valueA = a[key];
|
|
3484
|
-
const valueB = b[key];
|
|
3485
|
-
if (Array.isArray(valueA) && Array.isArray(valueB)) {
|
|
3486
|
-
return valueA.length === valueB.length && valueA.every((item, index) => item === valueB[index]);
|
|
3487
|
-
}
|
|
3488
|
-
return valueA === valueB;
|
|
3489
|
-
});
|
|
3490
|
-
}
|
|
3491
3584
|
;// ./src/state-tracker/RelationshipsManager.ts
|
|
3492
3585
|
|
|
3493
3586
|
|
|
@@ -3683,6 +3776,7 @@ class ChatStateTracker {
|
|
|
3683
3776
|
try {
|
|
3684
3777
|
this._me = snapshot.user;
|
|
3685
3778
|
this.users._importUser(snapshot.user);
|
|
3779
|
+
this.users._importRooms(snapshot.rooms);
|
|
3686
3780
|
this.rooms._importRooms(snapshot.rooms);
|
|
3687
3781
|
this.spaces._importSpaces(snapshot.spaces, snapshot.spaceRooms);
|
|
3688
3782
|
this.rooms.followedTopics._importFollowedTopics(snapshot.followedTopics);
|
|
@@ -4196,6 +4290,7 @@ let ErrorCode = /*#__PURE__*/function (ErrorCode) {
|
|
|
4196
4290
|
ErrorCode["InvalidSearchQuery"] = "InvalidSearchQueryException";
|
|
4197
4291
|
ErrorCode["MessageSearchUnavailable"] = "MessageSearchUnavailableException";
|
|
4198
4292
|
ErrorCode["MessageNotFound"] = "MessageNotFoundException";
|
|
4293
|
+
ErrorCode["RoomIgnored"] = "RoomIgnoredException";
|
|
4199
4294
|
ErrorCode["RoomNotFound"] = "RoomNotFoundException";
|
|
4200
4295
|
ErrorCode["TopicNotFound"] = "TopicNotFoundException";
|
|
4201
4296
|
ErrorCode["UserNotFound"] = "UserNotFoundException";
|
|
@@ -4281,6 +4376,7 @@ let UserFeature = /*#__PURE__*/function (UserFeature) {
|
|
|
4281
4376
|
UserFeature["MessageLength"] = "user.message.length";
|
|
4282
4377
|
UserFeature["StorageLimit"] = "user.storage.limit";
|
|
4283
4378
|
UserFeature["StorageSingleFileLimit"] = "user.storage.single_file_limit";
|
|
4379
|
+
UserFeature["ExternalEmoticons"] = "user.external_emoticons";
|
|
4284
4380
|
return UserFeature;
|
|
4285
4381
|
}({});
|
|
4286
4382
|
|
|
@@ -4333,6 +4429,6 @@ let SpaceIntent = /*#__PURE__*/function (SpaceIntent) {
|
|
|
4333
4429
|
|
|
4334
4430
|
|
|
4335
4431
|
|
|
4336
|
-
export { AbstractRestClient, ErrorCode, FilesClient, HistoryRotation, IndexedCollection, IndexedObjectCollection, Layer, NO_LIMIT, ObservableIndexedCollection, ObservableIndexedObjectCollection, PermissionDefinition, Permissions, RoleFlag, STATE_SNAPSHOT_VERSION, STORAGE_UNIT_BYTES, SearchRange, SpaceFeature, SpaceIntent, UiPurpose, UserFeature, UserStatus, WebApiChatClient, WebSocketChatClient, extractUserFromMember };
|
|
4432
|
+
export { AbstractRestClient, ErrorCode, FilesClient, HistoryRotation, IndexedCollection, IndexedObjectCollection, Layer, NO_LIMIT, ObservableIndexedCollection, ObservableIndexedObjectCollection, PermissionDefinition, Permissions, PmParticipantFlag, RoleFlag, STATE_SNAPSHOT_VERSION, STORAGE_UNIT_BYTES, SearchRange, SpaceFeature, SpaceIntent, UiPurpose, UserFeature, UserStatus, WebApiChatClient, WebSocketChatClient, extractUserFromMember, getPmPeers, isGroupPm };
|
|
4337
4433
|
|
|
4338
4434
|
//# sourceMappingURL=index.mjs.map
|