aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorAidan Epstein <aidan@jmad.org>2020-03-21 12:34:00 -0700
committerAidan Epstein <aidan@jmad.org>2020-03-21 12:34:00 -0700
commitdc7489d2ea4440d10a61294334ff78f62afa9874 (patch)
treee73c1152f2f337bfdbfb7a69d1d10074eb10c3e9 /wee_slack.py
parent2a0ee25f95c13766efa1989dc609ff38f4ed9806 (diff)
downloadwee-slack-dc7489d2ea4440d10a61294334ff78f62afa9874.tar.gz
Use actual last_read times in threads, instead of that of the parent channel.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 69a4195..8848d62 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2240,6 +2240,8 @@ class SlackThreadChannel(SlackChannelCommon):
self.members = self.parent_message.channel.members
self.team = self.parent_message.team
self.last_line_from = None
+ self.last_read = self.parent_message.message_json.get("last_read", SlackTS())
+ self.new_messages = False
@property
def identifier(self):
@@ -2266,32 +2268,42 @@ class SlackThreadChannel(SlackChannelCommon):
self.rename()
def mark_read(self, ts=None, update_remote=True, force=False):
- if True or force: #TODO: Add check for new_messages here.
+ if self.new_messages or force:
if self.channel_buffer:
w.buffer_set(self.channel_buffer, "unread", "")
w.buffer_set(self.channel_buffer, "hotlist", "-1")
if not ts:
ts = next(reversed(self.messages), SlackTS())
+ if ts > self.last_read:
+ self.last_read = ts
if update_remote:
s = SlackRequest(self.team, SLACK_API_TRANSLATOR[self.type]["mark"],
{"channel": self.identifier, "thread_ts": self.parent_message.ts, "ts": ts}, channel=self)
self.eventrouter.receive(s)
+ self.new_messages = False
def buffer_prnt(self, nick, text, timestamp, tag_nick=None):
data = "{}\t{}".format(format_nick(nick, self.last_line_from), text)
self.last_line_from = nick
ts = SlackTS(timestamp)
if self.channel_buffer:
+ # backlog messages - we will update the read marker as we print these
+ backlog = ts <= self.last_read
+ if not backlog:
+ self.new_messages = True
+
if self.parent_message.channel.type in ["im", "mpim"]:
tagset = "dm"
else:
tagset = "channel"
+
+ no_log = backlog
self_msg = tag_nick == self.team.nick
- tags = tag(tagset, user=tag_nick, self_msg=self_msg)
+ tags = tag(tagset, user=tag_nick, self_msg=self_msg, backlog=backlog, no_log=no_log)
w.prnt_date_tags(self.channel_buffer, ts.major, tags, data)
modify_last_print_time(self.channel_buffer, ts.minor)
- if self_msg:
+ if backlog or self_msg:
self.mark_read(ts, update_remote=False, force=True)
def get_history(self):
@@ -3030,8 +3042,8 @@ def subprocess_thread_message(message_json, eventrouter, team, channel, history_
if parent_message.thread_channel and parent_message.thread_channel.active:
parent_message.thread_channel.buffer_prnt(message.sender, parent_message.thread_channel.render(message), message.ts, tag_nick=message.sender_plain)
- elif message.ts > channel.last_read and parent_message.subscribed:
- parent_message.notify_thread(action="subscribed", sender_id=message_json["user"]) #TODO: Use thread last_read ts
+ elif message.ts > message.message_json.get("last_read", SlackTS()) and parent_message.subscribed:
+ parent_message.notify_thread(action="subscribed", sender_id=message_json["user"])
elif message.ts > channel.last_read and message.has_mention():
parent_message.notify_thread(action="mention", sender_id=message_json["user"])