Update call history timestamps from group call update messages

This commit is contained in:
Jamie Kyle 2023-09-28 13:55:23 -07:00 committed by GitHub
parent 72d1695612
commit 66a4a8690a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 191 additions and 118 deletions

View file

@ -186,7 +186,10 @@ import {
getCallsHistoryForRedux,
loadCallsHistory,
} from './services/callHistoryLoader';
import { getCallIdFromEra } from './util/callDisposition';
import {
getCallIdFromEra,
updateLocalGroupCallHistoryTimestamp,
} from './util/callDisposition';
export function isOverHourIntoPast(timestamp: number): boolean {
return isNumber(timestamp) && isOlderThan(timestamp, HOUR);
@ -2908,16 +2911,29 @@ export async function startApp(): Promise<void> {
): boolean {
if (message.groupCallUpdate) {
if (message.groupV2 && messageDescriptor.type === Message.GROUP) {
const conversationId = messageDescriptor.id;
const callId =
message.groupCallUpdate?.eraId != null
? getCallIdFromEra(message.groupCallUpdate.eraId)
: null;
log.info(
'handleGroupCallUpdateMessage',
message.timestamp,
message.groupCallUpdate?.eraId != null
? getCallIdFromEra(message.groupCallUpdate.eraId)
: null
callId,
conversationId
);
window.reduxActions.calling.peekNotConnectedGroupCall({
conversationId: messageDescriptor.id,
conversationId,
});
if (callId != null) {
drop(
updateLocalGroupCallHistoryTimestamp(
conversationId,
callId,
message.timestamp
)
);
}
return true;
}
log.warn(

View file

@ -59,6 +59,7 @@ import {
callDetailsSchema,
} from '../types/CallDisposition';
import type { ConversationType } from '../state/ducks/conversations';
import type { ConversationModel } from '../models/conversations';
// utils
// -----
@ -781,8 +782,23 @@ async function updateLocalCallHistory(
return null;
}
const updatedCallHistory = await saveCallHistory(
callHistory,
conversation,
receivedAtCounter
);
return updatedCallHistory;
}
);
}
async function saveCallHistory(
callHistory: CallHistoryDetails,
conversation: ConversationModel,
receivedAtCounter: number | null
): Promise<CallHistoryDetails> {
log.info(
'updateLocalCallHistory: Saving call history:',
'saveCallHistory: Saving call history:',
formatCallHistory(callHistory)
);
@ -798,20 +814,19 @@ async function updateLocalCallHistory(
window.reduxActions.callHistory.addCallHistory(callHistory);
}
const prevMessage =
await window.Signal.Data.getCallHistoryMessageByCallId({
const prevMessage = await window.Signal.Data.getCallHistoryMessageByCallId({
conversationId: conversation.id,
callId: callHistory.callId,
});
if (prevMessage != null) {
log.info(
'updateLocalCallHistory: Found previous call history message:',
'saveCallHistory: Found previous call history message:',
prevMessage.id
);
} else {
log.info(
'updateLocalCallHistory: No previous call history message',
'saveCallHistory: No previous call history message',
conversation.id
);
}
@ -866,7 +881,7 @@ async function updateLocalCallHistory(
// We don't want to force save if we're updating an existing message
forceSave: prevMessage == null,
});
log.info('updateLocalCallHistory: Saved call history message:', id);
log.info('saveCallHistory: Saved call history message:', id);
const model = window.MessageController.register(
id,
@ -895,8 +910,6 @@ async function updateLocalCallHistory(
}
return callHistory;
}
);
}
async function updateRemoteCallHistory(
@ -1016,3 +1029,47 @@ export async function clearCallHistoryDataAndSync(): Promise<void> {
log.error('clearCallHistory: Failed to clear call history', error);
}
}
export async function updateLocalGroupCallHistoryTimestamp(
conversationId: string,
callId: string,
timestamp: number
): Promise<CallHistoryDetails | null> {
const conversation = window.ConversationController.get(conversationId);
if (conversation == null) {
return null;
}
const peerId = getPeerIdFromConversation(conversation.attributes);
const prevCallHistory =
(await window.Signal.Data.getCallHistory(callId, peerId)) ?? null;
// We don't have all the details to add new call history here
if (prevCallHistory != null) {
log.info(
'updateLocalGroupCallHistoryTimestamp: Found previous call history:',
formatCallHistory(prevCallHistory)
);
} else {
log.info('updateLocalGroupCallHistoryTimestamp: No previous call history');
return null;
}
if (timestamp >= prevCallHistory.timestamp) {
log.info(
'updateLocalGroupCallHistoryTimestamp: New timestamp is later than existing call history, ignoring'
);
return prevCallHistory;
}
const updatedCallHistory = await saveCallHistory(
{
...prevCallHistory,
timestamp,
},
conversation,
null
);
return updatedCallHistory;
}