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()
.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,
content,
author: get_message_author(&ctx, &message).await,
replies_to,
}));
})));
}
async fn message_update(
@ -118,11 +118,13 @@ impl EventHandler for DiscordHandler {
let content = discord_message_format::parse(&new_message.content);
let content = message_ast::convert_discord(&content);
let _ = self.event_tx.send(MessageEvent::Edit(EditedMessage {
replacing: message_ref,
content,
author: get_message_author(&ctx, &new_message).await,
}));
let _ = self
.event_tx
.send(MessageEvent::Edit(Box::new(EditedMessage {
replacing: message_ref,
content,
author: get_message_author(&ctx, &new_message).await,
})));
}
}
@ -134,9 +136,11 @@ impl EventHandler for DiscordHandler {
_guild_id: Option<GuildId>,
) {
let message_ref = MessageReference::Discord(channel_id.0, deleted_message_id.0);
let _ = self.event_tx.send(MessageEvent::Delete(DeletedMessage {
reference: message_ref,
}));
let _ = self
.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 {
match event {
MessageEvent::Send(sent_message) => {
bridgers.send_message(sent_message).await;
bridgers.send_message(*sent_message).await;
}
MessageEvent::Edit(edited_message) => {
bridgers.edit_message(edited_message).await;
bridgers.edit_message(*edited_message).await;
}
MessageEvent::Delete(deleted_message) => {
bridgers.delete_message(deleted_message).await;
bridgers.delete_message(*deleted_message).await;
}
MessageEvent::AdminLinkChannels(channels) => {

View File

@ -182,24 +182,24 @@ async fn on_message_sent(
None
};
Some(MessageEvent::Send(SentMessage {
Some(MessageEvent::Send(Box::new(SentMessage {
source: message_ref,
content,
author,
replies_to,
}))
})))
}
MessageType::Emote(emote) => {
let mut content = ctx.get_content(&emote.body, &emote.formatted);
content.insert(0, MessageComponent::Plain("* ".to_string()));
Some(MessageEvent::Send(SentMessage {
Some(MessageEvent::Send(Box::new(SentMessage {
source: message_ref,
content,
author,
replies_to: None,
}))
})))
}
// 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);
if let Some(author) = ctx.get_message_author(&room, &event.sender).await {
let _ = ctx.message_tx.send(MessageEvent::Edit(EditedMessage {
replacing: message_ref,
content,
author,
}));
let _ = ctx
.message_tx
.send(MessageEvent::Edit(Box::new(EditedMessage {
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) {
let message_ref = MessageReference::from((room.room_id(), &event.redacts));
let _ = ctx.message_tx.send(MessageEvent::Delete(DeletedMessage {
reference: message_ref,
}));
let _ = ctx
.message_tx
.send(MessageEvent::Delete(Box::new(DeletedMessage {
reference: message_ref,
})));
}
fn generate_html_content(content: &[MessageComponent], author: &MessageAuthor) -> (String, String) {

View File

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