mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
left sidebar: Add support to unstar all messages in topic.
This adds support for unstarring all (starred) messages from a particular topic, from the topic popover. The earlier implementation of this in #16898 was reverted inbc55aa6a01(#17429) because it had two problems- 1. The crash reported inbc55aa6a01was due to message_store returning undefined. This happens when the message itself hasn't been fetched from the server yet, but we know that the message is starred from the ids in `page_params` in `starred_messages.js`. This commit handles this case explicitly. Note that, we simply ignore those messages which we haven't fetched, and because of this, it may happen that we don't unstar some messages from that topic. The correct implementation for this would be to ask the backend for starred IDs in a topic. 2. The earlier implementation actually unstarred **all** messages. This was because it grabbed the topic and stream_id from the topic popover `data` attributes, after the topic popover had been closed. This passed `undefined`, which the function then interpreted as an action to unstar all messages. With this commit, we use the confirm_dialog widget, which eliminates the need to store this data in the DOM.
This commit is contained in:
committed by
Tim Abbott
parent
f17a52b2f3
commit
42aea49784
@@ -9,7 +9,9 @@ const {run_test} = require("../zjsunit/test");
|
||||
const page_params = set_global("page_params", {});
|
||||
|
||||
zrequire("timerender");
|
||||
const message_store = zrequire("message_store");
|
||||
const starred_messages = zrequire("starred_messages");
|
||||
const stream_popover = zrequire("stream_popover");
|
||||
const top_left_corner = zrequire("top_left_corner");
|
||||
|
||||
run_test("add starred", (override) => {
|
||||
@@ -38,6 +40,48 @@ run_test("remove starred", (override) => {
|
||||
assert.equal(starred_messages.get_count(), 1);
|
||||
});
|
||||
|
||||
run_test("get starred ids in topic", () => {
|
||||
for (const id of [1, 2, 3, 4, 5]) {
|
||||
starred_messages.starred_ids.add(id);
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
starred_messages.get_starred_message_ids_in_topic(undefined, "topic name"),
|
||||
[],
|
||||
);
|
||||
assert.deepEqual(starred_messages.get_starred_message_ids_in_topic(3, undefined), []);
|
||||
|
||||
// id: 1 isn't inserted, to test handling the case
|
||||
// when message_store.get() returns undefined
|
||||
message_store.create_mock_message({
|
||||
id: 2,
|
||||
type: "private",
|
||||
});
|
||||
message_store.create_mock_message({
|
||||
// Different stream
|
||||
id: 3,
|
||||
type: "stream",
|
||||
stream_id: 19,
|
||||
topic: "topic",
|
||||
});
|
||||
message_store.create_mock_message({
|
||||
// Different topic
|
||||
id: 4,
|
||||
type: "stream",
|
||||
stream_id: 20,
|
||||
topic: "some other topic",
|
||||
});
|
||||
message_store.create_mock_message({
|
||||
// Correct match
|
||||
id: 5,
|
||||
type: "stream",
|
||||
stream_id: 20,
|
||||
topic: "topic",
|
||||
});
|
||||
|
||||
assert.deepEqual(starred_messages.get_starred_message_ids_in_topic(20, "topic"), [5]);
|
||||
});
|
||||
|
||||
run_test("initialize", (override) => {
|
||||
starred_messages.starred_ids.clear();
|
||||
for (const id of [1, 2, 3]) {
|
||||
@@ -59,6 +103,7 @@ run_test("rerender_ui", () => {
|
||||
page_params.starred_message_counts = true;
|
||||
with_overrides((override) => {
|
||||
const stub = make_stub();
|
||||
override(stream_popover, "hide_topic_popover", () => {});
|
||||
override(top_left_corner, "update_starred_count", stub.f);
|
||||
starred_messages.rerender_ui();
|
||||
assert.equal(stub.num_calls, 1);
|
||||
@@ -69,6 +114,7 @@ run_test("rerender_ui", () => {
|
||||
page_params.starred_message_counts = false;
|
||||
with_overrides((override) => {
|
||||
const stub = make_stub();
|
||||
override(stream_popover, "hide_topic_popover", () => {});
|
||||
override(top_left_corner, "update_starred_count", stub.f);
|
||||
starred_messages.rerender_ui();
|
||||
assert.equal(stub.num_calls, 1);
|
||||
|
||||
Reference in New Issue
Block a user