mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-24 10:23:28 +00:00
Send new number unread conversations for user
This commit is contained in:
@ -10,6 +10,7 @@ import { time } from '../utils/DateUtils';
|
||||
import { randomStr } from '../utils/CryptUtils';
|
||||
import { EventsHelper } from '../helpers/EventsHelper';
|
||||
import { NotificationsHelper } from '../helpers/NotificationsHelper';
|
||||
import { ConversationsHelper } from '../helpers/ConversationsHelper';
|
||||
|
||||
interface PendingRequests {
|
||||
time: number,
|
||||
@ -208,10 +209,33 @@ export class UserWebSocketController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send upated number of unread conversations count
|
||||
*
|
||||
* @param usersID Target users ID
|
||||
*/
|
||||
public static async SendNewUnreadConversationsCount(usersID: number[]) {
|
||||
for(const userID of usersID) {
|
||||
|
||||
if(!this.IsConnected(userID))
|
||||
continue;
|
||||
|
||||
// Notify user
|
||||
this.Send(userID, "", {
|
||||
title: "number_unread_conversations",
|
||||
id: "",
|
||||
data: await ConversationsHelper.CountUnreadForUser(userID)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When user sign out
|
||||
EventsHelper.Listen("destroyed_login_tokens", (e) => UserWebSocketController.CloseClientSockets(e.client.id, e.userID));
|
||||
|
||||
// When we get a new number of notifications
|
||||
EventsHelper.Listen("updated_number_notifications", async (e) => await UserWebSocketController.SendNewNotificationsNumber(e.usersID));
|
||||
EventsHelper.Listen("updated_number_notifications", async (e) => await UserWebSocketController.SendNewNotificationsNumber(e.usersID));
|
||||
|
||||
// When we get a new number of unread conversations
|
||||
EventsHelper.Listen("updated_number_unread_conversations", async (e) => await UserWebSocketController.SendNewUnreadConversationsCount(e.usersID));
|
Reference in New Issue
Block a user