From 75fc44e34f5a7e7b7f0a31f73c9e5e73eca84f69 Mon Sep 17 00:00:00 2001 From: gridtime Date: Fri, 15 Dec 2023 04:06:53 +0100 Subject: [PATCH] removes mx-reply block for history diff --- src/backend/matrix_client.py | 2 +- src/backend/utils.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 9b81eccf..3b42822d 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -2516,7 +2516,7 @@ class MatrixClient(nio.AsyncClient): history = replaced_event.content_history or [] if history: content_history["content_diff"] = utils.diff_body( - history[-1]["body"], content_history["body"]) + history[-1]["content"], content_history["content"]) history.append(content_history) replaced_event.set_fields( replaced = True, diff --git a/src/backend/utils.py b/src/backend/utils.py index ea6d3994..4552724b 100644 --- a/src/backend/utils.py +++ b/src/backend/utils.py @@ -207,8 +207,12 @@ def strip_html_tags(text: str) -> str: return re.sub(r"<\/?[^>]+(>|$)", "", text) +def remove_reply(text: str): + return re.sub(r".*?<\/mx-reply>", "", text) + + def diff_body(a: str, b: str): - sm = SequenceMatcher(None, plain2html(a), plain2html(b)) + sm = SequenceMatcher(None, remove_reply(a), remove_reply(b)) output = [] for opcode, a0, a1, b0, b1 in sm.get_opcodes(): if opcode == "equal":