# # Copyright 2015 (c) Anna Schumaker. # # # This class represents a slack "thread", which could be a channel, group, # or chat. Note that child classes need to implement the following methods: # # - do_fetch_info(): Call .info to find unread count and timestamp. # class Thread: def __init__(self, json): self.__id = json.get("id", 0) self.__name = json.get("name", "").title() self.__topic = json["topic"].get("value", "").encode("utf-8").decode("latin-1") self.__purpose = json["purpose"].get("value", "").encode("utf-8").decode("latin-1") self.__unread = json.get("unread_count", None) self.__last_ts = json.get("last_read", None) def __str__(self): topic="" if self.__topic != "": topic = "\nTopic: %s" % self.__topic return "%s: %s%s" % (self.__name, self.__purpose, topic) def fetch_info(self): json = self.do_fetch_info() if json != None: self.__unread = json.get("unread_count", None) self.__last_ts = json.get("last_read", None) def id(self): return self.__id def is_member(self): return True def name(self): return self.__name def unread_count(self): if self.__unread == None: self.fetch_info() return self.__unread