@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/build/index.mjs
CHANGED
|
@@ -3503,6 +3503,10 @@ class Permissions {
|
|
|
3503
3503
|
ManageCalls: {
|
|
3504
3504
|
value: 2 ** 33,
|
|
3505
3505
|
maxLayer: Layer.Room
|
|
3506
|
+
},
|
|
3507
|
+
StartCalls: {
|
|
3508
|
+
value: 2 ** 34,
|
|
3509
|
+
maxLayer: Layer.Room
|
|
3506
3510
|
}
|
|
3507
3511
|
};
|
|
3508
3512
|
|
|
@@ -4270,6 +4274,395 @@ class CallsManager {
|
|
|
4270
4274
|
this.ringing.delete(...roomIdsOf(this.ringing.items.map(incoming => incoming.call)));
|
|
4271
4275
|
}
|
|
4272
4276
|
}
|
|
4277
|
+
;// ./src/state-tracker/ActivitiesManager.ts
|
|
4278
|
+
|
|
4279
|
+
|
|
4280
|
+
|
|
4281
|
+
// Mirror the server, so a live activity joins its group as the stored one did
|
|
4282
|
+
const VISIBLE_LIMIT = 20;
|
|
4283
|
+
const GROUP_SCAN = 5;
|
|
4284
|
+
const MAX_ACTORS = 3;
|
|
4285
|
+
const time = isoDate => isoDate ? Date.parse(isoDate) : 0;
|
|
4286
|
+
const newestFirst = (a, b) => time(b.createdAt) - time(a.createdAt);
|
|
4287
|
+
|
|
4288
|
+
// A reaction is to one's own message, so acknowledging it says nothing about the reaction
|
|
4289
|
+
const isReadWithAck = activity => activity.type !== 'Reaction' && activity.type !== 'Custom';
|
|
4290
|
+
|
|
4291
|
+
// Message ids are time-ordered and their base58 form has a fixed length, so they compare as strings
|
|
4292
|
+
const isAcknowledged = (activity, topicId, lastAckMessageId) => isReadWithAck(activity) && activity.location?.topicId === topicId && activity.messageId !== null && activity.messageId <= lastAckMessageId;
|
|
4293
|
+
class ActivitiesManager extends EventTarget {
|
|
4294
|
+
activities = new ObservableIndexedObjectCollection('id');
|
|
4295
|
+
messages = new ObservableIndexedObjectCollection('id');
|
|
4296
|
+
users = new ObservableIndexedObjectCollection('id');
|
|
4297
|
+
promises = new PromiseRegistry();
|
|
4298
|
+
acks = new Map();
|
|
4299
|
+
hiddenRoomIds = new Set();
|
|
4300
|
+
activitiesWanted = false;
|
|
4301
|
+
messagesWanted = false;
|
|
4302
|
+
refreshScheduled = false;
|
|
4303
|
+
seen = null;
|
|
4304
|
+
constructor(tracker) {
|
|
4305
|
+
super();
|
|
4306
|
+
this.tracker = tracker;
|
|
4307
|
+
this.tracker.client.on('NewActivity', ev => this.handleNewActivity(ev));
|
|
4308
|
+
this.tracker.client.on('ActivityUpdated', ev => this.handleActivityUpdated(ev));
|
|
4309
|
+
this.tracker.client.on('ActivityDeleted', ev => this.handleActivityDeleted(ev));
|
|
4310
|
+
this.tracker.client.on('FollowedTopicUpdated', ev => this.handleFollowedTopicUpdated(ev));
|
|
4311
|
+
this.tracker.client.on('MessageUpdated', ev => this.handleMessageUpdated(ev));
|
|
4312
|
+
this.tracker.client.on('MessagesRedacted', ev => this.handleMessagesRedacted(ev));
|
|
4313
|
+
this.tracker.client.on('RoomDeleted', ev => this.handleRoomDeleted(ev));
|
|
4314
|
+
this.tracker.client.on('RoomLeft', ev => this.handleRoomLeft(ev));
|
|
4315
|
+
this.tracker.client.on('RoomJoined', ev => this.handleRoomJoined(ev));
|
|
4316
|
+
this.tracker.client.on('Session', () => this.handleSession());
|
|
4317
|
+
}
|
|
4318
|
+
|
|
4319
|
+
/**
|
|
4320
|
+
* Your latest activities, keyed by id; always the same collection. The first call fetches them, later ones resolve
|
|
4321
|
+
* with them. Once fetched, they are fetched again after every reconnect, also when the first fetch failed because
|
|
4322
|
+
* the connection was not ready yet. The collection keeps no meaningful order - sort by `createdAt`. Marking the list
|
|
4323
|
+
* as seen and clearing it is done with the `UpdateActivities` command.
|
|
4324
|
+
* @param fetchWithMessages Fetch the messages and the actors of the activities along, so {@link getMessages} and
|
|
4325
|
+
* {@link getUsers} need no request.
|
|
4326
|
+
*/
|
|
4327
|
+
async get(fetchWithMessages = false) {
|
|
4328
|
+
if (fetchWithMessages) {
|
|
4329
|
+
await this.getMessages();
|
|
4330
|
+
}
|
|
4331
|
+
if (this.promises.notExist('activities')) {
|
|
4332
|
+
this.activitiesWanted = true;
|
|
4333
|
+
this.registerFetch(false);
|
|
4334
|
+
}
|
|
4335
|
+
await this.promises.get('activities');
|
|
4336
|
+
return this.activities;
|
|
4337
|
+
}
|
|
4338
|
+
|
|
4339
|
+
/**
|
|
4340
|
+
* The messages the activities point at, keyed by message id; always the same collection. The first call fetches
|
|
4341
|
+
* them together with the list of {@link get}, unless they were fetched already; afterwards they come with new
|
|
4342
|
+
* activities, follow the edits and are fetched again after every reconnect.
|
|
4343
|
+
*/
|
|
4344
|
+
async getMessages() {
|
|
4345
|
+
if (this.promises.notExist('messages')) {
|
|
4346
|
+
this.activitiesWanted = true;
|
|
4347
|
+
this.messagesWanted = true;
|
|
4348
|
+
this.registerFetch(true);
|
|
4349
|
+
}
|
|
4350
|
+
await this.promises.get('messages');
|
|
4351
|
+
return this.messages;
|
|
4352
|
+
}
|
|
4353
|
+
|
|
4354
|
+
/**
|
|
4355
|
+
* The actors of the activities, keyed by user id; always the same collection, fetched and kept together with
|
|
4356
|
+
* {@link getMessages}.
|
|
4357
|
+
*/
|
|
4358
|
+
async getUsers() {
|
|
4359
|
+
await this.getMessages();
|
|
4360
|
+
return this.users;
|
|
4361
|
+
}
|
|
4362
|
+
|
|
4363
|
+
/**
|
|
4364
|
+
* When the list was last seen, on any device; null until it is fetched or while it was never seen. A change emits
|
|
4365
|
+
* `seenAtChange`. Activities created later that are not {@link Activity.isRead} are the unread ones.
|
|
4366
|
+
*/
|
|
4367
|
+
get seenAt() {
|
|
4368
|
+
return this.seen;
|
|
4369
|
+
}
|
|
4370
|
+
registerFetch(withMessages) {
|
|
4371
|
+
const fetching = this.fetch(withMessages);
|
|
4372
|
+
this.promises.register(fetching, 'activities');
|
|
4373
|
+
if (withMessages) {
|
|
4374
|
+
this.promises.register(fetching, 'messages');
|
|
4375
|
+
}
|
|
4376
|
+
}
|
|
4377
|
+
async fetch(withMessages) {
|
|
4378
|
+
const result = await this.tracker.client.send('GetActivities', {
|
|
4379
|
+
withMessages
|
|
4380
|
+
});
|
|
4381
|
+
if (result.error) {
|
|
4382
|
+
throw result.error;
|
|
4383
|
+
}
|
|
4384
|
+
this.apply(result.data, withMessages);
|
|
4385
|
+
}
|
|
4386
|
+
apply(ev, withMessages) {
|
|
4387
|
+
this.activities.reconcile(...ev.activities);
|
|
4388
|
+
if (withMessages) {
|
|
4389
|
+
this.messages.reconcile(...ev.messages);
|
|
4390
|
+
this.users.reconcile(...ev.users);
|
|
4391
|
+
}
|
|
4392
|
+
this.setSeen(ev.seenAt);
|
|
4393
|
+
}
|
|
4394
|
+
refresh() {
|
|
4395
|
+
if (this.messagesWanted) {
|
|
4396
|
+
this.registerFetch(true);
|
|
4397
|
+
} else if (this.activitiesWanted) {
|
|
4398
|
+
this.registerFetch(false);
|
|
4399
|
+
}
|
|
4400
|
+
this.promises.get('activities')?.catch(() => {});
|
|
4401
|
+
}
|
|
4402
|
+
setSeen(seenAt) {
|
|
4403
|
+
if (seenAt !== this.seen) {
|
|
4404
|
+
this.seen = seenAt;
|
|
4405
|
+
this.emit('seenAtChange', {});
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
handleNewActivity(ev) {
|
|
4409
|
+
if (!this.activitiesWanted) {
|
|
4410
|
+
return;
|
|
4411
|
+
}
|
|
4412
|
+
const topicId = ev.activity.location?.topicId ?? '';
|
|
4413
|
+
const lastAck = this.acks.get(topicId);
|
|
4414
|
+
const added = lastAck && isAcknowledged(ev.activity, topicId, lastAck) ? {
|
|
4415
|
+
...ev.activity,
|
|
4416
|
+
isRead: true
|
|
4417
|
+
} : ev.activity;
|
|
4418
|
+
const newest = this.activities.items.sort(newestFirst);
|
|
4419
|
+
const group = added.groupKey === null ? undefined : newest.slice(0, GROUP_SCAN).find(activity => activity.groupKey === added.groupKey);
|
|
4420
|
+
if (group && time(group.createdAt) > time(this.seen)) {
|
|
4421
|
+
this.activities.set({
|
|
4422
|
+
...added,
|
|
4423
|
+
id: group.id,
|
|
4424
|
+
count: group.count + 1,
|
|
4425
|
+
actorIds: [...new Set([...added.actorIds, ...group.actorIds])].slice(0, MAX_ACTORS)
|
|
4426
|
+
});
|
|
4427
|
+
} else {
|
|
4428
|
+
this.activities.set(added);
|
|
4429
|
+
this.activities.delete(...newest.slice(VISIBLE_LIMIT - 1).map(activity => activity.id));
|
|
4430
|
+
}
|
|
4431
|
+
if (this.messagesWanted) {
|
|
4432
|
+
if (ev.message) {
|
|
4433
|
+
this.messages.set(ev.message);
|
|
4434
|
+
}
|
|
4435
|
+
this.users.set(...ev.users);
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4438
|
+
handleActivityUpdated(ev) {
|
|
4439
|
+
if (time(ev.seenAt) > time(this.seen)) {
|
|
4440
|
+
this.setSeen(ev.seenAt);
|
|
4441
|
+
}
|
|
4442
|
+
if (ev.cleared) {
|
|
4443
|
+
this.activities.deleteAll();
|
|
4444
|
+
this.messages.deleteAll();
|
|
4445
|
+
this.users.deleteAll();
|
|
4446
|
+
}
|
|
4447
|
+
}
|
|
4448
|
+
handleActivityDeleted(ev) {
|
|
4449
|
+
if (this.activities.has(ev.id)) {
|
|
4450
|
+
this.activities.delete(ev.id);
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
handleFollowedTopicUpdated(ev) {
|
|
4454
|
+
const {
|
|
4455
|
+
location,
|
|
4456
|
+
lastAckMessageId
|
|
4457
|
+
} = ev.followedTopic;
|
|
4458
|
+
if (!location.topicId || !lastAckMessageId) {
|
|
4459
|
+
return;
|
|
4460
|
+
}
|
|
4461
|
+
|
|
4462
|
+
// An acknowledgement may come before the activity of the same message
|
|
4463
|
+
this.acks.set(location.topicId, lastAckMessageId);
|
|
4464
|
+
const read = this.activities.items.filter(activity => !activity.isRead && isAcknowledged(activity, location.topicId, lastAckMessageId)).map(activity => ({
|
|
4465
|
+
...activity,
|
|
4466
|
+
isRead: true
|
|
4467
|
+
}));
|
|
4468
|
+
this.activities.set(...read);
|
|
4469
|
+
}
|
|
4470
|
+
handleMessageUpdated(ev) {
|
|
4471
|
+
if (this.messages.has(ev.message.id)) {
|
|
4472
|
+
this.messages.set(ev.message);
|
|
4473
|
+
}
|
|
4474
|
+
}
|
|
4475
|
+
handleMessagesRedacted(ev) {
|
|
4476
|
+
const ids = new Set(ev.ids);
|
|
4477
|
+
this.deleteActivities(activity => activity.messageId !== null && ids.has(activity.messageId));
|
|
4478
|
+
}
|
|
4479
|
+
handleRoomDeleted(ev) {
|
|
4480
|
+
this.hiddenRoomIds.delete(ev.id);
|
|
4481
|
+
this.deleteActivities(activity => activity.location?.roomId === ev.id);
|
|
4482
|
+
}
|
|
4483
|
+
handleRoomLeft(ev) {
|
|
4484
|
+
// The server keeps them and hands them back once you rejoin
|
|
4485
|
+
if (this.deleteActivities(activity => activity.location?.roomId === ev.id)) {
|
|
4486
|
+
this.hiddenRoomIds.add(ev.id);
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
handleRoomJoined(ev) {
|
|
4490
|
+
if (!this.hiddenRoomIds.delete(ev.room.id) || this.refreshScheduled) {
|
|
4491
|
+
return;
|
|
4492
|
+
}
|
|
4493
|
+
|
|
4494
|
+
// Joining a space joins its rooms one by one; one request brings back the activities of all of them
|
|
4495
|
+
this.refreshScheduled = true;
|
|
4496
|
+
setTimeout(() => {
|
|
4497
|
+
this.refreshScheduled = false;
|
|
4498
|
+
this.refresh();
|
|
4499
|
+
}, 0);
|
|
4500
|
+
}
|
|
4501
|
+
deleteActivities(predicate) {
|
|
4502
|
+
const deleted = this.activities.items.filter(predicate);
|
|
4503
|
+
const messageIds = deleted.map(activity => activity.messageId).filter(id => id !== null && this.messages.has(id));
|
|
4504
|
+
this.activities.delete(...deleted.map(activity => activity.id));
|
|
4505
|
+
this.messages.delete(...messageIds);
|
|
4506
|
+
return deleted.length > 0;
|
|
4507
|
+
}
|
|
4508
|
+
handleSession() {
|
|
4509
|
+
this.acks.clear();
|
|
4510
|
+
this.promises.forgetAll();
|
|
4511
|
+
this.refresh();
|
|
4512
|
+
}
|
|
4513
|
+
}
|
|
4514
|
+
;// ./src/state-tracker/SavedItemsManager.ts
|
|
4515
|
+
|
|
4516
|
+
|
|
4517
|
+
/**
|
|
4518
|
+
* The key of a saved item in the collection returned by {@link SavedItemsManager.get}.
|
|
4519
|
+
*/
|
|
4520
|
+
const savedItemKey = (type, id) => `${type}:${id}`;
|
|
4521
|
+
const keyOf = item => savedItemKey(item.type, item.id);
|
|
4522
|
+
class SavedItemsManager {
|
|
4523
|
+
items = new ObservableIndexedObjectCollection(keyOf);
|
|
4524
|
+
messages = new ObservableIndexedObjectCollection('id');
|
|
4525
|
+
promises = new PromiseRegistry();
|
|
4526
|
+
hiddenRoomIds = new Set();
|
|
4527
|
+
itemsWanted = false;
|
|
4528
|
+
messagesWanted = false;
|
|
4529
|
+
refreshScheduled = false;
|
|
4530
|
+
constructor(tracker) {
|
|
4531
|
+
this.tracker = tracker;
|
|
4532
|
+
this.tracker.client.on('ItemSaved', ev => this.handleItemSaved(ev));
|
|
4533
|
+
this.tracker.client.on('ItemUnsaved', ev => this.handleItemUnsaved(ev));
|
|
4534
|
+
this.tracker.client.on('MessageUpdated', ev => this.handleMessageUpdated(ev));
|
|
4535
|
+
this.tracker.client.on('MessagesRedacted', ev => this.handleMessagesRedacted(ev));
|
|
4536
|
+
this.tracker.client.on('RoomDeleted', ev => this.handleRoomDeleted(ev));
|
|
4537
|
+
this.tracker.client.on('RoomLeft', ev => this.handleRoomLeft(ev));
|
|
4538
|
+
this.tracker.client.on('RoomJoined', ev => this.handleRoomJoined(ev));
|
|
4539
|
+
this.tracker.client.on('Session', () => this.handleSession());
|
|
4540
|
+
}
|
|
4541
|
+
|
|
4542
|
+
/**
|
|
4543
|
+
* The rooms and messages you saved, keyed by {@link savedItemKey}; always the same collection. The first call fetches
|
|
4544
|
+
* the list, later ones resolve with it. Items of rooms you are not a member of are left out until you rejoin. The
|
|
4545
|
+
* collection keeps no meaningful order - sort by `savedAt`. Once fetched, the list is fetched again after every
|
|
4546
|
+
* reconnect. Saving and unsaving is done with the `SaveItem` and `UnsaveItem` commands.
|
|
4547
|
+
* @param fetchWithMessages Fetch the contents of the saved messages along, so {@link getMessages} needs no request.
|
|
4548
|
+
*/
|
|
4549
|
+
async get(fetchWithMessages = false) {
|
|
4550
|
+
if (fetchWithMessages) {
|
|
4551
|
+
await this.getMessages();
|
|
4552
|
+
}
|
|
4553
|
+
if (this.promises.notExist('items')) {
|
|
4554
|
+
this.itemsWanted = true;
|
|
4555
|
+
this.registerFetch(false);
|
|
4556
|
+
}
|
|
4557
|
+
await this.promises.get('items');
|
|
4558
|
+
return this.items;
|
|
4559
|
+
}
|
|
4560
|
+
|
|
4561
|
+
/**
|
|
4562
|
+
* The contents of the saved messages, keyed by message id; always the same collection. The first call fetches them
|
|
4563
|
+
* together with the list of {@link get}, unless they were fetched already; afterwards they follow the edits and are
|
|
4564
|
+
* fetched again after every reconnect.
|
|
4565
|
+
*/
|
|
4566
|
+
async getMessages() {
|
|
4567
|
+
if (this.promises.notExist('messages')) {
|
|
4568
|
+
this.itemsWanted = true;
|
|
4569
|
+
this.messagesWanted = true;
|
|
4570
|
+
this.registerFetch(true);
|
|
4571
|
+
}
|
|
4572
|
+
await this.promises.get('messages');
|
|
4573
|
+
return this.messages;
|
|
4574
|
+
}
|
|
4575
|
+
async isSaved(type, id) {
|
|
4576
|
+
return (await this.get()).has(savedItemKey(type, id));
|
|
4577
|
+
}
|
|
4578
|
+
registerFetch(withMessages) {
|
|
4579
|
+
const fetching = this.fetch(withMessages);
|
|
4580
|
+
this.promises.register(fetching, 'items');
|
|
4581
|
+
if (withMessages) {
|
|
4582
|
+
this.promises.register(fetching, 'messages');
|
|
4583
|
+
}
|
|
4584
|
+
}
|
|
4585
|
+
async fetch(withMessages) {
|
|
4586
|
+
const result = await this.tracker.client.send('GetSavedItems', {
|
|
4587
|
+
withMessages
|
|
4588
|
+
});
|
|
4589
|
+
if (result.error) {
|
|
4590
|
+
throw result.error;
|
|
4591
|
+
}
|
|
4592
|
+
this.apply(result.data, withMessages);
|
|
4593
|
+
}
|
|
4594
|
+
apply(ev, withMessages) {
|
|
4595
|
+
this.items.reconcile(...ev.items);
|
|
4596
|
+
if (withMessages) {
|
|
4597
|
+
this.messages.reconcile(...ev.messages);
|
|
4598
|
+
}
|
|
4599
|
+
}
|
|
4600
|
+
refresh() {
|
|
4601
|
+
if (this.messagesWanted) {
|
|
4602
|
+
this.registerFetch(true);
|
|
4603
|
+
} else if (this.itemsWanted) {
|
|
4604
|
+
this.registerFetch(false);
|
|
4605
|
+
}
|
|
4606
|
+
this.promises.get('items')?.catch(() => {});
|
|
4607
|
+
}
|
|
4608
|
+
handleItemSaved(ev) {
|
|
4609
|
+
if (!this.itemsWanted) {
|
|
4610
|
+
return;
|
|
4611
|
+
}
|
|
4612
|
+
this.items.set(ev.item);
|
|
4613
|
+
if (this.messagesWanted && ev.message) {
|
|
4614
|
+
this.messages.set(ev.message);
|
|
4615
|
+
}
|
|
4616
|
+
}
|
|
4617
|
+
handleItemUnsaved(ev) {
|
|
4618
|
+
this.items.delete(savedItemKey(ev.type, ev.id));
|
|
4619
|
+
if (ev.type === 'Message') {
|
|
4620
|
+
this.messages.delete(ev.id);
|
|
4621
|
+
}
|
|
4622
|
+
}
|
|
4623
|
+
handleMessageUpdated(ev) {
|
|
4624
|
+
if (this.messages.has(ev.message.id)) {
|
|
4625
|
+
this.messages.set(ev.message);
|
|
4626
|
+
}
|
|
4627
|
+
}
|
|
4628
|
+
handleMessagesRedacted(ev) {
|
|
4629
|
+
const saved = ev.ids.filter(id => this.items.has(savedItemKey('Message', id)));
|
|
4630
|
+
this.items.delete(...saved.map(id => savedItemKey('Message', id)));
|
|
4631
|
+
this.messages.delete(...saved.filter(id => this.messages.has(id)));
|
|
4632
|
+
}
|
|
4633
|
+
handleRoomDeleted(ev) {
|
|
4634
|
+
this.hiddenRoomIds.delete(ev.id);
|
|
4635
|
+
this.deleteRoomItems(ev.id);
|
|
4636
|
+
}
|
|
4637
|
+
handleRoomLeft(ev) {
|
|
4638
|
+
// The server keeps them and hands them back once you rejoin
|
|
4639
|
+
if (this.deleteRoomItems(ev.id)) {
|
|
4640
|
+
this.hiddenRoomIds.add(ev.id);
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
handleRoomJoined(ev) {
|
|
4644
|
+
if (!this.hiddenRoomIds.delete(ev.room.id) || this.refreshScheduled) {
|
|
4645
|
+
return;
|
|
4646
|
+
}
|
|
4647
|
+
|
|
4648
|
+
// Joining a space joins its rooms one by one; one request brings back the items of all of them
|
|
4649
|
+
this.refreshScheduled = true;
|
|
4650
|
+
setTimeout(() => {
|
|
4651
|
+
this.refreshScheduled = false;
|
|
4652
|
+
this.refresh();
|
|
4653
|
+
}, 0);
|
|
4654
|
+
}
|
|
4655
|
+
deleteRoomItems(roomId) {
|
|
4656
|
+
const items = this.items.items.filter(item => item.roomId === roomId);
|
|
4657
|
+
this.items.delete(...items.map(keyOf));
|
|
4658
|
+
this.messages.delete(...items.filter(item => this.messages.has(item.id)).map(item => item.id));
|
|
4659
|
+
return items.length > 0;
|
|
4660
|
+
}
|
|
4661
|
+
handleSession() {
|
|
4662
|
+
this.promises.forgetAll();
|
|
4663
|
+
this.refresh();
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4273
4666
|
;// ./src/state-tracker/ChatStateTracker.ts
|
|
4274
4667
|
|
|
4275
4668
|
|
|
@@ -4280,6 +4673,8 @@ class CallsManager {
|
|
|
4280
4673
|
|
|
4281
4674
|
|
|
4282
4675
|
|
|
4676
|
+
|
|
4677
|
+
|
|
4283
4678
|
class ChatStateTracker {
|
|
4284
4679
|
client;
|
|
4285
4680
|
|
|
@@ -4317,6 +4712,19 @@ class ChatStateTracker {
|
|
|
4317
4712
|
* State of the calls in your rooms and of the calls ringing at you.
|
|
4318
4713
|
*/
|
|
4319
4714
|
calls;
|
|
4715
|
+
|
|
4716
|
+
/**
|
|
4717
|
+
* Your latest personal events from all spaces (mentions, replies, reactions, followed threads, missed calls) and the
|
|
4718
|
+
* activities the server publishes. Private conversations keep their own unread state. Nothing is fetched until you
|
|
4719
|
+
* ask for it. Not part of the state snapshot.
|
|
4720
|
+
*/
|
|
4721
|
+
activities;
|
|
4722
|
+
|
|
4723
|
+
/**
|
|
4724
|
+
* The rooms and messages you saved, from all spaces. Nothing is fetched until you ask for it. Not part of the state
|
|
4725
|
+
* snapshot.
|
|
4726
|
+
*/
|
|
4727
|
+
savedItems;
|
|
4320
4728
|
_me = null;
|
|
4321
4729
|
deferredSession = new DeferredTask();
|
|
4322
4730
|
sessionReceived = false;
|
|
@@ -4331,6 +4739,8 @@ class ChatStateTracker {
|
|
|
4331
4739
|
this.users = new UsersManager(this);
|
|
4332
4740
|
this.relationships = new RelationshipsManager(this);
|
|
4333
4741
|
this.calls = new CallsManager(this);
|
|
4742
|
+
this.activities = new ActivitiesManager(this);
|
|
4743
|
+
this.savedItems = new SavedItemsManager(this);
|
|
4334
4744
|
|
|
4335
4745
|
// Registered after the managers, so it runs once they have applied the session.
|
|
4336
4746
|
this.client.on('Session', ev => this.handleSessionAfterImport(ev));
|
|
@@ -4967,10 +5377,12 @@ let ErrorCode = /*#__PURE__*/function (ErrorCode) {
|
|
|
4967
5377
|
ErrorCode["ReactionExistsAlready"] = "ReactionExistsAlreadyException";
|
|
4968
5378
|
ErrorCode["RoomIgnored"] = "RoomIgnoredException";
|
|
4969
5379
|
ErrorCode["RoomNotFound"] = "RoomNotFoundException";
|
|
5380
|
+
ErrorCode["SavedItemsLimitReached"] = "SavedItemsLimitReachedException";
|
|
4970
5381
|
ErrorCode["SpaceJoinRestricted"] = "SpaceJoinRestrictedException";
|
|
4971
5382
|
ErrorCode["TooManyCallInvitees"] = "TooManyCallInviteesException";
|
|
4972
5383
|
ErrorCode["TopicNotFound"] = "TopicNotFoundException";
|
|
4973
5384
|
ErrorCode["UserNotFound"] = "UserNotFoundException";
|
|
5385
|
+
ErrorCode["UserType"] = "UserTypeException";
|
|
4974
5386
|
return ErrorCode;
|
|
4975
5387
|
}({});
|
|
4976
5388
|
;// ./src/protocol/schemes/MessageEmbed.ts
|
|
@@ -5113,6 +5525,7 @@ let SpaceIntent = /*#__PURE__*/function (SpaceIntent) {
|
|
|
5113
5525
|
|
|
5114
5526
|
|
|
5115
5527
|
|
|
5116
|
-
|
|
5528
|
+
|
|
5529
|
+
export { AbstractRestClient, CallMemberFlag, ErrorCode, FilesClient, HistoryRotation, IndexedCollection, IndexedObjectCollection, Layer, MessageEmbedFlag, NO_LIMIT, ObservableIndexedCollection, ObservableIndexedObjectCollection, PermissionDefinition, Permissions, PmParticipantFlag, RoleFlag, STATE_SNAPSHOT_VERSION, STORAGE_UNIT_BYTES, SearchRange, SpaceFeature, SpaceIntent, TYPING_INTERVAL_MS, TYPING_TIMEOUT_MS, UiPurpose, UserFeature, UserStatus, WebApiChatClient, WebSocketChatClient, extractUserFromMember, getPmPeers, isGroupPm, savedItemKey };
|
|
5117
5530
|
|
|
5118
5531
|
//# sourceMappingURL=index.mjs.map
|