diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 778101ecabc..94a0ab114be 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -1763,6 +1763,11 @@ export class ConversationModel extends window.Backbone.Model< return false; } + const hasNoMessages = (this.get('messageCount') || 0) === 0; + if (hasNoMessages) { + return false; + } + return !this.get('profileSharing'); } diff --git a/ts/services/storage.ts b/ts/services/storage.ts index ab90367131a..d4afa505814 100644 --- a/ts/services/storage.ts +++ b/ts/services/storage.ts @@ -1,4 +1,4 @@ -import _ from 'lodash'; +import { debounce, isNumber, partition } from 'lodash'; import pMap from 'p-map'; import Crypto from '../textsecure/Crypto'; @@ -753,7 +753,7 @@ async function processManifest( // Merge Account records last const sortedStorageItems = ([] as Array).concat( - ..._.partition( + ...partition( decryptedStorageItems, storageRecord => storageRecord.storageRecord.account === undefined ) @@ -897,7 +897,14 @@ async function sync(): Promise { window.log.info('storageService.sync: starting...'); try { - const localManifestVersion = window.storage.get('manifestVersion') || 0; + // If we've previously interacted with strage service, update 'fetchComplete' record + const previousFetchComplete = window.storage.get('storageFetchComplete'); + const manifestFromStorage = window.storage.get('manifestVersion'); + if (!previousFetchComplete && isNumber(manifestFromStorage)) { + window.storage.put('storageFetchComplete', true); + } + + const localManifestVersion = manifestFromStorage || 0; const manifest = await fetchManifest(localManifestVersion); // Guarding against no manifests being returned, everything should be ok @@ -918,6 +925,9 @@ async function sync(): Promise { if (hasConflicts) { await upload(); } + + // We now know that we've successfully completed a storage service fetch + window.storage.put('storageFetchComplete', true); } catch (err) { window.log.error( 'storageService.sync: error processing manifest', @@ -1013,7 +1023,7 @@ export async function eraseAllStorageServiceState(): Promise { window.log.info('storageService.eraseAllStorageServiceState: complete'); } -export const storageServiceUploadJob = _.debounce(() => { +export const storageServiceUploadJob = debounce(() => { if (!storageServiceEnabled) { window.log.info( 'storageService.storageServiceUploadJob: called before enabled' @@ -1024,7 +1034,7 @@ export const storageServiceUploadJob = _.debounce(() => { storageJobQueue(upload, `upload v${window.storage.get('manifestVersion')}`); }, 500); -export const runStorageServiceSyncJob = _.debounce(() => { +export const runStorageServiceSyncJob = debounce(() => { if (!storageServiceEnabled) { window.log.info( 'storageService.runStorageServiceSyncJob: called before enabled' diff --git a/ts/services/storageRecordOps.ts b/ts/services/storageRecordOps.ts index 6489d2f36ec..91dca083dcf 100644 --- a/ts/services/storageRecordOps.ts +++ b/ts/services/storageRecordOps.ts @@ -462,7 +462,7 @@ export async function mergeGroupV2Record( updateConversation(conversation.attributes); const isGroupNewToUs = !isNumber(conversation.get('revision')); - const isFirstSync = !isNumber(window.storage.get('manifestVersion')); + const isFirstSync = !window.storage.get('storageFetchComplete'); const dropInitialJoinMessage = isFirstSync; // We don't need to update GroupV2 groups all the time. We fetch group state the first diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index f33ce73dc15..9274bfb0e5a 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -2840,6 +2840,13 @@ Whisper.ConversationView = Whisper.View.extend({ return; } + const mandatoryProfileSharingEnabled = window.Signal.RemoteConfig.isEnabled( + 'desktop.mandatoryProfileSharing' + ); + if (mandatoryProfileSharingEnabled && !this.model.get('profileSharing')) { + this.model.set({ profileSharing: true }); + } + const { packId, stickerId } = options; this.model.sendStickerMessage(packId, stickerId); } catch (error) { @@ -3035,6 +3042,13 @@ Whisper.ConversationView = Whisper.View.extend({ return; } + const mandatoryProfileSharingEnabled = window.Signal.RemoteConfig.isEnabled( + 'desktop.mandatoryProfileSharing' + ); + if (mandatoryProfileSharingEnabled && !this.model.get('profileSharing')) { + this.model.set({ profileSharing: true }); + } + const attachments = await this.getFiles(); const sendDelta = Date.now() - this.sendStart; window.log.info('Send pre-checks took', sendDelta, 'milliseconds');