parsers: port Message to use the derive macros

This commit is contained in:
Jonas Schäfer 2025-04-18 12:26:27 +02:00
commit 5172fb5e0f
11 changed files with 183 additions and 202 deletions

View file

@ -7,7 +7,7 @@
use tokio_xmpp::jid::BareJid;
#[cfg(feature = "avatars")]
use tokio_xmpp::jid::Jid;
use tokio_xmpp::parsers::{message::Body, roster::Item as RosterItem};
use tokio_xmpp::parsers::roster::Item as RosterItem;
use crate::{delay::StanzaTimeInfo, Error, MessageId, RoomNick};
@ -23,25 +23,25 @@ pub enum Event {
/// A chat message was received. It may have been delayed on the network.
/// - The [`MessageId`] is a unique identifier for this message.
/// - The [`BareJid`] is the sender's JID.
/// - The [`Body`] is the message body.
/// - The [`String`] is the message body.
/// - The [`StanzaTimeInfo`] about when message was received, and when the message was claimed sent.
ChatMessage(Option<MessageId>, BareJid, Body, StanzaTimeInfo),
ChatMessage(Option<MessageId>, BareJid, String, StanzaTimeInfo),
/// A message in a one-to-one chat was corrected/edited.
/// - The [`MessageId`] is the ID of the message that was corrected.
/// - The [`BareJid`] is the JID of the other participant in the chat.
/// - The [`Body`] is the new body of the message, to replace the old one.
/// - The [`String`] is the new body of the message, to replace the old one.
/// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
ChatMessageCorrection(MessageId, BareJid, Body, StanzaTimeInfo),
ChatMessageCorrection(MessageId, BareJid, String, StanzaTimeInfo),
RoomJoined(BareJid),
RoomLeft(BareJid),
RoomMessage(Option<MessageId>, BareJid, RoomNick, Body, StanzaTimeInfo),
RoomMessage(Option<MessageId>, BareJid, RoomNick, String, StanzaTimeInfo),
/// A message in a MUC was corrected/edited.
/// - The [`MessageId`] is the ID of the message that was corrected.
/// - The [`BareJid`] is the JID of the room where the message was sent.
/// - The [`RoomNick`] is the nickname of the sender of the message.
/// - The [`Body`] is the new body of the message, to replace the old one.
/// - The [`String`] is the new body of the message, to replace the old one.
/// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
RoomMessageCorrection(MessageId, BareJid, RoomNick, Body, StanzaTimeInfo),
RoomMessageCorrection(MessageId, BareJid, RoomNick, String, StanzaTimeInfo),
/// The subject of a room was received.
/// - The BareJid is the room's address.
/// - The RoomNick is the nickname of the room member who set the subject.
@ -49,14 +49,14 @@ pub enum Event {
RoomSubject(BareJid, Option<RoomNick>, String, StanzaTimeInfo),
/// A private message received from a room, containing the message ID, the room's BareJid,
/// the sender's nickname, and the message body.
RoomPrivateMessage(Option<MessageId>, BareJid, RoomNick, Body, StanzaTimeInfo),
RoomPrivateMessage(Option<MessageId>, BareJid, RoomNick, String, StanzaTimeInfo),
/// A private message in a MUC was corrected/edited.
/// - The [`MessageId`] is the ID of the message that was corrected.
/// - The [`BareJid`] is the JID of the room where the message was sent.
/// - The [`RoomNick`] is the nickname of the sender of the message.
/// - The [`Body`] is the new body of the message, to replace the old one.
/// - The [`String`] is the new body of the message, to replace the old one.
/// - The [`StanzaTimeInfo`] is the time the message correction was sent/received
RoomPrivateMessageCorrection(MessageId, BareJid, RoomNick, Body, StanzaTimeInfo),
ServiceMessage(Option<MessageId>, BareJid, Body, StanzaTimeInfo),
RoomPrivateMessageCorrection(MessageId, BareJid, RoomNick, String, StanzaTimeInfo),
ServiceMessage(Option<MessageId>, BareJid, String, StanzaTimeInfo),
HttpUploadedFile(String),
}

View file

@ -25,7 +25,7 @@ pub async fn handle_message_group_chat(
events.push(Event::RoomSubject(
from.to_bare(),
from.resource().map(RoomNick::from_resource_ref),
subject.0.clone(),
subject.clone(),
time_info.clone(),
));
found_subject = true;

View file

@ -7,7 +7,7 @@
use crate::{
jid::{BareJid, Jid},
minidom::Element,
parsers::message::{Body, Message, MessagePayload, MessageType},
parsers::message::{Message, MessagePayload, MessageType},
};
use crate::Agent;
@ -66,7 +66,7 @@ pub async fn send_raw_message<'a>(agent: &mut Agent, settings: RawMessageSetting
stanza.type_ = message_type;
stanza
.bodies
.insert(lang.unwrap_or("").to_string(), Body(String::from(message)));
.insert(lang.unwrap_or("").into(), String::from(message));
agent.client.send_stanza(stanza.into()).await.unwrap();
}