polfan-server-js-client 0.2.43 → 0.2.45
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/.idea/workspace.xml +57 -23
- package/build/index.cjs.js +61 -1
- package/build/index.cjs.js.map +1 -1
- package/build/index.umd.js +1 -1
- package/build/index.umd.js.map +1 -1
- package/build/types/AbstractChatClient.d.ts +8 -1
- package/build/types/state-tracker/ChatStateTracker.d.ts +5 -0
- package/build/types/state-tracker/RelationshipsManager.d.ts +15 -0
- package/build/types/types/src/index.d.ts +7 -1
- package/build/types/types/src/schemes/UserRelationship.d.ts +8 -0
- package/build/types/types/src/schemes/commands/CreateRelationship.d.ts +5 -0
- package/build/types/types/src/schemes/commands/DeleteRelationship.d.ts +5 -0
- package/build/types/types/src/schemes/commands/GetRelationships.d.ts +2 -0
- package/build/types/types/src/schemes/events/NewRelationship.d.ts +4 -0
- package/build/types/types/src/schemes/events/RelationshipDeleted.d.ts +4 -0
- package/build/types/types/src/schemes/events/Relationships.d.ts +4 -0
- package/package.json +1 -1
- package/src/AbstractChatClient.ts +8 -1
- package/src/state-tracker/ChatStateTracker.ts +6 -0
- package/src/state-tracker/RelationshipsManager.ts +68 -0
- package/src/state-tracker/RoomsManager.ts +1 -1
- package/src/types/src/index.ts +13 -0
- package/src/types/src/schemes/UserRelationship.ts +9 -0
- package/src/types/src/schemes/commands/CreateRelationship.ts +6 -0
- package/src/types/src/schemes/commands/DeleteRelationship.ts +6 -0
- package/src/types/src/schemes/commands/GetRelationships.ts +3 -0
- package/src/types/src/schemes/events/NewRelationship.ts +5 -0
- package/src/types/src/schemes/events/RelationshipDeleted.ts +5 -0
- package/src/types/src/schemes/events/Relationships.ts +5 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Bye, GetSession, JoinSpace, Session, SpaceJoined, Error as ErrorType, SpaceLeft, SpaceMemberJoined, SpaceMemberLeft, SpaceMemberUpdated, SpaceDeleted, SpaceMembers, SpaceRooms, NewRole, RoomDeleted, RoomJoined, RoomLeft, RoomMemberLeft, RoomMemberJoined, RoomMembers, NewRoom, NewTopic, TopicDeleted, NewMessage, GetPermissionOverwrites, GetComputedPermissions, LeaveSpace, CreateSpace, DeleteSpace, GetSpaceMembers, GetSpaceRooms, CreateRole, DeleteRole, AssignRole, DeassignRole, SetPermissionOverwrites, JoinRoom, LeaveRoom, CreateRoom, DeleteRoom, GetRoomMembers, CreateTopic, DeleteTopic, CreateMessage, Envelope, PermissionOverwrites, PermissionOverwritesUpdated, RoomMemberUpdated, UpdateRole, RoleUpdated, Ack, UserUpdated, UpdateRoom, RoomUpdated, UpdateSpace, SpaceUpdated, PermissionOverwriteTargets, GetPermissionOverwriteTargets, Owners, Ok, GetOwners, CreateOwner, RoleDeleted, FollowedTopicUpdated, TopicFollowed, TopicUnfollowed, FollowedTopics, FollowTopic, UnfollowTopic, GetFollowedTopics, Messages, GetMessages, Topics, GetTopics, TopicUpdated, UpdateTopic, GetDiscoverableSpaces, DiscoverableSpaces, CreateEmoticon, DeleteEmoticon, GetEmoticons, Emoticons, EmoticonDeleted, NewEmoticon, Bans, GetBans, Ban, Unban, Kick, ClientData, GetClientData, SetClientData, GetRoomSummary, GetSpaceSummary, RoomSummaryEvent, SpaceSummaryEvent, SetCustomNick } from "./types/src/index";
|
|
1
|
+
import { Bye, GetSession, JoinSpace, Session, SpaceJoined, Error as ErrorType, SpaceLeft, SpaceMemberJoined, SpaceMemberLeft, SpaceMemberUpdated, SpaceDeleted, SpaceMembers, SpaceRooms, NewRole, RoomDeleted, RoomJoined, RoomLeft, RoomMemberLeft, RoomMemberJoined, RoomMembers, NewRoom, NewTopic, TopicDeleted, NewMessage, GetPermissionOverwrites, GetComputedPermissions, LeaveSpace, CreateSpace, DeleteSpace, GetSpaceMembers, GetSpaceRooms, CreateRole, DeleteRole, AssignRole, DeassignRole, SetPermissionOverwrites, JoinRoom, LeaveRoom, CreateRoom, DeleteRoom, GetRoomMembers, CreateTopic, DeleteTopic, CreateMessage, Envelope, PermissionOverwrites, PermissionOverwritesUpdated, RoomMemberUpdated, UpdateRole, RoleUpdated, Ack, UserUpdated, UpdateRoom, RoomUpdated, UpdateSpace, SpaceUpdated, PermissionOverwriteTargets, GetPermissionOverwriteTargets, Owners, Ok, GetOwners, CreateOwner, RoleDeleted, FollowedTopicUpdated, TopicFollowed, TopicUnfollowed, FollowedTopics, FollowTopic, UnfollowTopic, GetFollowedTopics, Messages, GetMessages, Topics, GetTopics, TopicUpdated, UpdateTopic, GetDiscoverableSpaces, DiscoverableSpaces, CreateEmoticon, DeleteEmoticon, GetEmoticons, Emoticons, EmoticonDeleted, NewEmoticon, Bans, GetBans, Ban, Unban, Kick, ClientData, GetClientData, SetClientData, GetRoomSummary, GetSpaceSummary, RoomSummaryEvent, SpaceSummaryEvent, SetCustomNick, Relationships, RelationshipDeleted, NewRelationship, DeleteRelationship, CreateRelationship } from "./types/src/index";
|
|
2
2
|
import { EventTarget } from "./EventTarget";
|
|
3
|
+
import { GetRelationships } from "./types/src/schemes/commands/GetRelationships";
|
|
3
4
|
type ArrayOfPromiseResolvers = [(value: any) => void, (reason?: any) => void];
|
|
4
5
|
export declare abstract class AbstractChatClient extends EventTarget {
|
|
5
6
|
protected awaitingResponse: Map<string, ArrayOfPromiseResolvers>;
|
|
@@ -34,6 +35,9 @@ export type EventsMap = {
|
|
|
34
35
|
Emoticons: Emoticons;
|
|
35
36
|
Bans: Bans;
|
|
36
37
|
ClientData: ClientData;
|
|
38
|
+
NewRelationship: NewRelationship;
|
|
39
|
+
RelationshipDeleted: RelationshipDeleted;
|
|
40
|
+
Relationships: Relationships;
|
|
37
41
|
DiscoverableSpaces: DiscoverableSpaces;
|
|
38
42
|
SpaceJoined: SpaceJoined;
|
|
39
43
|
SpaceLeft: SpaceLeft;
|
|
@@ -91,6 +95,9 @@ export type CommandsMap = {
|
|
|
91
95
|
Kick: [Kick, EventsMap['Ok']];
|
|
92
96
|
GetClientData: [GetClientData, EventsMap['ClientData']];
|
|
93
97
|
SetClientData: [SetClientData, EventsMap['Ok']];
|
|
98
|
+
DeleteRelationship: [DeleteRelationship, EventsMap['RelationshipDeleted']];
|
|
99
|
+
CreateRelationship: [CreateRelationship, EventsMap['NewRelationship']];
|
|
100
|
+
GetRelationships: [GetRelationships, EventsMap['Relationships']];
|
|
94
101
|
GetDiscoverableSpaces: [GetDiscoverableSpaces, EventsMap['DiscoverableSpaces']];
|
|
95
102
|
JoinSpace: [JoinSpace, EventsMap['SpaceJoined']];
|
|
96
103
|
LeaveSpace: [LeaveSpace, EventsMap['SpaceLeft']];
|
|
@@ -5,6 +5,7 @@ import { SpacesManager } from "./SpacesManager";
|
|
|
5
5
|
import { PermissionsManager } from "./PermissionsManager";
|
|
6
6
|
import { EmoticonsManager } from "./EmoticonsManager";
|
|
7
7
|
import { UsersManager } from "./UsersManager";
|
|
8
|
+
import { RelationshipsManager } from "./RelationshipsManager";
|
|
8
9
|
export declare class ChatStateTracker {
|
|
9
10
|
readonly client: WebSocketChatClient;
|
|
10
11
|
/**
|
|
@@ -27,6 +28,10 @@ export declare class ChatStateTracker {
|
|
|
27
28
|
* Users related state.
|
|
28
29
|
*/
|
|
29
30
|
readonly users: UsersManager;
|
|
31
|
+
/**
|
|
32
|
+
* State of relationships with other users.
|
|
33
|
+
*/
|
|
34
|
+
readonly relationships: RelationshipsManager;
|
|
30
35
|
private _me;
|
|
31
36
|
private readonly deferredSession;
|
|
32
37
|
constructor(client: WebSocketChatClient);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ObservableIndexedObjectCollection } from "../IndexedObjectCollection";
|
|
2
|
+
import { UserRelationship, UserRelationshipType } from "../types/src";
|
|
3
|
+
import { ChatStateTracker } from "./ChatStateTracker";
|
|
4
|
+
export declare class RelationshipsManager {
|
|
5
|
+
private tracker;
|
|
6
|
+
private relationships;
|
|
7
|
+
private promises;
|
|
8
|
+
constructor(tracker: ChatStateTracker);
|
|
9
|
+
get(): Promise<ObservableIndexedObjectCollection<UserRelationship>>;
|
|
10
|
+
exists(refUserId: string, type: UserRelationshipType): Promise<boolean>;
|
|
11
|
+
private handleRelationships;
|
|
12
|
+
private handleNewRelationship;
|
|
13
|
+
private handleRelationshipDeleted;
|
|
14
|
+
private handleSession;
|
|
15
|
+
}
|
|
@@ -117,4 +117,10 @@ import { SpaceFlag } from "./schemes/Space";
|
|
|
117
117
|
import { SpaceSummary as SpaceSummaryEvent } from "./schemes/events/SpaceSummary";
|
|
118
118
|
import { RoomSummary as RoomSummaryEvent } from "./schemes/events/RoomSummary";
|
|
119
119
|
import { SetCustomNick } from "./schemes/commands/SetCustomNick";
|
|
120
|
-
|
|
120
|
+
import { NewRelationship } from "./schemes/events/NewRelationship";
|
|
121
|
+
import { RelationshipDeleted } from "./schemes/events/RelationshipDeleted";
|
|
122
|
+
import { UserRelationship, UserRelationshipType } from "./schemes/UserRelationship";
|
|
123
|
+
import { DeleteRelationship } from "./schemes/commands/DeleteRelationship";
|
|
124
|
+
import { Relationships } from "./schemes/events/Relationships";
|
|
125
|
+
import { CreateRelationship } from "./schemes/commands/CreateRelationship";
|
|
126
|
+
export { Envelope, Message, MessageType, MessageAuthor, Role, Room, RoomFlag, RoomType, RoomMember, RoomSummary, RoomSummaryExtras, Space, SpaceFlag, SpaceMember, Topic, FollowedTopic, User, UserState, PermissionOverwritesValue, ChatLocation, SpaceSummary, SpaceDiscoverable, Emoticon, PermissionOverwritesTarget, BanObject, LeaveReason, RoomStream, RoomStreamType, UserRelationship, UserRelationshipType, Bye, Error, Messages, NewMessage, NewRole, NewRoom, NewTopic, TopicFollowed, TopicUnfollowed, FollowedTopics, FollowedTopicUpdated, ComputedPermissions, PermissionOverwrites, PermissionOverwritesUpdated, RoleDeleted, RoleUpdated, RoomDeleted, RoomUpdated, RoomJoined, RoomLeft, RoomMemberJoined, RoomMemberLeft, RoomMembers, RoomMemberUpdated, UserUpdated, Session, SpaceDeleted, SpaceUpdated, SpaceJoined, SpaceLeft, SpaceMemberJoined, SpaceMemberLeft, SpaceMembers, SpaceMemberUpdated, SpaceRooms, TopicDeleted, TopicUpdated, PermissionOverwriteTargets, Owners, Ok, DiscoverableSpaces, Emoticons, EmoticonDeleted, NewEmoticon, Bans, ClientData, SpaceSummaryEvent, RoomSummaryEvent, NewRelationship, RelationshipDeleted, Relationships, AssignRole, GetMessages, CreateMessage, Ack, CreateRole, CreateRoom, CreateSpace, CreateTopic, FollowTopic, UnfollowTopic, GetFollowedTopics, DeassignRole, DeleteRole, DeleteRoom, DeleteSpace, DeleteTopic, SetPermissionOverwrites, GetPermissionOverwrites, GetComputedPermissions, GetRoomMembers, GetSession, GetSpaceMembers, GetSpaceRooms, JoinRoom, JoinSpace, LeaveRoom, LeaveSpace, UpdateRole, UpdateSpace, UpdateRoom, UpdateTopic, GetPermissionOverwriteTargets, CreateOwner, DeleteOwner, GetOwners, Topics, GetTopics, GetDiscoverableSpaces, GetEmoticons, CreateEmoticon, DeleteEmoticon, Ban, Unban, GetBans, Kick, GetClientData, SetClientData, GetSpaceSummary, GetRoomSummary, SetCustomNick, CreateRelationship, DeleteRelationship };
|
package/package.json
CHANGED
|
@@ -87,9 +87,10 @@ import {
|
|
|
87
87
|
GetSpaceSummary,
|
|
88
88
|
RoomSummaryEvent,
|
|
89
89
|
SpaceSummaryEvent,
|
|
90
|
-
SetCustomNick,
|
|
90
|
+
SetCustomNick, Relationships, RelationshipDeleted, NewRelationship, DeleteRelationship, CreateRelationship,
|
|
91
91
|
} from "./types/src/index";
|
|
92
92
|
import {EventTarget} from "./EventTarget";
|
|
93
|
+
import {GetRelationships} from "./types/src/schemes/commands/GetRelationships";
|
|
93
94
|
|
|
94
95
|
type ArrayOfPromiseResolvers = [(value: any) => void, (reason?: any) => void];
|
|
95
96
|
|
|
@@ -165,6 +166,9 @@ export type EventsMap = {
|
|
|
165
166
|
Emoticons: Emoticons,
|
|
166
167
|
Bans: Bans,
|
|
167
168
|
ClientData: ClientData,
|
|
169
|
+
NewRelationship: NewRelationship,
|
|
170
|
+
RelationshipDeleted: RelationshipDeleted,
|
|
171
|
+
Relationships: Relationships,
|
|
168
172
|
// Space events
|
|
169
173
|
DiscoverableSpaces: DiscoverableSpaces,
|
|
170
174
|
SpaceJoined: SpaceJoined,
|
|
@@ -227,6 +231,9 @@ export type CommandsMap = {
|
|
|
227
231
|
Kick: [Kick, EventsMap['Ok']],
|
|
228
232
|
GetClientData: [GetClientData, EventsMap['ClientData']],
|
|
229
233
|
SetClientData: [SetClientData, EventsMap['Ok']],
|
|
234
|
+
DeleteRelationship: [DeleteRelationship, EventsMap['RelationshipDeleted']],
|
|
235
|
+
CreateRelationship: [CreateRelationship, EventsMap['NewRelationship']],
|
|
236
|
+
GetRelationships: [GetRelationships, EventsMap['Relationships']],
|
|
230
237
|
// Space commands
|
|
231
238
|
GetDiscoverableSpaces: [GetDiscoverableSpaces, EventsMap['DiscoverableSpaces']],
|
|
232
239
|
JoinSpace: [JoinSpace, EventsMap['SpaceJoined']],
|
|
@@ -6,6 +6,7 @@ import {PermissionsManager} from "./PermissionsManager";
|
|
|
6
6
|
import {DeferredTask} from "./AsyncUtils";
|
|
7
7
|
import {EmoticonsManager} from "./EmoticonsManager";
|
|
8
8
|
import {UsersManager} from "./UsersManager";
|
|
9
|
+
import {RelationshipsManager} from "./RelationshipsManager";
|
|
9
10
|
|
|
10
11
|
export class ChatStateTracker {
|
|
11
12
|
/**
|
|
@@ -33,6 +34,11 @@ export class ChatStateTracker {
|
|
|
33
34
|
*/
|
|
34
35
|
public readonly users = new UsersManager(this);
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* State of relationships with other users.
|
|
39
|
+
*/
|
|
40
|
+
public readonly relationships = new RelationshipsManager(this);
|
|
41
|
+
|
|
36
42
|
private _me: User = null;
|
|
37
43
|
private readonly deferredSession = new DeferredTask();
|
|
38
44
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {ObservableIndexedObjectCollection} from "../IndexedObjectCollection";
|
|
2
|
+
import {
|
|
3
|
+
NewRelationship,
|
|
4
|
+
RelationshipDeleted,
|
|
5
|
+
Relationships,
|
|
6
|
+
UserRelationship,
|
|
7
|
+
UserRelationshipType
|
|
8
|
+
} from "../types/src";
|
|
9
|
+
import {PromiseRegistry} from "./AsyncUtils";
|
|
10
|
+
import {ChatStateTracker} from "./ChatStateTracker";
|
|
11
|
+
|
|
12
|
+
const getId = (refUserId: string, type: UserRelationshipType): string => `${refUserId}-${type}`;
|
|
13
|
+
const getIdFromRelationship = (relationship: UserRelationship): string => getId(relationship.refUserId, relationship.type);
|
|
14
|
+
|
|
15
|
+
export class RelationshipsManager {
|
|
16
|
+
private relationships: ObservableIndexedObjectCollection<UserRelationship> = new ObservableIndexedObjectCollection<UserRelationship>(getIdFromRelationship);
|
|
17
|
+
private promises = new PromiseRegistry();
|
|
18
|
+
|
|
19
|
+
public constructor(private tracker: ChatStateTracker) {
|
|
20
|
+
this.tracker.client.on('Relationships', ev => this.handleRelationships(ev));
|
|
21
|
+
this.tracker.client.on('NewRelationship', ev => this.handleNewRelationship(ev));
|
|
22
|
+
this.tracker.client.on('RelationshipDeleted', ev => this.handleRelationshipDeleted(ev));
|
|
23
|
+
this.tracker.client.on('Session', () => this.handleSession());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public async get(): Promise<ObservableIndexedObjectCollection<UserRelationship>> {
|
|
27
|
+
if (this.promises.notExist('all')) {
|
|
28
|
+
this.promises.registerByFunction(async () => {
|
|
29
|
+
const result = await this.tracker.client.send('GetRelationships', {});
|
|
30
|
+
if (result.error) {
|
|
31
|
+
throw result.error;
|
|
32
|
+
}
|
|
33
|
+
}, 'all');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await this.promises.get('all');
|
|
37
|
+
return this.relationships;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async exists(refUserId: string, type: UserRelationshipType): Promise<boolean> {
|
|
41
|
+
await this.get();
|
|
42
|
+
return this.relationships.has(getId(refUserId, type));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private handleRelationships(ev: Relationships): void {
|
|
46
|
+
this.relationships.deleteAll();
|
|
47
|
+
ev.relationships.forEach(relationship => {
|
|
48
|
+
this.relationships.set(relationship);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private handleNewRelationship(ev: NewRelationship): void {
|
|
53
|
+
if (this.promises.has('all')) {
|
|
54
|
+
this.relationships.set(ev.relationship);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private handleRelationshipDeleted(ev: RelationshipDeleted): void {
|
|
59
|
+
if (this.promises.has('all')) {
|
|
60
|
+
this.relationships.delete(getIdFromRelationship(ev.relationship));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private handleSession(): void {
|
|
65
|
+
this.promises.forgetAll();
|
|
66
|
+
this.relationships.deleteAll();
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/types/src/index.ts
CHANGED
|
@@ -117,6 +117,12 @@ import {SpaceFlag} from "./schemes/Space";
|
|
|
117
117
|
import {SpaceSummary as SpaceSummaryEvent} from "./schemes/events/SpaceSummary";
|
|
118
118
|
import {RoomSummary as RoomSummaryEvent} from "./schemes/events/RoomSummary";
|
|
119
119
|
import {SetCustomNick} from "./schemes/commands/SetCustomNick";
|
|
120
|
+
import {NewRelationship} from "./schemes/events/NewRelationship";
|
|
121
|
+
import {RelationshipDeleted} from "./schemes/events/RelationshipDeleted";
|
|
122
|
+
import {UserRelationship, UserRelationshipType} from "./schemes/UserRelationship";
|
|
123
|
+
import {DeleteRelationship} from "./schemes/commands/DeleteRelationship";
|
|
124
|
+
import {Relationships} from "./schemes/events/Relationships";
|
|
125
|
+
import {CreateRelationship} from "./schemes/commands/CreateRelationship";
|
|
120
126
|
|
|
121
127
|
export {
|
|
122
128
|
// objects
|
|
@@ -148,6 +154,8 @@ export {
|
|
|
148
154
|
LeaveReason,
|
|
149
155
|
RoomStream,
|
|
150
156
|
RoomStreamType,
|
|
157
|
+
UserRelationship,
|
|
158
|
+
UserRelationshipType,
|
|
151
159
|
// events
|
|
152
160
|
Bye,
|
|
153
161
|
Error,
|
|
@@ -197,6 +205,9 @@ export {
|
|
|
197
205
|
ClientData,
|
|
198
206
|
SpaceSummaryEvent,
|
|
199
207
|
RoomSummaryEvent,
|
|
208
|
+
NewRelationship,
|
|
209
|
+
RelationshipDeleted,
|
|
210
|
+
Relationships,
|
|
200
211
|
// commands
|
|
201
212
|
AssignRole,
|
|
202
213
|
GetMessages,
|
|
@@ -248,4 +259,6 @@ export {
|
|
|
248
259
|
GetSpaceSummary,
|
|
249
260
|
GetRoomSummary,
|
|
250
261
|
SetCustomNick,
|
|
262
|
+
CreateRelationship,
|
|
263
|
+
DeleteRelationship
|
|
251
264
|
};
|