1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Can register to post

This commit is contained in:
Pierre HUBERT 2020-04-01 17:26:56 +02:00
parent 054b388224
commit 21ba8eff25
3 changed files with 30 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import { ConversationsHelper } from "../helpers/ConversationsHelper";
import { EventsHelper } from "../helpers/EventsHelper"; import { EventsHelper } from "../helpers/EventsHelper";
import { ConversationMessage } from "../entities/ConversationMessage"; import { ConversationMessage } from "../entities/ConversationMessage";
import { ConversationsController } from "./ConversationsController"; import { ConversationsController } from "./ConversationsController";
import { PostAccessLevel } from "../entities/Post";
export class UserWebSocketActions { export class UserWebSocketActions {
@ -47,6 +48,28 @@ export class UserWebSocketActions {
h.success(); 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 * Send updated notifications number to some users

View File

@ -29,6 +29,7 @@ export interface ActiveClient {
incognito: boolean, incognito: boolean,
registeredConversations: Set<number>, registeredConversations: Set<number>,
registeredPosts: Set<number>,
} }
// Tokens are valid only 10 seconds after they are generated // Tokens are valid only 10 seconds after they are generated
@ -119,7 +120,8 @@ export class UserWebSocketController {
userID: entry.userID, userID: entry.userID,
ws: ws, ws: ws,
incognito: entry.incognito, incognito: entry.incognito,
registeredConversations: new Set() registeredConversations: new Set(),
registeredPosts: new Set(),
} }
this.active_clients.push(client); this.active_clients.push(client);

View File

@ -20,9 +20,13 @@ export const UserWebSocketRoutes: UserWebSocketRoute[] = [
// Main controller // Main controller
{title: "$main/set_incognito", handler: (h) => UserWebSocketActions.SetIncognito(h)}, {title: "$main/set_incognito", handler: (h) => UserWebSocketActions.SetIncognito(h)},
{title: "$main/register_conv", handler: (h) => UserWebSocketActions.RegisterConv(h)}, {title: "$main/register_conv", handler: (h) => UserWebSocketActions.RegisterConv(h)},
{title: "$main/unregister_conv", handler: (h) => UserWebSocketActions.UnregisterConv(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 // Likes controller
{title: "likes/update", handler: (h) => LikesController.Update(h)}, {title: "likes/update", handler: (h) => LikesController.Update(h)},