polfan-server-js-client 0.2.107 → 0.2.108

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.
@@ -6,5 +6,6 @@ import { Permissions, PermissionDefinition, Layer } from "./Permissions";
6
6
  import * as ChatTypes from './types/src';
7
7
  import { extractUserFromMember } from "./state-tracker/functions";
8
8
  import { AbstractRestClient } from "./AbstractRestClient";
9
+ import { UnreadSummary } from "./state-tracker/FollowedTopicsManager";
9
10
  export { IndexedCollection, ObservableIndexedCollection, IndexedObjectCollection, ObservableIndexedObjectCollection, Permissions, PermissionDefinition, Layer, WebSocketChatClient, WebApiChatClient, FilesClient, AbstractRestClient, extractUserFromMember, };
10
- export type { ChatTypes, File, };
11
+ export type { ChatTypes, File, UnreadSummary, };
@@ -5,6 +5,11 @@ import { ChatLocation, FollowedTopic } from "../types/src";
5
5
  interface EventMap {
6
6
  change: {};
7
7
  }
8
+ export interface UnreadSummary {
9
+ mentionCount: number;
10
+ unreadTopicCount: number;
11
+ isUnread: boolean;
12
+ }
8
13
  export declare class FollowedTopicsManager extends EventTarget<EventMap> {
9
14
  private tracker;
10
15
  private readonly followedTopics;
@@ -38,10 +43,7 @@ export declare class FollowedTopicsManager extends EventTarget<EventMap> {
38
43
  * Capture the 'change' event to determine when it's worth calling this method again due to data changes.
39
44
  * @return Undefined if you are not in room.
40
45
  */
41
- summarize(location: ChatLocation): Promise<{
42
- mentionCount: number;
43
- isUnread: boolean;
44
- }>;
46
+ summarize(location: ChatLocation): Promise<UnreadSummary>;
45
47
  /**
46
48
  * For internal use. If you want to delete the message, execute a proper command on client object.
47
49
  * @internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polfan-server-js-client",
3
- "version": "0.2.107",
3
+ "version": "0.2.108",
4
4
  "description": "JavaScript client library for handling communication with Polfan chat server.",
5
5
  "author": "Jarosław Żak",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ import { Permissions, PermissionDefinition, Layer } from "./Permissions";
11
11
  import * as ChatTypes from './types/src';
12
12
  import {extractUserFromMember} from "./state-tracker/functions";
13
13
  import {AbstractRestClient} from "./AbstractRestClient";
14
+ import {UnreadSummary} from "./state-tracker/FollowedTopicsManager";
14
15
 
15
16
  export {
16
17
  IndexedCollection, ObservableIndexedCollection,
@@ -25,4 +26,5 @@ export {
25
26
  export type {
26
27
  ChatTypes,
27
28
  File,
29
+ UnreadSummary,
28
30
  };
@@ -17,11 +17,17 @@ interface EventMap {
17
17
  change: {};
18
18
  }
19
19
 
20
+ export interface UnreadSummary {
21
+ mentionCount: number;
22
+ unreadTopicCount: number;
23
+ isUnread: boolean;
24
+ }
25
+
20
26
  export class FollowedTopicsManager extends EventTarget<EventMap> {
21
27
  private readonly followedTopics = new IndexedCollection<string, ObservableIndexedObjectCollection<FollowedTopic>>();
22
28
  private readonly followedTopicsPromises = new PromiseRegistry();
23
29
  private readonly deferredSession = new DeferredTask();
24
- private readonly summariesCache = new Map<string, { mentionCount: number, isUnread: boolean }>();
30
+ private readonly summariesCache = new Map<string, UnreadSummary>();
25
31
 
26
32
  /**
27
33
  * Rooms whose cached followed-topics are stale after a reconnect and must
@@ -134,7 +140,7 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
134
140
  * Capture the 'change' event to determine when it's worth calling this method again due to data changes.
135
141
  * @return Undefined if you are not in room.
136
142
  */
137
- public async summarize(location: ChatLocation): Promise<{ mentionCount: number, isUnread: boolean }> {
143
+ public async summarize(location: ChatLocation): Promise<UnreadSummary> {
138
144
  const cacheKey = location.topicId
139
145
  ? `topic:${location.roomId}:${location.topicId}`
140
146
  : location.roomId
@@ -168,7 +174,7 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
168
174
  }
169
175
 
170
176
  let mentionCount = 0;
171
- let isUnread = false;
177
+ let unreadTopicCount = 0;
172
178
 
173
179
  for (const roomId of roomIds) {
174
180
  const collection = await this.getForRoom(roomId);
@@ -183,14 +189,14 @@ export class FollowedTopicsManager extends EventTarget<EventMap> {
183
189
  }
184
190
 
185
191
  if (topic.isUnread) {
186
- isUnread = true;
192
+ unreadTopicCount++;
187
193
  }
188
194
 
189
195
  mentionCount += (topic.mentionCount ?? 0);
190
196
  }
191
197
  }
192
198
 
193
- const result = { mentionCount, isUnread };
199
+ const result = { mentionCount, unreadTopicCount, isUnread: unreadTopicCount > 0 };
194
200
  this.summariesCache.set(cacheKey, result);
195
201
 
196
202
  return result;