mirror of https://github.com/zulip/zulip.git
sent_messages: Convert module to TypeScript.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
082a291bd1
commit
820dcc50a0
|
@ -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
|
the server-rendered content, which can be used for statistics on how
|
||||||
effective our [local echo system](markdown.md) is.
|
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
|
We have similar reporting for the time it takes to narrow / switch to
|
||||||
a new view:
|
a new view:
|
||||||
|
|
|
@ -184,7 +184,7 @@ EXEMPT_FILES = make_set(
|
||||||
"web/src/scroll_bar.ts",
|
"web/src/scroll_bar.ts",
|
||||||
"web/src/scroll_util.ts",
|
"web/src/scroll_util.ts",
|
||||||
"web/src/search.js",
|
"web/src/search.js",
|
||||||
"web/src/sent_messages.js",
|
"web/src/sent_messages.ts",
|
||||||
"web/src/sentry.ts",
|
"web/src/sentry.ts",
|
||||||
"web/src/server_events.js",
|
"web/src/server_events.js",
|
||||||
"web/src/settings.js",
|
"web/src/settings.js",
|
||||||
|
|
|
@ -3,31 +3,31 @@ import * as Sentry from "@sentry/browser";
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
|
|
||||||
export let next_local_id = 0;
|
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;
|
next_local_id += 1;
|
||||||
const local_id = next_local_id;
|
const local_id = next_local_id;
|
||||||
return "loc-" + local_id.toString();
|
return "loc-" + local_id.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MessageState {
|
export class MessageState {
|
||||||
local_id = undefined;
|
local_id: string;
|
||||||
locally_echoed = undefined;
|
locally_echoed: boolean;
|
||||||
rendered_changed = false;
|
rendered_changed = false;
|
||||||
|
|
||||||
server_acked = false;
|
server_acked = false;
|
||||||
saw_event = false;
|
saw_event = false;
|
||||||
|
|
||||||
txn = undefined;
|
txn: Sentry.Transaction | undefined = undefined;
|
||||||
event_span = undefined;
|
event_span: Sentry.Span | undefined = undefined;
|
||||||
|
|
||||||
constructor(opts) {
|
constructor(opts: {local_id: string; locally_echoed: boolean}) {
|
||||||
this.local_id = opts.local_id;
|
this.local_id = opts.local_id;
|
||||||
this.locally_echoed = opts.locally_echoed;
|
this.locally_echoed = opts.locally_echoed;
|
||||||
}
|
}
|
||||||
|
|
||||||
start_send() {
|
start_send(): Sentry.Transaction {
|
||||||
this.txn = Sentry.startTransaction({
|
this.txn = Sentry.startTransaction({
|
||||||
op: "function",
|
op: "function",
|
||||||
description: "message send",
|
description: "message send",
|
||||||
|
@ -40,16 +40,16 @@ export class MessageState {
|
||||||
return this.txn;
|
return this.txn;
|
||||||
}
|
}
|
||||||
|
|
||||||
mark_disparity() {
|
mark_disparity(): void {
|
||||||
this.rendered_changed = true;
|
this.rendered_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
report_server_ack() {
|
report_server_ack(): void {
|
||||||
this.server_acked = true;
|
this.server_acked = true;
|
||||||
this.maybe_finish_txn();
|
this.maybe_finish_txn();
|
||||||
}
|
}
|
||||||
|
|
||||||
report_event_received() {
|
report_event_received(): void {
|
||||||
if (!this.event_span) {
|
if (!this.event_span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -58,23 +58,23 @@ export class MessageState {
|
||||||
this.maybe_finish_txn();
|
this.maybe_finish_txn();
|
||||||
}
|
}
|
||||||
|
|
||||||
maybe_finish_txn() {
|
maybe_finish_txn(): void {
|
||||||
if (!this.saw_event || !this.server_acked) {
|
if (!this.saw_event || !this.server_acked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const setTag = (name, val) => {
|
const setTag = (name: string, val: boolean): void => {
|
||||||
const str_val = val ? "true" : "false";
|
const str_val = val ? "true" : "false";
|
||||||
this.event_span.setTag(name, str_val);
|
this.event_span!.setTag(name, str_val);
|
||||||
this.txn.setTag(name, str_val);
|
this.txn!.setTag(name, str_val);
|
||||||
};
|
};
|
||||||
setTag("rendered_changed", this.rendered_changed);
|
setTag("rendered_changed", this.rendered_changed);
|
||||||
setTag("locally_echoed", this.locally_echoed);
|
setTag("locally_echoed", this.locally_echoed);
|
||||||
this.txn.finish();
|
this.txn!.finish();
|
||||||
messages.delete(this.local_id);
|
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;
|
const local_id = opts.local_id;
|
||||||
|
|
||||||
if (!opts.local_id) {
|
if (!opts.local_id) {
|
||||||
|
@ -92,7 +92,7 @@ export function start_tracking_message(opts) {
|
||||||
messages.set(local_id, state);
|
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);
|
const state = messages.get(local_id);
|
||||||
|
|
||||||
if (!state) {
|
if (!state) {
|
||||||
|
@ -102,7 +102,7 @@ export function get_message_state(local_id) {
|
||||||
return state;
|
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);
|
const state = get_message_state(local_id);
|
||||||
if (!state) {
|
if (!state) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -111,7 +111,7 @@ export function start_send(local_id) {
|
||||||
return state.start_send();
|
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);
|
const state = get_message_state(local_id);
|
||||||
if (!state) {
|
if (!state) {
|
||||||
return;
|
return;
|
||||||
|
@ -119,7 +119,7 @@ export function mark_disparity(local_id) {
|
||||||
state.mark_disparity();
|
state.mark_disparity();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function report_event_received(local_id) {
|
export function report_event_received(local_id: string): void {
|
||||||
if (local_id === undefined) {
|
if (local_id === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
Loading…
Reference in New Issue