removes mx-reply block for history diff
This commit is contained in:
parent
fc23274c94
commit
75fc44e34f
|
@ -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,
|
||||||
|
|
|
@ -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":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user