@@ -8,6 +8,7 @@ import {forceLogoutIfNecessary} from '@actions/remote/session';
8
8
import { updateThreadFollowing } from '@actions/remote/thread' ;
9
9
import { fetchUsersByIds } from '@actions/remote/user' ;
10
10
import {
11
+ endCallConfirmationAlert ,
11
12
leaveAndJoinWithAlert ,
12
13
needsRecordingErrorAlert ,
13
14
needsRecordingWillBePostedAlert ,
@@ -28,6 +29,7 @@ import {
28
29
setScreenShareURL ,
29
30
setSpeakerPhone ,
30
31
} from '@calls/state' ;
32
+ import { type AudioDevice , type Call , type CallSession , type CallsConnection , EndCallReturn } from '@calls/types/calls' ;
31
33
import { General , Preferences } from '@constants' ;
32
34
import Calls from '@constants/calls' ;
33
35
import DatabaseManager from '@database/manager' ;
@@ -44,7 +46,6 @@ import {displayUsername, getUserIdFromChannelName, isSystemAdmin} from '@utils/u
44
46
45
47
import { newConnection } from '../connection/connection' ;
46
48
47
- import type { AudioDevice , Call , CallSession , CallsConnection } from '@calls/types/calls' ;
48
49
import type { CallChannelState , CallState , EmojiData , SessionState } from '@mattermost/calls/lib/types' ;
49
50
import type { IntlShape } from 'react-intl' ;
50
51
@@ -132,7 +133,7 @@ export const loadCallForChannel = async (serverUrl: string, channelId: string) =
132
133
fetchUsersByIds ( serverUrl , Array . from ( ids ) ) ;
133
134
}
134
135
135
- setCallForChannel ( serverUrl , channelId , resp . enabled , call ) ;
136
+ setCallForChannel ( serverUrl , channelId , call , resp . enabled ) ;
136
137
137
138
return { data : { call, enabled : resp . enabled } } ;
138
139
} ;
@@ -160,11 +161,12 @@ const convertOldCallToNew = (call: CallState): CallState => {
160
161
} ;
161
162
} ;
162
163
163
- const createCallAndAddToIds = ( channelId : string , call : CallState , ids : Set < string > ) => {
164
- return {
164
+ export const createCallAndAddToIds = ( channelId : string , call : CallState , ids ?: Set < string > ) => {
165
+ // Don't cast so that we get alerted to missing types
166
+ const convertedCall : Call = {
165
167
sessions : Object . values ( call . sessions ) . reduce ( ( accum , cur ) => {
166
168
// Add the id to the set of UserModels we want to ensure are loaded.
167
- ids . add ( cur . user_id ) ;
169
+ ids ? .add ( cur . user_id ) ;
168
170
169
171
// Create the CallParticipant
170
172
accum [ cur . session_id ] = {
@@ -184,7 +186,9 @@ const createCallAndAddToIds = (channelId: string, call: CallState, ids: Set<stri
184
186
hostId : call . host_id ,
185
187
recState : call . recording ,
186
188
dismissed : call . dismissed_notification || { } ,
187
- } as Call ;
189
+ } ;
190
+
191
+ return convertedCall ;
188
192
} ;
189
193
190
194
export const loadConfigAndCalls = async ( serverUrl : string , userId : string ) => {
@@ -302,6 +306,29 @@ export const leaveCall = (err?: Error) => {
302
306
}
303
307
} ;
304
308
309
+ export const leaveCallConfirmation = async (
310
+ intl : IntlShape ,
311
+ otherParticipants : boolean ,
312
+ isAdmin : boolean ,
313
+ isHost : boolean ,
314
+ serverUrl : string ,
315
+ channelId : string ,
316
+ leaveCb ?: ( ) => void ) => {
317
+ const showHostControls = ( isHost || isAdmin ) && otherParticipants ;
318
+ const ret = await endCallConfirmationAlert ( intl , showHostControls ) as EndCallReturn ;
319
+ switch ( ret ) {
320
+ case EndCallReturn . Cancel :
321
+ return ;
322
+ case EndCallReturn . LeaveCall :
323
+ leaveCall ( ) ;
324
+ leaveCb ?.( ) ;
325
+ return ;
326
+ case EndCallReturn . EndCall :
327
+ endCall ( serverUrl , channelId ) ;
328
+ leaveCb ?.( ) ;
329
+ }
330
+ } ;
331
+
305
332
export const muteMyself = ( ) => {
306
333
if ( connection ) {
307
334
connection . mute ( ) ;
0 commit comments