From 2eab74246bd8d5e0119aff3c17c588ba0c8b690f Mon Sep 17 00:00:00 2001 From: warrickct Date: Tue, 16 Nov 2021 13:22:12 +1100 Subject: [PATCH] PR changes. Disabling message requests behind feature flags. --- preload.js | 1 + ts/components/ConversationListItem.tsx | 8 ----- ts/components/LeftPane.tsx | 3 -- .../session/LeftPaneMessageSection.tsx | 36 ++++++------------- .../session/SessionClosableOverlay.tsx | 3 -- ts/models/conversation.ts | 8 +---- ts/receiver/configMessage.ts | 10 ------ ts/receiver/dataMessage.ts | 1 - ts/state/selectors/conversations.ts | 4 +++ ts/window.d.ts | 1 + 10 files changed, 17 insertions(+), 58 deletions(-) diff --git a/preload.js b/preload.js index 281b08ee2..9cf51698a 100644 --- a/preload.js +++ b/preload.js @@ -51,6 +51,7 @@ window.lokiFeatureFlags = { padOutgoingAttachments: true, enablePinConversations: true, useUnsendRequests: false, + useMessageRequests: false, }; window.isBeforeVersion = (toCheck, baseVersion) => { diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 9decf0223..c412b4db3 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -303,10 +303,6 @@ const ConversationListItem = (props: Props) => { const handleConversationAccept = async () => { const conversationToApprove = await getConversationById(conversationId); await conversationToApprove?.setIsApproved(true); - console.warn({ convoAfterSetIsApproved: conversationToApprove }); - // TODO: Send sync message to other devices. Using config message - - // await syncConfigurationIfNeeded(true); await forceSyncConfigurationNowIfNeeded(); }; @@ -315,10 +311,6 @@ const ConversationListItem = (props: Props) => {
{ - // e.stopPropagation(); - // e.preventDefault(); - // }} onContextMenu={(e: any) => { contextMenu.show({ id: triggerId, diff --git a/ts/components/LeftPane.tsx b/ts/components/LeftPane.tsx index 56bfe79bc..271485155 100644 --- a/ts/components/LeftPane.tsx +++ b/ts/components/LeftPane.tsx @@ -30,9 +30,6 @@ const InnerLeftPaneMessageSection = () => { const lists = showSearch ? undefined : useSelector(getLeftPaneLists); // tslint:disable: use-simple-attributes - - // const - return ( { @@ -66,19 +64,12 @@ export class LeftPaneMessageSection extends React.Component { public constructor(props: Props) { super(props); - const approvedConversations = props.conversations?.filter(convo => Boolean(convo.isApproved)); - const unapprovedConversations = props.conversations?.filter( - convo => !Boolean(convo.isApproved) - ); - console.warn('convos updated'); this.state = { loading: false, overlay: false, valuePasted: '', - approvedConversations: approvedConversations || [], - unapprovedConversations: unapprovedConversations || [], }; autoBind(this); @@ -87,23 +78,19 @@ export class LeftPaneMessageSection extends React.Component { public renderRow = ({ index, key, style }: RowRendererParamsType): JSX.Element | null => { const { conversations } = this.props; - const conversationsToShow = conversations?.filter(async c => { - return ( - Boolean(c.isApproved) === true && - (await BlockedNumberController.isBlockedAsync(c.id)) === false - ); - }); - if (!conversations || !conversationsToShow) { + + //assume conversations that have been marked unapproved should be filtered out by selector. + if (!conversations) { throw new Error('renderRow: Tried to render without conversations'); } - // TODO: make this only filtered when the setting is enabled const messageRequestsEnabled = - window.inboxStore?.getState().userConfig.messageRequests === true; + window.inboxStore?.getState().userConfig.messageRequests === true && + window?.lokiFeatureFlags?.useMessageRequests; let conversation; - if (conversationsToShow?.length) { - conversation = conversationsToShow[index]; + if (conversations?.length) { + conversation = conversations[index]; } if (!conversation) { @@ -129,10 +116,6 @@ export class LeftPaneMessageSection extends React.Component { throw new Error('render: must provided conversations if no search results are provided'); } - // TODO: make selectors for this instead. - // TODO: only filter conversations if setting for requests is applied - - // TODO: readjust to be approved length as only approved convos will show here. const length = this.props.conversations ? this.props.conversations.length : 0; const listKey = 0; @@ -145,7 +128,6 @@ export class LeftPaneMessageSection extends React.Component { {({ height, width }) => ( { onChange={this.updateSearch} placeholder={window.i18n('searchFor...')} /> - + {window.lokiFeatureFlags.useMessageRequests ? ( + + ) : null} {this.renderList()} {this.renderBottomButtons()}
diff --git a/ts/components/session/SessionClosableOverlay.tsx b/ts/components/session/SessionClosableOverlay.tsx index 54414e585..c5b532aa1 100644 --- a/ts/components/session/SessionClosableOverlay.tsx +++ b/ts/components/session/SessionClosableOverlay.tsx @@ -297,9 +297,7 @@ export class SessionClosableOverlay extends React.Component { */ const MessageRequestList = () => { const lists = useSelector(getLeftPaneLists); - // const validConversationRequests = lists?.conversations.filter(c => { const validConversationRequests = lists?.conversationRequests; - console.warn({ unapprovedConversationsListConstructor: validConversationRequests }); return (
{validConversationRequests.map(conversation => { @@ -309,7 +307,6 @@ const MessageRequestList = () => { ); }; -// const MessageRequestListItem = (props: { conversation: ConversationModel }) => { const MessageRequestListItem = (props: { conversation: ConversationListItemProps }) => { const { conversation } = props; return ( diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 173ad05f2..c05077662 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -716,12 +716,6 @@ export class ConversationModel extends Backbone.Model { const sentAt = message.get('sent_at'); - // TODO: msgreq for debugging - const unapprove = message.get('body')?.includes('unapprove'); - if (unapprove) { - await this.setIsApproved(false); - } - if (!sentAt) { throw new Error('sendMessageJob() sent_at must be set.'); } @@ -743,7 +737,7 @@ export class ConversationModel extends Backbone.Model { const updateApprovalNeeded = !this.isApproved() && (this.isPrivate() || this.isMediumGroup() || this.isClosedGroup()); - if (updateApprovalNeeded && !unapprove) { + if (updateApprovalNeeded) { this.setIsApproved(true); await syncConfigurationIfNeeded(true); } diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index a8d7f0ec6..4df55f14d 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -54,16 +54,6 @@ async function handleGroupsAndContactsFromConfigMessage( envelope: EnvelopePlus, configMessage: SignalService.ConfigurationMessage ) { - // const didWeHandleAConfigurationMessageAlready = - // (await getItemById(hasSyncedInitialConfigurationItem))?.value || false; - - // TODO: debug - // if (didWeHandleAConfigurationMessageAlready) { - // window?.log?.info( - // 'Dropping configuration contacts/groups change as we already handled one... ' - // ); - // return; - // } await createOrUpdateItem({ id: 'hasSyncedInitialConfigurationItem', value: true, diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 47a8d3d68..e6720c81b 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -403,7 +403,6 @@ export async function isMessageDuplicate({ return false; } const filteredResult = [result].filter((m: any) => m.attributes.body === message.body); - console.warn({ filteredResult }); return filteredResult.some(m => isDuplicate(m, message, source)); } catch (error) { window?.log?.error('isMessageDuplicate error:', Errors.toLogFormat(error)); diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 15ec06bba..8cbed2136 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -304,6 +304,10 @@ export const _getLeftPaneLists = ( }; } + 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; diff --git a/ts/window.d.ts b/ts/window.d.ts index 61d1a538f..488b79281 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -48,6 +48,7 @@ declare global { padOutgoingAttachments: boolean; enablePinConversations: boolean; useUnsendRequests: boolean; + useMessageRequests: boolean; }; lokiSnodeAPI: LokiSnodeAPI; onLogin: any;