removes mx-reply block for history diff

This commit is contained in:
gridtime 2023-12-15 04:06:53 +01:00
parent fc23274c94
commit 75fc44e34f
No known key found for this signature in database
GPG Key ID: FB6ACC7A1C9182F8
2 changed files with 6 additions and 2 deletions

View File

@ -2516,7 +2516,7 @@ class MatrixClient(nio.AsyncClient):
history = replaced_event.content_history or [] history = replaced_event.content_history or []
if history: if history:
content_history["content_diff"] = utils.diff_body( content_history["content_diff"] = utils.diff_body(
history[-1]["body"], content_history["body"]) history[-1]["content"], content_history["content"])
history.append(content_history) history.append(content_history)
replaced_event.set_fields( replaced_event.set_fields(
replaced = True, replaced = True,

View File

@ -207,8 +207,12 @@ def strip_html_tags(text: str) -> str:
return re.sub(r"<\/?[^>]+(>|$)", "", text) return re.sub(r"<\/?[^>]+(>|$)", "", text)
def remove_reply(text: str):
return re.sub(r"<mx-reply.*?>.*?<\/mx-reply>", "", text)
def diff_body(a: str, b: str): def diff_body(a: str, b: str):
sm = SequenceMatcher(None, plain2html(a), plain2html(b)) sm = SequenceMatcher(None, remove_reply(a), remove_reply(b))
output = [] output = []
for opcode, a0, a1, b0, b1 in sm.get_opcodes(): for opcode, a0, a1, b0, b1 in sm.get_opcodes():
if opcode == "equal": if opcode == "equal":