polfan-server-js-client 0.1.56 → 0.1.57
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/.gitmodules +3 -0
- package/build/index.js +295 -138
- package/build/index.js.map +1 -1
- package/build/types/AbstractChatClient.d.ts +2 -2
- package/build/types/index.d.ts +3 -1
- package/build/types/state-tracker/ChatStateTracker.d.ts +5 -5
- package/build/types/state-tracker/MessagesManager.d.ts +3 -3
- package/build/types/state-tracker/PermissionsManager.d.ts +5 -4
- package/build/types/state-tracker/RoomsManager.d.ts +1 -1
- package/build/types/state-tracker/SpacesManager.d.ts +2 -1
- package/build/types/state-tracker/functions.d.ts +1 -1
- package/build/types/types/src/index.d.ts +81 -0
- package/build/types/types/src/schemes/AckReport.d.ts +7 -0
- package/build/types/types/src/schemes/ChatLocation.d.ts +5 -0
- package/build/types/types/src/schemes/Envelope.d.ts +5 -0
- package/build/types/types/src/schemes/Message.d.ts +7 -0
- package/build/types/types/src/schemes/PermissionOverwritesValue.d.ts +4 -0
- package/build/types/types/src/schemes/Role.d.ts +6 -0
- package/build/types/types/src/schemes/Room.d.ts +10 -0
- package/build/types/types/src/schemes/RoomMember.d.ts +7 -0
- package/build/types/types/src/schemes/RoomSummary.d.ts +5 -0
- package/build/types/types/src/schemes/Space.d.ts +6 -0
- package/build/types/types/src/schemes/SpaceMember.d.ts +5 -0
- package/build/types/types/src/schemes/Topic.d.ts +5 -0
- package/build/types/types/src/schemes/User.d.ts +8 -0
- package/build/types/types/src/schemes/UserState.d.ts +6 -0
- package/build/types/types/src/schemes/commands/Ack.d.ts +5 -0
- package/build/types/types/src/schemes/commands/AssignRole.d.ts +6 -0
- package/build/types/types/src/schemes/commands/CreateMessage.d.ts +5 -0
- package/build/types/types/src/schemes/commands/CreateOwner.d.ts +5 -0
- package/build/types/types/src/schemes/commands/CreateRole.d.ts +5 -0
- package/build/types/types/src/schemes/commands/CreateRoom.d.ts +5 -0
- package/build/types/types/src/schemes/commands/CreateSpace.d.ts +3 -0
- package/build/types/types/src/schemes/commands/CreateTopic.d.ts +12 -0
- package/build/types/types/src/schemes/commands/DeassignRole.d.ts +6 -0
- package/build/types/types/src/schemes/commands/DeleteOwner.d.ts +5 -0
- package/build/types/types/src/schemes/commands/DeleteRole.d.ts +4 -0
- package/build/types/types/src/schemes/commands/DeleteRoom.d.ts +3 -0
- package/build/types/types/src/schemes/commands/DeleteSpace.d.ts +3 -0
- package/build/types/types/src/schemes/commands/DeleteTopic.d.ts +4 -0
- package/build/types/types/src/schemes/commands/GetAckReports.d.ts +4 -0
- package/build/types/types/src/schemes/commands/GetComputedPermissions.d.ts +4 -0
- package/build/types/types/src/schemes/commands/GetOwners.d.ts +4 -0
- package/build/types/types/src/schemes/commands/GetPermissionOverwriteTargets.d.ts +4 -0
- package/build/types/types/src/schemes/commands/GetPermissionOverwrites.d.ts +6 -0
- package/build/types/types/src/schemes/commands/GetRoomMembers.d.ts +3 -0
- package/build/types/types/src/schemes/commands/GetSession.d.ts +2 -0
- package/build/types/types/src/schemes/commands/GetSpaceMembers.d.ts +3 -0
- package/build/types/types/src/schemes/commands/GetSpaceRooms.d.ts +3 -0
- package/build/types/types/src/schemes/commands/JoinRoom.d.ts +3 -0
- package/build/types/types/src/schemes/commands/JoinSpace.d.ts +3 -0
- package/build/types/types/src/schemes/commands/LeaveRoom.d.ts +3 -0
- package/build/types/types/src/schemes/commands/LeaveSpace.d.ts +3 -0
- package/build/types/types/src/schemes/commands/SetPermissionOverwrites.d.ts +8 -0
- package/build/types/types/src/schemes/commands/UpdateRole.d.ts +7 -0
- package/build/types/types/src/schemes/commands/UpdateRoom.d.ts +5 -0
- package/build/types/types/src/schemes/commands/UpdateSpace.d.ts +4 -0
- package/build/types/types/src/schemes/events/AckReports.d.ts +4 -0
- package/build/types/types/src/schemes/events/Bye.d.ts +3 -0
- package/build/types/types/src/schemes/events/ComputedPermissions.d.ts +5 -0
- package/build/types/types/src/schemes/events/Error.d.ts +4 -0
- package/build/types/types/src/schemes/events/NewMessage.d.ts +6 -0
- package/build/types/types/src/schemes/events/NewRole.d.ts +5 -0
- package/build/types/types/src/schemes/events/NewRoom.d.ts +5 -0
- package/build/types/types/src/schemes/events/NewTopic.d.ts +5 -0
- package/build/types/types/src/schemes/events/Ok.d.ts +2 -0
- package/build/types/types/src/schemes/events/Owners.d.ts +8 -0
- package/build/types/types/src/schemes/events/PermissionOverwriteTargets.d.ts +10 -0
- package/build/types/types/src/schemes/events/PermissionOverwrites.d.ts +8 -0
- package/build/types/types/src/schemes/events/PermissionOverwritesUpdated.d.ts +8 -0
- package/build/types/types/src/schemes/events/RoleDeleted.d.ts +4 -0
- package/build/types/types/src/schemes/events/RoleUpdated.d.ts +5 -0
- package/build/types/types/src/schemes/events/RoomDeleted.d.ts +3 -0
- package/build/types/types/src/schemes/events/RoomJoined.d.ts +4 -0
- package/build/types/types/src/schemes/events/RoomLeft.d.ts +3 -0
- package/build/types/types/src/schemes/events/RoomMemberJoined.d.ts +5 -0
- package/build/types/types/src/schemes/events/RoomMemberLeft.d.ts +4 -0
- package/build/types/types/src/schemes/events/RoomMemberUpdated.d.ts +6 -0
- package/build/types/types/src/schemes/events/RoomMembers.d.ts +5 -0
- package/build/types/types/src/schemes/events/RoomUpdated.d.ts +4 -0
- package/build/types/types/src/schemes/events/Session.d.ts +7 -0
- package/build/types/types/src/schemes/events/SpaceDeleted.d.ts +3 -0
- package/build/types/types/src/schemes/events/SpaceJoined.d.ts +4 -0
- package/build/types/types/src/schemes/events/SpaceLeft.d.ts +3 -0
- package/build/types/types/src/schemes/events/SpaceMemberJoined.d.ts +5 -0
- package/build/types/types/src/schemes/events/SpaceMemberLeft.d.ts +4 -0
- package/build/types/types/src/schemes/events/SpaceMemberUpdated.d.ts +6 -0
- package/build/types/types/src/schemes/events/SpaceMembers.d.ts +5 -0
- package/build/types/types/src/schemes/events/SpaceRooms.d.ts +5 -0
- package/build/types/types/src/schemes/events/SpaceUpdated.d.ts +4 -0
- package/build/types/types/src/schemes/events/TopicDeleted.d.ts +4 -0
- package/build/types/types/src/schemes/events/UserUpdated.d.ts +4 -0
- package/package.json +3 -4
- package/src/AbstractChatClient.ts +3 -3
- package/src/WebApiChatClient.ts +1 -1
- package/src/WebSocketChatClient.ts +1 -1
- package/src/index.ts +5 -2
- package/src/state-tracker/ChatStateTracker.ts +5 -5
- package/src/state-tracker/MessagesManager.ts +11 -11
- package/src/state-tracker/PermissionsManager.ts +51 -53
- package/src/state-tracker/RoomsManager.ts +11 -6
- package/src/state-tracker/SpacesManager.ts +12 -4
- package/src/state-tracker/functions.ts +1 -1
- package/src/types/README.md +2 -0
- package/src/types/package-lock.json +31 -0
- package/src/types/package.json +16 -0
- package/src/types/src/index.ts +166 -0
- package/src/types/src/schemes/AckReport.ts +7 -0
- package/src/types/src/schemes/ChatLocation.ts +5 -0
- package/src/types/src/schemes/Envelope.ts +5 -0
- package/src/types/src/schemes/Message.ts +8 -0
- package/src/types/src/schemes/PermissionOverwritesValue.ts +4 -0
- package/src/types/src/schemes/Role.ts +6 -0
- package/src/types/src/schemes/Room.ts +12 -0
- package/src/types/src/schemes/RoomMember.ts +8 -0
- package/src/types/src/schemes/RoomSummary.ts +5 -0
- package/src/types/src/schemes/Space.ts +7 -0
- package/src/types/src/schemes/SpaceMember.ts +6 -0
- package/src/types/src/schemes/Topic.ts +5 -0
- package/src/types/src/schemes/User.ts +9 -0
- package/src/types/src/schemes/UserState.ts +7 -0
- package/src/types/src/schemes/commands/Ack.ts +6 -0
- package/src/types/src/schemes/commands/AssignRole.ts +7 -0
- package/src/types/src/schemes/commands/CreateMessage.ts +6 -0
- package/src/types/src/schemes/commands/CreateOwner.ts +6 -0
- package/src/types/src/schemes/commands/CreateRole.ts +5 -0
- package/src/types/src/schemes/commands/CreateRoom.ts +5 -0
- package/src/types/src/schemes/commands/CreateSpace.ts +3 -0
- package/src/types/src/schemes/commands/CreateTopic.ts +14 -0
- package/src/types/src/schemes/commands/DeassignRole.ts +7 -0
- package/src/types/src/schemes/commands/DeleteOwner.ts +6 -0
- package/src/types/src/schemes/commands/DeleteRole.ts +4 -0
- package/src/types/src/schemes/commands/DeleteRoom.ts +3 -0
- package/src/types/src/schemes/commands/DeleteSpace.ts +3 -0
- package/src/types/src/schemes/commands/DeleteTopic.ts +5 -0
- package/src/types/src/schemes/commands/GetAckReports.ts +5 -0
- package/src/types/src/schemes/commands/GetComputedPermissions.ts +5 -0
- package/src/types/src/schemes/commands/GetOwners.ts +5 -0
- package/src/types/src/schemes/commands/GetPermissionOverwriteTargets.ts +5 -0
- package/src/types/src/schemes/commands/GetPermissionOverwrites.ts +7 -0
- package/src/types/src/schemes/commands/GetRoomMembers.ts +3 -0
- package/src/types/src/schemes/commands/GetSession.ts +2 -0
- package/src/types/src/schemes/commands/GetSpaceMembers.ts +3 -0
- package/src/types/src/schemes/commands/GetSpaceRooms.ts +3 -0
- package/src/types/src/schemes/commands/JoinRoom.ts +3 -0
- package/src/types/src/schemes/commands/JoinSpace.ts +3 -0
- package/src/types/src/schemes/commands/LeaveRoom.ts +3 -0
- package/src/types/src/schemes/commands/LeaveSpace.ts +3 -0
- package/src/types/src/schemes/commands/SetPermissionOverwrites.ts +9 -0
- package/src/types/src/schemes/commands/UpdateRole.ts +7 -0
- package/src/types/src/schemes/commands/UpdateRoom.ts +5 -0
- package/src/types/src/schemes/commands/UpdateSpace.ts +4 -0
- package/src/types/src/schemes/events/AckReports.ts +5 -0
- package/src/types/src/schemes/events/Bye.ts +3 -0
- package/src/types/src/schemes/events/ComputedPermissions.ts +6 -0
- package/src/types/src/schemes/events/Error.ts +4 -0
- package/src/types/src/schemes/events/NewMessage.ts +7 -0
- package/src/types/src/schemes/events/NewRole.ts +6 -0
- package/src/types/src/schemes/events/NewRoom.ts +6 -0
- package/src/types/src/schemes/events/NewTopic.ts +6 -0
- package/src/types/src/schemes/events/Ok.ts +3 -0
- package/src/types/src/schemes/events/Owners.ts +9 -0
- package/src/types/src/schemes/events/PermissionOverwriteTargets.ts +11 -0
- package/src/types/src/schemes/events/PermissionOverwrites.ts +9 -0
- package/src/types/src/schemes/events/PermissionOverwritesUpdated.ts +9 -0
- package/src/types/src/schemes/events/RoleDeleted.ts +4 -0
- package/src/types/src/schemes/events/RoleUpdated.ts +6 -0
- package/src/types/src/schemes/events/RoomDeleted.ts +3 -0
- package/src/types/src/schemes/events/RoomJoined.ts +5 -0
- package/src/types/src/schemes/events/RoomLeft.ts +3 -0
- package/src/types/src/schemes/events/RoomMemberJoined.ts +6 -0
- package/src/types/src/schemes/events/RoomMemberLeft.ts +4 -0
- package/src/types/src/schemes/events/RoomMemberUpdated.ts +7 -0
- package/src/types/src/schemes/events/RoomMembers.ts +6 -0
- package/src/types/src/schemes/events/RoomUpdated.ts +5 -0
- package/src/types/src/schemes/events/Session.ts +8 -0
- package/src/types/src/schemes/events/SpaceDeleted.ts +3 -0
- package/src/types/src/schemes/events/SpaceJoined.ts +5 -0
- package/src/types/src/schemes/events/SpaceLeft.ts +3 -0
- package/src/types/src/schemes/events/SpaceMemberJoined.ts +6 -0
- package/src/types/src/schemes/events/SpaceMemberLeft.ts +4 -0
- package/src/types/src/schemes/events/SpaceMemberUpdated.ts +7 -0
- package/src/types/src/schemes/events/SpaceMembers.ts +6 -0
- package/src/types/src/schemes/events/SpaceRooms.ts +6 -0
- package/src/types/src/schemes/events/SpaceUpdated.ts +5 -0
- package/src/types/src/schemes/events/TopicDeleted.ts +5 -0
- package/src/types/src/schemes/events/UserUpdated.ts +5 -0
- package/src/types/tsconfig.json +75 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PermissionOverwritesValue } from "../PermissionOverwritesValue";
|
|
2
|
+
import { ChatLocation } from "../ChatLocation";
|
|
3
|
+
export interface PermissionOverwritesUpdated {
|
|
4
|
+
location: ChatLocation;
|
|
5
|
+
target: 'User' | 'Role';
|
|
6
|
+
targetId: string;
|
|
7
|
+
overwrites: PermissionOverwritesValue;
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polfan-server-js-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.57",
|
|
4
4
|
"description": "JavaScript client library for handling communication with Polfan chat server.",
|
|
5
5
|
"author": "Jarosław Żak",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,14 +35,13 @@
|
|
|
35
35
|
"html-webpack-plugin": "^5.5.0",
|
|
36
36
|
"jest": "^29.3.1",
|
|
37
37
|
"mini-css-extract-plugin": "^2.7.2",
|
|
38
|
-
"pserv-ts-types": "^0.0.30",
|
|
39
38
|
"style-loader": "^3.3.1",
|
|
40
39
|
"terser-webpack-plugin": "^5.3.5",
|
|
40
|
+
"ts-node": "^10.9.2",
|
|
41
41
|
"typescript": "^4.9.4",
|
|
42
42
|
"url-loader": "^4.1.1",
|
|
43
43
|
"webpack": "^5.75.0",
|
|
44
44
|
"webpack-cli": "^5.0.1",
|
|
45
|
-
"webpack-dev-server": "4.11.1"
|
|
46
|
-
"ts-node": "^10.9.2"
|
|
45
|
+
"webpack-dev-server": "4.11.1"
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -62,8 +62,8 @@ import {
|
|
|
62
62
|
Owners,
|
|
63
63
|
Ok,
|
|
64
64
|
GetOwners,
|
|
65
|
-
CreateOwner,
|
|
66
|
-
} from "
|
|
65
|
+
CreateOwner, RoleDeleted,
|
|
66
|
+
} from "./types/src/index";
|
|
67
67
|
import {EventTarget} from "./EventTarget";
|
|
68
68
|
|
|
69
69
|
type ArrayOfPromiseResolvers = [(value: any) => void, (reason?: any) => void];
|
|
@@ -146,7 +146,7 @@ export type EventsMap = {
|
|
|
146
146
|
SpaceMembers: SpaceMembers,
|
|
147
147
|
SpaceRooms: SpaceRooms,
|
|
148
148
|
NewRole: NewRole,
|
|
149
|
-
RoleDeleted:
|
|
149
|
+
RoleDeleted: RoleDeleted,
|
|
150
150
|
RoleUpdated: RoleUpdated,
|
|
151
151
|
// Room events
|
|
152
152
|
RoomJoined: RoomJoined,
|
package/src/WebApiChatClient.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {AbstractChatClient, CommandResult, CommandsMap} from "./AbstractChatClient";
|
|
2
2
|
import {ObservableInterface} from "./EventTarget";
|
|
3
|
-
import {Envelope} from "
|
|
3
|
+
import {Envelope} from "./types/src";
|
|
4
4
|
|
|
5
5
|
export interface WebApiChatClientOptions {
|
|
6
6
|
url: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ObservableInterface} from "./EventTarget";
|
|
2
2
|
import {AbstractChatClient, CommandResult, CommandsMap} from "./AbstractChatClient";
|
|
3
|
-
import {Envelope} from "pserv-ts-types";
|
|
4
3
|
import {ChatStateTracker} from "./state-tracker/ChatStateTracker";
|
|
4
|
+
import {Envelope} from "./types/src";
|
|
5
5
|
|
|
6
6
|
export interface WebSocketClientOptions {
|
|
7
7
|
url: string;
|
package/src/index.ts
CHANGED
|
@@ -8,11 +8,14 @@ import {
|
|
|
8
8
|
} from "./IndexedObjectCollection";
|
|
9
9
|
import { AuthClient } from "./AuthClient";
|
|
10
10
|
import { Permissions, PermissionDefinition, Layer } from "./Permissions";
|
|
11
|
+
import * as ChatTypes from './types/src';
|
|
11
12
|
|
|
12
13
|
export {
|
|
13
14
|
IndexedCollection, ObservableIndexedCollection,
|
|
14
15
|
IndexedObjectCollection, ObservableIndexedObjectCollection,
|
|
15
16
|
Permissions, PermissionDefinition, Layer,
|
|
16
17
|
WebSocketChatClient, WebApiChatClient,
|
|
17
|
-
AuthClient
|
|
18
|
-
};
|
|
18
|
+
AuthClient,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type {ChatTypes};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {WebSocketChatClient} from "../WebSocketChatClient";
|
|
2
|
-
import {Session, User} from "
|
|
2
|
+
import {Session, User} from "../types/src";
|
|
3
3
|
import {RoomsManager} from "./RoomsManager";
|
|
4
4
|
import {SpacesManager} from "./SpacesManager";
|
|
5
5
|
import {PermissionsManager} from "./PermissionsManager";
|
|
6
6
|
import {DeferredTask} from "./AsyncUtils";
|
|
7
7
|
|
|
8
8
|
export class ChatStateTracker {
|
|
9
|
+
/**
|
|
10
|
+
* State of your permissions.
|
|
11
|
+
*/
|
|
12
|
+
public readonly permissions = new PermissionsManager(this);
|
|
9
13
|
/**
|
|
10
14
|
* State of the rooms you are in.
|
|
11
15
|
*/
|
|
@@ -14,10 +18,6 @@ export class ChatStateTracker {
|
|
|
14
18
|
* State of the spaces you are in.
|
|
15
19
|
*/
|
|
16
20
|
public readonly spaces = new SpacesManager(this);
|
|
17
|
-
/**
|
|
18
|
-
* State of your permissions.
|
|
19
|
-
*/
|
|
20
|
-
public readonly permissions = new PermissionsManager(this);
|
|
21
21
|
|
|
22
22
|
private _me: User = null;
|
|
23
23
|
private readonly deferredSession = new DeferredTask();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {ChatStateTracker} from "./ChatStateTracker";
|
|
2
|
-
import {AckReport, AckReports, Message, NewMessage, Topic} from "
|
|
2
|
+
import {AckReport, AckReports, ChatLocation, Message, NewMessage, Topic} from "../types/src";
|
|
3
3
|
import {
|
|
4
4
|
IndexedCollection,
|
|
5
5
|
ObservableIndexedObjectCollection
|
|
6
6
|
} from "../IndexedObjectCollection";
|
|
7
7
|
|
|
8
|
-
export const getCombinedId = (
|
|
8
|
+
export const getCombinedId = (location: ChatLocation) => Object.values(location).filter(v => v).join('_');
|
|
9
9
|
|
|
10
10
|
export class MessagesManager {
|
|
11
11
|
// Temporary not lazy loaded; server must implement GetTopicMessages command.
|
|
@@ -20,8 +20,8 @@ export class MessagesManager {
|
|
|
20
20
|
/**
|
|
21
21
|
* Get collection of the messages written in topic.
|
|
22
22
|
*/
|
|
23
|
-
public async get(
|
|
24
|
-
return this.list.get(getCombinedId(
|
|
23
|
+
public async get(location: ChatLocation): Promise<ObservableIndexedObjectCollection<Message> | undefined> {
|
|
24
|
+
return this.list.get(getCombinedId(location));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -39,7 +39,7 @@ export class MessagesManager {
|
|
|
39
39
|
|
|
40
40
|
if (missingRoomIds.length) {
|
|
41
41
|
// If we don't have ack reports for all rooms in space, fetch them
|
|
42
|
-
const result = await this.tracker.client.send('GetAckReports', {spaceId});
|
|
42
|
+
const result = await this.tracker.client.send('GetAckReports', {location: {spaceId}});
|
|
43
43
|
|
|
44
44
|
if (result.error) {
|
|
45
45
|
throw result.error;
|
|
@@ -64,7 +64,7 @@ export class MessagesManager {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
if (! this.acks.has(roomId)) {
|
|
67
|
-
const result = await this.tracker.client.send('GetAckReports', {roomId});
|
|
67
|
+
const result = await this.tracker.client.send('GetAckReports', {location: {roomId}});
|
|
68
68
|
|
|
69
69
|
if (result.error) {
|
|
70
70
|
throw result.error;
|
|
@@ -81,7 +81,7 @@ export class MessagesManager {
|
|
|
81
81
|
* @internal
|
|
82
82
|
*/
|
|
83
83
|
public _deleteByTopicIds(roomId: string, ...topicIds: string[]): void {
|
|
84
|
-
this.list.delete(...topicIds.map(topicId => getCombinedId(roomId, topicId)));
|
|
84
|
+
this.list.delete(...topicIds.map(topicId => getCombinedId({roomId, topicId})));
|
|
85
85
|
this.acks.get(roomId)?.delete(...topicIds);
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -91,14 +91,14 @@ export class MessagesManager {
|
|
|
91
91
|
*/
|
|
92
92
|
public _handleNewTopics(roomId: string, ...topics: Topic[]): void {
|
|
93
93
|
this.list.set(...topics.map<[string, ObservableIndexedObjectCollection<Message>]>(topic => [
|
|
94
|
-
getCombinedId(roomId, topic.id),
|
|
94
|
+
getCombinedId({roomId, topicId: topic.id}),
|
|
95
95
|
new ObservableIndexedObjectCollection<Message>('id'),
|
|
96
96
|
]));
|
|
97
97
|
this.createAckReportsForNewTopics(roomId, topics);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
private handleNewMessage(ev: NewMessage): void {
|
|
101
|
-
this.list.get(getCombinedId(ev.
|
|
101
|
+
this.list.get(getCombinedId(ev.location)).set(ev.message);
|
|
102
102
|
this.updateLocallyAckReportOnNewMessage(ev);
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -127,7 +127,7 @@ export class MessagesManager {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
private updateLocallyAckReportOnNewMessage(ev: NewMessage): void {
|
|
130
|
-
const ackReports = this.acks.get(ev.roomId);
|
|
130
|
+
const ackReports = this.acks.get(ev.location.roomId);
|
|
131
131
|
|
|
132
132
|
if (! ackReports) {
|
|
133
133
|
// If we don't follow ack reports for this room, skip
|
|
@@ -135,7 +135,7 @@ export class MessagesManager {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
const isMe = ev.message.author.id === this.tracker.me?.id;
|
|
138
|
-
const currentAckReport = ackReports.get(ev.topicId);
|
|
138
|
+
const currentAckReport = ackReports.get(ev.location.topicId);
|
|
139
139
|
let update: Partial<AckReport>;
|
|
140
140
|
|
|
141
141
|
if (isMe) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {ChatStateTracker} from "./ChatStateTracker";
|
|
2
2
|
import {
|
|
3
|
+
ChatLocation,
|
|
3
4
|
PermissionOverwrites,
|
|
4
5
|
PermissionOverwritesUpdated,
|
|
5
6
|
PermissionOverwritesValue,
|
|
@@ -10,21 +11,20 @@ import {
|
|
|
10
11
|
SpaceLeft, SpaceMember,
|
|
11
12
|
SpaceMemberUpdated,
|
|
12
13
|
TopicDeleted,
|
|
13
|
-
} from "
|
|
14
|
+
} from "../types/src";
|
|
14
15
|
import {EventHandler, EventTarget} from "../EventTarget";
|
|
15
16
|
import {IndexedCollection} from "../IndexedObjectCollection";
|
|
16
17
|
import {Permissions} from "../Permissions";
|
|
17
18
|
import {PromiseRegistry} from "./AsyncUtils";
|
|
18
19
|
|
|
19
20
|
const getOvId = (
|
|
20
|
-
|
|
21
|
-
layerId: PermissionOverwrites['layerId'],
|
|
21
|
+
location: ChatLocation,
|
|
22
22
|
target?: PermissionOverwrites['target'],
|
|
23
23
|
targetId?: PermissionOverwrites['targetId'],
|
|
24
|
-
) =>
|
|
24
|
+
) => (location.spaceId ?? '') + (location.roomId ?? '') + (location.topicId ?? '') + (target ?? '') + (targetId ?? '');
|
|
25
25
|
|
|
26
26
|
const getOvIdByObject = (overwrites: PermissionOverwrites | PermissionOverwritesUpdated): string => getOvId(
|
|
27
|
-
overwrites.
|
|
27
|
+
overwrites.location, overwrites.target, overwrites.targetId
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
interface CheckPermissionsResult {
|
|
@@ -56,18 +56,19 @@ export class PermissionsManager extends EventTarget {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
public async getOverwrites(
|
|
59
|
-
|
|
60
|
-
layerId: PermissionOverwrites['layerId'],
|
|
59
|
+
location: ChatLocation,
|
|
61
60
|
target: PermissionOverwrites['target'],
|
|
62
61
|
targetId: PermissionOverwrites['targetId'],
|
|
63
62
|
): Promise<PermissionOverwrites | undefined> {
|
|
64
|
-
|
|
63
|
+
this.validateLocation(location);
|
|
64
|
+
|
|
65
|
+
const id = getOvId(location, target, targetId);
|
|
65
66
|
|
|
66
67
|
if (this.overwritesPromises.notExist(id)) {
|
|
67
68
|
this.overwritesPromises.registerByFunction(async () => {
|
|
68
69
|
const result = await this.tracker.client.send(
|
|
69
70
|
'GetPermissionOverwrites',
|
|
70
|
-
{
|
|
71
|
+
{location, target, targetId},
|
|
71
72
|
);
|
|
72
73
|
if (result.error) {
|
|
73
74
|
throw result.error;
|
|
@@ -86,15 +87,13 @@ export class PermissionsManager extends EventTarget {
|
|
|
86
87
|
|
|
87
88
|
public async check(
|
|
88
89
|
permissionNames: (keyof typeof Permissions.list)[],
|
|
89
|
-
|
|
90
|
-
roomId?: string,
|
|
91
|
-
topicId?: string,
|
|
90
|
+
location: ChatLocation,
|
|
92
91
|
): Promise<CheckPermissionsResult> {
|
|
93
92
|
if (! permissionNames.length) {
|
|
94
93
|
throw new Error('Permission names array cannot be empty');
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
const ownedPermissions = await this.calculatePermissions(
|
|
96
|
+
const ownedPermissions = await this.calculatePermissions(location);
|
|
98
97
|
const missing: string[] = [];
|
|
99
98
|
|
|
100
99
|
permissionNames.forEach(name => {
|
|
@@ -111,44 +110,36 @@ export class PermissionsManager extends EventTarget {
|
|
|
111
110
|
};
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
public async calculatePermissions(
|
|
115
|
-
|
|
116
|
-
throw new Error('Corrupted arguments hierarchy');
|
|
117
|
-
}
|
|
113
|
+
public async calculatePermissions(location: ChatLocation): Promise<number> {
|
|
114
|
+
this.validateLocation(location);
|
|
118
115
|
|
|
119
116
|
const userId = (await this.tracker.getMe()).id;
|
|
120
|
-
const [spaceMember, roomMember] = await this.fetchMembersOrFail(
|
|
117
|
+
const [spaceMember, roomMember] = await this.fetchMembersOrFail(location);
|
|
121
118
|
const userRoles: string[] = [...(spaceMember?.roles ?? []), ...(roomMember?.roles ?? [])];
|
|
122
|
-
const [spaces, rooms, topics] = await Promise.all([
|
|
123
|
-
this.tracker.spaces.get(),
|
|
124
|
-
this.tracker.rooms.get(),
|
|
125
|
-
roomId ? this.tracker.rooms.getTopics(roomId) : null,
|
|
126
|
-
]);
|
|
127
|
-
|
|
128
119
|
const promises: Promise<PermissionOverwritesValue>[] = [
|
|
129
120
|
// Global user overwrites
|
|
130
|
-
this.getOverwrites(
|
|
121
|
+
this.getOverwrites({}, 'User', userId).then(v => v.overwrites),
|
|
131
122
|
];
|
|
132
123
|
|
|
133
|
-
if (spaceId && spaces.has(spaceId)) {
|
|
134
|
-
|
|
135
|
-
promises.push(this.
|
|
124
|
+
if (location.spaceId && (await this.tracker.spaces.get())?.has(location.spaceId)) {
|
|
125
|
+
const filterLocation: ChatLocation = {spaceId: location.spaceId};
|
|
126
|
+
promises.push(this.collectRoleOverwrites(filterLocation, userRoles));
|
|
127
|
+
promises.push(this.getOverwrites(filterLocation, 'User', userId).then(v => v.overwrites));
|
|
136
128
|
}
|
|
137
129
|
|
|
138
|
-
if (roomId && rooms.has(roomId)) {
|
|
130
|
+
if (location.roomId && (await this.tracker.rooms.get())?.has(location.roomId)) {
|
|
131
|
+
const filterLocation: ChatLocation = {spaceId: location.spaceId, roomId: location.roomId};
|
|
139
132
|
if (userRoles.length) {
|
|
140
|
-
promises.push(this.collectRoleOverwrites(
|
|
133
|
+
promises.push(this.collectRoleOverwrites(filterLocation, userRoles));
|
|
141
134
|
}
|
|
142
|
-
|
|
143
|
-
promises.push(this.getOverwrites('Room', roomId, 'User', userId).then(v => v.overwrites));
|
|
135
|
+
promises.push(this.getOverwrites(filterLocation, 'User', userId).then(v => v.overwrites));
|
|
144
136
|
}
|
|
145
137
|
|
|
146
|
-
if (topicId &&
|
|
138
|
+
if (location.topicId && (await this.tracker.rooms.getTopics(location.roomId))?.has(location.topicId)) {
|
|
147
139
|
if (userRoles.length) {
|
|
148
|
-
promises.push(this.collectRoleOverwrites(
|
|
140
|
+
promises.push(this.collectRoleOverwrites(location, userRoles));
|
|
149
141
|
}
|
|
150
|
-
|
|
151
|
-
promises.push(this.getOverwrites('Topic', topicId, 'User', userId).then(v => v.overwrites));
|
|
142
|
+
promises.push(this.getOverwrites(location, 'User', userId).then(v => v.overwrites));
|
|
152
143
|
}
|
|
153
144
|
|
|
154
145
|
return this.resolveOverwritesHierarchy(await Promise.all(promises));
|
|
@@ -160,22 +151,25 @@ export class PermissionsManager extends EventTarget {
|
|
|
160
151
|
}
|
|
161
152
|
|
|
162
153
|
private handleSpaceDeleted(ev: SpaceDeleted | SpaceLeft): void {
|
|
163
|
-
const ids = this.deleteOverwritesByIdPrefix(getOvId(
|
|
154
|
+
const ids = this.deleteOverwritesByIdPrefix(getOvId({spaceId: ev.id}));
|
|
164
155
|
this.overwritesPromises.forget(...ids);
|
|
165
156
|
}
|
|
166
157
|
|
|
167
|
-
private handleRoomDeleted(ev: RoomDeleted | RoomLeft): void {
|
|
168
|
-
const
|
|
169
|
-
|
|
158
|
+
private async handleRoomDeleted(ev: RoomDeleted | RoomLeft): Promise<void> {
|
|
159
|
+
const room = (await this.tracker.rooms.get()).get(ev.id);
|
|
160
|
+
if (room) {
|
|
161
|
+
const ids = this.deleteOverwritesByIdPrefix(getOvId({spaceId: room.spaceId, roomId: room.id}));
|
|
162
|
+
this.overwritesPromises.forget(...ids);
|
|
163
|
+
}
|
|
170
164
|
}
|
|
171
165
|
|
|
172
166
|
private handleTopicDeleted(ev: TopicDeleted): void {
|
|
173
|
-
const ids = this.deleteOverwritesByIdPrefix(getOvId(
|
|
167
|
+
const ids = this.deleteOverwritesByIdPrefix(getOvId(ev.location));
|
|
174
168
|
this.overwritesPromises.forget(...ids);
|
|
175
169
|
}
|
|
176
170
|
|
|
177
171
|
private handleRoleDeleted(ev: RoleDeleted): void {
|
|
178
|
-
const ids = this.deleteOverwritesByIdPrefix(getOvId(
|
|
172
|
+
const ids = this.deleteOverwritesByIdPrefix(getOvId({spaceId: ev.spaceId}, 'Role', ev.id));
|
|
179
173
|
this.overwritesPromises.forget(...ids);
|
|
180
174
|
}
|
|
181
175
|
|
|
@@ -209,16 +203,14 @@ export class PermissionsManager extends EventTarget {
|
|
|
209
203
|
}
|
|
210
204
|
|
|
211
205
|
private async collectRoleOverwrites(
|
|
212
|
-
|
|
213
|
-
layer: PermissionOverwrites['layer'],
|
|
214
|
-
layerId: PermissionOverwrites['layerId'],
|
|
206
|
+
location: ChatLocation,
|
|
215
207
|
userRoles: string[],
|
|
216
208
|
): Promise<PermissionOverwritesValue> {
|
|
217
209
|
const roleOverwrites = await Promise.all(userRoles.map(
|
|
218
|
-
roleId => this.getOverwrites(
|
|
210
|
+
roleId => this.getOverwrites(location, 'Role', roleId)
|
|
219
211
|
));
|
|
220
212
|
|
|
221
|
-
return this.resolveOverwritesFromRolesByOrder(spaceId, roleOverwrites);
|
|
213
|
+
return this.resolveOverwritesFromRolesByOrder(location.spaceId, roleOverwrites);
|
|
222
214
|
}
|
|
223
215
|
|
|
224
216
|
private async resolveOverwritesFromRolesByOrder(
|
|
@@ -289,20 +281,26 @@ export class PermissionsManager extends EventTarget {
|
|
|
289
281
|
return result;
|
|
290
282
|
}
|
|
291
283
|
|
|
292
|
-
private async fetchMembersOrFail(
|
|
284
|
+
private async fetchMembersOrFail(location: ChatLocation): Promise<[SpaceMember | null, RoomMember | null]> {
|
|
293
285
|
const results = await Promise.all([
|
|
294
|
-
spaceId ? this.tracker.spaces.getMe(spaceId) : null,
|
|
295
|
-
roomId ? this.tracker.rooms.getMe(roomId) : null,
|
|
286
|
+
location.spaceId ? this.tracker.spaces.getMe(location.spaceId) : null,
|
|
287
|
+
location.roomId ? this.tracker.rooms.getMe(location.roomId) : null,
|
|
296
288
|
]);
|
|
297
289
|
|
|
298
|
-
const spaceFail = spaceId && ! results[0];
|
|
299
|
-
const roomFail = roomId && ! results[1];
|
|
290
|
+
const spaceFail = location.spaceId && ! results[0];
|
|
291
|
+
const roomFail = location.roomId && ! results[1];
|
|
300
292
|
|
|
301
293
|
if (spaceFail || roomFail) {
|
|
302
|
-
const layer = spaceFail ? `space (${spaceId})` : `room (${roomId})`;
|
|
294
|
+
const layer = spaceFail ? `space (${location.spaceId})` : `room (${location.roomId})`;
|
|
303
295
|
throw new Error(`Attempting to calculate permissions for a ${layer} that the user does not belong to`);
|
|
304
296
|
}
|
|
305
297
|
|
|
306
298
|
return results;
|
|
307
299
|
}
|
|
300
|
+
|
|
301
|
+
private validateLocation(location: ChatLocation): void {
|
|
302
|
+
if (location.topicId && ! location.roomId || ! location.spaceId && ! location.roomId && ! location.topicId) {
|
|
303
|
+
throw new Error('Corrupted arguments hierarchy');
|
|
304
|
+
}
|
|
305
|
+
}
|
|
308
306
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
Topic,
|
|
10
10
|
TopicDeleted,
|
|
11
11
|
UserUpdated,
|
|
12
|
-
} from "
|
|
12
|
+
} from "../types/src";
|
|
13
13
|
import {ChatStateTracker} from "./ChatStateTracker";
|
|
14
14
|
import {DeferredTask, PromiseRegistry} from "./AsyncUtils";
|
|
15
15
|
import {MessagesManager} from "./MessagesManager";
|
|
@@ -163,14 +163,17 @@ export class RoomsManager {
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
private handleTopicDeleted(ev: TopicDeleted): void {
|
|
166
|
-
const collection = this.topics.get(ev.roomId);
|
|
167
|
-
collection.delete(ev.
|
|
168
|
-
|
|
166
|
+
const collection = this.topics.get(ev.location.roomId);
|
|
167
|
+
collection.delete(ev.location.topicId);
|
|
168
|
+
|
|
169
|
+
const room = this.list.get(ev.location.roomId);
|
|
170
|
+
if (room.defaultTopic?.id === ev.location.topicId) {
|
|
171
|
+
this.list.set({...room, defaultTopic: null});
|
|
172
|
+
}
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
private handleNewTopic(ev: NewTopic): void {
|
|
172
176
|
this.addJoinedRoomTopics(ev.roomId, ev.topic);
|
|
173
|
-
this.list.get(ev.roomId).topics.push(ev.topic);
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
private addJoinedRoomTopics(roomId: string, ...topics: Topic[]): void {
|
|
@@ -201,7 +204,9 @@ export class RoomsManager {
|
|
|
201
204
|
|
|
202
205
|
private addJoinedRooms(...rooms: Room[]): void {
|
|
203
206
|
for (const room of rooms) {
|
|
204
|
-
|
|
207
|
+
if (room.defaultTopic) {
|
|
208
|
+
this.addJoinedRoomTopics(room.id, room.defaultTopic);
|
|
209
|
+
}
|
|
205
210
|
}
|
|
206
211
|
this.list.set(...rooms);
|
|
207
212
|
}
|