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:
Anna Schumaker 2015-09-04 14:18:36 -04:00
parent 673bac86bc
commit 3c264554d8
2 changed files with 5 additions and 4 deletions

View File

@ -25,7 +25,7 @@ class Message:
self.__ts = json["ts"]
self.__time = datetime.fromtimestamp(float(self.__ts))
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):
return self.__time < other.__time

View File

@ -16,8 +16,8 @@ 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.__topic = json["topic"].get("value", "").encode("utf-8").decode(errors="replace")
self.__purpose = json["purpose"].get("value", "").encode("utf-8").decode(errors="replace")
self.__unread = json.get("unread_count", None)
self.__last_ts = json.get("last_read", None)
@ -49,7 +49,8 @@ class Thread:
# Read original message list
o_list = []
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()
# Merge together messages from the same user