aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorAidan Epstein <aidan@jmad.org>2020-03-25 19:51:28 -0700
committerAidan Epstein <aidan@jmad.org>2020-03-25 19:51:28 -0700
commit87aa6cd5b1ddb8a2b50489d90e33ef75bb857900 (patch)
treebb5ac3f7b6523071f0961e39698af8034fef7603 /wee_slack.py
parenta4ac89208b4f7b916c48191fbca95602ceb5adde (diff)
downloadwee-slack-87aa6cd5b1ddb8a2b50489d90e33ef75bb857900.tar.gz
Refactor mark_read into SlackChannelCommon.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py43
1 files changed, 15 insertions, 28 deletions
diff --git a/wee_slack.py b/wee_slack.py
index ec5cfa0..a019263 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1597,6 +1597,20 @@ class SlackChannelCommon(object):
elif ts in self.messages:
return self.messages[ts].hash
+ def mark_read(self, ts=None, update_remote=True, force=False, post_data={}):
+ 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, "ts": ts, **post_data}, channel=self)
+ self.eventrouter.receive(s)
+ self.new_messages = False
class SlackChannel(SlackChannelCommon):
@@ -1943,21 +1957,6 @@ class SlackChannel(SlackChannelCommon):
del self.typing[user]
return typing
- def mark_read(self, ts=None, update_remote=True, force=False):
- 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, "ts": ts}, channel=self)
- self.eventrouter.receive(s)
- self.new_messages = False
-
def user_joined(self, user_id):
# ugly hack - for some reason this gets turned into a list
self.members = set(self.members)
@@ -2268,19 +2267,7 @@ class SlackThreadChannel(SlackChannelCommon):
self.rename()
def mark_read(self, ts=None, update_remote=True, force=False):
- 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
+ super().mark_read(ts=ts, update_remote=update_remote, force=force, post_data={"thread_ts": self.parent_message.ts})
def buffer_prnt(self, nick, text, timestamp, tag_nick=None):
data = "{}\t{}".format(format_nick(nick, self.last_line_from), text)