Add more timestamp fallbacks for call migration

This commit is contained in:
Jamie Kyle 2023-08-29 16:31:45 -07:00 committed by GitHub
parent bc74a696f4
commit eae9e570fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 104 additions and 10 deletions

View file

@ -37,7 +37,7 @@ type GroupCallHistoryDetailsType = {
callMode: CallMode.Group;
creatorUuid: string;
eraId: string;
startedTime: number;
startedTime?: number; // Treat this as optional, some calls may be missing it
};
export type CallHistoryDetailsType =
| DirectCallHistoryDetailsType
@ -113,7 +113,8 @@ function convertLegacyCallDetails(
ourUuid: string | undefined,
peerId: string,
message: MessageType,
partialDetails: CallHistoryDetailsFromDiskType
partialDetails: CallHistoryDetailsFromDiskType,
logger: LoggerType
): CallHistoryDetails {
const details = upcastCallHistoryDetailsFromDiskType(partialDetails);
const { callMode: mode } = details;
@ -127,6 +128,10 @@ function convertLegacyCallDetails(
strictAssert(mode != null, 'mode must exist');
// If we cannot find any timestamp on the message, we'll use 0
const fallbackTimestamp =
message.timestamp ?? message.sent_at ?? message.received_at_ms ?? 0;
if (mode === CallMode.Direct) {
// We don't have a callId for older calls, generating a uuid instead
callId = details.callId ?? generateUuid();
@ -141,7 +146,7 @@ function convertLegacyCallDetails(
? DirectCallStatus.Declined
: DirectCallStatus.Missed;
}
timestamp = details.acceptedTime ?? details.endedTime ?? message.timestamp;
timestamp = details.acceptedTime ?? details.endedTime ?? fallbackTimestamp;
} else if (mode === CallMode.Group) {
callId = Long.fromValue(callIdFromEra(details.eraId)).toString();
type = CallType.Group;
@ -150,7 +155,7 @@ function convertLegacyCallDetails(
? CallDirection.Outgoing
: CallDirection.Incoming;
status = GroupCallStatus.GenericGroupCall;
timestamp = details.startedTime;
timestamp = details.startedTime ?? fallbackTimestamp;
ringerId = details.creatorUuid;
} else {
throw missingCaseError(mode);
@ -167,7 +172,16 @@ function convertLegacyCallDetails(
timestamp,
};
return callHistoryDetailsSchema.parse(callHistory);
const result = callHistoryDetailsSchema.safeParse(callHistory);
if (result.success) {
return result.data;
}
logger.error(
`convertLegacyCallDetails: Could not convert ${mode} call`,
result.error.toString()
);
throw new Error(`Failed to convert legacy ${mode} call details`);
}
export default function updateToSchemaVersion89(
@ -265,7 +279,8 @@ export default function updateToSchemaVersion89(
ourUuid,
peerId,
message,
details
details,
logger
);
const [insertQuery, insertParams] = sql`