2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
|
|
|
const {make_stub} = require("./lib/stub");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const blueslip = require("./lib/zblueslip");
|
|
|
|
const $ = require("./lib/zjquery");
|
2024-02-13 02:08:16 +01:00
|
|
|
const {current_user, page_params, user_settings} = require("./lib/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-02-25 19:10:42 +01:00
|
|
|
const alice_user_id = 5;
|
2021-02-28 01:26:16 +01:00
|
|
|
|
2021-03-12 14:24:53 +01:00
|
|
|
const sample_message = {
|
2017-05-28 16:18:12 +02:00
|
|
|
id: 1001,
|
|
|
|
reactions: [
|
2020-06-30 21:16:29 +02:00
|
|
|
{emoji_name: "smile", user_id: 5, reaction_type: "unicode_emoji", emoji_code: "1f642"},
|
|
|
|
{emoji_name: "smile", user_id: 6, reaction_type: "unicode_emoji", emoji_code: "1f642"},
|
2020-07-15 01:29:15 +02:00
|
|
|
{emoji_name: "frown", user_id: 7, reaction_type: "unicode_emoji", emoji_code: "1f641"},
|
2020-10-21 15:09:10 +02:00
|
|
|
|
|
|
|
{emoji_name: "tada", user_id: 7, reaction_type: "unicode_emoji", emoji_code: "1f389"},
|
|
|
|
{emoji_name: "tada", user_id: 8, reaction_type: "unicode_emoji", emoji_code: "1f389"},
|
|
|
|
|
|
|
|
{emoji_name: "rocket", user_id: 5, reaction_type: "unicode_emoji", emoji_code: "1f680"},
|
|
|
|
{emoji_name: "rocket", user_id: 6, reaction_type: "unicode_emoji", emoji_code: "1f680"},
|
|
|
|
{emoji_name: "rocket", user_id: 7, reaction_type: "unicode_emoji", emoji_code: "1f680"},
|
|
|
|
|
|
|
|
{emoji_name: "wave", user_id: 6, reaction_type: "unicode_emoji", emoji_code: "1f44b"},
|
|
|
|
{emoji_name: "wave", user_id: 7, reaction_type: "unicode_emoji", emoji_code: "1f44b"},
|
|
|
|
{emoji_name: "wave", user_id: 8, reaction_type: "unicode_emoji", emoji_code: "1f44b"},
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
{
|
|
|
|
emoji_name: "inactive_realm_emoji",
|
|
|
|
user_id: 5,
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
emoji_code: "992",
|
|
|
|
},
|
2017-05-28 16:18:12 +02:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const channel = mock_esm("../src/channel");
|
|
|
|
const message_store = mock_esm("../src/message_store");
|
2023-12-01 14:42:00 +01:00
|
|
|
const settings_data = mock_esm("../src/settings_data");
|
2023-02-22 23:04:10 +01:00
|
|
|
const spectators = mock_esm("../src/spectators", {
|
2021-09-07 04:09:12 +02:00
|
|
|
login_to_access() {},
|
2021-01-28 06:01:09 +01:00
|
|
|
});
|
2024-01-19 07:37:02 +01:00
|
|
|
const message_lists = mock_esm("../src/message_lists", {
|
2024-01-10 09:31:36 +01:00
|
|
|
current: {
|
|
|
|
id: 1,
|
|
|
|
},
|
2024-01-19 07:37:02 +01:00
|
|
|
home: {
|
|
|
|
id: 2,
|
|
|
|
},
|
2024-01-10 09:31:36 +01:00
|
|
|
});
|
2021-02-28 01:10:03 +01:00
|
|
|
|
2021-03-07 13:57:14 +01:00
|
|
|
set_global("document", "document-stub");
|
2017-09-18 22:06:39 +02:00
|
|
|
|
2022-03-25 14:47:51 +01:00
|
|
|
const emoji = zrequire("emoji");
|
2023-02-22 23:03:47 +01:00
|
|
|
const emoji_codes = zrequire("../../static/generated/emoji/emoji_codes.json");
|
2020-12-01 23:21:38 +01:00
|
|
|
const people = zrequire("people");
|
|
|
|
const reactions = zrequire("reactions");
|
|
|
|
|
|
|
|
const emoji_params = {
|
|
|
|
realm_emoji: {
|
|
|
|
991: {
|
|
|
|
id: "991",
|
|
|
|
name: "realm_emoji",
|
|
|
|
source_url: "/url/for/991",
|
|
|
|
deactivated: false,
|
|
|
|
},
|
|
|
|
992: {
|
|
|
|
id: "992",
|
|
|
|
name: "inactive_realm_emoji",
|
|
|
|
source_url: "/url/for/992",
|
2021-11-20 20:38:00 +01:00
|
|
|
still_url: "/still/url/for/992",
|
2020-12-01 23:21:38 +01:00
|
|
|
deactivated: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
emoji_codes,
|
|
|
|
};
|
|
|
|
|
|
|
|
emoji.initialize(emoji_params);
|
|
|
|
|
|
|
|
const alice = {
|
|
|
|
email: "alice@example.com",
|
|
|
|
user_id: alice_user_id,
|
|
|
|
full_name: "Alice",
|
|
|
|
};
|
|
|
|
const bob = {
|
|
|
|
email: "bob@example.com",
|
|
|
|
user_id: 6,
|
|
|
|
full_name: "Bob van Roberts",
|
|
|
|
};
|
|
|
|
const cali = {
|
|
|
|
email: "cali@example.com",
|
|
|
|
user_id: 7,
|
|
|
|
full_name: "Cali",
|
|
|
|
};
|
|
|
|
const alexus = {
|
|
|
|
email: "alexus@example.com",
|
|
|
|
user_id: 8,
|
|
|
|
full_name: "Alexus",
|
|
|
|
};
|
|
|
|
people.add_active_user(alice);
|
|
|
|
people.add_active_user(bob);
|
|
|
|
people.add_active_user(cali);
|
|
|
|
people.add_active_user(alexus);
|
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.user_id = alice_user_id;
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-04-03 19:07:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
function sample_message_with_clean_reactions() {
|
2021-03-12 14:24:53 +01:00
|
|
|
const message = {...sample_message};
|
2024-05-28 22:55:41 +02:00
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
function convert_reactions_to_clean_reactions(message) {
|
|
|
|
message.clean_reactions = reactions.generate_clean_reactions(message);
|
|
|
|
delete message.reactions;
|
|
|
|
}
|
|
|
|
|
|
|
|
test("basics", () => {
|
2023-12-01 14:42:00 +01:00
|
|
|
settings_data.user_can_access_all_other_users = () => true;
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = sample_message_with_clean_reactions();
|
2019-11-02 00:06:25 +01:00
|
|
|
const result = reactions.get_message_reactions(message);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(reactions.current_user_has_reacted_to_emoji(message, "unicode_emoji,1f642"));
|
|
|
|
assert.ok(!reactions.current_user_has_reacted_to_emoji(message, "bogus"));
|
2017-05-11 17:00:24 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
result.sort((a, b) => a.count - b.count);
|
2017-03-26 20:20:42 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const expected_result = [
|
2018-05-07 03:30:13 +02:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
emoji_name: "frown",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f641",
|
|
|
|
local_id: "unicode_emoji,1f641",
|
2018-05-07 03:30:13 +02:00
|
|
|
count: 1,
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "1",
|
2018-05-07 03:30:13 +02:00
|
|
|
user_ids: [7],
|
2020-10-21 15:09:10 +02:00
|
|
|
label: "translated: Cali reacted with :frown:",
|
2018-05-07 03:30:13 +02:00
|
|
|
emoji_alt_code: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
class: "message_reaction",
|
2021-11-20 20:38:00 +01:00
|
|
|
is_realm_emoji: false,
|
2018-05-07 03:30:13 +02:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
emoji_name: "inactive_realm_emoji",
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
emoji_code: "992",
|
|
|
|
local_id: "realm_emoji,992",
|
2018-05-07 03:30:13 +02:00
|
|
|
count: 1,
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "1",
|
2018-05-07 03:30:13 +02:00
|
|
|
user_ids: [5],
|
2020-10-21 15:09:10 +02:00
|
|
|
label: "translated: You (click to remove) reacted with :inactive_realm_emoji:",
|
2018-05-07 03:30:13 +02:00
|
|
|
emoji_alt_code: false,
|
|
|
|
is_realm_emoji: true,
|
2021-02-25 14:54:11 +01:00
|
|
|
url: "/url/for/992",
|
2021-11-20 20:38:00 +01:00
|
|
|
still_url: "/still/url/for/992",
|
2020-07-15 01:29:15 +02:00
|
|
|
class: "message_reaction reacted",
|
2018-05-07 03:30:13 +02:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
emoji_name: "smile",
|
|
|
|
reaction_type: "unicode_emoji",
|
2020-06-30 21:16:29 +02:00
|
|
|
emoji_code: "1f642",
|
|
|
|
local_id: "unicode_emoji,1f642",
|
2018-05-07 03:30:13 +02:00
|
|
|
count: 2,
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "2",
|
2018-05-07 03:30:13 +02:00
|
|
|
user_ids: [5, 6],
|
2020-10-21 15:09:10 +02:00
|
|
|
label: "translated: You (click to remove) and Bob van Roberts reacted with :smile:",
|
2018-05-07 03:30:13 +02:00
|
|
|
emoji_alt_code: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
class: "message_reaction reacted",
|
2021-11-20 20:38:00 +01:00
|
|
|
is_realm_emoji: false,
|
2018-05-07 03:30:13 +02:00
|
|
|
},
|
2020-10-21 15:09:10 +02:00
|
|
|
{
|
|
|
|
emoji_name: "tada",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f389",
|
|
|
|
local_id: "unicode_emoji,1f389",
|
|
|
|
count: 2,
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "2",
|
2020-10-21 15:09:10 +02:00
|
|
|
user_ids: [7, 8],
|
|
|
|
label: "translated: Cali and Alexus reacted with :tada:",
|
|
|
|
emoji_alt_code: false,
|
|
|
|
class: "message_reaction",
|
2021-11-20 20:38:00 +01:00
|
|
|
is_realm_emoji: false,
|
2020-10-21 15:09:10 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_name: "rocket",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f680",
|
|
|
|
local_id: "unicode_emoji,1f680",
|
|
|
|
count: 3,
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "3",
|
2020-10-21 15:09:10 +02:00
|
|
|
user_ids: [5, 6, 7],
|
2021-05-09 22:29:53 +02:00
|
|
|
label: "translated: You (click to remove), Bob van Roberts and Cali reacted with :rocket:",
|
2020-10-21 15:09:10 +02:00
|
|
|
emoji_alt_code: false,
|
|
|
|
class: "message_reaction reacted",
|
2021-11-20 20:38:00 +01:00
|
|
|
is_realm_emoji: false,
|
2020-10-21 15:09:10 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_name: "wave",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f44b",
|
|
|
|
local_id: "unicode_emoji,1f44b",
|
|
|
|
count: 3,
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "3",
|
2020-10-21 15:09:10 +02:00
|
|
|
user_ids: [6, 7, 8],
|
|
|
|
label: "translated: Bob van Roberts, Cali and Alexus reacted with :wave:",
|
|
|
|
emoji_alt_code: false,
|
|
|
|
class: "message_reaction",
|
2021-11-20 20:38:00 +01:00
|
|
|
is_realm_emoji: false,
|
2020-10-21 15:09:10 +02:00
|
|
|
},
|
2018-05-07 03:30:13 +02:00
|
|
|
];
|
|
|
|
assert.deepEqual(result, expected_result);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-28 16:18:12 +02:00
|
|
|
|
2023-12-01 14:42:00 +01:00
|
|
|
test("reactions from unknown users", () => {
|
|
|
|
settings_data.user_can_access_all_other_users = () => false;
|
|
|
|
people.add_inaccessible_user(10);
|
|
|
|
const message = {
|
|
|
|
id: 1001,
|
|
|
|
reactions: [
|
|
|
|
{emoji_name: "smile", user_id: 5, reaction_type: "unicode_emoji", emoji_code: "1f642"},
|
|
|
|
{emoji_name: "smile", user_id: 9, reaction_type: "unicode_emoji", emoji_code: "1f642"},
|
|
|
|
{emoji_name: "frown", user_id: 9, reaction_type: "unicode_emoji", emoji_code: "1f641"},
|
|
|
|
|
|
|
|
{emoji_name: "tada", user_id: 6, reaction_type: "unicode_emoji", emoji_code: "1f389"},
|
|
|
|
{emoji_name: "tada", user_id: 10, reaction_type: "unicode_emoji", emoji_code: "1f389"},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
convert_reactions_to_clean_reactions(message);
|
2023-12-01 14:42:00 +01:00
|
|
|
const result = reactions.get_message_reactions(message);
|
|
|
|
result.sort((a, b) => a.count - b.count);
|
|
|
|
|
|
|
|
const expected_result = [
|
|
|
|
{
|
|
|
|
emoji_name: "frown",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f641",
|
|
|
|
local_id: "unicode_emoji,1f641",
|
|
|
|
count: 1,
|
|
|
|
vote_text: "1",
|
|
|
|
user_ids: [9],
|
|
|
|
label: "translated: translated: Unknown user reacted with :frown:",
|
|
|
|
emoji_alt_code: false,
|
|
|
|
class: "message_reaction",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_name: "smile",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f642",
|
|
|
|
local_id: "unicode_emoji,1f642",
|
|
|
|
count: 2,
|
|
|
|
vote_text: "2",
|
|
|
|
user_ids: [5, 9],
|
|
|
|
label: "translated: You (click to remove) and translated: Unknown user reacted with :smile:",
|
|
|
|
emoji_alt_code: false,
|
|
|
|
class: "message_reaction reacted",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_name: "tada",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f389",
|
|
|
|
local_id: "unicode_emoji,1f389",
|
|
|
|
count: 2,
|
|
|
|
vote_text: "2",
|
|
|
|
user_ids: [6, 10],
|
|
|
|
label: "translated: Bob van Roberts and translated: Unknown user reacted with :tada:",
|
|
|
|
emoji_alt_code: false,
|
|
|
|
class: "message_reaction",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
assert.deepEqual(result, expected_result);
|
|
|
|
});
|
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
test("unknown realm emojis (add)", () => {
|
2021-11-20 20:38:00 +01:00
|
|
|
assert.throws(
|
|
|
|
() =>
|
2023-12-28 05:02:26 +01:00
|
|
|
reactions.insert_new_reaction(
|
2022-10-22 02:42:51 +02:00
|
|
|
{
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
emoji_name: "false_emoji",
|
|
|
|
emoji_code: "broken",
|
|
|
|
},
|
|
|
|
1000,
|
|
|
|
alice.user_id,
|
|
|
|
),
|
2021-11-20 20:38:00 +01:00
|
|
|
{
|
|
|
|
name: "Error",
|
|
|
|
message: "Cannot find realm emoji for code 'broken'.",
|
|
|
|
},
|
|
|
|
);
|
2020-10-06 23:57:16 +02:00
|
|
|
});
|
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
test("unknown realm emojis (insert)", () => {
|
2021-11-20 20:13:59 +01:00
|
|
|
assert.throws(
|
|
|
|
() =>
|
2023-12-28 05:02:26 +01:00
|
|
|
reactions.insert_new_reaction(
|
2022-10-22 02:42:51 +02:00
|
|
|
{
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
emoji_name: "fake_emoji",
|
|
|
|
emoji_code: "bogus",
|
|
|
|
},
|
|
|
|
1000,
|
|
|
|
bob.user_id,
|
|
|
|
),
|
2021-11-20 20:13:59 +01:00
|
|
|
{
|
|
|
|
name: "Error",
|
|
|
|
message: "Cannot find realm emoji for code 'bogus'.",
|
|
|
|
},
|
|
|
|
);
|
2020-10-06 23:57:16 +02:00
|
|
|
});
|
|
|
|
|
2022-01-08 10:27:06 +01:00
|
|
|
test("sending", ({override, override_rewire}) => {
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = sample_message_with_clean_reactions();
|
2021-03-12 14:24:53 +01:00
|
|
|
assert.equal(message.id, 1001);
|
|
|
|
override(message_store, "get", (message_id) => {
|
|
|
|
assert.equal(message_id, message.id);
|
|
|
|
return message;
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let emoji_name = "smile"; // should be a current reaction
|
2017-05-28 16:18:12 +02:00
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(reactions, "add_reaction", noop);
|
|
|
|
override_rewire(reactions, "remove_reaction", noop);
|
2017-12-19 00:55:40 +01:00
|
|
|
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-12-01 00:57:57 +01:00
|
|
|
channel.del = stub.f;
|
2024-03-05 19:26:09 +01:00
|
|
|
reactions.toggle_emoji_reaction(message, emoji_name);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("args").args;
|
|
|
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
2017-10-31 22:33:28 +01:00
|
|
|
assert.deepEqual(args.data, {
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_name: "smile",
|
2020-06-30 21:16:29 +02:00
|
|
|
emoji_code: "1f642",
|
2017-10-31 22:33:28 +01:00
|
|
|
});
|
2017-05-28 16:18:12 +02:00
|
|
|
// args.success() does nothing; just make sure it doesn't crash
|
|
|
|
args.success();
|
|
|
|
|
|
|
|
// similarly, we only exercise the failure codepath
|
2018-07-10 09:14:51 +02:00
|
|
|
// Since this path calls blueslip.warn, we need to handle it.
|
2023-02-27 15:59:23 +01:00
|
|
|
blueslip.expect("error", "XHR error message.");
|
2021-05-10 07:02:14 +02:00
|
|
|
channel.xhr_error_message = () => "XHR error message.";
|
2023-07-18 20:19:22 +02:00
|
|
|
args.error({readyState: 4, responseJSON: {msg: "Some error message"}});
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
emoji_name = "alien"; // not set yet
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-12-01 00:57:57 +01:00
|
|
|
channel.post = stub.f;
|
2024-03-05 19:26:09 +01:00
|
|
|
reactions.toggle_emoji_reaction(message, emoji_name);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("args").args;
|
|
|
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
2017-10-31 22:33:28 +01:00
|
|
|
assert.deepEqual(args.data, {
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_name: "alien",
|
|
|
|
emoji_code: "1f47d",
|
2017-10-31 22:33:28 +01:00
|
|
|
});
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2017-05-28 16:18:12 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
emoji_name = "inactive_realm_emoji";
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
2022-02-08 00:13:33 +01:00
|
|
|
// Test removing a deactivated realm emoji. A user can interact with a
|
2017-12-15 16:54:07 +01:00
|
|
|
// deactivated realm emoji only by clicking on a reaction, hence, only
|
|
|
|
// `process_reaction_click()` codepath supports deleting/adding a deactivated
|
|
|
|
// realm emoji.
|
2021-02-13 03:46:14 +01:00
|
|
|
const stub = make_stub();
|
2020-12-01 00:57:57 +01:00
|
|
|
channel.del = stub.f;
|
2021-03-12 14:24:53 +01:00
|
|
|
reactions.process_reaction_click(message.id, "realm_emoji,992");
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("args").args;
|
|
|
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
2017-10-31 22:33:28 +01:00
|
|
|
assert.deepEqual(args.data, {
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
emoji_name: "inactive_realm_emoji",
|
|
|
|
emoji_code: "992",
|
2017-10-31 22:33:28 +01:00
|
|
|
});
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2017-10-08 17:02:14 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
emoji_name = "zulip"; // Test adding zulip emoji.
|
2021-02-13 03:46:14 +01:00
|
|
|
{
|
|
|
|
const stub = make_stub();
|
2020-12-01 00:57:57 +01:00
|
|
|
channel.post = stub.f;
|
2024-03-05 19:26:09 +01:00
|
|
|
reactions.toggle_emoji_reaction(message, emoji_name);
|
2021-02-13 03:46:14 +01:00
|
|
|
assert.equal(stub.num_calls, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
const args = stub.get_args("args").args;
|
|
|
|
assert.equal(args.url, "/json/messages/1001/reactions");
|
2017-10-31 22:33:28 +01:00
|
|
|
assert.deepEqual(args.data, {
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "zulip_extra_emoji",
|
|
|
|
emoji_name: "zulip",
|
|
|
|
emoji_code: "zulip",
|
2023-04-05 12:51:26 +02:00
|
|
|
still_url: null,
|
2021-07-26 12:43:55 +02:00
|
|
|
url: "/static/generated/emoji/images/emoji/unicode/zulip.png",
|
2017-10-31 22:33:28 +01:00
|
|
|
});
|
2021-02-13 03:46:14 +01:00
|
|
|
}
|
2017-10-31 22:33:28 +01:00
|
|
|
|
2020-07-16 23:29:01 +02:00
|
|
|
emoji_name = "unknown-emoji"; // Test sending an emoji unknown to frontend.
|
2024-03-05 19:26:09 +01:00
|
|
|
assert.throws(() => reactions.toggle_emoji_reaction(message, emoji_name), {
|
2021-07-26 12:43:55 +02:00
|
|
|
name: "Error",
|
|
|
|
message: "Bad emoji name: unknown-emoji",
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-28 17:04:30 +02:00
|
|
|
|
2024-03-05 19:26:09 +01:00
|
|
|
test("prevent_simultaneous_requests_updating_reaction", ({override_rewire}) => {
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = sample_message_with_clean_reactions();
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(reactions, "add_reaction", noop);
|
2023-02-27 15:59:23 +01:00
|
|
|
const stub = make_stub();
|
|
|
|
channel.post = stub.f;
|
|
|
|
|
|
|
|
// Verify that two requests to add the same reaction in a row only
|
|
|
|
// result in a single request to the server.
|
2024-03-05 19:26:09 +01:00
|
|
|
reactions.toggle_emoji_reaction(message, "cow");
|
|
|
|
reactions.toggle_emoji_reaction(message, "cow");
|
2023-02-27 15:59:23 +01:00
|
|
|
|
|
|
|
assert.equal(stub.num_calls, 1);
|
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
function stub_reactions(message_id) {
|
|
|
|
const $message_reactions = $.create("reactions-stub");
|
2024-01-10 09:31:36 +01:00
|
|
|
const $message_row = $.create(`#message-row-1-${CSS.escape(message_id)}`);
|
2024-01-19 07:37:02 +01:00
|
|
|
message_lists.all_rendered_row_for_message_id = () => $message_row;
|
2022-07-10 01:06:33 +02:00
|
|
|
$message_row.set_find_results(".message_reactions", $message_reactions);
|
|
|
|
return $message_reactions;
|
|
|
|
}
|
|
|
|
|
|
|
|
function stub_reaction(message_id, local_id) {
|
|
|
|
const $reaction = $.create("reaction-stub");
|
|
|
|
stub_reactions(message_id).set_find_results(
|
|
|
|
`[data-reaction-id='${CSS.escape(local_id)}']`,
|
|
|
|
$reaction,
|
|
|
|
);
|
|
|
|
return $reaction;
|
|
|
|
}
|
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
test("get_vote_text (more than 3 reactions)", () => {
|
|
|
|
const user_ids = [5, 6, 7];
|
|
|
|
const message = {...sample_message};
|
|
|
|
|
|
|
|
user_settings.display_emoji_reaction_users = true;
|
|
|
|
assert.equal(
|
|
|
|
"translated: You, Bob van Roberts, Cali",
|
2024-01-05 07:19:42 +01:00
|
|
|
reactions.get_vote_text(user_ids, message),
|
2022-10-22 02:51:46 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get_vote_text (3 reactions)", () => {
|
|
|
|
const user_ids = [5, 6, 7];
|
|
|
|
const message = {...sample_message};
|
|
|
|
|
|
|
|
// slicing the reactions array to only include first 3 reactions
|
|
|
|
message.reactions = message.reactions.slice(0, 3);
|
|
|
|
|
|
|
|
user_settings.display_emoji_reaction_users = true;
|
|
|
|
assert.equal(
|
|
|
|
"translated: You, Bob van Roberts, Cali",
|
2024-01-05 07:19:42 +01:00
|
|
|
reactions.get_vote_text(user_ids, message),
|
2022-10-22 02:51:46 +02:00
|
|
|
);
|
|
|
|
});
|
2017-05-29 19:24:31 +02:00
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
test("update_vote_text_on_message", ({override_rewire}) => {
|
|
|
|
// the vote_text in this message is intentionally wrong.
|
|
|
|
// After calling update_vote_text_on_message(), we
|
|
|
|
// will check if the vote_text has been correctly updated.
|
|
|
|
const message = {
|
|
|
|
id: 1001,
|
|
|
|
reactions: [
|
|
|
|
{
|
|
|
|
emoji_name: "wave",
|
|
|
|
user_id: 5,
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f44b",
|
|
|
|
vote_text: "2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_name: "wave",
|
|
|
|
user_id: 6,
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f44b",
|
|
|
|
vote_text: "2",
|
|
|
|
},
|
2017-05-29 19:24:31 +02:00
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
{
|
|
|
|
emoji_name: "inactive_realm_emoji",
|
|
|
|
user_id: 5,
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
emoji_code: "992",
|
|
|
|
vote_text: "1",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2024-05-28 22:55:41 +02:00
|
|
|
convert_reactions_to_clean_reactions(message);
|
2017-05-29 19:24:31 +02:00
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
user_settings.display_emoji_reaction_users = true;
|
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
override_rewire(reactions, "find_reaction", noop);
|
|
|
|
override_rewire(reactions, "set_reaction_vote_text", noop);
|
2022-10-22 02:51:46 +02:00
|
|
|
|
|
|
|
reactions.update_vote_text_on_message(message);
|
|
|
|
|
|
|
|
const updated_message = {
|
|
|
|
clean_reactions: new Map(
|
|
|
|
Object.entries({
|
|
|
|
"realm_emoji,992": {
|
|
|
|
class: "message_reaction reacted",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: "992",
|
|
|
|
emoji_name: "inactive_realm_emoji",
|
|
|
|
is_realm_emoji: true,
|
|
|
|
label: "translated: You (click to remove) reacted with :inactive_realm_emoji:",
|
|
|
|
local_id: "realm_emoji,992",
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
still_url: "/still/url/for/992",
|
|
|
|
url: "/url/for/992",
|
|
|
|
user_ids: [5],
|
|
|
|
vote_text: "translated: You",
|
|
|
|
},
|
|
|
|
"unicode_emoji,1f44b": {
|
|
|
|
class: "message_reaction reacted",
|
|
|
|
count: 2,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: "1f44b",
|
|
|
|
emoji_name: "wave",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
label: "translated: You (click to remove) and Bob van Roberts reacted with :wave:",
|
|
|
|
local_id: "unicode_emoji,1f44b",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [5, 6],
|
|
|
|
vote_text: "translated: You, Bob van Roberts",
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
id: 1001,
|
|
|
|
};
|
|
|
|
// message.reactions is deleted too.
|
|
|
|
assert.deepEqual(message, updated_message);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-29 19:24:31 +02:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
test("find_reaction", () => {
|
2021-02-24 22:45:47 +01:00
|
|
|
const message_id = 99;
|
|
|
|
const local_id = "unicode_emoji,1f44b";
|
2022-07-10 01:06:33 +02:00
|
|
|
const $reaction = stub_reaction(message_id, local_id);
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
assert.equal(reactions.find_reaction(message_id, local_id), $reaction);
|
2021-02-24 22:45:47 +01:00
|
|
|
});
|
|
|
|
|
2024-01-20 17:05:22 +01:00
|
|
|
test("get_reaction_sections", () => {
|
2022-07-10 01:06:33 +02:00
|
|
|
const $message_reactions = stub_reactions(555);
|
2017-06-29 17:19:14 +02:00
|
|
|
|
2024-01-20 17:05:22 +01:00
|
|
|
const $section = reactions.get_reaction_sections(555);
|
2017-06-29 17:19:14 +02:00
|
|
|
|
2022-03-16 21:37:41 +01:00
|
|
|
assert.equal($section, $message_reactions);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-29 17:19:14 +02:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("emoji_reaction_title", ({override}) => {
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = sample_message_with_clean_reactions();
|
2021-03-12 14:24:53 +01:00
|
|
|
override(message_store, "get", () => message);
|
2020-06-30 21:16:29 +02:00
|
|
|
const local_id = "unicode_emoji,1f642";
|
2019-04-04 14:56:54 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2021-03-12 14:24:53 +01:00
|
|
|
reactions.get_reaction_title_data(message.id, local_id),
|
2020-10-21 15:09:10 +02:00
|
|
|
"translated: You (click to remove) and Bob van Roberts reacted with :smile:",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2019-04-04 14:56:54 +02:00
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("add_reaction/remove_reaction", ({override, override_rewire}) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const message = {
|
2017-06-28 22:47:47 +02:00
|
|
|
id: 2001,
|
|
|
|
reactions: [],
|
|
|
|
};
|
2024-05-28 22:55:41 +02:00
|
|
|
convert_reactions_to_clean_reactions(message);
|
2017-06-28 22:47:47 +02:00
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
user_settings.display_emoji_reaction_users = true;
|
|
|
|
|
2021-02-25 14:13:30 +01:00
|
|
|
override(message_store, "get", () => message);
|
2017-06-28 22:47:47 +02:00
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
let function_calls = [];
|
2021-02-25 14:29:15 +01:00
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
override_rewire(reactions, "insert_new_reaction", (clean_reaction_object, message, user_id) => {
|
|
|
|
function_calls.push({
|
2022-10-22 02:42:51 +02:00
|
|
|
name: "insert_new_reaction",
|
|
|
|
clean_reaction_object,
|
|
|
|
message,
|
|
|
|
user_id,
|
|
|
|
});
|
|
|
|
});
|
2023-12-28 05:02:26 +01:00
|
|
|
override_rewire(
|
|
|
|
reactions,
|
2022-10-20 02:16:48 +02:00
|
|
|
"update_existing_reaction",
|
2022-10-22 02:42:51 +02:00
|
|
|
(clean_reaction_object, message, user_id) => {
|
2023-12-28 05:02:26 +01:00
|
|
|
function_calls.push({
|
2022-10-20 02:16:48 +02:00
|
|
|
name: "update_existing_reaction",
|
|
|
|
clean_reaction_object,
|
2022-10-22 02:42:51 +02:00
|
|
|
message,
|
2022-10-20 02:16:48 +02:00
|
|
|
user_id,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2023-12-28 05:02:26 +01:00
|
|
|
override_rewire(
|
|
|
|
reactions,
|
|
|
|
"remove_reaction_from_view",
|
|
|
|
(clean_reaction_object, message, user_id) => {
|
|
|
|
function_calls.push({
|
|
|
|
name: "remove_reaction_from_view",
|
|
|
|
clean_reaction_object,
|
|
|
|
message,
|
|
|
|
user_id,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2021-02-25 14:29:15 +01:00
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
function test_function_calls(test_params) {
|
|
|
|
function_calls = [];
|
2017-06-28 22:47:47 +02:00
|
|
|
|
|
|
|
test_params.run_code();
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
assert.deepEqual(function_calls, test_params.expected_function_calls);
|
2021-02-25 14:21:01 +01:00
|
|
|
assert.deepEqual(
|
|
|
|
new Set(reactions.get_emojis_used_by_user_for_message_id(message.message_id)),
|
|
|
|
new Set(test_params.alice_emojis),
|
|
|
|
);
|
2017-06-28 22:47:47 +02:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice_8ball_event = {
|
2017-06-28 22:47:47 +02:00
|
|
|
message_id: 2001,
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
emoji_code: "1f3b1",
|
2020-04-22 23:24:28 +02:00
|
|
|
user_id: alice.user_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob_8ball_event = {
|
2017-06-28 22:47:47 +02:00
|
|
|
message_id: 2001,
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
emoji_code: "1f3b1",
|
2020-04-22 23:24:28 +02:00
|
|
|
user_id: bob.user_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const cali_airplane_event = {
|
2017-06-28 22:47:47 +02:00
|
|
|
message_id: 2001,
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_name: "airplane",
|
|
|
|
emoji_code: "2708",
|
2020-04-22 23:24:28 +02:00
|
|
|
user_id: cali.user_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
};
|
|
|
|
|
2022-10-22 02:42:51 +02:00
|
|
|
const clean_reaction_object_alice = {
|
|
|
|
class: "message_reaction reacted",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: alice_8ball_event.emoji_code,
|
|
|
|
emoji_name: alice_8ball_event.emoji_name,
|
|
|
|
is_realm_emoji: false,
|
|
|
|
label: "translated: You (click to remove) reacted with :8ball:",
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: alice_8ball_event.reaction_type,
|
|
|
|
user_ids: [alice.user_id],
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "translated: You",
|
2022-10-22 02:42:51 +02:00
|
|
|
};
|
2023-12-28 05:02:26 +01:00
|
|
|
test_function_calls({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2017-06-28 22:47:47 +02:00
|
|
|
reactions.add_reaction(alice_8ball_event);
|
|
|
|
},
|
2023-12-28 05:02:26 +01:00
|
|
|
expected_function_calls: [
|
2017-06-28 22:47:47 +02:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "insert_new_reaction",
|
2022-10-22 02:42:51 +02:00
|
|
|
clean_reaction_object: clean_reaction_object_alice,
|
|
|
|
message: {
|
|
|
|
id: alice_8ball_event.message_id,
|
|
|
|
clean_reactions: new Map(
|
|
|
|
Object.entries({
|
|
|
|
"unicode_emoji,1f3b1": clean_reaction_object_alice,
|
|
|
|
}),
|
|
|
|
),
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
2022-10-20 02:16:48 +02:00
|
|
|
user_id: alice_8ball_event.user_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
|
|
|
],
|
2021-02-25 14:21:01 +01:00
|
|
|
alice_emojis: ["8ball"],
|
2017-06-28 22:47:47 +02:00
|
|
|
});
|
|
|
|
|
2021-02-25 18:02:11 +01:00
|
|
|
// Add redundant reaction.
|
2023-12-28 05:02:26 +01:00
|
|
|
test_function_calls({
|
2021-02-25 18:02:11 +01:00
|
|
|
run_code() {
|
|
|
|
reactions.add_reaction(alice_8ball_event);
|
|
|
|
},
|
2023-12-28 05:02:26 +01:00
|
|
|
expected_function_calls: [],
|
2021-02-25 18:02:11 +01:00
|
|
|
alice_emojis: ["8ball"],
|
|
|
|
});
|
|
|
|
|
2022-10-22 02:42:51 +02:00
|
|
|
const clean_reaction_object_bob = {
|
|
|
|
class: "message_reaction reacted",
|
|
|
|
count: 2,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: bob_8ball_event.emoji_code,
|
|
|
|
emoji_name: bob_8ball_event.emoji_name,
|
|
|
|
is_realm_emoji: false,
|
|
|
|
label: "translated: You (click to remove) and Bob van Roberts reacted with :8ball:",
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: bob_8ball_event.reaction_type,
|
|
|
|
user_ids: [alice.user_id, bob.user_id],
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "translated: You, Bob van Roberts",
|
2022-10-22 02:42:51 +02:00
|
|
|
};
|
2023-12-28 05:02:26 +01:00
|
|
|
test_function_calls({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2017-06-28 22:47:47 +02:00
|
|
|
reactions.add_reaction(bob_8ball_event);
|
|
|
|
},
|
2023-12-28 05:02:26 +01:00
|
|
|
expected_function_calls: [
|
2017-06-28 22:47:47 +02:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "update_existing_reaction",
|
2022-10-22 02:42:51 +02:00
|
|
|
clean_reaction_object: clean_reaction_object_bob,
|
|
|
|
message: {
|
|
|
|
id: bob_8ball_event.message_id,
|
|
|
|
clean_reactions: new Map(
|
|
|
|
Object.entries({
|
|
|
|
"unicode_emoji,1f3b1": clean_reaction_object_bob,
|
|
|
|
}),
|
|
|
|
),
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
2022-10-20 02:16:48 +02:00
|
|
|
user_id: bob_8ball_event.user_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
|
|
|
],
|
2021-02-25 14:21:01 +01:00
|
|
|
alice_emojis: ["8ball"],
|
2017-06-28 22:47:47 +02:00
|
|
|
});
|
|
|
|
|
2022-10-22 02:42:51 +02:00
|
|
|
const clean_reaction_object_cali = {
|
|
|
|
class: "message_reaction",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: cali_airplane_event.emoji_code,
|
|
|
|
emoji_name: cali_airplane_event.emoji_name,
|
|
|
|
is_realm_emoji: false,
|
|
|
|
label: "translated: Cali reacted with :airplane:",
|
|
|
|
local_id: "unicode_emoji,2708",
|
|
|
|
reaction_type: cali_airplane_event.reaction_type,
|
|
|
|
user_ids: [cali.user_id],
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "Cali",
|
2022-10-22 02:42:51 +02:00
|
|
|
};
|
2023-12-28 05:02:26 +01:00
|
|
|
test_function_calls({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2017-06-28 22:47:47 +02:00
|
|
|
reactions.add_reaction(cali_airplane_event);
|
|
|
|
},
|
2023-12-28 05:02:26 +01:00
|
|
|
expected_function_calls: [
|
2017-06-28 22:47:47 +02:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "insert_new_reaction",
|
2022-10-22 02:42:51 +02:00
|
|
|
clean_reaction_object: clean_reaction_object_cali,
|
|
|
|
message: {
|
|
|
|
id: cali_airplane_event.message_id,
|
|
|
|
clean_reactions: new Map(
|
|
|
|
Object.entries({
|
|
|
|
"unicode_emoji,1f3b1": clean_reaction_object_bob,
|
|
|
|
"unicode_emoji,2708": clean_reaction_object_cali,
|
|
|
|
}),
|
|
|
|
),
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
2022-10-20 02:16:48 +02:00
|
|
|
user_id: cali_airplane_event.user_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
|
|
|
],
|
2021-02-25 14:21:01 +01:00
|
|
|
alice_emojis: ["8ball"],
|
2017-06-28 22:47:47 +02:00
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test_function_calls({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2017-06-28 22:47:47 +02:00
|
|
|
reactions.remove_reaction(bob_8ball_event);
|
|
|
|
},
|
2023-12-28 05:02:26 +01:00
|
|
|
expected_function_calls: [
|
2017-06-28 22:47:47 +02:00
|
|
|
{
|
2023-12-28 05:02:26 +01:00
|
|
|
name: "remove_reaction_from_view",
|
2022-10-22 02:42:51 +02:00
|
|
|
clean_reaction_object: clean_reaction_object_alice,
|
|
|
|
message: {
|
|
|
|
clean_reactions: new Map(
|
|
|
|
Object.entries({
|
|
|
|
"unicode_emoji,1f3b1": clean_reaction_object_alice,
|
|
|
|
"unicode_emoji,2708": clean_reaction_object_cali,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
id: bob_8ball_event.message_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
2022-10-20 02:16:48 +02:00
|
|
|
user_id: bob_8ball_event.user_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
|
|
|
],
|
2021-02-25 14:21:01 +01:00
|
|
|
alice_emojis: ["8ball"],
|
2017-06-28 22:47:47 +02:00
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test_function_calls({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2017-06-28 22:47:47 +02:00
|
|
|
reactions.remove_reaction(alice_8ball_event);
|
|
|
|
},
|
2023-12-28 05:02:26 +01:00
|
|
|
expected_function_calls: [
|
2017-06-28 22:47:47 +02:00
|
|
|
{
|
2023-12-28 05:02:26 +01:00
|
|
|
name: "remove_reaction_from_view",
|
2022-10-20 02:16:48 +02:00
|
|
|
clean_reaction_object: {
|
2022-10-22 02:51:46 +02:00
|
|
|
count: 0,
|
|
|
|
class: "message_reaction",
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: alice_8ball_event.emoji_code,
|
|
|
|
emoji_name: alice_8ball_event.emoji_name,
|
|
|
|
is_realm_emoji: false,
|
|
|
|
label: "translated: and reacted with :8ball:",
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: alice_8ball_event.reaction_type,
|
2022-10-20 02:16:48 +02:00
|
|
|
user_ids: [],
|
2022-10-22 02:51:46 +02:00
|
|
|
vote_text: "",
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
2022-10-22 02:42:51 +02:00
|
|
|
message: {
|
|
|
|
clean_reactions: new Map(
|
|
|
|
Object.entries({
|
|
|
|
"unicode_emoji,2708": clean_reaction_object_cali,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
id: alice_8ball_event.message_id,
|
|
|
|
},
|
2022-10-20 02:16:48 +02:00
|
|
|
user_id: alice_8ball_event.user_id,
|
2017-06-28 22:47:47 +02:00
|
|
|
},
|
|
|
|
],
|
2021-02-25 14:21:01 +01:00
|
|
|
alice_emojis: [],
|
2017-06-28 22:47:47 +02:00
|
|
|
});
|
2021-02-25 18:02:11 +01:00
|
|
|
|
|
|
|
// Test redundant remove.
|
2023-12-28 05:02:26 +01:00
|
|
|
test_function_calls({
|
2021-02-25 18:02:11 +01:00
|
|
|
run_code() {
|
|
|
|
reactions.remove_reaction(alice_8ball_event);
|
|
|
|
},
|
2023-12-28 05:02:26 +01:00
|
|
|
expected_function_calls: [],
|
2021-02-25 18:02:11 +01:00
|
|
|
alice_emojis: [],
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-28 22:47:47 +02:00
|
|
|
|
2024-10-02 09:16:01 +02:00
|
|
|
test("insert_new_reaction (first reaction)", ({mock_template, override_rewire}) => {
|
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
label: "translated: You (click to remove) reacted with :8ball:",
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [alice.user_id],
|
|
|
|
};
|
|
|
|
const message_id = 501;
|
|
|
|
|
|
|
|
mock_template("message_reactions.hbs", false, (data) => {
|
|
|
|
assert.deepEqual(data, {
|
|
|
|
msg: {
|
|
|
|
message_reactions: [
|
|
|
|
{
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_name: "8ball",
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
class: "message_reaction reacted",
|
|
|
|
message_id,
|
|
|
|
label: "translated: You (click to remove) reacted with :8ball:",
|
|
|
|
reaction_type: clean_reaction_object.reaction_type,
|
|
|
|
is_realm_emoji: false,
|
|
|
|
vote_text: "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return "<msg-reactions-section-stub>";
|
|
|
|
});
|
|
|
|
|
|
|
|
const $rows = $.create("rows-stub");
|
|
|
|
message_lists.all_rendered_row_for_message_id = () => $rows;
|
|
|
|
|
|
|
|
const $messagebox_content = $.create("messagebox-content-stub");
|
|
|
|
$rows.set_find_results(".messagebox-content", $messagebox_content);
|
|
|
|
|
|
|
|
let append_called = false;
|
|
|
|
$messagebox_content.append = (element) => {
|
|
|
|
assert.equal(element, "<msg-reactions-section-stub>");
|
|
|
|
append_called = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const message = {
|
|
|
|
id: message_id,
|
|
|
|
reactions: [
|
|
|
|
{
|
|
|
|
emoji_name: "8ball",
|
|
|
|
user_id: alice.user_id,
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
override_rewire(reactions, "update_vote_text_on_message", noop);
|
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
reactions.insert_new_reaction(clean_reaction_object, message, alice.user_id);
|
|
|
|
assert.ok(append_called);
|
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("insert_new_reaction (me w/unicode emoji)", ({mock_template}) => {
|
2022-10-20 02:16:48 +02:00
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
2021-02-24 22:45:47 +01:00
|
|
|
emoji_code: "1f3b1",
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_name: "8ball",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
label: "translated: You (click to remove) reacted with :8ball:",
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [alice.user_id],
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
2022-10-20 02:16:48 +02:00
|
|
|
const message_id = 501;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-20 02:16:48 +02:00
|
|
|
const $message_reactions = stub_reactions(message_id);
|
2022-10-22 02:51:46 +02:00
|
|
|
const $reaction_button = $.create("reaction-button-stub");
|
|
|
|
$message_reactions.find = () => $reaction_button;
|
2024-10-02 09:16:01 +02:00
|
|
|
const $message_reactions_count = $.create("message-reaction-count-stub");
|
2022-10-22 02:51:46 +02:00
|
|
|
$reaction_button.find = (selector) => {
|
|
|
|
assert.equal(selector, ".message_reaction_count");
|
2024-10-02 09:16:01 +02:00
|
|
|
return $message_reactions_count;
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("message_reaction.hbs", false, (data) => {
|
2021-02-24 22:45:47 +01:00
|
|
|
assert.deepEqual(data, {
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_name: "8ball",
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
class: "message_reaction reacted",
|
2022-10-20 02:16:48 +02:00
|
|
|
message_id,
|
2021-02-24 22:45:47 +01:00
|
|
|
label: "translated: You (click to remove) reacted with :8ball:",
|
2022-10-20 02:16:48 +02:00
|
|
|
reaction_type: clean_reaction_object.reaction_type,
|
2021-11-20 20:13:59 +01:00
|
|
|
is_realm_emoji: false,
|
2023-03-23 19:59:41 +01:00
|
|
|
vote_text: "",
|
2021-02-24 22:45:47 +01:00
|
|
|
});
|
2022-03-17 00:31:13 +01:00
|
|
|
return "<new-reaction-stub>";
|
2021-02-24 22:45:47 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
let insert_called;
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<new-reaction-stub>").insertBefore = (element) => {
|
2022-10-22 02:51:46 +02:00
|
|
|
assert.equal(element, $reaction_button);
|
2021-02-24 22:45:47 +01:00
|
|
|
insert_called = true;
|
|
|
|
};
|
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = {
|
|
|
|
id: message_id,
|
|
|
|
reactions: [
|
2024-10-02 09:16:01 +02:00
|
|
|
{
|
|
|
|
emoji_name: "+1",
|
|
|
|
user_id: bob.user_id,
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f44d",
|
|
|
|
},
|
2024-05-28 22:55:41 +02:00
|
|
|
{
|
|
|
|
emoji_name: "8ball",
|
|
|
|
user_id: alice.user_id,
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2024-10-02 09:16:01 +02:00
|
|
|
convert_reactions_to_clean_reactions(message);
|
2024-05-28 22:55:41 +02:00
|
|
|
reactions.insert_new_reaction(clean_reaction_object, message, alice.user_id);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(insert_called);
|
2021-02-24 22:45:47 +01:00
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("insert_new_reaction (them w/zulip emoji)", ({mock_template}) => {
|
2022-10-20 02:16:48 +02:00
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
2021-11-20 20:00:38 +01:00
|
|
|
emoji_code: "zulip",
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_name: "zulip",
|
|
|
|
is_realm_emoji: false,
|
2022-10-22 02:51:46 +02:00
|
|
|
label: "translated: Bob van Roberts reacted with :zulip:",
|
2022-10-20 02:16:48 +02:00
|
|
|
local_id: "realm_emoji,zulip",
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
user_ids: [bob.user_id],
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
2022-10-20 02:16:48 +02:00
|
|
|
const message_id = 501;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-20 02:16:48 +02:00
|
|
|
const $message_reactions = stub_reactions(message_id);
|
2022-10-22 02:51:46 +02:00
|
|
|
const $reaction_button = $.create("reaction-button-stub");
|
|
|
|
$message_reactions.find = () => $reaction_button;
|
2024-10-02 09:16:01 +02:00
|
|
|
const $message_reactions_count = $.create("message-reaction-count-stub");
|
2022-10-22 02:51:46 +02:00
|
|
|
$reaction_button.find = (selector) => {
|
|
|
|
assert.equal(selector, ".message_reaction_count");
|
2024-10-02 09:16:01 +02:00
|
|
|
return $message_reactions_count;
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
|
|
|
|
2021-06-28 00:41:05 +02:00
|
|
|
mock_template("message_reaction.hbs", false, (data) => {
|
2021-02-24 22:45:47 +01:00
|
|
|
assert.deepEqual(data, {
|
|
|
|
count: 1,
|
|
|
|
url: "/static/generated/emoji/images/emoji/unicode/zulip.png",
|
|
|
|
is_realm_emoji: true,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_name: "zulip",
|
|
|
|
emoji_code: "zulip",
|
|
|
|
local_id: "realm_emoji,zulip",
|
|
|
|
class: "message_reaction",
|
2022-10-20 02:16:48 +02:00
|
|
|
message_id,
|
2021-02-24 22:45:47 +01:00
|
|
|
label: "translated: Bob van Roberts reacted with :zulip:",
|
2023-03-26 08:46:21 +02:00
|
|
|
still_url: null,
|
2022-10-20 02:16:48 +02:00
|
|
|
reaction_type: clean_reaction_object.reaction_type,
|
2023-03-23 19:59:41 +01:00
|
|
|
vote_text: "",
|
2021-02-24 22:45:47 +01:00
|
|
|
});
|
2022-03-17 00:31:13 +01:00
|
|
|
return "<new-reaction-stub>";
|
2021-02-24 22:45:47 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
let insert_called;
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<new-reaction-stub>").insertBefore = (element) => {
|
2022-10-22 02:51:46 +02:00
|
|
|
assert.equal(element, $reaction_button);
|
2021-02-24 22:45:47 +01:00
|
|
|
insert_called = true;
|
|
|
|
};
|
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = {
|
|
|
|
id: message_id,
|
|
|
|
reactions: [
|
2024-10-02 09:16:01 +02:00
|
|
|
{
|
|
|
|
emoji_name: "+1",
|
|
|
|
user_id: bob.user_id,
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f44d",
|
|
|
|
},
|
2024-05-28 22:55:41 +02:00
|
|
|
{
|
|
|
|
emoji_name: "8ball",
|
|
|
|
user_id: bob.user_id,
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
reactions.insert_new_reaction(clean_reaction_object, message, bob.user_id);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(insert_called);
|
2021-02-24 22:45:47 +01:00
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("update_existing_reaction (me)", () => {
|
2022-10-20 02:16:48 +02:00
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
2022-10-22 02:51:46 +02:00
|
|
|
count: 2,
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_alt_code: false,
|
2021-02-24 22:45:47 +01:00
|
|
|
emoji_code: "1f3b1",
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_name: "8ball",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [alice.user_id, bob.user_id],
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
2022-10-20 02:16:48 +02:00
|
|
|
const message_id = 503;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-20 02:16:48 +02:00
|
|
|
const $our_reaction = stub_reaction(message_id, "unicode_emoji,1f3b1");
|
2022-07-10 01:06:33 +02:00
|
|
|
const $reaction_count = $.create("reaction-count-stub");
|
|
|
|
$our_reaction.set_find_results(".message_reaction_count", $reaction_count);
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = {
|
|
|
|
id: message_id,
|
|
|
|
reactions: [
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: alice.user_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: bob.user_id,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
reactions.update_existing_reaction(clean_reaction_object, message, alice.user_id);
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok($our_reaction.hasClass("reacted"));
|
2021-02-24 22:45:47 +01:00
|
|
|
assert.equal(
|
2022-01-25 11:36:19 +01:00
|
|
|
$our_reaction.attr("aria-label"),
|
2021-02-24 22:45:47 +01:00
|
|
|
"translated: You (click to remove) and Bob van Roberts reacted with :8ball:",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("update_existing_reaction (them)", () => {
|
2022-10-20 02:16:48 +02:00
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
2022-10-22 02:51:46 +02:00
|
|
|
count: 4,
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_alt_code: false,
|
2021-02-24 22:45:47 +01:00
|
|
|
emoji_code: "1f3b1",
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_name: "8ball",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [alice.user_id, bob.user_id, cali.user_id, alexus.user_id],
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
2022-10-20 02:16:48 +02:00
|
|
|
const message_id = 504;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-20 02:16:48 +02:00
|
|
|
const $our_reaction = stub_reaction(message_id, "unicode_emoji,1f3b1");
|
2022-07-10 01:06:33 +02:00
|
|
|
const $reaction_count = $.create("reaction-count-stub");
|
|
|
|
$our_reaction.set_find_results(".message_reaction_count", $reaction_count);
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = {
|
|
|
|
id: message_id,
|
|
|
|
reactions: [
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: alice.user_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: bob.user_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: cali.user_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: alexus.user_id,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
|
|
|
|
reactions.update_existing_reaction(clean_reaction_object, message, alexus.user_id);
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.ok(!$our_reaction.hasClass("reacted"));
|
2021-02-24 22:45:47 +01:00
|
|
|
assert.equal(
|
2022-01-25 11:36:19 +01:00
|
|
|
$our_reaction.attr("aria-label"),
|
2021-02-24 22:45:47 +01:00
|
|
|
"translated: You (click to remove), Bob van Roberts, Cali and Alexus reacted with :8ball:",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("remove_reaction_from_view (me)", () => {
|
2022-10-20 02:16:48 +02:00
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
2022-10-22 02:51:46 +02:00
|
|
|
count: 2,
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_alt_code: false,
|
2021-02-24 22:45:47 +01:00
|
|
|
emoji_code: "1f3b1",
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_name: "8ball",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [bob.user_id, cali.user_id],
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
2022-10-20 02:16:48 +02:00
|
|
|
const message_id = 505;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
const $message_reactions = stub_reaction(message_id, "unicode_emoji,1f3b1");
|
|
|
|
$message_reactions.addClass("reacted");
|
|
|
|
const $reaction_button = $.create("reaction-button-stub");
|
|
|
|
$message_reactions.find = () => $reaction_button;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = {
|
|
|
|
id: message_id,
|
|
|
|
reactions: [
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: bob.user_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: cali.user_id,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
|
|
|
|
reactions.remove_reaction_from_view(clean_reaction_object, message, alice.user_id);
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
assert.ok(!$message_reactions.hasClass("reacted"));
|
2021-02-24 22:45:47 +01:00
|
|
|
assert.equal(
|
2022-10-22 02:51:46 +02:00
|
|
|
$message_reactions.attr("aria-label"),
|
2021-02-24 22:45:47 +01:00
|
|
|
"translated: Bob van Roberts and Cali reacted with :8ball:",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("remove_reaction_from_view (them)", () => {
|
2022-10-20 02:16:48 +02:00
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
2021-02-24 22:45:47 +01:00
|
|
|
emoji_code: "1f3b1",
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_name: "8ball",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [alice.user_id],
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
2022-10-20 02:16:48 +02:00
|
|
|
const message_id = 506;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
const $message_reactions = stub_reaction(message_id, "unicode_emoji,1f3b1");
|
|
|
|
$message_reactions.addClass("reacted");
|
|
|
|
const $reaction_button = $.create("reaction-button-stub");
|
|
|
|
$message_reactions.find = () => $reaction_button;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = {
|
|
|
|
id: message_id,
|
|
|
|
reactions: [
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: alice.user_id,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
|
|
|
|
reactions.remove_reaction_from_view(clean_reaction_object, message, bob.user_id);
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-22 02:51:46 +02:00
|
|
|
assert.ok($message_reactions.hasClass("reacted"));
|
2021-02-24 22:45:47 +01:00
|
|
|
assert.equal(
|
2022-10-22 02:51:46 +02:00
|
|
|
$message_reactions.attr("aria-label"),
|
2021-02-24 22:45:47 +01:00
|
|
|
"translated: You (click to remove) reacted with :8ball:",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-10-02 09:16:01 +02:00
|
|
|
test("remove_reaction_from_view (last person to react)", ({override_rewire}) => {
|
2022-10-20 02:16:48 +02:00
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
2021-02-24 22:45:47 +01:00
|
|
|
emoji_code: "1f3b1",
|
2022-10-20 02:16:48 +02:00
|
|
|
emoji_name: "8ball",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [],
|
2021-02-24 22:45:47 +01:00
|
|
|
};
|
2022-10-20 02:16:48 +02:00
|
|
|
const message_id = 507;
|
2021-02-24 22:45:47 +01:00
|
|
|
|
2022-10-20 02:16:48 +02:00
|
|
|
const $our_reaction = stub_reaction(message_id, "unicode_emoji,1f3b1");
|
2024-10-02 09:16:01 +02:00
|
|
|
override_rewire(reactions, "find_reaction", (message_id_param, local_id) => {
|
|
|
|
assert.equal(message_id_param, message_id);
|
|
|
|
assert.equal(local_id, "unicode_emoji,1f3b1");
|
|
|
|
return $our_reaction;
|
|
|
|
});
|
2021-02-24 22:45:47 +01:00
|
|
|
|
|
|
|
let removed;
|
2022-01-25 11:36:19 +01:00
|
|
|
$our_reaction.remove = () => {
|
2021-02-24 22:45:47 +01:00
|
|
|
removed = true;
|
|
|
|
};
|
2024-05-28 22:55:41 +02:00
|
|
|
|
2024-10-02 09:16:01 +02:00
|
|
|
const message = {
|
|
|
|
id: message_id,
|
|
|
|
reactions: [
|
|
|
|
{
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: bob.user_id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
emoji_code: "1f44d",
|
|
|
|
emoji_name: "thumbs_up",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_id: alice.user_id,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
override_rewire(reactions, "update_vote_text_on_message", noop);
|
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
reactions.remove_reaction_from_view(clean_reaction_object, message, bob.user_id);
|
|
|
|
assert.ok(removed);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("remove_reaction_from_view (last reaction)", () => {
|
|
|
|
const clean_reaction_object = {
|
|
|
|
class: "message_reaction",
|
|
|
|
count: 1,
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: "1f3b1",
|
|
|
|
emoji_name: "8ball",
|
|
|
|
is_realm_emoji: false,
|
|
|
|
local_id: "unicode_emoji,1f3b1",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
user_ids: [],
|
|
|
|
};
|
|
|
|
const message_id = 507;
|
|
|
|
|
|
|
|
const $message_reactions = stub_reactions(message_id);
|
|
|
|
|
|
|
|
// Create a stub for the specific reaction
|
|
|
|
const $specific_reaction = $.create("specific-reaction-stub");
|
|
|
|
$message_reactions.find = () => $specific_reaction;
|
|
|
|
|
|
|
|
let removed = false;
|
|
|
|
$message_reactions.remove = () => {
|
|
|
|
removed = true;
|
|
|
|
};
|
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = {id: message_id, reactions: []};
|
|
|
|
convert_reactions_to_clean_reactions(message);
|
|
|
|
reactions.remove_reaction_from_view(clean_reaction_object, message, bob.user_id);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(removed);
|
2021-02-24 22:45:47 +01:00
|
|
|
});
|
|
|
|
|
2024-03-05 19:43:44 +01:00
|
|
|
test("bogus_event", ({override}) => {
|
|
|
|
// We don't expect errors when we process events with
|
|
|
|
// bad message ids.
|
|
|
|
override(message_store, "get", noop);
|
|
|
|
|
|
|
|
const bogus_event = {
|
|
|
|
message_id: 55,
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
emoji_name: "realm_emoji",
|
|
|
|
emoji_code: "991",
|
|
|
|
user_id: 99,
|
|
|
|
};
|
|
|
|
reactions.add_reaction(bogus_event);
|
|
|
|
reactions.remove_reaction(bogus_event);
|
|
|
|
});
|
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("remove spurious user", ({override}) => {
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
// get coverage for removing non-user (it should just
|
|
|
|
// silently fail)
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = sample_message_with_clean_reactions();
|
2021-03-12 14:24:53 +01:00
|
|
|
override(message_store, "get", () => message);
|
|
|
|
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
const event = {
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_name: "frown",
|
|
|
|
emoji_code: "1f641",
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
message_id: message.id,
|
2020-04-22 23:24:28 +02:00
|
|
|
user_id: alice.user_id,
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
reactions.remove_reaction(event);
|
|
|
|
});
|
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("remove last user", ({override, override_rewire}) => {
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = sample_message_with_clean_reactions();
|
2021-03-12 14:24:53 +01:00
|
|
|
|
|
|
|
override(message_store, "get", () => message);
|
2023-12-28 05:02:26 +01:00
|
|
|
override_rewire(reactions, "remove_reaction_from_view", noop);
|
2021-02-25 14:29:15 +01:00
|
|
|
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
function assert_names(names) {
|
|
|
|
assert.deepEqual(
|
|
|
|
reactions.get_message_reactions(message).map((r) => r.emoji_name),
|
2020-07-02 02:16:03 +02:00
|
|
|
names,
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-24 22:45:47 +01:00
|
|
|
assert_names(["smile", "frown", "tada", "rocket", "wave", "inactive_realm_emoji"]);
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
|
|
|
|
const event = {
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_name: "frown",
|
|
|
|
emoji_code: "1f641",
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
message_id: message.id,
|
2020-04-22 23:24:28 +02:00
|
|
|
user_id: cali.user_id,
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
};
|
|
|
|
reactions.remove_reaction(event);
|
|
|
|
|
2021-02-24 22:45:47 +01:00
|
|
|
assert_names(["smile", "tada", "rocket", "wave", "inactive_realm_emoji"]);
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
});
|
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
test("local_reaction_id", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const reaction_info = {
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_code: "1f44d",
|
2017-10-31 22:33:28 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const local_id = reactions.get_local_reaction_id(reaction_info);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(local_id, "unicode_emoji,1f44d");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-10-31 22:33:28 +01:00
|
|
|
|
2023-12-28 05:02:26 +01:00
|
|
|
test("process_reaction_click", ({override, override_rewire}) => {
|
|
|
|
override_rewire(reactions, "remove_reaction_from_view", noop);
|
2021-02-25 14:29:15 +01:00
|
|
|
|
2024-05-28 22:55:41 +02:00
|
|
|
const message = sample_message_with_clean_reactions();
|
2021-03-12 14:24:53 +01:00
|
|
|
override(message_store, "get", () => message);
|
|
|
|
|
2021-02-18 06:30:13 +01:00
|
|
|
const expected_reaction_info = {
|
2020-07-15 01:29:15 +02:00
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_name: "smile",
|
2020-06-30 21:16:29 +02:00
|
|
|
emoji_code: "1f642",
|
2017-10-31 22:33:28 +01:00
|
|
|
};
|
2021-01-28 06:01:09 +01:00
|
|
|
|
|
|
|
// Test spectator cannot react.
|
|
|
|
page_params.is_spectator = true;
|
|
|
|
let stub = make_stub();
|
2021-09-07 04:09:12 +02:00
|
|
|
spectators.login_to_access = stub.f;
|
2021-01-28 06:01:09 +01:00
|
|
|
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);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("code coverage", ({override}) => {
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
/*
|
|
|
|
We just silently fail in a few places in the reaction
|
|
|
|
code, since events may come for messages that we don't
|
|
|
|
have yet, or reactions may be for deactivated users, etc.
|
|
|
|
|
|
|
|
Here we just cheaply ensure 100% line coverage to make
|
|
|
|
it easy to enforce 100% coverage for more significant
|
|
|
|
code additions.
|
|
|
|
*/
|
2021-02-25 14:13:30 +01:00
|
|
|
override(message_store, "get", (id) => {
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
assert.equal(id, 42);
|
|
|
|
return {
|
2024-05-28 22:55:41 +02:00
|
|
|
clean_reactions: new Map(),
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
};
|
2021-02-25 14:13:30 +01:00
|
|
|
});
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
|
|
|
|
reactions.remove_reaction({
|
2020-04-22 23:24:28 +02:00
|
|
|
message_id: 42, // TODO: REACTIONS API
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-03 19:07:13 +02:00
|
|
|
test("duplicates", () => {
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
const dup_reaction_message = {
|
|
|
|
id: 1001,
|
|
|
|
reactions: [
|
2020-06-30 21:16:29 +02:00
|
|
|
{emoji_name: "smile", user_id: 5, reaction_type: "unicode_emoji", emoji_code: "1f642"},
|
|
|
|
{emoji_name: "smile", user_id: 5, reaction_type: "unicode_emoji", emoji_code: "1f642"},
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.expect("error", "server sent duplicate reactions");
|
2024-05-28 22:55:41 +02:00
|
|
|
convert_reactions_to_clean_reactions(dup_reaction_message);
|
reactions: Rewrite code to use clean reactions.
Before this commit, the reactions code would
take the `message.reactions` structure from
the server and try to "collapse" all the reactions
for the same users into the same reactions,
but with each reaction having a list of user_ids.
It was a strangely denormalized structure that
was awkward to work with, and it made it really
hard to reason about whether the data was in
the original structure that the server sent or
the modified structure.
Now we use a cleaner, normalized Map to keep
each reaction (i.e. one per emoji), and we
write that to `message.clean_reactions`.
The `clean_reactions` structure is now the
authoritatize source for all reaction-related
operations. As soon as you try to do anything
with reactions, we build the `clean_reactions`
data on the fly from the server data.
In particular, when we process events, we just
directly manipulate the `clean_reactions` data,
which is much easier to work with, since it's
a Map and doesn't duplicate any data.
This rewrite should avoid some obscure bugs.
I use `r` as shorthand for the clean reaction
structures, so as not to confuse it with
data from the server's message.reactions.
It also avoids some confusion where we use
`reaction` as a var name for the reaction
elements.
2020-03-08 13:13:47 +01:00
|
|
|
});
|
2020-03-09 14:26:17 +01:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("process_reaction_click undefined", ({override}) => {
|
2021-02-24 17:08:13 +01:00
|
|
|
override(message_store, "get", () => undefined);
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.expect("error", "reactions: Bad message id");
|
|
|
|
blueslip.expect("error", "message_id for reaction click is unknown");
|
2020-07-15 01:29:15 +02:00
|
|
|
reactions.process_reaction_click(55, "whatever");
|
2021-02-24 17:08:13 +01:00
|
|
|
});
|
2020-03-09 14:26:17 +01:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("process_reaction_click bad local id", ({override}) => {
|
2024-05-28 22:55:41 +02:00
|
|
|
const stub_message = {id: 4001, clean_reactions: new Map()};
|
2021-03-12 14:24:53 +01:00
|
|
|
override(message_store, "get", () => stub_message);
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.expect("error", "Data integrity problem for reaction");
|
2020-07-15 01:29:15 +02:00
|
|
|
reactions.process_reaction_click("some-msg-id", "bad-local-id");
|
2020-03-09 14:26:17 +01:00
|
|
|
});
|