2023-12-30 00:35:29 +01:00
|
|
|
// Copyright (c) 2023 xmpp-rs contributors.
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
2023-12-30 13:18:12 +01:00
|
|
|
use tokio_xmpp::parsers::{
|
|
|
|
|
message::{Message, MessageType},
|
|
|
|
|
ns,
|
2023-12-30 00:35:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use crate::{pubsub, Agent, Event};
|
|
|
|
|
|
2023-12-30 13:18:12 +01:00
|
|
|
pub mod chat;
|
2023-12-30 13:09:01 +01:00
|
|
|
pub mod group_chat;
|
|
|
|
|
|
2023-12-30 00:35:29 +01:00
|
|
|
pub async fn handle_message(agent: &mut Agent, message: Message) -> Vec<Event> {
|
|
|
|
|
let mut events = vec![];
|
|
|
|
|
let from = message.from.clone().unwrap();
|
2023-12-30 13:09:01 +01:00
|
|
|
|
|
|
|
|
match message.type_ {
|
|
|
|
|
MessageType::Groupchat => {
|
|
|
|
|
group_chat::handle_message_group_chat(agent, &mut events, from.clone(), &message).await;
|
|
|
|
|
}
|
2023-12-30 13:18:12 +01:00
|
|
|
MessageType::Chat | MessageType::Normal => {
|
|
|
|
|
chat::handle_message_chat(agent, &mut events, from.clone(), &message).await;
|
|
|
|
|
}
|
2023-12-30 13:09:01 +01:00
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 00:35:29 +01:00
|
|
|
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
|
|
|
|
|
}
|