@devanachat/sdk 0.8.1 → 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/build/index.mjs CHANGED
@@ -1075,10 +1075,12 @@ class TopicHistoryWindow extends TraversableRemoteCollection {
1075
1075
  value
1076
1076
  });
1077
1077
  }
1078
- const {
1079
- [ev.messageId]: _previous,
1080
- ...myReactions
1081
- } = this.internalState.myReactions;
1078
+
1079
+ // Not `{[ev.messageId]: _, ...rest}` - Babel's loose object rest drops the key when the binding is unused (babel/babel#18196)
1080
+ const myReactions = {
1081
+ ...this.internalState.myReactions
1082
+ };
1083
+ delete myReactions[ev.messageId];
1082
1084
  if (own.length) {
1083
1085
  myReactions[ev.messageId] = own;
1084
1086
  }
@@ -2111,7 +2113,15 @@ class RoomsManager {
2111
2113
  const promise = this.tracker.client.send('GetTopics', {
2112
2114
  roomId,
2113
2115
  topicIds: idsToFetch
2114
- }).then(result => this.topics.get(result.data.location.roomId)?.set(...result.data.topics));
2116
+ }).then(result => {
2117
+ const topics = this.topics.get(roomId);
2118
+ if (topics) {
2119
+ topics.set(...result.data.topics);
2120
+ } else {
2121
+ // A room not joined yet has nowhere to keep them - let them be fetched again once it is.
2122
+ this.topicsPromises.forget(...idsToFetch.map(topicId => roomId + topicId));
2123
+ }
2124
+ });
2115
2125
  idsToFetch.forEach(topicId => this.topicsPromises.register(promise, roomId + topicId));
2116
2126
  }
