mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
Previously, if a user had zero total starred messages, we would still show the "Unstar all messages" in the left sidebar on opening the starred messages popover. This commit adds a check to show button only if the user had non-zero starred messages. This is done because- 1. The button, when shown when the user has zero starred messages, is redundant and may be confusing. 2. Clicking on the button when having zero starred messages sends a zero-length array to the backend, resulting in HTTP 400 error.
51 lines
969 B
JavaScript
51 lines
969 B
JavaScript
import * as stream_popover from "./stream_popover";
|
|
import * as top_left_corner from "./top_left_corner";
|
|
|
|
export const starred_ids = new Set();
|
|
|
|
export function initialize() {
|
|
starred_ids.clear();
|
|
|
|
for (const id of page_params.starred_messages) {
|
|
starred_ids.add(id);
|
|
}
|
|
|
|
rerender_ui();
|
|
}
|
|
|
|
export function add(ids) {
|
|
for (const id of ids) {
|
|
starred_ids.add(id);
|
|
}
|
|
|
|
rerender_ui();
|
|
}
|
|
|
|
export function remove(ids) {
|
|
for (const id of ids) {
|
|
starred_ids.delete(id);
|
|
}
|
|
|
|
rerender_ui();
|
|
}
|
|
|
|
export function get_count() {
|
|
return starred_ids.size;
|
|
}
|
|
|
|
export function get_starred_msg_ids() {
|
|
return Array.from(starred_ids);
|
|
}
|
|
|
|
export function rerender_ui() {
|
|
let count = get_count();
|
|
|
|
if (!page_params.starred_message_counts) {
|
|
// This essentially hides the count
|
|
count = 0;
|
|
}
|
|
|
|
top_left_corner.update_starred_count(count);
|
|
stream_popover.hide_starred_messages_popover();
|
|
}
|