From f304ed698f0d0ac2ecb8909ada1e2d53d2e8a905 Mon Sep 17 00:00:00 2001 From: Paul Nameless Date: Fri, 22 May 2020 14:00:56 +0800 Subject: [PATCH] Fix invalid usage of content_type --- tg/models.py | 4 ++-- tg/msg.py | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tg/models.py b/tg/models.py index c926ffd..4b151fa 100644 --- a/tg/models.py +++ b/tg/models.py @@ -284,9 +284,9 @@ class MsgModel: if message["id"] != msg_id: continue msg = MsgProxy(message) - if msg.type == "voice": + if msg.content_type == "voice": msg.is_listened = True - elif msg.type == "recording": + elif msg.content_type == "recording": msg.is_viewed = True # TODO: start the TTL timer for self-destructing messages # that is the last case to implement diff --git a/tg/msg.py b/tg/msg.py index ba8474a..2c27a12 100644 --- a/tg/msg.py +++ b/tg/msg.py @@ -114,7 +114,7 @@ class MsgProxy: @property def local_path(self): - if self.msg["content"]["@type"] not in self.types: + if self.msg["content"]["@type"] is None: return None doc = self.get_doc(self.msg) return doc["local"]["path"] @@ -126,7 +126,7 @@ class MsgProxy: @local.setter def local(self, value): - if self.msg["content"]["@type"] not in self.types: + if self.msg["content"]["@type"] is None: return None doc = self.get_doc(self.msg) doc["local"] = value @@ -146,27 +146,25 @@ class MsgProxy: @property def is_listened(self) -> Optional[bool]: - if self.type != "voice": + if self.content_type != "voice": return None return self.msg["content"]["is_listened"] @is_listened.setter def is_listened(self, value: bool): - if self.type != "voice": - return None - self.msg["content"]["is_listened"] = value + if self.content_type == "voice": + self.msg["content"]["is_listened"] = value @property def is_viewed(self) -> Optional[bool]: - if self.type != "recording": + if self.content_type != "recording": return None return self.msg["content"]["is_viewed"] @is_viewed.setter def is_viewed(self, value: bool): - if self.type != "recording": - return None - self.msg["content"]["is_viewed"] = value + if self.content_type == "recording": + self.msg["content"]["is_viewed"] = value @property def msg_id(self) -> int: