diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index d47566c98..c5c356c43 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -181,11 +181,6 @@ export class LeftPaneMessageSection extends React.Component { ); } - private handleMessageRequestsClick() { - console.warn('handle msg req clicked'); - this.handleToggleOverlay(SessionClosableOverlayType.MessageRequests); - } - public updateSearch(searchTerm: string) { if (!searchTerm) { window.inboxStore?.dispatch(clearSearch()); @@ -224,6 +219,10 @@ export class LeftPaneMessageSection extends React.Component { ); } + private handleMessageRequestsClick() { + this.handleToggleOverlay(SessionClosableOverlayType.MessageRequests); + } + private renderClosableOverlay() { const { searchTerm, searchResults } = this.props; const { loading, overlay } = this.state; @@ -282,9 +281,8 @@ export class LeftPaneMessageSection extends React.Component { this.handleToggleOverlay(undefined); }} onButtonClick={async () => { + // block all convo requests. Force sync if there were changes. window?.log?.info('Blocking all conversations'); - // TODO: msgrequest iterate all convos and block - // iterate all conversations and set all to approve then const { conversationRequests } = this.props; let syncRequired = false; @@ -293,9 +291,9 @@ export class LeftPaneMessageSection extends React.Component { return; } - _.forEach(conversationRequests, convo => { + _.forEach(conversationRequests, async convo => { if (convo.isApproved !== true) { - BlockedNumberController.block(convo.id); + await BlockedNumberController.block(convo.id); syncRequired = true; } }); diff --git a/ts/components/session/SessionClosableOverlay.tsx b/ts/components/session/SessionClosableOverlay.tsx index c5b532aa1..ad4edeb0e 100644 --- a/ts/components/session/SessionClosableOverlay.tsx +++ b/ts/components/session/SessionClosableOverlay.tsx @@ -199,7 +199,6 @@ export class SessionClosableOverlay extends React.Component { {isMessageRequestView ? ( <> -
@@ -301,7 +300,7 @@ const MessageRequestList = () => { return (
{validConversationRequests.map(conversation => { - return ; + return ; })}
); @@ -309,10 +308,5 @@ const MessageRequestList = () => { const MessageRequestListItem = (props: { conversation: ConversationListItemProps }) => { const { conversation } = props; - return ( - - ); + return ; }; diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index e30ff986e..7fc08d049 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -50,7 +50,7 @@ import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsMana import { IMAGE_JPEG } from '../types/MIME'; import { UnsendMessage } from '../session/messages/outgoing/controlMessage/UnsendMessage'; import { getLatestTimestampOffset, networkDeleteMessages } from '../session/snode_api/SNodeAPI'; -import { syncConfigurationIfNeeded } from '../session/utils/syncUtils'; +import { forceSyncConfigurationNowIfNeeded } from '../session/utils/syncUtils'; export enum ConversationTypeEnum { GROUP = 'group', @@ -738,8 +738,8 @@ export class ConversationModel extends Backbone.Model { const updateApprovalNeeded = !this.isApproved() && (this.isPrivate() || this.isMediumGroup() || this.isClosedGroup()); if (updateApprovalNeeded) { - this.setIsApproved(true); - await syncConfigurationIfNeeded(true); + await this.setIsApproved(true); + await forceSyncConfigurationNowIfNeeded(); } if (this.isOpenGroupV2()) { @@ -1397,13 +1397,15 @@ export class ConversationModel extends Backbone.Model { public async setIsApproved(value: boolean) { if (value !== this.get('isApproved')) { - console.warn(`Setting ${this.attributes.profileName} isApproved to:: ${value}`); + window?.log?.info(`Setting ${this.attributes.profileName} isApproved to:: ${value}`); this.set({ isApproved: value, }); // to exclude the conversation from left pane messages list and message requests - if (value === false) this.set({ active_at: undefined }); + if (value === false) { + this.set({ active_at: undefined }); + } await this.commit(); } diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index 297a8ea79..4a2fb4d67 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -130,7 +130,7 @@ const handleContactReceived = async ( window.inboxStore?.getState().userConfig.messageRequests && contactReceived.isApproved === true ) { - contactConvo.setIsApproved(Boolean(contactReceived.isApproved)); + await contactConvo.setIsApproved(Boolean(contactReceived.isApproved)); if (contactReceived.isBlocked === true) { await BlockedNumberController.block(contactConvo.id); diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 9be31a3a8..ca57e91cd 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -314,8 +314,8 @@ async function handleRegularMessage( if (type === 'outgoing' && window.lokiFeatureFlags.useMessageRequests) { handleSyncedReceipts(message, conversation); - // assumes sync receipts are always from linked device outgoings? - conversation.setIsApproved(true); + // assumes sync receipts are always from linked device outgoings + await conversation.setIsApproved(true); } const conversationActiveAt = conversation.get('active_at'); diff --git a/ts/session/utils/syncUtils.ts b/ts/session/utils/syncUtils.ts index 9c6017bd5..854be417c 100644 --- a/ts/session/utils/syncUtils.ts +++ b/ts/session/utils/syncUtils.ts @@ -38,23 +38,20 @@ const writeLastSyncTimestampToDb = async (timestamp: number) => createOrUpdateItem({ id: ITEM_ID_LAST_SYNC_TIMESTAMP, value: timestamp }); /** - * Syncs usre configuration with other devices linked to this user. - * @param force Bypass duration time limit for sending sync messages - * @returns + * Conditionally Syncs user configuration with other devices linked. */ -export const syncConfigurationIfNeeded = async (force: boolean = false) => { +export const syncConfigurationIfNeeded = async () => { const lastSyncedTimestamp = (await getLastSyncTimestampFromDb()) || 0; const now = Date.now(); // if the last sync was less than 2 days before, return early. - if (!force && Math.abs(now - lastSyncedTimestamp) < DURATION.DAYS * 7) { + if (Math.abs(now - lastSyncedTimestamp) < DURATION.DAYS * 7) { return; } - const allConvos = await (await getAllConversations()).models; + const allConvoCollection = await getAllConversations(); + const allConvos = allConvoCollection.models; - console.warn({ test: allConvos[0].attributes.isApproved }); - // const configMessage = await getCurrentConfigurationMessage(allConvos); const configMessage = await getCurrentConfigurationMessage(allConvos); try { // window?.log?.info('syncConfigurationIfNeeded with', configMessage); @@ -71,7 +68,6 @@ export const syncConfigurationIfNeeded = async (force: boolean = false) => { export const forceSyncConfigurationNowIfNeeded = async (waitForMessageSent = false) => new Promise(async resolve => { - // const allConvos = getConversationController().getConversations(); const allConvos = (await getAllConversations()).models; // if we hang for more than 10sec, force resolve this promise.