From 81dd44ae091b5e2fa3908702737663ba5583b507 Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Thu, 15 Jun 2023 10:08:50 -0400 Subject: [PATCH] MM-52653 - Calls: Attach call to existing thread on `/call start` (#7338) * send rootId when starting a call from a thread * allow join to start calls in threads and with thread titles --- .../post_draft/send_handler/send_handler.tsx | 2 +- app/products/calls/actions/calls.ts | 13 ++++++++----- app/products/calls/alerts.ts | 8 +++++--- app/products/calls/connection/connection.ts | 2 ++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/components/post_draft/send_handler/send_handler.tsx b/app/components/post_draft/send_handler/send_handler.tsx index dd901b59a..cc0f15ce6 100644 --- a/app/components/post_draft/send_handler/send_handler.tsx +++ b/app/components/post_draft/send_handler/send_handler.tsx @@ -166,7 +166,7 @@ export default function SendHandler({ const sendCommand = useCallback(async () => { if (value.trim().startsWith('/call')) { - const {handled, error} = await handleCallsSlashCommand(value.trim(), serverUrl, channelId, currentUserId, intl); + const {handled, error} = await handleCallsSlashCommand(value.trim(), serverUrl, channelId, rootId, currentUserId, intl); if (handled) { setSendingMessage(false); clearDraft(); diff --git a/app/products/calls/actions/calls.ts b/app/products/calls/actions/calls.ts index 4d372dcbf..4f560a143 100644 --- a/app/products/calls/actions/calls.ts +++ b/app/products/calls/actions/calls.ts @@ -208,6 +208,7 @@ export const joinCall = async ( userId: string, hasMicPermission: boolean, title?: string, + rootId?: string, ): Promise<{ error?: unknown; data?: string }> => { // Edge case: calls was disabled when app loaded, and then enabled, but app hasn't // reconnected its websocket since then (i.e., hasn't called batchLoadCalls yet) @@ -226,7 +227,7 @@ export const joinCall = async ( try { connection = await newConnection(serverUrl, channelId, () => { myselfLeftCall(); - }, setScreenShareURL, hasMicPermission, title); + }, setScreenShareURL, hasMicPermission, title, rootId); } catch (error) { await forceLogoutIfNecessary(serverUrl, error); return {error}; @@ -417,7 +418,7 @@ export const stopCallRecording = async (serverUrl: string, callId: string) => { }; // handleCallsSlashCommand will return true if the slash command was handled -export const handleCallsSlashCommand = async (value: string, serverUrl: string, channelId: string, currentUserId: string, intl: IntlShape): +export const handleCallsSlashCommand = async (value: string, serverUrl: string, channelId: string, rootId: string, currentUserId: string, intl: IntlShape): Promise<{ handled?: boolean; error?: string }> => { const tokens = value.split(' '); if (tokens.length < 2 || tokens[0] !== '/call') { @@ -438,12 +439,14 @@ export const handleCallsSlashCommand = async (value: string, serverUrl: string, }; } const title = tokens.length > 2 ? tokens.slice(2).join(' ') : undefined; - await leaveAndJoinWithAlert(intl, serverUrl, channelId, title); + await leaveAndJoinWithAlert(intl, serverUrl, channelId, title, rootId); return {handled: true}; } - case 'join': - await leaveAndJoinWithAlert(intl, serverUrl, channelId); + case 'join': { + const title = tokens.length > 2 ? tokens.slice(2).join(' ') : undefined; + await leaveAndJoinWithAlert(intl, serverUrl, channelId, title, rootId); return {handled: true}; + } case 'leave': if (getCurrentCall()?.channelId === channelId) { await leaveCall(); diff --git a/app/products/calls/alerts.ts b/app/products/calls/alerts.ts index 0759cb6d8..22bf8b78c 100644 --- a/app/products/calls/alerts.ts +++ b/app/products/calls/alerts.ts @@ -72,6 +72,7 @@ export const leaveAndJoinWithAlert = async ( joinServerUrl: string, joinChannelId: string, title?: string, + rootId?: string, ) => { let leaveChannelName = ''; let joinChannelName = ''; @@ -132,13 +133,13 @@ export const leaveAndJoinWithAlert = async ( id: 'mobile.leave_and_join_confirmation', defaultMessage: 'Leave & Join', }), - onPress: () => doJoinCall(joinServerUrl, joinChannelId, joinChannelIsDMorGM, newCall, intl, title), + onPress: () => doJoinCall(joinServerUrl, joinChannelId, joinChannelIsDMorGM, newCall, intl, title, rootId), style: 'cancel', }, ], ); } else { - doJoinCall(joinServerUrl, joinChannelId, joinChannelIsDMorGM, newCall, intl, title); + doJoinCall(joinServerUrl, joinChannelId, joinChannelIsDMorGM, newCall, intl, title, rootId); } }; @@ -149,6 +150,7 @@ const doJoinCall = async ( newCall: boolean, intl: IntlShape, title?: string, + rootId?: string, ) => { const {formatMessage} = intl; @@ -197,7 +199,7 @@ const doJoinCall = async ( const hasPermission = await hasMicrophonePermission(); setMicPermissionsGranted(hasPermission); - const res = await joinCall(serverUrl, channelId, user.id, hasPermission, title); + const res = await joinCall(serverUrl, channelId, user.id, hasPermission, title, rootId); if (res.error) { const seeLogs = formatMessage({id: 'mobile.calls_see_logs', defaultMessage: 'See server logs'}); errorAlert(res.error?.toString() || seeLogs, intl); diff --git a/app/products/calls/connection/connection.ts b/app/products/calls/connection/connection.ts index 99a6b6ff6..0dd69a3d2 100644 --- a/app/products/calls/connection/connection.ts +++ b/app/products/calls/connection/connection.ts @@ -31,6 +31,7 @@ export async function newConnection( setScreenShareURL: (url: string) => void, hasMicPermission: boolean, title?: string, + rootId?: string, ) { let peer: RTCPeer | null = null; let stream: MediaStream; @@ -323,6 +324,7 @@ export async function newConnection( ws.send('join', { channelID, title, + threadID: rootId, }); } });