@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/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,71 @@ All notable changes to this project are documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project follows
|
|
5
5
|
[semver](https://semver.org) (`0.x` minor releases may break the API).
|
|
6
6
|
|
|
7
|
-
## [0.
|
|
7
|
+
## [0.10.0]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Group private conversations: a `Pm` room has 1 (notes), 2 or 3-10 participants; `CreateRoom` takes up to 9
|
|
12
|
+
`recipientIds` and, for a new conversation of 3 or more people, a `name`.
|
|
13
|
+
- `Room.participants` (`PmParticipant[]`, `null` for rooms of spaces): the users of a private conversation with their
|
|
14
|
+
`flags`; `PmParticipantFlag.IgnoresRoom` marks a participant ignoring it. The members of a private conversation
|
|
15
|
+
(`RoomsManager.getMembers()`) are its participants without the ones ignoring it, rebuilt on `RoomUpdated`, and the
|
|
16
|
+
participants land in `UsersManager.getAvailable()`.
|
|
17
|
+
- `isGroupPm(room)` and `getPmPeers(room, meId)` helpers.
|
|
18
|
+
- Ignoring a group conversation: `LeaveRoom` takes `ignore: true` (answered with `RoomLeft`, or `Ok` when the
|
|
19
|
+
user was not its member); `JoinRoom` of the ignoring participant stops ignoring it. `GetIgnoredRooms` returns the
|
|
20
|
+
ignored conversations as `IgnoredRooms`. `CreateRoom` for an ignored conversation fails with
|
|
21
|
+
`ErrorCode.RoomIgnored`, its id in `Error.details.roomId`.
|
|
22
|
+
- `UpdateRoom` changes the name of a group conversation (only `name` is accepted for a `Pm` room).
|
|
23
|
+
- Message type `RoomRename` (content: the new name, empty when the name was removed); `RoomJoin` and `RoomLeave` in a
|
|
24
|
+
group conversation mean stopping and starting to ignore it.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- **Breaking:** the members of a private conversation and its users in `UsersManager` come from `Room.participants`,
|
|
29
|
+
so a server that does not send `participants` leaves private conversations without members.
|
|
30
|
+
- `STATE_SNAPSHOT_VERSION` is 2 - snapshots of the previous version (rooms without `participants`) are rejected on
|
|
31
|
+
import.
|
|
32
|
+
|
|
33
|
+
### Deprecated
|
|
34
|
+
|
|
35
|
+
- `Room.recipients` - use `Room.participants`.
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- `RoomMemberUpdated` of a member missing from the room's collection threw instead of being skipped.
|
|
40
|
+
|
|
41
|
+
## [0.9.0]
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- `Permissions.list.UseExternalEmoticons` (`1 << 26`, space and room layer): using emoticons of other spaces.
|
|
46
|
+
- `UserFeature.ExternalEmoticons` (`user.external_emoticons`): the account may use emoticons outside their spaces.
|
|
47
|
+
- `MessageReaction.name` and `ToggledReaction.name`: the emoticon name of an `Emoticon` reaction.
|
|
48
|
+
- `GetEmoticons` takes `ids` (up to 100) and returns those of the emoticons the user may see - the ones of the spaces
|
|
49
|
+
they belong to and of the spaces that let their emoticons be used outside (space flag `1 << 2`, `spaceId` and `user`
|
|
50
|
+
null for a space the user does not belong to); the rest is left out. The response has `location: null` and does not
|
|
51
|
+
change the collections returned by `EmoticonsManager.get()`.
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- **Breaking:** there are no global emoticons any more. `EmoticonsManager.get()` requires a `spaceId`,
|
|
56
|
+
`CreateEmoticon.spaceId` and `EmoticonDeleted.spaceId` are required, and `EmoticonsSnapshot.spaceId` is a string -
|
|
57
|
+
global emoticons kept in an older snapshot are dropped on import.
|
|
58
|
+
- **Breaking:** `Emoticon.tag` (emoticon categories) is gone. `Emoticon.spaceId` and `Emoticon.user` (the author) are
|
|
59
|
+
`null` for an emoticon of a space the user does not belong to.
|
|
60
|
+
- **Breaking (protocol):** an `Emoticon` reaction (`React`, `Unreact`, `GetReactionDetails`, reactions of a message,
|
|
61
|
+
poll options) is identified by the emoticon id in `value` instead of its name. Servers before this change send the
|
|
62
|
+
name in `value` and no `name` - an application that has to work with both tells them apart by the length of `value`
|
|
63
|
+
(a name has at most 20 characters, an id 22).
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- Withdrawing the last own reaction from a message (`Reacted` with `isAdded: false`) left it in
|
|
68
|
+
`TopicHistoryWindow.myReactions` in apps built with Babel's loose object rest transform (e.g. `babel-preset-expo` on
|
|
69
|
+
web) - it dropped the message ID from the exclusion list (babel/babel#18196).
|
|
70
|
+
|
|
71
|
+
## [0.8.1]
|
|
8
72
|
|
|
9
73
|
### Added
|
|
10
74
|
|
|
@@ -28,7 +92,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
28
92
|
earlier jump) waits for it to end and then jumps, instead of returning at once without loading anything - a caller
|
|
29
93
|
checking `has(id)` afterwards took the message for missing.
|
|
30
94
|
|
|
31
|
-
## [0.8.0]
|
|
95
|
+
## [0.8.0]
|
|
32
96
|
|
|
33
97
|
### Added
|
|
34
98
|
|
|
@@ -53,7 +117,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
53
117
|
fetches it anew (as on a reconnect) and fetches the restored topics other than the default ones.
|
|
54
118
|
- Type exports `StateSnapshot`, `StateSnapshotIntent`, `TopicHistorySnapshot`, `RoomMembersSnapshot`,
|
|
55
119
|
`SpaceRoomsSnapshot`, `RoomFollowedTopicsSnapshot`, `EmoticonsSnapshot` and the `STATE_SNAPSHOT_VERSION` constant.
|
|
56
|
-
## [0.7.0]
|
|
120
|
+
## [0.7.0]
|
|
57
121
|
|
|
58
122
|
### Added
|
|
59
123
|
|
|
@@ -97,7 +161,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
97
161
|
|
|
98
162
|
Migrating from `polfan-server-js-client` 0.5.0: see [docs/migration-0.5-to-0.7.md](docs/migration-0.5-to-0.7.md).
|
|
99
163
|
|
|
100
|
-
## [0.6.0]
|
|
164
|
+
## [0.6.0]
|
|
101
165
|
|
|
102
166
|
The first release under the new name. Earlier versions were published as `polfan-server-js-client`.
|
|
103
167
|
|
package/build/index.cjs.js
CHANGED
|
@@ -51,6 +51,7 @@ __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),
|
|
@@ -62,7 +63,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
62
63
|
UserStatus: () => (/* reexport */ UserStatus),
|
|
63
64
|
WebApiChatClient: () => (/* reexport */ WebApiChatClient),
|
|
64
65
|
WebSocketChatClient: () => (/* reexport */ WebSocketChatClient),
|
|
65
|
-
extractUserFromMember: () => (/* reexport */ extractUserFromMember)
|
|
66
|
+
extractUserFromMember: () => (/* reexport */ extractUserFromMember),
|
|
67
|
+
getPmPeers: () => (/* reexport */ getPmPeers),
|
|
68
|
+
isGroupPm: () => (/* reexport */ isGroupPm)
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
;// ./src/EventTarget.ts
|
|
@@ -1118,10 +1121,12 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1118
1121
|
value
|
|
1119
1122
|
});
|
|
1120
1123
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1124
|
+
|
|
1125
|
+
// Not `{[ev.messageId]: _, ...rest}` - Babel's loose object rest drops the key when the binding is unused (babel/babel#18196)
|
|
1126
|
+
const myReactions = {
|
|
1127
|
+
...this.internalState.myReactions
|
|
1128
|
+
};
|
|
1129
|
+
delete myReactions[ev.messageId];
|
|
1125
1130
|
if (own.length) {
|
|
1126
1131
|
myReactions[ev.messageId] = own;
|
|
1127
1132
|
}
|
|
@@ -1944,7 +1949,7 @@ let UserStatus = /*#__PURE__*/function (UserStatus) {
|
|
|
1944
1949
|
/**
|
|
1945
1950
|
* Version of the {@link StateSnapshot} format. A snapshot of any other version is rejected on import.
|
|
1946
1951
|
*/
|
|
1947
|
-
const STATE_SNAPSHOT_VERSION =
|
|
1952
|
+
const STATE_SNAPSHOT_VERSION = 2;
|
|
1948
1953
|
|
|
1949
1954
|
/**
|
|
1950
1955
|
* Plain, JSON-serializable copy of the state tracked by {@link ChatStateTracker}, made to restore the state at the
|
|
@@ -2014,6 +2019,9 @@ function hasId(value) {
|
|
|
2014
2019
|
function isUser(value) {
|
|
2015
2020
|
return hasId(value);
|
|
2016
2021
|
}
|
|
2022
|
+
function isPmParticipant(value) {
|
|
2023
|
+
return isObject(value) && isUser(value.user) && typeof value.flags === 'number';
|
|
2024
|
+
}
|
|
2017
2025
|
function isRole(value) {
|
|
2018
2026
|
return hasId(value) && typeof value.priority === 'number';
|
|
2019
2027
|
}
|
|
@@ -2030,7 +2038,7 @@ function isFullMessage(value) {
|
|
|
2030
2038
|
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);
|
|
2031
2039
|
}
|
|
2032
2040
|
function isRoom(value) {
|
|
2033
|
-
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);
|
|
2041
|
+
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);
|
|
2034
2042
|
}
|
|
2035
2043
|
function isSpaceRooms(value) {
|
|
2036
2044
|
return isObject(value) && isString(value.spaceId) && isArrayOf(value.summaries, hasId);
|
|
@@ -2059,12 +2067,84 @@ function isRoomMember(value) {
|
|
|
2059
2067
|
function isRoomMembers(value) {
|
|
2060
2068
|
return isObject(value) && isString(value.roomId) && isArrayOf(value.members, isRoomMember);
|
|
2061
2069
|
}
|
|
2070
|
+
;// ./src/protocol/schemes/PmParticipant.ts
|
|
2071
|
+
let PmParticipantFlag = /*#__PURE__*/function (PmParticipantFlag) {
|
|
2072
|
+
PmParticipantFlag[PmParticipantFlag["IgnoresRoom"] = 1] = "IgnoresRoom";
|
|
2073
|
+
return PmParticipantFlag;
|
|
2074
|
+
}({});
|
|
2075
|
+
;// ./src/state-tracker/functions.ts
|
|
2076
|
+
|
|
2077
|
+
|
|
2078
|
+
/**
|
|
2079
|
+
* @return New objects of the other roles whose priority has to move; the given roles are left intact.
|
|
2080
|
+
*/
|
|
2081
|
+
function reorderRolesOnPriorityUpdate(allRoles, oldRole, updatedRole) {
|
|
2082
|
+
// If the priority has changed, adjust the rest of roles
|
|
2083
|
+
const increased = updatedRole.priority - oldRole.priority > 0;
|
|
2084
|
+
const decreased = !increased;
|
|
2085
|
+
const changedRoles = [];
|
|
2086
|
+
allRoles.forEach(role => {
|
|
2087
|
+
if (role.id === updatedRole.id) {
|
|
2088
|
+
// Skip the updated role
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
if (increased && oldRole.priority <= role.priority) {
|
|
2092
|
+
changedRoles.push({
|
|
2093
|
+
...role,
|
|
2094
|
+
priority: role.priority - 1
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
if (decreased && updatedRole.priority <= role.priority) {
|
|
2098
|
+
changedRoles.push({
|
|
2099
|
+
...role,
|
|
2100
|
+
priority: role.priority + 1
|
|
2101
|
+
});
|
|
2102
|
+
}
|
|
2103
|
+
});
|
|
2104
|
+
return changedRoles;
|
|
2105
|
+
}
|
|
2106
|
+
function extractUserFromMember(member) {
|
|
2107
|
+
return member.user ?? member.spaceMember?.user;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
/**
|
|
2111
|
+
* Whether the room is a private group conversation - 3 or more participants, including the ones ignoring it.
|
|
2112
|
+
*/
|
|
2113
|
+
function isGroupPm(room) {
|
|
2114
|
+
return room.type === 'Pm' && (room.participants?.length ?? 0) >= 3;
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
/**
|
|
2118
|
+
* Participants of a private conversation taking part in it: without the ones ignoring it and without the user
|
|
2119
|
+
* `meId`. Empty for notes and for rooms of spaces.
|
|
2120
|
+
*/
|
|
2121
|
+
function getPmPeers(room, meId) {
|
|
2122
|
+
return getActivePmParticipants(room).filter(participant => participant.user.id !== meId);
|
|
2123
|
+
}
|
|
2124
|
+
function getActivePmParticipants(room) {
|
|
2125
|
+
return (room.participants ?? []).filter(participant => !(participant.flags & PmParticipantFlag.IgnoresRoom));
|
|
2126
|
+
}
|
|
2127
|
+
function isSameUser(a, b) {
|
|
2128
|
+
const keys = Object.keys(a);
|
|
2129
|
+
if (keys.length !== Object.keys(b).length) {
|
|
2130
|
+
return false;
|
|
2131
|
+
}
|
|
2132
|
+
return keys.every(key => {
|
|
2133
|
+
const valueA = a[key];
|
|
2134
|
+
const valueB = b[key];
|
|
2135
|
+
if (Array.isArray(valueA) && Array.isArray(valueB)) {
|
|
2136
|
+
return valueA.length === valueB.length && valueA.every((item, index) => item === valueB[index]);
|
|
2137
|
+
}
|
|
2138
|
+
return valueA === valueB;
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2062
2141
|
;// ./src/state-tracker/RoomsManager.ts
|
|
2063
2142
|
|
|
2064
2143
|
|
|
2065
2144
|
|
|
2066
2145
|
|
|
2067
2146
|
|
|
2147
|
+
|
|
2068
2148
|
class RoomsManager {
|
|
2069
2149
|
messages;
|
|
2070
2150
|
followedTopics;
|
|
@@ -2154,7 +2234,15 @@ class RoomsManager {
|
|
|
2154
2234
|
const promise = this.tracker.client.send('GetTopics', {
|
|
2155
2235
|
roomId,
|
|
2156
2236
|
topicIds: idsToFetch
|
|
2157
|
-
}).then(result =>
|
|
2237
|
+
}).then(result => {
|
|
2238
|
+
const topics = this.topics.get(roomId);
|
|
2239
|
+
if (topics) {
|
|
2240
|
+
topics.set(...result.data.topics);
|
|
2241
|
+
} else {
|
|
2242
|
+
// A room not joined yet has nowhere to keep them - let them be fetched again once it is.
|
|
2243
|
+
this.topicsPromises.forget(...idsToFetch.map(topicId => roomId + topicId));
|
|
2244
|
+
}
|
|
2245
|
+
});
|
|
2158
2246
|
idsToFetch.forEach(topicId => this.topicsPromises.register(promise, roomId + topicId));
|
|
2159
2247
|
}
|
|
2160
2248
|
for (const topicId of tryToFetchTopicIds) {
|
|
@@ -2185,9 +2273,13 @@ class RoomsManager {
|
|
|
2185
2273
|
* @internal
|
|
2186
2274
|
*/
|
|
2187
2275
|
_exportRooms() {
|
|
2188
|
-
return this.list.items.map(room => room.
|
|
2276
|
+
return this.list.items.map(room => room.participants ? {
|
|
2189
2277
|
...room,
|
|
2190
|
-
|
|
2278
|
+
participants: room.participants.map(participant => ({
|
|
2279
|
+
...participant,
|
|
2280
|
+
user: withoutPresence(participant.user)
|
|
2281
|
+
})),
|
|
2282
|
+
recipients: room.recipients?.map(withoutPresence) ?? null
|
|
2191
2283
|
} : room);
|
|
2192
2284
|
}
|
|
2193
2285
|
|
|
@@ -2239,7 +2331,7 @@ class RoomsManager {
|
|
|
2239
2331
|
}
|
|
2240
2332
|
|
|
2241
2333
|
/**
|
|
2242
|
-
* Members of private conversations are not exported - they are made of the
|
|
2334
|
+
* Members of private conversations are not exported - they are made of the participants of the room.
|
|
2243
2335
|
* @internal
|
|
2244
2336
|
*/
|
|
2245
2337
|
_exportMembers(roomIds, limit) {
|
|
@@ -2365,6 +2457,9 @@ class RoomsManager {
|
|
|
2365
2457
|
}
|
|
2366
2458
|
const members = this.members.get(ev.roomId);
|
|
2367
2459
|
const member = members.get(ev.userId);
|
|
2460
|
+
if (!member) {
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2368
2463
|
const user = member.spaceMember?.user ?? member.user;
|
|
2369
2464
|
|
|
2370
2465
|
// Preserving user object, because it's not included in event
|
|
@@ -2409,6 +2504,7 @@ class RoomsManager {
|
|
|
2409
2504
|
handleRoomUpdated(ev) {
|
|
2410
2505
|
if (this.list.has(ev.room.id)) {
|
|
2411
2506
|
this.list.set(ev.room);
|
|
2507
|
+
this.setPmMembers(ev.room);
|
|
2412
2508
|
}
|
|
2413
2509
|
}
|
|
2414
2510
|
handleRoomDeleted(ev) {
|
|
@@ -2432,27 +2528,39 @@ class RoomsManager {
|
|
|
2432
2528
|
if (room.defaultTopic) {
|
|
2433
2529
|
this.addJoinedRoomTopics(room.id, room.defaultTopic);
|
|
2434
2530
|
}
|
|
2435
|
-
|
|
2436
|
-
// Treat PM recipients as normal room members.
|
|
2437
|
-
// We are registering fake promise in `memberPromises`
|
|
2438
|
-
// because GetMembers are not supported for PM rooms.
|
|
2439
|
-
this.handleRoomMembers({
|
|
2440
|
-
id: room.id,
|
|
2441
|
-
members: room.recipients.map(user => ({
|
|
2442
|
-
user,
|
|
2443
|
-
spaceMember: null,
|
|
2444
|
-
roles: null,
|
|
2445
|
-
customColor: null,
|
|
2446
|
-
customNick: null,
|
|
2447
|
-
customAvatar: null,
|
|
2448
|
-
extras: ''
|
|
2449
|
-
}))
|
|
2450
|
-
});
|
|
2451
|
-
this.membersPromises.register(Promise.resolve(), room.id);
|
|
2452
|
-
}
|
|
2531
|
+
this.setPmMembers(room);
|
|
2453
2532
|
}
|
|
2454
2533
|
this.list.set(...rooms);
|
|
2455
2534
|
}
|
|
2535
|
+
setPmMembers(room) {
|
|
2536
|
+
if (room.type !== 'Pm' || !room.participants) {
|
|
2537
|
+
return;
|
|
2538
|
+
}
|
|
2539
|
+
const current = this.members.get(room.id);
|
|
2540
|
+
const members = getActivePmParticipants(room).map(({
|
|
2541
|
+
user
|
|
2542
|
+
}) => {
|
|
2543
|
+
const member = current?.get(user.id);
|
|
2544
|
+
return member && isSameUser(member.user, user) ? member : {
|
|
2545
|
+
user,
|
|
2546
|
+
spaceMember: null,
|
|
2547
|
+
roles: null,
|
|
2548
|
+
customColor: null,
|
|
2549
|
+
customNick: null,
|
|
2550
|
+
customAvatar: null,
|
|
2551
|
+
extras: ''
|
|
2552
|
+
};
|
|
2553
|
+
});
|
|
2554
|
+
if (current?.length === members.length && members.every(member => current.get(member.user.id) === member)) {
|
|
2555
|
+
return;
|
|
2556
|
+
}
|
|
2557
|
+
this.handleRoomMembers({
|
|
2558
|
+
id: room.id,
|
|
2559
|
+
members
|
|
2560
|
+
});
|
|
2561
|
+
// GetRoomMembers is not supported for private conversations
|
|
2562
|
+
this.membersPromises.register(Promise.resolve(), room.id);
|
|
2563
|
+
}
|
|
2456
2564
|
handleRoomLeft(ev) {
|
|
2457
2565
|
this.deleteRoom(ev.id);
|
|
2458
2566
|
}
|
|
@@ -2516,13 +2624,17 @@ class RoomsManager {
|
|
|
2516
2624
|
});
|
|
2517
2625
|
});
|
|
2518
2626
|
|
|
2519
|
-
// Update
|
|
2627
|
+
// Update users of private conversation participants
|
|
2520
2628
|
const newRooms = [];
|
|
2521
2629
|
this.list.items.forEach(room => {
|
|
2522
|
-
if (room.
|
|
2630
|
+
if (room.participants?.some(participant => participant.user.id === ev.user.id)) {
|
|
2523
2631
|
newRooms.push({
|
|
2524
2632
|
...room,
|
|
2525
|
-
|
|
2633
|
+
participants: room.participants.map(participant => participant.user.id === ev.user.id ? {
|
|
2634
|
+
...participant,
|
|
2635
|
+
user: ev.user
|
|
2636
|
+
} : participant),
|
|
2637
|
+
recipients: room.recipients?.map(user => user.id === ev.user.id ? ev.user : user) ?? null
|
|
2526
2638
|
});
|
|
2527
2639
|
}
|
|
2528
2640
|
});
|
|
@@ -2574,38 +2686,6 @@ class RoomsManager {
|
|
|
2574
2686
|
}
|
|
2575
2687
|
}
|
|
2576
2688
|
}
|
|
2577
|
-
;// ./src/state-tracker/functions.ts
|
|
2578
|
-
/**
|
|
2579
|
-
* @return New objects of the other roles whose priority has to move; the given roles are left intact.
|
|
2580
|
-
*/
|
|
2581
|
-
function reorderRolesOnPriorityUpdate(allRoles, oldRole, updatedRole) {
|
|
2582
|
-
// If the priority has changed, adjust the rest of roles
|
|
2583
|
-
const increased = updatedRole.priority - oldRole.priority > 0;
|
|
2584
|
-
const decreased = !increased;
|
|
2585
|
-
const changedRoles = [];
|
|
2586
|
-
allRoles.forEach(role => {
|
|
2587
|
-
if (role.id === updatedRole.id) {
|
|
2588
|
-
// Skip the updated role
|
|
2589
|
-
return;
|
|
2590
|
-
}
|
|
2591
|
-
if (increased && oldRole.priority <= role.priority) {
|
|
2592
|
-
changedRoles.push({
|
|
2593
|
-
...role,
|
|
2594
|
-
priority: role.priority - 1
|
|
2595
|
-
});
|
|
2596
|
-
}
|
|
2597
|
-
if (decreased && updatedRole.priority <= role.priority) {
|
|
2598
|
-
changedRoles.push({
|
|
2599
|
-
...role,
|
|
2600
|
-
priority: role.priority + 1
|
|
2601
|
-
});
|
|
2602
|
-
}
|
|
2603
|
-
});
|
|
2604
|
-
return changedRoles;
|
|
2605
|
-
}
|
|
2606
|
-
function extractUserFromMember(member) {
|
|
2607
|
-
return member.user ?? member.spaceMember?.user;
|
|
2608
|
-
}
|
|
2609
2689
|
;// ./src/state-tracker/SpacesManager.ts
|
|
2610
2690
|
|
|
2611
2691
|
|
|
@@ -3058,6 +3138,10 @@ class Permissions {
|
|
|
3058
3138
|
SearchMessages: {
|
|
3059
3139
|
value: 1 << 25,
|
|
3060
3140
|
maxLayer: Layer.Room
|
|
3141
|
+
},
|
|
3142
|
+
UseExternalEmoticons: {
|
|
3143
|
+
value: 1 << 26,
|
|
3144
|
+
maxLayer: Layer.Room
|
|
3061
3145
|
}
|
|
3062
3146
|
};
|
|
3063
3147
|
static getNames() {
|
|
@@ -3351,7 +3435,6 @@ class PermissionsManager extends EventTarget {
|
|
|
3351
3435
|
;// ./src/state-tracker/EmoticonsManager.ts
|
|
3352
3436
|
|
|
3353
3437
|
|
|
3354
|
-
const GLOBAL_KEY = 'global';
|
|
3355
3438
|
class EmoticonsManager {
|
|
3356
3439
|
list = new IndexedCollection();
|
|
3357
3440
|
emoticonsPromises = new PromiseRegistry();
|
|
@@ -3364,8 +3447,7 @@ class EmoticonsManager {
|
|
|
3364
3447
|
this.tracker.client.on('Session', () => this.handleSession());
|
|
3365
3448
|
}
|
|
3366
3449
|
async get(spaceId) {
|
|
3367
|
-
|
|
3368
|
-
if (this.emoticonsPromises.notExist(key)) {
|
|
3450
|
+
if (this.emoticonsPromises.notExist(spaceId)) {
|
|
3369
3451
|
this.emoticonsPromises.registerByFunction(async () => {
|
|
3370
3452
|
const result = await this.tracker.client.send('GetEmoticons', {
|
|
3371
3453
|
spaceId
|
|
@@ -3374,10 +3456,10 @@ class EmoticonsManager {
|
|
|
3374
3456
|
throw result.error;
|
|
3375
3457
|
}
|
|
3376
3458
|
this.handleEmoticons(result.data);
|
|
3377
|
-
},
|
|
3459
|
+
}, spaceId);
|
|
3378
3460
|
}
|
|
3379
|
-
await this.emoticonsPromises.get(
|
|
3380
|
-
return this.list.get(
|
|
3461
|
+
await this.emoticonsPromises.get(spaceId);
|
|
3462
|
+
return this.list.get(spaceId);
|
|
3381
3463
|
}
|
|
3382
3464
|
|
|
3383
3465
|
/**
|
|
@@ -3385,8 +3467,8 @@ class EmoticonsManager {
|
|
|
3385
3467
|
* @internal
|
|
3386
3468
|
*/
|
|
3387
3469
|
_exportEmoticons() {
|
|
3388
|
-
return Array.from(this.list.items).map(([
|
|
3389
|
-
spaceId
|
|
3470
|
+
return Array.from(this.list.items).map(([spaceId, emoticons]) => ({
|
|
3471
|
+
spaceId,
|
|
3390
3472
|
emoticons: emoticons.items
|
|
3391
3473
|
}));
|
|
3392
3474
|
}
|
|
@@ -3401,17 +3483,19 @@ class EmoticonsManager {
|
|
|
3401
3483
|
spaceId,
|
|
3402
3484
|
emoticons
|
|
3403
3485
|
} of snapshots) {
|
|
3404
|
-
|
|
3486
|
+
// TODO(emoticons-compat): snapshots written before the global emoticons were gone still hold them under
|
|
3487
|
+
// null - drop the comment once no such snapshot can be left on a device (the check itself stays).
|
|
3488
|
+
if (!joinedSpaceIds.has(spaceId)) {
|
|
3405
3489
|
continue;
|
|
3406
3490
|
}
|
|
3407
3491
|
this.handleEmoticons({
|
|
3408
3492
|
location: {
|
|
3409
|
-
spaceId
|
|
3493
|
+
spaceId
|
|
3410
3494
|
},
|
|
3411
3495
|
emoticons
|
|
3412
3496
|
});
|
|
3413
3497
|
// Served from the snapshot until the session invalidates it.
|
|
3414
|
-
this.emoticonsPromises.register(Promise.resolve(), spaceId
|
|
3498
|
+
this.emoticonsPromises.register(Promise.resolve(), spaceId);
|
|
3415
3499
|
}
|
|
3416
3500
|
}
|
|
3417
3501
|
|
|
@@ -3420,13 +3504,19 @@ class EmoticonsManager {
|
|
|
3420
3504
|
* @internal
|
|
3421
3505
|
*/
|
|
3422
3506
|
_forgetSpacesExcept(spaceIds) {
|
|
3423
|
-
const keptKeys = new Set(
|
|
3507
|
+
const keptKeys = new Set(spaceIds);
|
|
3424
3508
|
const removedKeys = Array.from(this.list.items.keys()).filter(key => !keptKeys.has(key));
|
|
3425
3509
|
this.list.delete(...removedKeys);
|
|
3426
3510
|
this.emoticonsPromises.forget(...removedKeys);
|
|
3427
3511
|
}
|
|
3428
3512
|
handleEmoticons(event) {
|
|
3429
|
-
|
|
3513
|
+
// A selection by ids has no location.
|
|
3514
|
+
// TODO(emoticons-compat): one without a space is the always empty list of the gone global emoticons, sent
|
|
3515
|
+
// until the server stops answering old clients that way.
|
|
3516
|
+
const spaceId = event.location?.spaceId;
|
|
3517
|
+
if (!spaceId) {
|
|
3518
|
+
return;
|
|
3519
|
+
}
|
|
3430
3520
|
if (!this.list.has(spaceId)) {
|
|
3431
3521
|
this.list.set([spaceId, new ObservableIndexedObjectCollection('id')]);
|
|
3432
3522
|
}
|
|
@@ -3437,11 +3527,11 @@ class EmoticonsManager {
|
|
|
3437
3527
|
this.list.get(spaceId).reconcile(...event.emoticons);
|
|
3438
3528
|
}
|
|
3439
3529
|
handleNewEmoticon(ev) {
|
|
3440
|
-
const collection = this.list.get(ev.emoticon.spaceId
|
|
3530
|
+
const collection = this.list.get(ev.emoticon.spaceId);
|
|
3441
3531
|
collection?.set(ev.emoticon);
|
|
3442
3532
|
}
|
|
3443
3533
|
handleEmoticonDeleted(ev) {
|
|
3444
|
-
const collection = this.list.get(ev.spaceId
|
|
3534
|
+
const collection = this.list.get(ev.spaceId);
|
|
3445
3535
|
collection?.delete(ev.emoticonId);
|
|
3446
3536
|
}
|
|
3447
3537
|
handleSpaceDeleted(event) {
|
|
@@ -3471,6 +3561,9 @@ class UsersManager {
|
|
|
3471
3561
|
tracker.client.on('RoomMembers', event => this.handleMembers(event.members));
|
|
3472
3562
|
tracker.client.on('Messages', event => this.handleUsers(event.messages.map(message => message.author.user)));
|
|
3473
3563
|
tracker.client.on('NewMessage', event => this.handleUsers([event.message.author.user]));
|
|
3564
|
+
tracker.client.on('RoomJoined', event => this.handleRooms([event.room]));
|
|
3565
|
+
tracker.client.on('RoomUpdated', event => this.handleRooms([event.room]));
|
|
3566
|
+
tracker.client.on('IgnoredRooms', event => this.handleRooms(event.rooms));
|
|
3474
3567
|
tracker.client.on('Session', event => this.handleSession(event));
|
|
3475
3568
|
}
|
|
3476
3569
|
|
|
@@ -3488,14 +3581,31 @@ class UsersManager {
|
|
|
3488
3581
|
_importUser(user) {
|
|
3489
3582
|
this.handleUsers([user]);
|
|
3490
3583
|
}
|
|
3584
|
+
|
|
3585
|
+
/**
|
|
3586
|
+
* For internal use.
|
|
3587
|
+
* @internal
|
|
3588
|
+
*/
|
|
3589
|
+
_importRooms(rooms) {
|
|
3590
|
+
this.handleRooms(rooms);
|
|
3591
|
+
}
|
|
3491
3592
|
handleMembers(members) {
|
|
3492
3593
|
this.handleUsers(members.map(extractUserFromMember));
|
|
3493
3594
|
}
|
|
3595
|
+
handleRooms(rooms) {
|
|
3596
|
+
const users = new Map();
|
|
3597
|
+
for (const room of rooms) {
|
|
3598
|
+
for (const participant of room.participants ?? []) {
|
|
3599
|
+
users.set(participant.user.id, participant.user);
|
|
3600
|
+
}
|
|
3601
|
+
}
|
|
3602
|
+
this.handleUsers([...users.values()]);
|
|
3603
|
+
}
|
|
3494
3604
|
handleSession(session) {
|
|
3495
3605
|
// Keep the "seen users" cache across reconnects so bound user lists do
|
|
3496
|
-
// not blank out
|
|
3497
|
-
// entries are refreshed as member/message collections refetch.
|
|
3606
|
+
// not blank out. Stale entries are refreshed as member/message collections refetch.
|
|
3498
3607
|
this.handleUsers([session.user]);
|
|
3608
|
+
this.handleRooms(session.state.rooms);
|
|
3499
3609
|
}
|
|
3500
3610
|
|
|
3501
3611
|
/**
|
|
@@ -3517,20 +3627,6 @@ class UsersManager {
|
|
|
3517
3627
|
this.users.set(...changedUsers);
|
|
3518
3628
|
}
|
|
3519
3629
|
}
|
|
3520
|
-
function isSameUser(a, b) {
|
|
3521
|
-
const keys = Object.keys(a);
|
|
3522
|
-
if (keys.length !== Object.keys(b).length) {
|
|
3523
|
-
return false;
|
|
3524
|
-
}
|
|
3525
|
-
return keys.every(key => {
|
|
3526
|
-
const valueA = a[key];
|
|
3527
|
-
const valueB = b[key];
|
|
3528
|
-
if (Array.isArray(valueA) && Array.isArray(valueB)) {
|
|
3529
|
-
return valueA.length === valueB.length && valueA.every((item, index) => item === valueB[index]);
|
|
3530
|
-
}
|
|
3531
|
-
return valueA === valueB;
|
|
3532
|
-
});
|
|
3533
|
-
}
|
|
3534
3630
|
;// ./src/state-tracker/RelationshipsManager.ts
|
|
3535
3631
|
|
|
3536
3632
|
|
|
@@ -3726,6 +3822,7 @@ class ChatStateTracker {
|
|
|
3726
3822
|
try {
|
|
3727
3823
|
this._me = snapshot.user;
|
|
3728
3824
|
this.users._importUser(snapshot.user);
|
|
3825
|
+
this.users._importRooms(snapshot.rooms);
|
|
3729
3826
|
this.rooms._importRooms(snapshot.rooms);
|
|
3730
3827
|
this.spaces._importSpaces(snapshot.spaces, snapshot.spaceRooms);
|
|
3731
3828
|
this.rooms.followedTopics._importFollowedTopics(snapshot.followedTopics);
|
|
@@ -4239,6 +4336,7 @@ let ErrorCode = /*#__PURE__*/function (ErrorCode) {
|
|
|
4239
4336
|
ErrorCode["InvalidSearchQuery"] = "InvalidSearchQueryException";
|
|
4240
4337
|
ErrorCode["MessageSearchUnavailable"] = "MessageSearchUnavailableException";
|
|
4241
4338
|
ErrorCode["MessageNotFound"] = "MessageNotFoundException";
|
|
4339
|
+
ErrorCode["RoomIgnored"] = "RoomIgnoredException";
|
|
4242
4340
|
ErrorCode["RoomNotFound"] = "RoomNotFoundException";
|
|
4243
4341
|
ErrorCode["TopicNotFound"] = "TopicNotFoundException";
|
|
4244
4342
|
ErrorCode["UserNotFound"] = "UserNotFoundException";
|
|
@@ -4324,6 +4422,7 @@ let UserFeature = /*#__PURE__*/function (UserFeature) {
|
|
|
4324
4422
|
UserFeature["MessageLength"] = "user.message.length";
|
|
4325
4423
|
UserFeature["StorageLimit"] = "user.storage.limit";
|
|
4326
4424
|
UserFeature["StorageSingleFileLimit"] = "user.storage.single_file_limit";
|
|
4425
|
+
UserFeature["ExternalEmoticons"] = "user.external_emoticons";
|
|
4327
4426
|
return UserFeature;
|
|
4328
4427
|
}({});
|
|
4329
4428
|
|