From c50e9d3d233852ecae1110a8147f66d9d93d27c8 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 13 Apr 2020 14:35:36 +0200 Subject: [PATCH] Check if there is an ongoing call on a conversation or not --- src/controllers/CallsController.ts | 12 ++++++++++++ src/controllers/ConversationsController.ts | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/controllers/CallsController.ts b/src/controllers/CallsController.ts index b98054f..1958822 100644 --- a/src/controllers/CallsController.ts +++ b/src/controllers/CallsController.ts @@ -40,6 +40,18 @@ export class CallsController { }) } + /** + * Check out whether a call is currently happening for a given + * conversation + * + * @param convID The ID of the conversation to check + * @return {boolean} True if there is an ongoing call / false else + */ + public static IsHavingCall(convID: number) : boolean { + return UserWebSocketController.active_clients + .find((f) => f.activeCalls.has(convID)) !== undefined; + } + /** * Join a call * diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index 6bb73ee..66377ba 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -6,6 +6,7 @@ import { removeHTMLNodes } from "../utils/StringUtils"; import { ConversationMessage } from "../entities/ConversationMessage"; import { UnreadConversation } from "../entities/UnreadConversation"; import { CallsHelper } from "../helpers/CallsHelper"; +import { CallsController } from "./CallsController"; /** * Conversations controller @@ -372,7 +373,8 @@ export class ConversationsController { saw_last_message: c.sawLastMessage ? 1 : 0, members: [...c.members], can_have_call: CallsHelper.CanHaveCall(c), - can_have_video_call: CallsHelper.CanHaveVideoCAll(c) + can_have_video_call: CallsHelper.CanHaveVideoCAll(c), + has_call_now: CallsController.IsHavingCall(c.id) }; }