user_status: Add architecture to support status emoji feature.

In this commit, we only update the existing architecture
to support the status emoji feature:

* We add the `user_status_emoji_info` map so we can
keep track of the users' staus emoji.

* Listen to the server event to update/set the
`user_status_emoji_info` map.

* Add `status_emoji_info` field, when getting user's data.
This commit is contained in:
Riken Shah 2021-06-27 17:04:17 +00:00 committed by Tim Abbott
parent 6c003a7802
commit 840ab92f7f
8 changed files with 121 additions and 3 deletions

View File

@ -387,6 +387,7 @@ test("first/prev/next", ({override, mock_template}) => {
user_circle_class: "user_circle_green",
user_circle_status: "translated: Active",
user_id: alice.user_id,
status_emoji_info: undefined,
});
} else if (data.user_id === fred.user_id) {
rendered_fred = true;
@ -400,6 +401,7 @@ test("first/prev/next", ({override, mock_template}) => {
user_circle_class: "user_circle_green",
user_circle_status: "translated: Active",
faded: false,
status_emoji_info: undefined,
});
} else {
throw new Error(`we did not expect to have to render a row for ${data.name}`);
@ -440,6 +442,7 @@ test("insert_one_user_into_empty_list", ({override, mock_template}) => {
user_circle_class: "user_circle_green",
user_circle_status: "translated: Active",
faded: true,
status_emoji_info: undefined,
});
assert.ok(html.startsWith("<li data-user-id="));
return html;

View File

@ -547,10 +547,17 @@ test("user_last_seen_time_status", ({override}) => {
assert.equal(buddy_data.user_last_seen_time_status(selma.user_id), "translated: Idle");
});
test("get_items_for_users", () => {
test("get_items_for_users", ({override}) => {
people.add_active_user(alice);
people.add_active_user(fred);
user_status.set_away(alice.user_id);
page_params.emojiset = "google";
const status_emoji_info = {
emoji_name: "car",
emoji_code: "1f697",
reaction_type: "unicode_emoji",
};
override(user_status, "get_status_emoji", () => status_emoji_info);
const user_ids = [me.user_id, alice.user_id, fred.user_id];
assert.deepEqual(buddy_data.get_items_for_users(user_ids), [
@ -561,6 +568,7 @@ test("get_items_for_users", () => {
my_user_status: "translated: (you)",
name: "Human Myself",
num_unread: 0,
status_emoji_info,
user_circle_class: "user_circle_green",
user_circle_status: "translated: Active",
user_id: 1001,
@ -572,6 +580,7 @@ test("get_items_for_users", () => {
my_user_status: undefined,
name: "Alice Smith",
num_unread: 0,
status_emoji_info,
user_circle_class: "user_circle_empty_line",
user_circle_status: "translated: Unavailable",
user_id: 1002,
@ -583,6 +592,7 @@ test("get_items_for_users", () => {
my_user_status: undefined,
name: "Fred Flintstone",
num_unread: 0,
status_emoji_info,
user_circle_class: "user_circle_empty",
user_circle_status: "translated: Offline",
user_id: 1003,

View File

@ -759,6 +759,7 @@ run_test("update_display_settings", ({override}) => {
event = event_fixtures.update_display_settings__emojiset;
called = false;
override(settings_display, "report_emojiset_change", stub.f);
override(activity, "build_user_sidebar", noop);
page_params.emojiset = "text";
dispatch(event);
assert.equal(stub.num_calls, 1);
@ -911,6 +912,24 @@ run_test("user_status", ({override}) => {
assert_same(args.user_id, 63);
}
event = event_fixtures.user_status__set_status_emoji;
{
const stub = make_stub();
override(activity, "redraw_user", stub.f);
dispatch(event);
assert.equal(stub.num_calls, 1);
const args = stub.get_args("user_id");
assert_same(args.user_id, test_user.user_id);
const emoji_info = user_status.get_status_emoji(test_user.user_id);
assert.deepEqual(emoji_info, {
emoji_name: "smiley",
emoji_code: "1f603",
reaction_type: "unicode_emoji",
// Extra parameters that were added by `emoji.get_emoji_details_by_name`
emoji_alt_code: false,
});
}
event = event_fixtures.user_status__set_status_text;
{
const stub = make_stub();

View File

@ -827,6 +827,14 @@ exports.fixtures = {
away: true,
},
user_status__set_status_emoji: {
type: "user_status",
user_id: test_user.user_id,
emoji_name: "smiley",
emoji_code: "1f603",
reaction_type: "unicode_emoji",
},
user_status__set_status_text: {
type: "user_status",
user_id: test_user.user_id,

View File

@ -62,6 +62,28 @@ run_test("basics", () => {
status_text: "",
});
assert.equal(user_status.get_status_text(2), undefined);
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",
// Extra parameters that were added by `emoji.get_emoji_details_by_name`
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);
});
run_test("server", () => {
@ -79,10 +101,22 @@ run_test("server", () => {
assert.equal(sent_data, undefined);
user_status.server_set_away();
assert.deepEqual(sent_data, {away: true, status_text: undefined});
assert.deepEqual(sent_data, {
away: true,
status_text: undefined,
emoji_code: undefined,
emoji_name: undefined,
reaction_type: undefined,
});
user_status.server_revoke_away();
assert.deepEqual(sent_data, {away: false, status_text: undefined});
assert.deepEqual(sent_data, {
away: false,
status_text: undefined,
emoji_code: undefined,
emoji_name: undefined,
reaction_type: undefined,
});
let called;

View File

@ -176,6 +176,8 @@ export function info_for(user_id) {
const user_circle_class = get_user_circle_class(user_id);
const person = people.get_by_user_id(user_id);
const my_user_status = get_my_user_status(user_id);
const status_emoji_info = user_status.get_status_emoji(user_id);
const user_circle_status = status_description(user_id);
return {
@ -183,6 +185,7 @@ export function info_for(user_id) {
name: person.full_name,
user_id,
my_user_status,
status_emoji_info,
is_current_user: people.is_my_user_id(user_id),
num_unread: get_num_unread(user_id),
user_circle_class,

View File

@ -626,6 +626,8 @@ export function dispatch_normal_event(event) {
if (message_lists.current === message_list.narrowed) {
message_list.narrowed.rerender();
}
// Rerender buddy list status emoji
activity.build_user_sidebar();
}
if (event.setting_name === "enter_sends") {
page_params.enter_sends = event.setting;
@ -710,6 +712,11 @@ export function dispatch_normal_event(event) {
});
activity.redraw_user(event.user_id);
}
if (event.emoji_name !== undefined) {
user_status.set_status_emoji(event);
activity.redraw_user(event.user_id);
}
break;
case "realm_export":
settings_exports.populate_exports_table(event.exports);

View File

@ -1,8 +1,12 @@
import * as emoji from "../shared/js/emoji";
import * as blueslip from "./blueslip";
import * as channel from "./channel";
import {page_params} from "./page_params";
const away_user_ids = new Set();
const user_info = new Map();
const user_status_emoji_info = new Map();
export function server_update(opts) {
channel.post({
@ -10,6 +14,9 @@ export function server_update(opts) {
data: {
away: opts.away,
status_text: opts.status_text,
emoji_name: opts.emoji_name,
emoji_code: opts.emoji_code,
reaction_type: opts.reaction_type,
},
idempotent: true,
success() {
@ -59,6 +66,25 @@ export function set_status_text(opts) {
user_info.set(opts.user_id, opts.status_text);
}
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, {
emoji_name: opts.emoji_name,
emoji_code: opts.emoji_code,
reaction_type: opts.reaction_type,
emoji_alt_code: page_params.emojiset === "text",
...emoji.get_emoji_details_by_name(opts.emoji_name),
});
}
export function initialize(params) {
away_user_ids.clear();
user_info.clear();
@ -75,5 +101,13 @@ export function initialize(params) {
if (dct.status_text) {
user_info.set(user_id, dct.status_text);
}
if (dct.emoji_name) {
user_status_emoji_info.set(user_id, {
emoji_name: dct.emoji_name,
emoji_code: dct.emoji_code,
reaction_type: dct.reaction_type,
});
}
}
}