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.

message view: Fix link generation logic of the end of results notice.

Ryan Rehmand59ccd4c0f38
diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js
index 26a9e5fafc8..cd35de6659d 100644
--- a/frontend_tests/node_tests/hash_util.js
+++ b/frontend_tests/node_tests/hash_util.js
@@ -2,6 +2,8 @@
zrequire('hash_util');
zrequire('stream_data');
zrequire('people');
+zrequire('Filter', 'js/filter');
+zrequire('narrow_state');
set_global('location', {
protocol: "https:",
@@ -161,3 +163,23 @@ run_test('test_by_conversation_and_time_uri', () => {
assert.equal(hash_util.by_conversation_and_time_uri(message),
'https://example.com/#narrow/pm-with/1-pm/near/43');
});
+
+run_test('test_search_public_streams_notice_url', () => {
+ function set_uri(uri) {
+ const operators = hash_util.parse_narrow(uri.split('/'));
+ narrow_state.set_current_filter(new Filter(operators));
+ }
+
+ set_uri("#narrow/search/abc");
+ assert.equal(hash_util.search_public_streams_notice_url(),
+ "#narrow/streams/public/search/abc");
+
+
+ set_uri("#narrow/has/link/has/image/has/attachment");
+ assert.equal(hash_util.search_public_streams_notice_url(),
+ "#narrow/streams/public/has/link/has/image/has/attachment");
+
+ set_uri("#narrow/sender/15");
+ assert.equal(hash_util.search_public_streams_notice_url(),
+ "#narrow/streams/public/sender/15");
+});
diff --git a/static/js/hash_util.js b/static/js/hash_util.js
index 5013330471d..083b2c33f90 100644
--- a/static/js/hash_util.js
+++ b/static/js/hash_util.js
@@ -148,6 +148,13 @@ exports.stream_edit_uri = function (sub) {
return hash;
};
+exports.search_public_streams_notice_url = function () {
+ // Computes the URL of the current narrow if streams:public were added.
+ const operators = narrow_state.filter().operators();
+ const public_operator = {operator: 'streams', operand: 'public'};
+ return exports.operators_to_hash([public_operator].concat(operators));
+};
+
exports.parse_narrow = function (hash) {
let i;
const operators = [];
diff --git a/static/js/message_scroll.js b/static/js/message_scroll.js
index 78be8c07ebe..6e2bb790b41 100644
--- a/static/js/message_scroll.js
+++ b/static/js/message_scroll.js
@@ -70,9 +70,8 @@ exports.show_end_of_results_notice = function () {
// It's a bit hacky to use the href, but
// !filter.includes_full_stream_history() implies streams:public
// wasn't already present.
- $(".all-messages-search-caution a.search-shared-history").attr(
- "href", window.location.hash.replace("#narrow/", "#narrow/streams/public/")
- );
+ const update_hash = hash_util.search_public_streams_notice_url();
+ $(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
};
exports.update_top_of_narrow_notices = function (msg_list) {