diff --git a/ts/background.ts b/ts/background.ts index f63f4464eb98..9bdf4775822f 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -2361,10 +2361,13 @@ export async function startApp(): Promise { const { data, confirm } = event; const messageDescriptor = getMessageDescriptor({ - message: data.message, // 'message' event: for 1:1 converations, the conversation is same as sender destination: data.source, destinationServiceId: data.sourceAci, + envelopeId: data.envelopeId, + message: data.message, + source: data.sourceAci ?? data.source, + sourceDevice: data.sourceDevice, }); const { PROFILE_KEY_UPDATE } = Proto.DataMessage.Flags; @@ -2706,18 +2709,26 @@ export async function startApp(): Promise { // Works with 'sent' and 'message' data sent from MessageReceiver const getMessageDescriptor = ({ - message, destination, destinationServiceId, + envelopeId, + message, + source, + sourceDevice, }: { - message: ProcessedDataMessage; destination?: string; destinationServiceId?: ServiceIdString; + envelopeId: string; + message: ProcessedDataMessage; + source: string | undefined; + sourceDevice: number | undefined; }): MessageDescriptor => { + const logId = `getMessageDescriptor/${source}.${sourceDevice}-${envelopeId}`; + if (message.groupV2) { const { id } = message.groupV2; if (!id) { - throw new Error('getMessageDescriptor: GroupV2 data was missing an id'); + throw new Error(`${logId}: GroupV2 data was missing an id`); } // First we check for an existing GroupV2 group @@ -2752,10 +2763,15 @@ export async function startApp(): Promise { }; } - const conversation = window.ConversationController.get( - destinationServiceId || destination + const id = destinationServiceId || destination; + strictAssert( + id, + `${logId}: We need some sort of destination for the conversation` + ); + const conversation = window.ConversationController.getOrCreate( + id, + 'private' ); - strictAssert(conversation, 'Destination conversation cannot be created'); return { type: Message.PRIVATE, @@ -2797,6 +2813,8 @@ export async function startApp(): Promise { const messageDescriptor = getMessageDescriptor({ ...data, + source: sourceServiceId, + sourceDevice: data.device, }); const { PROFILE_KEY_UPDATE } = Proto.DataMessage.Flags; diff --git a/ts/services/calling.ts b/ts/services/calling.ts index da1440f265a4..91c098e15bc8 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -885,50 +885,61 @@ export class CallingClass { hasLocalAudio: boolean, hasLocalVideo: boolean ): Promise { - log.info('CallingClass.startOutgoingDirectCall()'); + const logId = 'CallingClass.startOutgoingDirectCall'; + log.info(logId); if (!this.reduxInterface) { - throw new Error('Redux actions not available'); + throw new Error(`${logId}: Redux actions not available`); } const conversation = window.ConversationController.get(conversationId); if (!conversation) { - log.error('Could not find conversation, cannot start call'); + log.error(`${logId}: Could not find conversation, cannot start call`); this.stopCallingLobby(); return; } const remoteUserId = this.getRemoteUserIdFromConversation(conversation); if (!remoteUserId || !this.localDeviceId) { - log.error('Missing identifier, new call not allowed.'); + log.error(`${logId}: Missing identifier, new call not allowed.`); this.stopCallingLobby(); return; } const haveMediaPermissions = await this.requestPermissions(hasLocalVideo); if (!haveMediaPermissions) { - log.info('Permissions were denied, new call not allowed.'); + log.info(`${logId}: Permissions were denied, new call not allowed.`); this.stopCallingLobby(); return; } - log.info('CallingClass.startOutgoingDirectCall(): Getting call settings'); - + log.info(`${logId}: Getting call settings`); // Check state after awaiting to debounce call button. if (RingRTC.call && RingRTC.call.state !== CallState.Ended) { - log.info('Call already in progress, new call not allowed.'); + log.info(`${logId}: Call already in progress, new call not allowed.`); this.stopCallingLobby(); return; } - log.info('CallingClass.startOutgoingDirectCall(): Starting in RingRTC'); - + log.info(`${logId}: Starting in RingRTC`); const call = RingRTC.startOutgoingCall( remoteUserId, hasLocalVideo, this.localDeviceId ); + // Send profile key to conversation recipient since call protos don't include it + if (!conversation.get('profileSharing')) { + log.info(`${logId}: Setting profileSharing=true`); + conversation.set({ profileSharing: true }); + await DataWriter.updateConversation(conversation.attributes); + } + log.info(`${logId}: Sending profile key`); + await conversationJobQueue.add({ + conversationId: conversation.id, + type: 'ProfileKey', + }); + RingRTC.setOutgoingAudio(call.callId, hasLocalAudio); RingRTC.setVideoCapturer(call.callId, this.videoCapturer); RingRTC.setVideoRenderer(call.callId, this.videoRenderer);