mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Send new number unread conversations for user
This commit is contained in:
parent
fd9ca17ef1
commit
197fa12cde
@ -10,6 +10,7 @@ import { time } from '../utils/DateUtils';
|
|||||||
import { randomStr } from '../utils/CryptUtils';
|
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';
|
||||||
|
|
||||||
interface PendingRequests {
|
interface PendingRequests {
|
||||||
time: number,
|
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
|
// When user sign out
|
||||||
EventsHelper.Listen("destroyed_login_tokens", (e) => UserWebSocketController.CloseClientSockets(e.client.id, e.userID));
|
EventsHelper.Listen("destroyed_login_tokens", (e) => UserWebSocketController.CloseClientSockets(e.client.id, e.userID));
|
||||||
|
|
||||||
// When we get a new number of notifications
|
// 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));
|
@ -4,6 +4,7 @@ import { time } from "../utils/DateUtils";
|
|||||||
import { ConversationMessage, BaseConversationMessage } from "../entities/ConversationMessage";
|
import { ConversationMessage, BaseConversationMessage } from "../entities/ConversationMessage";
|
||||||
import { UnreadConversation } from "../entities/UnreadConversation";
|
import { UnreadConversation } from "../entities/UnreadConversation";
|
||||||
import { existsSync, unlinkSync } from "fs";
|
import { existsSync, unlinkSync } from "fs";
|
||||||
|
import { EventsHelper } from "./EventsHelper";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conversations helper
|
* Conversations helper
|
||||||
@ -407,7 +408,7 @@ export class ConversationsHelper {
|
|||||||
* @param userID Target user ID
|
* @param userID Target user ID
|
||||||
*/
|
*/
|
||||||
public static async MarkUserSeen(convID: number, userID: number) {
|
public static async MarkUserSeen(convID: number, userID: number) {
|
||||||
await DatabaseHelper.UpdateRows({
|
const count = await DatabaseHelper.UpdateRows({
|
||||||
table: USERS_TABLE,
|
table: USERS_TABLE,
|
||||||
where: {
|
where: {
|
||||||
conv_id: convID,
|
conv_id: convID,
|
||||||
@ -417,6 +418,12 @@ export class ConversationsHelper {
|
|||||||
saw_last_message: 1
|
saw_last_message: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Send an event if required
|
||||||
|
if(count > 0)
|
||||||
|
await EventsHelper.Emit("updated_number_unread_conversations", {
|
||||||
|
usersID: [userID]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,12 +18,18 @@ export interface UpdatedNotificationsNumberEvent {
|
|||||||
usersID: number[]
|
usersID: number[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When some users have an updated number of unread conversations
|
||||||
|
export interface UpdateNumberUnreadConversations {
|
||||||
|
usersID: number[]
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global map of all possible events
|
* Global map of all possible events
|
||||||
*/
|
*/
|
||||||
export interface EventsMap {
|
export interface EventsMap {
|
||||||
"destroyed_login_tokens": DestroyedLoginTokensEvent,
|
"destroyed_login_tokens": DestroyedLoginTokensEvent,
|
||||||
"updated_number_notifications": UpdatedNotificationsNumberEvent,
|
"updated_number_notifications": UpdatedNotificationsNumberEvent,
|
||||||
|
"updated_number_unread_conversations": UpdateNumberUnreadConversations
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EventsHelper {
|
export class EventsHelper {
|
||||||
|
Loading…
Reference in New Issue
Block a user