Mark channels read when updated

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-05-26 17:00:20 -04:00
parent b5d715096e
commit 253e0374f0
2 changed files with 12 additions and 2 deletions

View File

@ -49,7 +49,8 @@ class Channel:
class Message:
def __init__(self, json):
self.__time = datetime.fromtimestamp(float(json["ts"]))
self.__ts = json["ts"]
self.__time = datetime.fromtimestamp(self.__ts))
self.__user = users.info(json["user"])
self.__text = json["text"].encode("utf-8").decode("latin-1")
@ -59,6 +60,9 @@ class Message:
def __str__(self):
return "%s %s: %s" % (self.__time.time(), self.__user.name(), self.__text)
def ts(self):
return self.__tsi
def history(channel, timestamp):
@ -70,6 +74,9 @@ def history(channel, timestamp):
for message in ret["messages"]:
m_list += [ Message(message) ]
m_list.sort()
if len(m_list) > 0:
mark(channel, m_list[-1].ts())
return m_list
def info(channel):
@ -87,3 +94,6 @@ def list():
for channel in ret["channels"]:
ch_list += [ Channel(channel) ]
return ch_list
def mark(channel, timestamp):
api.call("channels.mark", token = auth.token(), channel = channel, ts = timestamp)

View File

@ -24,7 +24,7 @@ for channel in slack.channels.list():
msg = MIMEText("\n".join(text))
msg["Subject"] = "[%s] %s" % (slack.team(), channel.name())
msg["From"] = "slack@OcarinaProject.net"
msg["From"] = "SlackMail@OcarinaProject.net"
msg["To"] = "schumaker.anna@gmail.com"
s.sendmail("SlackMail", "schumaker.anna@gmail.com", msg.as_string())