aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_message.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2024-02-03 11:38:33 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 12:57:00 +0100
commit7639dcb4995b13c2756f9d59e0a67e22cba57a38 (patch)
treef38f36bfab6ab13fb89497fff1fb5e8d29e787ac /slack/slack_message.py
parent15cabf8ba1b9daa7e28475ea46cc5a8fd478e174 (diff)
downloadwee-slack-7639dcb4995b13c2756f9d59e0a67e22cba57a38.tar.gz
Correctly show reactions with more than 50 users in v3.0.0
If a reaction has more than 50 users, the list of users will be cropped to just 50 users. This made the counts wrong since we used the number of users rather than the count property. Fix it by using the count property instead and adding "and others" to the list of users if show_reaction_nicks is enabled (the same as the Slack client shows when you hover over the reaction). This is the same fix as in commit 6b388cd9, but for version 3.0.0.
Diffstat (limited to 'slack/slack_message.py')
-rw-r--r--slack/slack_message.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/slack/slack_message.py b/slack/slack_message.py
index 576629c..30f1ad4 100644
--- a/slack/slack_message.py
+++ b/slack/slack_message.py
@@ -853,14 +853,15 @@ class SlackMessage:
users = await gather(
*(self.workspace.users[user_id] for user_id in reaction["users"])
)
- nicks = ",".join(user.nick.format() for user in users)
- users_str = f"({nicks})"
+ nicks = [user.nick.format() for user in users]
+ nicks_extra = (
+ ["and others"] if len(reaction["users"]) < reaction["count"] else []
+ )
+ users_str = f"({', '.join(nicks + nicks_extra)})"
else:
users_str = ""
- reaction_string = (
- f"{get_emoji(reaction['name'])}{len(reaction['users'])}{users_str}"
- )
+ reaction_string = f"{get_emoji(reaction['name'])}{reaction['count']}{users_str}"
if self.workspace.my_user.id in reaction["users"]:
return with_color(
@@ -874,7 +875,7 @@ class SlackMessage:
async def _create_reactions_string(self) -> str:
reactions = self._message_json.get("reactions", [])
reactions_with_users = [
- reaction for reaction in reactions if len(reaction["users"]) > 0
+ reaction for reaction in reactions if reaction["count"] > 0
]
reaction_strings = await gather(
*(