mirror of
https://github.com/paul-nameless/tg
synced 2024-11-25 13:20:25 +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:
|
def open_url(self) -> None:
|
||||||
msg = MsgProxy(self.model.current_msg)
|
msg = MsgProxy(self.model.current_msg)
|
||||||
if not msg.is_text:
|
if not msg.is_text:
|
||||||
self.present_error("Does not contain urls")
|
return self.present_error("Does not contain urls")
|
||||||
return
|
|
||||||
text = msg["content"]["text"]["text"]
|
text = msg["content"]["text"]["text"]
|
||||||
urls = []
|
urls = []
|
||||||
for entity in msg["content"]["text"]["entities"]:
|
for entity in msg["content"]["text"]["entities"]:
|
||||||
if entity["type"]["@type"] != "textEntityTypeUrl":
|
_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
|
continue
|
||||||
offset = entity["offset"]
|
|
||||||
length = entity["length"]
|
|
||||||
url = text[offset : offset + length]
|
|
||||||
urls.append(url)
|
urls.append(url)
|
||||||
if not urls:
|
if not urls:
|
||||||
self.present_error("No url to open")
|
return self.present_error("No url to open")
|
||||||
return
|
|
||||||
if len(urls) == 1:
|
if len(urls) == 1:
|
||||||
with suspend(self.view) as s:
|
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
|
return
|
||||||
with suspend(self.view) as s:
|
with suspend(self.view) as s:
|
||||||
s.run_with_input(config.URL_VIEW, "\n".join(urls))
|
s.run_with_input(config.URL_VIEW, "\n".join(urls))
|
||||||
|
@ -347,8 +351,7 @@ class Controller:
|
||||||
is_deleted = self.model.delete_msgs()
|
is_deleted = self.model.delete_msgs()
|
||||||
self.discard_selected_msgs()
|
self.discard_selected_msgs()
|
||||||
if not is_deleted:
|
if not is_deleted:
|
||||||
self.present_error("Can't delete msg(s)")
|
return self.present_error("Can't delete msg(s)")
|
||||||
return
|
|
||||||
self.present_info("Message deleted")
|
self.present_info("Message deleted")
|
||||||
|
|
||||||
@bind(msg_handler, ["S"])
|
@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"]:
|
if not msg_proxy.is_text or "web_page" not in msg_proxy.msg["content"]:
|
||||||
return ""
|
return ""
|
||||||
web = msg_proxy.msg["content"]["web_page"]
|
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"]
|
name = web["site_name"]
|
||||||
title = web["title"]
|
title = web["title"]
|
||||||
description = web["description"].replace("\n", "")
|
description = web["description"].replace("\n", "")
|
||||||
|
|
Loading…
Reference in a new issue