filter: Fix combined feed navigating to muted unread message.

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.
This commit is contained in:
Aman Agrawal 2024-05-23 07:37:39 +00:00 committed by Tim Abbott
parent 62dfd93a83
commit b22adc1d5f
2 changed files with 32 additions and 2 deletions

View File

@ -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)
);
}

View File

@ -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");
@ -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
@ -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");