Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

narrow: Fix last unread when narrowed to a `dm` message using `with`.

roanster007519614ffbb3b
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 7ab22ad7016..12a348f90ce 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -15,7 +15,7 @@ import {page_params} from "./page_params";
import type {User} from "./people";
import * as people from "./people";
import type {UserPillItem} from "./search_suggestion";
-import {realm} from "./state_data";
+import {current_user, realm} from "./state_data";
import type {NarrowTerm} from "./state_data";
import * as stream_data from "./stream_data";
import type {StreamSubscription} from "./sub_store";
@@ -831,7 +831,19 @@ export class Filter {
});
assert(typeof message.display_recipient !== "string");
- const dm_participants = message.display_recipient.map((user) => user.email);
+
+ // We should make sure the current user is not included for
+ // the `dm` operand for the narrow.
+ const dm_participants = message.display_recipient
+ .map((user) => user.email)
+ .filter((user_email) => user_email !== current_user.email);
+
+ // However, if the current user is the only recipient of the
+ // message, we should include the user in the operand.
+ if (dm_participants.length === 0) {
+ dm_participants.push(current_user.email);
+ }
+
const dm_operand = dm_participants.join(",");
const dm_conversation_terms = [{operator: "dm", operand: dm_operand, negated: false}];
diff --git a/web/tests/filter.test.js b/web/tests/filter.test.js
index 4add189d0e6..192aa1aa4ab 100644
--- a/web/tests/filter.test.js
+++ b/web/tests/filter.test.js
@@ -8,7 +8,7 @@ const {mock_esm, with_overrides, zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
-const {page_params, realm} = require("./lib/zpage_params");
+const {current_user, page_params, realm} = require("./lib/zpage_params");
const message_store = mock_esm("../src/message_store");
const user_topics = mock_esm("../src/user_topics");
@@ -2431,6 +2431,7 @@ run_test("equals", () => {
});
run_test("adjusted_terms_if_moved", () => {
+ current_user.email = me.email;
// should return null for non-stream messages containing no
// `with` operator
let raw_terms = [{operator: "channel", operand: "Foo"}];
@@ -2440,7 +2441,14 @@ run_test("adjusted_terms_if_moved", () => {
// should adjust terms to contain `dm` for non-stream messages
// if it contains `with` operator
- message = {type: "private", id: 2, display_recipient: [{id: 3, email: "[email protected]"}]};
+ message = {
+ type: "private",
+ id: 2,
+ display_recipient: [
+ {id: 3, email: "[email protected]"},
+ {id: me.user_id, email: me.email},
+ ],
+ };
raw_terms = [
{operator: "channel", operand: "Foo"},
{operator: "with", operand: `${message.id}`},
@@ -2451,6 +2459,21 @@ run_test("adjusted_terms_if_moved", () => {
{operator: "with", operand: "2"},
]);
+ message = {
+ type: "private",
+ id: 2,
+ display_recipient: [{id: me.user_id, email: me.email}],
+ };
+ raw_terms = [
+ {operator: "channel", operand: "Foo"},
+ {operator: "with", operand: `${message.id}`},
+ ];
+ result = Filter.adjusted_terms_if_moved(raw_terms, message);
+ assert.deepEqual(result, [
+ {operator: "dm", operand: me.email, negated: false},
+ {operator: "with", operand: "2"},
+ ]);
+
// should return null if no terms are changed
raw_terms = [{operator: "channel", operand: "general"}];
message = {type: "stream", display_recipient: "general", topic: "discussion"};