2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 00:57:20 +01:00
|
|
|
import * as resize from "./resize";
|
2023-05-02 21:08:15 +02:00
|
|
|
import * as scheduled_messages from "./scheduled_messages";
|
2023-10-23 21:12:18 +02:00
|
|
|
import * as settings_config from "./settings_config";
|
2021-04-09 09:18:43 +02:00
|
|
|
import * as ui_util from "./ui_util";
|
2023-04-07 20:06:13 +02:00
|
|
|
|
|
|
|
let last_mention_count = 0;
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
export function update_starred_count(count) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $starred_li = $(".top_left_starred_messages");
|
|
|
|
ui_util.update_unread_count_in_dom($starred_li, count);
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2023-05-02 21:08:15 +02:00
|
|
|
export function update_scheduled_messages_row() {
|
|
|
|
const $scheduled_li = $(".top_left_scheduled_messages");
|
|
|
|
const count = scheduled_messages.get_count();
|
2023-05-02 19:25:44 +02:00
|
|
|
if (count > 0) {
|
2023-10-16 21:41:23 +02:00
|
|
|
$scheduled_li.addClass("show-with-scheduled-messages");
|
2023-05-02 19:25:44 +02:00
|
|
|
} else {
|
2023-10-16 21:41:23 +02:00
|
|
|
$scheduled_li.removeClass("show-with-scheduled-messages");
|
2023-05-02 19:25:44 +02:00
|
|
|
}
|
2023-05-02 21:08:15 +02:00
|
|
|
ui_util.update_unread_count_in_dom($scheduled_li, count);
|
|
|
|
}
|
|
|
|
|
2023-05-03 19:32:40 +02:00
|
|
|
export function update_dom_with_unread_counts(counts, skip_animations) {
|
2023-06-16 13:23:39 +02:00
|
|
|
// Note that direct message counts are handled in pm_list.js.
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2023-10-03 18:36:02 +02:00
|
|
|
// mentioned/inbox have simple integer counts
|
2022-01-25 11:36:19 +01:00
|
|
|
const $mentioned_li = $(".top_left_mentions");
|
2023-10-03 18:36:02 +02:00
|
|
|
const $inbox_li = $(".top_left_inbox");
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
ui_util.update_unread_count_in_dom($mentioned_li, counts.mentioned_message_count);
|
2023-10-03 18:36:02 +02:00
|
|
|
ui_util.update_unread_count_in_dom($inbox_li, counts.home_unread_messages);
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2023-05-03 19:32:40 +02:00
|
|
|
if (!skip_animations) {
|
|
|
|
animate_mention_changes($mentioned_li, counts.mentioned_message_count);
|
|
|
|
}
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2023-09-08 07:30:31 +02:00
|
|
|
// TODO: Rewrite how we handle activation of narrows when doing the redesign.
|
|
|
|
// We don't want to adjust class for all the buttons when switching narrows.
|
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
function remove($elem) {
|
|
|
|
$elem.removeClass("active-filter active-sub-filter");
|
2020-07-05 12:19:09 +02:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2022-09-13 13:15:57 +02:00
|
|
|
export function deselect_top_left_corner_items() {
|
2020-07-15 01:29:15 +02:00
|
|
|
remove($(".top_left_all_messages"));
|
|
|
|
remove($(".top_left_starred_messages"));
|
|
|
|
remove($(".top_left_mentions"));
|
2023-09-06 23:55:09 +02:00
|
|
|
remove($(".top_left_recent_view"));
|
2023-08-09 07:23:30 +02:00
|
|
|
remove($(".top_left_inbox"));
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 00:44:57 +01:00
|
|
|
export function handle_narrow_activated(filter) {
|
2017-08-12 17:26:12 +02:00
|
|
|
deselect_top_left_corner_items();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let ops;
|
|
|
|
let filter_name;
|
2022-01-25 11:36:19 +01:00
|
|
|
let $filter_li;
|
2017-08-12 17:26:12 +02:00
|
|
|
|
|
|
|
// TODO: handle confused filters like "in:all stream:foo"
|
2020-07-15 01:29:15 +02:00
|
|
|
ops = filter.operands("in");
|
2017-08-12 17:26:12 +02:00
|
|
|
if (ops.length >= 1) {
|
|
|
|
filter_name = ops[0];
|
2020-07-15 01:29:15 +02:00
|
|
|
if (filter_name === "home") {
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter_li = $(".top_left_all_messages");
|
|
|
|
$filter_li.addClass("active-filter");
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
ops = filter.operands("is");
|
2017-08-12 17:26:12 +02:00
|
|
|
if (ops.length >= 1) {
|
|
|
|
filter_name = ops[0];
|
2020-07-15 01:29:15 +02:00
|
|
|
if (filter_name === "starred") {
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter_li = $(".top_left_starred_messages");
|
|
|
|
$filter_li.addClass("active-filter");
|
2020-07-15 01:29:15 +02:00
|
|
|
} else if (filter_name === "mentioned") {
|
2022-01-25 11:36:19 +01:00
|
|
|
$filter_li = $(".top_left_mentions");
|
|
|
|
$filter_li.addClass("active-filter");
|
2017-08-12 17:26:12 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2017-08-12 17:26:12 +02:00
|
|
|
|
2023-10-16 21:50:48 +02:00
|
|
|
function toggle_condensed_navigation_area() {
|
|
|
|
const $views_label_container = $("#views-label-container");
|
|
|
|
const $views_label_icon = $("#toggle-top-left-navigation-area-icon");
|
|
|
|
if ($views_label_container.hasClass("showing-expanded-navigation")) {
|
|
|
|
// Toggle into the condensed state
|
|
|
|
$views_label_container.addClass("showing-condensed-navigation");
|
|
|
|
$views_label_container.removeClass("showing-expanded-navigation");
|
|
|
|
$views_label_icon.addClass("fa-caret-right");
|
|
|
|
$views_label_icon.removeClass("fa-caret-down");
|
|
|
|
} else {
|
|
|
|
// Toggle into the expanded state
|
|
|
|
$views_label_container.addClass("showing-expanded-navigation");
|
|
|
|
$views_label_container.removeClass("showing-condensed-navigation");
|
|
|
|
$views_label_icon.addClass("fa-caret-down");
|
|
|
|
$views_label_icon.removeClass("fa-caret-right");
|
|
|
|
}
|
2023-10-27 18:24:06 +02:00
|
|
|
resize.resize_stream_filters_container();
|
2023-10-16 21:50:48 +02:00
|
|
|
}
|
|
|
|
|
2023-09-08 07:51:34 +02:00
|
|
|
export function highlight_recent_view() {
|
2020-07-05 12:19:09 +02:00
|
|
|
remove($(".top_left_all_messages"));
|
|
|
|
remove($(".top_left_starred_messages"));
|
|
|
|
remove($(".top_left_mentions"));
|
2023-08-09 07:23:30 +02:00
|
|
|
remove($(".top_left_inbox"));
|
2023-09-06 23:55:09 +02:00
|
|
|
$(".top_left_recent_view").addClass("active-filter");
|
2020-11-30 11:07:54 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
resize.resize_stream_filters_container();
|
|
|
|
}, 0);
|
2021-02-28 00:44:57 +01:00
|
|
|
}
|
2023-04-07 20:06:13 +02:00
|
|
|
|
|
|
|
export function animate_mention_changes($li, new_mention_count) {
|
|
|
|
if (new_mention_count > last_mention_count) {
|
|
|
|
do_new_messages_animation($li);
|
|
|
|
}
|
|
|
|
last_mention_count = new_mention_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_new_messages_animation($li) {
|
|
|
|
$li.addClass("new_messages");
|
|
|
|
function mid_animation() {
|
|
|
|
$li.removeClass("new_messages");
|
|
|
|
$li.addClass("new_messages_fadeout");
|
|
|
|
}
|
|
|
|
function end_animation() {
|
|
|
|
$li.removeClass("new_messages_fadeout");
|
|
|
|
}
|
|
|
|
setTimeout(mid_animation, 3000);
|
|
|
|
setTimeout(end_animation, 6000);
|
|
|
|
}
|
2023-05-02 21:08:15 +02:00
|
|
|
|
2023-08-09 07:23:30 +02:00
|
|
|
export function highlight_inbox_view() {
|
|
|
|
remove($(".top_left_all_messages"));
|
|
|
|
remove($(".top_left_starred_messages"));
|
|
|
|
remove($(".top_left_recent_view"));
|
|
|
|
remove($(".top_left_mentions"));
|
|
|
|
$(".top_left_inbox").addClass("active-filter");
|
|
|
|
setTimeout(() => {
|
|
|
|
resize.resize_stream_filters_container();
|
|
|
|
}, 0);
|
|
|
|
}
|
2023-10-16 21:46:36 +02:00
|
|
|
|
2023-10-23 09:02:57 +02:00
|
|
|
export function handle_home_view_changed(new_home_view) {
|
2023-10-23 21:12:18 +02:00
|
|
|
const $recent_view_sidebar_menu_icon = $(".recent-view-sidebar-menu-icon");
|
|
|
|
const $all_messages_sidebar_menu_icon = $(".all-messages-sidebar-menu-icon");
|
2023-10-23 09:02:57 +02:00
|
|
|
if (new_home_view === settings_config.web_home_view_values.all_messages.code) {
|
2023-10-23 21:12:18 +02:00
|
|
|
$recent_view_sidebar_menu_icon.removeClass("hide");
|
|
|
|
$all_messages_sidebar_menu_icon.addClass("hide");
|
2023-10-23 09:02:57 +02:00
|
|
|
} else if (new_home_view === settings_config.web_home_view_values.recent_topics.code) {
|
2023-10-23 21:12:18 +02:00
|
|
|
$recent_view_sidebar_menu_icon.addClass("hide");
|
|
|
|
$all_messages_sidebar_menu_icon.removeClass("hide");
|
|
|
|
} else {
|
2023-10-23 09:02:57 +02:00
|
|
|
// Inbox is home view.
|
2023-10-23 21:12:18 +02:00
|
|
|
$recent_view_sidebar_menu_icon.removeClass("hide");
|
|
|
|
$all_messages_sidebar_menu_icon.removeClass("hide");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-16 21:46:36 +02:00
|
|
|
export function initialize() {
|
|
|
|
update_scheduled_messages_row();
|
2023-10-16 21:50:48 +02:00
|
|
|
|
|
|
|
$("body").on("click", "#views-label-container", (e) => {
|
|
|
|
if (
|
|
|
|
$(e.currentTarget).hasClass("showing-condensed-navigation") &&
|
|
|
|
!($(e.target).hasClass("sidebar-title") || $(e.target).hasClass("fa-caret-right"))
|
|
|
|
) {
|
|
|
|
// Ignore clicks on condensed nav items
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.stopPropagation();
|
|
|
|
toggle_condensed_navigation_area();
|
|
|
|
});
|
2023-10-16 21:46:36 +02:00
|
|
|
}
|