2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
const {mock_esm, zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-03-16 23:38:59 +01:00
|
|
|
const blueslip = require("../zjsunit/zblueslip");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-03-10 06:10:32 +01:00
|
|
|
const channel = mock_esm("../../static/js/channel");
|
2021-07-23 22:24:51 +02:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const user_status = zrequire("user_status");
|
2021-06-27 17:07:12 +02:00
|
|
|
const emoji_codes = zrequire("../generated/emoji/emoji_codes.json");
|
2022-03-25 14:47:51 +01:00
|
|
|
const emoji = zrequire("emoji");
|
2021-06-27 17:07:12 +02:00
|
|
|
|
|
|
|
const emoji_params = {
|
|
|
|
realm_emoji: {
|
|
|
|
991: {
|
|
|
|
id: "991",
|
user_status: Fix status emoji handling of deactivated custom emoji.
Previously, if a user had a realm emoji set as their status emoji and
someone deleted the realm emoji, the app would fail to initialize,
because of the error we throw from `./shared/js/emoji.js`.
This commit fixes this by just displaying the deactivated emoji,
similar to how we do when realm_emoji used as reactions are deleted.
As part of the fix, we add a function get_emoji_details_for_rendering,
which duplicates some of the logic used in `reactions.js`, we can
refactor to remove the duplication in `reactions.js` in future
commits.
Note that the following behaviour is a part of our design:
If a user sets their emoji to a particular realm emoji, say for
example "octo-ninja", and "octo-ninja" was then deleted, and a new
emoji was added with the name "octo-ninja", the user's status emoji
would change to show the new emoji instead of the deleted emoji.
Also note that in the `user_status.js` node test, we were able to
change the name for the 991 realm_emoji because it had not been
previously used anywhere in the test (possibly added as just a copy
paste artifact?).
Fixes: #20274.
emoji: Use reaction_type parameter to analyze emoji.
2021-11-20 10:14:52 +01:00
|
|
|
name: "example_realm_emoji",
|
2021-06-27 17:07:12 +02:00
|
|
|
source_url: "/url/for/991",
|
user_status: Fix status emoji handling of deactivated custom emoji.
Previously, if a user had a realm emoji set as their status emoji and
someone deleted the realm emoji, the app would fail to initialize,
because of the error we throw from `./shared/js/emoji.js`.
This commit fixes this by just displaying the deactivated emoji,
similar to how we do when realm_emoji used as reactions are deleted.
As part of the fix, we add a function get_emoji_details_for_rendering,
which duplicates some of the logic used in `reactions.js`, we can
refactor to remove the duplication in `reactions.js` in future
commits.
Note that the following behaviour is a part of our design:
If a user sets their emoji to a particular realm emoji, say for
example "octo-ninja", and "octo-ninja" was then deleted, and a new
emoji was added with the name "octo-ninja", the user's status emoji
would change to show the new emoji instead of the deleted emoji.
Also note that in the `user_status.js` node test, we were able to
change the name for the 991 realm_emoji because it had not been
previously used anywhere in the test (possibly added as just a copy
paste artifact?).
Fixes: #20274.
emoji: Use reaction_type parameter to analyze emoji.
2021-11-20 10:14:52 +01:00
|
|
|
still_url: "/url/still/991",
|
2021-06-27 17:07:12 +02:00
|
|
|
deactivated: false,
|
|
|
|
},
|
user_status: Fix status emoji handling of deactivated custom emoji.
Previously, if a user had a realm emoji set as their status emoji and
someone deleted the realm emoji, the app would fail to initialize,
because of the error we throw from `./shared/js/emoji.js`.
This commit fixes this by just displaying the deactivated emoji,
similar to how we do when realm_emoji used as reactions are deleted.
As part of the fix, we add a function get_emoji_details_for_rendering,
which duplicates some of the logic used in `reactions.js`, we can
refactor to remove the duplication in `reactions.js` in future
commits.
Note that the following behaviour is a part of our design:
If a user sets their emoji to a particular realm emoji, say for
example "octo-ninja", and "octo-ninja" was then deleted, and a new
emoji was added with the name "octo-ninja", the user's status emoji
would change to show the new emoji instead of the deleted emoji.
Also note that in the `user_status.js` node test, we were able to
change the name for the 991 realm_emoji because it had not been
previously used anywhere in the test (possibly added as just a copy
paste artifact?).
Fixes: #20274.
emoji: Use reaction_type parameter to analyze emoji.
2021-11-20 10:14:52 +01:00
|
|
|
992: {
|
|
|
|
id: "992",
|
|
|
|
name: "deactivated_realm_emoji",
|
|
|
|
source_url: "/url/for/992",
|
|
|
|
still_url: "/url/still/992",
|
|
|
|
deactivated: true,
|
|
|
|
},
|
2021-06-27 17:07:12 +02:00
|
|
|
},
|
|
|
|
emoji_codes,
|
|
|
|
};
|
|
|
|
|
|
|
|
emoji.initialize(emoji_params);
|
2018-12-19 17:11:17 +01:00
|
|
|
|
|
|
|
function initialize() {
|
2020-02-25 12:16:26 +01:00
|
|
|
const params = {
|
|
|
|
user_status: {
|
2020-07-15 01:29:15 +02:00
|
|
|
1: {away: true, status_text: "in a meeting"},
|
2020-02-25 12:16:26 +01:00
|
|
|
2: {away: true},
|
|
|
|
3: {away: true},
|
2021-06-27 17:07:12 +02:00
|
|
|
4: {emoji_name: "smiley", emoji_code: "1f603", reaction_type: "unicode_emoji"},
|
user_status: Fix status emoji handling of deactivated custom emoji.
Previously, if a user had a realm emoji set as their status emoji and
someone deleted the realm emoji, the app would fail to initialize,
because of the error we throw from `./shared/js/emoji.js`.
This commit fixes this by just displaying the deactivated emoji,
similar to how we do when realm_emoji used as reactions are deleted.
As part of the fix, we add a function get_emoji_details_for_rendering,
which duplicates some of the logic used in `reactions.js`, we can
refactor to remove the duplication in `reactions.js` in future
commits.
Note that the following behaviour is a part of our design:
If a user sets their emoji to a particular realm emoji, say for
example "octo-ninja", and "octo-ninja" was then deleted, and a new
emoji was added with the name "octo-ninja", the user's status emoji
would change to show the new emoji instead of the deleted emoji.
Also note that in the `user_status.js` node test, we were able to
change the name for the 991 realm_emoji because it had not been
previously used anywhere in the test (possibly added as just a copy
paste artifact?).
Fixes: #20274.
emoji: Use reaction_type parameter to analyze emoji.
2021-11-20 10:14:52 +01:00
|
|
|
5: {
|
|
|
|
emoji_name: "deactivated_realm_emoji",
|
|
|
|
emoji_code: "992",
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
},
|
2020-02-25 12:16:26 +01:00
|
|
|
},
|
2019-01-21 19:06:03 +01:00
|
|
|
};
|
2020-02-25 12:16:26 +01:00
|
|
|
user_status.initialize(params);
|
2018-12-19 17:11:17 +01:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("basics", () => {
|
2018-12-19 17:11:17 +01:00
|
|
|
initialize();
|
user_status: Fix status emoji handling of deactivated custom emoji.
Previously, if a user had a realm emoji set as their status emoji and
someone deleted the realm emoji, the app would fail to initialize,
because of the error we throw from `./shared/js/emoji.js`.
This commit fixes this by just displaying the deactivated emoji,
similar to how we do when realm_emoji used as reactions are deleted.
As part of the fix, we add a function get_emoji_details_for_rendering,
which duplicates some of the logic used in `reactions.js`, we can
refactor to remove the duplication in `reactions.js` in future
commits.
Note that the following behaviour is a part of our design:
If a user sets their emoji to a particular realm emoji, say for
example "octo-ninja", and "octo-ninja" was then deleted, and a new
emoji was added with the name "octo-ninja", the user's status emoji
would change to show the new emoji instead of the deleted emoji.
Also note that in the `user_status.js` node test, we were able to
change the name for the 991 realm_emoji because it had not been
previously used anywhere in the test (possibly added as just a copy
paste artifact?).
Fixes: #20274.
emoji: Use reaction_type parameter to analyze emoji.
2021-11-20 10:14:52 +01:00
|
|
|
|
|
|
|
assert.deepEqual(user_status.get_status_emoji(5), {
|
|
|
|
emoji_code: "992",
|
|
|
|
emoji_name: "deactivated_realm_emoji",
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
url: "/url/for/992",
|
|
|
|
still_url: "/url/still/992",
|
|
|
|
});
|
|
|
|
|
|
|
|
user_status.set_status_emoji({
|
|
|
|
user_id: 5,
|
|
|
|
emoji_code: "991",
|
|
|
|
emoji_name: "example_realm_emoji",
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(user_status.get_status_emoji(5), {
|
|
|
|
emoji_alt_code: false,
|
|
|
|
emoji_code: "991",
|
|
|
|
emoji_name: "example_realm_emoji",
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
still_url: "/url/still/991",
|
|
|
|
url: "/url/for/991",
|
|
|
|
});
|
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(user_status.is_away(2));
|
|
|
|
assert.ok(!user_status.is_away(99));
|
2018-12-19 17:11:17 +01:00
|
|
|
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!user_status.is_away(4));
|
2018-12-19 17:11:17 +01:00
|
|
|
user_status.set_away(4);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(user_status.is_away(4));
|
2018-12-19 17:11:17 +01:00
|
|
|
user_status.revoke_away(4);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!user_status.is_away(4));
|
2019-01-23 19:25:22 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(user_status.get_status_text(1), "in a meeting");
|
2019-01-23 19:25:22 +01:00
|
|
|
|
|
|
|
user_status.set_status_text({
|
|
|
|
user_id: 2,
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "out to lunch",
|
2019-01-23 19:25:22 +01:00
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(user_status.get_status_text(2), "out to lunch");
|
2019-01-23 19:25:22 +01:00
|
|
|
|
|
|
|
user_status.set_status_text({
|
|
|
|
user_id: 2,
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "",
|
2019-01-23 19:25:22 +01:00
|
|
|
});
|
|
|
|
assert.equal(user_status.get_status_text(2), undefined);
|
2021-06-27 19:04:17 +02:00
|
|
|
|
|
|
|
user_status.set_status_emoji({
|
|
|
|
user_id: 2,
|
|
|
|
emoji_name: "smiley",
|
|
|
|
emoji_code: "1f603",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
});
|
|
|
|
assert.deepEqual(user_status.get_status_emoji(2), {
|
|
|
|
emoji_name: "smiley",
|
|
|
|
emoji_code: "1f603",
|
|
|
|
reaction_type: "unicode_emoji",
|
|
|
|
emoji_alt_code: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
user_status.set_status_emoji({
|
|
|
|
user_id: 2,
|
|
|
|
emoji_name: "",
|
|
|
|
emoji_code: "",
|
|
|
|
reaction_type: "",
|
|
|
|
});
|
|
|
|
assert.deepEqual(user_status.get_status_emoji(2), undefined);
|
2018-12-19 17:11:17 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("server", () => {
|
2018-12-19 17:11:17 +01:00
|
|
|
initialize();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let sent_data;
|
|
|
|
let success;
|
2018-12-19 17:11:17 +01:00
|
|
|
|
|
|
|
channel.post = (opts) => {
|
2019-01-23 19:25:22 +01:00
|
|
|
sent_data = opts.data;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(opts.url, "/json/users/me/status");
|
2019-01-26 21:14:33 +01:00
|
|
|
success = opts.success;
|
2018-12-19 17:11:17 +01:00
|
|
|
};
|
|
|
|
|
2019-01-23 19:25:22 +01:00
|
|
|
assert.equal(sent_data, undefined);
|
2018-12-19 17:11:17 +01:00
|
|
|
|
|
|
|
user_status.server_set_away();
|
2021-06-27 19:04:17 +02:00
|
|
|
assert.deepEqual(sent_data, {
|
|
|
|
away: true,
|
|
|
|
status_text: undefined,
|
|
|
|
emoji_code: undefined,
|
|
|
|
emoji_name: undefined,
|
|
|
|
reaction_type: undefined,
|
|
|
|
});
|
2018-12-19 17:11:17 +01:00
|
|
|
|
|
|
|
user_status.server_revoke_away();
|
2021-06-27 19:04:17 +02:00
|
|
|
assert.deepEqual(sent_data, {
|
|
|
|
away: false,
|
|
|
|
status_text: undefined,
|
|
|
|
emoji_code: undefined,
|
|
|
|
emoji_name: undefined,
|
|
|
|
reaction_type: undefined,
|
|
|
|
});
|
2019-01-26 21:14:33 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let called;
|
2019-01-26 21:14:33 +01:00
|
|
|
|
|
|
|
user_status.server_update({
|
2020-07-15 01:29:15 +02:00
|
|
|
status_text: "out to lunch",
|
2019-01-26 21:14:33 +01:00
|
|
|
success: () => {
|
|
|
|
called = true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
success();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(called);
|
2018-12-19 17:11:17 +01:00
|
|
|
});
|
2020-01-12 22:17:02 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("defensive checks", () => {
|
|
|
|
blueslip.expect("error", "need ints for user_id", 2);
|
|
|
|
user_status.set_away("string");
|
|
|
|
user_status.revoke_away("string");
|
user_status: Fix status emoji handling of deactivated custom emoji.
Previously, if a user had a realm emoji set as their status emoji and
someone deleted the realm emoji, the app would fail to initialize,
because of the error we throw from `./shared/js/emoji.js`.
This commit fixes this by just displaying the deactivated emoji,
similar to how we do when realm_emoji used as reactions are deleted.
As part of the fix, we add a function get_emoji_details_for_rendering,
which duplicates some of the logic used in `reactions.js`, we can
refactor to remove the duplication in `reactions.js` in future
commits.
Note that the following behaviour is a part of our design:
If a user sets their emoji to a particular realm emoji, say for
example "octo-ninja", and "octo-ninja" was then deleted, and a new
emoji was added with the name "octo-ninja", the user's status emoji
would change to show the new emoji instead of the deleted emoji.
Also note that in the `user_status.js` node test, we were able to
change the name for the 991 realm_emoji because it had not been
previously used anywhere in the test (possibly added as just a copy
paste artifact?).
Fixes: #20274.
emoji: Use reaction_type parameter to analyze emoji.
2021-11-20 10:14:52 +01:00
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() =>
|
|
|
|
user_status.set_status_emoji({
|
|
|
|
user_id: 5,
|
|
|
|
emoji_name: "emoji",
|
|
|
|
// no status code or reaction type.
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
name: "Error",
|
|
|
|
message: "Invalid params.",
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() =>
|
|
|
|
user_status.set_status_emoji({
|
|
|
|
user_id: 5,
|
|
|
|
reaction_type: "realm_emoji",
|
|
|
|
emoji_name: "does_not_exist",
|
|
|
|
emoji_code: "fake_code",
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
name: "Error",
|
|
|
|
message: "Cannot find realm emoji for code 'fake_code'.",
|
|
|
|
},
|
|
|
|
);
|
2020-01-12 22:17:02 +01:00
|
|
|
});
|