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.

js: Convert static/js/typing_events.js to ES6 module.

Anders Kaseorgb9e1d320e8c9
diff --git a/.eslintrc.json b/.eslintrc.json
index 997bc311e96..4a45fde58d6 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -156,7 +156,6 @@
"stream_list": false,
"StripeCheckout": false,
"subs": false,
- "typing_events": false,
"ui": false,
"ui_init": false,
"unread": false,
diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js
index 2152196ec1f..07e55cd6fca 100644
--- a/frontend_tests/node_tests/dispatch.js
+++ b/frontend_tests/node_tests/dispatch.js
@@ -88,7 +88,8 @@ const stream_events = {__esModule: true};
rewiremock("../../static/js/stream_events").with(stream_events);
const submessage = {__esModule: true};
rewiremock("../../static/js/submessage").with(submessage);
-const typing_events = set_global("typing_events", {});
+const typing_events = {__esModule: true};
+rewiremock("../../static/js/typing_events").with(typing_events);
const ui = set_global("ui", {});
const unread_ops = set_global("unread_ops", {});
const user_events = {__esModule: true};
diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js
index 85d6c704643..4f381061d97 100644
--- a/frontend_tests/node_tests/narrow_activate.js
+++ b/frontend_tests/node_tests/narrow_activate.js
@@ -40,7 +40,8 @@ const message_view_header = {__esModule: true};
rewiremock("../../static/js/message_view_header").with(message_view_header);
const top_left_corner = {__esModule: true};
rewiremock("../../static/js/top_left_corner").with(top_left_corner);
-const typing_events = set_global("typing_events", {});
+const typing_events = {__esModule: true};
+rewiremock("../../static/js/typing_events").with(typing_events);
const ui_util = {__esModule: true};
rewiremock("../../static/js/ui_util").with(ui_util);
const unread_ops = set_global("unread_ops", {});
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index e585f4b9781..3c5f6021690 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -37,7 +37,6 @@ import "../templates";
import "../dropdown_list_widget";
import "../settings_profile_fields";
import "../settings";
-import "../typing_events";
import "../ui_init";
import "../emoji_picker";
import "../compose_ui";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 7dc814e4854..3555bed33b8 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -27,7 +27,6 @@ declare let search_pill_widget: any;
declare let settings_profile_fields: any;
declare let stream_list: any;
declare let subs: any;
-declare let typing_events: any;
declare let ui: any;
declare let unread: any;
declare let unread_ops: any;
diff --git a/static/js/narrow.js b/static/js/narrow.js
index 4d27babd1e8..2ef8a0f5fb1 100644
--- a/static/js/narrow.js
+++ b/static/js/narrow.js
@@ -23,6 +23,7 @@ const stream_data = require("./stream_data");
const stream_topic_history = require("./stream_topic_history");
const top_left_corner = require("./top_left_corner");
const topic_generator = require("./topic_generator");
+const typing_events = require("./typing_events");
const ui_util = require("./ui_util");
const util = require("./util");
diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js
index 074da3a603a..cdeea3ca106 100644
--- a/static/js/server_events_dispatch.js
+++ b/static/js/server_events_dispatch.js
@@ -41,6 +41,7 @@ import * as stream_data from "./stream_data";
import * as stream_events from "./stream_events";
import * as stream_topic_history from "./stream_topic_history";
import * as submessage from "./submessage";
+import * as typing_events from "./typing_events";
import * as user_events from "./user_events";
import * as user_groups from "./user_groups";
import * as user_status from "./user_status";
diff --git a/static/js/typing_events.js b/static/js/typing_events.js
index c63a30a5c4b..3a59448cc0c 100644
--- a/static/js/typing_events.js
+++ b/static/js/typing_events.js
@@ -1,10 +1,8 @@
-"use strict";
+import render_typing_notifications from "../templates/typing_notifications.hbs";
-const render_typing_notifications = require("../templates/typing_notifications.hbs");
-
-const narrow_state = require("./narrow_state");
-const people = require("./people");
-const typing_data = require("./typing_data");
+import * as narrow_state from "./narrow_state";
+import * as people from "./people";
+import * as typing_data from "./typing_data";
// See docs/subsystems/typing-indicators.md for details on typing indicators.
@@ -46,7 +44,7 @@ function get_users_typing_for_narrow() {
return typing_data.get_all_typists();
}
-exports.render_notifications_for_narrow = function () {
+export function render_notifications_for_narrow() {
const user_ids = get_users_typing_for_narrow();
const users_typing = user_ids.map((user_id) => people.get_by_user_id(user_id));
if (users_typing.length === 0) {
@@ -55,9 +53,9 @@ exports.render_notifications_for_narrow = function () {
$("#typing_notifications").html(render_typing_notifications({users: users_typing}));
$("#typing_notifications").show();
}
-};
+}
-exports.hide_notification = function (event) {
+export function hide_notification(event) {
const recipients = event.recipients.map((user) => user.user_id);
recipients.sort();
@@ -66,11 +64,11 @@ exports.hide_notification = function (event) {
const removed = typing_data.remove_typist(recipients, event.sender.user_id);
if (removed) {
- exports.render_notifications_for_narrow();
+ render_notifications_for_narrow();
}
-};
+}
-exports.display_notification = function (event) {
+export function display_notification(event) {
const recipients = event.recipients.map((user) => user.user_id);
recipients.sort();
@@ -79,10 +77,9 @@ exports.display_notification = function (event) {
typing_data.add_typist(recipients, sender_id);
- exports.render_notifications_for_narrow();
+ render_notifications_for_narrow();
typing_data.kickstart_inbound_timer(recipients, TYPING_STARTED_EXPIRY_PERIOD, () => {
- exports.hide_notification(event);
+ hide_notification(event);
});
-};
-window.typing_events = exports;
+}