diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2020-05-14 02:03:20 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2020-05-30 21:13:21 +0200 |
commit | a1abd66ff18e2bf64ca0e3cec382c5093a10f325 (patch) | |
tree | 9d16aa81d1d6f6bb56b5f76dbf1020a137624d6c | |
parent | 9ebe3f79c6000455f5ba6387ba0f3572e0fe4bca (diff) | |
download | wee-slack-a1abd66ff18e2bf64ca0e3cec382c5093a10f325.tar.gz |
Notify for newly subscribed threads
When you receive a new thread message on one of your messages that's not
already a thread you may get the subscribed event after the message
event. Previously, that meant you would not get a notification, because
notify_thread ran in process_message, before you were subscribed. Run
notify_thread in process_thread_subscribed too to ensure we notify for
these messages.
-rw-r--r-- | wee_slack.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/wee_slack.py b/wee_slack.py index 2d1aad8..d6175d9 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2618,6 +2618,7 @@ class SlackMessage(object): self.ts = SlackTS(message_json['ts']) self.subscribed = message_json.get("subscribed", False) self.last_read = SlackTS(message_json.get("last_read", 0)) + self.last_notify = SlackTS(0) def __hash__(self): return hash(self.ts) @@ -2756,9 +2757,14 @@ class SlackMessage(object): def number_of_replies(self): return max(len(self.submessages), self.message_json.get("reply_count", 0)) - def notify_thread(self, message): + def notify_thread(self, message=None): + if message is None: + if not self.submessages: + return + message = self.channel.messages.get(self.submessages[-1]) + if (self.thread_channel and self.thread_channel.active or - message.ts <= self.last_read): + message.ts <= self.last_read or message.ts <= self.last_notify): return if message.has_mention(): @@ -2768,6 +2774,8 @@ class SlackMessage(object): else: return + self.last_notify = SlackTS() + if config.auto_open_threads: self.open_thread() @@ -3472,8 +3480,10 @@ def process_thread_subscribed(message_json, eventrouter, team, channel, metadata parent_ts = SlackTS(message_json["subscription"]["thread_ts"]) parent_message = channel.messages.get(parent_ts) if parent_message: + parent_message.last_read = SlackTS(message_json["subscription"]["last_read"]) parent_message.subscribed = True channel.change_message(parent_ts) + parent_message.notify_thread() else: channel.get_thread_history(parent_ts) |