diff --git a/src/controllers/UserWebSocketActions.ts b/src/controllers/UserWebSocketActions.ts index 459c08f..1c22d85 100644 --- a/src/controllers/UserWebSocketActions.ts +++ b/src/controllers/UserWebSocketActions.ts @@ -12,6 +12,7 @@ import { ConversationsHelper } from "../helpers/ConversationsHelper"; import { EventsHelper } from "../helpers/EventsHelper"; import { ConversationMessage } from "../entities/ConversationMessage"; import { ConversationsController } from "./ConversationsController"; +import { PostAccessLevel } from "../entities/Post"; export class UserWebSocketActions { @@ -47,6 +48,28 @@ export class UserWebSocketActions { h.success(); } + /** + * Request to be notified of post changes + * + * @param h Request handler + */ + public static async RegisterPost(h: UserWebSocketRequestsHandler) { + const postID = await h.postPostIDWithAccess("postID", PostAccessLevel.BASIC_ACCESS); + h.wsClient.registeredPosts.add(postID); + h.success(); + } + + /** + * Unregister a post + * + * @param h Request handler + */ + public static async UnregisterPost(h: UserWebSocketRequestsHandler) { + const postID = h.postInt("postID"); // Warning ! we do not check post access level here because it is not required! + h.wsClient.registeredPosts.delete(postID); + h.success(); + } + /** * Send updated notifications number to some users diff --git a/src/controllers/UserWebSocketController.ts b/src/controllers/UserWebSocketController.ts index 5680607..f15b830 100644 --- a/src/controllers/UserWebSocketController.ts +++ b/src/controllers/UserWebSocketController.ts @@ -29,6 +29,7 @@ export interface ActiveClient { incognito: boolean, registeredConversations: Set, + registeredPosts: Set, } // Tokens are valid only 10 seconds after they are generated @@ -119,7 +120,8 @@ export class UserWebSocketController { userID: entry.userID, ws: ws, incognito: entry.incognito, - registeredConversations: new Set() + registeredConversations: new Set(), + registeredPosts: new Set(), } this.active_clients.push(client); diff --git a/src/controllers/UserWebSocketRoutes.ts b/src/controllers/UserWebSocketRoutes.ts index 2bb1756..92f3089 100644 --- a/src/controllers/UserWebSocketRoutes.ts +++ b/src/controllers/UserWebSocketRoutes.ts @@ -20,8 +20,12 @@ export const UserWebSocketRoutes: UserWebSocketRoute[] = [ // Main controller {title: "$main/set_incognito", handler: (h) => UserWebSocketActions.SetIncognito(h)}, + {title: "$main/register_conv", handler: (h) => UserWebSocketActions.RegisterConv(h)}, {title: "$main/unregister_conv", handler: (h) => UserWebSocketActions.UnregisterConv(h)}, + + {title: "$main/register_post", handler: (h) => UserWebSocketActions.RegisterPost(h)}, + {title: "$main/unregister_post", handler: (h) => UserWebSocketActions.UnregisterPost(h)}, // Likes controller {title: "likes/update", handler: (h) => LikesController.Update(h)},