polfan-server-js-client 0.2.55 → 0.2.56

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.
@@ -1,6 +1,6 @@
1
1
  import { Message, Topic } from "../types/src";
2
2
  import { ChatStateTracker } from "./ChatStateTracker";
3
- import { ObservableIndexedObjectCollection } from "../IndexedObjectCollection";
3
+ import { IndexedObjectCollection, ObservableIndexedObjectCollection } from "../IndexedObjectCollection";
4
4
  export declare enum WindowState {
5
5
  /**
6
6
  * The latest messages (those received live) are available in the history window, history has not been fetched.
@@ -31,9 +31,10 @@ export declare abstract class TraversableRemoteCollection<T> extends ObservableI
31
31
  * Null for unlimited.
32
32
  */
33
33
  limit: number | null;
34
- private currentState;
35
- private fetchingState;
36
34
  oldestId: string;
35
+ protected currentState: WindowState;
36
+ protected fetchingState: WindowState;
37
+ abstract shallowCopy(): IndexedObjectCollection<T>;
37
38
  get hasLatest(): boolean;
38
39
  get hasOldest(): boolean;
39
40
  resetToLatest(): Promise<void>;
@@ -60,6 +61,7 @@ export declare class TopicHistoryWindow extends TraversableRemoteCollection<Mess
60
61
  readonly WindowState: typeof WindowState;
61
62
  private traverseLock;
62
63
  constructor(roomId: string, topicId: string, tracker: ChatStateTracker);
64
+ shallowCopy(): IndexedObjectCollection<Message>;
63
65
  get isTraverseLocked(): boolean;
64
66
  setTraverseLock(lock: boolean): Promise<void>;
65
67
  resetToLatest(): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polfan-server-js-client",
3
- "version": "0.2.55",
3
+ "version": "0.2.56",
4
4
  "description": "JavaScript client library for handling communication with Polfan chat server.",
5
5
  "author": "Jarosław Żak",
6
6
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  import {Message, NewMessage, Session, Topic} from "../types/src";
2
2
  import {ChatStateTracker} from "./ChatStateTracker";
3
- import {ObservableIndexedObjectCollection} from "../IndexedObjectCollection";
3
+ import {IndexedObjectCollection, ObservableIndexedObjectCollection} from "../IndexedObjectCollection";
4
4
 
5
5
  export enum WindowState {
6
6
  /**
@@ -40,10 +40,13 @@ export abstract class TraversableRemoteCollection<T> extends ObservableIndexedOb
40
40
  */
41
41
  public limit: number | null = 50;
42
42
 
43
- private currentState: WindowState = WindowState.LIVE;
44
- private fetchingState: WindowState = undefined;
45
43
  public oldestId: string = null;
46
44
 
45
+ protected currentState: WindowState = WindowState.LIVE;
46
+ protected fetchingState: WindowState = undefined;
47
+
48
+ public abstract shallowCopy(): IndexedObjectCollection<T>;
49
+
47
50
  public get hasLatest(): boolean {
48
51
  return [WindowState.LATEST, WindowState.LIVE].includes(this.state);
49
52
  }
@@ -199,6 +202,16 @@ export class TopicHistoryWindow extends TraversableRemoteCollection<Message> {
199
202
  this.tracker.client.on('NewMessage', ev => this.handleNewMessage(ev));
200
203
  }
201
204
 
205
+ public shallowCopy(): IndexedObjectCollection<Message> {
206
+ const copy = new TopicHistoryWindow(this.roomId, this.topicId, this.tracker);
207
+ copy._items = this._items;
208
+ copy.limit = this.limit;
209
+ copy.currentState = this.currentState;
210
+ copy.fetchingState = this.fetchingState;
211
+ copy.oldestId = this.oldestId;
212
+ return copy;
213
+ }
214
+
202
215
  public get isTraverseLocked(): boolean {
203
216
  return this.traverseLock;
204
217
  }
@@ -1,4 +1,5 @@
1
- import {TraversableRemoteCollection, WindowState} from "../src/state-tracker/TopicHistoryWindow";
1
+ import { IndexedObjectCollection } from "../src";
2
+ import {TopicHistoryWindow, TraversableRemoteCollection, WindowState} from "../src/state-tracker/TopicHistoryWindow";
2
3
 
3
4
  interface SimpleMessage {
4
5
  id: number;
@@ -18,6 +19,10 @@ const messages: SimpleMessage[] = [
18
19
  ];
19
20
 
20
21
  class TestableHistoryWindow extends TraversableRemoteCollection<SimpleMessage> {
22
+ public shallowCopy(): IndexedObjectCollection<SimpleMessage> {
23
+ throw new Error('Method not implemented.');
24
+ }
25
+
21
26
  public constructor() {
22
27
  super('id');
23
28
  }