Box the contents of internal event messages

This really just gets rid of a Clippy warning but putting them behind a
pointer indirection should be optimal
legacy
Charlotte Som 2021-10-03 12:26:14 +01:00
parent 19f28da49a
commit 8e699a310a
4 changed files with 36 additions and 28 deletions

View File

@ -91,12 +91,12 @@ impl EventHandler for DiscordHandler {
.as_ref() .as_ref()
.map(|m| MessageReference::from(m.as_ref())); .map(|m| MessageReference::from(m.as_ref()));
let _ = self.event_tx.send(MessageEvent::Send(SentMessage { let _ = self.event_tx.send(MessageEvent::Send(Box::new(SentMessage {
source: message_ref, source: message_ref,
content, content,
author: get_message_author(&ctx, &message).await, author: get_message_author(&ctx, &message).await,
replies_to, replies_to,
})); })));
} }
async fn message_update( async fn message_update(
@ -118,11 +118,13 @@ impl EventHandler for DiscordHandler {
let content = discord_message_format::parse(&new_message.content); let content = discord_message_format::parse(&new_message.content);
let content = message_ast::convert_discord(&content); let content = message_ast::convert_discord(&content);
let _ = self.event_tx.send(MessageEvent::Edit(EditedMessage { let _ = self
replacing: message_ref, .event_tx
content, .send(MessageEvent::Edit(Box::new(EditedMessage {
author: get_message_author(&ctx, &new_message).await, replacing: message_ref,
})); content,
author: get_message_author(&ctx, &new_message).await,
})));
} }
} }
@ -134,9 +136,11 @@ impl EventHandler for DiscordHandler {
_guild_id: Option<GuildId>, _guild_id: Option<GuildId>,
) { ) {
let message_ref = MessageReference::Discord(channel_id.0, deleted_message_id.0); let message_ref = MessageReference::Discord(channel_id.0, deleted_message_id.0);
let _ = self.event_tx.send(MessageEvent::Delete(DeletedMessage { let _ = self
reference: message_ref, .event_tx
})); .send(MessageEvent::Delete(Box::new(DeletedMessage {
reference: message_ref,
})));
} }
} }

View File

@ -88,13 +88,13 @@ async fn main() {
while let Some(event) = event_rx.recv().await { while let Some(event) = event_rx.recv().await {
match event { match event {
MessageEvent::Send(sent_message) => { MessageEvent::Send(sent_message) => {
bridgers.send_message(sent_message).await; bridgers.send_message(*sent_message).await;
} }
MessageEvent::Edit(edited_message) => { MessageEvent::Edit(edited_message) => {
bridgers.edit_message(edited_message).await; bridgers.edit_message(*edited_message).await;
} }
MessageEvent::Delete(deleted_message) => { MessageEvent::Delete(deleted_message) => {
bridgers.delete_message(deleted_message).await; bridgers.delete_message(*deleted_message).await;
} }
MessageEvent::AdminLinkChannels(channels) => { MessageEvent::AdminLinkChannels(channels) => {

View File

@ -182,24 +182,24 @@ async fn on_message_sent(
None None
}; };
Some(MessageEvent::Send(SentMessage { Some(MessageEvent::Send(Box::new(SentMessage {
source: message_ref, source: message_ref,
content, content,
author, author,
replies_to, replies_to,
})) })))
} }
MessageType::Emote(emote) => { MessageType::Emote(emote) => {
let mut content = ctx.get_content(&emote.body, &emote.formatted); let mut content = ctx.get_content(&emote.body, &emote.formatted);
content.insert(0, MessageComponent::Plain("* ".to_string())); content.insert(0, MessageComponent::Plain("* ".to_string()));
Some(MessageEvent::Send(SentMessage { Some(MessageEvent::Send(Box::new(SentMessage {
source: message_ref, source: message_ref,
content, content,
author, author,
replies_to: None, replies_to: None,
})) })))
} }
// TODO: Handle reactions, uploads (audio, video, image, file), and any other types of event // TODO: Handle reactions, uploads (audio, video, image, file), and any other types of event
@ -226,11 +226,13 @@ async fn on_message_edited(
let content = ctx.get_content(&text.body, &text.formatted); let content = ctx.get_content(&text.body, &text.formatted);
if let Some(author) = ctx.get_message_author(&room, &event.sender).await { if let Some(author) = ctx.get_message_author(&room, &event.sender).await {
let _ = ctx.message_tx.send(MessageEvent::Edit(EditedMessage { let _ = ctx
replacing: message_ref, .message_tx
content, .send(MessageEvent::Edit(Box::new(EditedMessage {
author, replacing: message_ref,
})); content,
author,
})));
} }
} }
} }
@ -238,9 +240,11 @@ async fn on_message_edited(
async fn on_redact_event(ctx: Arc<MatrixHandler>, event: SyncRedactionEvent, room: Room) { async fn on_redact_event(ctx: Arc<MatrixHandler>, event: SyncRedactionEvent, room: Room) {
let message_ref = MessageReference::from((room.room_id(), &event.redacts)); let message_ref = MessageReference::from((room.room_id(), &event.redacts));
let _ = ctx.message_tx.send(MessageEvent::Delete(DeletedMessage { let _ = ctx
reference: message_ref, .message_tx
})); .send(MessageEvent::Delete(Box::new(DeletedMessage {
reference: message_ref,
})));
} }
fn generate_html_content(content: &[MessageComponent], author: &MessageAuthor) -> (String, String) { fn generate_html_content(content: &[MessageComponent], author: &MessageAuthor) -> (String, String) {

View File

@ -34,7 +34,7 @@ pub struct DeletedMessage {
pub enum MessageEvent { pub enum MessageEvent {
AdminLinkChannels(Vec<ChannelReference>), AdminLinkChannels(Vec<ChannelReference>),
Send(SentMessage), Send(Box<SentMessage>),
Edit(EditedMessage), Edit(Box<EditedMessage>),
Delete(DeletedMessage), Delete(Box<DeletedMessage>),
} }