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:
Anna Schumaker 2016-11-22 16:48:59 -05:00
parent a0644d225c
commit 3ae8ce02b5
2 changed files with 11 additions and 4 deletions

View File

@ -10,10 +10,11 @@ class IM(threads.Thread):
def __init__(self, json):
threads.Thread.__init__(self, json)
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.__uid = json.get("user")
self.__user = users.info(self.__uid)
self.__im_open = None
def name(self):
return "Chat With %s" % self.__user.name()
@ -22,8 +23,15 @@ class IM(threads.Thread):
return "%s/messages/@%s/" % (base, self.__user.user())
def call_fetch_info(self):
return api.call(self.api_info["call"], token = auth.token(),
user = self.__uid, return_im = True)
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():

View File

@ -37,7 +37,6 @@ class Thread:
if json["ok"] == True:
self.__unread = json[self.api_info["ret"]].get("unread_count", 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):
json = api.call(self.api_history, token = auth.token(),