Skip to content

Commit

Permalink
messages: Update metadata handling for message reaction.
Browse files Browse the repository at this point in the history
This commit is in sync with the new metadata changes for
reactions data sent in messages API. It uses user_id
for identification of the reaction's user.
  • Loading branch information
mounilKshah committed Nov 17, 2024
1 parent d88adae commit 4a0bc53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 16 additions & 0 deletions tests/ui_tools/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,22 @@ def test_transform_content(self, mocker, raw_html, expected_content):
@pytest.mark.parametrize(
"to_vary_in_each_message, expected_text, expected_attributes",
[
case(
{
"reactions": [
{
"emoji_name": "thumbs_up",
"emoji_code": "1f44d",
"user_id": 1001,
"reaction_type": "unicode_emoji",
},
],
},
" :thumbs_up: 1 ",
[
("reaction", 17),
],
),
case(
{
"reactions": [
Expand Down
11 changes: 8 additions & 3 deletions zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,19 @@ def reactions_view(
my_user_id = self.model.user_id
reaction_stats = defaultdict(list)
for reaction in reactions:
user_id = int(reaction["user"].get("id", -1))
user_id = reaction.get("user_id", -1)
if user_id == -1:
user_id = int(reaction["user"]["user_id"])
user_name = reaction["user"]["full_name"]
user_id = int(reaction["user"].get("id", -1))
if user_id == -1:
user_id = int(reaction["user"]["user_id"])
user_name = self.model.user_dict.get(user_id, None)
if user_id is None:
user_name = reaction["user"]["full_name"]
if user_id == my_user_id:
user_name = "You"
reaction_stats[reaction["emoji_name"]].append((user_id, user_name))


for reaction, ids in reaction_stats.items():
if (my_user_id, "You") in ids:
ids.remove((my_user_id, "You"))
Expand Down

0 comments on commit 4a0bc53

Please sign in to comment.