@devanachat/sdk 0.14.0 → 0.15.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 +49 -1
- package/build/index.cjs.js +415 -1
- package/build/index.cjs.js.map +1 -1
- package/build/index.mjs +414 -1
- 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 +13 -1
- package/build/types/Permissions.d.ts +4 -0
- package/build/types/index.d.ts +4 -2
- package/build/types/protocol/index.d.ts +15 -1
- package/build/types/protocol/schemes/Activity.d.ts +16 -0
- package/build/types/protocol/schemes/SavedItem.d.ts +7 -0
- package/build/types/protocol/schemes/commands/GetActivities.d.ts +3 -0
- package/build/types/protocol/schemes/commands/GetSavedItems.d.ts +3 -0
- package/build/types/protocol/schemes/commands/SaveItem.d.ts +5 -0
- package/build/types/protocol/schemes/commands/UnsaveItem.d.ts +5 -0
- package/build/types/protocol/schemes/commands/UpdateActivities.d.ts +4 -0
- package/build/types/protocol/schemes/events/Activities.d.ts +9 -0
- package/build/types/protocol/schemes/events/ActivityDeleted.d.ts +3 -0
- package/build/types/protocol/schemes/events/ActivityUpdated.d.ts +4 -0
- package/build/types/protocol/schemes/events/Error.d.ts +3 -1
- package/build/types/protocol/schemes/events/ItemSaved.d.ts +6 -0
- package/build/types/protocol/schemes/events/ItemUnsaved.d.ts +5 -0
- package/build/types/protocol/schemes/events/NewActivity.d.ts +8 -0
- package/build/types/protocol/schemes/events/SavedItems.d.ts +6 -0
- package/build/types/state-tracker/ActivitiesManager.d.ts +63 -0
- package/build/types/state-tracker/ChatStateTracker.d.ts +13 -0
- package/build/types/state-tracker/SavedItemsManager.d.ts +46 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,55 @@ 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
|
+
## [0.15.0]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Activities: your latest personal events from all spaces - a mention of you or of your role, a reply to you, a
|
|
12
|
+
reaction to your message, a reply in a thread you follow and a missed call - and the activities the server publishes
|
|
13
|
+
itself, with a `title`, a `description` and a `link`. Private conversations keep their own unread state: apart from a
|
|
14
|
+
missed call they make no activities. Bots have none: their `GetActivities` and `UpdateActivity` fail with
|
|
15
|
+
`UserTypeException`. The protocol: the `GetActivities` command answered with `Activities` - up to 20 `Activity`
|
|
16
|
+
objects, newest first, and the `seenAt` time; with `withMessages` also the messages they point at and their actors
|
|
17
|
+
(`users`), which are empty otherwise. The `UpdateActivity` command (`seenAt` marks the list as seen, `clear` empties
|
|
18
|
+
it) is answered with `ActivityUpdated`, which every session of the user gets. The event `NewActivity` carries the
|
|
19
|
+
new activity with its `message` and its actor (`users`), `ActivityDeleted` an activity the server deleted. Activities
|
|
20
|
+
of one group (`groupKey`: reactions to one message, replies in one thread) join while unseen: `count` grows,
|
|
21
|
+
`actorIds` keeps the last three and `messageId` points at the newest message. `Activity.isRead` is set once the
|
|
22
|
+
message of the activity is acknowledged (`Ack`; reactions excepted); a live `NewActivity` of a message comes a few
|
|
23
|
+
seconds late and only to those who have not acknowledged it by then, so an activity in the topic you are reading
|
|
24
|
+
does not show at all.
|
|
25
|
+
- `ChatStateTracker.activities` (`ActivitiesManager`): `get(fetchWithMessages)` resolves with an observable collection
|
|
26
|
+
of the activities keyed by id, `getMessages()` and `getUsers()` with the collections of their messages and actors,
|
|
27
|
+
and `seenAt` (with a `seenAtChange` event) tells when the list was last seen; the activities created later that are
|
|
28
|
+
not `isRead` are the unread ones. Nothing is fetched until you ask; afterwards a reconnect fetches again what was
|
|
29
|
+
fetched, with one request, into the same collections - also when the first fetch failed because the connection was
|
|
30
|
+
not ready. A live activity joins its group the way the server does; `ActivityUpdated`, `ActivityDeleted`,
|
|
31
|
+
`FollowedTopicUpdated` (an acknowledgement, also from another device), edits and deletions of the messages and
|
|
32
|
+
deleted rooms change the collections; leaving a room hides its activities and rejoining brings them back. The
|
|
33
|
+
collection order is not meaningful - sort by `createdAt`. Activities are not part of the state snapshot.
|
|
34
|
+
- Saved items: rooms (private conversations included) and messages you save to keep at hand. The protocol: the
|
|
35
|
+
`SaveItem` and `UnsaveItem` commands (`type` `Room` or `Message` and the `id`), answered with `ItemSaved` (the
|
|
36
|
+
`SavedItem` and, for a message, its `Message`) and `ItemUnsaved`, which the other sessions of the user get as
|
|
37
|
+
events when something changed; the `GetSavedItems` command answered with `SavedItems` - the items, newest first, and
|
|
38
|
+
with `withMessages` the saved messages too. Items of rooms you are not a member of are left out until you rejoin.
|
|
39
|
+
Saving over the server limit fails with `ErrorCode.SavedItemsLimitReached` (`subcode` `Room` or `Message`). Bots have
|
|
40
|
+
none: their commands fail with `ErrorCode.UserType`.
|
|
41
|
+
- `ChatStateTracker.savedItems` (`SavedItemsManager`): `get(fetchWithMessages)` resolves with an observable collection
|
|
42
|
+
of the items keyed by `savedItemKey(type, id)`, `getMessages()` with the collection of the saved messages, and
|
|
43
|
+
`isSaved()`. Nothing is fetched until you ask; afterwards a reconnect fetches again what was fetched, with one request,
|
|
44
|
+
into the same collections. `ItemSaved` / `ItemUnsaved` (also from another device), edits and deletions of the saved
|
|
45
|
+
messages and deleted rooms change the collections; leaving a room hides its items and rejoining brings them back. The
|
|
46
|
+
collection order is not meaningful - sort by `SavedItem.savedAt`. Saved items are not part of the state snapshot.
|
|
47
|
+
- The `StartCalls` permission (`2 ** 34`, up to the room layer): starting a call in a room, in every call mode. It
|
|
48
|
+
takes effect only together with `JoinCalls`, as whoever starts a call joins it.
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- Room call permissions mean the same in every call mode. `JoinCalls` lets you join an ongoing call and no longer
|
|
53
|
+
start one: without `StartCalls` the `JoinCall` that would start a call fails with the `AccessDeniedException` error.
|
|
54
|
+
`ManageCalls` no longer lets you start an event (`Stage`). Whoever starts an event speaks in it, also without
|
|
55
|
+
`ManageCalls`. Private conversations still check none of these.
|
|
8
56
|
|
|
9
57
|
## [0.14.0]
|
|
10
58
|
|
package/build/index.cjs.js
CHANGED
|
@@ -69,7 +69,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
69
69
|
WebSocketChatClient: () => (/* reexport */ WebSocketChatClient),
|
|
70
70
|
extractUserFromMember: () => (/* reexport */ extractUserFromMember),
|
|
71
71
|
getPmPeers: () => (/* reexport */ getPmPeers),
|
|
72
|
-
isGroupPm: () => (/* reexport */ isGroupPm)
|
|
72
|
+
isGroupPm: () => (/* reexport */ isGroupPm),
|
|
73
|
+
savedItemKey: () => (/* reexport */ savedItemKey)
|
|
73
74
|
});
|
|
74
75
|
|
|
75
76
|
;// ./src/EventTarget.ts
|
|
@@ -3553,6 +3554,10 @@ class Permissions {
|
|
|
3553
3554
|
ManageCalls: {
|
|
3554
3555
|
value: 2 ** 33,
|
|
3555
3556
|
maxLayer: Layer.Room
|
|
3557
|
+
},
|
|
3558
|
+
StartCalls: {
|
|
3559
|
+
value: 2 ** 34,
|
|
3560
|
+
maxLayer: Layer.Room
|
|
3556
3561
|
}
|
|
3557
3562
|
};
|
|
3558
3563
|
|
|
@@ -4320,6 +4325,395 @@ class CallsManager {
|
|
|
4320
4325
|
this.ringing.delete(...roomIdsOf(this.ringing.items.map(incoming => incoming.call)));
|
|
4321
4326
|
}
|
|
4322
4327
|
}
|
|
4328
|
+
;// ./src/state-tracker/ActivitiesManager.ts
|
|
4329
|
+
|
|
4330
|
+
|
|
4331
|
+
|
|
4332
|
+
// Mirror the server, so a live activity joins its group as the stored one did
|
|
4333
|
+
const VISIBLE_LIMIT = 20;
|
|
4334
|
+
const GROUP_SCAN = 5;
|
|
4335
|
+
const MAX_ACTORS = 3;
|
|
4336
|
+
const time = isoDate => isoDate ? Date.parse(isoDate) : 0;
|
|
4337
|
+
const newestFirst = (a, b) => time(b.createdAt) - time(a.createdAt);
|
|
4338
|
+
|
|
4339
|
+
// A reaction is to one's own message, so acknowledging it says nothing about the reaction
|
|
4340
|
+
const isReadWithAck = activity => activity.type !== 'Reaction' && activity.type !== 'Custom';
|
|
4341
|
+
|
|
4342
|
+
// Message ids are time-ordered and their base58 form has a fixed length, so they compare as strings
|
|
4343
|
+
const isAcknowledged = (activity, topicId, lastAckMessageId) => isReadWithAck(activity) && activity.location?.topicId === topicId && activity.messageId !== null && activity.messageId <= lastAckMessageId;
|
|
4344
|
+
class ActivitiesManager extends EventTarget {
|
|
4345
|
+
activities = new ObservableIndexedObjectCollection('id');
|
|
4346
|
+
messages = new ObservableIndexedObjectCollection('id');
|
|
4347
|
+
users = new ObservableIndexedObjectCollection('id');
|
|
4348
|
+
promises = new PromiseRegistry();
|
|
4349
|
+
acks = new Map();
|
|
4350
|
+
hiddenRoomIds = new Set();
|
|
4351
|
+
activitiesWanted = false;
|
|
4352
|
+
messagesWanted = false;
|
|
4353
|
+
refreshScheduled = false;
|
|
4354
|
+
seen = null;
|
|
4355
|
+
constructor(tracker) {
|
|
4356
|
+
super();
|
|
4357
|
+
this.tracker = tracker;
|
|
4358
|
+
this.tracker.client.on('NewActivity', ev => this.handleNewActivity(ev));
|
|
4359
|
+
this.tracker.client.on('ActivityUpdated', ev => this.handleActivityUpdated(ev));
|
|
4360
|
+
this.tracker.client.on('ActivityDeleted', ev => this.handleActivityDeleted(ev));
|
|
4361
|
+
this.tracker.client.on('FollowedTopicUpdated', ev => this.handleFollowedTopicUpdated(ev));
|
|
4362
|
+
this.tracker.client.on('MessageUpdated', ev => this.handleMessageUpdated(ev));
|
|
4363
|
+
this.tracker.client.on('MessagesRedacted', ev => this.handleMessagesRedacted(ev));
|
|
4364
|
+
this.tracker.client.on('RoomDeleted', ev => this.handleRoomDeleted(ev));
|
|
4365
|
+
this.tracker.client.on('RoomLeft', ev => this.handleRoomLeft(ev));
|
|
4366
|
+
this.tracker.client.on('RoomJoined', ev => this.handleRoomJoined(ev));
|
|
4367
|
+
this.tracker.client.on('Session', () => this.handleSession());
|
|
4368
|
+
}
|
|
4369
|
+
|
|
4370
|
+
/**
|
|
4371
|
+
* Your latest activities, keyed by id; always the same collection. The first call fetches them, later ones resolve
|
|
4372
|
+
* with them. Once fetched, they are fetched again after every reconnect, also when the first fetch failed because
|
|
4373
|
+
* the connection was not ready yet. The collection keeps no meaningful order - sort by `createdAt`. Marking the list
|
|
4374
|
+
* as seen and clearing it is done with the `UpdateActivities` command.
|
|
4375
|
+
* @param fetchWithMessages Fetch the messages and the actors of the activities along, so {@link getMessages} and
|
|
4376
|
+
* {@link getUsers} need no request.
|
|
4377
|
+
*/
|
|
4378
|
+
async get(fetchWithMessages = false) {
|
|
4379
|
+
if (fetchWithMessages) {
|
|
4380
|
+
await this.getMessages();
|
|
4381
|
+
}
|
|
4382
|
+
if (this.promises.notExist('activities')) {
|
|
4383
|
+
this.activitiesWanted = true;
|
|
4384
|
+
this.registerFetch(false);
|
|
4385
|
+
}
|
|
4386
|
+
await this.promises.get('activities');
|
|
4387
|
+
return this.activities;
|
|
4388
|
+
}
|
|
4389
|
+
|
|
4390
|
+
/**
|
|
4391
|
+
* The messages the activities point at, keyed by message id; always the same collection. The first call fetches
|
|
4392
|
+
* them together with the list of {@link get}, unless they were fetched already; afterwards they come with new
|
|
4393
|
+
* activities, follow the edits and are fetched again after every reconnect.
|
|
4394
|
+
*/
|
|
4395
|
+
async getMessages() {
|
|
4396
|
+
if (this.promises.notExist('messages')) {
|
|
4397
|
+
this.activitiesWanted = true;
|
|
4398
|
+
this.messagesWanted = true;
|
|
4399
|
+
this.registerFetch(true);
|
|
4400
|
+
}
|
|
4401
|
+
await this.promises.get('messages');
|
|
4402
|
+
return this.messages;
|
|
4403
|
+
}
|
|
4404
|
+
|
|
4405
|
+
/**
|
|
4406
|
+
* The actors of the activities, keyed by user id; always the same collection, fetched and kept together with
|
|
4407
|
+
* {@link getMessages}.
|
|
4408
|
+
*/
|
|
4409
|
+
async getUsers() {
|
|
4410
|
+
await this.getMessages();
|
|
4411
|
+
return this.users;
|
|
4412
|
+
}
|
|
4413
|
+
|
|
4414
|
+
/**
|
|
4415
|
+
* When the list was last seen, on any device; null until it is fetched or while it was never seen. A change emits
|
|
4416
|
+
* `seenAtChange`. Activities created later that are not {@link Activity.isRead} are the unread ones.
|
|
4417
|
+
*/
|
|
4418
|
+
get seenAt() {
|
|
4419
|
+
return this.seen;
|
|
4420
|
+
}
|
|
4421
|
+
registerFetch(withMessages) {
|
|
4422
|
+
const fetching = this.fetch(withMessages);
|
|
4423
|
+
this.promises.register(fetching, 'activities');
|
|
4424
|
+
if (withMessages) {
|
|
4425
|
+
this.promises.register(fetching, 'messages');
|
|
4426
|
+
}
|
|
4427
|
+
}
|
|
4428
|
+
async fetch(withMessages) {
|
|
4429
|
+
const result = await this.tracker.client.send('GetActivities', {
|
|
4430
|
+
withMessages
|
|
4431
|
+
});
|
|
4432
|
+
if (result.error) {
|
|
4433
|
+
throw result.error;
|
|
4434
|
+
}
|
|
4435
|
+
this.apply(result.data, withMessages);
|
|
4436
|
+
}
|
|
4437
|
+
apply(ev, withMessages) {
|
|
4438
|
+
this.activities.reconcile(...ev.activities);
|
|
4439
|
+
if (withMessages) {
|
|
4440
|
+
this.messages.reconcile(...ev.messages);
|
|
4441
|
+
this.users.reconcile(...ev.users);
|
|
4442
|
+
}
|
|
4443
|
+
this.setSeen(ev.seenAt);
|
|
4444
|
+
}
|
|
4445
|
+
refresh() {
|
|
4446
|
+
if (this.messagesWanted) {
|
|
4447
|
+
this.registerFetch(true);
|
|
4448
|
+
} else if (this.activitiesWanted) {
|
|
4449
|
+
this.registerFetch(false);
|
|
4450
|
+
}
|
|
4451
|
+
this.promises.get('activities')?.catch(() => {});
|
|
4452
|
+
}
|
|
4453
|
+
setSeen(seenAt) {
|
|
4454
|
+
if (seenAt !== this.seen) {
|
|
4455
|
+
this.seen = seenAt;
|
|
4456
|
+
this.emit('seenAtChange', {});
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
4459
|
+
handleNewActivity(ev) {
|
|
4460
|
+
if (!this.activitiesWanted) {
|
|
4461
|
+
return;
|
|
4462
|
+
}
|
|
4463
|
+
const topicId = ev.activity.location?.topicId ?? '';
|
|
4464
|
+
const lastAck = this.acks.get(topicId);
|
|
4465
|
+
const added = lastAck && isAcknowledged(ev.activity, topicId, lastAck) ? {
|
|
4466
|
+
...ev.activity,
|
|
4467
|
+
isRead: true
|
|
4468
|
+
} : ev.activity;
|
|
4469
|
+
const newest = this.activities.items.sort(newestFirst);
|
|
4470
|
+
const group = added.groupKey === null ? undefined : newest.slice(0, GROUP_SCAN).find(activity => activity.groupKey === added.groupKey);
|
|
4471
|
+
if (group && time(group.createdAt) > time(this.seen)) {
|
|
4472
|
+
this.activities.set({
|
|
4473
|
+
...added,
|
|
4474
|
+
id: group.id,
|
|
4475
|
+
count: group.count + 1,
|
|
4476
|
+
actorIds: [...new Set([...added.actorIds, ...group.actorIds])].slice(0, MAX_ACTORS)
|
|
4477
|
+
});
|
|
4478
|
+
} else {
|
|
4479
|
+
this.activities.set(added);
|
|
4480
|
+
this.activities.delete(...newest.slice(VISIBLE_LIMIT - 1).map(activity => activity.id));
|
|
4481
|
+
}
|
|
4482
|
+
if (this.messagesWanted) {
|
|
4483
|
+
if (ev.message) {
|
|
4484
|
+
this.messages.set(ev.message);
|
|
4485
|
+
}
|
|
4486
|
+
this.users.set(...ev.users);
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
handleActivityUpdated(ev) {
|
|
4490
|
+
if (time(ev.seenAt) > time(this.seen)) {
|
|
4491
|
+
this.setSeen(ev.seenAt);
|
|
4492
|
+
}
|
|
4493
|
+
if (ev.cleared) {
|
|
4494
|
+
this.activities.deleteAll();
|
|
4495
|
+
this.messages.deleteAll();
|
|
4496
|
+
this.users.deleteAll();
|
|
4497
|
+
}
|
|
4498
|
+
}
|
|
4499
|
+
handleActivityDeleted(ev) {
|
|
4500
|
+
if (this.activities.has(ev.id)) {
|
|
4501
|
+
this.activities.delete(ev.id);
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
handleFollowedTopicUpdated(ev) {
|
|
4505
|
+
const {
|
|
4506
|
+
location,
|
|
4507
|
+
lastAckMessageId
|
|
4508
|
+
} = ev.followedTopic;
|
|
4509
|
+
if (!location.topicId || !lastAckMessageId) {
|
|
4510
|
+
return;
|
|
4511
|
+
}
|
|
4512
|
+
|
|
4513
|
+
// An acknowledgement may come before the activity of the same message
|
|
4514
|
+
this.acks.set(location.topicId, lastAckMessageId);
|
|
4515
|
+
const read = this.activities.items.filter(activity => !activity.isRead && isAcknowledged(activity, location.topicId, lastAckMessageId)).map(activity => ({
|
|
4516
|
+
...activity,
|
|
4517
|
+
isRead: true
|
|
4518
|
+
}));
|
|
4519
|
+
this.activities.set(...read);
|
|
4520
|
+
}
|
|
4521
|
+
handleMessageUpdated(ev) {
|
|
4522
|
+
if (this.messages.has(ev.message.id)) {
|
|
4523
|
+
this.messages.set(ev.message);
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4526
|
+
handleMessagesRedacted(ev) {
|
|
4527
|
+
const ids = new Set(ev.ids);
|
|
4528
|
+
this.deleteActivities(activity => activity.messageId !== null && ids.has(activity.messageId));
|
|
4529
|
+
}
|
|
4530
|
+
handleRoomDeleted(ev) {
|
|
4531
|
+
this.hiddenRoomIds.delete(ev.id);
|
|
4532
|
+
this.deleteActivities(activity => activity.location?.roomId === ev.id);
|
|
4533
|
+
}
|
|
4534
|
+
handleRoomLeft(ev) {
|
|
4535
|
+
// The server keeps them and hands them back once you rejoin
|
|
4536
|
+
if (this.deleteActivities(activity => activity.location?.roomId === ev.id)) {
|
|
4537
|
+
this.hiddenRoomIds.add(ev.id);
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
handleRoomJoined(ev) {
|
|
4541
|
+
if (!this.hiddenRoomIds.delete(ev.room.id) || this.refreshScheduled) {
|
|
4542
|
+
return;
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4545
|
+
// Joining a space joins its rooms one by one; one request brings back the activities of all of them
|
|
4546
|
+
this.refreshScheduled = true;
|
|
4547
|
+
setTimeout(() => {
|
|
4548
|
+
this.refreshScheduled = false;
|
|
4549
|
+
this.refresh();
|
|
4550
|
+
}, 0);
|
|
4551
|
+
}
|
|
4552
|
+
deleteActivities(predicate) {
|
|
4553
|
+
const deleted = this.activities.items.filter(predicate);
|
|
4554
|
+
const messageIds = deleted.map(activity => activity.messageId).filter(id => id !== null && this.messages.has(id));
|
|
4555
|
+
this.activities.delete(...deleted.map(activity => activity.id));
|
|
4556
|
+
this.messages.delete(...messageIds);
|
|
4557
|
+
return deleted.length > 0;
|
|
4558
|
+
}
|
|
4559
|
+
handleSession() {
|
|
4560
|
+
this.acks.clear();
|
|
4561
|
+
this.promises.forgetAll();
|
|
4562
|
+
this.refresh();
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4565
|
+
;// ./src/state-tracker/SavedItemsManager.ts
|
|
4566
|
+
|
|
4567
|
+
|
|
4568
|
+
/**
|
|
4569
|
+
* The key of a saved item in the collection returned by {@link SavedItemsManager.get}.
|
|
4570
|
+
*/
|
|
4571
|
+
const savedItemKey = (type, id) => `${type}:${id}`;
|
|
4572
|
+
const keyOf = item => savedItemKey(item.type, item.id);
|
|
4573
|
+
class SavedItemsManager {
|
|
4574
|
+
items = new ObservableIndexedObjectCollection(keyOf);
|
|
4575
|
+
messages = new ObservableIndexedObjectCollection('id');
|
|
4576
|
+
promises = new PromiseRegistry();
|
|
4577
|
+
hiddenRoomIds = new Set();
|
|
4578
|
+
itemsWanted = false;
|
|
4579
|
+
messagesWanted = false;
|
|
4580
|
+
refreshScheduled = false;
|
|
4581
|
+
constructor(tracker) {
|
|
4582
|
+
this.tracker = tracker;
|
|
4583
|
+
this.tracker.client.on('ItemSaved', ev => this.handleItemSaved(ev));
|
|
4584
|
+
this.tracker.client.on('ItemUnsaved', ev => this.handleItemUnsaved(ev));
|
|
4585
|
+
this.tracker.client.on('MessageUpdated', ev => this.handleMessageUpdated(ev));
|
|
4586
|
+
this.tracker.client.on('MessagesRedacted', ev => this.handleMessagesRedacted(ev));
|
|
4587
|
+
this.tracker.client.on('RoomDeleted', ev => this.handleRoomDeleted(ev));
|
|
4588
|
+
this.tracker.client.on('RoomLeft', ev => this.handleRoomLeft(ev));
|
|
4589
|
+
this.tracker.client.on('RoomJoined', ev => this.handleRoomJoined(ev));
|
|
4590
|
+
this.tracker.client.on('Session', () => this.handleSession());
|
|
4591
|
+
}
|
|
4592
|
+
|
|
4593
|
+
/**
|
|
4594
|
+
* The rooms and messages you saved, keyed by {@link savedItemKey}; always the same collection. The first call fetches
|
|
4595
|
+
* the list, later ones resolve with it. Items of rooms you are not a member of are left out until you rejoin. The
|
|
4596
|
+
* collection keeps no meaningful order - sort by `savedAt`. Once fetched, the list is fetched again after every
|
|
4597
|
+
* reconnect. Saving and unsaving is done with the `SaveItem` and `UnsaveItem` commands.
|
|
4598
|
+
* @param fetchWithMessages Fetch the contents of the saved messages along, so {@link getMessages} needs no request.
|
|
4599
|
+
*/
|
|
4600
|
+
async get(fetchWithMessages = false) {
|
|
4601
|
+
if (fetchWithMessages) {
|
|
4602
|
+
await this.getMessages();
|
|
4603
|
+
}
|
|
4604
|
+
if (this.promises.notExist('items')) {
|
|
4605
|
+
this.itemsWanted = true;
|
|
4606
|
+
this.registerFetch(false);
|
|
4607
|
+
}
|
|
4608
|
+
await this.promises.get('items');
|
|
4609
|
+
return this.items;
|
|
4610
|
+
}
|
|
4611
|
+
|
|
4612
|
+
/**
|
|
4613
|
+
* The contents of the saved messages, keyed by message id; always the same collection. The first call fetches them
|
|
4614
|
+
* together with the list of {@link get}, unless they were fetched already; afterwards they follow the edits and are
|
|
4615
|
+
* fetched again after every reconnect.
|
|
4616
|
+
*/
|
|
4617
|
+
async getMessages() {
|
|
4618
|
+
if (this.promises.notExist('messages')) {
|
|
4619
|
+
this.itemsWanted = true;
|
|
4620
|
+
this.messagesWanted = true;
|
|
4621
|
+
this.registerFetch(true);
|
|
4622
|
+
}
|
|
4623
|
+
await this.promises.get('messages');
|
|
4624
|
+
return this.messages;
|
|
4625
|
+
}
|
|
4626
|
+
async isSaved(type, id) {
|
|
4627
|
+
return (await this.get()).has(savedItemKey(type, id));
|
|
4628
|
+
}
|
|
4629
|
+
registerFetch(withMessages) {
|
|
4630
|
+
const fetching = this.fetch(withMessages);
|
|
4631
|
+
this.promises.register(fetching, 'items');
|
|
4632
|
+
if (withMessages) {
|
|
4633
|
+
this.promises.register(fetching, 'messages');
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
async fetch(withMessages) {
|
|
4637
|
+
const result = await this.tracker.client.send('GetSavedItems', {
|
|
4638
|
+
withMessages
|
|
4639
|
+
});
|
|
4640
|
+
if (result.error) {
|
|
4641
|
+
throw result.error;
|
|
4642
|
+
}
|
|
4643
|
+
this.apply(result.data, withMessages);
|
|
4644
|
+
}
|
|
4645
|
+
apply(ev, withMessages) {
|
|
4646
|
+
this.items.reconcile(...ev.items);
|
|
4647
|
+
if (withMessages) {
|
|
4648
|
+
this.messages.reconcile(...ev.messages);
|
|
4649
|
+
}
|
|
4650
|
+
}
|
|
4651
|
+
refresh() {
|
|
4652
|
+
if (this.messagesWanted) {
|
|
4653
|
+
this.registerFetch(true);
|
|
4654
|
+
} else if (this.itemsWanted) {
|
|
4655
|
+
this.registerFetch(false);
|
|
4656
|
+
}
|
|
4657
|
+
this.promises.get('items')?.catch(() => {});
|
|
4658
|
+
}
|
|
4659
|
+
handleItemSaved(ev) {
|
|
4660
|
+
if (!this.itemsWanted) {
|
|
4661
|
+
return;
|
|
4662
|
+
}
|
|
4663
|
+
this.items.set(ev.item);
|
|
4664
|
+
if (this.messagesWanted && ev.message) {
|
|
4665
|
+
this.messages.set(ev.message);
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4668
|
+
handleItemUnsaved(ev) {
|
|
4669
|
+
this.items.delete(savedItemKey(ev.type, ev.id));
|
|
4670
|
+
if (ev.type === 'Message') {
|
|
4671
|
+
this.messages.delete(ev.id);
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
handleMessageUpdated(ev) {
|
|
4675
|
+
if (this.messages.has(ev.message.id)) {
|
|
4676
|
+
this.messages.set(ev.message);
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
handleMessagesRedacted(ev) {
|
|
4680
|
+
const saved = ev.ids.filter(id => this.items.has(savedItemKey('Message', id)));
|
|
4681
|
+
this.items.delete(...saved.map(id => savedItemKey('Message', id)));
|
|
4682
|
+
this.messages.delete(...saved.filter(id => this.messages.has(id)));
|
|
4683
|
+
}
|
|
4684
|
+
handleRoomDeleted(ev) {
|
|
4685
|
+
this.hiddenRoomIds.delete(ev.id);
|
|
4686
|
+
this.deleteRoomItems(ev.id);
|
|
4687
|
+
}
|
|
4688
|
+
handleRoomLeft(ev) {
|
|
4689
|
+
// The server keeps them and hands them back once you rejoin
|
|
4690
|
+
if (this.deleteRoomItems(ev.id)) {
|
|
4691
|
+
this.hiddenRoomIds.add(ev.id);
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
handleRoomJoined(ev) {
|
|
4695
|
+
if (!this.hiddenRoomIds.delete(ev.room.id) || this.refreshScheduled) {
|
|
4696
|
+
return;
|
|
4697
|
+
}
|
|
4698
|
+
|
|
4699
|
+
// Joining a space joins its rooms one by one; one request brings back the items of all of them
|
|
4700
|
+
this.refreshScheduled = true;
|
|
4701
|
+
setTimeout(() => {
|
|
4702
|
+
this.refreshScheduled = false;
|
|
4703
|
+
this.refresh();
|
|
4704
|
+
}, 0);
|
|
4705
|
+
}
|
|
4706
|
+
deleteRoomItems(roomId) {
|
|
4707
|
+
const items = this.items.items.filter(item => item.roomId === roomId);
|
|
4708
|
+
this.items.delete(...items.map(keyOf));
|
|
4709
|
+
this.messages.delete(...items.filter(item => this.messages.has(item.id)).map(item => item.id));
|
|
4710
|
+
return items.length > 0;
|
|
4711
|
+
}
|
|
4712
|
+
handleSession() {
|
|
4713
|
+
this.promises.forgetAll();
|
|
4714
|
+
this.refresh();
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4323
4717
|
;// ./src/state-tracker/ChatStateTracker.ts
|
|
4324
4718
|
|
|
4325
4719
|
|
|
@@ -4330,6 +4724,8 @@ class CallsManager {
|
|
|
4330
4724
|
|
|
4331
4725
|
|
|
4332
4726
|
|
|
4727
|
+
|
|
4728
|
+
|
|
4333
4729
|
class ChatStateTracker {
|
|
4334
4730
|
client;
|
|
4335
4731
|
|
|
@@ -4367,6 +4763,19 @@ class ChatStateTracker {
|
|
|
4367
4763
|
* State of the calls in your rooms and of the calls ringing at you.
|
|
4368
4764
|
*/
|
|
4369
4765
|
calls;
|
|
4766
|
+
|
|
4767
|
+
/**
|
|
4768
|
+
* Your latest personal events from all spaces (mentions, replies, reactions, followed threads, missed calls) and the
|
|
4769
|
+
* activities the server publishes. Private conversations keep their own unread state. Nothing is fetched until you
|
|
4770
|
+
* ask for it. Not part of the state snapshot.
|
|
4771
|
+
*/
|
|
4772
|
+
activities;
|
|
4773
|
+
|
|
4774
|
+
/**
|
|
4775
|
+
* The rooms and messages you saved, from all spaces. Nothing is fetched until you ask for it. Not part of the state
|
|
4776
|
+
* snapshot.
|
|
4777
|
+
*/
|
|
4778
|
+
savedItems;
|
|
4370
4779
|
_me = null;
|
|
4371
4780
|
deferredSession = new DeferredTask();
|
|
4372
4781
|
sessionReceived = false;
|
|
@@ -4381,6 +4790,8 @@ class ChatStateTracker {
|
|
|
4381
4790
|
this.users = new UsersManager(this);
|
|
4382
4791
|
this.relationships = new RelationshipsManager(this);
|
|
4383
4792
|
this.calls = new CallsManager(this);
|
|
4793
|
+
this.activities = new ActivitiesManager(this);
|
|
4794
|
+
this.savedItems = new SavedItemsManager(this);
|
|
4384
4795
|
|
|
4385
4796
|
// Registered after the managers, so it runs once they have applied the session.
|
|
4386
4797
|
this.client.on('Session', ev => this.handleSessionAfterImport(ev));
|
|
@@ -5017,10 +5428,12 @@ let ErrorCode = /*#__PURE__*/function (ErrorCode) {
|
|
|
5017
5428
|
ErrorCode["ReactionExistsAlready"] = "ReactionExistsAlreadyException";
|
|
5018
5429
|
ErrorCode["RoomIgnored"] = "RoomIgnoredException";
|
|
5019
5430
|
ErrorCode["RoomNotFound"] = "RoomNotFoundException";
|
|
5431
|
+
ErrorCode["SavedItemsLimitReached"] = "SavedItemsLimitReachedException";
|
|
5020
5432
|
ErrorCode["SpaceJoinRestricted"] = "SpaceJoinRestrictedException";
|
|
5021
5433
|
ErrorCode["TooManyCallInvitees"] = "TooManyCallInviteesException";
|
|
5022
5434
|
ErrorCode["TopicNotFound"] = "TopicNotFoundException";
|
|
5023
5435
|
ErrorCode["UserNotFound"] = "UserNotFoundException";
|
|
5436
|
+
ErrorCode["UserType"] = "UserTypeException";
|
|
5024
5437
|
return ErrorCode;
|
|
5025
5438
|
}({});
|
|
5026
5439
|
;// ./src/protocol/schemes/MessageEmbed.ts
|
|
@@ -5163,6 +5576,7 @@ let SpaceIntent = /*#__PURE__*/function (SpaceIntent) {
|
|
|
5163
5576
|
|
|
5164
5577
|
|
|
5165
5578
|
|
|
5579
|
+
|
|
5166
5580
|
module.exports = __webpack_exports__;
|
|
5167
5581
|
/******/ })()
|
|
5168
5582
|
;
|