From 06f71a7ef8da8597eda6d82a7af0d1b10f9a979d Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 28 May 2024 15:13:09 +1000 Subject: [PATCH] Ensure left pane has correct timestamp for call --- ts/models/conversations.ts | 7 ++++ ts/services/calling.ts | 23 +++++++----- ts/textsecure/MessageReceiver.ts | 3 +- ts/textsecure/messageReceiverEvents.ts | 1 + ts/util/callDisposition.ts | 49 ++++++++++++++++---------- ts/util/onCallEventSync.ts | 8 +++-- 6 files changed, 62 insertions(+), 29 deletions(-) diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 5858d707285..de9f33920c6 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -165,6 +165,7 @@ import OS from '../util/os/osMain'; import { getMessageAuthorText } from '../util/getMessageAuthorText'; import { downscaleOutgoingAttachment } from '../util/attachments'; import { MessageRequestResponseEvent } from '../types/MessageRequestResponseEvent'; +import { getCallHistorySelector } from '../state/selectors/callHistory'; /* eslint-disable more/no-then */ window.Whisper = window.Whisper || {}; @@ -4190,7 +4191,13 @@ export class ConversationModel extends window.Backbone let lastMessageReceivedAt = this.get('lastMessageReceivedAt'); let lastMessageReceivedAtMs = this.get('lastMessageReceivedAtMs'); if (activityMessage) { + const callId = activityMessage.get('callId'); + const callHistory = callId + ? getCallHistorySelector(window.reduxStore.getState())(callId) + : undefined; + timestamp = + callHistory?.timestamp || activityMessage.get('editMessageTimestamp') || activityMessage.get('sent_at') || timestamp; diff --git a/ts/services/calling.ts b/ts/services/calling.ts index 451dc8cf550..74d0f6969e4 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -2216,7 +2216,8 @@ export class CallingClass { ); await updateCallHistoryFromLocalEvent( callEvent, - envelope.receivedAtCounter + envelope.receivedAtCounter, + envelope.receivedAtDate ); return; @@ -2500,7 +2501,7 @@ export class CallingClass { localEventForCall, 'CallingClass.handleGroupCallRingUpdate' ); - await updateCallHistoryFromLocalEvent(callEvent, null); + await updateCallHistoryFromLocalEvent(callEvent, null, null); } } @@ -2588,7 +2589,7 @@ export class CallingClass { localCallEvent, 'CallingClass.handleIncomingCall' ); - await updateCallHistoryFromLocalEvent(callEvent, null); + await updateCallHistoryFromLocalEvent(callEvent, null, null); return false; } @@ -2613,7 +2614,9 @@ export class CallingClass { callEndedReason: CallEndedReason, ageInSeconds: number, wasVideoCall: boolean, - receivedAtCounter: number | undefined + receivedAtCounter: number | undefined, + // TODO: DESKTOP-7145 + receivedAtMS: number | undefined = undefined ) { const conversation = window.ConversationController.get(remoteUserId); if (!conversation) { @@ -2645,7 +2648,11 @@ export class CallingClass { localCallEvent, 'CallingClass.handleAutoEndedIncomingCallRequest' ); - await updateCallHistoryFromLocalEvent(callEvent, receivedAtCounter ?? null); + await updateCallHistoryFromLocalEvent( + callEvent, + receivedAtCounter ?? null, + receivedAtMS ?? null + ); } private attachToCall(conversation: ConversationModel, call: Call): void { @@ -2679,7 +2686,7 @@ export class CallingClass { localCallEvent, 'call.handleStateChanged' ); - await updateCallHistoryFromLocalEvent(callEvent, null); + await updateCallHistoryFromLocalEvent(callEvent, null, null); } reduxInterface.callStateChange({ @@ -2966,7 +2973,7 @@ export class CallingClass { localCallEvent, 'CallingClass.updateCallHistoryForGroupCallOnLocalChanged' ); - await updateCallHistoryFromLocalEvent(callEvent, null); + await updateCallHistoryFromLocalEvent(callEvent, null, null); } catch (error) { log.error( 'CallingClass.updateCallHistoryForGroupCallOnLocalChanged: Error updating state', @@ -3022,7 +3029,7 @@ export class CallingClass { localCallEvent, 'CallingClass.updateCallHistoryForGroupCallOnPeek' ); - await updateCallHistoryFromLocalEvent(callEvent, null); + await updateCallHistoryFromLocalEvent(callEvent, null, null); } } diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index e3cb5333827..d9cf0981d0c 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -3501,7 +3501,7 @@ export default class MessageReceiver logUnexpectedUrgentValue(envelope, 'callEventSync'); - const { receivedAtCounter } = envelope; + const { receivedAtCounter, receivedAtDate: receivedAtMS } = envelope; const callEventDetails = getCallEventForProto( callEvent, @@ -3512,6 +3512,7 @@ export default class MessageReceiver { callEventDetails, receivedAtCounter, + receivedAtMS, }, this.removeFromCache.bind(this, envelope) ); diff --git a/ts/textsecure/messageReceiverEvents.ts b/ts/textsecure/messageReceiverEvents.ts index 653005b63ea..dbfec138515 100644 --- a/ts/textsecure/messageReceiverEvents.ts +++ b/ts/textsecure/messageReceiverEvents.ts @@ -429,6 +429,7 @@ export class ViewSyncEvent extends ConfirmableEvent { export type CallEventSyncEventData = Readonly<{ callEventDetails: CallEventDetails; receivedAtCounter: number; + receivedAtMS: number; }>; export class CallEventSyncEvent extends ConfirmableEvent { diff --git a/ts/util/callDisposition.ts b/ts/util/callDisposition.ts index 7e5f4f14266..75ca52f872e 100644 --- a/ts/util/callDisposition.ts +++ b/ts/util/callDisposition.ts @@ -848,7 +848,8 @@ function transitionAdhocCallStatus( async function updateLocalCallHistory( callEvent: CallEventDetails, - receivedAtCounter: number | null + receivedAtCounter: number | null, + receivedAtMS: number | null ): Promise { const conversation = window.ConversationController.get(callEvent.peerId); strictAssert( @@ -892,11 +893,12 @@ async function updateLocalCallHistory( return null; } - const updatedCallHistory = await saveCallHistory( + const updatedCallHistory = await saveCallHistory({ callHistory, conversation, - receivedAtCounter - ); + receivedAtCounter, + receivedAtMS, + }); return updatedCallHistory; } ); @@ -977,11 +979,17 @@ export async function updateLocalAdhocCallHistory( return callHistory; } -async function saveCallHistory( - callHistory: CallHistoryDetails, - conversation: ConversationModel, - receivedAtCounter: number | null -): Promise { +async function saveCallHistory({ + callHistory, + conversation, + receivedAtCounter, + receivedAtMS, +}: { + callHistory: CallHistoryDetails; + conversation: ConversationModel; + receivedAtCounter: number | null; + receivedAtMS: number | null; +}): Promise { log.info( 'saveCallHistory: Saving call history:', formatCallHistory(callHistory) @@ -1052,7 +1060,8 @@ async function saveCallHistory( prevMessage?.received_at ?? receivedAtCounter ?? incrementMessageCounter(), - received_at_ms: prevMessage?.received_at_ms ?? callHistory.timestamp, + received_at_ms: + prevMessage?.received_at_ms ?? receivedAtMS ?? callHistory.timestamp, readStatus: ReadStatus.Read, seenStatus, callId: callHistory.callId, @@ -1153,10 +1162,11 @@ async function updateRemoteCallHistory( export async function updateCallHistoryFromRemoteEvent( callEvent: CallEventDetails, - receivedAtCounter: number + receivedAtCounter: number, + receivedAtMS: number ): Promise { if (callEvent.mode === CallMode.Direct || callEvent.mode === CallMode.Group) { - await updateLocalCallHistory(callEvent, receivedAtCounter); + await updateLocalCallHistory(callEvent, receivedAtCounter, receivedAtMS); } else if (callEvent.mode === CallMode.Adhoc) { await updateLocalAdhocCallHistory(callEvent); } @@ -1164,11 +1174,13 @@ export async function updateCallHistoryFromRemoteEvent( export async function updateCallHistoryFromLocalEvent( callEvent: CallEventDetails, - receivedAtCounter: number | null + receivedAtCounter: number | null, + receivedAtMS: number | null ): Promise { const updatedCallHistory = await updateLocalCallHistory( callEvent, - receivedAtCounter + receivedAtCounter, + receivedAtMS ); if (updatedCallHistory == null) { return; @@ -1303,14 +1315,15 @@ export async function updateLocalGroupCallHistoryTimestamp( return prevCallHistory; } - const updatedCallHistory = await saveCallHistory( - { + const updatedCallHistory = await saveCallHistory({ + callHistory: { ...prevCallHistory, timestamp, }, conversation, - null - ); + receivedAtCounter: null, + receivedAtMS: null, + }); return updatedCallHistory; } diff --git a/ts/util/onCallEventSync.ts b/ts/util/onCallEventSync.ts index 8271a2b6055..db47af3f632 100644 --- a/ts/util/onCallEventSync.ts +++ b/ts/util/onCallEventSync.ts @@ -13,7 +13,7 @@ export async function onCallEventSync( syncEvent: CallEventSyncEvent ): Promise { const { callEvent, confirm } = syncEvent; - const { callEventDetails, receivedAtCounter } = callEvent; + const { callEventDetails, receivedAtCounter, receivedAtMS } = callEvent; if ( callEventDetails.mode === CallMode.Direct || @@ -31,6 +31,10 @@ export async function onCallEventSync( } } - await updateCallHistoryFromRemoteEvent(callEventDetails, receivedAtCounter); + await updateCallHistoryFromRemoteEvent( + callEventDetails, + receivedAtCounter, + receivedAtMS + ); confirm(); }