From 4a82d95488735fa651747719a5b9555e2a87eb17 Mon Sep 17 00:00:00 2001 From: mounilKshah Date: Sun, 17 Nov 2024 17:11:31 +0530 Subject: [PATCH] messages: Update metadata handling for message reaction. 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. --- tests/ui_tools/test_messages.py | 16 ++++++++++++++++ zulipterminal/ui_tools/messages.py | 12 +++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/ui_tools/test_messages.py b/tests/ui_tools/test_messages.py index 08ba7d0661..5ef0df43ba 100644 --- a/tests/ui_tools/test_messages.py +++ b/tests/ui_tools/test_messages.py @@ -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": [ diff --git a/zulipterminal/ui_tools/messages.py b/zulipterminal/ui_tools/messages.py index 2b67ae6e71..f9f18fb064 100644 --- a/zulipterminal/ui_tools/messages.py +++ b/zulipterminal/ui_tools/messages.py @@ -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))