@devanachat/sdk 0.9.0 → 0.11.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 +67 -0
- package/build/index.cjs.js +322 -105
- package/build/index.cjs.js.map +1 -1
- package/build/index.mjs +317 -105
- 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 +5 -1
- package/build/types/Permissions.d.ts +8 -0
- package/build/types/index.d.ts +5 -4
- package/build/types/protocol/index.d.ts +9 -4
- 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/Role.d.ts +6 -0
- package/build/types/protocol/schemes/Room.d.ts +3 -0
- package/build/types/protocol/schemes/Space.d.ts +1 -0
- package/build/types/protocol/schemes/Topic.d.ts +1 -0
- package/build/types/protocol/schemes/commands/CreateMessage.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/commands/Type.d.ts +4 -0
- package/build/types/protocol/schemes/commands/UpdateRole.d.ts +2 -0
- package/build/types/protocol/schemes/commands/UpdateSpace.d.ts +1 -0
- package/build/types/protocol/schemes/commands/UpdateTopic.d.ts +1 -0
- package/build/types/protocol/schemes/events/Error.d.ts +7 -0
- package/build/types/protocol/schemes/events/IgnoredRooms.d.ts +4 -0
- package/build/types/protocol/schemes/events/NewMessage.d.ts +1 -0
- package/build/types/protocol/schemes/events/Typing.d.ts +5 -0
- package/build/types/state-tracker/PermissionsManager.d.ts +1 -1
- package/build/types/state-tracker/RoomsManager.d.ts +4 -1
- package/build/types/state-tracker/StateSnapshot.d.ts +1 -1
- package/build/types/state-tracker/TypingManager.d.ts +35 -0
- 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.cjs.js
CHANGED
|
@@ -51,18 +51,23 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
51
51
|
ObservableIndexedObjectCollection: () => (/* reexport */ ObservableIndexedObjectCollection),
|
|
52
52
|
PermissionDefinition: () => (/* reexport */ PermissionDefinition),
|
|
53
53
|
Permissions: () => (/* reexport */ Permissions),
|
|
54
|
+
PmParticipantFlag: () => (/* reexport */ PmParticipantFlag),
|
|
54
55
|
RoleFlag: () => (/* reexport */ RoleFlag),
|
|
55
56
|
STATE_SNAPSHOT_VERSION: () => (/* reexport */ STATE_SNAPSHOT_VERSION),
|
|
56
57
|
STORAGE_UNIT_BYTES: () => (/* reexport */ STORAGE_UNIT_BYTES),
|
|
57
58
|
SearchRange: () => (/* reexport */ SearchRange),
|
|
58
59
|
SpaceFeature: () => (/* reexport */ SpaceFeature),
|
|
59
60
|
SpaceIntent: () => (/* reexport */ SpaceIntent),
|
|
61
|
+
TYPING_INTERVAL_MS: () => (/* reexport */ TYPING_INTERVAL_MS),
|
|
62
|
+
TYPING_TIMEOUT_MS: () => (/* reexport */ TYPING_TIMEOUT_MS),
|
|
60
63
|
UiPurpose: () => (/* reexport */ UiPurpose),
|
|
61
64
|
UserFeature: () => (/* reexport */ UserFeature),
|
|
62
65
|
UserStatus: () => (/* reexport */ UserStatus),
|
|
63
66
|
WebApiChatClient: () => (/* reexport */ WebApiChatClient),
|
|
64
67
|
WebSocketChatClient: () => (/* reexport */ WebSocketChatClient),
|
|
65
|
-
extractUserFromMember: () => (/* reexport */ extractUserFromMember)
|
|
68
|
+
extractUserFromMember: () => (/* reexport */ extractUserFromMember),
|
|
69
|
+
getPmPeers: () => (/* reexport */ getPmPeers),
|
|
70
|
+
isGroupPm: () => (/* reexport */ isGroupPm)
|
|
66
71
|
});
|
|
67
72
|
|
|
68
73
|
;// ./src/EventTarget.ts
|
|
@@ -1925,6 +1930,129 @@ class FollowedTopicsManager extends EventTarget {
|
|
|
1925
1930
|
this.invalidateUnreadSummaries(roomId);
|
|
1926
1931
|
}
|
|
1927
1932
|
}
|
|
1933
|
+
;// ./src/state-tracker/TypingManager.ts
|
|
1934
|
+
|
|
1935
|
+
const TYPING_INTERVAL_MS = 5000;
|
|
1936
|
+
const TYPING_TIMEOUT_MS = 2 * TYPING_INTERVAL_MS;
|
|
1937
|
+
|
|
1938
|
+
/**
|
|
1939
|
+
* Ids of the users typing in a topic, each mapped to the time (`Date.now()`) its typing expires at.
|
|
1940
|
+
*/
|
|
1941
|
+
|
|
1942
|
+
class TypingManager {
|
|
1943
|
+
topics = new IndexedCollection();
|
|
1944
|
+
lastSentAt = new Map();
|
|
1945
|
+
constructor(tracker) {
|
|
1946
|
+
this.tracker = tracker;
|
|
1947
|
+
this.tracker.client.on('Typing', ev => this.handleTyping(ev));
|
|
1948
|
+
this.tracker.client.on('NewMessage', ev => this.handleNewMessage(ev));
|
|
1949
|
+
this.tracker.client.on('TopicDeleted', ev => this.handleTopicDeleted(ev));
|
|
1950
|
+
this.tracker.client.on('RoomLeft', ev => this.handleRoomGone(ev));
|
|
1951
|
+
this.tracker.client.on('RoomDeleted', ev => this.handleRoomGone(ev));
|
|
1952
|
+
this.tracker.client.on('Session', () => this.handleSession());
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
/**
|
|
1956
|
+
* Users typing in the topic, without you. Tracking of the topic starts with the first call, so the collection
|
|
1957
|
+
* fills up with the next notifications, within {@link TYPING_INTERVAL_MS}. A user leaves it
|
|
1958
|
+
* {@link TYPING_TIMEOUT_MS} after their last notification or at once with their message in the topic.
|
|
1959
|
+
* Only ids are kept - resolve the users yourself, e.g. from {@link RoomsManager.getMembers}.
|
|
1960
|
+
*/
|
|
1961
|
+
get(roomId, topicId) {
|
|
1962
|
+
if (!this.topics.has(topicId)) {
|
|
1963
|
+
this.topics.set([topicId, {
|
|
1964
|
+
roomId,
|
|
1965
|
+
users: new ObservableIndexedCollection()
|
|
1966
|
+
}]);
|
|
1967
|
+
}
|
|
1968
|
+
return this.topics.get(topicId).users;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
/**
|
|
1972
|
+
* Tell the other members of the room that you are typing in the topic. Call it on every change of the text:
|
|
1973
|
+
* the command is sent at most once per {@link TYPING_INTERVAL_MS} for a topic, and again right after your
|
|
1974
|
+
* message in it. Classic rooms do not support typing.
|
|
1975
|
+
*/
|
|
1976
|
+
notify(roomId, topicId) {
|
|
1977
|
+
const now = Date.now();
|
|
1978
|
+
if (now - (this.lastSentAt.get(topicId) ?? -Infinity) < TYPING_INTERVAL_MS) {
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
this.lastSentAt.set(topicId, now);
|
|
1982
|
+
this.tracker.client.send('Type', {
|
|
1983
|
+
location: {
|
|
1984
|
+
roomId,
|
|
1985
|
+
topicId
|
|
1986
|
+
}
|
|
1987
|
+
}).catch(() => undefined);
|
|
1988
|
+
}
|
|
1989
|
+
handleTyping(ev) {
|
|
1990
|
+
const topic = this.topics.get(ev.location.topicId);
|
|
1991
|
+
if (!topic || ev.userId === this.tracker.me?.id) {
|
|
1992
|
+
return;
|
|
1993
|
+
}
|
|
1994
|
+
topic.users.set([ev.userId, Date.now() + TYPING_TIMEOUT_MS]);
|
|
1995
|
+
this.scheduleExpiry(topic);
|
|
1996
|
+
}
|
|
1997
|
+
handleNewMessage(ev) {
|
|
1998
|
+
const topicId = ev.message.location.topicId;
|
|
1999
|
+
const authorId = ev.message.author.user.id;
|
|
2000
|
+
if (authorId === this.tracker.me?.id) {
|
|
2001
|
+
this.lastSentAt.delete(topicId);
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
const topic = this.topics.get(topicId);
|
|
2005
|
+
if (topic?.users.has(authorId)) {
|
|
2006
|
+
topic.users.delete(authorId);
|
|
2007
|
+
this.scheduleExpiry(topic);
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
handleTopicDeleted(ev) {
|
|
2011
|
+
this.clear(ev.location.topicId);
|
|
2012
|
+
}
|
|
2013
|
+
handleRoomGone(ev) {
|
|
2014
|
+
for (const [topicId, topic] of this.topics.items.entries()) {
|
|
2015
|
+
if (topic.roomId === ev.id) {
|
|
2016
|
+
this.clear(topicId);
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
handleSession() {
|
|
2021
|
+
this.lastSentAt.clear();
|
|
2022
|
+
for (const topic of this.topics.items.values()) {
|
|
2023
|
+
clearTimeout(topic.timer);
|
|
2024
|
+
topic.users.deleteAll();
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
clear(topicId) {
|
|
2028
|
+
const topic = this.topics.get(topicId);
|
|
2029
|
+
if (topic) {
|
|
2030
|
+
clearTimeout(topic.timer);
|
|
2031
|
+
topic.users.deleteAll();
|
|
2032
|
+
}
|
|
2033
|
+
this.lastSentAt.delete(topicId);
|
|
2034
|
+
}
|
|
2035
|
+
scheduleExpiry(topic) {
|
|
2036
|
+
clearTimeout(topic.timer);
|
|
2037
|
+
topic.timer = undefined;
|
|
2038
|
+
if (!topic.users.length) {
|
|
2039
|
+
return;
|
|
2040
|
+
}
|
|
2041
|
+
const nextExpiry = Math.min(...topic.users.items.values());
|
|
2042
|
+
topic.timer = setTimeout(() => this.expire(topic), Math.max(0, nextExpiry - Date.now()));
|
|
2043
|
+
}
|
|
2044
|
+
expire(topic) {
|
|
2045
|
+
const now = Date.now();
|
|
2046
|
+
const expiredIds = [];
|
|
2047
|
+
for (const [userId, expiresAt] of topic.users.items.entries()) {
|
|
2048
|
+
if (expiresAt <= now) {
|
|
2049
|
+
expiredIds.push(userId);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
topic.users.delete(...expiredIds);
|
|
2053
|
+
this.scheduleExpiry(topic);
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
1928
2056
|
;// ./src/protocol/schemes/User.ts
|
|
1929
2057
|
/**
|
|
1930
2058
|
* Availability of a user, aggregated over all of their sessions.
|
|
@@ -1946,7 +2074,7 @@ let UserStatus = /*#__PURE__*/function (UserStatus) {
|
|
|
1946
2074
|
/**
|
|
1947
2075
|
* Version of the {@link StateSnapshot} format. A snapshot of any other version is rejected on import.
|
|
1948
2076
|
*/
|
|
1949
|
-
const STATE_SNAPSHOT_VERSION =
|
|
2077
|
+
const STATE_SNAPSHOT_VERSION = 2;
|
|
1950
2078
|
|
|
1951
2079
|
/**
|
|
1952
2080
|
* Plain, JSON-serializable copy of the state tracked by {@link ChatStateTracker}, made to restore the state at the
|
|
@@ -2016,6 +2144,9 @@ function hasId(value) {
|
|
|
2016
2144
|
function isUser(value) {
|
|
2017
2145
|
return hasId(value);
|
|
2018
2146
|
}
|
|
2147
|
+
function isPmParticipant(value) {
|
|
2148
|
+
return isObject(value) && isUser(value.user) && typeof value.flags === 'number';
|
|
2149
|
+
}
|
|
2019
2150
|
function isRole(value) {
|
|
2020
2151
|
return hasId(value) && typeof value.priority === 'number';
|
|
2021
2152
|
}
|
|
@@ -2032,7 +2163,7 @@ function isFullMessage(value) {
|
|
|
2032
2163
|
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);
|
|
2033
2164
|
}
|
|
2034
2165
|
function isRoom(value) {
|
|
2035
|
-
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);
|
|
2166
|
+
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);
|
|
2036
2167
|
}
|
|
2037
2168
|
function isSpaceRooms(value) {
|
|
2038
2169
|
return isObject(value) && isString(value.spaceId) && isArrayOf(value.summaries, hasId);
|
|
@@ -2061,15 +2192,89 @@ function isRoomMember(value) {
|
|
|
2061
2192
|
function isRoomMembers(value) {
|
|
2062
2193
|
return isObject(value) && isString(value.roomId) && isArrayOf(value.members, isRoomMember);
|
|
2063
2194
|
}
|
|
2195
|
+
;// ./src/protocol/schemes/PmParticipant.ts
|
|
2196
|
+
let PmParticipantFlag = /*#__PURE__*/function (PmParticipantFlag) {
|
|
2197
|
+
PmParticipantFlag[PmParticipantFlag["IgnoresRoom"] = 1] = "IgnoresRoom";
|
|
2198
|
+
return PmParticipantFlag;
|
|
2199
|
+
}({});
|
|
2200
|
+
;// ./src/state-tracker/functions.ts
|
|
2201
|
+
|
|
2202
|
+
|
|
2203
|
+
/**
|
|
2204
|
+
* @return New objects of the other roles whose priority has to move; the given roles are left intact.
|
|
2205
|
+
*/
|
|
2206
|
+
function reorderRolesOnPriorityUpdate(allRoles, oldRole, updatedRole) {
|
|
2207
|
+
// If the priority has changed, adjust the rest of roles
|
|
2208
|
+
const increased = updatedRole.priority - oldRole.priority > 0;
|
|
2209
|
+
const decreased = !increased;
|
|
2210
|
+
const changedRoles = [];
|
|
2211
|
+
allRoles.forEach(role => {
|
|
2212
|
+
if (role.id === updatedRole.id) {
|
|
2213
|
+
// Skip the updated role
|
|
2214
|
+
return;
|
|
2215
|
+
}
|
|
2216
|
+
if (increased && oldRole.priority <= role.priority) {
|
|
2217
|
+
changedRoles.push({
|
|
2218
|
+
...role,
|
|
2219
|
+
priority: role.priority - 1
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
if (decreased && updatedRole.priority <= role.priority) {
|
|
2223
|
+
changedRoles.push({
|
|
2224
|
+
...role,
|
|
2225
|
+
priority: role.priority + 1
|
|
2226
|
+
});
|
|
2227
|
+
}
|
|
2228
|
+
});
|
|
2229
|
+
return changedRoles;
|
|
2230
|
+
}
|
|
2231
|
+
function extractUserFromMember(member) {
|
|
2232
|
+
return member.user ?? member.spaceMember?.user;
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
/**
|
|
2236
|
+
* Whether the room is a private group conversation - 3 or more participants, including the ones ignoring it.
|
|
2237
|
+
*/
|
|
2238
|
+
function isGroupPm(room) {
|
|
2239
|
+
return room.type === 'Pm' && (room.participants?.length ?? 0) >= 3;
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
/**
|
|
2243
|
+
* Participants of a private conversation taking part in it: without the ones ignoring it and without the user
|
|
2244
|
+
* `meId`. Empty for notes and for rooms of spaces.
|
|
2245
|
+
*/
|
|
2246
|
+
function getPmPeers(room, meId) {
|
|
2247
|
+
return getActivePmParticipants(room).filter(participant => participant.user.id !== meId);
|
|
2248
|
+
}
|
|
2249
|
+
function getActivePmParticipants(room) {
|
|
2250
|
+
return (room.participants ?? []).filter(participant => !(participant.flags & PmParticipantFlag.IgnoresRoom));
|
|
2251
|
+
}
|
|
2252
|
+
function isSameUser(a, b) {
|
|
2253
|
+
const keys = Object.keys(a);
|
|
2254
|
+
if (keys.length !== Object.keys(b).length) {
|
|
2255
|
+
return false;
|
|
2256
|
+
}
|
|
2257
|
+
return keys.every(key => {
|
|
2258
|
+
const valueA = a[key];
|
|
2259
|
+
const valueB = b[key];
|
|
2260
|
+
if (Array.isArray(valueA) && Array.isArray(valueB)) {
|
|
2261
|
+
return valueA.length === valueB.length && valueA.every((item, index) => item === valueB[index]);
|
|
2262
|
+
}
|
|
2263
|
+
return valueA === valueB;
|
|
2264
|
+
});
|
|
2265
|
+
}
|
|
2064
2266
|
;// ./src/state-tracker/RoomsManager.ts
|
|
2065
2267
|
|
|
2066
2268
|
|
|
2067
2269
|
|
|
2068
2270
|
|
|
2069
2271
|
|
|
2272
|
+
|
|
2273
|
+
|
|
2070
2274
|
class RoomsManager {
|
|
2071
2275
|
messages;
|
|
2072
2276
|
followedTopics;
|
|
2277
|
+
typing;
|
|
2073
2278
|
list = new ObservableIndexedObjectCollection('id');
|
|
2074
2279
|
topics = new IndexedCollection();
|
|
2075
2280
|
members = new IndexedCollection();
|
|
@@ -2081,6 +2286,7 @@ class RoomsManager {
|
|
|
2081
2286
|
this.tracker = tracker;
|
|
2082
2287
|
this.messages = new MessagesManager(tracker);
|
|
2083
2288
|
this.followedTopics = new FollowedTopicsManager(tracker);
|
|
2289
|
+
this.typing = new TypingManager(tracker);
|
|
2084
2290
|
this.tracker.client.on('NewMessage', ev => this.handleNewMessage(ev));
|
|
2085
2291
|
this.tracker.client.on('MessagesRedacted', ev => this.handleMessagesRedacted(ev));
|
|
2086
2292
|
this.tracker.client.on('NewTopic', ev => this.handleNewTopic(ev));
|
|
@@ -2195,9 +2401,13 @@ class RoomsManager {
|
|
|
2195
2401
|
* @internal
|
|
2196
2402
|
*/
|
|
2197
2403
|
_exportRooms() {
|
|
2198
|
-
return this.list.items.map(room => room.
|
|
2404
|
+
return this.list.items.map(room => room.participants ? {
|
|
2199
2405
|
...room,
|
|
2200
|
-
|
|
2406
|
+
participants: room.participants.map(participant => ({
|
|
2407
|
+
...participant,
|
|
2408
|
+
user: withoutPresence(participant.user)
|
|
2409
|
+
})),
|
|
2410
|
+
recipients: room.recipients?.map(withoutPresence) ?? null
|
|
2201
2411
|
} : room);
|
|
2202
2412
|
}
|
|
2203
2413
|
|
|
@@ -2249,7 +2459,7 @@ class RoomsManager {
|
|
|
2249
2459
|
}
|
|
2250
2460
|
|
|
2251
2461
|
/**
|
|
2252
|
-
* Members of private conversations are not exported - they are made of the
|
|
2462
|
+
* Members of private conversations are not exported - they are made of the participants of the room.
|
|
2253
2463
|
* @internal
|
|
2254
2464
|
*/
|
|
2255
2465
|
_exportMembers(roomIds, limit) {
|
|
@@ -2375,6 +2585,9 @@ class RoomsManager {
|
|
|
2375
2585
|
}
|
|
2376
2586
|
const members = this.members.get(ev.roomId);
|
|
2377
2587
|
const member = members.get(ev.userId);
|
|
2588
|
+
if (!member) {
|
|
2589
|
+
return;
|
|
2590
|
+
}
|
|
2378
2591
|
const user = member.spaceMember?.user ?? member.user;
|
|
2379
2592
|
|
|
2380
2593
|
// Preserving user object, because it's not included in event
|
|
@@ -2419,6 +2632,7 @@ class RoomsManager {
|
|
|
2419
2632
|
handleRoomUpdated(ev) {
|
|
2420
2633
|
if (this.list.has(ev.room.id)) {
|
|
2421
2634
|
this.list.set(ev.room);
|
|
2635
|
+
this.setPmMembers(ev.room);
|
|
2422
2636
|
}
|
|
2423
2637
|
}
|
|
2424
2638
|
handleRoomDeleted(ev) {
|
|
@@ -2442,27 +2656,40 @@ class RoomsManager {
|
|
|
2442
2656
|
if (room.defaultTopic) {
|
|
2443
2657
|
this.addJoinedRoomTopics(room.id, room.defaultTopic);
|
|
2444
2658
|
}
|
|
2445
|
-
|
|
2446
|
-
// Treat PM recipients as normal room members.
|
|
2447
|
-
// We are registering fake promise in `memberPromises`
|
|
2448
|
-
// because GetMembers are not supported for PM rooms.
|
|
2449
|
-
this.handleRoomMembers({
|
|
2450
|
-
id: room.id,
|
|
2451
|
-
members: room.recipients.map(user => ({
|
|
2452
|
-
user,
|
|
2453
|
-
spaceMember: null,
|
|
2454
|
-
roles: null,
|
|
2455
|
-
customColor: null,
|
|
2456
|
-
customNick: null,
|
|
2457
|
-
customAvatar: null,
|
|
2458
|
-
extras: ''
|
|
2459
|
-
}))
|
|
2460
|
-
});
|
|
2461
|
-
this.membersPromises.register(Promise.resolve(), room.id);
|
|
2462
|
-
}
|
|
2659
|
+
this.setPmMembers(room);
|
|
2463
2660
|
}
|
|
2464
2661
|
this.list.set(...rooms);
|
|
2465
2662
|
}
|
|
2663
|
+
setPmMembers(room) {
|
|
2664
|
+
if (room.type !== 'Pm' || !room.participants) {
|
|
2665
|
+
return;
|
|
2666
|
+
}
|
|
2667
|
+
const current = this.members.get(room.id);
|
|
2668
|
+
const members = getActivePmParticipants(room).map(({
|
|
2669
|
+
user
|
|
2670
|
+
}) => {
|
|
2671
|
+
const member = current?.get(user.id);
|
|
2672
|
+
return member && isSameUser(member.user, user) ? member : {
|
|
2673
|
+
user,
|
|
2674
|
+
spaceMember: null,
|
|
2675
|
+
roles: null,
|
|
2676
|
+
customColor: null,
|
|
2677
|
+
customNick: null,
|
|
2678
|
+
customAvatar: null,
|
|
2679
|
+
extras: ''
|
|
2680
|
+
};
|
|
2681
|
+
});
|
|
2682
|
+
|
|
2683
|
+
// GetRoomMembers is not supported for private conversations
|
|
2684
|
+
this.membersPromises.register(Promise.resolve(), room.id);
|
|
2685
|
+
if (current?.length === members.length && members.every(member => current.get(member.user.id) === member)) {
|
|
2686
|
+
return;
|
|
2687
|
+
}
|
|
2688
|
+
this.handleRoomMembers({
|
|
2689
|
+
id: room.id,
|
|
2690
|
+
members
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2466
2693
|
handleRoomLeft(ev) {
|
|
2467
2694
|
this.deleteRoom(ev.id);
|
|
2468
2695
|
}
|
|
@@ -2526,13 +2753,17 @@ class RoomsManager {
|
|
|
2526
2753
|
});
|
|
2527
2754
|
});
|
|
2528
2755
|
|
|
2529
|
-
// Update
|
|
2756
|
+
// Update users of private conversation participants
|
|
2530
2757
|
const newRooms = [];
|
|
2531
2758
|
this.list.items.forEach(room => {
|
|
2532
|
-
if (room.
|
|
2759
|
+
if (room.participants?.some(participant => participant.user.id === ev.user.id)) {
|
|
2533
2760
|
newRooms.push({
|
|
2534
2761
|
...room,
|
|
2535
|
-
|
|
2762
|
+
participants: room.participants.map(participant => participant.user.id === ev.user.id ? {
|
|
2763
|
+
...participant,
|
|
2764
|
+
user: ev.user
|
|
2765
|
+
} : participant),
|
|
2766
|
+
recipients: room.recipients?.map(user => user.id === ev.user.id ? ev.user : user) ?? null
|
|
2536
2767
|
});
|
|
2537
2768
|
}
|
|
2538
2769
|
});
|
|
@@ -2547,7 +2778,8 @@ class RoomsManager {
|
|
|
2547
2778
|
const newTopic = {
|
|
2548
2779
|
...topic,
|
|
2549
2780
|
messageCount: topic.messageCount + 1,
|
|
2550
|
-
lastMessage: ev.message
|
|
2781
|
+
lastMessage: ev.message,
|
|
2782
|
+
stickyMessage: ev.sticky ? ev.message : topic.stickyMessage
|
|
2551
2783
|
};
|
|
2552
2784
|
topics.set(newTopic);
|
|
2553
2785
|
this.updatePmDefaultTopic(ev.message.location.roomId, newTopic);
|
|
@@ -2559,10 +2791,14 @@ class RoomsManager {
|
|
|
2559
2791
|
if (topic) {
|
|
2560
2792
|
const messageCount = Math.max(topic.messageCount - ev.ids.length, 0);
|
|
2561
2793
|
const lastMessage = messageCount > 0 ? await this.messages._resolveLastMessage(ev.location) : null;
|
|
2794
|
+
// Read after the await - a message stuck meanwhile must not be replaced with the stale one
|
|
2795
|
+
const currentSticky = (topics.get(ev.location.topicId) ?? topic).stickyMessage;
|
|
2796
|
+
const stickyMessage = ev.ids.includes(currentSticky?.id) ? null : currentSticky;
|
|
2562
2797
|
const newTopic = {
|
|
2563
2798
|
...topic,
|
|
2564
2799
|
messageCount,
|
|
2565
|
-
lastMessage
|
|
2800
|
+
lastMessage,
|
|
2801
|
+
stickyMessage
|
|
2566
2802
|
};
|
|
2567
2803
|
topics.set(newTopic);
|
|
2568
2804
|
this.updatePmDefaultTopic(ev.location.roomId, newTopic);
|
|
@@ -2584,38 +2820,6 @@ class RoomsManager {
|
|
|
2584
2820
|
}
|
|
2585
2821
|
}
|
|
2586
2822
|
}
|
|
2587
|
-
;// ./src/state-tracker/functions.ts
|
|
2588
|
-
/**
|
|
2589
|
-
* @return New objects of the other roles whose priority has to move; the given roles are left intact.
|
|
2590
|
-
*/
|
|
2591
|
-
function reorderRolesOnPriorityUpdate(allRoles, oldRole, updatedRole) {
|
|
2592
|
-
// If the priority has changed, adjust the rest of roles
|
|
2593
|
-
const increased = updatedRole.priority - oldRole.priority > 0;
|
|
2594
|
-
const decreased = !increased;
|
|
2595
|
-
const changedRoles = [];
|
|
2596
|
-
allRoles.forEach(role => {
|
|
2597
|
-
if (role.id === updatedRole.id) {
|
|
2598
|
-
// Skip the updated role
|
|
2599
|
-
return;
|
|
2600
|
-
}
|
|
2601
|
-
if (increased && oldRole.priority <= role.priority) {
|
|
2602
|
-
changedRoles.push({
|
|
2603
|
-
...role,
|
|
2604
|
-
priority: role.priority - 1
|
|
2605
|
-
});
|
|
2606
|
-
}
|
|
2607
|
-
if (decreased && updatedRole.priority <= role.priority) {
|
|
2608
|
-
changedRoles.push({
|
|
2609
|
-
...role,
|
|
2610
|
-
priority: role.priority + 1
|
|
2611
|
-
});
|
|
2612
|
-
}
|
|
2613
|
-
});
|
|
2614
|
-
return changedRoles;
|
|
2615
|
-
}
|
|
2616
|
-
function extractUserFromMember(member) {
|
|
2617
|
-
return member.user ?? member.spaceMember?.user;
|
|
2618
|
-
}
|
|
2619
2823
|
;// ./src/state-tracker/SpacesManager.ts
|
|
2620
2824
|
|
|
2621
2825
|
|
|
@@ -2804,6 +3008,13 @@ class SpacesManager {
|
|
|
2804
3008
|
}
|
|
2805
3009
|
handleRoleDeleted(ev) {
|
|
2806
3010
|
this.roles.get(ev.spaceId).delete(ev.id);
|
|
3011
|
+
const space = this.list.get(ev.spaceId);
|
|
3012
|
+
if (space?.guestRole === ev.id) {
|
|
3013
|
+
this.list.set({
|
|
3014
|
+
...space,
|
|
3015
|
+
guestRole: null
|
|
3016
|
+
});
|
|
3017
|
+
}
|
|
2807
3018
|
this.syncSpaceRoles(ev.spaceId);
|
|
2808
3019
|
}
|
|
2809
3020
|
|
|
@@ -3072,6 +3283,14 @@ class Permissions {
|
|
|
3072
3283
|
UseExternalEmoticons: {
|
|
3073
3284
|
value: 1 << 26,
|
|
3074
3285
|
maxLayer: Layer.Room
|
|
3286
|
+
},
|
|
3287
|
+
ManagePins: {
|
|
3288
|
+
value: 1 << 27,
|
|
3289
|
+
maxLayer: Layer.Topic
|
|
3290
|
+
},
|
|
3291
|
+
SendAttachments: {
|
|
3292
|
+
value: 1 << 28,
|
|
3293
|
+
maxLayer: Layer.Topic
|
|
3075
3294
|
}
|
|
3076
3295
|
};
|
|
3077
3296
|
static getNames() {
|
|
@@ -3205,7 +3424,7 @@ class PermissionsManager extends EventTarget {
|
|
|
3205
3424
|
userId
|
|
3206
3425
|
}).then(v => v.overwrites));
|
|
3207
3426
|
}
|
|
3208
|
-
return this.resolveOverwritesHierarchy(await Promise.all(promises));
|
|
3427
|
+
return this.resolveOverwritesHierarchy([].concat(...(await Promise.all(promises))));
|
|
3209
3428
|
}
|
|
3210
3429
|
|
|
3211
3430
|
/**
|
|
@@ -3282,34 +3501,22 @@ class PermissionsManager extends EventTarget {
|
|
|
3282
3501
|
type: 'Role',
|
|
3283
3502
|
roleId
|
|
3284
3503
|
})));
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
const revDecAllows = overwrites.allow?.toString(2).split('').reverse().join('') ?? '';
|
|
3299
|
-
for (let i = 0; i < permissionsLength; i++) {
|
|
3300
|
-
const deny = parseInt(revDecDenies[i] ?? '0');
|
|
3301
|
-
const allow = parseInt(revDecAllows[i] ?? '0');
|
|
3302
|
-
if (deny) {
|
|
3303
|
-
denies |= 1 << i;
|
|
3304
|
-
}
|
|
3305
|
-
if (allow) {
|
|
3306
|
-
allows |= 1 << i;
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
3309
|
-
});
|
|
3504
|
+
// The space default role (everyone) has the space id; it is applied before the other roles, as on the server.
|
|
3505
|
+
const isDefaultRole = overwrites => overwrites.target.roleId === location.spaceId;
|
|
3506
|
+
return [this.mergeRolesOverwrites(roleOverwrites.filter(isDefaultRole)), this.mergeRolesOverwrites(roleOverwrites.filter(overwrites => !isDefaultRole(overwrites)))];
|
|
3507
|
+
}
|
|
3508
|
+
mergeRolesOverwrites(rolesOverwrites) {
|
|
3509
|
+
let allow = 0,
|
|
3510
|
+
deny = 0;
|
|
3511
|
+
for (const {
|
|
3512
|
+
overwrites
|
|
3513
|
+
} of rolesOverwrites) {
|
|
3514
|
+
allow |= overwrites.allow ?? 0;
|
|
3515
|
+
deny |= overwrites.deny ?? 0;
|
|
3516
|
+
}
|
|
3310
3517
|
return {
|
|
3311
|
-
allow
|
|
3312
|
-
deny
|
|
3518
|
+
allow,
|
|
3519
|
+
deny
|
|
3313
3520
|
};
|
|
3314
3521
|
}
|
|
3315
3522
|
resolveOverwritesHierarchy(permissionOverwritesValues) {
|
|
@@ -3491,6 +3698,9 @@ class UsersManager {
|
|
|
3491
3698
|
tracker.client.on('RoomMembers', event => this.handleMembers(event.members));
|
|
3492
3699
|
tracker.client.on('Messages', event => this.handleUsers(event.messages.map(message => message.author.user)));
|
|
3493
3700
|
tracker.client.on('NewMessage', event => this.handleUsers([event.message.author.user]));
|
|
3701
|
+
tracker.client.on('RoomJoined', event => this.handleRooms([event.room]));
|
|
3702
|
+
tracker.client.on('RoomUpdated', event => this.handleRooms([event.room]));
|
|
3703
|
+
tracker.client.on('IgnoredRooms', event => this.handleRooms(event.rooms));
|
|
3494
3704
|
tracker.client.on('Session', event => this.handleSession(event));
|
|
3495
3705
|
}
|
|
3496
3706
|
|
|
@@ -3508,14 +3718,31 @@ class UsersManager {
|
|
|
3508
3718
|
_importUser(user) {
|
|
3509
3719
|
this.handleUsers([user]);
|
|
3510
3720
|
}
|
|
3721
|
+
|
|
3722
|
+
/**
|
|
3723
|
+
* For internal use.
|
|
3724
|
+
* @internal
|
|
3725
|
+
*/
|
|
3726
|
+
_importRooms(rooms) {
|
|
3727
|
+
this.handleRooms(rooms);
|
|
3728
|
+
}
|
|
3511
3729
|
handleMembers(members) {
|
|
3512
3730
|
this.handleUsers(members.map(extractUserFromMember));
|
|
3513
3731
|
}
|
|
3732
|
+
handleRooms(rooms) {
|
|
3733
|
+
const users = new Map();
|
|
3734
|
+
for (const room of rooms) {
|
|
3735
|
+
for (const participant of room.participants ?? []) {
|
|
3736
|
+
users.set(participant.user.id, participant.user);
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3739
|
+
this.handleUsers([...users.values()]);
|
|
3740
|
+
}
|
|
3514
3741
|
handleSession(session) {
|
|
3515
3742
|
// Keep the "seen users" cache across reconnects so bound user lists do
|
|
3516
|
-
// not blank out
|
|
3517
|
-
// entries are refreshed as member/message collections refetch.
|
|
3743
|
+
// not blank out. Stale entries are refreshed as member/message collections refetch.
|
|
3518
3744
|
this.handleUsers([session.user]);
|
|
3745
|
+
this.handleRooms(session.state.rooms);
|
|
3519
3746
|
}
|
|
3520
3747
|
|
|
3521
3748
|
/**
|
|
@@ -3537,20 +3764,6 @@ class UsersManager {
|
|
|
3537
3764
|
this.users.set(...changedUsers);
|
|
3538
3765
|
}
|
|
3539
3766
|
}
|
|
3540
|
-
function isSameUser(a, b) {
|
|
3541
|
-
const keys = Object.keys(a);
|
|
3542
|
-
if (keys.length !== Object.keys(b).length) {
|
|
3543
|
-
return false;
|
|
3544
|
-
}
|
|
3545
|
-
return keys.every(key => {
|
|
3546
|
-
const valueA = a[key];
|
|
3547
|
-
const valueB = b[key];
|
|
3548
|
-
if (Array.isArray(valueA) && Array.isArray(valueB)) {
|
|
3549
|
-
return valueA.length === valueB.length && valueA.every((item, index) => item === valueB[index]);
|
|
3550
|
-
}
|
|
3551
|
-
return valueA === valueB;
|
|
3552
|
-
});
|
|
3553
|
-
}
|
|
3554
3767
|
;// ./src/state-tracker/RelationshipsManager.ts
|
|
3555
3768
|
|
|
3556
3769
|
|
|
@@ -3746,6 +3959,7 @@ class ChatStateTracker {
|
|
|
3746
3959
|
try {
|
|
3747
3960
|
this._me = snapshot.user;
|
|
3748
3961
|
this.users._importUser(snapshot.user);
|
|
3962
|
+
this.users._importRooms(snapshot.rooms);
|
|
3749
3963
|
this.rooms._importRooms(snapshot.rooms);
|
|
3750
3964
|
this.spaces._importSpaces(snapshot.spaces, snapshot.spaceRooms);
|
|
3751
3965
|
this.rooms.followedTopics._importFollowedTopics(snapshot.followedTopics);
|
|
@@ -4259,7 +4473,9 @@ let ErrorCode = /*#__PURE__*/function (ErrorCode) {
|
|
|
4259
4473
|
ErrorCode["InvalidSearchQuery"] = "InvalidSearchQueryException";
|
|
4260
4474
|
ErrorCode["MessageSearchUnavailable"] = "MessageSearchUnavailableException";
|
|
4261
4475
|
ErrorCode["MessageNotFound"] = "MessageNotFoundException";
|
|
4476
|
+
ErrorCode["RoomIgnored"] = "RoomIgnoredException";
|
|
4262
4477
|
ErrorCode["RoomNotFound"] = "RoomNotFoundException";
|
|
4478
|
+
ErrorCode["SpaceJoinRestricted"] = "SpaceJoinRestrictedException";
|
|
4263
4479
|
ErrorCode["TopicNotFound"] = "TopicNotFoundException";
|
|
4264
4480
|
ErrorCode["UserNotFound"] = "UserNotFoundException";
|
|
4265
4481
|
return ErrorCode;
|
|
@@ -4397,6 +4613,7 @@ let SpaceIntent = /*#__PURE__*/function (SpaceIntent) {
|
|
|
4397
4613
|
|
|
4398
4614
|
|
|
4399
4615
|
|
|
4616
|
+
|
|
4400
4617
|
module.exports = __webpack_exports__;
|
|
4401
4618
|
/******/ })()
|
|
4402
4619
|
;
|