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.

reactions: Don't process clicks from spectators.

Aman Agrawala67cff49649b
diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js
index 64c44ddf480..a225577cbf1 100644
--- a/frontend_tests/node_tests/reactions.js
+++ b/frontend_tests/node_tests/reactions.js
@@ -44,6 +44,9 @@ const emoji_picker = mock_esm("../../static/js/emoji_picker", {
});
const message_lists = mock_esm("../../static/js/message_lists");
const message_store = mock_esm("../../static/js/message_store");
+const login_to_access = mock_esm("../../static/js/login_to_access", {
+ show() {},
+});
message_lists.current = {
selected_message() {
@@ -907,15 +910,23 @@ test("process_reaction_click", ({override}) => {
emoji_name: "smile",
emoji_code: "1f642",
};
- {
- const stub = make_stub();
- channel.del = stub.f;
- reactions.process_reaction_click(message.id, "unicode_emoji,1f642");
- assert.equal(stub.num_calls, 1);
- const args = stub.get_args("args").args;
- assert.equal(args.url, "/json/messages/1001/reactions");
- assert.deepEqual(args.data, expected_reaction_info);
- }
+
+ // Test spectator cannot react.
+ page_params.is_spectator = true;
+ let stub = make_stub();
+ login_to_access.show = stub.f;
+ reactions.process_reaction_click(message.id, "unicode_emoji,1f642");
+ let args = stub.get_args("args").args;
+ assert.equal(args, undefined);
+
+ page_params.is_spectator = false;
+ stub = make_stub();
+ channel.del = stub.f;
+ reactions.process_reaction_click(message.id, "unicode_emoji,1f642");
+ assert.equal(stub.num_calls, 1);
+ args = stub.get_args("args").args;
+ assert.equal(args.url, "/json/messages/1001/reactions");
+ assert.deepEqual(args.data, expected_reaction_info);
});
test("warnings", () => {
diff --git a/static/js/reactions.js b/static/js/reactions.js
index d9d6418d3f4..0932a7fe8e6 100644
--- a/static/js/reactions.js
+++ b/static/js/reactions.js
@@ -8,6 +8,7 @@ import * as blueslip from "./blueslip";
import * as channel from "./channel";
import * as emoji_picker from "./emoji_picker";
import {$t} from "./i18n";
+import * as login_to_access from "./login_to_access";
import * as message_lists from "./message_lists";
import * as message_store from "./message_store";
import {page_params} from "./page_params";
@@ -110,6 +111,13 @@ export function toggle_emoji_reaction(message_id, emoji_name) {
}
export function process_reaction_click(message_id, local_id) {
+ if (page_params.is_spectator) {
+ // Spectators can't react, since they don't have accounts. We
+ // stop here to avoid a confusing reaction local echo.
+ login_to_access.show();
+ return;
+ }
+
const message = get_message(message_id);
if (!message) {