Implement a single mark_messages() function
Rather than having each thread type define its own mark method, let's instead have them tell us what api call to use to avoid duplicating work. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
f517f8c391
commit
53d9aa4e3d
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 <whatever>.info to find unread count and timestamp.
|
||||
# - self.api_history: The slack api method to find unread messages
|
||||
# - do_mark_messages(): Call <whatever>.mark to set unread cursor.
|
||||
# - do_fetch_info(): Call <whatever>.info to find unread count and timestamp.
|
||||
# - self.api_history: The slack api method to find unread messages
|
||||
# - self.api_mark: Call <whatever>.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):
|
||||
|
|
Loading…
Reference in New Issue