Strip <mx-reply> from matrix HTML conversion

This is handled by rich replies
legacy
Charlotte Som 2021-09-13 20:50:13 +01:00
parent 535afb4796
commit 0ddd756abf
1 changed files with 21 additions and 4 deletions

View File

@ -12,12 +12,21 @@ pub fn convert_matrix(message: &str) -> MessageContent {
let mut parents = vec![]; let mut parents = vec![];
let mut components = vec![]; let mut components = vec![];
let mut skip_text = false; let mut skip_text = 0;
let mut skip_all = 0;
for edge in dom.traverse() { for edge in dom.traverse() {
match edge { match edge {
NodeEdge::Start(node) => { NodeEdge::Start(node) => {
if let NodeData::Element(element) = node.data() { if let NodeData::Element(element) = node.data() {
if element.name.local == *"mx-reply" {
skip_all += 1;
}
if skip_all > 0 {
continue;
}
if element.name.ns == ns!(html) { if element.name.ns == ns!(html) {
match element.name.local { match element.name.local {
local_name!("strong") local_name!("strong")
@ -41,7 +50,7 @@ pub fn convert_matrix(message: &str) -> MessageContent {
} }
local_name!("code") => { local_name!("code") => {
skip_text = true; skip_text += 1;
} }
_ => {} _ => {}
@ -52,12 +61,20 @@ pub fn convert_matrix(message: &str) -> MessageContent {
NodeEdge::End(node) => match node.data() { NodeEdge::End(node) => match node.data() {
NodeData::Text(text) => { NodeData::Text(text) => {
if !skip_text { if skip_text <= 0 && skip_all <= 0 {
let text = text.borrow().lines().collect::<Vec<_>>().join(" "); let text = text.borrow().lines().collect::<Vec<_>>().join(" ");
components.push(MessageComponent::Plain(text)); components.push(MessageComponent::Plain(text));
} }
} }
NodeData::Element(element) => { NodeData::Element(element) => {
if element.name.local == *"mx-reply" {
skip_all -= 1;
}
if skip_all > 0 {
continue;
}
macro_rules! construct_component { macro_rules! construct_component {
($f:expr) => {{ ($f:expr) => {{
let component_type = $f; let component_type = $f;
@ -142,7 +159,7 @@ pub fn convert_matrix(message: &str) -> MessageContent {
MessageComponent::Code(node.text_contents()) MessageComponent::Code(node.text_contents())
}); });
skip_text = false; skip_text -= 1;
} }
_ => {} _ => {}
} }