mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
reactions: Deduplicate shared code.
Creates a function for code shared by update_user_fields and make_clean_reaction.
This commit is contained in:
@@ -579,27 +579,35 @@ function make_clean_reaction({
|
|||||||
emoji_details.reaction_type === "realm_emoji" ||
|
emoji_details.reaction_type === "realm_emoji" ||
|
||||||
emoji_details.reaction_type === "zulip_extra_emoji";
|
emoji_details.reaction_type === "zulip_extra_emoji";
|
||||||
|
|
||||||
const count = user_ids.length;
|
|
||||||
const label = generate_title(emoji_name, user_ids);
|
|
||||||
|
|
||||||
const reaction_class = user_ids.includes(current_user.user_id)
|
|
||||||
? "message_reaction reacted"
|
|
||||||
: "message_reaction";
|
|
||||||
|
|
||||||
// The vote_text field set here is used directly in the Handlebars
|
|
||||||
// template for rendering (or rerendering!) a message.
|
|
||||||
const vote_text = get_vote_text(user_ids, should_display_reactors);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
local_id,
|
local_id,
|
||||||
user_ids,
|
user_ids,
|
||||||
...emoji_details,
|
...emoji_details,
|
||||||
emoji_alt_code,
|
emoji_alt_code,
|
||||||
is_realm_emoji,
|
is_realm_emoji,
|
||||||
class: reaction_class,
|
...build_reaction_data(user_ids, emoji_name, should_display_reactors),
|
||||||
count,
|
};
|
||||||
label,
|
}
|
||||||
vote_text,
|
|
||||||
|
function build_reaction_data(
|
||||||
|
user_ids: number[],
|
||||||
|
emoji_name: string,
|
||||||
|
should_display_reactors: boolean,
|
||||||
|
): {
|
||||||
|
count: number;
|
||||||
|
label: string;
|
||||||
|
class: string;
|
||||||
|
vote_text: string;
|
||||||
|
} {
|
||||||
|
return {
|
||||||
|
count: user_ids.length,
|
||||||
|
label: generate_title(emoji_name, user_ids),
|
||||||
|
class: user_ids.includes(current_user.user_id)
|
||||||
|
? "message_reaction reacted"
|
||||||
|
: "message_reaction",
|
||||||
|
// The vote_text field set here is used directly in the Handlebars
|
||||||
|
// template for rendering (or rerendering!) a message.
|
||||||
|
vote_text: get_vote_text(user_ids, should_display_reactors),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,30 +619,14 @@ export function update_user_fields(
|
|||||||
// who reacted on a message might have changed, including due to
|
// who reacted on a message might have changed, including due to
|
||||||
// upvote/downvotes on ANY reaction in the message, because those
|
// upvote/downvotes on ANY reaction in the message, because those
|
||||||
// can change the correct value of should_display_reactors to use.
|
// can change the correct value of should_display_reactors to use.
|
||||||
clean_reaction_object.count = clean_reaction_object.user_ids.length;
|
Object.assign(clean_reaction_object, {
|
||||||
clean_reaction_object.label = generate_title(
|
...clean_reaction_object,
|
||||||
clean_reaction_object.emoji_name,
|
...build_reaction_data(
|
||||||
clean_reaction_object.user_ids,
|
clean_reaction_object.user_ids,
|
||||||
);
|
clean_reaction_object.emoji_name,
|
||||||
|
should_display_reactors,
|
||||||
if (clean_reaction_object.user_ids.includes(current_user.user_id)) {
|
),
|
||||||
clean_reaction_object.class = "message_reaction reacted";
|
});
|
||||||
} else {
|
|
||||||
clean_reaction_object.class = "message_reaction";
|
|
||||||
}
|
|
||||||
|
|
||||||
clean_reaction_object.count = clean_reaction_object.user_ids.length;
|
|
||||||
clean_reaction_object.label = generate_title(
|
|
||||||
clean_reaction_object.emoji_name,
|
|
||||||
clean_reaction_object.user_ids,
|
|
||||||
);
|
|
||||||
|
|
||||||
// The vote_text field set here is used directly in the Handlebars
|
|
||||||
// template for rendering (or rerendering!) a message.
|
|
||||||
clean_reaction_object.vote_text = get_vote_text(
|
|
||||||
clean_reaction_object.user_ids,
|
|
||||||
should_display_reactors,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReactionUserIdAndCount = {
|
type ReactionUserIdAndCount = {
|
||||||
|
|||||||
@@ -1177,6 +1177,22 @@ test("remove_reaction_from_view (last person)", () => {
|
|||||||
assert.ok(removed);
|
assert.ok(removed);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
test("remove spurious user", ({override}) => {
|
test("remove spurious user", ({override}) => {
|
||||||
// get coverage for removing non-user (it should just
|
// get coverage for removing non-user (it should just
|
||||||
// silently fail)
|
// silently fail)
|
||||||
|
|||||||
Reference in New Issue
Block a user