Fix replying to replies of forwarded messages

Fixes #93
This commit is contained in:
Tulir Asokan
2018-03-31 19:48:28 +03:00
parent 66d68f6b63
commit 133e4af712
2 changed files with 10 additions and 6 deletions
+6 -5
View File
@@ -20,7 +20,7 @@ from typing import Optional, List, Tuple
try:
from lxml.html.diff import htmldiff
except ImportError:
htmldiff = None
htmldiff = None # type: function
import logging
import re
@@ -89,9 +89,10 @@ async def _add_forward_header(source, text: str, html: Optional[str],
fwd_from_text = "Unknown source"
fwd_from_html = f"<b>{fwd_from_text}</b>"
text = f"Forwarded from {fwd_from}:\n{text}"
text = "\n".join([f"> {line}" for line in text.split("\n")])
text = f"Forwarded from {fwd_from_text}:\n{text}"
html = (f"Forwarded message from {fwd_from_html}<br/>"
f"<blockquote>{html}</blockquote>")
f"<blockquote><forward>{html}</forward></blockquote>")
return text, html
@@ -142,9 +143,9 @@ async def _add_reply_header(source: u.User, text: str, html: str, evt: Message,
if is_edit and should_highlight_edits:
html = highlight_edits(html or escape(text), r_html_body)
except (ValueError, KeyError, MatrixRequestError):
except (ValueError, KeyError, MatrixRequestError) as e:
r_sender_link = "unknown user"
# r_sender = "unknown user"
r_displayname = "unknown user"
r_text_body = "Failed to fetch message"
r_html_body = "<em>Failed to fetch message</em>"
+4 -1
View File
@@ -45,7 +45,10 @@ def trim_reply_fallback_text(text: str) -> str:
return "\n".join(lines)
html_reply_fallback_regex = re.compile(r"^<blockquote data-mx-reply>[\s\S]+?</blockquote>")
html_reply_fallback_regex = re.compile("^<blockquote data-mx-reply>"
r"[\s\S]+?"
"(</forward></blockquote>)?"
"</blockquote>")
def trim_reply_fallback_html(html: str) -> str: