xmpp/message/receive/
mod.rs1use tokio_xmpp::parsers::{
8 message::{Message, MessageType},
9 ns,
10};
11
12use crate::{delay::message_time_info, pubsub, Agent, Event};
13
14pub mod chat;
15pub mod group_chat;
16
17pub async fn handle_message(agent: &mut Agent, mut message: Message) -> Vec<Event> {
18 let mut events = vec![];
19 let from = message.from.clone().unwrap();
20 let time_info = message_time_info(&message);
21
22 match message.type_ {
23 MessageType::Groupchat => {
24 group_chat::handle_message_group_chat(
25 agent,
26 &mut events,
27 from.clone(),
28 &mut message,
29 time_info,
30 )
31 .await;
32 }
33 MessageType::Chat | MessageType::Normal => {
34 chat::handle_message_chat(agent, &mut events, from.clone(), &mut message, time_info)
35 .await;
36 }
37 _ => {}
38 }
39
40 for child in message.payloads {
44 if child.is("event", ns::PUBSUB_EVENT) {
45 let new_events = pubsub::handle_event(&from, child, agent).await;
46 events.extend(new_events);
47 }
48 }
49
50 events
51}