diff --git a/slack/channels.py b/slack/channels.py index d6f4e87..1b497c6 100644 --- a/slack/channels.py +++ b/slack/channels.py @@ -12,14 +12,12 @@ class Channel(threads.Thread): def __init__(self, json): threads.Thread.__init__(self, json) self.api_history = "channels.history" + self.api_mark = "channels.mark" self.__member = json.get("is_member", False) def do_fetch_info(self): return info(self.id()) - def do_mark_messages(self, ts): - mark(self.id(), ts) - def is_member(self): return self.__member @@ -40,6 +38,3 @@ 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) diff --git a/slack/groups.py b/slack/groups.py index 94d6fd9..949fd03 100644 --- a/slack/groups.py +++ b/slack/groups.py @@ -10,13 +10,11 @@ class Group(threads.Thread): def __init__(self, json): threads.Thread.__init__(self, json) self.api_history = "groups.history" + self.api_mark = "groups.mark" def do_fetch_info(self): return info(self.id()) - def do_mark_messages(self, ts): - mark(self.id(), ts) - def info(group): @@ -34,6 +32,3 @@ def list(): for group in ret["groups"]: gr_list += [ Group(group) ] return gr_list - -def mark(group, timestamp): - api.call("groups.mark", token = auth.token(), channel = group, ts = timestamp) diff --git a/slack/im.py b/slack/im.py index 055fc4c..1a72411 100644 --- a/slack/im.py +++ b/slack/im.py @@ -10,6 +10,7 @@ class IM(threads.Thread): def __init__(self, json): threads.Thread.__init__(self, json) self.api_history = "im.history" + self.api_mark = "im.mark" self.__uid = json.get("user") self.__user = users.info(self.__uid) @@ -22,9 +23,6 @@ class IM(threads.Thread): def do_fetch_info(self): return info(self.id(), self.__uid) - def do_mark_messages(self, ts): - mark(self.id(), ts) - def info(im, uid): @@ -42,6 +40,3 @@ def list(): for im in ret["ims"]: im_list += [ IM(im) ] return im_list - -def mark(im, timestamp): - api.call("im.mark", token = auth.token(), channel = im, ts = timestamp) diff --git a/slack/threads.py b/slack/threads.py index d9c607f..eaa74e5 100644 --- a/slack/threads.py +++ b/slack/threads.py @@ -9,9 +9,9 @@ from . import chat # This class represents a slack "thread", which could be a channel, group, # or chat. Note that child classes need to define the following variables: # -# - do_fetch_info(): Call .info to find unread count and timestamp. -# - self.api_history: The slack api method to find unread messages -# - do_mark_messages(): Call .mark to set unread cursor. +# - do_fetch_info(): Call .info to find unread count and timestamp. +# - self.api_history: The slack api method to find unread messages +# - self.api_mark: Call .mark to set unread cursor. # class Thread: def __init__(self, json): @@ -42,6 +42,10 @@ class Thread: return None return json["messages"] + def mark_messages(self, stamp): + api.call(self.api_mark, token = auth.token(), + channel = self.__id, ts = stamp) + def id(self): return self.__id @@ -73,7 +77,7 @@ class Thread: else: m_list += [ msg ] - self.do_mark_messages(m_list[-1].ts()) + self.mark_messages(m_list[-1].ts()) return m_list def unread_count(self):