From a60cf05f8381bf66922e7eccf9bcae35598c3a37 Mon Sep 17 00:00:00 2001 From: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com> Date: Wed, 3 Jan 2024 11:19:08 -0800 Subject: [PATCH] Fix wrong ringerId in auto-ended remote call --- ts/services/calling.ts | 38 +++++++++++++++++++++++++------- ts/textsecure/MessageReceiver.ts | 5 ++++- ts/types/CallDisposition.ts | 2 ++ ts/util/callDisposition.ts | 28 +++++++++++++++++------ 4 files changed, 57 insertions(+), 16 deletions(-) diff --git a/ts/services/calling.ts b/ts/services/calling.ts index a59433eac6..9c8b643714 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -752,7 +752,8 @@ export class CallingClass { ); const callEvent = getCallEventDetails( callDetails, - localCallEvent + localCallEvent, + 'RingRTC.onLocalDeviceStateChanged' ); drop(updateCallHistoryFromLocalEvent(callEvent, null)); } @@ -1757,12 +1758,16 @@ export class CallingClass { const callDetails = getCallDetailsFromEndedDirectCall( callId.toString(), peerId, - peerId, // Incoming call + remoteUserId, // Incoming call wasVideoCall, envelope.timestamp ); const localCallEvent = LocalCallEvent.Missed; - const callEvent = getCallEventDetails(callDetails, localCallEvent); + const callEvent = getCallEventDetails( + callDetails, + localCallEvent, + 'CallingClass.handleCallingMessage' + ); await updateCallHistoryFromLocalEvent( callEvent, envelope.receivedAtCounter @@ -2016,7 +2021,8 @@ export class CallingClass { }); const callEvent = getCallEventDetails( callDetails, - shouldRing ? LocalCallEvent.Ringing : LocalCallEvent.Started + shouldRing ? LocalCallEvent.Ringing : LocalCallEvent.Started, + 'CallingClass.handleGroupCallRingUpdate' ); await updateCallHistoryFromLocalEvent(callEvent, null); } @@ -2108,7 +2114,11 @@ export class CallingClass { const localCallEvent = LocalCallEvent.Missed; const peerId = getPeerIdFromConversation(conversation.attributes); const callDetails = getCallDetailsFromDirectCall(peerId, call); - const callEvent = getCallEventDetails(callDetails, localCallEvent); + const callEvent = getCallEventDetails( + callDetails, + localCallEvent, + 'CallingClass.handleIncomingCall' + ); await updateCallHistoryFromLocalEvent(callEvent, null); return false; @@ -2161,7 +2171,11 @@ export class CallingClass { ); const localCallEvent = getLocalCallEventFromCallEndedReason(callEndedReason); - const callEvent = getCallEventDetails(callDetails, localCallEvent); + const callEvent = getCallEventDetails( + callDetails, + localCallEvent, + 'CallingClass.handleAutoEndedIncomingCallRequest' + ); await updateCallHistoryFromLocalEvent(callEvent, receivedAtCounter ?? null); } @@ -2191,7 +2205,11 @@ export class CallingClass { if (localCallEvent != null) { const peerId = getPeerIdFromConversation(conversation.attributes); const callDetails = getCallDetailsFromDirectCall(peerId, call); - const callEvent = getCallEventDetails(callDetails, localCallEvent); + const callEvent = getCallEventDetails( + callDetails, + localCallEvent, + 'call.handleStateChanged' + ); await updateCallHistoryFromLocalEvent(callEvent, null); } @@ -2397,7 +2415,11 @@ export class CallingClass { peerId, groupCallMeta ); - const callEvent = getCallEventDetails(callDetails, localCallEvent); + const callEvent = getCallEventDetails( + callDetails, + localCallEvent, + 'CallingClass.updateCallHistoryForGroupCall' + ); await updateCallHistoryFromLocalEvent(callEvent, null); } } diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index a1c3278cf3..756ef63870 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -3450,7 +3450,10 @@ export default class MessageReceiver const { receivedAtCounter } = envelope; - const callEventDetails = getCallEventForProto(callEvent); + const callEventDetails = getCallEventForProto( + callEvent, + 'MessageReceiver.handleCallEvent' + ); const callEventSync = new CallEventSyncEvent( { diff --git a/ts/types/CallDisposition.ts b/ts/types/CallDisposition.ts index 00d7ae666a..ba7be52cd6 100644 --- a/ts/types/CallDisposition.ts +++ b/ts/types/CallDisposition.ts @@ -79,6 +79,7 @@ export type CallDetails = Readonly<{ export type CallEventDetails = CallDetails & Readonly<{ event: CallEvent; + eventSource: string; }>; export type CallHistoryDetails = CallDetails & @@ -145,6 +146,7 @@ export const callDetailsSchema = z.object({ export const callEventDetailsSchema = callDetailsSchema.extend({ event: callEventSchema, + eventSource: z.string(), }) satisfies z.ZodType; export const callHistoryDetailsSchema = callDetailsSchema.extend({ diff --git a/ts/util/callDisposition.ts b/ts/util/callDisposition.ts index 6699a88f1d..c67956cf7a 100644 --- a/ts/util/callDisposition.ts +++ b/ts/util/callDisposition.ts @@ -65,14 +65,25 @@ import type { ConversationModel } from '../models/conversations'; // ----- export function formatCallEvent(callEvent: CallEventDetails): string { - const { callId, peerId, direction, event, type, mode, timestamp } = callEvent; - return `CallEvent (${callId}, ${peerId}, ${mode}, ${event}, ${direction}, ${type}, ${mode}, ${timestamp})`; + const { + callId, + peerId, + direction, + event, + eventSource, + type, + mode, + ringerId, + timestamp, + } = callEvent; + const peerIdLog = mode === CallMode.Group ? `groupv2(${peerId})` : peerId; + return `CallEvent (${callId}, ${peerIdLog}, ${mode}, ${event}, ${direction}, ${type}, ${mode}, ${timestamp}, ${ringerId}, ${eventSource})`; } export function formatCallHistory(callHistory: CallHistoryDetails): string { - const { callId, peerId, direction, status, type, mode, timestamp } = + const { callId, peerId, direction, status, type, mode, timestamp, ringerId } = callHistory; - return `CallHistory (${callId}, ${peerId}, ${mode}, ${status}, ${direction}, ${type}, ${mode}, ${timestamp})`; + return `CallHistory (${callId}, ${peerId}, ${mode}, ${status}, ${direction}, ${type}, ${mode}, ${timestamp}, ${ringerId})`; } export function formatCallHistoryGroup( @@ -162,7 +173,8 @@ export function convertJoinState(joinState: JoinState): GroupCallJoinState { // ---------------------- export function getCallEventForProto( - callEventProto: Proto.SyncMessage.ICallEvent + callEventProto: Proto.SyncMessage.ICallEvent, + eventSource: string ): CallEventDetails { const callEvent = callEventNormalizeSchema.parse(callEventProto); const { callId, peerId, timestamp } = callEvent; @@ -218,6 +230,7 @@ export function getCallEventForProto( direction, timestamp, event, + eventSource, }); } @@ -459,9 +472,10 @@ export function getCallDetailsFromGroupCallMeta( export function getCallEventDetails( callDetails: CallDetails, - event: LocalCallEvent + event: LocalCallEvent, + eventSource: string ): CallEventDetails { - return callEventDetailsSchema.parse({ ...callDetails, event }); + return callEventDetailsSchema.parse({ ...callDetails, event, eventSource }); } // transitions