diff --git a/preload.js b/preload.js index 9cf51698a..aab289d73 100644 --- a/preload.js +++ b/preload.js @@ -51,7 +51,7 @@ window.lokiFeatureFlags = { padOutgoingAttachments: true, enablePinConversations: true, useUnsendRequests: false, - useMessageRequests: false, + useMessageRequests: true, }; window.isBeforeVersion = (toCheck, baseVersion) => { diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index c90ab435b..b78208892 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -84,10 +84,6 @@ export class LeftPaneMessageSection extends React.Component { throw new Error('renderRow: Tried to render without conversations'); } - const messageRequestsEnabled = - window.inboxStore?.getState().userConfig.messageRequests === true && - window?.lokiFeatureFlags?.useMessageRequests; - let conversation; if (conversations?.length) { conversation = conversations[index]; @@ -97,10 +93,6 @@ export class LeftPaneMessageSection extends React.Component { return null; } - // TODO: need to confirm what default setting is best here. - if (messageRequestsEnabled && !Boolean(conversation.isApproved)) { - return null; - } return ; }; diff --git a/ts/session/conversations/ConversationController.ts b/ts/session/conversations/ConversationController.ts index ae840959b..61016796b 100644 --- a/ts/session/conversations/ConversationController.ts +++ b/ts/session/conversations/ConversationController.ts @@ -236,7 +236,11 @@ export class ConversationController { if (conversation.isPrivate()) { window.log.info(`deleteContact isPrivate, marking as inactive: ${id}`); - conversation.set('active_at', undefined); + // conversation.set('active_at', undefined); + conversation.set({ + active_at: undefined, + isApproved: false, + }); await conversation.commit(); } else { window.log.info(`deleteContact !isPrivate, removing convo from DB: ${id}`); diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 8cbed2136..bf9f20e52 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -304,41 +304,49 @@ export const _getLeftPaneLists = ( }; } - if (!Boolean(conversation.isApproved) === true && window.lokiFeatureFlags.useMessageRequests) { - continue; - } + const messageRequestsEnabled = + window.inboxStore?.getState().userConfig.messageRequests === true && + window?.lokiFeatureFlags?.useMessageRequests === true; + + // if (!Boolean(conversation.isApproved) === true && window.lokiFeatureFlags.useMessageRequests) { + // continue; + // } // Add Open Group to list as soon as the name has been set - if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) { - continue; + // if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) { + // continue; + // } + + // if (!conversation.isApproved && !conversation.isBlocked) { + // conversationRequests.push(conversation); + // } + + if (shouldShowInRequestList(conversation, messageRequestsEnabled)) { + conversationRequests.push(conversation); } // Remove all invalid conversations and conversatons of devices associated // with cancelled attempted links - if (!conversation.isPublic && !conversation.activeAt) { - continue; - } + // if (!conversation.isPublic && !conversation.activeAt) { + // continue; + // } - if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) { + // if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) { + // directConversations.push(conversation); + // } + + if (shouldShowInContacts(conversation)) { directConversations.push(conversation); } - if (!conversation.isApproved && !conversation.isBlocked) { - conversationRequests.push(conversation); - } - - if ( - unreadCount < 9 && - conversation.unreadCount && - conversation.unreadCount > 0 && - conversation.currentNotificationSetting !== 'disabled' - ) { - unreadCount += conversation.unreadCount; - } - - if (conversation.isApproved) { + if (shouldShowInConversationList(conversation, messageRequestsEnabled)) { conversations.push(conversation); + unreadCount = calculateNewUnreadTotal(unreadCount, conversation); } + + // if (conversation.isApproved) { + // conversations.push(conversation); + // } } return { @@ -349,6 +357,84 @@ export const _getLeftPaneLists = ( }; }; +const calculateNewUnreadTotal = (unreadCount: number, conversation: ReduxConversationType) => { + if ( + unreadCount < 9 && + conversation.unreadCount && + conversation.unreadCount > 0 && + conversation.currentNotificationSetting !== 'disabled' + ) { + unreadCount += conversation.unreadCount; + } + return unreadCount; +}; + +const shouldShowInRequestList = ( + conversation: ReduxConversationType, + messageRequestsEnabled: boolean +) => { + if (conversation.isPublic || conversation.isBlocked || Boolean(conversation.activeAt) === false) { + return false; + } + + if (messageRequestsEnabled) { + if (Boolean(conversation.isApproved || !conversation.isBlocked)) { + return false; + } + } + return true; +}; + +const shouldShowInContacts = (conversation: ReduxConversationType) => { + // Add Open Group to list as soon as the name has been set + if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) { + return false; + } + + // if (shouldShowInRequestList(conversation)) { + // conversationRequests.push(conversation); + // } + + // Remove all invalid conversations and conversatons of devices associated + // with cancelled attempted links + if (!conversation.isPublic && !conversation.activeAt) { + return false; + } + + if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) { + // directConversations.push(conversation); + return true; + } else { + return false; + } +}; + +const shouldShowInConversationList = ( + conversation: ReduxConversationType, + messageRequestsEnabled: boolean +) => { + // // Add Open Group to list as soon as the name has been set + if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) { + return false; + } + + // Remove all invalid conversations and conversatons of devices associated + // with cancelled attempted links + if (!conversation.isPublic && !conversation.activeAt) { + return false; + } + + // if (!conversation.activeAt) { + // return false; + // } + + if (messageRequestsEnabled && !conversation.isApproved) { + return false; + } + + return true; +}; + export const getLeftPaneLists = createSelector( getConversationLookup, getConversationComparator,