@devanachat/sdk 0.8.0 → 0.9.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 +57 -4
- package/build/index.cjs.js +177 -44
- package/build/index.cjs.js.map +1 -1
- package/build/index.mjs +177 -44
- 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/Permissions.d.ts +4 -0
- 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/Reaction.d.ts +2 -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/events/EmoticonDeleted.d.ts +1 -1
- package/build/types/protocol/schemes/events/Emoticons.d.ts +1 -1
- package/build/types/state-tracker/EmoticonsManager.d.ts +1 -1
- package/build/types/state-tracker/RoomMessagesHistory.d.ts +10 -3
- package/build/types/state-tracker/StateSnapshot.d.ts +1 -4
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +31 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,61 @@ 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
|
-
## [
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `Permissions.list.UseExternalEmoticons` (`1 << 26`, space and room layer): using emoticons of other spaces.
|
|
12
|
+
- `UserFeature.ExternalEmoticons` (`user.external_emoticons`): the account may use emoticons outside their spaces.
|
|
13
|
+
- `MessageReaction.name` and `ToggledReaction.name`: the emoticon name of an `Emoticon` reaction.
|
|
14
|
+
- `GetEmoticons` takes `ids` (up to 100) and returns those of the emoticons the user may see - the ones of the spaces
|
|
15
|
+
they belong to and of the spaces that let their emoticons be used outside (space flag `1 << 2`, `spaceId` and `user`
|
|
16
|
+
null for a space the user does not belong to); the rest is left out. The response has `location: null` and does not
|
|
17
|
+
change the collections returned by `EmoticonsManager.get()`.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **Breaking:** there are no global emoticons any more. `EmoticonsManager.get()` requires a `spaceId`,
|
|
22
|
+
`CreateEmoticon.spaceId` and `EmoticonDeleted.spaceId` are required, and `EmoticonsSnapshot.spaceId` is a string -
|
|
23
|
+
global emoticons kept in an older snapshot are dropped on import.
|
|
24
|
+
- **Breaking:** `Emoticon.tag` (emoticon categories) is gone. `Emoticon.spaceId` and `Emoticon.user` (the author) are
|
|
25
|
+
`null` for an emoticon of a space the user does not belong to.
|
|
26
|
+
- **Breaking (protocol):** an `Emoticon` reaction (`React`, `Unreact`, `GetReactionDetails`, reactions of a message,
|
|
27
|
+
poll options) is identified by the emoticon id in `value` instead of its name. Servers before this change send the
|
|
28
|
+
name in `value` and no `name` - an application that has to work with both tells them apart by the length of `value`
|
|
29
|
+
(a name has at most 20 characters, an id 22).
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- Withdrawing the last own reaction from a message (`Reacted` with `isAdded: false`) left it in
|
|
34
|
+
`TopicHistoryWindow.myReactions` in apps built with Babel's loose object rest transform (e.g. `babel-preset-expo` on
|
|
35
|
+
web) - it dropped the message ID from the exclusion list (babel/babel#18196).
|
|
36
|
+
|
|
37
|
+
## [0.8.1]
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- History gaps: `TopicHistoryWindow.gaps` lists the IDs of the messages with a gap in front of them - the message above
|
|
42
|
+
in the window is not the real predecessor, an unknown number of messages in between was never fetched. A marker
|
|
43
|
+
disappears with its message (deleted, trimmed, the window replaced by `resetToLatest()` or `jumpTo()`) and is closed
|
|
44
|
+
once the messages before it are fetched (`fetchPrevious()` from it, or a later page reaching over it).
|
|
45
|
+
- `TopicHistoryWindow.resyncToLatest()` - the latest page merged on top of the loaded messages instead of replacing
|
|
46
|
+
them (a message in both is taken from the page); a full page that does not reach the loaded messages marks a gap.
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
|
|
50
|
+
- On a reconnect the `LATEST` windows of rooms with a time-limited history (`MaxAge`) keep the loaded messages and get
|
|
51
|
+
the missed ones with `resyncToLatest()` - the server may no longer serve the older ones. Full history rooms are still
|
|
52
|
+
reset to the latest page, ephemeral ones are left untouched.
|
|
53
|
+
- A snapshot of a window with a gap saves only the messages below the newest gap.
|
|
54
|
+
|
|
55
|
+
### Fixed
|
|
56
|
+
|
|
57
|
+
- `TopicHistoryWindow.jumpTo()` asked for while another fetch of the window runs (e.g. the reset of a reconnect, or an
|
|
58
|
+
earlier jump) waits for it to end and then jumps, instead of returning at once without loading anything - a caller
|
|
59
|
+
checking `has(id)` afterwards took the message for missing.
|
|
60
|
+
|
|
61
|
+
## [0.8.0]
|
|
8
62
|
|
|
9
63
|
### Added
|
|
10
64
|
|
|
@@ -29,8 +83,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
29
83
|
fetches it anew (as on a reconnect) and fetches the restored topics other than the default ones.
|
|
30
84
|
- Type exports `StateSnapshot`, `StateSnapshotIntent`, `TopicHistorySnapshot`, `RoomMembersSnapshot`,
|
|
31
85
|
`SpaceRoomsSnapshot`, `RoomFollowedTopicsSnapshot`, `EmoticonsSnapshot` and the `STATE_SNAPSHOT_VERSION` constant.
|
|
32
|
-
|
|
33
|
-
## [0.7.0] - Unreleased
|
|
86
|
+
## [0.7.0]
|
|
34
87
|
|
|
35
88
|
### Added
|
|
36
89
|
|
|
@@ -74,7 +127,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
74
127
|
|
|
75
128
|
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).
|
|
76
129
|
|
|
77
|
-
## [0.6.0]
|
|
130
|
+
## [0.6.0]
|
|
78
131
|
|
|
79
132
|
The first release under the new name. Earlier versions were published as `polfan-server-js-client`.
|
|
80
133
|
|
package/build/index.cjs.js
CHANGED
|
@@ -482,7 +482,8 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
482
482
|
retainRatio: 1,
|
|
483
483
|
fetchLimit: 50,
|
|
484
484
|
lastFetchCount: 0,
|
|
485
|
-
oldestId: null
|
|
485
|
+
oldestId: null,
|
|
486
|
+
gaps: []
|
|
486
487
|
};
|
|
487
488
|
|
|
488
489
|
/**
|
|
@@ -537,6 +538,16 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
537
538
|
get hasLatest() {
|
|
538
539
|
return [WindowState.LATEST, WindowState.LIVE].includes(this.state);
|
|
539
540
|
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* IDs of the items with a gap in front of them: the item right above in the window is not the real predecessor,
|
|
544
|
+
* an unknown number of items in between was never fetched. Such a seam appears when {@link resyncToLatest} gets
|
|
545
|
+
* a full page that does not reach the loaded items. A marker lives as long as its item stays in the window and
|
|
546
|
+
* is closed once the items right before it are fetched.
|
|
547
|
+
*/
|
|
548
|
+
get gaps() {
|
|
549
|
+
return this.internalState.gaps;
|
|
550
|
+
}
|
|
540
551
|
get hasOldest() {
|
|
541
552
|
return this.state === WindowState.OLDEST || this.state === WindowState.LATEST && this.length < this.fetchLimit || this.internalState.oldestId !== null && this.has(this.internalState.oldestId);
|
|
542
553
|
}
|
|
@@ -546,15 +557,51 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
546
557
|
}
|
|
547
558
|
let result;
|
|
548
559
|
const originalState = this.state;
|
|
549
|
-
this.
|
|
560
|
+
this.beginFetch(WindowState.LATEST);
|
|
561
|
+
try {
|
|
562
|
+
result = await this.fetchLatestItems();
|
|
563
|
+
this.internalState.lastFetchCount = result.length;
|
|
564
|
+
} finally {
|
|
565
|
+
this.endFetch();
|
|
566
|
+
}
|
|
567
|
+
this.replaceItems(result);
|
|
568
|
+
this.internalState.current = WindowState.LATEST;
|
|
569
|
+
this.emitChangeWithDiff(true, originalState);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Refresh the window with the latest page, keeping the already loaded items instead of replacing them - the
|
|
574
|
+
* reconnect-friendly variant of {@link resetToLatest}. The page is merged on top of the loaded items (an item in
|
|
575
|
+
* both is taken from the page) and only the window size limit pushes the oldest ones out. When the page is full
|
|
576
|
+
* and does not reach the newest loaded item, both parts are still kept and the seam is recorded in {@link gaps}.
|
|
577
|
+
*/
|
|
578
|
+
async resyncToLatest() {
|
|
579
|
+
if (this.internalState.ongoing) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
let result;
|
|
583
|
+
const originalState = this.state;
|
|
584
|
+
this.beginFetch(WindowState.LATEST);
|
|
550
585
|
try {
|
|
551
586
|
result = await this.fetchLatestItems();
|
|
552
587
|
this.internalState.lastFetchCount = result.length;
|
|
553
588
|
} finally {
|
|
554
|
-
this.
|
|
589
|
+
this.endFetch();
|
|
590
|
+
}
|
|
591
|
+
const loaded = this.items;
|
|
592
|
+
const fetchedIds = new Set(result.map(item => this.getId(item)));
|
|
593
|
+
const retained = loaded.filter(item => !fetchedIds.has(this.getId(item)));
|
|
594
|
+
|
|
595
|
+
// A page shorter than the limit is everything the remote side has, so nothing can be missing in between.
|
|
596
|
+
const isContinuous = !retained.length || result.length < this.internalState.fetchLimit || fetchedIds.has(this.getId(loaded[loaded.length - 1]));
|
|
597
|
+
|
|
598
|
+
// The page is continuous, so only its first item can have a gap in front of it.
|
|
599
|
+
this.forgetGapsOf(result.slice(1).map(item => this.getId(item)));
|
|
600
|
+
if (!isContinuous && !this.internalState.gaps.includes(this.getId(result[0]))) {
|
|
601
|
+
this.internalState.gaps = [...this.internalState.gaps, this.getId(result[0])];
|
|
555
602
|
}
|
|
556
603
|
this._items.deleteAll(); // Directly call deleteAll to prevent event emit.
|
|
557
|
-
this.addItems(result, 'tail');
|
|
604
|
+
this.addItems([...retained, ...result], 'tail');
|
|
558
605
|
this.internalState.current = WindowState.LATEST;
|
|
559
606
|
this.emitChangeWithDiff(true, originalState);
|
|
560
607
|
}
|
|
@@ -564,18 +611,18 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
564
611
|
}
|
|
565
612
|
let result;
|
|
566
613
|
const originalState = this.state;
|
|
567
|
-
|
|
614
|
+
const firstItem = this.getAt(0);
|
|
615
|
+
this.beginFetch(WindowState.PAST);
|
|
568
616
|
try {
|
|
569
617
|
result = await this.fetchItemsBefore();
|
|
570
618
|
this.internalState.lastFetchCount = result ? result.length : 0;
|
|
571
619
|
} finally {
|
|
572
|
-
this.
|
|
620
|
+
this.endFetch();
|
|
573
621
|
}
|
|
574
622
|
if (!result) {
|
|
575
623
|
return this.resetToLatest();
|
|
576
624
|
}
|
|
577
625
|
if (!result.length) {
|
|
578
|
-
const firstItem = this.getAt(0);
|
|
579
626
|
this.internalState.oldestId = firstItem ? this.getId(firstItem) : null;
|
|
580
627
|
await this.refreshFetchedState();
|
|
581
628
|
|
|
@@ -586,6 +633,10 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
586
633
|
this.emitChangeWithDiff(false, originalState);
|
|
587
634
|
return;
|
|
588
635
|
}
|
|
636
|
+
if (firstItem) {
|
|
637
|
+
// The page was fetched as the direct predecessors of the first item, so a gap in front of it is closed.
|
|
638
|
+
this.forgetGapsOf([this.getId(firstItem)]);
|
|
639
|
+
}
|
|
589
640
|
this.addItems(result, 'head');
|
|
590
641
|
await this.refreshFetchedState();
|
|
591
642
|
this.emitChangeWithDiff(true, originalState);
|
|
@@ -606,12 +657,12 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
606
657
|
}
|
|
607
658
|
let result;
|
|
608
659
|
const originalState = this.state;
|
|
609
|
-
this.
|
|
660
|
+
this.beginFetch(WindowState.PAST);
|
|
610
661
|
try {
|
|
611
662
|
result = await this.fetchItemsAfter();
|
|
612
663
|
this.internalState.lastFetchCount = result ? result.length : 0;
|
|
613
664
|
} finally {
|
|
614
|
-
this.
|
|
665
|
+
this.endFetch();
|
|
615
666
|
}
|
|
616
667
|
if (!result) {
|
|
617
668
|
await this.resetToLatest(true);
|
|
@@ -624,26 +675,41 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
624
675
|
return;
|
|
625
676
|
}
|
|
626
677
|
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Load the items around the given one. Asked for while another fetch is running, it waits for that fetch to end
|
|
681
|
+
* instead of being dropped - when the call returns, the window either holds the item or it could not be loaded.
|
|
682
|
+
*/
|
|
627
683
|
async jumpTo(id) {
|
|
628
|
-
|
|
684
|
+
while (this.internalState.ongoing) {
|
|
685
|
+
await this.internalState.fetchSettled;
|
|
686
|
+
}
|
|
687
|
+
if (this.state !== WindowState.LIVE && this._items.has(id)) {
|
|
629
688
|
return;
|
|
630
689
|
}
|
|
631
690
|
let result;
|
|
632
691
|
const originalState = this.state;
|
|
633
|
-
this.
|
|
692
|
+
this.beginFetch(WindowState.PAST);
|
|
634
693
|
try {
|
|
635
694
|
result = await this.fetchItemsAround(id);
|
|
636
695
|
this.internalState.lastFetchCount = result ? result.length : 0;
|
|
637
696
|
if (result) {
|
|
638
|
-
this.
|
|
639
|
-
this.addItems(result, 'tail');
|
|
697
|
+
this.replaceItems(result);
|
|
640
698
|
await this.refreshFetchedState();
|
|
641
699
|
}
|
|
642
700
|
} finally {
|
|
643
|
-
this.
|
|
701
|
+
this.endFetch();
|
|
644
702
|
}
|
|
645
703
|
this.emitChangeWithDiff(!!result, originalState);
|
|
646
704
|
}
|
|
705
|
+
delete(...ids) {
|
|
706
|
+
super.delete(...ids);
|
|
707
|
+
this.forgetGapsOf(ids);
|
|
708
|
+
}
|
|
709
|
+
deleteAll() {
|
|
710
|
+
super.deleteAll();
|
|
711
|
+
this.internalState.gaps = [];
|
|
712
|
+
}
|
|
647
713
|
async refreshFetchedState() {
|
|
648
714
|
this.internalState.current = (await this.isLatestItemLoaded()) ? WindowState.LATEST : WindowState.PAST;
|
|
649
715
|
}
|
|
@@ -666,6 +732,29 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
666
732
|
this._items.set(...entries, ...loaded);
|
|
667
733
|
return this.trimTail(this.getLowWatermark(highWatermark));
|
|
668
734
|
}
|
|
735
|
+
beginFetch(kind) {
|
|
736
|
+
this.internalState.ongoing = kind;
|
|
737
|
+
this.internalState.fetchSettled = new Promise(resolve => this.internalState.settleFetch = resolve);
|
|
738
|
+
}
|
|
739
|
+
endFetch() {
|
|
740
|
+
this.internalState.ongoing = undefined;
|
|
741
|
+
this.internalState.settleFetch?.();
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Replace the whole content without emitting an event; the old gap markers mean nothing for the new content.
|
|
746
|
+
*/
|
|
747
|
+
replaceItems(items) {
|
|
748
|
+
this._items.deleteAll();
|
|
749
|
+
this.internalState.gaps = [];
|
|
750
|
+
this.addItems(items, 'tail');
|
|
751
|
+
}
|
|
752
|
+
forgetGapsOf(ids) {
|
|
753
|
+
if (this.internalState.gaps.length && ids.length) {
|
|
754
|
+
const removed = new Set(ids);
|
|
755
|
+
this.internalState.gaps = this.internalState.gaps.filter(id => !removed.has(id));
|
|
756
|
+
}
|
|
757
|
+
}
|
|
669
758
|
emitChangeWithDiff(itemChanged, originalState) {
|
|
670
759
|
if (itemChanged || originalState !== this.state) {
|
|
671
760
|
this.eventTarget.emit('change', {
|
|
@@ -692,6 +781,7 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
692
781
|
deletedItems.push(id);
|
|
693
782
|
}
|
|
694
783
|
this._items.delete(...deletedItems);
|
|
784
|
+
this.forgetGapsOf(deletedItems);
|
|
695
785
|
if (this.internalState.current === WindowState.OLDEST) {
|
|
696
786
|
this.internalState.current = WindowState.PAST;
|
|
697
787
|
}
|
|
@@ -703,6 +793,7 @@ class TraversableRemoteCollection extends ObservableIndexedObjectCollection {
|
|
|
703
793
|
}
|
|
704
794
|
const deletedItems = Array.from(this._items.items.keys()).slice(keep);
|
|
705
795
|
this._items.delete(...deletedItems);
|
|
796
|
+
this.forgetGapsOf(deletedItems);
|
|
706
797
|
return deletedItems;
|
|
707
798
|
}
|
|
708
799
|
|
|
@@ -795,6 +886,12 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
795
886
|
}
|
|
796
887
|
return super.resetToLatest(force);
|
|
797
888
|
}
|
|
889
|
+
async resyncToLatest() {
|
|
890
|
+
if (this.internalState.traverseLock) {
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
return super.resyncToLatest();
|
|
894
|
+
}
|
|
798
895
|
async fetchNext() {
|
|
799
896
|
if (this.internalState.traverseLock) {
|
|
800
897
|
return;
|
|
@@ -825,7 +922,10 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
825
922
|
if (this.state !== WindowState.LATEST) {
|
|
826
923
|
return null;
|
|
827
924
|
}
|
|
828
|
-
const
|
|
925
|
+
const items = this.items;
|
|
926
|
+
// A restored window is taken for continuous, so nothing above the newest gap goes into it.
|
|
927
|
+
const continuousFrom = Math.max(0, ...this.internalState.gaps.map(id => items.findIndex(item => item.id === id)));
|
|
928
|
+
const messages = items.slice(Math.max(continuousFrom, items.length - Math.max(limit, this.fetchLimit)));
|
|
829
929
|
const myReactions = {};
|
|
830
930
|
for (const message of messages) {
|
|
831
931
|
if (this.internalState.myReactions[message.id]) {
|
|
@@ -845,8 +945,7 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
845
945
|
*/
|
|
846
946
|
_restoreLatest(messages, myReactions) {
|
|
847
947
|
const originalState = this.state;
|
|
848
|
-
this.
|
|
849
|
-
this.addItems(messages, 'tail');
|
|
948
|
+
this.replaceItems(messages);
|
|
850
949
|
this.internalState.myReactions = {
|
|
851
950
|
...myReactions
|
|
852
951
|
};
|
|
@@ -1019,10 +1118,12 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
|
|
|
1019
1118
|
value
|
|
1020
1119
|
});
|
|
1021
1120
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1121
|
+
|
|
1122
|
+
// Not `{[ev.messageId]: _, ...rest}` - Babel's loose object rest drops the key when the binding is unused (babel/babel#18196)
|
|
1123
|
+
const myReactions = {
|
|
1124
|
+
...this.internalState.myReactions
|
|
1125
|
+
};
|
|
1126
|
+
delete myReactions[ev.messageId];
|
|
1026
1127
|
if (own.length) {
|
|
1027
1128
|
myReactions[ev.messageId] = own;
|
|
1028
1129
|
}
|
|
@@ -1060,6 +1161,7 @@ class RoomMessagesHistory {
|
|
|
1060
1161
|
roomId;
|
|
1061
1162
|
historyWindows = new IndexedCollection();
|
|
1062
1163
|
traverseLock = false;
|
|
1164
|
+
timeLimitedHistory = false;
|
|
1063
1165
|
room;
|
|
1064
1166
|
constructor(room, tracker) {
|
|
1065
1167
|
this.tracker = tracker;
|
|
@@ -1067,7 +1169,7 @@ class RoomMessagesHistory {
|
|
|
1067
1169
|
this.room = typeof room === 'string' ? null : room;
|
|
1068
1170
|
this.isPreview = this.room === null;
|
|
1069
1171
|
if (this.room) {
|
|
1070
|
-
this.
|
|
1172
|
+
this.updateHistoryMode(this.room);
|
|
1071
1173
|
}
|
|
1072
1174
|
if (this.room?.defaultTopic) {
|
|
1073
1175
|
this.createHistoryWindowForTopic(this.room.defaultTopic);
|
|
@@ -1100,13 +1202,19 @@ class RoomMessagesHistory {
|
|
|
1100
1202
|
*
|
|
1101
1203
|
* The window bindings are preserved; only windows that the application had
|
|
1102
1204
|
* actually pulled to the latest page (state === LATEST) are refreshed, with
|
|
1103
|
-
* a single
|
|
1104
|
-
*
|
|
1205
|
+
* a single request instead of a chain of catch-up requests. Windows that
|
|
1206
|
+
* were never pulled (LIVE) or belong to an ephemeral room are left
|
|
1105
1207
|
* untouched so their in-memory context survives the reconnect.
|
|
1208
|
+
*
|
|
1209
|
+
* Rooms keeping the full history are reset to the latest page (the rest can
|
|
1210
|
+
* always be traversed back), while the windows of rooms with a time-limited
|
|
1211
|
+
* history (MaxAge) keep what they had loaded and get the missed messages on
|
|
1212
|
+
* top - the server may no longer serve the older ones. If more messages were
|
|
1213
|
+
* missed than a single page holds, the seam is recorded in the window gaps.
|
|
1106
1214
|
*/
|
|
1107
1215
|
async resync(room) {
|
|
1108
1216
|
this.room = room;
|
|
1109
|
-
this.
|
|
1217
|
+
this.updateHistoryMode(room);
|
|
1110
1218
|
if (this.room.defaultTopic) {
|
|
1111
1219
|
this.createHistoryWindowForTopic(this.room.defaultTopic);
|
|
1112
1220
|
}
|
|
@@ -1119,7 +1227,12 @@ class RoomMessagesHistory {
|
|
|
1119
1227
|
if (this.traverseLock) {
|
|
1120
1228
|
continue;
|
|
1121
1229
|
}
|
|
1122
|
-
if (window.state
|
|
1230
|
+
if (window.state !== WindowState.LATEST) {
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
if (this.timeLimitedHistory) {
|
|
1234
|
+
await window.resyncToLatest();
|
|
1235
|
+
} else {
|
|
1123
1236
|
await window.resetToLatest(true);
|
|
1124
1237
|
}
|
|
1125
1238
|
} catch (_e) {
|
|
@@ -1161,7 +1274,7 @@ class RoomMessagesHistory {
|
|
|
1161
1274
|
*/
|
|
1162
1275
|
async _handleRoomUpdated(ev) {
|
|
1163
1276
|
this.room = ev.room;
|
|
1164
|
-
this.
|
|
1277
|
+
this.updateHistoryMode(ev.room);
|
|
1165
1278
|
if (ev.room.defaultTopic) {
|
|
1166
1279
|
this.createHistoryWindowForTopic(ev.room.defaultTopic);
|
|
1167
1280
|
}
|
|
@@ -1247,8 +1360,9 @@ class RoomMessagesHistory {
|
|
|
1247
1360
|
this.tracker.rooms._deleteTopicsFromRoom(this.roomId, ...deletedTopicIds);
|
|
1248
1361
|
});
|
|
1249
1362
|
}
|
|
1250
|
-
|
|
1363
|
+
updateHistoryMode(room) {
|
|
1251
1364
|
this.traverseLock = room.history.mode === 'Ephemeral';
|
|
1365
|
+
this.timeLimitedHistory = room.history.mode === 'MaxAge';
|
|
1252
1366
|
}
|
|
1253
1367
|
}
|
|
1254
1368
|
;// ./src/state-tracker/MessagesManager.ts
|
|
@@ -2042,7 +2156,15 @@ class RoomsManager {
|
|
|
2042
2156
|
const promise = this.tracker.client.send('GetTopics', {
|
|
2043
2157
|
roomId,
|
|
2044
2158
|
topicIds: idsToFetch
|
|
2045
|
-
}).then(result =>
|
|
2159
|
+
}).then(result => {
|
|
2160
|
+
const topics = this.topics.get(roomId);
|
|
2161
|
+
if (topics) {
|
|
2162
|
+
topics.set(...result.data.topics);
|
|
2163
|
+
} else {
|
|
2164
|
+
// A room not joined yet has nowhere to keep them - let them be fetched again once it is.
|
|
2165
|
+
this.topicsPromises.forget(...idsToFetch.map(topicId => roomId + topicId));
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2046
2168
|
idsToFetch.forEach(topicId => this.topicsPromises.register(promise, roomId + topicId));
|
|
2047
2169
|
}
|
|
2048
2170
|
for (const topicId of tryToFetchTopicIds) {
|
|
@@ -2946,6 +3068,10 @@ class Permissions {
|
|
|
2946
3068
|
SearchMessages: {
|
|
2947
3069
|
value: 1 << 25,
|
|
2948
3070
|
maxLayer: Layer.Room
|
|
3071
|
+
},
|
|
3072
|
+
UseExternalEmoticons: {
|
|
3073
|
+
value: 1 << 26,
|
|
3074
|
+
maxLayer: Layer.Room
|
|
2949
3075
|
}
|
|
2950
3076
|
};
|
|
2951
3077
|
static getNames() {
|
|
@@ -3239,7 +3365,6 @@ class PermissionsManager extends EventTarget {
|
|
|
3239
3365
|
;// ./src/state-tracker/EmoticonsManager.ts
|
|
3240
3366
|
|
|
3241
3367
|
|
|
3242
|
-
const GLOBAL_KEY = 'global';
|
|
3243
3368
|
class EmoticonsManager {
|
|
3244
3369
|
list = new IndexedCollection();
|
|
3245
3370
|
emoticonsPromises = new PromiseRegistry();
|
|
@@ -3252,8 +3377,7 @@ class EmoticonsManager {
|
|
|
3252
3377
|
this.tracker.client.on('Session', () => this.handleSession());
|
|
3253
3378
|
}
|
|
3254
3379
|
async get(spaceId) {
|
|
3255
|
-
|
|
3256
|
-
if (this.emoticonsPromises.notExist(key)) {
|
|
3380
|
+
if (this.emoticonsPromises.notExist(spaceId)) {
|
|
3257
3381
|
this.emoticonsPromises.registerByFunction(async () => {
|
|
3258
3382
|
const result = await this.tracker.client.send('GetEmoticons', {
|
|
3259
3383
|
spaceId
|
|
@@ -3262,10 +3386,10 @@ class EmoticonsManager {
|
|
|
3262
3386
|
throw result.error;
|
|
3263
3387
|
}
|
|
3264
3388
|
this.handleEmoticons(result.data);
|
|
3265
|
-
},
|
|
3389
|
+
}, spaceId);
|
|
3266
3390
|
}
|
|
3267
|
-
await this.emoticonsPromises.get(
|
|
3268
|
-
return this.list.get(
|
|
3391
|
+
await this.emoticonsPromises.get(spaceId);
|
|
3392
|
+
return this.list.get(spaceId);
|
|
3269
3393
|
}
|
|
3270
3394
|
|
|
3271
3395
|
/**
|
|
@@ -3273,8 +3397,8 @@ class EmoticonsManager {
|
|
|
3273
3397
|
* @internal
|
|
3274
3398
|
*/
|
|
3275
3399
|
_exportEmoticons() {
|
|
3276
|
-
return Array.from(this.list.items).map(([
|
|
3277
|
-
spaceId
|
|
3400
|
+
return Array.from(this.list.items).map(([spaceId, emoticons]) => ({
|
|
3401
|
+
spaceId,
|
|
3278
3402
|
emoticons: emoticons.items
|
|
3279
3403
|
}));
|
|
3280
3404
|
}
|
|
@@ -3289,17 +3413,19 @@ class EmoticonsManager {
|
|
|
3289
3413
|
spaceId,
|
|
3290
3414
|
emoticons
|
|
3291
3415
|
} of snapshots) {
|
|
3292
|
-
|
|
3416
|
+
// TODO(emoticons-compat): snapshots written before the global emoticons were gone still hold them under
|
|
3417
|
+
// null - drop the comment once no such snapshot can be left on a device (the check itself stays).
|
|
3418
|
+
if (!joinedSpaceIds.has(spaceId)) {
|
|
3293
3419
|
continue;
|
|
3294
3420
|
}
|
|
3295
3421
|
this.handleEmoticons({
|
|
3296
3422
|
location: {
|
|
3297
|
-
spaceId
|
|
3423
|
+
spaceId
|
|
3298
3424
|
},
|
|
3299
3425
|
emoticons
|
|
3300
3426
|
});
|
|
3301
3427
|
// Served from the snapshot until the session invalidates it.
|
|
3302
|
-
this.emoticonsPromises.register(Promise.resolve(), spaceId
|
|
3428
|
+
this.emoticonsPromises.register(Promise.resolve(), spaceId);
|
|
3303
3429
|
}
|
|
3304
3430
|
}
|
|
3305
3431
|
|
|
@@ -3308,13 +3434,19 @@ class EmoticonsManager {
|
|
|
3308
3434
|
* @internal
|
|
3309
3435
|
*/
|
|
3310
3436
|
_forgetSpacesExcept(spaceIds) {
|
|
3311
|
-
const keptKeys = new Set(
|
|
3437
|
+
const keptKeys = new Set(spaceIds);
|
|
3312
3438
|
const removedKeys = Array.from(this.list.items.keys()).filter(key => !keptKeys.has(key));
|
|
3313
3439
|
this.list.delete(...removedKeys);
|
|
3314
3440
|
this.emoticonsPromises.forget(...removedKeys);
|
|
3315
3441
|
}
|
|
3316
3442
|
handleEmoticons(event) {
|
|
3317
|
-
|
|
3443
|
+
// A selection by ids has no location.
|
|
3444
|
+
// TODO(emoticons-compat): one without a space is the always empty list of the gone global emoticons, sent
|
|
3445
|
+
// until the server stops answering old clients that way.
|
|
3446
|
+
const spaceId = event.location?.spaceId;
|
|
3447
|
+
if (!spaceId) {
|
|
3448
|
+
return;
|
|
3449
|
+
}
|
|
3318
3450
|
if (!this.list.has(spaceId)) {
|
|
3319
3451
|
this.list.set([spaceId, new ObservableIndexedObjectCollection('id')]);
|
|
3320
3452
|
}
|
|
@@ -3325,11 +3457,11 @@ class EmoticonsManager {
|
|
|
3325
3457
|
this.list.get(spaceId).reconcile(...event.emoticons);
|
|
3326
3458
|
}
|
|
3327
3459
|
handleNewEmoticon(ev) {
|
|
3328
|
-
const collection = this.list.get(ev.emoticon.spaceId
|
|
3460
|
+
const collection = this.list.get(ev.emoticon.spaceId);
|
|
3329
3461
|
collection?.set(ev.emoticon);
|
|
3330
3462
|
}
|
|
3331
3463
|
handleEmoticonDeleted(ev) {
|
|
3332
|
-
const collection = this.list.get(ev.spaceId
|
|
3464
|
+
const collection = this.list.get(ev.spaceId);
|
|
3333
3465
|
collection?.delete(ev.emoticonId);
|
|
3334
3466
|
}
|
|
3335
3467
|
handleSpaceDeleted(event) {
|
|
@@ -4212,6 +4344,7 @@ let UserFeature = /*#__PURE__*/function (UserFeature) {
|
|
|
4212
4344
|
UserFeature["MessageLength"] = "user.message.length";
|
|
4213
4345
|
UserFeature["StorageLimit"] = "user.storage.limit";
|
|
4214
4346
|
UserFeature["StorageSingleFileLimit"] = "user.storage.single_file_limit";
|
|
4347
|
+
UserFeature["ExternalEmoticons"] = "user.external_emoticons";
|
|
4215
4348
|
return UserFeature;
|
|
4216
4349
|
}({});
|
|
4217
4350
|
|