mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
Fix attached msg photos layout (#188)
* Fix attached msg photos layout * handle urls in textEntityTypeTextUrl
This commit is contained in:
parent
fabcafbb94
commit
2bd0fcbc51
2 changed files with 17 additions and 11 deletions
|
@ -118,23 +118,27 @@ class Controller:
|
|||
def open_url(self) -> None:
|
||||
msg = MsgProxy(self.model.current_msg)
|
||||
if not msg.is_text:
|
||||
self.present_error("Does not contain urls")
|
||||
return
|
||||
return self.present_error("Does not contain urls")
|
||||
text = msg["content"]["text"]["text"]
|
||||
urls = []
|
||||
for entity in msg["content"]["text"]["entities"]:
|
||||
if entity["type"]["@type"] != "textEntityTypeUrl":
|
||||
continue
|
||||
_type = entity["type"]["@type"]
|
||||
if _type == "textEntityTypeUrl":
|
||||
offset = entity["offset"]
|
||||
length = entity["length"]
|
||||
url = text[offset : offset + length]
|
||||
elif _type == "textEntityTypeTextUrl":
|
||||
url = entity["type"]["url"]
|
||||
else:
|
||||
continue
|
||||
urls.append(url)
|
||||
if not urls:
|
||||
self.present_error("No url to open")
|
||||
return
|
||||
return self.present_error("No url to open")
|
||||
if len(urls) == 1:
|
||||
with suspend(self.view) as s:
|
||||
s.call(config.DEFAULT_OPEN.format(file_path=shlex.quote(url)))
|
||||
s.call(
|
||||
config.DEFAULT_OPEN.format(file_path=shlex.quote(urls[0]))
|
||||
)
|
||||
return
|
||||
with suspend(self.view) as s:
|
||||
s.run_with_input(config.URL_VIEW, "\n".join(urls))
|
||||
|
@ -347,8 +351,7 @@ class Controller:
|
|||
is_deleted = self.model.delete_msgs()
|
||||
self.discard_selected_msgs()
|
||||
if not is_deleted:
|
||||
self.present_error("Can't delete msg(s)")
|
||||
return
|
||||
return self.present_error("Can't delete msg(s)")
|
||||
self.present_info("Message deleted")
|
||||
|
||||
@bind(msg_handler, ["S"])
|
||||
|
|
|
@ -362,6 +362,9 @@ class MsgView:
|
|||
if not msg_proxy.is_text or "web_page" not in msg_proxy.msg["content"]:
|
||||
return ""
|
||||
web = msg_proxy.msg["content"]["web_page"]
|
||||
page_type = web["type"]
|
||||
if page_type == "photo":
|
||||
return f"\n | photo: {web['url']}"
|
||||
name = web["site_name"]
|
||||
title = web["title"]
|
||||
description = web["description"].replace("\n", "")
|
||||
|
|
Loading…
Reference in a new issue