From 3336e85f04173fe0c9364e00e484ace04dbbd286 Mon Sep 17 00:00:00 2001 From: jainkuniya Date: Tue, 5 Feb 2019 19:22:06 +0530 Subject: [PATCH] isMessageInNarrow: Fix regression in `matchRecipients`. Remove `normalizedRecipients === ownEmail` condition, as it is not taking `narrow` in consideration. For self message, `display_recipient` will only consist of `ownEmail`. Thus for calling `isMessageInNarrow` with self message and any private narrow was returning `true` (because of `normalizedRecipients === ownEmail`). So remove this condition. Also improve `normalizedNarrow`, so that it consist of only unique values. Now this change will take care of logic which was intended to be taken by `normalizedRecipients === ownEmail` (which is getting removed, by this commit). Fixes: #3324 --- src/utils/narrow.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/narrow.js b/src/utils/narrow.js index 42f22eaeb19..0846bb5ab5d 100644 --- a/src/utils/narrow.js +++ b/src/utils/narrow.js @@ -1,6 +1,7 @@ /* @flow strict-local */ import isEqual from 'lodash.isequal'; import unescape from 'lodash.unescape'; +import uniqby from 'lodash.uniqby'; import type { Narrow, Message } from '../types'; import { normalizeRecipients } from './recipient'; @@ -210,8 +211,10 @@ export const isSearchNarrow = (narrow?: Narrow): boolean => export const isMessageInNarrow = (message: Message, narrow: Narrow, ownEmail: string): boolean => { const matchRecipients = (emails: string[]) => { const normalizedRecipients = normalizeRecipients(message.display_recipient); - const normalizedNarrow = [...emails, ownEmail].sort().join(','); - return normalizedRecipients === ownEmail || normalizedRecipients === normalizedNarrow; + const normalizedNarrow = uniqby([...emails, ownEmail]) + .sort() + .join(','); + return normalizedRecipients === normalizedNarrow; }; return caseNarrow(narrow, {