2117
2127
  for (const topicId of tryToFetchTopicIds) {
@@ -3015,6 +3025,10 @@ class Permissions {
3015
3025
  SearchMessages: {
3016
3026
  value: 1 << 25,
3017
3027
  maxLayer: Layer.Room
3028
+ },
3029
+ UseExternalEmoticons: {
3030
+ value: 1 << 26,
3031
+ maxLayer: Layer.Room
3018
3032
  }
3019
3033
  };
3020
3034
  static getNames() {
@@ -3308,7 +3322,6 @@ class PermissionsManager extends EventTarget {
3308
3322
  ;// ./src/state-tracker/EmoticonsManager.ts
3309
3323
 
3310
3324
 
3311
- const GLOBAL_KEY = 'global';
3312
3325
  class EmoticonsManager {
3313
3326
  list = new IndexedCollection();
3314
3327
  emoticonsPromises = new PromiseRegistry();
@@ -3321,8 +3334,7 @@ class EmoticonsManager {
3321
3334
  this.tracker.client.on('Session', () => this.handleSession());
3322
3335
  }
3323
3336
  async get(spaceId) {
3324
- const key = spaceId ?? GLOBAL_KEY;
3325
- if (this.emoticonsPromises.notExist(key)) {
3337
+ if (this.emoticonsPromises.notExist(spaceId)) {
3326
3338
  this.emoticonsPromises.registerByFunction(async () => {
3327
3339
  const result = await this.tracker.client.send('GetEmoticons', {
3328
3340
  spaceId
@@ -3331,10 +3343,10 @@ class EmoticonsManager {
3331
3343
  throw result.error;
3332
3344
  }
3333
3345
  this.handleEmoticons(result.data);
3334
- }, key);
3346
+ }, spaceId);
3335
3347
  }
3336
- await this.emoticonsPromises.get(key);
3337
- return this.list.get(key);
3348
+ await this.emoticonsPromises.get(spaceId);
3349
+ return this.list.get(spaceId);
3338
3350
  }
3339
3351
 
3340
3352
  /**
@@ -3342,8 +3354,8 @@ class EmoticonsManager {
3342
3354
  * @internal
3343
3355
  */
3344
3356
  _exportEmoticons() {
3345
- return Array.from(this.list.items).map(([key, emoticons]) => ({
3346
- spaceId: key === GLOBAL_KEY ? null : key,
3357
+ return Array.from(this.list.items).map(([spaceId, emoticons]) => ({
3358
+ spaceId,
3347
3359
  emoticons: emoticons.items
3348
3360
  }));
3349
3361
  }
@@ -3358,17 +3370,19 @@ class EmoticonsManager {
3358
3370
  spaceId,
3359
3371
  emoticons
3360
3372
  } of snapshots) {
3361
- if (spaceId !== null && !joinedSpaceIds.has(spaceId)) {
3373
+ // TODO(emoticons-compat): snapshots written before the global emoticons were gone still hold them under
3374
+ // null - drop the comment once no such snapshot can be left on a device (the check itself stays).
3375
+ if (!joinedSpaceIds.has(spaceId)) {
3362
3376
  continue;
3363
3377
  }
3364
3378
  this.handleEmoticons({
3365
3379
  location: {
3366
- spaceId: spaceId ?? undefined
3380
+ spaceId
3367
3381
  },
3368
3382
  emoticons
3369
3383
  });
3370
3384
  // Served from the snapshot until the session invalidates it.
3371
- this.emoticonsPromises.register(Promise.resolve(), spaceId ?? GLOBAL_KEY);
3385
+ this.emoticonsPromises.register(Promise.resolve(), spaceId);
3372
3386
  }
3373
3387
  }
3374
3388
 
@@ -3377,13 +3391,19 @@ class EmoticonsManager {
3377
3391
  * @internal
3378
3392
  */
3379
3393
  _forgetSpacesExcept(spaceIds) {
3380
- const keptKeys = new Set([GLOBAL_KEY, ...spaceIds]);
3394
+ const keptKeys = new Set(spaceIds);
3381
3395
  const removedKeys = Array.from(this.list.items.keys()).filter(key => !keptKeys.has(key));
3382
3396
  this.list.delete(...removedKeys);
3383
3397
  this.emoticonsPromises.forget(...removedKeys);
3384
3398
  }
3385
3399
  handleEmoticons(event) {
3386
- const spaceId = event.location.spaceId ?? GLOBAL_KEY;
3400
+ // A selection by ids has no location.
3401
+ // TODO(emoticons-compat): one without a space is the always empty list of the gone global emoticons, sent
3402
+ // until the server stops answering old clients that way.
3403
+ const spaceId = event.location?.spaceId;
3404
+ if (!spaceId) {
3405
+ return;
3406
+ }
3387
3407
  if (!this.list.has(spaceId)) {
3388
3408
  this.list.set([spaceId, new ObservableIndexedObjectCollection('id')]);
3389
3409
  }
@@ -3394,11 +3414,11 @@ class EmoticonsManager {
3394
3414
  this.list.get(spaceId).reconcile(...event.emoticons);
3395
3415
  }
3396
3416
  handleNewEmoticon(ev) {
3397
- const collection = this.list.get(ev.emoticon.spaceId ?? GLOBAL_KEY);
3417
+ const collection = this.list.get(ev.emoticon.spaceId);
3398
3418
  collection?.set(ev.emoticon);
3399
3419
  }
3400
3420
  handleEmoticonDeleted(ev) {
3401
- const collection = this.list.get(ev.spaceId ?? GLOBAL_KEY);
3421
+ const collection = this.list.get(ev.spaceId);
3402
3422
  collection?.delete(ev.emoticonId);
3403
3423
  }
3404
3424
  handleSpaceDeleted(event) {
@@ -4281,6 +4301,7 @@ let UserFeature = /*#__PURE__*/function (UserFeature) {
4281
4301
  UserFeature["MessageLength"] = "user.message.length";
4282
4302
  UserFeature["StorageLimit"] = "user.storage.limit";
4283
4303
  UserFeature["StorageSingleFileLimit"] = "user.storage.single_file_limit";
4304
+ UserFeature["ExternalEmoticons"] = "user.external_emoticons";
4284
4305
  return UserFeature;
4285
4306
  }({});
4286
4307