mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
refactor: Rename MessageList.muting_enabled.
Previously, the `muting_enabled` property of MessageListData class was used to indicate whether some messages in the message list need to be filtered due to topic muting, depending on the narrow. For example, we exclude messages belonging to muted topics from stream narrows, but not from search narrows. The name `muting_enabled` is a bit confusing, and hence is changed to `excludes_muted_topics`. It is also important that the name be specific, since a similar new property will be added for user mutes in future commits.
This commit is contained in:
committed by
Steve Howell
parent
90636d5e81
commit
9ae44c769c
@@ -38,7 +38,7 @@ function assert_contents(mld, msg_ids) {
|
||||
|
||||
run_test("basics", () => {
|
||||
const mld = new MessageListData({
|
||||
muting_enabled: false,
|
||||
excludes_muted_topics: false,
|
||||
filter: undefined,
|
||||
});
|
||||
|
||||
@@ -105,7 +105,7 @@ run_test("basics", () => {
|
||||
|
||||
run_test("muting enabled", () => {
|
||||
const mld = new MessageListData({
|
||||
muting_enabled: true,
|
||||
excludes_muted_topics: true,
|
||||
filter: undefined,
|
||||
});
|
||||
|
||||
@@ -139,7 +139,7 @@ run_test("more muting", () => {
|
||||
};
|
||||
|
||||
const mld = new MessageListData({
|
||||
muting_enabled: true,
|
||||
excludes_muted_topics: true,
|
||||
filter: undefined,
|
||||
});
|
||||
|
||||
@@ -202,7 +202,7 @@ run_test("more muting", () => {
|
||||
|
||||
run_test("errors", () => {
|
||||
const mld = new MessageListData({
|
||||
muting_enabled: false,
|
||||
excludes_muted_topics: false,
|
||||
filter: undefined,
|
||||
});
|
||||
assert.equal(mld.get("bogus-id"), undefined);
|
||||
|
||||
@@ -32,10 +32,10 @@ function test_with(fixture) {
|
||||
}
|
||||
}
|
||||
|
||||
const muting_enabled = narrow_state.muting_enabled();
|
||||
const excludes_muted_topics = narrow_state.excludes_muted_topics();
|
||||
const msg_data = new MessageListData({
|
||||
filter: narrow_state.filter(),
|
||||
muting_enabled,
|
||||
excludes_muted_topics,
|
||||
});
|
||||
const id_info = {
|
||||
target_id: fixture.target_id,
|
||||
|
||||
@@ -140,27 +140,27 @@ run_test("operators", () => {
|
||||
assert.equal(result.length, 0);
|
||||
});
|
||||
|
||||
run_test("muting_enabled", () => {
|
||||
run_test("excludes_muted_topics", () => {
|
||||
set_filter([["stream", "devel"]]);
|
||||
assert(narrow_state.muting_enabled());
|
||||
assert(narrow_state.excludes_muted_topics());
|
||||
|
||||
narrow_state.reset_current_filter(); // not narrowed, basically
|
||||
assert(narrow_state.muting_enabled());
|
||||
assert(narrow_state.excludes_muted_topics());
|
||||
|
||||
set_filter([
|
||||
["stream", "devel"],
|
||||
["topic", "mac"],
|
||||
]);
|
||||
assert(!narrow_state.muting_enabled());
|
||||
assert(!narrow_state.excludes_muted_topics());
|
||||
|
||||
set_filter([["search", "whatever"]]);
|
||||
assert(!narrow_state.muting_enabled());
|
||||
assert(!narrow_state.excludes_muted_topics());
|
||||
|
||||
set_filter([["is", "private"]]);
|
||||
assert(!narrow_state.muting_enabled());
|
||||
assert(!narrow_state.excludes_muted_topics());
|
||||
|
||||
set_filter([["is", "starred"]]);
|
||||
assert(!narrow_state.muting_enabled());
|
||||
assert(!narrow_state.excludes_muted_topics());
|
||||
});
|
||||
|
||||
run_test("set_compose_defaults", () => {
|
||||
|
||||
@@ -466,7 +466,7 @@ exports.initialize = function () {
|
||||
// without a `table_name` attached.
|
||||
const recent_topics_message_list = new message_list.MessageList({
|
||||
filter: new Filter([{operator: "in", operand: "home"}]),
|
||||
muting_enabled: true,
|
||||
excludes_muted_topics: true,
|
||||
});
|
||||
exports.load_messages({
|
||||
anchor: "newest",
|
||||
|
||||
@@ -10,14 +10,14 @@ exports.set_narrowed = function (value) {
|
||||
class MessageList {
|
||||
constructor(opts) {
|
||||
if (opts.data) {
|
||||
this.muting_enabled = opts.data.muting_enabled;
|
||||
this.excludes_muted_topics = opts.data.excludes_muted_topics;
|
||||
this.data = opts.data;
|
||||
} else {
|
||||
const filter = opts.filter;
|
||||
|
||||
this.muting_enabled = opts.muting_enabled;
|
||||
this.excludes_muted_topics = opts.excludes_muted_topics;
|
||||
this.data = new MessageListData({
|
||||
muting_enabled: this.muting_enabled,
|
||||
excludes_muted_topics: this.excludes_muted_topics,
|
||||
filter,
|
||||
});
|
||||
}
|
||||
@@ -375,7 +375,7 @@ class MessageList {
|
||||
}
|
||||
|
||||
update_muting_and_rerender() {
|
||||
if (!this.muting_enabled) {
|
||||
if (!this.excludes_muted_topics) {
|
||||
return;
|
||||
}
|
||||
this.data.update_items_for_muting();
|
||||
@@ -412,7 +412,7 @@ class MessageList {
|
||||
exports.MessageList = MessageList;
|
||||
|
||||
exports.all = new MessageList({
|
||||
muting_enabled: false,
|
||||
excludes_muted_topics: false,
|
||||
});
|
||||
|
||||
window.message_list = exports;
|
||||
|
||||
@@ -6,8 +6,8 @@ const util = require("./util");
|
||||
|
||||
class MessageListData {
|
||||
constructor(opts) {
|
||||
this.muting_enabled = opts.muting_enabled;
|
||||
if (this.muting_enabled) {
|
||||
this.excludes_muted_topics = opts.excludes_muted_topics;
|
||||
if (this.excludes_muted_topics) {
|
||||
this._all_items = [];
|
||||
}
|
||||
this._items = [];
|
||||
@@ -110,7 +110,7 @@ class MessageListData {
|
||||
}
|
||||
|
||||
clear() {
|
||||
if (this.muting_enabled) {
|
||||
if (this.excludes_muted_topics) {
|
||||
this._all_items = [];
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ class MessageListData {
|
||||
}
|
||||
|
||||
update_items_for_muting() {
|
||||
if (!this.muting_enabled) {
|
||||
if (!this.excludes_muted_topics) {
|
||||
return;
|
||||
}
|
||||
this._items = this.unmuted_messages(this._all_items);
|
||||
@@ -253,7 +253,7 @@ class MessageListData {
|
||||
// "interior" messages to add and can't optimize
|
||||
// things by only doing prepend or only doing append.
|
||||
let viewable_messages;
|
||||
if (this.muting_enabled) {
|
||||
if (this.excludes_muted_topics) {
|
||||
this._all_items = messages.concat(this._all_items);
|
||||
this._all_items.sort((a, b) => a.id - b.id);
|
||||
|
||||
@@ -272,7 +272,7 @@ class MessageListData {
|
||||
append(messages) {
|
||||
// Caller should have already filtered
|
||||
let viewable_messages;
|
||||
if (this.muting_enabled) {
|
||||
if (this.excludes_muted_topics) {
|
||||
this._all_items = this._all_items.concat(messages);
|
||||
viewable_messages = this.unmuted_messages(messages);
|
||||
} else {
|
||||
@@ -286,7 +286,7 @@ class MessageListData {
|
||||
prepend(messages) {
|
||||
// Caller should have already filtered
|
||||
let viewable_messages;
|
||||
if (this.muting_enabled) {
|
||||
if (this.excludes_muted_topics) {
|
||||
this._all_items = messages.concat(this._all_items);
|
||||
viewable_messages = this.unmuted_messages(messages);
|
||||
} else {
|
||||
@@ -305,7 +305,7 @@ class MessageListData {
|
||||
}
|
||||
|
||||
this._items = this._items.filter((msg) => !msg_ids_to_remove.has(msg.id));
|
||||
if (this.muting_enabled) {
|
||||
if (this.excludes_muted_topics) {
|
||||
this._all_items = this._all_items.filter((msg) => !msg_ids_to_remove.has(msg.id));
|
||||
}
|
||||
}
|
||||
@@ -496,7 +496,7 @@ class MessageListData {
|
||||
) {
|
||||
blueslip.debug("Changed message ID from server caused out-of-order list, reordering");
|
||||
this._items.sort(message_sort_func);
|
||||
if (this.muting_enabled) {
|
||||
if (this.excludes_muted_topics) {
|
||||
this._all_items.sort(message_sort_func);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -16,7 +16,7 @@ exports.rerender_on_topic_update = function () {
|
||||
// re-doing a mute or unmute is a pretty recoverable thing.
|
||||
|
||||
stream_list.update_streams_sidebar();
|
||||
if (current_msg_list.muting_enabled) {
|
||||
if (current_msg_list.excludes_muted_topics) {
|
||||
current_msg_list.update_muting_and_rerender();
|
||||
}
|
||||
if (current_msg_list !== home_msg_list) {
|
||||
|
||||
@@ -218,14 +218,14 @@ exports.activate = function (raw_operators, opts) {
|
||||
// reflect the upcoming narrow.
|
||||
narrow_state.set_current_filter(filter);
|
||||
|
||||
const muting_enabled = narrow_state.muting_enabled();
|
||||
const excludes_muted_topics = narrow_state.excludes_muted_topics();
|
||||
|
||||
// Save how far from the pointer the top of the message list was.
|
||||
exports.save_pre_narrow_offset_for_reload();
|
||||
|
||||
let msg_data = new MessageListData({
|
||||
filter: narrow_state.filter(),
|
||||
muting_enabled,
|
||||
excludes_muted_topics,
|
||||
});
|
||||
|
||||
// Populate the message list if we can apply our filter locally (i.e.
|
||||
@@ -246,7 +246,7 @@ exports.activate = function (raw_operators, opts) {
|
||||
// the block we're about to request from the server instead.
|
||||
msg_data = new MessageListData({
|
||||
filter: narrow_state.filter(),
|
||||
muting_enabled,
|
||||
excludes_muted_topics,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ exports.narrowed_to_starred = function () {
|
||||
return current_filter.has_operand("is", "starred");
|
||||
};
|
||||
|
||||
exports.muting_enabled = function () {
|
||||
exports.excludes_muted_topics = function () {
|
||||
return (
|
||||
!exports.narrowed_to_topic() &&
|
||||
!exports.narrowed_to_search() &&
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
const home_msg_list = new message_list.MessageList({
|
||||
table_name: "zhome",
|
||||
filter: new Filter([{operator: "in", operand: "home"}]),
|
||||
muting_enabled: true,
|
||||
excludes_muted_topics: true,
|
||||
});
|
||||
|
||||
window.home_msg_list = home_msg_list;
|
||||
|
||||
Reference in New Issue
Block a user