Add option to link to original message in non-native reply

This commit is contained in:
Tulir Asokan
2018-02-08 15:27:21 +02:00
parent 9eff63c220
commit d349c58f90
3 changed files with 20 additions and 6 deletions
+7 -1
View File
@@ -60,7 +60,13 @@ bridge:
# Whether or not to use native Matrix replies. At the time of writing, only riot-web supports
# replies and the format of them is subject to change.
native_replies: False
native_replies: True
# If native replies are disabled, should the custom replies contain a link to the message being
# replied to?
#
# Warning: Using this on a client with native replies will not look good: the message will have
# a native quote AND a non-native quote.
link_in_reply: False
# The prefix for commands. Only required in non-management rooms.
command_prefix: "!tg"
+12 -5
View File
@@ -196,7 +196,8 @@ def matrix_to_telegram(html, tg_space=None):
# endregion
# region Telegram to Matrix
def telegram_event_to_matrix(evt, source, native_replies=False, main_intent=None):
def telegram_event_to_matrix(evt, source, native_replies=False, message_link_in_reply=False,
main_intent=None):
text = evt.message
html = telegram_to_matrix(evt.message, evt.entities) if evt.entities else None
@@ -233,11 +234,17 @@ def telegram_event_to_matrix(evt, source, native_replies=False, main_intent=None
try:
event = main_intent.get_event(msg.mx_room, msg.mxid)
content = event["content"]
body = content["formatted_body"] if "formatted_body" in content else content["body"]
reply_to = f"<a href='https://matrix.to/#/{event['sender']}'>event['sender']</a>"
quote = f"Reply to {reply_to}<blockquote>{body}</blockquote>"
body = (content["formatted_body"]
if "formatted_body" in content
else content["body"])
reply_to_user = ("<a href='https://matrix.to/#/"
+ f"{event['sender']}'>{event['sender']}</a>")
reply_to_msg = (("<a href='https://matrix.to/#/"
+ f"{msg.mx_room}/{msg.mxid}'>Reply</a>")
if message_link_in_reply else "Reply")
quote = f"{reply_to_msg} to {reply_to_user}<blockquote>{body}</blockquote>"
except (ValueError, KeyError, MatrixRequestError):
quote = "Reply to someone (failed to fetch message)<br/>"
quote = "Reply to unknown user <em>(Failed to fetch message)</em>:<br/>"
if html:
html = quote + html
else:
+1
View File
@@ -682,6 +682,7 @@ class Portal:
self.log.debug(f"Sending {evt.message} to {self.mxid} by {sender.id}")
text, html = formatter.telegram_event_to_matrix(evt, source,
config["bridge.native_replies"],
config["bridge.link_in_reply"],
self.main_intent)
sender.intent.set_typing(self.mxid, is_typing=False)
return sender.intent.send_text(self.mxid, text, html=html)