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.

refactor: Extract stream_topic_history_util.

Steve Howell12650c1becfe
diff --git a/frontend_tests/node_tests/stream_topic_history.js b/frontend_tests/node_tests/stream_topic_history.js
index 620c34c4058..8cadbb2c167 100644
--- a/frontend_tests/node_tests/stream_topic_history.js
+++ b/frontend_tests/node_tests/stream_topic_history.js
@@ -12,6 +12,7 @@ const all_messages_data = zrequire("all_messages_data");
const unread = zrequire("unread");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
+const stream_topic_history_util = zrequire("stream_topic_history_util");
function test(label, f) {
run_test(label, (override) => {
@@ -313,7 +314,7 @@ test("server_history_end_to_end", () => {
get_success_callback = opts.success;
};
- stream_topic_history.get_server_history(stream_id, () => {
+ stream_topic_history_util.get_server_history(stream_id, () => {
on_success_called = true;
});
@@ -331,7 +332,7 @@ test("server_history_end_to_end", () => {
};
on_success_called = false;
- stream_topic_history.get_server_history(stream_id, () => {
+ stream_topic_history_util.get_server_history(stream_id, () => {
on_success_called = true;
});
assert(on_success_called);
diff --git a/static/js/stream_topic_history.js b/static/js/stream_topic_history.js
index c1dbd601644..5c407d34d89 100644
--- a/static/js/stream_topic_history.js
+++ b/static/js/stream_topic_history.js
@@ -1,5 +1,4 @@
import {all_messages_data} from "./all_messages_data";
-import * as channel from "./channel";
import {FoldDict} from "./fold_dict";
import * as message_util from "./message_util";
import * as stream_data from "./stream_data";
@@ -291,23 +290,8 @@ export function add_history(stream_id, server_history) {
fetched_stream_ids.add(stream_id);
}
-export function get_server_history(stream_id, on_success) {
- if (fetched_stream_ids.has(stream_id)) {
- on_success();
- return;
- }
-
- const url = "/json/users/me/" + stream_id + "/topics";
-
- channel.get({
- url,
- data: {},
- success(data) {
- const server_history = data.topics;
- add_history(stream_id, server_history);
- on_success();
- },
- });
+export function has_history_for(stream_id) {
+ return fetched_stream_ids.has(stream_id);
}
export function get_recent_topic_names(stream_id) {
diff --git a/static/js/stream_topic_history_util.js b/static/js/stream_topic_history_util.js
new file mode 100644
index 00000000000..c6d37758f5a
--- /dev/null
+++ b/static/js/stream_topic_history_util.js
@@ -0,0 +1,21 @@
+import * as channel from "./channel";
+import * as stream_topic_history from "./stream_topic_history";
+
+export function get_server_history(stream_id, on_success) {
+ if (stream_topic_history.has_history_for(stream_id)) {
+ on_success();
+ return;
+ }
+
+ const url = "/json/users/me/" + stream_id + "/topics";
+
+ channel.get({
+ url,
+ data: {},
+ success(data) {
+ const server_history = data.topics;
+ stream_topic_history.add_history(stream_id, server_history);
+ on_success();
+ },
+ });
+}
diff --git a/static/js/topic_list.js b/static/js/topic_list.js
index 7af91704670..aacc9358333 100644
--- a/static/js/topic_list.js
+++ b/static/js/topic_list.js
@@ -10,6 +10,7 @@ import * as narrow from "./narrow";
import * as stream_data from "./stream_data";
import * as stream_popover from "./stream_popover";
import * as stream_topic_history from "./stream_topic_history";
+import * as stream_topic_history_util from "./stream_topic_history_util";
import * as topic_list_data from "./topic_list_data";
import * as ui from "./ui";
import * as vdom from "./vdom";
@@ -251,7 +252,7 @@ export function zoom_in() {
const spinner = true;
active_widget.build(spinner);
- stream_topic_history.get_server_history(stream_id, on_success);
+ stream_topic_history_util.get_server_history(stream_id, on_success);
}
export function initialize() {