Skip to content

Commit 4a82d95

Browse files
committed
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.
1 parent d88adae commit 4a82d95

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

tests/ui_tools/test_messages.py

+16
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,22 @@ def test_transform_content(self, mocker, raw_html, expected_content):
15971597
@pytest.mark.parametrize(
15981598
"to_vary_in_each_message, expected_text, expected_attributes",
15991599
[
1600+
case(
1601+
{
1602+
"reactions": [
1603+
{
1604+
"emoji_name": "thumbs_up",
1605+
"emoji_code": "1f44d",
1606+
"user_id": 1001,
1607+
"reaction_type": "unicode_emoji",
1608+
},
1609+
],
1610+
},
1611+
" :thumbs_up: 1 ",
1612+
[
1613+
("reaction", 17),
1614+
],
1615+
),
16001616
case(
16011617
{
16021618
"reactions": [

zulipterminal/ui_tools/messages.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,16 @@ def reactions_view(
272272
my_user_id = self.model.user_id
273273
reaction_stats = defaultdict(list)
274274
for reaction in reactions:
275-
user_id = int(reaction["user"].get("id", -1))
275+
user_id = reaction.get("user_id", -1)
276276
if user_id == -1:
277-
user_id = int(reaction["user"]["user_id"])
278-
user_name = reaction["user"]["full_name"]
277+
user_id = int(reaction["user"].get("id", -1))
278+
if user_id == -1:
279+
user_id = int(reaction["user"]["user_id"])
280+
if user_id is None:
281+
user_name = reaction["user"]["full_name"]
282+
user = self.model.get_user_info(user_id)
283+
if user is not None:
284+
user_name = user.get("full_name", None)
279285
if user_id == my_user_id:
280286
user_name = "You"
281287
reaction_stats[reaction["emoji_name"]].append((user_id, user_name))

0 commit comments

Comments
 (0)