From 95bee1c881be0c390b234eedcf09d7ae9e647cfb Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Fri, 7 Oct 2022 17:19:02 -0700 Subject: [PATCH] Sync group stories through storage service --- protos/SignalStorage.proto | 24 ++- ts/background.ts | 13 +- ts/components/SendStoryModal.tsx | 2 +- ts/groups.ts | 3 +- ts/model-types.d.ts | 3 +- ts/models/conversations.ts | 16 +- ts/services/storage.ts | 319 ++++++++++++++++++---------- ts/services/storageRecordOps.ts | 32 ++- ts/signal.ts | 14 +- ts/state/ducks/conversations.ts | 12 +- ts/state/selectors/conversations.ts | 33 ++- ts/types/StorageService.d.ts | 3 + ts/types/Stories.ts | 6 + ts/util/isGroupInStoryMode.ts | 23 ++ ts/window.d.ts | 9 +- 15 files changed, 355 insertions(+), 157 deletions(-) create mode 100644 ts/util/isGroupInStoryMode.ts diff --git a/protos/SignalStorage.proto b/protos/SignalStorage.proto index b5b9c5fb9f2..3dbe6b4c6a8 100644 --- a/protos/SignalStorage.proto +++ b/protos/SignalStorage.proto @@ -101,14 +101,22 @@ message GroupV1Record { } message GroupV2Record { - optional bytes masterKey = 1; - optional bool blocked = 2; - optional bool whitelisted = 3; - optional bool archived = 4; - optional bool markedUnread = 5; - optional uint64 mutedUntilTimestamp = 6; - optional bool dontNotifyForMentionsIfMuted = 7; - optional bool hideStory = 8; + enum StorySendMode { + DEFAULT = 0; + DISABLED = 1; + ENABLED = 2; + } + + optional bytes masterKey = 1; + optional bool blocked = 2; + optional bool whitelisted = 3; + optional bool archived = 4; + optional bool markedUnread = 5; + optional uint64 mutedUntilTimestamp = 6; + optional bool dontNotifyForMentionsIfMuted = 7; + optional bool hideStory = 8; + reserved /* storySendEnabled */ 9; // removed + optional StorySendMode storySendMode = 10; } message AccountRecord { diff --git a/ts/background.ts b/ts/background.ts index c3eb99378da..c68a740a441 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -51,6 +51,7 @@ import { import { senderCertificateService } from './services/senderCertificate'; import { GROUP_CREDENTIALS_KEY } from './services/groupCredentialFetcher'; import * as KeyboardLayout from './services/keyboardLayout'; +import * as StorageService from './services/storage'; import { RoutineProfileRefresher } from './routineProfileRefresh'; import { isMoreRecentThan, isOlderThan, toDayMillis } from './util/timestamp'; import { isValidReactionEmoji } from './reactions/isValidReactionEmoji'; @@ -786,7 +787,7 @@ export async function startApp(): Promise { window.isBeforeVersion(lastVersion, 'v1.36.0-beta.1') && window.isAfterVersion(lastVersion, 'v1.35.0-beta.1') ) { - await window.Signal.Services.eraseAllStorageServiceState(); + await StorageService.eraseAllStorageServiceState(); } if (window.isBeforeVersion(lastVersion, 'v5.2.0')) { @@ -846,6 +847,8 @@ export async function startApp(): Promise { // Don't block on the following operation window.Signal.Data.ensureFilePermissions(); + + StorageService.reprocessUnknownFields(); } try { @@ -1737,7 +1740,7 @@ export async function startApp(): Promise { }); async function runStorageService() { - window.Signal.Services.enableStorageService(); + StorageService.enableStorageService(); if (window.ConversationController.areWePrimaryDevice()) { log.warn( @@ -3548,7 +3551,7 @@ export async function startApp(): Promise { } case FETCH_LATEST_ENUM.STORAGE_MANIFEST: log.info('onFetchLatestSync: fetching latest manifest'); - await window.Signal.Services.runStorageServiceSyncJob(); + await StorageService.runStorageServiceSyncJob(); break; case FETCH_LATEST_ENUM.SUBSCRIPTION_STATUS: log.info('onFetchLatestSync: fetching latest subscription status'); @@ -3582,12 +3585,12 @@ export async function startApp(): Promise { 'onKeysSync: updated storage service key, erasing state and fetching' ); await window.storage.put('storageKey', storageServiceKeyBase64); - await window.Signal.Services.eraseAllStorageServiceState({ + await StorageService.eraseAllStorageServiceState({ keepUnknownFields: true, }); } - await window.Signal.Services.runStorageServiceSyncJob(); + await StorageService.runStorageServiceSyncJob(); } } diff --git a/ts/components/SendStoryModal.tsx b/ts/components/SendStoryModal.tsx index 66a5ed7198d..07b14dd5f16 100644 --- a/ts/components/SendStoryModal.tsx +++ b/ts/components/SendStoryModal.tsx @@ -444,7 +444,7 @@ export const SendStoryModal = ({ <>
{selectedNames}