Clean up obsolete / fulfilled TODO items
parent
77c789b39e
commit
bd5669d3e4
|
@ -16,8 +16,6 @@ impl From<&Message> for MessageReference {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Some way to emit messages for matrix,
|
|
||||||
// and some way to receive messages from matrix.
|
|
||||||
struct DiscordHandler {
|
struct DiscordHandler {
|
||||||
ctx_tx: mpsc::UnboundedSender<Context>,
|
ctx_tx: mpsc::UnboundedSender<Context>,
|
||||||
message_tx: mpsc::UnboundedSender<SentMessage>,
|
message_tx: mpsc::UnboundedSender<SentMessage>,
|
||||||
|
@ -38,7 +36,6 @@ impl EventHandler for DiscordHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
let message_ref = MessageReference::from(&message);
|
let message_ref = MessageReference::from(&message);
|
||||||
// TODO: Store this message ref & associations in the DB
|
|
||||||
|
|
||||||
let content = discord_message_format::parse(&message.content);
|
let content = discord_message_format::parse(&message.content);
|
||||||
let content = message_ast::convert_discord(&content);
|
let content = message_ast::convert_discord(&content);
|
||||||
|
|
|
@ -93,7 +93,6 @@ impl EventHandler for MatrixHandler {
|
||||||
.filter(|f| f.format == MessageFormat::Html)
|
.filter(|f| f.format == MessageFormat::Html)
|
||||||
.map(|f| &f.body)
|
.map(|f| &f.body)
|
||||||
{
|
{
|
||||||
// TODO: Parse html_body into MessageContent AST
|
|
||||||
convert_matrix(html)
|
convert_matrix(html)
|
||||||
} else {
|
} else {
|
||||||
convert_plain(&text.body)
|
convert_plain(&text.body)
|
||||||
|
@ -113,10 +112,7 @@ impl EventHandler for MatrixHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageType::Emote(_emote) => {
|
// TODO: Handle reactions, uploads (audio, video, image, file), and any other types of event
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,75 +45,72 @@ pub fn convert_matrix(message: &str) -> MessageContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeEdge::End(node) => {
|
NodeEdge::End(node) => match node.data() {
|
||||||
match node.data() {
|
NodeData::Text(text) => {
|
||||||
NodeData::Text(text) => {
|
components.push(MessageComponent::Plain(text.borrow().clone()));
|
||||||
// TODO: Does this need to get HTML-decoded or something
|
}
|
||||||
components.push(MessageComponent::Plain(text.borrow().clone()));
|
NodeData::Element(element) => {
|
||||||
|
macro_rules! construct_component {
|
||||||
|
($f:expr) => {{
|
||||||
|
let component_type = $f;
|
||||||
|
if let Some(mut parent_components) = parents.pop() {
|
||||||
|
parent_components.push((component_type)(components));
|
||||||
|
components = parent_components;
|
||||||
|
}
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
NodeData::Element(element) => {
|
|
||||||
macro_rules! construct_component {
|
if element.name.ns == ns!(html) {
|
||||||
($f:expr) => {{
|
match element.name.local {
|
||||||
let component_type = $f;
|
local_name!("strong") | local_name!("b") => {
|
||||||
|
construct_component!(MessageComponent::Bold)
|
||||||
|
}
|
||||||
|
local_name!("em") | local_name!("i") => {
|
||||||
|
construct_component!(MessageComponent::Italic)
|
||||||
|
}
|
||||||
|
local_name!("s") => {
|
||||||
|
construct_component!(MessageComponent::Strikethrough)
|
||||||
|
}
|
||||||
|
local_name!("u") => {
|
||||||
|
construct_component!(MessageComponent::Underline)
|
||||||
|
}
|
||||||
|
local_name!("a") => {
|
||||||
if let Some(mut parent_components) = parents.pop() {
|
if let Some(mut parent_components) = parents.pop() {
|
||||||
parent_components.push((component_type)(components));
|
let attrs = element.attributes.borrow();
|
||||||
|
if let Some(href) = attrs.get(local_name!("href")) {
|
||||||
|
parent_components.push(MessageComponent::Link {
|
||||||
|
target: href.to_string(),
|
||||||
|
text: components,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
parent_components.append(&mut components);
|
||||||
|
}
|
||||||
|
|
||||||
components = parent_components;
|
components = parent_components;
|
||||||
}
|
}
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
if element.name.ns == ns!(html) {
|
|
||||||
match element.name.local {
|
|
||||||
local_name!("strong") | local_name!("b") => {
|
|
||||||
construct_component!(MessageComponent::Bold)
|
|
||||||
}
|
|
||||||
local_name!("em") | local_name!("i") => {
|
|
||||||
construct_component!(MessageComponent::Italic)
|
|
||||||
}
|
|
||||||
local_name!("s") => {
|
|
||||||
construct_component!(MessageComponent::Strikethrough)
|
|
||||||
}
|
|
||||||
local_name!("u") => {
|
|
||||||
construct_component!(MessageComponent::Underline)
|
|
||||||
}
|
|
||||||
local_name!("a") => {
|
|
||||||
if let Some(mut parent_components) = parents.pop() {
|
|
||||||
let attrs = element.attributes.borrow();
|
|
||||||
if let Some(href) = attrs.get(local_name!("href")) {
|
|
||||||
parent_components.push(MessageComponent::Link {
|
|
||||||
target: href.to_string(),
|
|
||||||
text: components,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
parent_components.append(&mut components);
|
|
||||||
}
|
|
||||||
|
|
||||||
components = parent_components;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
local_name!("br") => {
|
|
||||||
components.push(MessageComponent::HardBreak);
|
|
||||||
}
|
|
||||||
local_name!("blockquote") => {
|
|
||||||
construct_component!(MessageComponent::BlockQuote)
|
|
||||||
}
|
|
||||||
local_name!("span") => {
|
|
||||||
let attrs = element.attributes.borrow();
|
|
||||||
if let Some(spoiler_reason) = attrs.get("data-mx-spoiler") {
|
|
||||||
construct_component!(|inner| MessageComponent::Spoiler {
|
|
||||||
reason: (!spoiler_reason.is_empty())
|
|
||||||
.then(|| spoiler_reason.to_string()),
|
|
||||||
content: inner,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
local_name!("br") => {
|
||||||
|
components.push(MessageComponent::HardBreak);
|
||||||
|
}
|
||||||
|
local_name!("blockquote") => {
|
||||||
|
construct_component!(MessageComponent::BlockQuote)
|
||||||
|
}
|
||||||
|
local_name!("span") => {
|
||||||
|
let attrs = element.attributes.borrow();
|
||||||
|
if let Some(spoiler_reason) = attrs.get("data-mx-spoiler") {
|
||||||
|
construct_component!(|inner| MessageComponent::Spoiler {
|
||||||
|
reason: (!spoiler_reason.is_empty())
|
||||||
|
.then(|| spoiler_reason.to_string()),
|
||||||
|
content: inner,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
_ => {}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue