Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

local_message: Convert module to typescript.

evykassirer5f5e77afd503
diff --git a/tools/test-js-with-node b/tools/test-js-with-node
index 45fcc836346..b2f769dce56 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 9bd2e6977ea..ccd060f7bf3 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 068ff2c43f1..e6f9df567f5 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[];