xmpp/message/receive/
group_chat.rsuse crate::{
delay::StanzaTimeInfo,
jid::Jid,
parsers::{message::Message, message_correct::Replace},
Agent, Event, RoomNick,
};
pub async fn handle_message_group_chat(
agent: &mut Agent,
events: &mut Vec<Event>,
from: Jid,
message: &mut Message,
time_info: StanzaTimeInfo,
) {
let langs: Vec<&str> = agent.lang.iter().map(String::as_str).collect();
let mut found_subject = false;
if let Some((_lang, subject)) = message.get_best_subject(langs.clone()) {
events.push(Event::RoomSubject(
from.to_bare(),
from.resource().map(RoomNick::from_resource_ref),
subject.0.clone(),
time_info.clone(),
));
found_subject = true;
}
let Some((_lang, body)) = message.get_best_body_cloned(langs) else {
if !found_subject {
debug!(
"Received groupchat message without body/subject:\n{:#?}",
message
);
}
return;
};
let correction = message.extract_payload::<Replace>().unwrap_or_else(|e| {
warn!("Failed to parse <replace> payload: {e}");
None
});
if let Some(resource) = from.resource() {
let event = if let Some(correction) = correction {
Event::RoomMessageCorrection(
correction.id,
from.to_bare(),
RoomNick::from_resource_ref(resource),
body.clone(),
time_info,
)
} else {
Event::RoomMessage(
message.id.clone(),
from.to_bare(),
RoomNick::from_resource_ref(resource),
body.clone(),
time_info,
)
};
events.push(event);
} else {
if correction.is_some() {
warn!("Found correction in service message:\n{:#?}", message);
} else {
let event = Event::ServiceMessage(message.id.clone(), from.to_bare(), body, time_info);
events.push(event);
}
}
}