Fix replies/forwards to/of images

This commit is contained in:
Tulir Asokan
2018-03-08 18:01:58 +02:00
parent 3eefbc4e34
commit 150321a4d7
2 changed files with 13 additions and 8 deletions
+7 -1
View File
@@ -120,11 +120,17 @@ async def _add_reply_header(source, text, html, evt, relates_to, main_intent, is
return text_with_quote, html
async def telegram_to_matrix(evt, source, main_intent=None, is_edit=False):
async def telegram_to_matrix(evt, source, main_intent=None, is_edit=False, prefix_text=None,
prefix_html=None):
text = add_surrogates(evt.message)
html = _telegram_entities_to_matrix_catch(text, evt.entities) if evt.entities else None
relates_to = {}
if prefix_html:
html = prefix_html + (html or escape(text))
if prefix_text:
text = prefix_text + text
if evt.fwd_from:
text, html = await _add_forward_header(source, text, html, evt.fwd_from.from_id)
+6 -7
View File
@@ -834,19 +834,18 @@ class Portal:
if self.mxid:
await user.intent.set_typing(self.mxid, is_typing=True)
async def handle_telegram_photo(self, source, intent, evt, relates_to=None):
async def handle_telegram_photo(self, source: u.User, intent, evt: Message, relates_to=None):
largest_size = self._get_largest_photo_size(evt.media.photo)
file = await util.transfer_file_to_matrix(self.db, source.client, intent,
largest_size.location)
if not file:
return None
if config["bridge.inline_images"] and evt.message:
text, html, relates_to = await formatter.telegram_to_matrix(evt, source,
self.main_intent)
if config["bridge.inline_images"] and (evt.message or evt.fwd_from or evt.reply_to_msg_id):
text, html, relates_to = await formatter.telegram_to_matrix(
evt, source, self.main_intent,
prefix_html=f"<img src='{file.mxc}' alt='Inline Telegram photo'/><br/>\n",
prefix_text="Inline image: ")
await intent.set_typing(self.mxid, is_typing=False)
inline_img = f"<img src='{file.mxc}' alt='Inline Telegram photo'/><br/>\n"
html = inline_img + (html or escape(text))
text = f"Inline image: {text}"
return await intent.send_text(self.mxid, text, html=html, relates_to=relates_to)
info = {
"h": largest_size.h,