fix: make sure existing sogs convo do not break on save

the app was crashing if a convo with an invalid read/write/upload capability was saved during a migration
This commit is contained in:
Audric Ackermann 2022-08-08 17:05:42 +10:00
parent 0ef847c104
commit ef27153c69
3 changed files with 21 additions and 6 deletions

View File

@ -1979,6 +1979,7 @@ function getConversationCount() {
}
// tslint:disable-next-line: max-func-body-length
// tslint:disable-next-line: cyclomatic-complexity
function saveConversation(data: ConversationAttributes, instance?: BetterSqlite3.Database) {
const formatted = assertValidConversationAttributes(data);
@ -2107,9 +2108,9 @@ function saveConversation(data: ConversationAttributes, instance?: BetterSqlite3
groupAdmins: groupAdmins && groupAdmins.length ? arrayStrToJson(groupAdmins) : '[]',
isKickedFromGroup: toSqliteBoolean(isKickedFromGroup),
subscriberCount,
readCapability,
writeCapability,
uploadCapability,
readCapability: toSqliteBoolean(readCapability),
writeCapability: toSqliteBoolean(writeCapability),
uploadCapability: toSqliteBoolean(uploadCapability),
is_medium_group: toSqliteBoolean(is_medium_group),
avatarPointer,

View File

@ -34,6 +34,9 @@ export type OpenGroupMessageV4 = {
const pollForEverythingInterval = DURATION.SECONDS * 10;
export const invalidAuthRequiresBlinding =
'Invalid authentication: this server requires the use of blinded ids';
/**
* An OpenGroupServerPollerV2 polls for everything for a particular server. We should
* have only have one OpenGroupServerPollerV2 per opengroup polling.
@ -295,9 +298,7 @@ export class OpenGroupServerPoller {
) {
const bodyPlainText = (batchPollResults.body as any).plainText;
// this is temporary (as of 27/06/2022) as we want to not support unblinded sogs after some time
if (
bodyPlainText === 'Invalid authentication: this server requires the use of blinded ids'
) {
if (bodyPlainText === invalidAuthRequiresBlinding) {
await fetchCapabilitiesAndUpdateRelatedRoomsOfServerUrl(this.serverUrl);
throw new Error('batchPollResults just detected switch to blinded enforced.');
}

View File

@ -21,6 +21,7 @@ import {
import { AbortSignal } from 'abort-controller';
import { pnServerPubkeyHex, pnServerUrl } from '../apis/push_notification_api/PnServer';
import { fileServerPubKey, fileServerURL } from '../apis/file_server_api/FileServerApi';
import { invalidAuthRequiresBlinding } from '../apis/open_group_api/opengroupV2/OpenGroupServerPoller';
export type OnionFetchOptions = {
method: string;
@ -162,6 +163,18 @@ const sendViaOnionV4ToNonSnodeWithRetries = async (
// the pn server replies with the decodedV4?.metadata as any)?.code syntax too since onion v4
const foundStatusCode = decodedV4?.metadata?.code || STATUS_NO_STATUS;
if (foundStatusCode < 200 || foundStatusCode > 299) {
// this is temporary (as of 27/06/2022) as we want to not support unblinded sogs after some time
if (
foundStatusCode === 400 &&
(decodedV4?.body as any).plainText === invalidAuthRequiresBlinding
) {
return {
status_code: foundStatusCode,
body: decodedV4?.body || null,
bodyBinary: decodedV4?.bodyBinary || null,
};
}
// we consider those cases as an error, and trigger a retry (if possible), by throwing a non-abortable error
throw new Error(
`sendViaOnionV4ToNonSnodeWithRetries failed with status code: ${foundStatusCode}. Retrying...`