Message and message_correct::Replace now has typed Id

This commit is contained in:
xmppftw xmppftw 2024-12-21 00:10:13 +01:00 committed by pep
commit 33098e6f2c
9 changed files with 45 additions and 32 deletions

View file

@ -13,6 +13,8 @@ XXXX-YY-ZZ [ RELEASER <admin@localhost> ]
use RoomNick as sender nickname; previously RoomNick was an alias for String
now it's a newtype wrapper around ResourcePart (!485)
- Agent::send_room_private_message now takes RoomPrivateMessageSettings (!487)
- Event now exposes Option<MessageId> for incoming messages, and MessageId
for incoming message corrections; type alias Id has been removed (!504)
* Added:
- Agent::send_room_message takes RoomMessageSettings argument (!483)
- Agent::send_raw_message takes RawMessageSettings for any message type (!487)

View file

@ -9,7 +9,7 @@ use tokio_xmpp::jid::BareJid;
use tokio_xmpp::jid::Jid;
use tokio_xmpp::parsers::{message::Body, roster::Item as RosterItem};
use crate::{delay::StanzaTimeInfo, Error, Id, RoomNick};
use crate::{delay::StanzaTimeInfo, Error, MessageId, RoomNick};
#[derive(Debug)]
pub enum Event {
@ -21,27 +21,27 @@ pub enum Event {
#[cfg(feature = "avatars")]
AvatarRetrieved(Jid, String),
/// A chat message was received. It may have been delayed on the network.
/// - The [`Id`] is a unique identifier for this message.
/// - The [`MessageId`] is a unique identifier for this message.
/// - The [`BareJid`] is the sender's JID.
/// - The [`Body`] is the message body.
/// - The [`StanzaTimeInfo`] about when message was received, and when the message was claimed sent.
ChatMessage(Id, BareJid, Body, StanzaTimeInfo),
ChatMessage(Option<MessageId>, BareJid, Body, StanzaTimeInfo),
/// A message in a one-to-one chat was corrected/edited.
/// - The [`Id`] is the ID of the message that was corrected (always Some)
/// - 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 [`StanzaTimeInfo`] is the time the message correction was sent/received
ChatMessageCorrection(Id, BareJid, Body, StanzaTimeInfo),
ChatMessageCorrection(MessageId, BareJid, Body, StanzaTimeInfo),
RoomJoined(BareJid),
RoomLeft(BareJid),
RoomMessage(Id, BareJid, RoomNick, Body, StanzaTimeInfo),
RoomMessage(Option<MessageId>, BareJid, RoomNick, Body, StanzaTimeInfo),
/// A message in a MUC was corrected/edited.
/// - The [`Id`] is the ID of the message that was corrected (always Some)
/// - 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 [`StanzaTimeInfo`] is the time the message correction was sent/received
RoomMessageCorrection(Id, BareJid, RoomNick, Body, StanzaTimeInfo),
RoomMessageCorrection(MessageId, BareJid, RoomNick, Body, 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(Id, BareJid, RoomNick, Body, StanzaTimeInfo),
RoomPrivateMessage(Option<MessageId>, BareJid, RoomNick, Body, StanzaTimeInfo),
/// A private message in a MUC was corrected/edited.
/// - The [`Id`] is the ID of the message that was corrected (always Some)
/// - 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 [`StanzaTimeInfo`] is the time the message correction was sent/received
RoomPrivateMessageCorrection(Id, BareJid, RoomNick, Body, StanzaTimeInfo),
ServiceMessage(Id, BareJid, Body, StanzaTimeInfo),
RoomPrivateMessageCorrection(MessageId, BareJid, RoomNick, Body, StanzaTimeInfo),
ServiceMessage(Option<MessageId>, BareJid, Body, StanzaTimeInfo),
HttpUploadedFile(String),
}

View file

@ -19,6 +19,7 @@ extern crate log;
use core::fmt;
use jid::{ResourcePart, ResourceRef};
use parsers::message::Id as MessageId;
pub mod agent;
pub mod builder;
@ -40,7 +41,6 @@ pub use event::Event;
pub use feature::ClientFeature;
pub type Error = tokio_xmpp::Error;
pub type Id = Option<String>;
/// Nickname for a person in a chatroom.
///

View file

@ -36,7 +36,7 @@ pub async fn handle_message_chat(
let event = if let Some(correction) = correction {
Event::RoomPrivateMessageCorrection(
Some(correction.id),
correction.id,
full_from.to_bare(),
RoomNick::from_resource_ref(full_from.resource()),
body.clone(),
@ -56,14 +56,9 @@ pub async fn handle_message_chat(
} else {
let event = if let Some(correction) = correction {
// TODO: Check that correction is valid (only for last N minutes or last N messages)
Event::ChatMessageCorrection(
Some(correction.id),
from.to_bare(),
body.clone(),
time_info,
)
Event::ChatMessageCorrection(correction.id, from.to_bare(), body.clone(), time_info)
} else {
Event::ChatMessage(message.id.clone(), from.to_bare(), body.clone(), time_info)
Event::ChatMessage(message.id.clone(), from.to_bare(), body, time_info)
};
events.push(event);
}

View file

@ -59,7 +59,7 @@ pub async fn handle_message_group_chat(
let event = if let Some(correction) = correction {
Event::RoomMessageCorrection(
Some(correction.id),
correction.id,
from.to_bare(),
RoomNick::from_resource_ref(resource),
body.clone(),