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>
This commit is contained in:
parent
a0644d225c
commit
3ae8ce02b5
14
slack/im.py
14
slack/im.py
|
@ -10,10 +10,11 @@ class IM(threads.Thread):
|
||||||
def __init__(self, json):
|
def __init__(self, json):
|
||||||
threads.Thread.__init__(self, json)
|
threads.Thread.__init__(self, json)
|
||||||
self.api_history = "im.history"
|
self.api_history = "im.history"
|
||||||
self.api_info = { "call" : "im.open", "ret" : "channel" }
|
self.api_info = { "call" : "im.info", "ret" : "im" }
|
||||||
self.api_mark = "im.mark"
|
self.api_mark = "im.mark"
|
||||||
self.__uid = json.get("user")
|
self.__uid = json.get("user")
|
||||||
self.__user = users.info(self.__uid)
|
self.__user = users.info(self.__uid)
|
||||||
|
self.__im_open = None
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return "Chat With %s" % self.__user.name()
|
return "Chat With %s" % self.__user.name()
|
||||||
|
@ -22,8 +23,15 @@ class IM(threads.Thread):
|
||||||
return "%s/messages/@%s/" % (base, self.__user.user())
|
return "%s/messages/@%s/" % (base, self.__user.user())
|
||||||
|
|
||||||
def call_fetch_info(self):
|
def call_fetch_info(self):
|
||||||
return api.call(self.api_info["call"], token = auth.token(),
|
ret = threads.Thread.call_fetch_info(self)
|
||||||
user = self.__uid, return_im = True)
|
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():
|
def list():
|
||||||
|
|
|
@ -37,7 +37,6 @@ class Thread:
|
||||||
if json["ok"] == True:
|
if json["ok"] == True:
|
||||||
self.__unread = json[self.api_info["ret"]].get("unread_count", None)
|
self.__unread = json[self.api_info["ret"]].get("unread_count", None)
|
||||||
self.__last_ts = json[self.api_info["ret"]].get("last_read", None)
|
self.__last_ts = json[self.api_info["ret"]].get("last_read", None)
|
||||||
self.__id = json[self.api_info["ret"]].get("id", 0)
|
|
||||||
|
|
||||||
def fetch_messages(self):
|
def fetch_messages(self):
|
||||||
json = api.call(self.api_history, token = auth.token(),
|
json = api.call(self.api_history, token = auth.token(),
|
||||||
|
|
Loading…
Reference in New Issue