From c91ca3eca8d53c53e4f59aebafe8fbd2e0a465e0 Mon Sep 17 00:00:00 2001 From: Varun Singh Date: Tue, 20 Feb 2024 16:09:39 +0530 Subject: [PATCH] message_live_update: Convert module to TypeScript. --- tools/test-js-with-node | 2 +- ..._live_update.js => message_live_update.ts} | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) rename web/src/{message_live_update.js => message_live_update.ts} (79%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 38458980f1..93ef7c6e5e 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -139,7 +139,7 @@ EXEMPT_FILES = make_set( "web/src/message_list_tooltips.js", "web/src/message_list_view.js", "web/src/message_lists.ts", - "web/src/message_live_update.js", + "web/src/message_live_update.ts", "web/src/message_notifications.js", "web/src/message_scroll.js", "web/src/message_scroll_state.ts", diff --git a/web/src/message_live_update.js b/web/src/message_live_update.ts similarity index 79% rename from web/src/message_live_update.js rename to web/src/message_live_update.ts index d59dfaf511..578fbba965 100644 --- a/web/src/message_live_update.js +++ b/web/src/message_live_update.ts @@ -2,13 +2,13 @@ import * as message_lists from "./message_lists"; import * as message_store from "./message_store"; import * as people from "./people"; -export function rerender_messages_view() { +export function rerender_messages_view(): void { for (const list of message_lists.all_rendered_message_lists()) { list.rerender_view(); } } -export function rerender_messages_view_by_message_ids(message_ids) { +export function rerender_messages_view_by_message_ids(message_ids: number[]): void { const messages_to_render = []; for (const id of message_ids) { const message = message_store.get(id); @@ -21,7 +21,7 @@ export function rerender_messages_view_by_message_ids(message_ids) { } } -function rerender_messages_view_for_user(user_id) { +function rerender_messages_view_for_user(user_id: number): void { for (const list of message_lists.all_rendered_message_lists()) { const messages = list.data.get_messages_sent_by_user(user_id); if (messages.length === 0) { @@ -31,7 +31,10 @@ function rerender_messages_view_for_user(user_id) { } } -export function update_message_in_all_views(message_id, callback) { +export function update_message_in_all_views( + message_id: number, + callback: ($row: JQuery) => void, +): void { for (const msg_list of message_lists.all_rendered_message_lists()) { const $row = msg_list.get_row(message_id); if ($row === undefined) { @@ -43,7 +46,7 @@ export function update_message_in_all_views(message_id, callback) { } } -export function update_starred_view(message_id, new_value) { +export function update_starred_view(message_id: number, new_value: boolean): void { const starred = new_value; // Avoid a full re-render, but update the star in each message @@ -65,24 +68,24 @@ export function update_starred_view(message_id, new_value) { }); } -export function update_stream_name(stream_id, new_name) { +export function update_stream_name(stream_id: number, new_name: string): void { message_store.update_stream_name(stream_id, new_name); rerender_messages_view(); } -export function update_user_full_name(user_id, full_name) { +export function update_user_full_name(user_id: number, full_name: string): void { message_store.update_sender_full_name(user_id, full_name); rerender_messages_view_for_user(user_id); } -export function update_avatar(user_id, avatar_url) { +export function update_avatar(user_id: number, avatar_url: string): void { let url = avatar_url; url = people.format_small_avatar_url(url); message_store.update_small_avatar_url(user_id, url); rerender_messages_view_for_user(user_id); } -export function update_user_status_emoji(user_id, status_emoji_info) { +export function update_user_status_emoji(user_id: number, status_emoji_info: string): void { message_store.update_status_emoji_info(user_id, status_emoji_info); rerender_messages_view_for_user(user_id); }