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 4a82d95
Show file tree
Hide file tree
Showing 2 changed files with 25 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
12 changes: 9 additions & 3 deletions zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,16 @@ 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"])
if user_id is None:
user_name = reaction["user"]["full_name"]
user = self.model.get_user_info(user_id)
if user is not None:
user_name = user.get("full_name", None)
if user_id == my_user_id:
user_name = "You"
reaction_stats[reaction["emoji_name"]].append((user_id, user_name))
Expand Down

0 comments on commit 4a82d95

Please sign in to comment.