xmpp/message/receive/
mod.rsuse tokio_xmpp::parsers::{
message::{Message, MessageType},
ns,
};
use crate::{delay::message_time_info, pubsub, Agent, Event};
pub mod chat;
pub mod group_chat;
pub async fn handle_message(agent: &mut Agent, message: Message) -> Vec<Event> {
let mut events = vec![];
let from = message.from.clone().unwrap();
let time_info = message_time_info(&message);
match message.type_ {
MessageType::Groupchat => {
group_chat::handle_message_group_chat(
agent,
&mut events,
from.clone(),
&message,
time_info,
)
.await;
}
MessageType::Chat | MessageType::Normal => {
chat::handle_message_chat(agent, &mut events, from.clone(), &message, time_info).await;
}
_ => {}
}
for child in message.payloads {
if child.is("event", ns::PUBSUB_EVENT) {
let new_events = pubsub::handle_event(&from, child, agent).await;
events.extend(new_events);
}
}
events
}