Fix invalid usage of content_type

This commit is contained in:
Paul Nameless 2020-05-22 14:00:56 +08:00
parent 981f0c7e65
commit f304ed698f
2 changed files with 10 additions and 12 deletions

View file

@ -284,9 +284,9 @@ class MsgModel:
if message["id"] != msg_id: if message["id"] != msg_id:
continue continue
msg = MsgProxy(message) msg = MsgProxy(message)
if msg.type == "voice": if msg.content_type == "voice":
msg.is_listened = True msg.is_listened = True
elif msg.type == "recording": elif msg.content_type == "recording":
msg.is_viewed = True msg.is_viewed = True
# TODO: start the TTL timer for self-destructing messages # TODO: start the TTL timer for self-destructing messages
# that is the last case to implement # that is the last case to implement

View file

@ -114,7 +114,7 @@ class MsgProxy:
@property @property
def local_path(self): def local_path(self):
if self.msg["content"]["@type"] not in self.types: if self.msg["content"]["@type"] is None:
return None return None
doc = self.get_doc(self.msg) doc = self.get_doc(self.msg)
return doc["local"]["path"] return doc["local"]["path"]
@ -126,7 +126,7 @@ class MsgProxy:
@local.setter @local.setter
def local(self, value): def local(self, value):
if self.msg["content"]["@type"] not in self.types: if self.msg["content"]["@type"] is None:
return None return None
doc = self.get_doc(self.msg) doc = self.get_doc(self.msg)
doc["local"] = value doc["local"] = value
@ -146,27 +146,25 @@ class MsgProxy:
@property @property
def is_listened(self) -> Optional[bool]: def is_listened(self) -> Optional[bool]:
if self.type != "voice": if self.content_type != "voice":
return None return None
return self.msg["content"]["is_listened"] return self.msg["content"]["is_listened"]
@is_listened.setter @is_listened.setter
def is_listened(self, value: bool): def is_listened(self, value: bool):
if self.type != "voice": if self.content_type == "voice":
return None self.msg["content"]["is_listened"] = value
self.msg["content"]["is_listened"] = value
@property @property
def is_viewed(self) -> Optional[bool]: def is_viewed(self) -> Optional[bool]:
if self.type != "recording": if self.content_type != "recording":
return None return None
return self.msg["content"]["is_viewed"] return self.msg["content"]["is_viewed"]
@is_viewed.setter @is_viewed.setter
def is_viewed(self, value: bool): def is_viewed(self, value: bool):
if self.type != "recording": if self.content_type == "recording":
return None self.msg["content"]["is_viewed"] = value
self.msg["content"]["is_viewed"] = value
@property @property
def msg_id(self) -> int: def msg_id(self) -> int: