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
pull/2403/head
Audric Ackermann 3 years ago
parent 0ef847c104
commit ef27153c69

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

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

@ -21,6 +21,7 @@ import {
import { AbortSignal } from 'abort-controller'; import { AbortSignal } from 'abort-controller';
import { pnServerPubkeyHex, pnServerUrl } from '../apis/push_notification_api/PnServer'; import { pnServerPubkeyHex, pnServerUrl } from '../apis/push_notification_api/PnServer';
import { fileServerPubKey, fileServerURL } from '../apis/file_server_api/FileServerApi'; import { fileServerPubKey, fileServerURL } from '../apis/file_server_api/FileServerApi';
import { invalidAuthRequiresBlinding } from '../apis/open_group_api/opengroupV2/OpenGroupServerPoller';
export type OnionFetchOptions = { export type OnionFetchOptions = {
method: string; 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 // the pn server replies with the decodedV4?.metadata as any)?.code syntax too since onion v4
const foundStatusCode = decodedV4?.metadata?.code || STATUS_NO_STATUS; const foundStatusCode = decodedV4?.metadata?.code || STATUS_NO_STATUS;
if (foundStatusCode < 200 || foundStatusCode > 299) { 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 // we consider those cases as an error, and trigger a retry (if possible), by throwing a non-abortable error
throw new Error( throw new Error(
`sendViaOnionV4ToNonSnodeWithRetries failed with status code: ${foundStatusCode}. Retrying...` `sendViaOnionV4ToNonSnodeWithRetries failed with status code: ${foundStatusCode}. Retrying...`

Loading…
Cancel
Save