From 4f8ce0a953f9a21d644c9fde01ff1f02a9725d34 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Sun, 31 Dec 2023 19:41:34 +0100 Subject: [PATCH] Implement Event::RoomSubject for room subject changes/retrieve --- xmpp/src/event.rs | 5 +++++ xmpp/src/message/receive/group_chat.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/xmpp/src/event.rs b/xmpp/src/event.rs index 2ba2d5f..2eea5c2 100644 --- a/xmpp/src/event.rs +++ b/xmpp/src/event.rs @@ -24,6 +24,11 @@ pub enum Event { RoomJoined(BareJid), RoomLeft(BareJid), RoomMessage(Id, BareJid, RoomNick, Body), + /// 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. + /// - The String is the new subject. + RoomSubject(BareJid, Option, String), /// 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), diff --git a/xmpp/src/message/receive/group_chat.rs b/xmpp/src/message/receive/group_chat.rs index 7cf81f8..71611fb 100644 --- a/xmpp/src/message/receive/group_chat.rs +++ b/xmpp/src/message/receive/group_chat.rs @@ -15,6 +15,11 @@ pub async fn handle_message_group_chat( message: &Message, ) { let langs: Vec<&str> = agent.lang.iter().map(String::as_str).collect(); + + if let Some((_lang, subject)) = message.get_best_subject(langs.clone()) { + events.push(Event::RoomSubject(from.to_bare(), from.resource_str().map(String::from), subject.0.clone())); + } + if let Some((_lang, body)) = message.get_best_body(langs) { let event = match from.clone() { Jid::Full(full) => Event::RoomMessage(