mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-02-15 07:28:59 +00:00
Fix db error from concurrent processing of call link update sync
This commit is contained in:
@@ -121,6 +121,41 @@ export function insertCallLink(db: WritableDB, callLink: CallLinkType): void {
|
||||
_insertCallLink(db, callLink);
|
||||
}
|
||||
|
||||
export type InsertOrUpdateCallLinkFromSyncResult = Readonly<{
|
||||
callLink: CallLinkType;
|
||||
inserted: boolean;
|
||||
updated: boolean;
|
||||
}>;
|
||||
|
||||
export function insertOrUpdateCallLinkFromSync(
|
||||
db: WritableDB,
|
||||
callLink: CallLinkType
|
||||
): InsertOrUpdateCallLinkFromSyncResult {
|
||||
const { roomId, adminKey } = callLink;
|
||||
return db.transaction(() => {
|
||||
const existingCallLink = getCallLinkByRoomId(db, roomId);
|
||||
if (existingCallLink) {
|
||||
if (adminKey && adminKey !== existingCallLink.adminKey) {
|
||||
updateCallLinkAdminKeyByRoomId(db, roomId, adminKey);
|
||||
return {
|
||||
callLink: { ...existingCallLink, adminKey },
|
||||
inserted: false,
|
||||
updated: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
callLink: existingCallLink,
|
||||
inserted: false,
|
||||
updated: false,
|
||||
};
|
||||
}
|
||||
|
||||
insertCallLink(db, callLink);
|
||||
return { callLink, inserted: true, updated: false };
|
||||
})();
|
||||
}
|
||||
|
||||
export function updateCallLink(db: WritableDB, callLink: CallLinkType): void {
|
||||
const { roomId, rootKey } = callLink;
|
||||
assertRoomIdMatchesRootKey(roomId, rootKey);
|
||||
|
||||
Reference in New Issue
Block a user