xmpp/message/receive/
group_chat.rs1use crate::{
8 delay::StanzaTimeInfo,
9 jid::Jid,
10 parsers::{message::Message, message_correct::Replace},
11 Agent, Event, RoomNick,
12};
13
14pub async fn handle_message_group_chat(
15 agent: &mut Agent,
16 events: &mut Vec<Event>,
17 from: Jid,
18 message: &mut Message,
19 time_info: StanzaTimeInfo,
20) {
21 let langs: Vec<&str> = agent.lang.iter().map(String::as_str).collect();
22 let mut found_subject = false;
23
24 if let Some((_lang, subject)) = message.get_best_subject(langs.clone()) {
25 events.push(Event::RoomSubject(
26 from.to_bare(),
27 from.resource().map(RoomNick::from_resource_ref),
28 subject.0.clone(),
29 time_info.clone(),
30 ));
31 found_subject = true;
32 }
33
34 let Some((_lang, body)) = message.get_best_body_cloned(langs) else {
35 if !found_subject {
36 debug!(
37 "Received groupchat message without body/subject:\n{:#?}",
38 message
39 );
40 }
41 return;
42 };
43
44 let correction = message.extract_payload::<Replace>().unwrap_or_else(|e| {
45 warn!("Failed to parse <replace> payload: {e}");
46 None
47 });
48
49 if let Some(resource) = from.resource() {
58 let event = if let Some(correction) = correction {
61 Event::RoomMessageCorrection(
62 correction.id,
63 from.to_bare(),
64 RoomNick::from_resource_ref(resource),
65 body.clone(),
66 time_info,
67 )
68 } else {
69 Event::RoomMessage(
70 message.id.clone(),
71 from.to_bare(),
72 RoomNick::from_resource_ref(resource),
73 body.clone(),
74 time_info,
75 )
76 };
77 events.push(event);
78 } else {
79 if correction.is_some() {
81 warn!("Found correction in service message:\n{:#?}", message);
82 } else {
83 let event = Event::ServiceMessage(message.id.clone(), from.to_bare(), body, time_info);
84 events.push(event);
85 }
86 }
87}