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_fetch: For spectators, add web-public to narrow.

Aman Agrawald6541c4724d8
diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js
index c2abdcf091e..1cd374d9355 100644
--- a/static/js/message_fetch.js
+++ b/static/js/message_fetch.js
@@ -240,6 +240,28 @@ export function load_messages(opts) {
data.client_gravatar = true;
data = handle_operators_supporting_id_based_api(data);
+ if (page_params.is_spectator) {
+ // This is a bit of a hack; ideally we'd unify this logic in
+ // some way with the above logic, and not need to do JSON
+ // parsing/stringifying here.
+ const web_public_narrow = {negated: false, operator: "streams", operand: "web-public"};
+
+ if (!data.narrow) {
+ /* For the "All messages" feed, this will be the only operator. */
+ data.narrow = JSON.stringify([web_public_narrow]);
+ } else {
+ // Otherwise, we append the operator. This logic is not
+ // ideal in that in theory an existing `streams:` operator
+ // could be present, but not in a useful way. We don't
+ // attempt to validate the narrow is compatible with
+ // spectators here; the server will return an error if
+ // appropriate.
+ data.narrow = JSON.parse(data.narrow);
+ data.narrow.push(web_public_narrow);
+ data.narrow = JSON.stringify(data.narrow);
+ }
+ }
+
channel.get({
url: "/json/messages",
data,