Update call history timestamps from group call update messages
This commit is contained in:
parent
72d1695612
commit
66a4a8690a
2 changed files with 191 additions and 118 deletions
|
@ -186,7 +186,10 @@ import {
|
||||||
getCallsHistoryForRedux,
|
getCallsHistoryForRedux,
|
||||||
loadCallsHistory,
|
loadCallsHistory,
|
||||||
} from './services/callHistoryLoader';
|
} from './services/callHistoryLoader';
|
||||||
import { getCallIdFromEra } from './util/callDisposition';
|
import {
|
||||||
|
getCallIdFromEra,
|
||||||
|
updateLocalGroupCallHistoryTimestamp,
|
||||||
|
} from './util/callDisposition';
|
||||||
|
|
||||||
export function isOverHourIntoPast(timestamp: number): boolean {
|
export function isOverHourIntoPast(timestamp: number): boolean {
|
||||||
return isNumber(timestamp) && isOlderThan(timestamp, HOUR);
|
return isNumber(timestamp) && isOlderThan(timestamp, HOUR);
|
||||||
|
@ -2908,16 +2911,29 @@ export async function startApp(): Promise<void> {
|
||||||
): boolean {
|
): boolean {
|
||||||
if (message.groupCallUpdate) {
|
if (message.groupCallUpdate) {
|
||||||
if (message.groupV2 && messageDescriptor.type === Message.GROUP) {
|
if (message.groupV2 && messageDescriptor.type === Message.GROUP) {
|
||||||
|
const conversationId = messageDescriptor.id;
|
||||||
|
const callId =
|
||||||
|
message.groupCallUpdate?.eraId != null
|
||||||
|
? getCallIdFromEra(message.groupCallUpdate.eraId)
|
||||||
|
: null;
|
||||||
log.info(
|
log.info(
|
||||||
'handleGroupCallUpdateMessage',
|
'handleGroupCallUpdateMessage',
|
||||||
message.timestamp,
|
message.timestamp,
|
||||||
message.groupCallUpdate?.eraId != null
|
callId,
|
||||||
? getCallIdFromEra(message.groupCallUpdate.eraId)
|
conversationId
|
||||||
: null
|
|
||||||
);
|
);
|
||||||
window.reduxActions.calling.peekNotConnectedGroupCall({
|
window.reduxActions.calling.peekNotConnectedGroupCall({
|
||||||
conversationId: messageDescriptor.id,
|
conversationId,
|
||||||
});
|
});
|
||||||
|
if (callId != null) {
|
||||||
|
drop(
|
||||||
|
updateLocalGroupCallHistoryTimestamp(
|
||||||
|
conversationId,
|
||||||
|
callId,
|
||||||
|
message.timestamp
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
log.warn(
|
log.warn(
|
||||||
|
|
|
@ -59,6 +59,7 @@ import {
|
||||||
callDetailsSchema,
|
callDetailsSchema,
|
||||||
} from '../types/CallDisposition';
|
} from '../types/CallDisposition';
|
||||||
import type { ConversationType } from '../state/ducks/conversations';
|
import type { ConversationType } from '../state/ducks/conversations';
|
||||||
|
import type { ConversationModel } from '../models/conversations';
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
// -----
|
// -----
|
||||||
|
@ -781,8 +782,23 @@ async function updateLocalCallHistory(
|
||||||
return null;
|
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(
|
log.info(
|
||||||
'updateLocalCallHistory: Saving call history:',
|
'saveCallHistory: Saving call history:',
|
||||||
formatCallHistory(callHistory)
|
formatCallHistory(callHistory)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -798,20 +814,19 @@ async function updateLocalCallHistory(
|
||||||
window.reduxActions.callHistory.addCallHistory(callHistory);
|
window.reduxActions.callHistory.addCallHistory(callHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
const prevMessage =
|
const prevMessage = await window.Signal.Data.getCallHistoryMessageByCallId({
|
||||||
await window.Signal.Data.getCallHistoryMessageByCallId({
|
|
||||||
conversationId: conversation.id,
|
conversationId: conversation.id,
|
||||||
callId: callHistory.callId,
|
callId: callHistory.callId,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (prevMessage != null) {
|
if (prevMessage != null) {
|
||||||
log.info(
|
log.info(
|
||||||
'updateLocalCallHistory: Found previous call history message:',
|
'saveCallHistory: Found previous call history message:',
|
||||||
prevMessage.id
|
prevMessage.id
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
log.info(
|
log.info(
|
||||||
'updateLocalCallHistory: No previous call history message',
|
'saveCallHistory: No previous call history message',
|
||||||
conversation.id
|
conversation.id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -866,7 +881,7 @@ async function updateLocalCallHistory(
|
||||||
// We don't want to force save if we're updating an existing message
|
// We don't want to force save if we're updating an existing message
|
||||||
forceSave: prevMessage == null,
|
forceSave: prevMessage == null,
|
||||||
});
|
});
|
||||||
log.info('updateLocalCallHistory: Saved call history message:', id);
|
log.info('saveCallHistory: Saved call history message:', id);
|
||||||
|
|
||||||
const model = window.MessageController.register(
|
const model = window.MessageController.register(
|
||||||
id,
|
id,
|
||||||
|
@ -895,8 +910,6 @@ async function updateLocalCallHistory(
|
||||||
}
|
}
|
||||||
|
|
||||||
return callHistory;
|
return callHistory;
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateRemoteCallHistory(
|
async function updateRemoteCallHistory(
|
||||||
|
@ -1016,3 +1029,47 @@ export async function clearCallHistoryDataAndSync(): Promise<void> {
|
||||||
log.error('clearCallHistory: Failed to clear call history', error);
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue