Skip to content

Commit

Permalink
No more type passed to removeAllConfiguration; keep more UI keys
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Nov 13, 2023
1 parent 046a3c4 commit d717751
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 52 deletions.
5 changes: 2 additions & 3 deletions ts/SignalProtocolStore.ts
Expand Up @@ -50,7 +50,6 @@ import type {
UnprocessedUpdateType,
CompatPreKeyType,
} from './textsecure/Types.d';
import type { RemoveAllConfiguration } from './types/RemoveAllConfiguration';
import type { ServiceIdString, PniString, AciString } from './types/ServiceId';
import { isServiceIdString, ServiceIdKind } from './types/ServiceId';
import type { Address } from './types/Address';
Expand Down Expand Up @@ -2699,8 +2698,8 @@ export class SignalProtocolStore extends EventEmitter {
this.emit('removeAllData');
}

async removeAllConfiguration(mode: RemoveAllConfiguration): Promise<void> {
await window.Signal.Data.removeAllConfiguration(mode);
async removeAllConfiguration(): Promise<void> {
await window.Signal.Data.removeAllConfiguration();
await this.hydrateCaches();

window.storage.reset();
Expand Down
19 changes: 8 additions & 11 deletions ts/background.ts
Expand Up @@ -137,7 +137,6 @@ import {
} from './util/handleRetry';
import { themeChanged } from './shims/themeChanged';
import { createIPCEvents } from './util/createIPCEvents';
import { RemoveAllConfiguration } from './types/RemoveAllConfiguration';
import type { ServiceIdString } from './types/ServiceId';
import { ServiceIdKind, isServiceIdString } from './types/ServiceId';
import { isAciString } from './util/isAciString';
Expand Down Expand Up @@ -849,7 +848,7 @@ export async function startApp(): Promise<void> {
log.warn(
`This instance has not been used for 30 days. Last heartbeat: ${lastHeartbeat}. Last startup: ${previousLastStartup}.`
);
await unlinkAndDisconnect(RemoveAllConfiguration.Soft);
await unlinkAndDisconnect();
}

// Start heartbeat timer
Expand Down Expand Up @@ -1343,7 +1342,7 @@ export async function startApp(): Promise<void> {
});

window.Whisper.events.on('unlinkAndDisconnect', () => {
void unlinkAndDisconnect(RemoveAllConfiguration.Full);
void unlinkAndDisconnect();
});

async function runStorageService() {
Expand Down Expand Up @@ -1784,7 +1783,7 @@ export async function startApp(): Promise<void> {

if (!window.textsecure.storage.user.getAci()) {
log.error('UUID not captured during registration, unlinking');
return unlinkAndDisconnect(RemoveAllConfiguration.Full);
return unlinkAndDisconnect();
}

if (connectCount === 1) {
Expand All @@ -1804,7 +1803,7 @@ export async function startApp(): Promise<void> {

if (!window.textsecure.storage.user.getPni()) {
log.error('PNI not captured during registration, unlinking softly');
return unlinkAndDisconnect(RemoveAllConfiguration.Soft);
return unlinkAndDisconnect();
}

if (firstRun === true && deviceId !== 1) {
Expand Down Expand Up @@ -2892,9 +2891,7 @@ export async function startApp(): Promise<void> {
return false;
}

async function unlinkAndDisconnect(
mode: RemoveAllConfiguration
): Promise<void> {
async function unlinkAndDisconnect(): Promise<void> {
window.Whisper.events.trigger('unauthorized');

log.warn(
Expand Down Expand Up @@ -2934,7 +2931,7 @@ export async function startApp(): Promise<void> {
);

try {
log.info(`unlinkAndDisconnect: removing configuration, mode ${mode}`);
log.info('unlinkAndDisconnect: removing configuration');

// First, make changes to conversations in memory
window.getConversations().forEach(conversation => {
Expand All @@ -2948,7 +2945,7 @@ export async function startApp(): Promise<void> {
await window.Signal.Data.getItemById('manifestVersion');

// Finally, conversations in the database, and delete all config tables
await window.textsecure.storage.protocol.removeAllConfiguration(mode);
await window.textsecure.storage.protocol.removeAllConfiguration();

// These three bits of data are important to ensure that the app loads up
// the conversation list, instead of showing just the QR code screen.
Expand Down Expand Up @@ -3001,7 +2998,7 @@ export async function startApp(): Promise<void> {
error instanceof HTTPError &&
(error.code === 401 || error.code === 403)
) {
void unlinkAndDisconnect(RemoveAllConfiguration.Full);
void unlinkAndDisconnect();
return;
}

Expand Down
3 changes: 1 addition & 2 deletions ts/sql/Interface.ts
Expand Up @@ -16,7 +16,6 @@ import type { QualifiedAddressStringType } from '../types/QualifiedAddress';
import type { StoryDistributionIdString } from '../types/StoryDistributionId';
import type { AciString, PniString, ServiceIdString } from '../types/ServiceId';
import type { BadgeType } from '../badges/types';
import type { RemoveAllConfiguration } from '../types/RemoveAllConfiguration';
import type { LoggerType } from '../types/Logging';
import type { ReadStatus } from '../messages/MessageReadStatus';
import type { RawBodyRange } from '../types/BodyRange';
Expand Down Expand Up @@ -794,7 +793,7 @@ export type DataInterface = {
countStoryReadsByConversation(conversationId: string): Promise<number>;

removeAll: () => Promise<void>;
removeAllConfiguration: (type?: RemoveAllConfiguration) => Promise<void>;
removeAllConfiguration: () => Promise<void>;
eraseStorageServiceState: () => Promise<void>;

getMessagesNeedingUpgrade: (
Expand Down
34 changes: 10 additions & 24 deletions ts/sql/Server.ts
Expand Up @@ -44,12 +44,10 @@ import { consoleLogger } from '../util/consoleLogger';
import { dropNull } from '../util/dropNull';
import { isNormalNumber } from '../util/isNormalNumber';
import { isNotNil } from '../util/isNotNil';
import { missingCaseError } from '../util/missingCaseError';
import { parseIntOrThrow } from '../util/parseIntOrThrow';
import * as durations from '../util/durations';
import { formatCountForLogging } from '../logging/formatCountForLogging';
import type { ConversationColorType, CustomColorType } from '../types/Colors';
import { RemoveAllConfiguration } from '../types/RemoveAllConfiguration';
import type { BadgeType, BadgeImageType } from '../badges/types';
import { parseBadgeCategory } from '../badges/BadgeCategory';
import { parseBadgeImageTheme } from '../badges/BadgeImageTheme';
Expand Down Expand Up @@ -5682,9 +5680,7 @@ async function removeAll(): Promise<void> {
}

// Anything that isn't user-visible data
async function removeAllConfiguration(
mode = RemoveAllConfiguration.Full
): Promise<void> {
async function removeAllConfiguration(): Promise<void> {
const db = await getWritableInstance();

db.transaction(() => {
Expand All @@ -5704,26 +5700,16 @@ async function removeAllConfiguration(
`
);

if (mode === RemoveAllConfiguration.Full) {
db.exec(
`
DELETE FROM items;
`
);
} else if (mode === RemoveAllConfiguration.Soft) {
const itemIds: ReadonlyArray<string> = db
.prepare<EmptyQuery>('SELECT id FROM items')
.pluck(true)
.all();

const allowedSet = new Set<string>(STORAGE_UI_KEYS);
for (const id of itemIds) {
if (!allowedSet.has(id)) {
removeById(db, 'items', id);
}
const itemIds: ReadonlyArray<string> = db
.prepare<EmptyQuery>('SELECT id FROM items')
.pluck(true)
.all();

const allowedSet = new Set<string>(STORAGE_UI_KEYS);
for (const id of itemIds) {
if (!allowedSet.has(id)) {
removeById(db, 'items', id);
}
} else {
throw missingCaseError(mode);
}

db.exec(
Expand Down
7 changes: 2 additions & 5 deletions ts/textsecure/AccountManager.ts
Expand Up @@ -24,7 +24,6 @@ import ProvisioningCipher from './ProvisioningCipher';
import type { IncomingWebSocketRequest } from './WebsocketResources';
import createTaskWithTimeout from './TaskWithTimeout';
import * as Bytes from '../Bytes';
import { RemoveAllConfiguration } from '../types/RemoveAllConfiguration';
import * as Errors from '../types/errors';
import { senderCertificateService } from '../services/senderCertificate';
import {
Expand Down Expand Up @@ -1043,10 +1042,8 @@ export default class AccountManager extends EventTarget {
);
}
} else {
log.info('createAccount: Erasing configuration (soft)');
await storage.protocol.removeAllConfiguration(
RemoveAllConfiguration.Soft
);
log.info('createAccount: Erasing configuration');
await storage.protocol.removeAllConfiguration();
}

await senderCertificateService.clear();
Expand Down
7 changes: 0 additions & 7 deletions ts/types/RemoveAllConfiguration.ts

This file was deleted.

9 changes: 9 additions & 0 deletions ts/types/StorageUIKeys.ts
Expand Up @@ -11,15 +11,21 @@ export type ThemeSettingType = z.infer<typeof themeSettingSchema>;
export const STORAGE_UI_KEYS: ReadonlyArray<keyof StorageAccessType> = [
'always-relay-calls',
'audio-notification',
'audioMessage',
'auto-download-update',
'badge-count-muted-conversations',
'call-ringtone-notification',
'call-system-notification',
'customColors',
'defaultConversationColor',
'existingOnboardingStoryMessageIds',
'formattingWarningShown',
'hasCompletedSafetyNumberOnboarding',
'hasCompletedUsernameLinkOnboarding',
'hide-menu-bar',
'incoming-call-notification',
'localeOverride',
'navTabsCollapsed',
'notification-draw-attention',
'notification-setting',
'pinnedConversationIds',
Expand All @@ -29,11 +35,14 @@ export const STORAGE_UI_KEYS: ReadonlyArray<keyof StorageAccessType> = [
'preferredLeftPaneWidth',
'preferredReactionEmoji',
'previousAudioDeviceModule',
'sendEditWarningShown',
'sent-media-quality',
'showStickerPickerHint',
'showStickersIntroduction',
'skinTone',
'spell-check',
'system-tray-setting',
'textFormatting',
'theme-setting',
'zoomFactor',
];

0 comments on commit d717751

Please sign in to comment.