mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Turn WsMessage into an object
This commit is contained in:
parent
d4b624e519
commit
348084442b
@ -11,6 +11,7 @@ import { randomStr } from '../utils/CryptUtils';
|
|||||||
import { EventsHelper } from '../helpers/EventsHelper';
|
import { EventsHelper } from '../helpers/EventsHelper';
|
||||||
import { NotificationsHelper } from '../helpers/NotificationsHelper';
|
import { NotificationsHelper } from '../helpers/NotificationsHelper';
|
||||||
import { ConversationsHelper } from '../helpers/ConversationsHelper';
|
import { ConversationsHelper } from '../helpers/ConversationsHelper';
|
||||||
|
import { WsMessage } from '../entities/WsMessage';
|
||||||
|
|
||||||
interface PendingRequests {
|
interface PendingRequests {
|
||||||
time: number,
|
time: number,
|
||||||
@ -26,12 +27,6 @@ export interface ActiveClient {
|
|||||||
ws: ws
|
ws: ws
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WsMessage {
|
|
||||||
id: string,
|
|
||||||
title: string,
|
|
||||||
data: any
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tokens are valid only 10 seconds after they are generated
|
// Tokens are valid only 10 seconds after they are generated
|
||||||
const TOKENS_DURATION = 10
|
const TOKENS_DURATION = 10
|
||||||
const TOKEN_LENGTH = 20
|
const TOKEN_LENGTH = 20
|
||||||
@ -201,11 +196,11 @@ export class UserWebSocketController {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Notify user
|
// Notify user
|
||||||
this.Send(userID, "", {
|
this.Send(userID, "", new WsMessage({
|
||||||
title: "number_notifs",
|
title: "number_notifs",
|
||||||
id: "",
|
id: "",
|
||||||
data: await NotificationsHelper.CountUnread(userID)
|
data: await NotificationsHelper.CountUnread(userID)
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -222,11 +217,11 @@ export class UserWebSocketController {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Notify user
|
// Notify user
|
||||||
this.Send(userID, "", {
|
this.Send(userID, "", new WsMessage({
|
||||||
title: "number_unread_conversations",
|
title: "number_unread_conversations",
|
||||||
id: "",
|
id: "",
|
||||||
data: await ConversationsHelper.CountUnreadForUser(userID)
|
data: await ConversationsHelper.CountUnreadForUser(userID)
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { BaseRequestsHandler } from "./BaseRequestsHandler";
|
import { BaseRequestsHandler } from "./BaseRequestsHandler";
|
||||||
import { ActiveClient, WsMessage } from "../controllers/UserWebSocketController";
|
import { ActiveClient } from "../controllers/UserWebSocketController";
|
||||||
|
import { WsMessage } from "./WsMessage";
|
||||||
|
|
||||||
export class UserWebSocketRequestsHandler extends BaseRequestsHandler {
|
export class UserWebSocketRequestsHandler extends BaseRequestsHandler {
|
||||||
|
|
||||||
|
24
src/entities/WsMessage.ts
Normal file
24
src/entities/WsMessage.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* WebSocket message
|
||||||
|
*
|
||||||
|
* @author Pierre Hubert
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface WsMessageBuilder {
|
||||||
|
id: string,
|
||||||
|
title: string,
|
||||||
|
data: any
|
||||||
|
}
|
||||||
|
|
||||||
|
export class WsMessage implements WsMessageBuilder {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
data: any;
|
||||||
|
|
||||||
|
public constructor(info: WsMessageBuilder) {
|
||||||
|
for (const key in info) {
|
||||||
|
if (info.hasOwnProperty(key))
|
||||||
|
this[key] = info[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user