aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2017-02-02 22:00:16 -0800
committerRyan Huber <rhuber@gmail.com>2017-02-02 22:00:16 -0800
commit4c8cf73778414336f979ef9efc3712ca6891c5f2 (patch)
tree330becc80d677af009881f1cda05a2a656ccc4cc /wee_slack.py
parent01b9f3c2525ecaf331175f2e447423e915c2d476 (diff)
downloadwee-slack-4c8cf73778414336f979ef9efc3712ca6891c5f2.tar.gz
backlog all works now
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 79e5d4c..d7dae0c 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -742,8 +742,11 @@ class SlackChannel(object):
data = "{}\t{}".format(nick, text)
ts = SlackTS(timestamp)
if self.channel_buffer:
- if ts < SlackTS(self.last_read):
+ #backlog messages - we will update the read marker as we print these
+ backlog = False
+ if ts <= SlackTS(self.last_read):
tags = tag("backlog")
+ backlog = True
elif self.type in ["im", "mpdm"]:
tags = tag("dm")
self.new_messages = True
@@ -753,13 +756,15 @@ class SlackChannel(object):
w.prnt_date_tags(self.channel_buffer, ts.major, tags, data)
modify_print_time(self.channel_buffer, ts.minorstr(), ts.major)
+ if backlog:
+ self.mark_read(ts, update_remote=False, force=True)
def send_message(self, message):
#team = self.eventrouter.teams[self.team]
message = linkify_text(message, self.team, self)
dbg(message)
request = {"type": "message", "channel": self.identifier, "text": message, "_team": self.team.team_hash, "user": self.team.myidentifier}
self.team.send_to_websocket(request)
- self.mark_read()
+ self.mark_read(force=True)
def store_message(self, message, team, from_me=False):
if from_me:
message.message_json["user"] = team.myidentifier
@@ -834,17 +839,15 @@ class SlackChannel(object):
if timestamp + 4 > time.time():
typing.append(user)
return typing
- def mark_read(self, ts=None, update_remote=True):
+ def mark_read(self, ts=None, update_remote=True, force=False):
if not ts:
ts = SlackTS()
- if self.new_messages:
- self.last_read = ts
+ 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 update_remote:
- s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["mark"], {"channel": self.identifier, "ts": self.last_read}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
- print s.request
+ s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["mark"], {"channel": self.identifier, "ts": ts}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
self.eventrouter.receive(s)
self.new_messages = False
@@ -1308,7 +1311,7 @@ def process_channel_marked(message_json, eventrouter, **kwargs):
"""
channel = kwargs["channel"]
ts = kwargs["ts"]
- channel.mark_read(False, ts)
+ channel.mark_read(ts=ts, update_remote=False)
def process_group_marked(message_json, eventrouter, **kwargs):
process_channel_marked(message_json, eventrouter, **kwargs)
def process_im_marked(message_json, eventrouter, **kwargs):