2015-06-09 09:56:55 -04:00
|
|
|
#
|
|
|
|
# Copyright 2015 (c) Anna Schumaker.
|
|
|
|
#
|
|
|
|
from . import api
|
|
|
|
from . import auth
|
|
|
|
from . import threads
|
|
|
|
|
|
|
|
|
|
|
|
class Group(threads.Thread):
|
|
|
|
def __init__(self, json):
|
|
|
|
threads.Thread.__init__(self, json)
|
|
|
|
|
|
|
|
def do_fetch_info(self):
|
|
|
|
return info(self.id())
|
|
|
|
|
2015-06-09 10:22:10 -04:00
|
|
|
def do_fetch_messages(self, ts):
|
|
|
|
return history(self.id(), ts)
|
|
|
|
|
|
|
|
def do_mark_messages(self, ts):
|
|
|
|
mark(self.id(), ts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def history(group, timestamp):
|
|
|
|
ret = api.call("groups.history", token = auth.token(), channel = group, oldest = timestamp)
|
|
|
|
if ret["ok"] == False:
|
|
|
|
return None
|
|
|
|
return ret["messages"]
|
2015-06-09 09:56:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
def info(group):
|
|
|
|
ret = api.call("groups.info", token = auth.token(), channel = group)
|
|
|
|
if ret["ok"] == False:
|
|
|
|
return None
|
|
|
|
return ret["group"]
|
|
|
|
|
|
|
|
def list():
|
|
|
|
ret = api.call("groups.list", token = auth.token())
|
|
|
|
if ret["ok"] == False:
|
|
|
|
return None
|
|
|
|
|
|
|
|
gr_list = []
|
|
|
|
for group in ret["groups"]:
|
|
|
|
gr_list += [ Group(group) ]
|
|
|
|
return gr_list
|
2015-06-09 10:22:10 -04:00
|
|
|
|
|
|
|
def mark(group, timestamp):
|
|
|
|
api.call("groups.mark", token = auth.token(), channel = group, ts = timestamp)
|