mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 23:43:43 +00:00
activity_ui: Convert module to typescript.
This commit is contained in:
@@ -13,30 +13,34 @@ import * as people from "./people";
|
||||
import * as pm_list from "./pm_list";
|
||||
import * as popovers from "./popovers";
|
||||
import * as presence from "./presence";
|
||||
import type {PresenceInfoFromEvent} from "./presence";
|
||||
import * as sidebar_ui from "./sidebar_ui";
|
||||
import {realm} from "./state_data";
|
||||
import * as ui_util from "./ui_util";
|
||||
import type {FullUnreadCountsData} from "./unread";
|
||||
import {UserSearch} from "./user_search";
|
||||
import * as util from "./util";
|
||||
|
||||
export let user_cursor;
|
||||
export let user_filter;
|
||||
export let user_cursor: ListCursor<number> | undefined;
|
||||
export let user_filter: UserSearch | undefined;
|
||||
|
||||
// Function initialized from `ui_init` to avoid importing narrow.js and causing circular imports.
|
||||
let narrow_by_email;
|
||||
let narrow_by_email: (email: string) => void;
|
||||
|
||||
function get_pm_list_item(user_id) {
|
||||
function get_pm_list_item(user_id: string): JQuery | undefined {
|
||||
return buddy_list.find_li({
|
||||
key: user_id,
|
||||
key: Number.parseInt(user_id, 10),
|
||||
});
|
||||
}
|
||||
|
||||
function set_pm_count(user_ids_string, count) {
|
||||
function set_pm_count(user_ids_string: string, count: number): void {
|
||||
const $pm_li = get_pm_list_item(user_ids_string);
|
||||
ui_util.update_unread_count_in_dom($pm_li, count);
|
||||
if ($pm_li !== undefined) {
|
||||
ui_util.update_unread_count_in_dom($pm_li, count);
|
||||
}
|
||||
}
|
||||
|
||||
export function update_dom_with_unread_counts(counts) {
|
||||
export function update_dom_with_unread_counts(counts: FullUnreadCountsData): void {
|
||||
// counts is just a data object that gets calculated elsewhere
|
||||
// Our job is to update some DOM elements.
|
||||
|
||||
@@ -49,12 +53,12 @@ export function update_dom_with_unread_counts(counts) {
|
||||
}
|
||||
}
|
||||
|
||||
export function clear_for_testing() {
|
||||
export function clear_for_testing(): void {
|
||||
user_cursor = undefined;
|
||||
user_filter = undefined;
|
||||
}
|
||||
|
||||
export function redraw_user(user_id) {
|
||||
export function redraw_user(user_id: number): void {
|
||||
if (realm.realm_presence_disabled) {
|
||||
return;
|
||||
}
|
||||
@@ -73,11 +77,11 @@ export function redraw_user(user_id) {
|
||||
});
|
||||
}
|
||||
|
||||
export function searching() {
|
||||
return user_filter && user_filter.searching();
|
||||
export function searching(): boolean {
|
||||
return user_filter?.searching() ?? false;
|
||||
}
|
||||
|
||||
export function render_empty_user_list_message_if_needed($container) {
|
||||
export function render_empty_user_list_message_if_needed($container: JQuery): void {
|
||||
const empty_list_message = $container.data("search-results-empty");
|
||||
|
||||
if (!empty_list_message || $container.children().length) {
|
||||
@@ -88,11 +92,12 @@ export function render_empty_user_list_message_if_needed($container) {
|
||||
$container.append(empty_list_widget);
|
||||
}
|
||||
|
||||
export function build_user_sidebar() {
|
||||
export function build_user_sidebar(): number[] | undefined {
|
||||
if (realm.realm_presence_disabled) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
assert(user_filter !== undefined);
|
||||
const filter_text = user_filter.text();
|
||||
|
||||
const all_user_ids = buddy_data.get_filtered_and_sorted_user_ids(filter_text);
|
||||
@@ -105,17 +110,18 @@ export function build_user_sidebar() {
|
||||
return all_user_ids; // for testing
|
||||
}
|
||||
|
||||
function do_update_users_for_search() {
|
||||
function do_update_users_for_search(): void {
|
||||
// Hide all the popovers but not userlist sidebar
|
||||
// when the user is searching.
|
||||
popovers.hide_all();
|
||||
build_user_sidebar();
|
||||
assert(user_cursor !== undefined);
|
||||
user_cursor.reset();
|
||||
}
|
||||
|
||||
const update_users_for_search = _.throttle(do_update_users_for_search, 50);
|
||||
|
||||
export function initialize(opts) {
|
||||
export function initialize(opts: {narrow_by_email: (email: string) => void}): void {
|
||||
narrow_by_email = opts.narrow_by_email;
|
||||
|
||||
set_cursor_and_filter();
|
||||
@@ -124,7 +130,7 @@ export function initialize(opts) {
|
||||
|
||||
buddy_list.start_scroll_handler();
|
||||
|
||||
function get_full_presence_list_update() {
|
||||
function get_full_presence_list_update(): void {
|
||||
activity.send_presence_to_server(redraw);
|
||||
}
|
||||
|
||||
@@ -137,7 +143,11 @@ export function initialize(opts) {
|
||||
activity.send_presence_to_server();
|
||||
}
|
||||
|
||||
export function update_presence_info(user_id, info, server_time) {
|
||||
export function update_presence_info(
|
||||
user_id: number,
|
||||
info: PresenceInfoFromEvent,
|
||||
server_time: number,
|
||||
): void {
|
||||
// There can be some case where the presence event
|
||||
// was set for an inaccessible user if
|
||||
// CAN_ACCESS_ALL_USERS_GROUP_LIMITS_PRESENCE is
|
||||
@@ -152,33 +162,37 @@ export function update_presence_info(user_id, info, server_time) {
|
||||
pm_list.update_private_messages();
|
||||
}
|
||||
|
||||
export function redraw() {
|
||||
export function redraw(): void {
|
||||
build_user_sidebar();
|
||||
assert(user_cursor !== undefined);
|
||||
user_cursor.redraw();
|
||||
pm_list.update_private_messages();
|
||||
}
|
||||
|
||||
export function reset_users() {
|
||||
export function reset_users(): void {
|
||||
// Call this when we're leaving the search widget.
|
||||
build_user_sidebar();
|
||||
assert(user_cursor !== undefined);
|
||||
user_cursor.clear();
|
||||
}
|
||||
|
||||
export function narrow_for_user(opts) {
|
||||
export function narrow_for_user(opts: {$li: JQuery}): void {
|
||||
const user_id = buddy_list.get_user_id_from_li({$li: opts.$li});
|
||||
return narrow_for_user_id({user_id});
|
||||
narrow_for_user_id({user_id});
|
||||
}
|
||||
|
||||
export function narrow_for_user_id(opts) {
|
||||
export function narrow_for_user_id(opts: {user_id: number}): void {
|
||||
const person = people.get_by_user_id(opts.user_id);
|
||||
const email = person.email;
|
||||
|
||||
assert(narrow_by_email);
|
||||
narrow_by_email(email);
|
||||
assert(user_filter !== undefined);
|
||||
user_filter.clear_and_hide_search();
|
||||
}
|
||||
|
||||
function keydown_enter_key() {
|
||||
function keydown_enter_key(): void {
|
||||
assert(user_cursor !== undefined);
|
||||
const user_id = user_cursor.get_key();
|
||||
if (user_id === undefined) {
|
||||
return;
|
||||
@@ -189,7 +203,7 @@ function keydown_enter_key() {
|
||||
popovers.hide_all();
|
||||
}
|
||||
|
||||
export function set_cursor_and_filter() {
|
||||
export function set_cursor_and_filter(): void {
|
||||
user_cursor = new ListCursor({
|
||||
list: buddy_list,
|
||||
highlight_class: "highlighted_user",
|
||||
@@ -198,12 +212,16 @@ export function set_cursor_and_filter() {
|
||||
user_filter = new UserSearch({
|
||||
update_list: update_users_for_search,
|
||||
reset_items: reset_users,
|
||||
on_focus: () => user_cursor.reset(),
|
||||
on_focus() {
|
||||
user_cursor!.reset();
|
||||
},
|
||||
});
|
||||
|
||||
const $input = user_filter.input_field();
|
||||
|
||||
$input.on("blur", () => user_cursor.clear());
|
||||
$input.on("blur", () => {
|
||||
user_cursor!.clear();
|
||||
});
|
||||
|
||||
keydown_util.handle({
|
||||
$elem: $input,
|
||||
@@ -213,31 +231,31 @@ export function set_cursor_and_filter() {
|
||||
return true;
|
||||
},
|
||||
ArrowUp() {
|
||||
user_cursor.prev();
|
||||
user_cursor!.prev();
|
||||
return true;
|
||||
},
|
||||
ArrowDown() {
|
||||
user_cursor.next();
|
||||
user_cursor!.next();
|
||||
return true;
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function initiate_search() {
|
||||
export function initiate_search(): void {
|
||||
if (user_filter) {
|
||||
popovers.hide_all();
|
||||
user_filter.initiate_search();
|
||||
}
|
||||
}
|
||||
|
||||
export function escape_search() {
|
||||
export function escape_search(): void {
|
||||
if (user_filter) {
|
||||
user_filter.clear_and_hide_search();
|
||||
}
|
||||
}
|
||||
|
||||
export function get_filter_text() {
|
||||
export function get_filter_text(): string {
|
||||
if (!user_filter) {
|
||||
// This may be overly defensive, but there may be
|
||||
// situations where get called before everything is
|
||||
@@ -13,7 +13,7 @@ export type PresenceStatus = {
|
||||
last_active?: number;
|
||||
};
|
||||
|
||||
type PresenceInfoFromEvent = {
|
||||
export type PresenceInfoFromEvent = {
|
||||
website: {
|
||||
client: "website";
|
||||
status: "idle" | "active";
|
||||
|
||||
Reference in New Issue
Block a user