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/recent_senders.js to ES6 module.

Anders Kaseorg1b151d0472e6
diff --git a/.eslintrc.json b/.eslintrc.json
index 72fde369675..27efa610a24 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -196,7 +196,6 @@
"realm_icon": false,
"realm_logo": false,
"realm_night_logo": false,
- "recent_senders": false,
"recent_topics": false,
"reload": false,
"reload_state": false,
diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js
index 611bc1eaa70..722a5dec48d 100644
--- a/frontend_tests/node_tests/composebox_typeahead.js
+++ b/frontend_tests/node_tests/composebox_typeahead.js
@@ -50,7 +50,6 @@ const stream_data = zrequire("stream_data");
const user_pill = zrequire("user_pill");
const compose_pm_pill = zrequire("compose_pm_pill");
const composebox_typeahead = zrequire("composebox_typeahead");
-zrequire("recent_senders");
zrequire("settings_org");
const settings_config = zrequire("settings_config");
const pygments_data = zrequire("pygments_data", "generated/pygments_data.json");
diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.js
index 84023d3ad7d..5a20e18a560 100644
--- a/frontend_tests/node_tests/message_events.js
+++ b/frontend_tests/node_tests/message_events.js
@@ -24,7 +24,6 @@ rewiremock.enable();
const message_events = zrequire("message_events");
const message_store = zrequire("message_store");
const people = zrequire("people");
-zrequire("recent_senders");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const unread = zrequire("unread");
diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js
index 76070c8eb9e..d46505ac8ae 100644
--- a/frontend_tests/node_tests/message_store.js
+++ b/frontend_tests/node_tests/message_store.js
@@ -2,6 +2,8 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test");
@@ -14,7 +16,7 @@ set_global("stream_topic_history", {
add_message: noop,
});
-set_global("recent_senders", {
+rewiremock("../../static/js/recent_senders").with({
process_message_for_senders: noop,
});
@@ -23,6 +25,8 @@ set_global("page_params", {
is_admin: true,
});
+rewiremock.enable();
+
const util = zrequire("util");
const people = zrequire("people");
const pm_conversations = zrequire("pm_conversations");
@@ -373,3 +377,4 @@ run_test("errors", () => {
blueslip.expect("error", "message_store.get got bad value: undefined");
message_store.get(undefined);
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js
index 5e38e5d433e..8c4dae0594a 100644
--- a/frontend_tests/node_tests/recent_topics.js
+++ b/frontend_tests/node_tests/recent_topics.js
@@ -51,7 +51,7 @@ set_global("hash_util", {
by_stream_uri: () => "https://www.example.com",
by_stream_topic_uri: () => "https://www.example.com",
});
-set_global("recent_senders", {
+rewiremock("../../static/js/recent_senders").with({
get_topic_recent_senders: () => [1, 2],
});
const ListWidget = set_global("ListWidget", {
diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.js
index 957c7eb44dd..77c81c99b99 100644
--- a/frontend_tests/node_tests/tutorial.js
+++ b/frontend_tests/node_tests/tutorial.js
@@ -138,7 +138,6 @@ const messages = {
// We are going to test a core module called messages_store.js next.
// This is an example of a deep unit test, where our dependencies
// are easy to test. Start by requiring the dependencies:
-zrequire("recent_senders");
const unread = zrequire("unread");
const stream_topic_history = zrequire("stream_topic_history");
const recent_topics = zrequire("recent_topics");
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index fdf2ebc56a5..403e84fc3db 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -19,7 +19,6 @@ import "../input_pill";
import "../setup";
import "../unread_ops";
import "../unread";
-import "../recent_senders";
import "../top_left_corner";
import "../stream_list";
import "../filter";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index e2a4b7970e7..a6604ce6749 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -70,7 +70,6 @@ declare let presence: any;
declare let reactions: any;
declare let realm_icon: any;
declare let realm_logo: any;
-declare let recent_senders: any;
declare let recent_topics: any;
declare let reload: any;
declare let reload_state: any;
diff --git a/static/js/message_events.js b/static/js/message_events.js
index c1e3a8e94c7..f0a32cb46e4 100644
--- a/static/js/message_events.js
+++ b/static/js/message_events.js
@@ -5,6 +5,7 @@ const channel = require("./channel");
const huddle_data = require("./huddle_data");
const message_edit_history = require("./message_edit_history");
const pm_list = require("./pm_list");
+const recent_senders = require("./recent_senders");
const unread_ui = require("./unread_ui");
const util = require("./util");
diff --git a/static/js/message_store.js b/static/js/message_store.js
index 211404ec9bc..459ade3df16 100644
--- a/static/js/message_store.js
+++ b/static/js/message_store.js
@@ -3,6 +3,7 @@
const alert_words = require("./alert_words");
const people = require("./people");
const pm_conversations = require("./pm_conversations");
+const recent_senders = require("./recent_senders");
const util = require("./util");
const stored_messages = new Map();
diff --git a/static/js/recent_senders.js b/static/js/recent_senders.js
index 6b5c666281e..6b25de8ab3a 100644
--- a/static/js/recent_senders.js
+++ b/static/js/recent_senders.js
@@ -1,13 +1,11 @@
-"use strict";
-
-const {FoldDict} = require("./fold_dict");
+import {FoldDict} from "./fold_dict";
// topic_senders[stream_id][topic_id][sender_id] = latest_message_id
const topic_senders = new Map();
// topic_senders[stream_id][sender_id] = latest_message_id
const stream_senders = new Map();
-exports.process_message_for_senders = function (message) {
+export function process_message_for_senders(message) {
const stream_id = message.stream_id;
const topic = message.topic;
@@ -32,9 +30,9 @@ exports.process_message_for_senders = function (message) {
}
stream_senders.set(stream_id, sender_message_ids);
-};
+}
-exports.process_topic_edit = function (old_stream_id, old_topic, new_topic, new_stream_id) {
+export function process_topic_edit(old_stream_id, old_topic, new_topic, new_stream_id) {
// When topic-editing occurs, we need to update the set of known
// senders in each stream/topic pair. This is complicated by the
// fact that the event we receive from the server does not
@@ -55,7 +53,7 @@ exports.process_topic_edit = function (old_stream_id, old_topic, new_topic, new_
// sensibly do with existing data structures.
const old_topic_msgs = message_util.get_messages_in_topic(old_stream_id, old_topic);
for (const msg of old_topic_msgs) {
- exports.process_message_for_senders(msg);
+ process_message_for_senders(msg);
}
// use new_stream_id if topic was moved to a new stream,
@@ -64,16 +62,16 @@ exports.process_topic_edit = function (old_stream_id, old_topic, new_topic, new_
new_stream_id = new_stream_id || old_stream_id;
const new_topic_msgs = message_util.get_messages_in_topic(new_stream_id, new_topic);
for (const msg of new_topic_msgs) {
- exports.process_message_for_senders(msg);
+ process_message_for_senders(msg);
}
// Note that we don't delete anything from stream_senders here.
// Our view is that it's probably better to not do so; users who
// recently posted to a stream are relevant for typeahead even if
// the messages were moved to another stream or deleted.
-};
+}
-exports.update_topics_of_deleted_message_ids = function (message_ids) {
+export function update_topics_of_deleted_message_ids(message_ids) {
const topics_to_update = message_util.get_topics_for_message_ids(message_ids);
for (const [stream_id, topic] of topics_to_update.values()) {
@@ -81,12 +79,12 @@ exports.update_topics_of_deleted_message_ids = function (message_ids) {
topic_dict.delete(topic);
const topic_msgs = message_util.get_messages_in_topic(stream_id, topic);
for (const msg of topic_msgs) {
- exports.process_message_for_senders(msg);
+ process_message_for_senders(msg);
}
}
-};
+}
-exports.compare_by_recency = function (user_a, user_b, stream_id, topic) {
+export function compare_by_recency(user_a, user_b, stream_id, topic) {
let a_message_id;
let b_message_id;
@@ -115,9 +113,9 @@ exports.compare_by_recency = function (user_a, user_b, stream_id, topic) {
}
return 0;
-};
+}
-exports.get_topic_recent_senders = function (stream_id, topic) {
+export function get_topic_recent_senders(stream_id, topic) {
const topic_dict = topic_senders.get(stream_id);
if (topic_dict === undefined) {
return [];
@@ -134,6 +132,4 @@ exports.get_topic_recent_senders = function (stream_id, topic) {
recent_senders.push(item[0]);
}
return recent_senders;
-};
-
-window.recent_senders = exports;
+}
diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js
index c08e480cbac..5f8f09e5b6b 100644
--- a/static/js/recent_topics.js
+++ b/static/js/recent_topics.js
@@ -8,6 +8,7 @@ const drafts = require("./drafts");
const {localstorage} = require("./localstorage");
const muting = require("./muting");
const people = require("./people");
+const recent_senders = require("./recent_senders");
const topics = new Map(); // Key is stream-id:topic.
let topics_widget;
diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js
index f0db218a354..c87691a3374 100644
--- a/static/js/typeahead_helper.js
+++ b/static/js/typeahead_helper.js
@@ -10,6 +10,7 @@ const render_typeahead_list_item = require("../templates/typeahead_list_item.hbs
const people = require("./people");
const pm_conversations = require("./pm_conversations");
+const recent_senders = require("./recent_senders");
const settings_data = require("./settings_data");
const user_groups = require("./user_groups");
const util = require("./util");