polfan-server-js-client 0.2.95 → 0.2.96

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polfan-server-js-client",
3
- "version": "0.2.95",
3
+ "version": "0.2.96",
4
4
  "description": "JavaScript client library for handling communication with Polfan chat server.",
5
5
  "author": "Jarosław Żak",
6
6
  "license": "MIT",
@@ -57,24 +57,32 @@ export class MessagesManager {
57
57
  throw new Error(`You are not in space ${spaceId}`);
58
58
  }
59
59
 
60
- const roomIds = (await this.tracker.rooms.get()).findBy('spaceId', spaceId).items.map(room => room.id);
60
+ const rooms = await this.tracker.rooms.get();
61
+ const roomIds = spaceId
62
+ ? rooms.findBy('spaceId', spaceId).items.map(r => r.id)
63
+ : rooms.items.filter(r => !r.spaceId).map(r => r.id);
61
64
 
62
- if (! roomIds.length) {
63
- // We don't need to ping server for followed topics for this space, if user has no joined rooms
65
+ if (!roomIds.length) {
64
66
  return;
65
67
  }
66
68
 
67
- const resultPromise = this.tracker.client.send('GetFollowedTopics', {location: {spaceId}});
69
+ const isAlreadyCached = roomIds.every(roomId => this.followedTopics.has(roomId));
70
+ if (isAlreadyCached) {
71
+ return;
72
+ }
68
73
 
69
- roomIds.forEach(roomId => this.followedTopicsPromises.register(resultPromise, roomId));
74
+ const spaceRegistryKey = `space_fetch_${spaceId || 'spaceless'}`;
70
75
 
71
- const result = await resultPromise;
76
+ if (this.followedTopicsPromises.notExist(spaceRegistryKey)) {
77
+ this.followedTopicsPromises.registerByFunction(async () => {
78
+ const result = await this.tracker.client.send('GetFollowedTopics', {location: {spaceId}});
79
+ if (result.error) throw result.error;
72
80
 
73
- if (result.error) {
74
- throw result.error;
81
+ this.setFollowedTopicsArray(roomIds, result.data.followedTopics);
82
+ }, spaceRegistryKey);
75
83
  }
76
84
 
77
- this.setFollowedTopicsArray(roomIds, result.data.followedTopics);
85
+ await this.followedTopicsPromises.get(spaceRegistryKey);
78
86
  }
79
87
 
80
88
  /**
@@ -155,6 +163,7 @@ export class MessagesManager {
155
163
  await this.cacheSpaceFollowedTopics(location.spaceId);
156
164
  roomIds = rooms.findBy('spaceId', location.spaceId).items.map(r => r.id);
157
165
  } else {
166
+ await this.cacheSpaceFollowedTopics(null);
158
167
  roomIds = rooms.items.filter(r => !r.spaceId).map(r => r.id);
159
168
  }
160
169