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.

sent_messages: Convert module to TypeScript.

Anders Kaseorg820dcc50a0b4
diff --git a/docs/subsystems/logging.md b/docs/subsystems/logging.md
index c9b4092a7c7..33773b0b0a3 100644
--- a/docs/subsystems/logging.md
+++ b/docs/subsystems/logging.md
@@ -256,7 +256,7 @@ and report to the server the following whenever a message is sent:
the server-rendered content, which can be used for statistics on how
effective our [local echo system](markdown.md) is.
-The code is all in `zerver/lib/report.py` and `web/src/sent_messages.js`.
+The code is all in `zerver/lib/report.py` and `web/src/sent_messages.ts`.
We have similar reporting for the time it takes to narrow / switch to
a new view:
diff --git a/tools/test-js-with-node b/tools/test-js-with-node
index c5cef1c2486..cde1f658385 100755
--- a/tools/test-js-with-node
+++ b/tools/test-js-with-node
@@ -184,7 +184,7 @@ EXEMPT_FILES = make_set(
"web/src/scroll_bar.ts",
"web/src/scroll_util.ts",
"web/src/search.js",
- "web/src/sent_messages.js",
+ "web/src/sent_messages.ts",
"web/src/sentry.ts",
"web/src/server_events.js",
"web/src/settings.js",
diff --git a/web/src/sent_messages.js b/web/src/sent_messages.ts
similarity index 68%
rename from web/src/sent_messages.js
rename to web/src/sent_messages.ts
index 0ca758a0637..4cdf5c4982d 100644
--- a/web/src/sent_messages.js
+++ b/web/src/sent_messages.ts
@@ -3,31 +3,31 @@ import * as Sentry from "@sentry/browser";
import * as blueslip from "./blueslip";
export let next_local_id = 0;
-export const messages = new Map();
+export const messages = new Map<string, MessageState>();
-export function get_new_local_id() {
+export function get_new_local_id(): string {
next_local_id += 1;
const local_id = next_local_id;
return "loc-" + local_id.toString();
}
export class MessageState {
- local_id = undefined;
- locally_echoed = undefined;
+ local_id: string;
+ locally_echoed: boolean;
rendered_changed = false;
server_acked = false;
saw_event = false;
- txn = undefined;
- event_span = undefined;
+ txn: Sentry.Transaction | undefined = undefined;
+ event_span: Sentry.Span | undefined = undefined;
- constructor(opts) {
+ constructor(opts: {local_id: string; locally_echoed: boolean}) {
this.local_id = opts.local_id;
this.locally_echoed = opts.locally_echoed;
}
- start_send() {
+ start_send(): Sentry.Transaction {
this.txn = Sentry.startTransaction({
op: "function",
description: "message send",
@@ -40,16 +40,16 @@ export class MessageState {
return this.txn;
}
- mark_disparity() {
+ mark_disparity(): void {
this.rendered_changed = true;
}
- report_server_ack() {
+ report_server_ack(): void {
this.server_acked = true;
this.maybe_finish_txn();
}
- report_event_received() {
+ report_event_received(): void {
if (!this.event_span) {
return;
}
@@ -58,23 +58,23 @@ export class MessageState {
this.maybe_finish_txn();
}
- maybe_finish_txn() {
+ maybe_finish_txn(): void {
if (!this.saw_event || !this.server_acked) {
return;
}
- const setTag = (name, val) => {
+ const setTag = (name: string, val: boolean): void => {
const str_val = val ? "true" : "false";
- this.event_span.setTag(name, str_val);
- this.txn.setTag(name, str_val);
+ this.event_span!.setTag(name, str_val);
+ this.txn!.setTag(name, str_val);
};
setTag("rendered_changed", this.rendered_changed);
setTag("locally_echoed", this.locally_echoed);
- this.txn.finish();
+ this.txn!.finish();
messages.delete(this.local_id);
}
}
-export function start_tracking_message(opts) {
+export function start_tracking_message(opts: {local_id: string; locally_echoed: boolean}): void {
const local_id = opts.local_id;
if (!opts.local_id) {
@@ -92,7 +92,7 @@ export function start_tracking_message(opts) {
messages.set(local_id, state);
}
-export function get_message_state(local_id) {
+export function get_message_state(local_id: string): MessageState | undefined {
const state = messages.get(local_id);
if (!state) {
@@ -102,7 +102,7 @@ export function get_message_state(local_id) {
return state;
}
-export function start_send(local_id) {
+export function start_send(local_id: string): Sentry.Transaction | undefined {
const state = get_message_state(local_id);
if (!state) {
return undefined;
@@ -111,7 +111,7 @@ export function start_send(local_id) {
return state.start_send();
}
-export function mark_disparity(local_id) {
+export function mark_disparity(local_id: string): void {
const state = get_message_state(local_id);
if (!state) {
return;
@@ -119,7 +119,7 @@ export function mark_disparity(local_id) {
state.mark_disparity();
}
-export function report_event_received(local_id) {
+export function report_event_received(local_id: string): void {
if (local_id === undefined) {
return;
}