slackmail/slack/im.py
Anna Schumaker 3ae8ce02b5 Don't open up IMs just to check their info
Instead, we can use the undocumented "im.info" call to find the same
thing.  Additionally, we can use the "is_open" value as the result of
the is_member() thread function.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
2016-11-22 16:48:59 -05:00

46 lines
1.1 KiB
Python

#
# Copyright 2016 (c) Anna Schumaker.
#
from . import api
from . import auth
from . import threads
from . import users
class IM(threads.Thread):
def __init__(self, json):
threads.Thread.__init__(self, json)
self.api_history = "im.history"
self.api_info = { "call" : "im.info", "ret" : "im" }
self.api_mark = "im.mark"
self.__uid = json.get("user")
self.__user = users.info(self.__uid)
self.__im_open = None
def name(self):
return "Chat With %s" % self.__user.name()
def url(self, base):
return "%s/messages/@%s/" % (base, self.__user.user())
def call_fetch_info(self):
ret = threads.Thread.call_fetch_info(self)
if ret["ok"] == True:
self.__im_open = ret[self.api_info["ret"]]["is_open"]
return ret
def is_member(self):
if self.__im_open == None:
self.fetch_info()
return self.__im_open
def list():
ret = api.call("im.list", token = auth.token())
if ret["ok"] == False:
return None
im_list = []
for im in ret["ims"]:
im_list += [ IM(im) ]
return im_list