@devanachat/sdk 0.7.0 → 0.8.1
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 +49 -0
- package/README.md +31 -0
- package/build/index.cjs.js +762 -36
- package/build/index.cjs.js.map +1 -1
- package/build/index.mjs +762 -37
- 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/index.d.ts +3 -1
- package/build/types/state-tracker/ChatStateTracker.d.ts +29 -0
- package/build/types/state-tracker/EmoticonsManager.d.ts +16 -0
- package/build/types/state-tracker/FollowedTopicsManager.d.ts +16 -0
- package/build/types/state-tracker/MessagesManager.d.ts +18 -1
- package/build/types/state-tracker/RelationshipsManager.d.ts +11 -0
- package/build/types/state-tracker/RoomMessagesHistory.d.ts +26 -4
- package/build/types/state-tracker/RoomsManager.d.ts +32 -0
- package/build/types/state-tracker/SpacesManager.d.ts +16 -0
- package/build/types/state-tracker/StateSnapshot.d.ts +102 -0
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +45 -0
- package/build/types/state-tracker/UsersManager.d.ts +5 -0
- package/package.json +1 -1
package/build/types/index.d.ts
CHANGED
|
@@ -10,10 +10,12 @@ import { AbstractRestClient } from "./AbstractRestClient";
|
|
|
10
10
|
import { UnreadSummary } from "./state-tracker/FollowedTopicsManager";
|
|
11
11
|
import { TopicHistoryWindow } from "./state-tracker/TopicHistoryWindow";
|
|
12
12
|
import { PermissionsManager } from "./state-tracker/PermissionsManager";
|
|
13
|
-
|
|
13
|
+
import { STATE_SNAPSHOT_VERSION } from "./state-tracker/StateSnapshot";
|
|
14
|
+
export { IndexedCollection, ObservableIndexedCollection, IndexedObjectCollection, ObservableIndexedObjectCollection, Permissions, PermissionDefinition, Layer, WebSocketChatClient, WebApiChatClient, FilesClient, AbstractRestClient, extractUserFromMember, ErrorCode, UserStatus, RoleFlag, SpaceFeature, UserFeature, HistoryRotation, SearchRange, UiPurpose, SpaceIntent, NO_LIMIT, STORAGE_UNIT_BYTES, STATE_SNAPSHOT_VERSION, };
|
|
14
15
|
export type { CommandResult, CommandRequest, CommandResponse, CommandsMap, EventsMap, } from "./AbstractChatClient";
|
|
15
16
|
export type { WebSocketClientOptions } from "./WebSocketChatClient";
|
|
16
17
|
export type { WebApiChatClientOptions } from "./WebApiChatClient";
|
|
17
18
|
export type { RestClientOptions, RestClientResponse } from "./AbstractRestClient";
|
|
18
19
|
export type { EventHandler, ObservableInterface } from "./EventTarget";
|
|
20
|
+
export type { StateSnapshot, SpaceRoomsSnapshot, RoomFollowedTopicsSnapshot, EmoticonsSnapshot, StateSnapshotIntent, TopicHistorySnapshot, RoomMembersSnapshot, } from "./state-tracker/StateSnapshot";
|
|
19
21
|
export type { ChatTypes, File, UnreadSummary, TopicHistoryWindow, PermissionsManager, };
|
|
@@ -6,6 +6,7 @@ import { PermissionsManager } from "./PermissionsManager";
|
|
|
6
6
|
import { EmoticonsManager } from "./EmoticonsManager";
|
|
7
7
|
import { UsersManager } from "./UsersManager";
|
|
8
8
|
import { RelationshipsManager } from "./RelationshipsManager";
|
|
9
|
+
import { StateSnapshot, StateSnapshotIntent } from "./StateSnapshot";
|
|
9
10
|
export declare class ChatStateTracker {
|
|
10
11
|
readonly client: WebSocketChatClient;
|
|
11
12
|
/**
|
|
@@ -34,8 +35,36 @@ export declare class ChatStateTracker {
|
|
|
34
35
|
readonly relationships: RelationshipsManager;
|
|
35
36
|
private _me;
|
|
36
37
|
private readonly deferredSession;
|
|
38
|
+
private sessionReceived;
|
|
39
|
+
private snapshotImported;
|
|
37
40
|
constructor(client: WebSocketChatClient);
|
|
38
41
|
get me(): User | null;
|
|
39
42
|
getMe(): Promise<User>;
|
|
43
|
+
/**
|
|
44
|
+
* Export the tracked state to a plain, JSON-serializable object, to be saved and restored with
|
|
45
|
+
* {@link importSnapshot} at the next start of the application, before the connection is established.
|
|
46
|
+
* See {@link StateSnapshot} for what is included.
|
|
47
|
+
* @param intent What to include beyond the state that is always exported, e.g. the message histories.
|
|
48
|
+
* @return Null if there is no state yet (no session has been received or imported).
|
|
49
|
+
*/
|
|
50
|
+
exportSnapshot(intent?: StateSnapshotIntent): StateSnapshot | null;
|
|
51
|
+
/**
|
|
52
|
+
* Restore the state exported with {@link exportSnapshot}, so it is available before the connection is
|
|
53
|
+
* established. The collections emit their usual change events and the getters waiting for the session resolve.
|
|
54
|
+
* The first `Session` from the server then replaces the restored state the same way it does on a reconnect:
|
|
55
|
+
* removed spaces and rooms are dropped, the rest is updated in place, the restored message histories and topics
|
|
56
|
+
* other than the default ones are fetched anew (as a window holding the latest messages is on a reconnect), and
|
|
57
|
+
* the lazily loaded lists are refetched on their next access.
|
|
58
|
+
*
|
|
59
|
+
* Allowed only once and only before the first `Session`.
|
|
60
|
+
* @return False if the snapshot was rejected (another version, malformed data, or a session already received) -
|
|
61
|
+
* the state is not changed then.
|
|
62
|
+
*/
|
|
63
|
+
importSnapshot(snapshot: unknown): boolean;
|
|
40
64
|
private handleSession;
|
|
65
|
+
/**
|
|
66
|
+
* A reconnect keeps the followed topics and emoticons of rooms and spaces that are gone; for the restored ones
|
|
67
|
+
* the first session is the only chance to tell they are gone.
|
|
68
|
+
*/
|
|
69
|
+
private handleSessionAfterImport;
|
|
41
70
|
}
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { ChatStateTracker } from "./ChatStateTracker";
|
|
2
2
|
import { ObservableIndexedObjectCollection } from "../IndexedObjectCollection";
|
|
3
3
|
import { Emoticon } from "../protocol";
|
|
4
|
+
import { EmoticonsSnapshot } from "./StateSnapshot";
|
|
4
5
|
export declare class EmoticonsManager {
|
|
5
6
|
private tracker;
|
|
6
7
|
private list;
|
|
7
8
|
private emoticonsPromises;
|
|
8
9
|
constructor(tracker: ChatStateTracker);
|
|
9
10
|
get(spaceId?: string): Promise<ObservableIndexedObjectCollection<Emoticon>>;
|
|
11
|
+
/**
|
|
12
|
+
* For internal use.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
_exportEmoticons(): EmoticonsSnapshot[];
|
|
16
|
+
/**
|
|
17
|
+
* Emoticons of spaces other than the given ones are skipped.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
_importEmoticons(snapshots: EmoticonsSnapshot[], spaceIds: string[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* For internal use.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
_forgetSpacesExcept(spaceIds: string[]): void;
|
|
10
26
|
private handleEmoticons;
|
|
11
27
|
private handleNewEmoticon;
|
|
12
28
|
private handleEmoticonDeleted;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventTarget } from "../EventTarget";
|
|
2
2
|
import { ChatStateTracker } from "./ChatStateTracker";
|
|
3
3
|
import { ObservableIndexedObjectCollection } from "../IndexedObjectCollection";
|
|
4
|
+
import { RoomFollowedTopicsSnapshot } from "./StateSnapshot";
|
|
4
5
|
import { ChatLocation, FollowedTopic } from "../protocol";
|
|
5
6
|
interface EventMap {
|
|
6
7
|
change: {};
|
|
@@ -50,6 +51,21 @@ export declare class FollowedTopicsManager extends EventTarget<EventMap> {
|
|
|
50
51
|
* @internal
|
|
51
52
|
*/
|
|
52
53
|
_deleteByTopicIds(roomId: string, ...topicIds: string[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* For internal use.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
_exportFollowedTopics(): RoomFollowedTopicsSnapshot[];
|
|
59
|
+
/**
|
|
60
|
+
* Expects the rooms to be imported already - followed topics of other rooms are skipped.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
_importFollowedTopics(snapshots: RoomFollowedTopicsSnapshot[]): void;
|
|
64
|
+
/**
|
|
65
|
+
* For internal use.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
_forgetRoomsExcept(roomIds: string[]): void;
|
|
53
69
|
private handleSession;
|
|
54
70
|
private handleNewMessage;
|
|
55
71
|
private handleFollowedTopicUpdated;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ChatStateTracker } from "./ChatStateTracker";
|
|
2
|
-
import { Message, ChatLocation } from "../protocol";
|
|
2
|
+
import { Room, Message, ChatLocation, Topic } from "../protocol";
|
|
3
3
|
import { RoomMessagesHistory } from "./RoomMessagesHistory";
|
|
4
|
+
import { TopicHistoryWindow } from "./TopicHistoryWindow";
|
|
5
|
+
import { TopicHistorySnapshot } from "./StateSnapshot";
|
|
4
6
|
export declare class MessagesManager {
|
|
5
7
|
private tracker;
|
|
6
8
|
private readonly roomHistories;
|
|
@@ -18,6 +20,21 @@ export declare class MessagesManager {
|
|
|
18
20
|
* @internal
|
|
19
21
|
*/
|
|
20
22
|
_resolveLastMessage(location: ChatLocation): Promise<Message | null>;
|
|
23
|
+
/**
|
|
24
|
+
* For internal use.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
_importRooms(rooms: Room[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* For internal use.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
_exportLatest(roomId: string, topicId: string, limit: number): ReturnType<TopicHistoryWindow['_exportLatest']>;
|
|
33
|
+
/**
|
|
34
|
+
* For internal use.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
_importHistory(roomId: string, topic: Topic, snapshot: TopicHistorySnapshot): void;
|
|
21
38
|
private forEachRoomHistory;
|
|
22
39
|
private createHistoryForNewRoom;
|
|
23
40
|
private handleRoomDeleted;
|
|
@@ -5,9 +5,20 @@ export declare class RelationshipsManager {
|
|
|
5
5
|
private tracker;
|
|
6
6
|
private relationships;
|
|
7
7
|
private promises;
|
|
8
|
+
private loaded;
|
|
8
9
|
constructor(tracker: ChatStateTracker);
|
|
9
10
|
get(): Promise<ObservableIndexedObjectCollection<UserRelationship>>;
|
|
10
11
|
exists(refUserId: string, type: UserRelationshipType): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* For internal use.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
_exportRelationships(): UserRelationship[] | null;
|
|
17
|
+
/**
|
|
18
|
+
* For internal use.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
_importRelationships(relationships: UserRelationship[] | null): void;
|
|
11
22
|
private handleRelationships;
|
|
12
23
|
private handleNewRelationship;
|
|
13
24
|
private handleRelationshipDeleted;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChatStateTracker } from "./ChatStateTracker";
|
|
2
|
-
import { MessagesRedacted, NewMessage, NewTopic, Reacted, ReactionUpdated, Room, RoomUpdated, TopicDeleted } from "../protocol";
|
|
2
|
+
import { Message, MessagesRedacted, NewMessage, NewTopic, Reacted, ReactionUpdated, Room, RoomUpdated, Topic, TopicDeleted, UserReaction } from "../protocol";
|
|
3
3
|
import { TopicHistoryWindow } from "./TopicHistoryWindow";
|
|
4
4
|
/**
|
|
5
5
|
* Does not subscribe to the client itself - the messages manager routes the events of its room to it, so a history
|
|
@@ -11,6 +11,7 @@ export declare class RoomMessagesHistory {
|
|
|
11
11
|
private readonly roomId;
|
|
12
12
|
private historyWindows;
|
|
13
13
|
private traverseLock;
|
|
14
|
+
private timeLimitedHistory;
|
|
14
15
|
private room;
|
|
15
16
|
constructor(room: Room | string, tracker: ChatStateTracker);
|
|
16
17
|
/**
|
|
@@ -26,11 +27,32 @@ export declare class RoomMessagesHistory {
|
|
|
26
27
|
*
|
|
27
28
|
* The window bindings are preserved; only windows that the application had
|
|
28
29
|
* actually pulled to the latest page (state === LATEST) are refreshed, with
|
|
29
|
-
* a single
|
|
30
|
-
*
|
|
30
|
+
* a single request instead of a chain of catch-up requests. Windows that
|
|
31
|
+
* were never pulled (LIVE) or belong to an ephemeral room are left
|
|
31
32
|
* untouched so their in-memory context survives the reconnect.
|
|
33
|
+
*
|
|
34
|
+
* Rooms keeping the full history are reset to the latest page (the rest can
|
|
35
|
+
* always be traversed back), while the windows of rooms with a time-limited
|
|
36
|
+
* history (MaxAge) keep what they had loaded and get the missed messages on
|
|
37
|
+
* top - the server may no longer serve the older ones. If more messages were
|
|
38
|
+
* missed than a single page holds, the seam is recorded in the window gaps.
|
|
32
39
|
*/
|
|
33
40
|
resync(room: Room): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* For internal use.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
get _isEphemeral(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The window of the topic, if created; unlike getMessagesWindow(), never creates nor fetches one.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
_peekWindow(topicId: string): TopicHistoryWindow | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* For internal use.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
_restoreWindow(topic: Topic, messages: Message[], myReactions: Record<string, UserReaction[]>): void;
|
|
34
56
|
/**
|
|
35
57
|
* For internal use.
|
|
36
58
|
* @internal
|
|
@@ -68,5 +90,5 @@ export declare class RoomMessagesHistory {
|
|
|
68
90
|
_handleReacted(ev: Reacted): void;
|
|
69
91
|
private createHistoryWindowForTopic;
|
|
70
92
|
private createHistoryWindow;
|
|
71
|
-
private
|
|
93
|
+
private updateHistoryMode;
|
|
72
94
|
}
|
|
@@ -3,6 +3,7 @@ import { Room, RoomMember, Topic } from "../protocol";
|
|
|
3
3
|
import { ChatStateTracker } from "./ChatStateTracker";
|
|
4
4
|
import { MessagesManager } from "./MessagesManager";
|
|
5
5
|
import { FollowedTopicsManager } from "./FollowedTopicsManager";
|
|
6
|
+
import { RoomMembersSnapshot, StateSnapshotIntent, TopicHistorySnapshot } from "./StateSnapshot";
|
|
6
7
|
export declare class RoomsManager {
|
|
7
8
|
private tracker;
|
|
8
9
|
readonly messages: MessagesManager;
|
|
@@ -13,6 +14,7 @@ export declare class RoomsManager {
|
|
|
13
14
|
private readonly deferredSession;
|
|
14
15
|
private readonly membersPromises;
|
|
15
16
|
private readonly topicsPromises;
|
|
17
|
+
private readonly importedTopicIds;
|
|
16
18
|
constructor(tracker: ChatStateTracker);
|
|
17
19
|
/**
|
|
18
20
|
* Get collection of room members.
|
|
@@ -41,6 +43,36 @@ export declare class RoomsManager {
|
|
|
41
43
|
* @internal
|
|
42
44
|
*/
|
|
43
45
|
_deleteTopicsFromRoom(roomId: string, ...topicIds: string[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* For internal use.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
_exportRooms(): Room[];
|
|
51
|
+
/**
|
|
52
|
+
* For internal use.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
_importRooms(rooms: Room[]): void;
|
|
56
|
+
/**
|
|
57
|
+
* For internal use.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
_exportHistories(intent: StateSnapshotIntent): TopicHistorySnapshot[];
|
|
61
|
+
/**
|
|
62
|
+
* Members of private conversations are not exported - they are made of the recipients of the room.
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
_exportMembers(roomIds: string[], limit: number): RoomMembersSnapshot[];
|
|
66
|
+
/**
|
|
67
|
+
* Expects the rooms to be imported already - histories and members of other rooms are skipped.
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
_importHistories(histories: TopicHistorySnapshot[], roomMembers: RoomMembersSnapshot[]): void;
|
|
71
|
+
/**
|
|
72
|
+
* The session carries only the default topics, so the other restored ones are fetched anew.
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
_refreshImportedTopics(): void;
|
|
44
76
|
private deleteRoom;
|
|
45
77
|
private deleteRoomsBySpaceId;
|
|
46
78
|
private handleSpaceMemberUpdated;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ChatStateTracker } from "./ChatStateTracker";
|
|
2
2
|
import { ObservableIndexedObjectCollection } from "../IndexedObjectCollection";
|
|
3
3
|
import { Role, RoomSummary, Space, SpaceMember } from "../protocol";
|
|
4
|
+
import { SpaceRoomsSnapshot } from "./StateSnapshot";
|
|
4
5
|
export declare class SpacesManager {
|
|
5
6
|
private tracker;
|
|
6
7
|
private readonly list;
|
|
@@ -38,6 +39,21 @@ export declare class SpacesManager {
|
|
|
38
39
|
* Get a space member representing the current user.
|
|
39
40
|
*/
|
|
40
41
|
getMe(spaceId: string): Promise<SpaceMember | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* For internal use.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
_exportSpaces(): Space[];
|
|
47
|
+
/**
|
|
48
|
+
* Room listings of the joined spaces only - of other spaces they are fetched for a moment's look.
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
_exportSpaceRooms(): SpaceRoomsSnapshot[];
|
|
52
|
+
/**
|
|
53
|
+
* For internal use.
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
_importSpaces(spaces: Space[], spaceRooms: SpaceRoomsSnapshot[]): void;
|
|
41
57
|
private handleNewRole;
|
|
42
58
|
private handleNewRoom;
|
|
43
59
|
private handleRoomUpdated;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Emoticon, FollowedTopic, Message, Room, RoomMember, RoomSummary, Space, Topic, User, UserReaction, UserRelationship } from "../protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Version of the {@link StateSnapshot} format. A snapshot of any other version is rejected on import.
|
|
4
|
+
*/
|
|
5
|
+
export declare const STATE_SNAPSHOT_VERSION = 1;
|
|
6
|
+
/**
|
|
7
|
+
* Plain, JSON-serializable copy of the state tracked by {@link ChatStateTracker}, made to restore the state at the
|
|
8
|
+
* application start (before the connection is established) - see {@link ChatStateTracker.exportSnapshot}.
|
|
9
|
+
*
|
|
10
|
+
* Only the data that lasts is included: the current user, the joined spaces (with roles) and rooms (with the default
|
|
11
|
+
* topics), and the lazily loaded lists already fetched - rooms of spaces, followed topics, emoticons and relationships.
|
|
12
|
+
* The message histories of the topics named in the {@link StateSnapshotIntent} are included too, with what their
|
|
13
|
+
* display needs: the topics referenced by the messages and, optionally, the members of the rooms.
|
|
14
|
+
* Left out on purpose:
|
|
15
|
+
* - presence - every user status is saved as `Offline`, a status from the past would show people online who are not;
|
|
16
|
+
* - members of spaces, and of rooms not asked for - large, made mostly of presence, and refetched cheaply on demand;
|
|
17
|
+
* - other message histories and topics, histories of ephemeral rooms (they live only in the memory of the session),
|
|
18
|
+
* permission overwrites and room previews - loaded on demand once the connection is up, as on a reconnect.
|
|
19
|
+
*/
|
|
20
|
+
export interface StateSnapshot {
|
|
21
|
+
version: typeof STATE_SNAPSHOT_VERSION;
|
|
22
|
+
/**
|
|
23
|
+
* Time of the export, in milliseconds since the epoch.
|
|
24
|
+
*/
|
|
25
|
+
createdAt: number;
|
|
26
|
+
user: User;
|
|
27
|
+
spaces: Space[];
|
|
28
|
+
rooms: Room[];
|
|
29
|
+
spaceRooms: SpaceRoomsSnapshot[];
|
|
30
|
+
followedTopics: RoomFollowedTopicsSnapshot[];
|
|
31
|
+
emoticons: EmoticonsSnapshot[];
|
|
32
|
+
/**
|
|
33
|
+
* Null when the relationships have not been loaded.
|
|
34
|
+
*/
|
|
35
|
+
relationships: UserRelationship[] | null;
|
|
36
|
+
histories: TopicHistorySnapshot[];
|
|
37
|
+
roomMembers: RoomMembersSnapshot[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What {@link ChatStateTracker.exportSnapshot} should include beyond the state that is always exported.
|
|
41
|
+
*/
|
|
42
|
+
export interface StateSnapshotIntent {
|
|
43
|
+
/**
|
|
44
|
+
* Topics to save the latest messages of, e.g. the ones last open in the application. Without `topicId`, the default
|
|
45
|
+
* topic of the room. Only a history window holding the latest messages (the `LATEST` state) is saved.
|
|
46
|
+
*/
|
|
47
|
+
histories?: {
|
|
48
|
+
roomId: string;
|
|
49
|
+
topicId?: string;
|
|
50
|
+
}[];
|
|
51
|
+
/**
|
|
52
|
+
* Messages saved per topic, the latest ones. Never fewer than the `fetchLimit` of the window (50 by default), so a
|
|
53
|
+
* restored window tells right whether it reaches the oldest message. Defaults to that `fetchLimit`.
|
|
54
|
+
*/
|
|
55
|
+
historyLimit?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Save the members of the rooms of the histories (for the roles, colors and avatars of the authors) when they are
|
|
58
|
+
* loaded and there are not more of them than this. Defaults to 0 - none.
|
|
59
|
+
*/
|
|
60
|
+
roomMembersLimit?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface TopicHistorySnapshot {
|
|
63
|
+
roomId: string;
|
|
64
|
+
topicId: string;
|
|
65
|
+
/**
|
|
66
|
+
* Oldest first.
|
|
67
|
+
*/
|
|
68
|
+
messages: Message[];
|
|
69
|
+
myReactions: Record<string, UserReaction[]>;
|
|
70
|
+
/**
|
|
71
|
+
* The topic of the history (if not the default one of the room) and the topics the messages refer to, as far as
|
|
72
|
+
* they are known.
|
|
73
|
+
*/
|
|
74
|
+
topics: Topic[];
|
|
75
|
+
}
|
|
76
|
+
export interface RoomMembersSnapshot {
|
|
77
|
+
roomId: string;
|
|
78
|
+
members: RoomMember[];
|
|
79
|
+
}
|
|
80
|
+
export interface SpaceRoomsSnapshot {
|
|
81
|
+
spaceId: string;
|
|
82
|
+
summaries: RoomSummary[];
|
|
83
|
+
}
|
|
84
|
+
export interface RoomFollowedTopicsSnapshot {
|
|
85
|
+
roomId: string;
|
|
86
|
+
followedTopics: FollowedTopic[];
|
|
87
|
+
}
|
|
88
|
+
export interface EmoticonsSnapshot {
|
|
89
|
+
/**
|
|
90
|
+
* Null for the global emoticons.
|
|
91
|
+
*/
|
|
92
|
+
spaceId: string | null;
|
|
93
|
+
emoticons: Emoticon[];
|
|
94
|
+
}
|
|
95
|
+
export declare function withoutPresence(user: User): User;
|
|
96
|
+
export declare function messageWithoutPresence(message: Message): Message;
|
|
97
|
+
export declare function memberWithoutPresence(member: RoomMember): RoomMember;
|
|
98
|
+
/**
|
|
99
|
+
* Structural check of the data restored from a storage - deep enough that importing it cannot throw, as the state
|
|
100
|
+
* handlers dereference these fields without checking them.
|
|
101
|
+
*/
|
|
102
|
+
export declare function isValidStateSnapshot(value: unknown): value is StateSnapshot;
|
|
@@ -29,11 +29,14 @@ export declare abstract class TraversableRemoteCollection<ItemT, EventMapT exten
|
|
|
29
29
|
protected internalState: {
|
|
30
30
|
current: WindowState;
|
|
31
31
|
ongoing?: WindowState;
|
|
32
|
+
fetchSettled?: Promise<void>;
|
|
33
|
+
settleFetch?: () => void;
|
|
32
34
|
limit: number | null;
|
|
33
35
|
retainRatio: number;
|
|
34
36
|
fetchLimit: number;
|
|
35
37
|
lastFetchCount: number;
|
|
36
38
|
oldestId: string | null;
|
|
39
|
+
gaps: string[];
|
|
37
40
|
};
|
|
38
41
|
/**
|
|
39
42
|
* Number of items to fetch per request.
|
|
@@ -62,16 +65,36 @@ export declare abstract class TraversableRemoteCollection<ItemT, EventMapT exten
|
|
|
62
65
|
*/
|
|
63
66
|
set retainRatio(value: number);
|
|
64
67
|
get hasLatest(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* IDs of the items with a gap in front of them: the item right above in the window is not the real predecessor,
|
|
70
|
+
* an unknown number of items in between was never fetched. Such a seam appears when {@link resyncToLatest} gets
|
|
71
|
+
* a full page that does not reach the loaded items. A marker lives as long as its item stays in the window and
|
|
72
|
+
* is closed once the items right before it are fetched.
|
|
73
|
+
*/
|
|
74
|
+
get gaps(): readonly string[];
|
|
65
75
|
get hasOldest(): boolean;
|
|
66
76
|
abstract createMirror(): TraversableRemoteCollection<ItemT, EventMapT>;
|
|
67
77
|
resetToLatest(force?: boolean): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Refresh the window with the latest page, keeping the already loaded items instead of replacing them - the
|
|
80
|
+
* reconnect-friendly variant of {@link resetToLatest}. The page is merged on top of the loaded items (an item in
|
|
81
|
+
* both is taken from the page) and only the window size limit pushes the oldest ones out. When the page is full
|
|
82
|
+
* and does not reach the newest loaded item, both parts are still kept and the seam is recorded in {@link gaps}.
|
|
83
|
+
*/
|
|
84
|
+
resyncToLatest(): Promise<void>;
|
|
68
85
|
fetchPrevious(): Promise<void>;
|
|
69
86
|
fetchNext(): Promise<void>;
|
|
70
87
|
/**
|
|
71
88
|
* Append the items that follow the last one in the window; an empty window gets the latest items.
|
|
72
89
|
*/
|
|
73
90
|
protected fetchAfterLast(): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Load the items around the given one. Asked for while another fetch is running, it waits for that fetch to end
|
|
93
|
+
* instead of being dropped - when the call returns, the window either holds the item or it could not be loaded.
|
|
94
|
+
*/
|
|
74
95
|
jumpTo(id: string): Promise<void>;
|
|
96
|
+
delete(...ids: string[]): void;
|
|
97
|
+
deleteAll(): void;
|
|
75
98
|
protected abstract fetchLatestItems(): Promise<ItemT[]>;
|
|
76
99
|
protected abstract fetchItemsBefore(): Promise<ItemT[] | null>;
|
|
77
100
|
protected abstract fetchItemsAfter(): Promise<ItemT[] | null>;
|
|
@@ -84,6 +107,13 @@ export declare abstract class TraversableRemoteCollection<ItemT, EventMapT exten
|
|
|
84
107
|
* @return Ids of the items trimmed out.
|
|
85
108
|
*/
|
|
86
109
|
protected addItems(newItems: ItemT[], to: 'head' | 'tail', highWatermark?: number | null): string[];
|
|
110
|
+
protected beginFetch(kind: WindowState): void;
|
|
111
|
+
protected endFetch(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Replace the whole content without emitting an event; the old gap markers mean nothing for the new content.
|
|
114
|
+
*/
|
|
115
|
+
protected replaceItems(items: ItemT[]): void;
|
|
116
|
+
protected forgetGapsOf(ids: string[]): void;
|
|
87
117
|
protected emitChangeWithDiff(itemChanged: boolean, originalState: WindowState): void;
|
|
88
118
|
/**
|
|
89
119
|
* Drop the oldest items, so that at most `keep` remain. The newest items stay, so whether the window holds the
|
|
@@ -145,9 +175,24 @@ export declare class TopicHistoryWindow extends TraversableRemoteCollection<Mess
|
|
|
145
175
|
set liveLimit(value: number | null);
|
|
146
176
|
setTraverseLock(lock: boolean): Promise<void>;
|
|
147
177
|
resetToLatest(force?: boolean): Promise<void>;
|
|
178
|
+
resyncToLatest(): Promise<void>;
|
|
148
179
|
fetchNext(): Promise<void>;
|
|
149
180
|
fetchPrevious(): Promise<void>;
|
|
150
181
|
jumpTo(id: string): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* The latest messages (oldest first) with the reactions of the user, or null if the window does not hold them.
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
_exportLatest(limit: number): {
|
|
187
|
+
messages: Message[];
|
|
188
|
+
myReactions: Record<string, UserReaction[]>;
|
|
189
|
+
} | null;
|
|
190
|
+
/**
|
|
191
|
+
* Fill the window with saved latest messages, as if they were just fetched; the next reset to the latest replaces
|
|
192
|
+
* them.
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
195
|
+
_restoreLatest(messages: Message[], myReactions: Record<string, UserReaction[]>): void;
|
|
151
196
|
/**
|
|
152
197
|
* For internal use.
|
|
153
198
|
* @internal
|
|
@@ -13,6 +13,11 @@ export declare class UsersManager {
|
|
|
13
13
|
* Get all available (cached) user objects at once.
|
|
14
14
|
*/
|
|
15
15
|
getAvailable(): Promise<ObservableIndexedObjectCollection<User>>;
|
|
16
|
+
/**
|
|
17
|
+
* For internal use.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
_importUser(user: User): void;
|
|
16
21
|
private handleMembers;
|
|
17
22
|
private handleSession;
|
|
18
23
|
/**
|
package/package.json
CHANGED