reactions: Remove emoji container when reaction count is 0.

While adding a new reaction, we create a new JQuery element
called "message_reaction_container" and append it to the
view to display the emoji.

Previously, when the reaction count became zero for an emoji,
we used to just remove the emoji but not the JQuery element
mentioned above, requiring a reload to remove it. This
inconsistency introduced a bug in the UI. causing unwanted
spaces between emojies as this element used to get accumulated.

This commit resolves the bug by introducing logic to remove
reaction containers with no reactions.

Fixes: #32983
This commit is contained in:
whilstsomebody
2025-01-13 20:16:15 +05:30
committed by Tim Abbott
parent 6586d9078e
commit 733ab5f2f8
2 changed files with 9 additions and 9 deletions

View File

@@ -468,9 +468,11 @@ export let remove_reaction_from_view = (
}
if (reaction_count === 0) {
// If this user was the only one reacting for this emoji, we simply
// remove the reaction and exit.
$reaction.remove();
// If this user was the only one reacting for this emoji, we
// remove the entire `message_reaction` template outer
// container, and then update vote text in case we now have
// few enough reactions to display names again.
$reaction.parent(".message_reaction_container").remove();
update_vote_text_on_message(message);
return;
}

View File

@@ -1259,15 +1259,13 @@ test("remove_reaction_from_view (last person to react)", ({override_rewire}) =>
};
const message_id = 507;
const $reaction_container = $.create("stub-reaction-container");
const $our_reaction = stub_reaction(message_id, "unicode_emoji,1f3b1");
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;
});
$our_reaction.parent = () => $reaction_container;
let removed;
$our_reaction.remove = () => {
$our_reaction.parent().remove = () => {
removed = true;
};