Skip to content

Commit

Permalink
View animated stickers thumbnail (#106)
Browse files Browse the repository at this point in the history
* Draft: adding lock to message update and using indexes for msgs

* Fix black formatting

* Rename msg_ids->msg_idx to better represent what variable contains

* Fix black formatting

* Check if msg_id in not_found

* Use lock in udpate_handler

* Add shortcut to jump to replied msg

* Open preview for animated sticker and show it's emoji

* Remove lock

* Show if sticker is animated
  • Loading branch information
paul-nameless committed Jul 3, 2020
1 parent 2a0c726 commit 4460c5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions tg/msg.py
Expand Up @@ -17,7 +17,7 @@ class MsgProxy:
"messageAudio": ("audio", "audio"),
"messageVideo": ("video", "video"),
"messageVideoNote": ("video_note", "video"),
"messageSticker": ("sticker", "sticker"),
"messageSticker": ("sticker", "thumbnail", "photo"),
}

types = {
Expand Down Expand Up @@ -114,7 +114,7 @@ def file_id(self) -> Optional[int]:

@property
def local_path(self) -> Optional[str]:
if self.msg["content"]["@type"] is None:
if self.content_type is None:
return None
doc = self.get_doc(self.msg)
return doc["local"]["path"]
Expand Down Expand Up @@ -196,3 +196,15 @@ def caption(self) -> Optional[str]:
if not caption:
return None
return caption["text"]

@property
def sticker_emoji(self) -> Optional[str]:
if self.content_type != "sticker":
return None
return self.msg["content"].get("sticker", {}).get("emoji")

@property
def is_animated(self) -> bool:
if self.content_type != "sticker":
return False
return self.msg["content"].get("sticker", {}).get("is_animated")
3 changes: 2 additions & 1 deletion tg/views.py
Expand Up @@ -111,7 +111,6 @@ def get_input(self, msg: str = "") -> str:

buff = ""
while True:
log.info("here:")
key = self.win.get_wch(0, min(len(buff) + len(msg), self.w - 1))
key = ord(key)
if key == 10: # return
Expand Down Expand Up @@ -592,6 +591,8 @@ def parse_content(content: Dict[str, Any]) -> str:
duration=msg.duration,
listened=format_bool(msg.is_listened),
viewed=format_bool(msg.is_viewed),
animated=msg.is_animated,
emoji=msg.sticker_emoji,
)
info = ", ".join(f"{k}={v}" for k, v in fields.items() if v)

Expand Down

0 comments on commit 4460c5f

Please sign in to comment.