Skip to content

Commit

Permalink
filter: Fix combined feed navigating to muted unread message.
Browse files Browse the repository at this point in the history
Some we didn't have a check for if topic is muted here which
resulted in combined feed trying to navigate user to muted
unread message if it was the first unread in the narrow.
  • Loading branch information
amanagr authored and timabbott committed May 23, 2024
1 parent 62dfd93 commit b22adc1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
8 changes: 7 additions & 1 deletion web/src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,15 @@ function message_in_home(message: Message): boolean {
return true;
}

if (user_topics.is_topic_muted(message.stream_id, message.topic)) {
// If topic is muted, we don't show the message.
return false;
}

return (
// If stream is muted, we show the message if topic is unmuted or followed.
!stream_data.is_muted(message.stream_id) ||
user_topics.is_topic_unmuted(message.stream_id, message.topic)
user_topics.is_topic_unmuted_or_followed(message.stream_id, message.topic)
);
}

Expand Down
26 changes: 25 additions & 1 deletion web/tests/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const $ = require("./lib/zjquery");
const {page_params, realm} = require("./lib/zpage_params");

const message_store = mock_esm("../src/message_store");
const user_topics = mock_esm("../src/user_topics");

const resolved_topic = zrequire("../shared/src/resolved_topic");
const stream_data = zrequire("stream_data");
Expand Down Expand Up @@ -753,7 +754,7 @@ test("canonicalization", () => {
assert.equal(term.operand, "link");
});

test("predicate_basics", () => {
test("predicate_basics", ({override}) => {
// Predicates are functions that accept a message object with the message
// attributes (not content), and return true if the message belongs in a
// given narrow. If the narrow parameters include a search, the predicate
Expand Down Expand Up @@ -831,10 +832,33 @@ test("predicate_basics", () => {
assert.ok(!predicate({type: stream_message, topic: "foo"}));

const unknown_stream_id = 999;
override(user_topics, "is_topic_muted", () => false);
override(user_topics, "is_topic_unmuted_or_followed", () => false);
predicate = get_predicate([["in", "home"]]);
assert.ok(!predicate({stream_id: unknown_stream_id, stream: "unknown"}));
assert.ok(predicate({type: direct_message}));

// Muted topic is not part of in-home.
with_overrides(({override}) => {
override(user_topics, "is_topic_muted", () => true);
assert.ok(!predicate({stream_id, topic: "bar"}));
});

// Muted stream is not part of in-home.
const muted_stream = {
stream_id: 94924,
name: "muted",
is_muted: true,
};
stream_data.add_sub(muted_stream);
assert.ok(!predicate({stream_id: muted_stream.stream_id, topic: "bar"}));

// Muted stream but topic is unmuted or followed is part of in-home.
with_overrides(({override}) => {
override(user_topics, "is_topic_unmuted_or_followed", () => true);
assert.ok(predicate({stream_id: muted_stream.stream_id, topic: "bar"}));
});

make_sub("kiosk", 1234);
with_overrides(({override}) => {
override(page_params, "narrow_stream", "kiosk");
Expand Down

0 comments on commit b22adc1

Please sign in to comment.