diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2016-03-05 00:00:13 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2016-04-22 16:41:10 +0200 |
commit | cb2f046ff82f6fe339a8a7d541eca61de7844958 (patch) | |
tree | c86c5b1ad26dd32c6050b990d78c743250a14a24 /wee_slack.py | |
parent | 4bedc30a4cfe4ff6aba9d1339a8da1305ea12ad8 (diff) | |
download | wee-slack-cb2f046ff82f6fe339a8a7d541eca61de7844958.tar.gz |
Show nicks for reactions
Instead of only showing the number of persons that added a reaction,
show the nicks that added them. The nicks are shown comma separated in
parenthesis after each reaction.
This adds an item named users to the reaction dict of a message, which
contains a list of all of the user ids. Since the code assumes that item
exists, which makes it incompatible with the old structure, the
CACHE_VERSION is increased by one.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/wee_slack.py b/wee_slack.py index ab41b37..a39f494 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -32,7 +32,7 @@ SCRIPT_DESC = "Extends weechat for typing notification/search/etc on slack.com" BACKLOG_SIZE = 200 SCROLLBACK_SIZE = 500 -CACHE_VERSION = "3" +CACHE_VERSION = "4" SLACK_API_TRANSLATOR = { "channel": { @@ -711,17 +711,17 @@ class Channel(object): self.buffer_redraw() return True - def add_reaction(self, ts, reaction): + def add_reaction(self, ts, reaction, user): if self.has_message(ts): message_index = self.messages.index(ts) - self.messages[message_index].add_reaction(reaction) + self.messages[message_index].add_reaction(reaction, user) self.change_message(ts) return True - def remove_reaction(self, ts, reaction): + def remove_reaction(self, ts, reaction, user): if self.has_message(ts): message_index = self.messages.index(ts) - self.messages[message_index].remove_reaction(reaction) + self.messages[message_index].remove_reaction(reaction, user) self.change_message(ts) return True @@ -933,23 +933,25 @@ class Message(object): new_text = unicode(new_text, 'utf-8') self.message_json["text"] = new_text - def add_reaction(self, reaction): + def add_reaction(self, reaction, user): if "reactions" in self.message_json: found = False for r in self.message_json["reactions"]: if r["name"] == reaction: r["count"] += 1 + r["users"].append(user) found = True if not found: - self.message_json["reactions"].append({u"count": 1, u"name": reaction}) + self.message_json["reactions"].append({u"count": 1, u"name": reaction, u"users": [user]}) else: - self.message_json["reactions"] = [{u"count": 1, u"name": reaction}] + self.message_json["reactions"] = [{u"count": 1, u"name": reaction, u"users": [user]}] - def remove_reaction(self, reaction): + def remove_reaction(self, reaction, user): if "reactions" in self.message_json: for r in self.message_json["reactions"]: if r["name"] == reaction: r["count"] -= 1 + r["users"].remove(user) else: pass @@ -1555,14 +1557,14 @@ def process_error(message_json): def process_reaction_added(message_json): if message_json["item"].get("type") == "message": channel = channels.find(message_json["item"]["channel"]) - channel.add_reaction(message_json["item"]["ts"], message_json["reaction"]) + channel.add_reaction(message_json["item"]["ts"], message_json["reaction"], message_json["user"]) else: dbg("Reaction to item type not supported: " + str(message_json)) def process_reaction_removed(message_json): if message_json["item"].get("type") == "message": channel = channels.find(message_json["item"]["channel"]) - channel.remove_reaction(message_json["item"]["ts"], message_json["reaction"]) + channel.remove_reaction(message_json["item"]["ts"], message_json["reaction"], message_json["user"]) else: dbg("Reaction to item type not supported: " + str(message_json)) @@ -1575,7 +1577,8 @@ def create_reaction_string(reactions): for r in reactions: if r["count"] > 0: count += 1 - reaction_string += ":{}:{} ".format(r["name"], r["count"]) + users = ",".join(resolve_ref("@{}".format(user)) for user in r["users"]) + reaction_string += ":{}:({}) ".format(r["name"], users) reaction_string = reaction_string[:-1] + ']' if count == 0: reaction_string = '' |