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.

typing: Do direct func calls to stop typing status on compose event.

Pratik Chanda7978cf72f4e4
diff --git a/web/src/compose.ts b/web/src/compose.ts
index 24b7aa8e631..1abc3f1cc5a 100644
--- a/web/src/compose.ts
+++ b/web/src/compose.ts
@@ -26,6 +26,7 @@ import * as sent_messages from "./sent_messages.ts";
import * as server_events_state from "./server_events_state.ts";
import {current_user} from "./state_data.ts";
import * as transmit from "./transmit.ts";
+import * as typing from "./typing.ts";
import {user_settings} from "./user_settings.ts";
import * as util from "./util.ts";
import * as zcommand from "./zcommand.ts";
@@ -402,6 +403,7 @@ export function do_post_send_tasks(): void {
// TODO: Do we want to fire the event even if the send failed due
// to a server-side error?
$(document).trigger("compose_finished.zulip");
+ typing.stop_typing_notifications();
reload.maybe_reset_pending_reload_timeout("compose_end");
}
diff --git a/web/src/typing.ts b/web/src/typing.ts
index 41b403c1972..b04ca50f22c 100644
--- a/web/src/typing.ts
+++ b/web/src/typing.ts
@@ -4,6 +4,7 @@ import assert from "minimalistic-assert";
import * as blueslip from "./blueslip.ts";
import * as channel from "./channel.ts";
+import * as compose_actions from "./compose_actions.ts";
import * as compose_pm_pill from "./compose_pm_pill.ts";
import * as compose_state from "./compose_state.ts";
import * as message_store from "./message_store.ts";
@@ -11,11 +12,12 @@ import * as people from "./people.ts";
import * as rows from "./rows.ts";
import {realm} from "./state_data.ts";
import * as stream_data from "./stream_data.ts";
-import type {EditingStatusWorker, Recipient} from "./typing_status.ts";
+import type {EditingStatusWorker, Recipient, TypingStatusWorker} from "./typing_status.ts";
import * as typing_status from "./typing_status.ts";
import {user_settings} from "./user_settings.ts";
let edit_box_worker: EditingStatusWorker;
+let worker: TypingStatusWorker;
type TypingAPIRequest = {op: "start" | "stop"} & (
| {
@@ -205,6 +207,15 @@ export function get_recipient(): Recipient | null {
return null;
}
+export function stop_typing_notifications(): void {
+ typing_status.update(
+ worker,
+ null,
+ realm.server_typing_started_wait_period_milliseconds,
+ realm.server_typing_stopped_wait_period_milliseconds,
+ );
+}
+
function get_message_edit_recipient(message_id: number): Recipient {
return {
notification_event_type: "typing_message_edit",
@@ -223,7 +234,7 @@ export function stop_message_edit_notifications(message_id: number): void {
}
export function initialize(): void {
- const worker = {
+ worker = {
get_current_time,
notify_server_start,
notify_server_stop,
@@ -266,12 +277,5 @@ export function initialize(): void {
// We send a stop-typing notification immediately when compose is
// closed/cancelled
- $(document).on("compose_canceled.zulip compose_finished.zulip", () => {
- typing_status.update(
- worker,
- null,
- realm.server_typing_started_wait_period_milliseconds,
- realm.server_typing_stopped_wait_period_milliseconds,
- );
- });
+ compose_actions.register_compose_cancel_hook(stop_typing_notifications);
}
diff --git a/web/src/typing_status.ts b/web/src/typing_status.ts
index d1ae74c6ed1..4c3232dd840 100644
--- a/web/src/typing_status.ts
+++ b/web/src/typing_status.ts
@@ -20,7 +20,7 @@ export type Recipient =
message_id: number;
};
-type TypingStatusWorker = {
+export type TypingStatusWorker = {
get_current_time: () => number;
notify_server_start: (recipient: Recipient) => void;
notify_server_stop: (recipient: Recipient) => void;