2024-06-26 08:34:42 +02:00
|
|
|
import _ from "lodash";
|
2023-12-22 06:02:47 +01:00
|
|
|
import assert from "minimalistic-assert";
|
|
|
|
|
2024-10-01 00:04:14 +02:00
|
|
|
import {electron_bridge} from "./electron_bridge";
|
2023-10-05 23:18:00 +02:00
|
|
|
import * as favicon from "./favicon";
|
2023-12-22 06:02:47 +01:00
|
|
|
import type {Filter} from "./filter";
|
2023-10-05 23:18:00 +02:00
|
|
|
import {$t} from "./i18n";
|
|
|
|
import * as inbox_util from "./inbox_util";
|
|
|
|
import * as people from "./people";
|
|
|
|
import * as recent_view_util from "./recent_view_util";
|
2024-02-13 02:08:24 +01:00
|
|
|
import {realm} from "./state_data";
|
2024-08-03 03:05:34 +02:00
|
|
|
import * as stream_data from "./stream_data";
|
2023-10-05 23:18:00 +02:00
|
|
|
import * as unread from "./unread";
|
2023-12-22 06:02:47 +01:00
|
|
|
import type {FullUnreadCountsData} from "./unread";
|
2023-10-05 23:18:00 +02:00
|
|
|
|
|
|
|
export let unread_count = 0;
|
|
|
|
let pm_count = 0;
|
|
|
|
export let narrow_title = "home";
|
|
|
|
|
2023-12-22 06:02:47 +01:00
|
|
|
export function compute_narrow_title(filter?: Filter): string {
|
2023-10-05 23:18:00 +02:00
|
|
|
if (filter === undefined) {
|
2024-04-02 13:10:48 +02:00
|
|
|
// Views without a message feed in the center pane.
|
2023-10-05 23:18:00 +02:00
|
|
|
if (recent_view_util.is_visible()) {
|
|
|
|
return $t({defaultMessage: "Recent conversations"});
|
|
|
|
}
|
|
|
|
|
2023-12-22 06:02:47 +01:00
|
|
|
assert(inbox_util.is_visible());
|
|
|
|
return $t({defaultMessage: "Inbox"});
|
2023-10-05 23:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const filter_title = filter.get_title();
|
|
|
|
|
|
|
|
if (filter_title === undefined) {
|
|
|
|
// Default result for uncommon narrow/search views.
|
|
|
|
return $t({defaultMessage: "Search results"});
|
|
|
|
}
|
|
|
|
|
2024-04-05 19:41:15 +02:00
|
|
|
if (filter.has_operator("channel")) {
|
2024-08-03 03:05:34 +02:00
|
|
|
const sub = stream_data.get_sub_by_id_string(filter.operands("channel")[0]!);
|
|
|
|
if (!sub) {
|
2023-10-05 23:18:00 +02:00
|
|
|
// The stream is not set because it does not currently
|
2024-08-03 03:05:34 +02:00
|
|
|
// exist, or it is a private stream and the user is not
|
|
|
|
// subscribed.
|
2023-10-05 23:18:00 +02:00
|
|
|
return filter_title;
|
|
|
|
}
|
|
|
|
if (filter.has_operator("topic")) {
|
|
|
|
const topic_name = filter.operands("topic")[0];
|
|
|
|
return "#" + filter_title + " > " + topic_name;
|
|
|
|
}
|
|
|
|
return "#" + filter_title;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter.has_operator("dm")) {
|
2024-05-24 00:02:38 +02:00
|
|
|
const emails = filter.operands("dm")[0]!;
|
2023-10-05 23:18:00 +02:00
|
|
|
const user_ids = people.emails_strings_to_user_ids_string(emails);
|
|
|
|
|
|
|
|
if (user_ids !== undefined) {
|
|
|
|
return people.get_recipients(user_ids);
|
|
|
|
}
|
|
|
|
if (emails.includes(",")) {
|
|
|
|
return $t({defaultMessage: "Invalid users"});
|
|
|
|
}
|
|
|
|
return $t({defaultMessage: "Invalid user"});
|
|
|
|
}
|
|
|
|
|
2024-06-26 08:34:42 +02:00
|
|
|
if (
|
|
|
|
_.isEqual(filter._sorted_term_types, ["sender", "has-reaction"]) &&
|
|
|
|
filter.operands("sender")[0] === people.my_current_email()
|
|
|
|
) {
|
|
|
|
return $t({defaultMessage: "Reactions"});
|
|
|
|
}
|
|
|
|
|
2023-10-05 23:18:00 +02:00
|
|
|
if (filter.has_operator("sender")) {
|
2024-05-24 00:02:38 +02:00
|
|
|
const user = people.get_by_email(filter.operands("sender")[0]!);
|
2023-10-05 23:18:00 +02:00
|
|
|
if (user) {
|
|
|
|
if (people.is_my_user_id(user.user_id)) {
|
|
|
|
return $t({defaultMessage: "Messages sent by you"});
|
|
|
|
}
|
|
|
|
return $t(
|
|
|
|
{defaultMessage: "Messages sent by {sender}"},
|
|
|
|
{
|
|
|
|
sender: user.full_name,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $t({defaultMessage: "Invalid user"});
|
|
|
|
}
|
|
|
|
|
|
|
|
return filter_title;
|
|
|
|
}
|
|
|
|
|
2023-12-22 06:02:47 +01:00
|
|
|
export function redraw_title(): void {
|
2023-10-05 23:18:00 +02:00
|
|
|
// Update window title to reflect unread messages in current view
|
|
|
|
const new_title =
|
|
|
|
(unread_count ? "(" + unread_count + ") " : "") +
|
|
|
|
narrow_title +
|
|
|
|
" - " +
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_name +
|
2023-10-05 23:18:00 +02:00
|
|
|
" - " +
|
|
|
|
"Zulip";
|
|
|
|
|
|
|
|
document.title = new_title;
|
|
|
|
}
|
|
|
|
|
2023-12-22 06:02:47 +01:00
|
|
|
export function update_unread_counts(counts: FullUnreadCountsData): void {
|
2023-10-05 23:18:00 +02:00
|
|
|
const new_unread_count = unread.calculate_notifiable_count(counts);
|
|
|
|
const new_pm_count = counts.direct_message_count;
|
|
|
|
if (new_unread_count === unread_count && new_pm_count === pm_count) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unread_count = new_unread_count;
|
|
|
|
pm_count = new_pm_count;
|
|
|
|
|
|
|
|
// Indicate the message count in the favicon
|
|
|
|
favicon.update_favicon(unread_count, pm_count);
|
|
|
|
|
|
|
|
// Notify the current desktop app's UI about the new unread count.
|
2024-10-01 00:04:14 +02:00
|
|
|
electron_bridge?.send_event("total_unread_count", unread_count);
|
2023-10-05 23:18:00 +02:00
|
|
|
|
2024-10-01 00:04:14 +02:00
|
|
|
// TODO: Add a `electron_bridge.updateDirectMessageCount(new_pm_count);` call?
|
2023-10-05 23:18:00 +02:00
|
|
|
redraw_title();
|
|
|
|
}
|
|
|
|
|
2024-04-04 04:53:12 +02:00
|
|
|
export function update_narrow_title(filter?: Filter): void {
|
2023-10-05 23:18:00 +02:00
|
|
|
narrow_title = compute_narrow_title(filter);
|
|
|
|
redraw_title();
|
|
|
|
}
|