@devanachat/sdk 0.10.0 → 0.12.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 +76 -0
- package/README.md +2 -2
- package/build/index.cjs.js +533 -147
- package/build/index.cjs.js.map +1 -1
- package/build/index.mjs +531 -148
- 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 +21 -4
- package/build/types/Permissions.d.ts +13 -1
- package/build/types/index.d.ts +4 -3
- package/build/types/protocol/index.d.ts +18 -4
- package/build/types/protocol/schemes/Message.d.ts +4 -0
- package/build/types/protocol/schemes/MessageEmbed.d.ts +83 -0
- package/build/types/protocol/schemes/Role.d.ts +6 -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/AckInteraction.d.ts +10 -0
- package/build/types/protocol/schemes/commands/CreateMessage.d.ts +8 -0
- package/build/types/protocol/schemes/commands/GetGifCategories.d.ts +3 -0
- package/build/types/protocol/schemes/commands/GetMessages.d.ts +1 -0
- package/build/types/protocol/schemes/commands/Interact.d.ts +5 -0
- package/build/types/protocol/schemes/commands/SearchGifs.d.ts +5 -0
- package/build/types/protocol/schemes/commands/Type.d.ts +4 -0
- package/build/types/protocol/schemes/commands/UpdateMessage.d.ts +8 -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 +3 -0
- package/build/types/protocol/schemes/events/FoundGifs.d.ts +14 -0
- package/build/types/protocol/schemes/events/GifCategories.d.ts +8 -0
- package/build/types/protocol/schemes/events/Interacted.d.ts +4 -0
- package/build/types/protocol/schemes/events/InteractionResolved.d.ts +7 -0
- package/build/types/protocol/schemes/events/MessageUpdated.d.ts +6 -0
- package/build/types/protocol/schemes/events/Messages.d.ts +6 -2
- package/build/types/protocol/schemes/events/NewInteraction.d.ts +10 -0
- package/build/types/protocol/schemes/events/NewMessage.d.ts +4 -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/RoomMessagesHistory.d.ts +7 -2
- package/build/types/state-tracker/RoomsManager.d.ts +14 -1
- package/build/types/state-tracker/StateSnapshot.d.ts +5 -1
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +29 -2
- package/build/types/state-tracker/TypingManager.d.ts +35 -0
- package/build/types/state-tracker/functions.d.ts +8 -1
- package/package.json +1 -1
package/build/index.cjs.js
CHANGED
|
@@ -46,6 +46,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
46
46
|
IndexedCollection: () => (/* reexport */ IndexedCollection),
|
|
47
47
|
IndexedObjectCollection: () => (/* reexport */ IndexedObjectCollection),
|
|
48
48
|
Layer: () => (/* reexport */ Layer),
|
|
49
|
+
MessageEmbedFlag: () => (/* reexport */ MessageEmbedFlag),
|
|
49
50
|
NO_LIMIT: () => (/* reexport */ NO_LIMIT),
|
|
50
51
|
ObservableIndexedCollection: () => (/* reexport */ ObservableIndexedCollection),
|
|
51
52
|
ObservableIndexedObjectCollection: () => (/* reexport */ ObservableIndexedObjectCollection),
|
|
@@ -58,6 +59,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
58
59
|
SearchRange: () => (/* reexport */ SearchRange),
|
|
59
60
|
SpaceFeature: () => (/* reexport */ SpaceFeature),
|
|
60
61
|
SpaceIntent: () => (/* reexport */ SpaceIntent),
|
|
62
|
+
TYPING_INTERVAL_MS: () => (/* reexport */ TYPING_INTERVAL_MS),
|
|
63
|
+
TYPING_TIMEOUT_MS: () => (/* reexport */ TYPING_TIMEOUT_MS),
|
|
61
64
|
UiPurpose: () => (/* reexport */ UiPurpose),
|
|
62
65
|
UserFeature: () => (/* reexport */ UserFeature),
|
|
63
66
|
UserStatus: () => (/* reexport */ UserStatus),
|
|
@@ -448,8 +451,116 @@ class PromiseRegistry {
|
|
|
448
451
|
this.promises.deleteAll();
|
|
449
452
|
}
|
|
450
453
|
}
|
|
454
|
+
;// ./src/protocol/schemes/PmParticipant.ts
|
|
455
|
+
let PmParticipantFlag = /*#__PURE__*/function (PmParticipantFlag) {
|
|
456
|
+
PmParticipantFlag[PmParticipantFlag["IgnoresRoom"] = 1] = "IgnoresRoom";
|
|
457
|
+
return PmParticipantFlag;
|
|
458
|
+
}({});
|
|
459
|
+
;// ./src/state-tracker/functions.ts
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @return New objects of the other roles whose priority has to move; the given roles are left intact.
|
|
464
|
+
*/
|
|
465
|
+
function reorderRolesOnPriorityUpdate(allRoles, oldRole, updatedRole) {
|
|
466
|
+
// If the priority has changed, adjust the rest of roles
|
|
467
|
+
const increased = updatedRole.priority - oldRole.priority > 0;
|
|
468
|
+
const decreased = !increased;
|
|
469
|
+
const changedRoles = [];
|
|
470
|
+
allRoles.forEach(role => {
|
|
471
|
+
if (role.id === updatedRole.id) {
|
|
472
|
+
// Skip the updated role
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (increased && oldRole.priority <= role.priority) {
|
|
476
|
+
changedRoles.push({
|
|
477
|
+
...role,
|
|
478
|
+
priority: role.priority - 1
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
if (decreased && updatedRole.priority <= role.priority) {
|
|
482
|
+
changedRoles.push({
|
|
483
|
+
...role,
|
|
484
|
+
priority: role.priority + 1
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
return changedRoles;
|
|
489
|
+
}
|
|
490
|
+
function extractUserFromMember(member) {
|
|
491
|
+
return member.user ?? member.spaceMember?.user;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Whether the room is a private group conversation - 3 or more participants, including the ones ignoring it.
|
|
496
|
+
*/
|
|
497
|
+
function isGroupPm(room) {
|
|
498
|
+
return room.type === 'Pm' && (room.participants?.length ?? 0) >= 3;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Participants of a private conversation taking part in it: without the ones ignoring it and without the user
|
|
503
|
+
* `meId`. Empty for notes and for rooms of spaces.
|
|
504
|
+
*/
|
|
505
|
+
function getPmPeers(room, meId) {
|
|
506
|
+
return getActivePmParticipants(room).filter(participant => participant.user.id !== meId);
|
|
507
|
+
}
|
|
508
|
+
function getActivePmParticipants(room) {
|
|
509
|
+
return (room.participants ?? []).filter(participant => !(participant.flags & PmParticipantFlag.IgnoresRoom));
|
|
510
|
+
}
|
|
511
|
+
function isSameUser(a, b) {
|
|
512
|
+
const keys = Object.keys(a);
|
|
513
|
+
if (keys.length !== Object.keys(b).length) {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
return keys.every(key => {
|
|
517
|
+
const valueA = a[key];
|
|
518
|
+
const valueB = b[key];
|
|
519
|
+
if (Array.isArray(valueA) && Array.isArray(valueB)) {
|
|
520
|
+
return valueA.length === valueB.length && valueA.every((item, index) => item === valueB[index]);
|
|
521
|
+
}
|
|
522
|
+
return valueA === valueB;
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* The counter arrives as the global source of truth - only it is overwritten, and a reaction nobody holds any more
|
|
528
|
+
* (count 0) leaves the message.
|
|
529
|
+
* @return Null when the reactions stay as they are.
|
|
530
|
+
*/
|
|
531
|
+
function applyReactionCounter(reactions, counter) {
|
|
532
|
+
const index = reactions.findIndex(reaction => reaction.type === counter.type && reaction.value === counter.value);
|
|
533
|
+
if (index === -1 && !counter.count) {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
const next = [...reactions];
|
|
537
|
+
if (index === -1) {
|
|
538
|
+
next.push(counter);
|
|
539
|
+
} else if (counter.count) {
|
|
540
|
+
next[index] = counter; // In place - a pill must not jump around as its counter moves
|
|
541
|
+
} else {
|
|
542
|
+
next.splice(index, 1);
|
|
543
|
+
}
|
|
544
|
+
return next;
|
|
545
|
+
}
|
|
546
|
+
function applyToggledReaction(own, toggled) {
|
|
547
|
+
const {
|
|
548
|
+
type,
|
|
549
|
+
value,
|
|
550
|
+
isAdded
|
|
551
|
+
} = toggled;
|
|
552
|
+
const next = own.filter(reaction => reaction.type !== type || reaction.value !== value);
|
|
553
|
+
if (isAdded) {
|
|
554
|
+
next.push({
|
|
555
|
+
type,
|
|
556
|
+
value
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
return next;
|
|
560
|
+
}
|
|
451
561
|
;// ./src/state-tracker/TopicHistoryWindow.ts
|
|
452
562
|
|
|
563
|
+
|
|
453
564
|
let WindowState = /*#__PURE__*/function (WindowState) {
|
|
454
565
|
/**
|
|
455
566
|
* The latest messages (those received live) are available in the history window, history has not been fetched.
|
|
@@ -827,6 +938,8 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
827
938
|
this.internalState.traverseLock = false;
|
|
828
939
|
this.internalState.includeMyReactions = !preview;
|
|
829
940
|
this.internalState.myReactions = {};
|
|
941
|
+
this.internalState.includeRepliedMessages = true;
|
|
942
|
+
this.internalState.repliedMessages = new Map();
|
|
830
943
|
this.internalState.liveLimit = 50;
|
|
831
944
|
}
|
|
832
945
|
createMirror() {
|
|
@@ -866,6 +979,32 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
866
979
|
this.internalState.includeMyReactions = value;
|
|
867
980
|
}
|
|
868
981
|
|
|
982
|
+
/**
|
|
983
|
+
* Whether the history is fetched together with the messages its messages reply to.
|
|
984
|
+
* Turn it off only where replies are never shown with what they reply to.
|
|
985
|
+
*/
|
|
986
|
+
get includeRepliedMessages() {
|
|
987
|
+
return this.internalState.includeRepliedMessages;
|
|
988
|
+
}
|
|
989
|
+
set includeRepliedMessages(value) {
|
|
990
|
+
this.internalState.includeRepliedMessages = value;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* The message the given one replies to: null when it replies to nothing or the replied message is gone,
|
|
995
|
+
* undefined when the window does not know it (replied messages are not fetched).
|
|
996
|
+
*/
|
|
997
|
+
getRepliedMessage(message) {
|
|
998
|
+
if (!message.replyTo) {
|
|
999
|
+
return null;
|
|
1000
|
+
}
|
|
1001
|
+
const replied = this.get(message.replyTo) ?? this.internalState.repliedMessages.get(message.replyTo);
|
|
1002
|
+
if (replied) {
|
|
1003
|
+
return replied;
|
|
1004
|
+
}
|
|
1005
|
+
return this.internalState.includeRepliedMessages ? null : undefined;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
869
1008
|
/**
|
|
870
1009
|
* Maximum number of items a window that has not been fetched yet (LIVE state) collects from the incoming
|
|
871
1010
|
* messages. Null for the same as {@link limit}. It keeps the windows of topics nobody looks at small;
|
|
@@ -930,14 +1069,21 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
930
1069
|
const continuousFrom = Math.max(0, ...this.internalState.gaps.map(id => items.findIndex(item => item.id === id)));
|
|
931
1070
|
const messages = items.slice(Math.max(continuousFrom, items.length - Math.max(limit, this.fetchLimit)));
|
|
932
1071
|
const myReactions = {};
|
|
1072
|
+
const exportedIds = new Set(messages.map(message => message.id));
|
|
1073
|
+
const repliedMessages = new Map();
|
|
933
1074
|
for (const message of messages) {
|
|
934
1075
|
if (this.internalState.myReactions[message.id]) {
|
|
935
1076
|
myReactions[message.id] = this.internalState.myReactions[message.id];
|
|
936
1077
|
}
|
|
1078
|
+
const replied = this.getRepliedMessage(message);
|
|
1079
|
+
if (replied && !exportedIds.has(replied.id)) {
|
|
1080
|
+
repliedMessages.set(replied.id, replied);
|
|
1081
|
+
}
|
|
937
1082
|
}
|
|
938
1083
|
return {
|
|
939
1084
|
messages,
|
|
940
|
-
myReactions
|
|
1085
|
+
myReactions,
|
|
1086
|
+
repliedMessages: [...repliedMessages.values()]
|
|
941
1087
|
};
|
|
942
1088
|
}
|
|
943
1089
|
|
|
@@ -946,12 +1092,13 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
946
1092
|
* them.
|
|
947
1093
|
* @internal
|
|
948
1094
|
*/
|
|
949
|
-
_restoreLatest(messages, myReactions) {
|
|
1095
|
+
_restoreLatest(messages, myReactions, repliedMessages) {
|
|
950
1096
|
const originalState = this.state;
|
|
951
1097
|
this.replaceItems(messages);
|
|
952
1098
|
this.internalState.myReactions = {
|
|
953
1099
|
...myReactions
|
|
954
1100
|
};
|
|
1101
|
+
this.storeRepliedMessages(messages, repliedMessages);
|
|
955
1102
|
this.internalState.current = WindowState.LATEST;
|
|
956
1103
|
this.emitChangeWithDiff(true, originalState);
|
|
957
1104
|
}
|
|
@@ -1002,12 +1149,14 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1002
1149
|
},
|
|
1003
1150
|
limit: this.internalState.fetchLimit,
|
|
1004
1151
|
includeMyReactions: this.internalState.includeMyReactions,
|
|
1152
|
+
includeRepliedMessages: this.internalState.includeRepliedMessages,
|
|
1005
1153
|
...criteria
|
|
1006
1154
|
});
|
|
1007
1155
|
if (result.error) {
|
|
1008
1156
|
throw new Error(`Cannot fetch messages: ${result.error.message}`);
|
|
1009
1157
|
}
|
|
1010
|
-
this.storeMyReactions(result.data.messages, result.data.myReactions);
|
|
1158
|
+
this.storeMyReactions(result.data.messages, result.data.myReactions ?? []);
|
|
1159
|
+
this.storeRepliedMessages(result.data.messages, result.data.repliedMessages ?? []);
|
|
1011
1160
|
return result.data.messages;
|
|
1012
1161
|
}
|
|
1013
1162
|
|
|
@@ -1023,15 +1172,63 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1023
1172
|
...this.internalState.myReactions
|
|
1024
1173
|
};
|
|
1025
1174
|
for (const message of messages) {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1175
|
+
delete next[message.id];
|
|
1176
|
+
}
|
|
1177
|
+
for (const own of myReactions) {
|
|
1178
|
+
if (own.reactions.length) {
|
|
1179
|
+
next[own.messageId] = own.reactions;
|
|
1031
1180
|
}
|
|
1032
1181
|
}
|
|
1033
1182
|
this.internalState.myReactions = next;
|
|
1034
1183
|
}
|
|
1184
|
+
|
|
1185
|
+
/**
|
|
1186
|
+
* The response is the truth for its replies: an original it leaves out is gone. The originals the page holds
|
|
1187
|
+
* itself are kept too, as the window may drop them while their replies stay.
|
|
1188
|
+
*/
|
|
1189
|
+
storeRepliedMessages(incoming, repliedMessages) {
|
|
1190
|
+
if (!this.internalState.includeRepliedMessages) {
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
const fromResponse = new Map();
|
|
1194
|
+
for (const message of [...incoming, ...repliedMessages]) {
|
|
1195
|
+
fromResponse.set(message.id, message);
|
|
1196
|
+
}
|
|
1197
|
+
const stored = this.internalState.repliedMessages;
|
|
1198
|
+
const kept = new Map();
|
|
1199
|
+
for (const message of incoming) {
|
|
1200
|
+
const replied = message.replyTo ? fromResponse.get(message.replyTo) : undefined;
|
|
1201
|
+
if (replied) {
|
|
1202
|
+
kept.set(replied.id, replied);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
for (const message of this.items) {
|
|
1206
|
+
if (!message.replyTo || fromResponse.has(message.id) || kept.has(message.replyTo)) {
|
|
1207
|
+
continue;
|
|
1208
|
+
}
|
|
1209
|
+
const replied = stored.get(message.replyTo) ?? this.get(message.replyTo);
|
|
1210
|
+
if (replied) {
|
|
1211
|
+
kept.set(replied.id, replied);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
this.internalState.repliedMessages = kept;
|
|
1215
|
+
}
|
|
1216
|
+
emitChange(setItems) {
|
|
1217
|
+
if (setItems.length) {
|
|
1218
|
+
this.eventTarget.emit('change', {
|
|
1219
|
+
setItems
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
repliesTo(repliedIds) {
|
|
1224
|
+
const replyIds = [];
|
|
1225
|
+
for (const message of this.items) {
|
|
1226
|
+
if (message.replyTo && repliedIds.has(message.replyTo)) {
|
|
1227
|
+
replyIds.push(message.id);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
return replyIds;
|
|
1231
|
+
}
|
|
1035
1232
|
async getTopic() {
|
|
1036
1233
|
if (this.preview) {
|
|
1037
1234
|
// The tracker holds the topics of the joined rooms only
|
|
@@ -1063,7 +1260,15 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1063
1260
|
return;
|
|
1064
1261
|
}
|
|
1065
1262
|
const limit = this.state === WindowState.LIVE && !this.internalState.traverseLock ? this.internalState.liveLimit ?? this.limit : this.limit;
|
|
1263
|
+
if (ev.repliedMessage && this.internalState.includeRepliedMessages) {
|
|
1264
|
+
this.internalState.repliedMessages.set(ev.repliedMessage.id, ev.repliedMessage);
|
|
1265
|
+
}
|
|
1066
1266
|
const deletedItems = this.addItems([ev.message], 'tail', limit);
|
|
1267
|
+
|
|
1268
|
+
// Pruned only once the store outgrows the window, not on every message that pushes one out
|
|
1269
|
+
if (deletedItems.length && this.internalState.repliedMessages.size > this.length) {
|
|
1270
|
+
this.storeRepliedMessages([], []);
|
|
1271
|
+
}
|
|
1067
1272
|
this.eventTarget.emit('change', deletedItems.length ? {
|
|
1068
1273
|
setItems: [ev.message.id],
|
|
1069
1274
|
deletedItems
|
|
@@ -1080,25 +1285,13 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1080
1285
|
*/
|
|
1081
1286
|
_handleReactionUpdated(ev) {
|
|
1082
1287
|
const message = this.get(ev.messageId);
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
}
|
|
1090
|
-
const reactions = [...message.reactions];
|
|
1091
|
-
if (index === -1) {
|
|
1092
|
-
reactions.push(ev.reaction);
|
|
1093
|
-
} else if (ev.reaction.count) {
|
|
1094
|
-
reactions[index] = ev.reaction; // In place - a pill must not jump around as its counter moves
|
|
1095
|
-
} else {
|
|
1096
|
-
reactions.splice(index, 1);
|
|
1288
|
+
const reactions = message ? applyReactionCounter(message.reactions, ev.reaction) : null;
|
|
1289
|
+
if (reactions) {
|
|
1290
|
+
this.set({
|
|
1291
|
+
...message,
|
|
1292
|
+
reactions
|
|
1293
|
+
});
|
|
1097
1294
|
}
|
|
1098
|
-
this.set({
|
|
1099
|
-
...message,
|
|
1100
|
-
reactions
|
|
1101
|
-
});
|
|
1102
1295
|
}
|
|
1103
1296
|
|
|
1104
1297
|
/**
|
|
@@ -1109,18 +1302,7 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1109
1302
|
if (!this.has(ev.messageId)) {
|
|
1110
1303
|
return;
|
|
1111
1304
|
}
|
|
1112
|
-
const
|
|
1113
|
-
type,
|
|
1114
|
-
value,
|
|
1115
|
-
isAdded
|
|
1116
|
-
} = ev.reaction;
|
|
1117
|
-
const own = (this.internalState.myReactions[ev.messageId] ?? []).filter(reaction => reaction.type !== type || reaction.value !== value);
|
|
1118
|
-
if (isAdded) {
|
|
1119
|
-
own.push({
|
|
1120
|
-
type,
|
|
1121
|
-
value
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1305
|
+
const own = applyToggledReaction(this.internalState.myReactions[ev.messageId] ?? [], ev.reaction);
|
|
1124
1306
|
|
|
1125
1307
|
// Not `{[ev.messageId]: _, ...rest}` - Babel's loose object rest drops the key when the binding is unused (babel/babel#18196)
|
|
1126
1308
|
const myReactions = {
|
|
@@ -1136,13 +1318,39 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1136
1318
|
});
|
|
1137
1319
|
}
|
|
1138
1320
|
|
|
1321
|
+
/**
|
|
1322
|
+
* Replaces a loaded message, also where it is kept as a replied one.
|
|
1323
|
+
* For internal use.
|
|
1324
|
+
* @internal
|
|
1325
|
+
*/
|
|
1326
|
+
_handleMessageUpdated(ev) {
|
|
1327
|
+
const {
|
|
1328
|
+
message
|
|
1329
|
+
} = ev;
|
|
1330
|
+
const loaded = this.has(message.id);
|
|
1331
|
+
const kept = this.internalState.repliedMessages.has(message.id);
|
|
1332
|
+
if (loaded) {
|
|
1333
|
+
this.set(message);
|
|
1334
|
+
}
|
|
1335
|
+
if (kept) {
|
|
1336
|
+
this.internalState.repliedMessages.set(message.id, message);
|
|
1337
|
+
}
|
|
1338
|
+
if (loaded || kept) {
|
|
1339
|
+
this.emitChange(this.repliesTo(new Set([message.id])));
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1139
1343
|
/**
|
|
1140
1344
|
* For internal use.
|
|
1141
1345
|
* @internal
|
|
1142
1346
|
*/
|
|
1143
1347
|
async _handleMessagesRedacted(ev) {
|
|
1144
1348
|
const refTopicIds = this.items.filter(msg => msg.topicRef && ev.ids.includes(msg.id)).map(msg => msg.topicRef);
|
|
1349
|
+
const redactedOriginals = new Set(ev.ids.filter(id => this.internalState.repliedMessages.delete(id) || this.has(id)));
|
|
1145
1350
|
this.delete(...ev.ids);
|
|
1351
|
+
if (redactedOriginals.size) {
|
|
1352
|
+
this.emitChange(this.repliesTo(redactedOriginals));
|
|
1353
|
+
}
|
|
1146
1354
|
if (this.length === 0) {
|
|
1147
1355
|
await this.resetToLatest();
|
|
1148
1356
|
}
|
|
@@ -1266,9 +1474,9 @@ class RoomMessagesHistory {
|
|
|
1266
1474
|
* For internal use.
|
|
1267
1475
|
* @internal
|
|
1268
1476
|
*/
|
|
1269
|
-
_restoreWindow(topic, messages, myReactions) {
|
|
1477
|
+
_restoreWindow(topic, messages, myReactions, repliedMessages) {
|
|
1270
1478
|
this.createHistoryWindowForTopic(topic);
|
|
1271
|
-
this.historyWindows.get(topic.id)._restoreLatest(messages, myReactions);
|
|
1479
|
+
this.historyWindows.get(topic.id)._restoreLatest(messages, myReactions, repliedMessages);
|
|
1272
1480
|
}
|
|
1273
1481
|
|
|
1274
1482
|
/**
|
|
@@ -1318,6 +1526,14 @@ class RoomMessagesHistory {
|
|
|
1318
1526
|
void this.historyWindows.get(ev.location.topicId)?._handleMessagesRedacted(ev);
|
|
1319
1527
|
}
|
|
1320
1528
|
|
|
1529
|
+
/**
|
|
1530
|
+
* For internal use.
|
|
1531
|
+
* @internal
|
|
1532
|
+
*/
|
|
1533
|
+
_handleMessageUpdated(ev) {
|
|
1534
|
+
this.historyWindows.get(ev.message.location.topicId)?._handleMessageUpdated(ev);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1321
1537
|
/**
|
|
1322
1538
|
* For internal use.
|
|
1323
1539
|
* @internal
|
|
@@ -1389,6 +1605,7 @@ class MessagesManager {
|
|
|
1389
1605
|
this.tracker.client.on('NewTopic', ev => this.roomHistories.get(ev.roomId)?._handleNewTopic(ev));
|
|
1390
1606
|
this.tracker.client.on('TopicDeleted', ev => this.roomHistories.get(ev.location.roomId)?._handleTopicDeleted(ev));
|
|
1391
1607
|
this.tracker.client.on('NewMessage', ev => this.roomHistories.get(ev.message.location.roomId)?._handleNewMessage(ev));
|
|
1608
|
+
this.tracker.client.on('MessageUpdated', ev => this.roomHistories.get(ev.message.location.roomId)?._handleMessageUpdated(ev));
|
|
1392
1609
|
this.tracker.client.on('MessagesRedacted', ev => this.roomHistories.get(ev.location.roomId)?._handleMessagesRedacted(ev));
|
|
1393
1610
|
this.tracker.client.on('ReactionUpdated', ev => this.forEachRoomHistory(history => history._handleReactionUpdated(ev)));
|
|
1394
1611
|
this.tracker.client.on('Reacted', ev => this.forEachRoomHistory(history => history._handleReacted(ev)));
|
|
@@ -1464,7 +1681,7 @@ class MessagesManager {
|
|
|
1464
1681
|
const history = this.roomHistories.get(roomId);
|
|
1465
1682
|
if (history && !history._isEphemeral) {
|
|
1466
1683
|
const messages = snapshot.messages.filter(message => message.location.roomId === roomId && message.location.topicId === topic.id);
|
|
1467
|
-
history._restoreWindow(topic, messages, snapshot.myReactions);
|
|
1684
|
+
history._restoreWindow(topic, messages, snapshot.myReactions, snapshot.repliedMessages);
|
|
1468
1685
|
}
|
|
1469
1686
|
}
|
|
1470
1687
|
forEachRoomHistory(callback) {
|
|
@@ -1928,6 +2145,129 @@ class FollowedTopicsManager extends EventTarget {
|
|
|
1928
2145
|
this.invalidateUnreadSummaries(roomId);
|
|
1929
2146
|
}
|
|
1930
2147
|
}
|
|
2148
|
+
;// ./src/state-tracker/TypingManager.ts
|
|
2149
|
+
|
|
2150
|
+
const TYPING_INTERVAL_MS = 5000;
|
|
2151
|
+
const TYPING_TIMEOUT_MS = 2 * TYPING_INTERVAL_MS;
|
|
2152
|
+
|
|
2153
|
+
/**
|
|
2154
|
+
* Ids of the users typing in a topic, each mapped to the time (`Date.now()`) its typing expires at.
|
|
2155
|
+
*/
|
|
2156
|
+
|
|
2157
|
+
class TypingManager {
|
|
2158
|
+
topics = new IndexedCollection();
|
|
2159
|
+
lastSentAt = new Map();
|
|
2160
|
+
constructor(tracker) {
|
|
2161
|
+
this.tracker = tracker;
|
|
2162
|
+
this.tracker.client.on('Typing', ev => this.handleTyping(ev));
|
|
2163
|
+
this.tracker.client.on('NewMessage', ev => this.handleNewMessage(ev));
|
|
2164
|
+
this.tracker.client.on('TopicDeleted', ev => this.handleTopicDeleted(ev));
|
|
2165
|
+
this.tracker.client.on('RoomLeft', ev => this.handleRoomGone(ev));
|
|
2166
|
+
this.tracker.client.on('RoomDeleted', ev => this.handleRoomGone(ev));
|
|
2167
|
+
this.tracker.client.on('Session', () => this.handleSession());
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
/**
|
|
2171
|
+
* Users typing in the topic, without you. Tracking of the topic starts with the first call, so the collection
|
|
2172
|
+
* fills up with the next notifications, within {@link TYPING_INTERVAL_MS}. A user leaves it
|
|
2173
|
+
* {@link TYPING_TIMEOUT_MS} after their last notification or at once with their message in the topic.
|
|
2174
|
+
* Only ids are kept - resolve the users yourself, e.g. from {@link RoomsManager.getMembers}.
|
|
2175
|
+
*/
|
|
2176
|
+
get(roomId, topicId) {
|
|
2177
|
+
if (!this.topics.has(topicId)) {
|
|
2178
|
+
this.topics.set([topicId, {
|
|
2179
|
+
roomId,
|
|
2180
|
+
users: new ObservableIndexedCollection()
|
|
2181
|
+
}]);
|
|
2182
|
+
}
|
|
2183
|
+
return this.topics.get(topicId).users;
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
/**
|
|
2187
|
+
* Tell the other members of the room that you are typing in the topic. Call it on every change of the text:
|
|
2188
|
+
* the command is sent at most once per {@link TYPING_INTERVAL_MS} for a topic, and again right after your
|
|
2189
|
+
* message in it. Classic rooms do not support typing.
|
|
2190
|
+
*/
|
|
2191
|
+
notify(roomId, topicId) {
|
|
2192
|
+
const now = Date.now();
|
|
2193
|
+
if (now - (this.lastSentAt.get(topicId) ?? -Infinity) < TYPING_INTERVAL_MS) {
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
this.lastSentAt.set(topicId, now);
|
|
2197
|
+
this.tracker.client.send('Type', {
|
|
2198
|
+
location: {
|
|
2199
|
+
roomId,
|
|
2200
|
+
topicId
|
|
2201
|
+
}
|
|
2202
|
+
}).catch(() => undefined);
|
|
2203
|
+
}
|
|
2204
|
+
handleTyping(ev) {
|
|
2205
|
+
const topic = this.topics.get(ev.location.topicId);
|
|
2206
|
+
if (!topic || ev.userId === this.tracker.me?.id) {
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
topic.users.set([ev.userId, Date.now() + TYPING_TIMEOUT_MS]);
|
|
2210
|
+
this.scheduleExpiry(topic);
|
|
2211
|
+
}
|
|
2212
|
+
handleNewMessage(ev) {
|
|
2213
|
+
const topicId = ev.message.location.topicId;
|
|
2214
|
+
const authorId = ev.message.author.user.id;
|
|
2215
|
+
if (authorId === this.tracker.me?.id) {
|
|
2216
|
+
this.lastSentAt.delete(topicId);
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
const topic = this.topics.get(topicId);
|
|
2220
|
+
if (topic?.users.has(authorId)) {
|
|
2221
|
+
topic.users.delete(authorId);
|
|
2222
|
+
this.scheduleExpiry(topic);
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
handleTopicDeleted(ev) {
|
|
2226
|
+
this.clear(ev.location.topicId);
|
|
2227
|
+
}
|
|
2228
|
+
handleRoomGone(ev) {
|
|
2229
|
+
for (const [topicId, topic] of this.topics.items.entries()) {
|
|
2230
|
+
if (topic.roomId === ev.id) {
|
|
2231
|
+
this.clear(topicId);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
handleSession() {
|
|
2236
|
+
this.lastSentAt.clear();
|
|
2237
|
+
for (const topic of this.topics.items.values()) {
|
|
2238
|
+
clearTimeout(topic.timer);
|
|
2239
|
+
topic.users.deleteAll();
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
clear(topicId) {
|
|
2243
|
+
const topic = this.topics.get(topicId);
|
|
2244
|
+
if (topic) {
|
|
2245
|
+
clearTimeout(topic.timer);
|
|
2246
|
+
topic.users.deleteAll();
|
|
2247
|
+
}
|
|
2248
|
+
this.lastSentAt.delete(topicId);
|
|
2249
|
+
}
|
|
2250
|
+
scheduleExpiry(topic) {
|
|
2251
|
+
clearTimeout(topic.timer);
|
|
2252
|
+
topic.timer = undefined;
|
|
2253
|
+
if (!topic.users.length) {
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
const nextExpiry = Math.min(...topic.users.items.values());
|
|
2257
|
+
topic.timer = setTimeout(() => this.expire(topic), Math.max(0, nextExpiry - Date.now()));
|
|
2258
|
+
}
|
|
2259
|
+
expire(topic) {
|
|
2260
|
+
const now = Date.now();
|
|
2261
|
+
const expiredIds = [];
|
|
2262
|
+
for (const [userId, expiresAt] of topic.users.items.entries()) {
|
|
2263
|
+
if (expiresAt <= now) {
|
|
2264
|
+
expiredIds.push(userId);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
topic.users.delete(...expiredIds);
|
|
2268
|
+
this.scheduleExpiry(topic);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
1931
2271
|
;// ./src/protocol/schemes/User.ts
|
|
1932
2272
|
/**
|
|
1933
2273
|
* Availability of a user, aggregated over all of their sessions.
|
|
@@ -1949,7 +2289,7 @@ let UserStatus = /*#__PURE__*/function (UserStatus) {
|
|
|
1949
2289
|
/**
|
|
1950
2290
|
* Version of the {@link StateSnapshot} format. A snapshot of any other version is rejected on import.
|
|
1951
2291
|
*/
|
|
1952
|
-
const STATE_SNAPSHOT_VERSION =
|
|
2292
|
+
const STATE_SNAPSHOT_VERSION = 3;
|
|
1953
2293
|
|
|
1954
2294
|
/**
|
|
1955
2295
|
* Plain, JSON-serializable copy of the state tracked by {@link ChatStateTracker}, made to restore the state at the
|
|
@@ -2059,7 +2399,7 @@ function isUserReactions(value) {
|
|
|
2059
2399
|
return isObject(value) && Object.values(value).every(reactions => isArrayOf(reactions, isObject));
|
|
2060
2400
|
}
|
|
2061
2401
|
function isTopicHistory(value) {
|
|
2062
|
-
return isObject(value) && isString(value.roomId) && isString(value.topicId) && isArrayOf(value.messages, isFullMessage) && isUserReactions(value.myReactions) && isArrayOf(value.topics, isTopic);
|
|
2402
|
+
return isObject(value) && isString(value.roomId) && isString(value.topicId) && isArrayOf(value.messages, isFullMessage) && isUserReactions(value.myReactions) && isArrayOf(value.repliedMessages, isFullMessage) && isArrayOf(value.topics, isTopic);
|
|
2063
2403
|
}
|
|
2064
2404
|
function isRoomMember(value) {
|
|
2065
2405
|
return isObject(value) && (isUser(value.user) || isObject(value.spaceMember) && isUser(value.spaceMember.user));
|
|
@@ -2067,77 +2407,6 @@ function isRoomMember(value) {
|
|
|
2067
2407
|
function isRoomMembers(value) {
|
|
2068
2408
|
return isObject(value) && isString(value.roomId) && isArrayOf(value.members, isRoomMember);
|
|
2069
2409
|
}
|
|
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
|
-
}
|
|
2141
2410
|
;// ./src/state-tracker/RoomsManager.ts
|
|
2142
2411
|
|
|
2143
2412
|
|
|
@@ -2145,9 +2414,11 @@ function isSameUser(a, b) {
|
|
|
2145
2414
|
|
|
2146
2415
|
|
|
2147
2416
|
|
|
2417
|
+
|
|
2148
2418
|
class RoomsManager {
|
|
2149
2419
|
messages;
|
|
2150
2420
|
followedTopics;
|
|
2421
|
+
typing;
|
|
2151
2422
|
list = new ObservableIndexedObjectCollection('id');
|
|
2152
2423
|
topics = new IndexedCollection();
|
|
2153
2424
|
members = new IndexedCollection();
|
|
@@ -2155,12 +2426,18 @@ class RoomsManager {
|
|
|
2155
2426
|
membersPromises = new PromiseRegistry();
|
|
2156
2427
|
topicsPromises = new PromiseRegistry();
|
|
2157
2428
|
importedTopicIds = new Map();
|
|
2429
|
+
stickyMyReactions = new ObservableIndexedObjectCollection('messageId');
|
|
2430
|
+
stickyMyReactionsPromises = new PromiseRegistry();
|
|
2158
2431
|
constructor(tracker) {
|
|
2159
2432
|
this.tracker = tracker;
|
|
2160
2433
|
this.messages = new MessagesManager(tracker);
|
|
2161
2434
|
this.followedTopics = new FollowedTopicsManager(tracker);
|
|
2435
|
+
this.typing = new TypingManager(tracker);
|
|
2162
2436
|
this.tracker.client.on('NewMessage', ev => this.handleNewMessage(ev));
|
|
2163
2437
|
this.tracker.client.on('MessagesRedacted', ev => this.handleMessagesRedacted(ev));
|
|
2438
|
+
this.tracker.client.on('MessageUpdated', ev => this.handleMessageUpdated(ev));
|
|
2439
|
+
this.tracker.client.on('ReactionUpdated', ev => this.handleReactionUpdated(ev));
|
|
2440
|
+
this.tracker.client.on('Reacted', ev => this.handleReacted(ev));
|
|
2164
2441
|
this.tracker.client.on('NewTopic', ev => this.handleNewTopic(ev));
|
|
2165
2442
|
this.tracker.client.on('TopicDeleted', ev => this.handleTopicDeleted(ev));
|
|
2166
2443
|
this.tracker.client.on('RoomJoined', ev => this.handleRoomJoined(ev));
|
|
@@ -2199,6 +2476,34 @@ class RoomsManager {
|
|
|
2199
2476
|
return this.members.get(roomId);
|
|
2200
2477
|
}
|
|
2201
2478
|
|
|
2479
|
+
/**
|
|
2480
|
+
* Get the reactions of the connected user on sticky messages, keyed by message id. A sticky message comes with its
|
|
2481
|
+
* topic, outside of the message history, so the reactions of the given one are fetched once and then follow
|
|
2482
|
+
* the reactions of the user.
|
|
2483
|
+
*/
|
|
2484
|
+
async getStickyMyReactions(location, messageId) {
|
|
2485
|
+
if (this.stickyMyReactionsPromises.notExist(messageId)) {
|
|
2486
|
+
this.stickyMyReactionsPromises.registerByFunction(async () => {
|
|
2487
|
+
const result = await this.tracker.client.send('GetMessages', {
|
|
2488
|
+
location,
|
|
2489
|
+
around: messageId,
|
|
2490
|
+
limit: 1,
|
|
2491
|
+
includeMyReactions: true
|
|
2492
|
+
});
|
|
2493
|
+
if (result.error) {
|
|
2494
|
+
throw result.error;
|
|
2495
|
+
}
|
|
2496
|
+
const own = result.data.myReactions?.find(item => item.messageId === messageId);
|
|
2497
|
+
this.stickyMyReactions.set({
|
|
2498
|
+
messageId,
|
|
2499
|
+
reactions: own?.reactions ?? []
|
|
2500
|
+
});
|
|
2501
|
+
}, messageId);
|
|
2502
|
+
}
|
|
2503
|
+
await this.stickyMyReactionsPromises.get(messageId);
|
|
2504
|
+
return this.stickyMyReactions;
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2202
2507
|
/**
|
|
2203
2508
|
* Get a room member representing the current user.
|
|
2204
2509
|
*/
|
|
@@ -2324,6 +2629,7 @@ class RoomsManager {
|
|
|
2324
2629
|
topicId,
|
|
2325
2630
|
messages: latest.messages.map(messageWithoutPresence),
|
|
2326
2631
|
myReactions: latest.myReactions,
|
|
2632
|
+
repliedMessages: latest.repliedMessages.map(messageWithoutPresence),
|
|
2327
2633
|
topics: Array.from(topicIds).filter(id => topics?.has(id)).map(id => topics.get(id))
|
|
2328
2634
|
});
|
|
2329
2635
|
}
|
|
@@ -2551,6 +2857,9 @@ class RoomsManager {
|
|
|
2551
2857
|
extras: ''
|
|
2552
2858
|
};
|
|
2553
2859
|
});
|
|
2860
|
+
|
|
2861
|
+
// GetRoomMembers is not supported for private conversations
|
|
2862
|
+
this.membersPromises.register(Promise.resolve(), room.id);
|
|
2554
2863
|
if (current?.length === members.length && members.every(member => current.get(member.user.id) === member)) {
|
|
2555
2864
|
return;
|
|
2556
2865
|
}
|
|
@@ -2558,8 +2867,6 @@ class RoomsManager {
|
|
|
2558
2867
|
id: room.id,
|
|
2559
2868
|
members
|
|
2560
2869
|
});
|
|
2561
|
-
// GetRoomMembers is not supported for private conversations
|
|
2562
|
-
this.membersPromises.register(Promise.resolve(), room.id);
|
|
2563
2870
|
}
|
|
2564
2871
|
handleRoomLeft(ev) {
|
|
2565
2872
|
this.deleteRoom(ev.id);
|
|
@@ -2599,6 +2906,8 @@ class RoomsManager {
|
|
|
2599
2906
|
// so bound views refresh in place without blanking.
|
|
2600
2907
|
this.membersPromises.forgetAll();
|
|
2601
2908
|
this.topicsPromises.forgetAll();
|
|
2909
|
+
// Reactions could change meanwhile, and missed changes never arrive
|
|
2910
|
+
this.stickyMyReactionsPromises.forgetAll();
|
|
2602
2911
|
|
|
2603
2912
|
// Upsert surviving/new rooms from the authoritative snapshot.
|
|
2604
2913
|
this.addJoinedRooms(...ev.state.rooms);
|
|
@@ -2641,6 +2950,10 @@ class RoomsManager {
|
|
|
2641
2950
|
this.list.set(...newRooms);
|
|
2642
2951
|
}
|
|
2643
2952
|
handleNewMessage(ev) {
|
|
2953
|
+
// Shown to one user and never stored, so it is neither counted nor the last message of the topic
|
|
2954
|
+
if (ev.message.type === 'Ephemeral') {
|
|
2955
|
+
return;
|
|
2956
|
+
}
|
|
2644
2957
|
const topics = this.topics.get(ev.message.location.roomId);
|
|
2645
2958
|
const topic = topics?.get(ev.message.location.topicId);
|
|
2646
2959
|
if (!topic) {
|
|
@@ -2649,22 +2962,79 @@ class RoomsManager {
|
|
|
2649
2962
|
const newTopic = {
|
|
2650
2963
|
...topic,
|
|
2651
2964
|
messageCount: topic.messageCount + 1,
|
|
2652
|
-
lastMessage: ev.message
|
|
2965
|
+
lastMessage: ev.message,
|
|
2966
|
+
stickyMessage: ev.sticky ? ev.message : topic.stickyMessage
|
|
2653
2967
|
};
|
|
2654
2968
|
topics.set(newTopic);
|
|
2655
2969
|
this.updatePmDefaultTopic(ev.message.location.roomId, newTopic);
|
|
2656
2970
|
}
|
|
2971
|
+
handleMessageUpdated(ev) {
|
|
2972
|
+
const topics = this.topics.get(ev.message.location.roomId);
|
|
2973
|
+
const refTopic = ev.message.topicRef ? topics?.get(ev.message.topicRef) : undefined;
|
|
2974
|
+
if (refTopic?.refMessage?.id === ev.message.id) {
|
|
2975
|
+
topics.set({
|
|
2976
|
+
...refTopic,
|
|
2977
|
+
refMessage: ev.message
|
|
2978
|
+
});
|
|
2979
|
+
}
|
|
2980
|
+
const topic = topics?.get(ev.message.location.topicId);
|
|
2981
|
+
const isLast = topic?.lastMessage?.id === ev.message.id;
|
|
2982
|
+
const isSticky = topic?.stickyMessage?.id === ev.message.id;
|
|
2983
|
+
if (!topic || !isLast && !isSticky) {
|
|
2984
|
+
return;
|
|
2985
|
+
}
|
|
2986
|
+
const newTopic = {
|
|
2987
|
+
...topic,
|
|
2988
|
+
lastMessage: isLast ? ev.message : topic.lastMessage,
|
|
2989
|
+
stickyMessage: isSticky ? ev.message : topic.stickyMessage
|
|
2990
|
+
};
|
|
2991
|
+
topics.set(newTopic);
|
|
2992
|
+
this.updatePmDefaultTopic(ev.message.location.roomId, newTopic);
|
|
2993
|
+
}
|
|
2994
|
+
handleReactionUpdated(ev) {
|
|
2995
|
+
for (const [roomId, topics] of this.topics.items) {
|
|
2996
|
+
for (const topic of topics.items) {
|
|
2997
|
+
const reactions = topic.stickyMessage?.id === ev.messageId ? applyReactionCounter(topic.stickyMessage.reactions, ev.reaction) : null;
|
|
2998
|
+
if (reactions) {
|
|
2999
|
+
const newTopic = {
|
|
3000
|
+
...topic,
|
|
3001
|
+
stickyMessage: {
|
|
3002
|
+
...topic.stickyMessage,
|
|
3003
|
+
reactions
|
|
3004
|
+
}
|
|
3005
|
+
};
|
|
3006
|
+
topics.set(newTopic);
|
|
3007
|
+
this.updatePmDefaultTopic(roomId, newTopic);
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
handleReacted(ev) {
|
|
3013
|
+
const own = this.stickyMyReactions.get(ev.messageId);
|
|
3014
|
+
if (own) {
|
|
3015
|
+
this.stickyMyReactions.set({
|
|
3016
|
+
messageId: own.messageId,
|
|
3017
|
+
reactions: applyToggledReaction(own.reactions, ev.reaction)
|
|
3018
|
+
});
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
2657
3021
|
async handleMessagesRedacted(ev) {
|
|
3022
|
+
this.stickyMyReactions.delete(...ev.ids);
|
|
3023
|
+
|
|
2658
3024
|
// Remove redacted messages from topic and update metadata
|
|
2659
3025
|
const topics = this.topics.get(ev.location.roomId);
|
|
2660
3026
|
const topic = topics?.get(ev.location.topicId);
|
|
2661
3027
|
if (topic) {
|
|
2662
3028
|
const messageCount = Math.max(topic.messageCount - ev.ids.length, 0);
|
|
2663
3029
|
const lastMessage = messageCount > 0 ? await this.messages._resolveLastMessage(ev.location) : null;
|
|
3030
|
+
// Read after the await - a message stuck meanwhile must not be replaced with the stale one
|
|
3031
|
+
const currentSticky = (topics.get(ev.location.topicId) ?? topic).stickyMessage;
|
|
3032
|
+
const stickyMessage = ev.ids.includes(currentSticky?.id) ? null : currentSticky;
|
|
2664
3033
|
const newTopic = {
|
|
2665
3034
|
...topic,
|
|
2666
3035
|
messageCount,
|
|
2667
|
-
lastMessage
|
|
3036
|
+
lastMessage,
|
|
3037
|
+
stickyMessage
|
|
2668
3038
|
};
|
|
2669
3039
|
topics.set(newTopic);
|
|
2670
3040
|
this.updatePmDefaultTopic(ev.location.roomId, newTopic);
|
|
@@ -2874,6 +3244,13 @@ class SpacesManager {
|
|
|
2874
3244
|
}
|
|
2875
3245
|
handleRoleDeleted(ev) {
|
|
2876
3246
|
this.roles.get(ev.spaceId).delete(ev.id);
|
|
3247
|
+
const space = this.list.get(ev.spaceId);
|
|
3248
|
+
if (space?.guestRole === ev.id) {
|
|
3249
|
+
this.list.set({
|
|
3250
|
+
...space,
|
|
3251
|
+
guestRole: null
|
|
3252
|
+
});
|
|
3253
|
+
}
|
|
2877
3254
|
this.syncSpaceRoles(ev.spaceId);
|
|
2878
3255
|
}
|
|
2879
3256
|
|
|
@@ -3111,7 +3488,7 @@ class Permissions {
|
|
|
3111
3488
|
value: 1 << 18,
|
|
3112
3489
|
maxLayer: Layer.Room
|
|
3113
3490
|
},
|
|
3114
|
-
|
|
3491
|
+
ManageMessages: {
|
|
3115
3492
|
value: 1 << 19,
|
|
3116
3493
|
maxLayer: Layer.Topic
|
|
3117
3494
|
},
|
|
@@ -3142,6 +3519,18 @@ class Permissions {
|
|
|
3142
3519
|
UseExternalEmoticons: {
|
|
3143
3520
|
value: 1 << 26,
|
|
3144
3521
|
maxLayer: Layer.Room
|
|
3522
|
+
},
|
|
3523
|
+
ManagePins: {
|
|
3524
|
+
value: 1 << 27,
|
|
3525
|
+
maxLayer: Layer.Topic
|
|
3526
|
+
},
|
|
3527
|
+
SendAttachments: {
|
|
3528
|
+
value: 1 << 28,
|
|
3529
|
+
maxLayer: Layer.Topic
|
|
3530
|
+
},
|
|
3531
|
+
EditMessages: {
|
|
3532
|
+
value: 1 << 29,
|
|
3533
|
+
maxLayer: Layer.Topic
|
|
3145
3534
|
}
|
|
3146
3535
|
};
|
|
3147
3536
|
static getNames() {
|
|
@@ -3275,7 +3664,7 @@ class PermissionsManager extends EventTarget {
|
|
|
3275
3664
|
userId
|
|
3276
3665
|
}).then(v => v.overwrites));
|
|
3277
3666
|
}
|
|
3278
|
-
return this.resolveOverwritesHierarchy(await Promise.all(promises));
|
|
3667
|
+
return this.resolveOverwritesHierarchy([].concat(...(await Promise.all(promises))));
|
|
3279
3668
|
}
|
|
3280
3669
|
|
|
3281
3670
|
/**
|
|
@@ -3352,34 +3741,22 @@ class PermissionsManager extends EventTarget {
|
|
|
3352
3741
|
type: 'Role',
|
|
3353
3742
|
roleId
|
|
3354
3743
|
})));
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
const revDecAllows = overwrites.allow?.toString(2).split('').reverse().join('') ?? '';
|
|
3369
|
-
for (let i = 0; i < permissionsLength; i++) {
|
|
3370
|
-
const deny = parseInt(revDecDenies[i] ?? '0');
|
|
3371
|
-
const allow = parseInt(revDecAllows[i] ?? '0');
|
|
3372
|
-
if (deny) {
|
|
3373
|
-
denies |= 1 << i;
|
|
3374
|
-
}
|
|
3375
|
-
if (allow) {
|
|
3376
|
-
allows |= 1 << i;
|
|
3377
|
-
}
|
|
3378
|
-
}
|
|
3379
|
-
});
|
|
3744
|
+
// The space default role (everyone) has the space id; it is applied before the other roles, as on the server.
|
|
3745
|
+
const isDefaultRole = overwrites => overwrites.target.roleId === location.spaceId;
|
|
3746
|
+
return [this.mergeRolesOverwrites(roleOverwrites.filter(isDefaultRole)), this.mergeRolesOverwrites(roleOverwrites.filter(overwrites => !isDefaultRole(overwrites)))];
|
|
3747
|
+
}
|
|
3748
|
+
mergeRolesOverwrites(rolesOverwrites) {
|
|
3749
|
+
let allow = 0,
|
|
3750
|
+
deny = 0;
|
|
3751
|
+
for (const {
|
|
3752
|
+
overwrites
|
|
3753
|
+
} of rolesOverwrites) {
|
|
3754
|
+
allow |= overwrites.allow ?? 0;
|
|
3755
|
+
deny |= overwrites.deny ?? 0;
|
|
3756
|
+
}
|
|
3380
3757
|
return {
|
|
3381
|
-
allow
|
|
3382
|
-
deny
|
|
3758
|
+
allow,
|
|
3759
|
+
deny
|
|
3383
3760
|
};
|
|
3384
3761
|
}
|
|
3385
3762
|
resolveOverwritesHierarchy(permissionOverwritesValues) {
|
|
@@ -4336,12 +4713,20 @@ let ErrorCode = /*#__PURE__*/function (ErrorCode) {
|
|
|
4336
4713
|
ErrorCode["InvalidSearchQuery"] = "InvalidSearchQueryException";
|
|
4337
4714
|
ErrorCode["MessageSearchUnavailable"] = "MessageSearchUnavailableException";
|
|
4338
4715
|
ErrorCode["MessageNotFound"] = "MessageNotFoundException";
|
|
4716
|
+
ErrorCode["ReactionExistsAlready"] = "ReactionExistsAlreadyException";
|
|
4339
4717
|
ErrorCode["RoomIgnored"] = "RoomIgnoredException";
|
|
4340
4718
|
ErrorCode["RoomNotFound"] = "RoomNotFoundException";
|
|
4719
|
+
ErrorCode["SpaceJoinRestricted"] = "SpaceJoinRestrictedException";
|
|
4341
4720
|
ErrorCode["TopicNotFound"] = "TopicNotFoundException";
|
|
4342
4721
|
ErrorCode["UserNotFound"] = "UserNotFoundException";
|
|
4343
4722
|
return ErrorCode;
|
|
4344
4723
|
}({});
|
|
4724
|
+
;// ./src/protocol/schemes/MessageEmbed.ts
|
|
4725
|
+
let MessageEmbedFlag = /*#__PURE__*/function (MessageEmbedFlag) {
|
|
4726
|
+
MessageEmbedFlag[MessageEmbedFlag["HideContent"] = 1] = "HideContent";
|
|
4727
|
+
MessageEmbedFlag[MessageEmbedFlag["Suppressed"] = 2] = "Suppressed";
|
|
4728
|
+
return MessageEmbedFlag;
|
|
4729
|
+
}({});
|
|
4345
4730
|
;// ./src/protocol/schemes/Role.ts
|
|
4346
4731
|
/**
|
|
4347
4732
|
* Bit flags of a role, stored in {@link Role.flags}.
|
|
@@ -4475,6 +4860,7 @@ let SpaceIntent = /*#__PURE__*/function (SpaceIntent) {
|
|
|
4475
4860
|
|
|
4476
4861
|
|
|
4477
4862
|
|
|
4863
|
+
|
|
4478
4864
|
module.exports = __webpack_exports__;
|
|
4479
4865
|
/******/ })()
|
|
4480
4866
|
;
|