xmpp: Use ResourcePart for sender of room events

This commit is contained in:
xmppftw xmppftw 2024-12-18 00:59:47 +01:00 • committed by xmpp ftw
commit 5477cf1240
4 changed files with 10 additions and 8 deletions

View file

@ -8,6 +8,8 @@ XXXX-YY-ZZ [ RELEASER <admin@localhost> ]
- builder::ClientBuilder::set_default_nick no longer takes a &str, but - builder::ClientBuilder::set_default_nick no longer takes a &str, but
any type that implements AsRef<jid::ResourceRef>, such as produced any type that implements AsRef<jid::ResourceRef>, such as produced
by ResourcePart::new (!485) by ResourcePart::new (!485)
- Event::RoomMessage, Event::RoomPrivateMessage, and Event::RoomSubject now
use ResourcePart as sender nickname (!485)
* Added: * Added:
- Agent::send_room_message takes RoomMessageSettings argument (!483) - Agent::send_room_message takes RoomMessageSettings argument (!483)
* Fixes: * Fixes:

View file

@ -4,12 +4,12 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use tokio_xmpp::jid::BareJid;
#[cfg(feature = "avatars")] #[cfg(feature = "avatars")]
use tokio_xmpp::jid::Jid; use tokio_xmpp::jid::Jid;
use tokio_xmpp::jid::{BareJid, ResourcePart};
use tokio_xmpp::parsers::{message::Body, roster::Item as RosterItem}; use tokio_xmpp::parsers::{message::Body, roster::Item as RosterItem};
use crate::{delay::StanzaTimeInfo, Error, Id, RoomNick}; use crate::{delay::StanzaTimeInfo, Error, Id};
#[derive(Debug)] #[derive(Debug)]
pub enum Event { pub enum Event {
@ -28,15 +28,15 @@ pub enum Event {
ChatMessage(Id, BareJid, Body, StanzaTimeInfo), ChatMessage(Id, BareJid, Body, StanzaTimeInfo),
RoomJoined(BareJid), RoomJoined(BareJid),
RoomLeft(BareJid), RoomLeft(BareJid),
RoomMessage(Id, BareJid, RoomNick, Body, StanzaTimeInfo), RoomMessage(Id, BareJid, ResourcePart, Body, StanzaTimeInfo),
/// The subject of a room was received. /// The subject of a room was received.
/// - The BareJid is the room's address. /// - The BareJid is the room's address.
/// - The RoomNick is the nickname of the room member who set the subject. /// - The RoomNick is the nickname of the room member who set the subject.
/// - The String is the new subject. /// - The String is the new subject.
RoomSubject(BareJid, Option<RoomNick>, String, StanzaTimeInfo), RoomSubject(BareJid, Option<ResourcePart>, String, StanzaTimeInfo),
/// A private message received from a room, containing the message ID, the room's BareJid, /// A private message received from a room, containing the message ID, the room's BareJid,
/// the sender's nickname, and the message body. /// the sender's nickname, and the message body.
RoomPrivateMessage(Id, BareJid, RoomNick, Body, StanzaTimeInfo), RoomPrivateMessage(Id, BareJid, ResourcePart, Body, StanzaTimeInfo),
ServiceMessage(Id, BareJid, Body, StanzaTimeInfo), ServiceMessage(Id, BareJid, Body, StanzaTimeInfo),
HttpUploadedFile(String), HttpUploadedFile(String),
} }

View file

@ -38,7 +38,7 @@ pub async fn handle_message_chat(
Ok(full) => Event::RoomPrivateMessage( Ok(full) => Event::RoomPrivateMessage(
message.id.clone(), message.id.clone(),
full.to_bare(), full.to_bare(),
full.resource().to_string(), full.resource().into(),
body.clone(), body.clone(),
time_info.clone(), time_info.clone(),
), ),

View file

@ -20,7 +20,7 @@ pub async fn handle_message_group_chat(
if let Some((_lang, subject)) = message.get_best_subject(langs.clone()) { if let Some((_lang, subject)) = message.get_best_subject(langs.clone()) {
events.push(Event::RoomSubject( events.push(Event::RoomSubject(
from.to_bare(), from.to_bare(),
from.resource().map(|x| x.to_string()), from.resource().map(Into::into),
subject.0.clone(), subject.0.clone(),
time_info.clone(), time_info.clone(),
)); ));
@ -31,7 +31,7 @@ pub async fn handle_message_group_chat(
Ok(full) => Event::RoomMessage( Ok(full) => Event::RoomMessage(
message.id.clone(), message.id.clone(),
from.to_bare(), from.to_bare(),
full.resource().to_string(), full.resource().into(),
body.clone(), body.clone(),
time_info, time_info,
), ),