2023-12-30 13:09:01 +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/.
|
|
|
|
|
|
|
|
|
|
use tokio_xmpp::{parsers::message::Message, Jid};
|
|
|
|
|
|
2023-12-31 21:06:15 +01:00
|
|
|
use crate::{delay::StanzaTimeInfo, Agent, Event};
|
2023-12-30 13:09:01 +01:00
|
|
|
|
|
|
|
|
pub async fn handle_message_group_chat(
|
|
|
|
|
agent: &mut Agent,
|
|
|
|
|
events: &mut Vec<Event>,
|
|
|
|
|
from: Jid,
|
|
|
|
|
message: &Message,
|
2023-12-31 21:06:15 +01:00
|
|
|
time_info: StanzaTimeInfo,
|
2023-12-30 13:09:01 +01:00
|
|
|
) {
|
|
|
|
|
let langs: Vec<&str> = agent.lang.iter().map(String::as_str).collect();
|
2023-12-31 19:41:34 +01:00
|
|
|
|
|
|
|
|
if let Some((_lang, subject)) = message.get_best_subject(langs.clone()) {
|
2023-12-31 19:59:05 +01:00
|
|
|
events.push(Event::RoomSubject(
|
|
|
|
|
from.to_bare(),
|
|
|
|
|
from.resource_str().map(String::from),
|
|
|
|
|
subject.0.clone(),
|
2023-12-31 21:06:15 +01:00
|
|
|
time_info.clone(),
|
2023-12-31 19:59:05 +01:00
|
|
|
));
|
2023-12-31 19:41:34 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 13:09:01 +01:00
|
|
|
if let Some((_lang, body)) = message.get_best_body(langs) {
|
|
|
|
|
let event = match from.clone() {
|
|
|
|
|
Jid::Full(full) => Event::RoomMessage(
|
|
|
|
|
message.id.clone(),
|
|
|
|
|
from.to_bare(),
|
|
|
|
|
full.resource_str().to_owned(),
|
|
|
|
|
body.clone(),
|
2023-12-31 21:06:15 +01:00
|
|
|
time_info,
|
2023-12-30 13:09:01 +01:00
|
|
|
),
|
2023-12-31 21:06:15 +01:00
|
|
|
Jid::Bare(bare) => {
|
|
|
|
|
Event::ServiceMessage(message.id.clone(), bare, body.clone(), time_info)
|
|
|
|
|
}
|
2023-12-30 13:09:01 +01:00
|
|
|
};
|
|
|
|
|
events.push(event)
|
|
|
|
|
}
|
|
|
|
|
}
|