From 5f5e77afd503e9c2a342425ea533cc23f0ca1731 Mon Sep 17 00:00:00 2001 From: evykassirer Date: Sun, 24 Dec 2023 19:07:52 -0800 Subject: [PATCH] local_message: Convert module to typescript. --- tools/test-js-with-node | 2 +- web/src/{local_message.js => local_message.ts} | 9 +++------ web/src/page_params.ts | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) rename web/src/{local_message.js => local_message.ts} (84%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 45fcc83634..b2f769dce5 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -123,7 +123,7 @@ EXEMPT_FILES = make_set( "web/src/list_util.ts", "web/src/list_widget.ts", "web/src/loading.ts", - "web/src/local_message.js", + "web/src/local_message.ts", "web/src/localstorage.ts", "web/src/message_actions_popover.js", "web/src/message_edit.js", diff --git a/web/src/local_message.js b/web/src/local_message.ts similarity index 84% rename from web/src/local_message.js rename to web/src/local_message.ts index 9bd2e6977e..ccd060f7bf 100644 --- a/web/src/local_message.js +++ b/web/src/local_message.ts @@ -2,19 +2,16 @@ import {all_messages_data} from "./all_messages_data"; import * as blueslip from "./blueslip"; import {page_params} from "./page_params"; -function truncate_precision(float) { +function truncate_precision(float: number): number { return Number.parseFloat(float.toFixed(3)); } export const get_next_id_float = (function () { const already_used = new Set(); - return function () { + return function (): number | undefined { const local_id_increment = 0.01; - let latest = page_params.max_message_id; - if (all_messages_data.last() !== undefined) { - latest = all_messages_data.last().id; - } + let latest = all_messages_data.last()?.id ?? page_params.max_message_id; latest = Math.max(0, latest); const local_id_float = truncate_precision(latest + local_id_increment); diff --git a/web/src/page_params.ts b/web/src/page_params.ts index 068ff2c43f..e6f9df567f 100644 --- a/web/src/page_params.ts +++ b/web/src/page_params.ts @@ -41,6 +41,7 @@ export const page_params: { max_avatar_file_size_mib: number; max_icon_file_size_mib: number; max_logo_file_size_mib: number; + max_message_id: number; muted_users: {id: number; timestamp: number}[]; narrow_stream?: string; narrow: Term[];