2021-02-28 00:39:51 +01:00
|
|
|
import * as channel from "./channel";
|
2022-03-25 14:47:51 +01:00
|
|
|
import * as emoji from "./emoji";
|
2021-07-28 16:00:58 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
2021-02-28 00:39:51 +01:00
|
|
|
|
2020-02-03 09:42:50 +01:00
|
|
|
const user_info = new Map();
|
2021-06-27 19:04:17 +02:00
|
|
|
const user_status_emoji_info = new Map();
|
2018-12-19 17:11:17 +01:00
|
|
|
|
2022-09-21 15:49:36 +02:00
|
|
|
export function server_update_status(opts) {
|
2018-12-19 17:11:17 +01:00
|
|
|
channel.post({
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/users/me/status",
|
2019-01-23 19:25:22 +01:00
|
|
|
data: {
|
|
|
|
status_text: opts.status_text,
|
2021-06-27 19:04:17 +02:00
|
|
|
emoji_name: opts.emoji_name,
|
|
|
|
emoji_code: opts.emoji_code,
|
|
|
|
reaction_type: opts.reaction_type,
|
2019-01-23 19:25:22 +01:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2019-01-26 21:14:33 +01:00
|
|
|
if (opts.success) {
|
|
|
|
opts.success();
|
|
|
|
}
|
|
|
|
},
|
2018-12-19 17:11:17 +01:00
|
|
|
});
|
2021-02-10 17:03:21 +01:00
|
|
|
}
|
2018-12-19 17:11:17 +01:00
|
|
|
|
2022-09-21 15:49:36 +02:00
|
|
|
export function server_invisible_mode_on() {
|
|
|
|
channel.patch({
|
|
|
|
url: "/json/settings",
|
|
|
|
data: {
|
|
|
|
presence_enabled: false,
|
|
|
|
},
|
|
|
|
});
|
2021-02-10 17:03:21 +01:00
|
|
|
}
|
2018-12-19 17:11:17 +01:00
|
|
|
|
2022-09-21 15:49:36 +02:00
|
|
|
export function server_invisible_mode_off() {
|
|
|
|
channel.patch({
|
|
|
|
url: "/json/settings",
|
|
|
|
data: {
|
|
|
|
presence_enabled: true,
|
|
|
|
},
|
|
|
|
});
|
2021-02-10 17:03:21 +01:00
|
|
|
}
|
2018-12-19 17:11:17 +01:00
|
|
|
|
2021-02-10 17:03:21 +01:00
|
|
|
export function get_status_text(user_id) {
|
2019-01-23 19:25:22 +01:00
|
|
|
return user_info.get(user_id);
|
2021-02-10 17:03:21 +01:00
|
|
|
}
|
2019-01-23 19:25:22 +01:00
|
|
|
|
2021-02-10 17:03:21 +01:00
|
|
|
export function set_status_text(opts) {
|
2019-01-23 19:25:22 +01:00
|
|
|
if (!opts.status_text) {
|
2020-02-03 07:41:38 +01:00
|
|
|
user_info.delete(opts.user_id);
|
2019-01-23 19:25:22 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
user_info.set(opts.user_id, opts.status_text);
|
2021-02-10 17:03:21 +01:00
|
|
|
}
|
2019-01-23 19:25:22 +01:00
|
|
|
|
2021-06-27 19:04:17 +02:00
|
|
|
export function get_status_emoji(user_id) {
|
|
|
|
return user_status_emoji_info.get(user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function set_status_emoji(opts) {
|
|
|
|
if (!opts.emoji_name) {
|
|
|
|
user_status_emoji_info.delete(opts.user_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
user_status_emoji_info.set(opts.user_id, {
|
2021-07-28 16:00:58 +02:00
|
|
|
emoji_alt_code: user_settings.emojiset === "text",
|
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
|
|
|
...emoji.get_emoji_details_for_rendering({
|
|
|
|
emoji_name: opts.emoji_name,
|
|
|
|
emoji_code: opts.emoji_code,
|
|
|
|
reaction_type: opts.reaction_type,
|
|
|
|
}),
|
2021-06-27 19:04:17 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-10 17:03:21 +01:00
|
|
|
export function initialize(params) {
|
2021-03-08 16:08:27 +01:00
|
|
|
user_info.clear();
|
|
|
|
|
2020-02-25 12:16:26 +01:00
|
|
|
for (const [str_user_id, dct] of Object.entries(params.user_status)) {
|
2020-01-12 22:09:39 +01:00
|
|
|
// JSON does not allow integer keys, so we
|
|
|
|
// convert them here.
|
2020-10-07 09:17:30 +02:00
|
|
|
const user_id = Number.parseInt(str_user_id, 10);
|
2020-01-12 22:09:39 +01:00
|
|
|
|
2019-01-23 19:25:22 +01:00
|
|
|
if (dct.status_text) {
|
|
|
|
user_info.set(user_id, dct.status_text);
|
|
|
|
}
|
2021-06-27 19:04:17 +02:00
|
|
|
|
|
|
|
if (dct.emoji_name) {
|
|
|
|
user_status_emoji_info.set(user_id, {
|
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
|
|
|
...emoji.get_emoji_details_for_rendering(dct),
|
2021-06-27 19:04:17 +02:00
|
|
|
});
|
|
|
|
}
|
2020-02-06 04:31:32 +01:00
|
|
|
}
|
2021-02-10 17:03:21 +01:00
|
|
|
}
|