aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-10-25 01:17:39 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2023-10-25 01:17:39 +0200
commit6b388cd9aea6b091e16bdd22d0a28d9f1931b284 (patch)
tree64c73dac45b8307372235731cf73527e5eaaab82 /wee_slack.py
parentcf244bb2b9571b64bdd9b9e9ec3ac4e74a213190 (diff)
downloadwee-slack-6b388cd9aea6b091e16bdd22d0a28d9f1931b284.tar.gz
Correctly show reactions with more than 50 users
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).
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 88949d9..73723b9 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -3505,17 +3505,19 @@ class SlackMessage(object):
def add_reaction(self, reaction_name, user):
reaction = self.get_reaction(reaction_name)
if reaction:
+ reaction["count"] += 1
if user not in reaction["users"]:
reaction["users"].append(user)
else:
if "reactions" not in self.message_json:
self.message_json["reactions"] = []
self.message_json["reactions"].append(
- {"name": reaction_name, "users": [user]}
+ {"name": reaction_name, "count": 1, "users": [user]}
)
def remove_reaction(self, reaction_name, user):
reaction = self.get_reaction(reaction_name)
+ reaction["count"] -= 1
if user in reaction["users"]:
reaction["users"].remove(user)
@@ -5139,9 +5141,12 @@ def create_user_status_string(profile):
def create_reaction_string(reaction, myidentifier):
if config.show_reaction_nicks:
nicks = [resolve_ref("@{}".format(user)) for user in reaction["users"]]
- users = "({})".format(", ".join(nicks))
+ nicks_extra = (
+ ["and others"] if len(reaction["users"]) < reaction["count"] else []
+ )
+ users = "({})".format(", ".join(nicks + nicks_extra))
else:
- users = len(reaction["users"])
+ users = reaction["count"]
reaction_string = ":{}:{}".format(reaction["name"], users)
if myidentifier in reaction["users"]:
return colorize_string(
@@ -5154,7 +5159,7 @@ def create_reaction_string(reaction, myidentifier):
def create_reactions_string(reactions, myidentifier):
- reactions_with_users = [r for r in reactions if len(r["users"]) > 0]
+ reactions_with_users = [r for r in reactions if r["count"] > 0]
reactions_string = " ".join(
create_reaction_string(r, myidentifier) for r in reactions_with_users
)