@@ -3,6 +3,7 @@ import React, {
33 useCallback ,
44 useContext ,
55 useEffect ,
6+ useEffectEvent ,
67 useMemo ,
78 useRef ,
89 useState ,
@@ -65,7 +66,8 @@ import { mouseEventToPosition } from '../../utils/mouseEventToPosition'
6566import { useRovingTabindex } from '../../contexts/RovingTabindex'
6667import { avatarInitial } from '@deltachat-desktop/shared/avatarInitial'
6768import { getLogger } from '@deltachat-desktop/shared/logger'
68- import Icon from '../Icon'
69+ import { IconButton } from '../Icon'
70+ import { useRpcFetch } from '../../hooks/useFetch'
6971
7072const log = getLogger ( 'Message' )
7173
@@ -817,12 +819,10 @@ export default function Message(props: {
817819 />
818820 ) : null }
819821 { message . viewType === 'Call' && (
820- < Icon
821- icon = 'phone'
822- className = 'phone-icon'
823- coloring = 'currentColor'
824- // `size` will be overridden in CSS
825- size = { 24 }
822+ < CallIconButton
823+ accountId = { accountId }
824+ chatId = { message . chatId }
825+ messageId = { message . id }
826826 />
827827 ) }
828828 </ div >
@@ -1249,3 +1249,60 @@ function WebxdcMessageContent({
12491249 </ div >
12501250 )
12511251}
1252+
1253+ function CallIconButton ( {
1254+ accountId,
1255+ chatId,
1256+ messageId,
1257+ } : {
1258+ accountId : number
1259+ chatId : number
1260+ messageId : number
1261+ } ) {
1262+ const callInfoFetch = useRpcFetch ( BackendRemote . rpc . callInfo , [
1263+ accountId ,
1264+ messageId ,
1265+ ] )
1266+ const refresh = useEffectEvent ( callInfoFetch . refresh )
1267+ useEffect ( ( ) => {
1268+ return onDCEvent ( accountId , 'MsgsChanged' , event => {
1269+ if ( event . msgId !== messageId ) {
1270+ return
1271+ }
1272+ refresh ( )
1273+ } )
1274+ } , [ accountId , messageId ] )
1275+
1276+ const onClickParams :
1277+ | undefined
1278+ | Parameters < typeof runtime . openIncomingVideoCallWindow > [ 0 ] =
1279+ callInfoFetch . result ?. ok &&
1280+ callInfoFetch . result . value . state . kind === 'Alerting'
1281+ ? {
1282+ accountId,
1283+ chatId,
1284+ callMessageId : messageId ,
1285+ callerWebrtcOffer : callInfoFetch . result . value . sdpOffer ,
1286+ startWithCameraEnabled : callInfoFetch . result . value . hasVideo ,
1287+ }
1288+ : undefined
1289+ // TODO fix: don't open a second window if one is already open
1290+ // for this message (this should be done in the main process).
1291+ const onClick = onClickParams
1292+ ? ( ) => runtime . openIncomingVideoCallWindow ( onClickParams )
1293+ : undefined
1294+
1295+ return (
1296+ < IconButton
1297+ aria-label = '📞'
1298+ onClick = { onClick }
1299+ aria-busy = { callInfoFetch . loading }
1300+ disabled = { onClick == undefined }
1301+ icon = 'phone'
1302+ className = 'phone-icon'
1303+ coloring = 'currentColor'
1304+ // `size` will be overridden in CSS
1305+ size = { 24 }
1306+ />
1307+ )
1308+ }
0 commit comments