Message handling fixes
Don't create a message object for posts without text. Additionally, use the accepted character replacements for unicode characters. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
673bac86bc
commit
3c264554d8
|
@ -25,7 +25,7 @@ class Message:
|
||||||
self.__ts = json["ts"]
|
self.__ts = json["ts"]
|
||||||
self.__time = datetime.fromtimestamp(float(self.__ts))
|
self.__time = datetime.fromtimestamp(float(self.__ts))
|
||||||
self.__user = users.info(json.get("user", None))
|
self.__user = users.info(json.get("user", None))
|
||||||
self.__text = [ json["text"].encode("utf-8").decode("latin-1") ]
|
self.__text = [ json["text"].encode("utf-8").decode(errors="replace")]
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return self.__time < other.__time
|
return self.__time < other.__time
|
||||||
|
|
|
@ -16,8 +16,8 @@ class Thread:
|
||||||
def __init__(self, json):
|
def __init__(self, json):
|
||||||
self.__id = json.get("id", 0)
|
self.__id = json.get("id", 0)
|
||||||
self.__name = json.get("name", "").title()
|
self.__name = json.get("name", "").title()
|
||||||
self.__topic = json["topic"].get("value", "").encode("utf-8").decode("latin-1")
|
self.__topic = json["topic"].get("value", "").encode("utf-8").decode(errors="replace")
|
||||||
self.__purpose = json["purpose"].get("value", "").encode("utf-8").decode("latin-1")
|
self.__purpose = json["purpose"].get("value", "").encode("utf-8").decode(errors="replace")
|
||||||
self.__unread = json.get("unread_count", None)
|
self.__unread = json.get("unread_count", None)
|
||||||
self.__last_ts = json.get("last_read", None)
|
self.__last_ts = json.get("last_read", None)
|
||||||
|
|
||||||
|
@ -49,7 +49,8 @@ class Thread:
|
||||||
# Read original message list
|
# Read original message list
|
||||||
o_list = []
|
o_list = []
|
||||||
for message in self.do_fetch_messages(self.__last_ts):
|
for message in self.do_fetch_messages(self.__last_ts):
|
||||||
o_list += [ chat.Message(message) ]
|
if message["text"] != None:
|
||||||
|
o_list += [ chat.Message(message) ]
|
||||||
o_list.sort()
|
o_list.sort()
|
||||||
|
|
||||||
# Merge together messages from the same user
|
# Merge together messages from the same user
|
||||||
|
|
Loading…
Reference in New Issue