mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-21 21:09:22 +00:00
Can register to post
This commit is contained in:
parent
054b388224
commit
21ba8eff25
@ -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
|
||||
|
@ -29,6 +29,7 @@ export interface ActiveClient {
|
||||
incognito: boolean,
|
||||
|
||||
registeredConversations: Set<number>,
|
||||
registeredPosts: Set<number>,
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
|
@ -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)},
|
||||
|
Loading…
Reference in New Issue
Block a user