diff --git a/ts/data/data.ts b/ts/data/data.ts index d48d8e68c..f27a727ff 100644 --- a/ts/data/data.ts +++ b/ts/data/data.ts @@ -38,6 +38,7 @@ let _shutdownPromise: any = null; export type StorageItem = { id: string; value: any; + timestamp?: number; }; export type IdentityKey = { diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index e3082c801..d395bb6bf 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -632,6 +632,17 @@ export class ConversationModel extends Backbone.Model { if (shouldApprove) { await this.setIsApproved(true); if (hasIncomingMessages) { + // have to manually add approval for local client here as DB conditional approval check in config msg handling will prevent this from running + await this.addSingleOutgoingMessage({ + sent_at: Date.now(), + messageRequestResponse: { + isApproved: 1, + }, + unread: 1, // 1 means unread + expireTimer: 0, + }); + this.updateLastMessage(); + if (!this.didApproveMe()) { await this.setDidApproveMe(true); } diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index d2894f537..ad6f53707 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -54,21 +54,33 @@ async function handleGroupsAndContactsFromConfigMessage( envelope: EnvelopePlus, configMessage: SignalService.ConfigurationMessage ) { - const didWeHandleAConfigurationMessageAlready = - (await getItemById(hasSyncedInitialConfigurationItem))?.value || false; - if (didWeHandleAConfigurationMessageAlready) { + const lastConfigUpdate = await getItemById(hasSyncedInitialConfigurationItem); + const lastConfigTimestamp = lastConfigUpdate?.timestamp; + console.warn({ lastConfigUpdate }); + console.warn({ lastConfigTimestamp }); + const isNewerConfig = lastConfigTimestamp && lastConfigTimestamp < _.toNumber(envelope.timestamp); + + // const didWeHandleAConfigurationMessageAlready = + // (await getItemById(hasSyncedInitialConfigurationItem))?.value || false; + // if (didWeHandleAConfigurationMessageAlready) { + if (isNewerConfig) { window?.log?.info( 'Dropping configuration groups change as we already handled one... Only handling contacts ' ); - if (configMessage.contacts?.length) { - await Promise.all(configMessage.contacts.map(async c => handleContactReceived(c, envelope))); + if (isNewerConfig) { + if (configMessage.contacts?.length) { + await Promise.all( + configMessage.contacts.map(async c => handleContactReceived(c, envelope)) + ); + } + return; } - return; } await createOrUpdateItem({ id: 'hasSyncedInitialConfigurationItem', value: true, + timestamp: _.toNumber(envelope.timestamp), }); const numberClosedGroup = configMessage.closedGroups?.length || 0; @@ -113,7 +125,7 @@ async function handleGroupsAndContactsFromConfigMessage( void joinOpenGroupV2WithUIEvents(currentOpenGroupUrl, false, true); } } - if (configMessage.contacts?.length) { + if (configMessage.contacts?.length && isNewerConfig) { await Promise.all(configMessage.contacts.map(async c => handleContactReceived(c, envelope))); } } @@ -140,11 +152,11 @@ const handleContactReceived = async ( contactConvo.set('active_at', _.toNumber(envelope.timestamp)); } + // checking for existence of field on protobuf if (contactReceived.isApproved === true) { if (!contactConvo.isApproved()) { - // checking for existence of field on protobuf - await contactConvo.setIsApproved(Boolean(contactReceived.isApproved)); // TODO: add message search in convo for pre-existing msgRequestResponse msg only happens once per convo + await contactConvo.setIsApproved(Boolean(contactReceived.isApproved)); await contactConvo.addSingleOutgoingMessage({ sent_at: _.toNumber(envelope.timestamp), messageRequestResponse: {