pub mod mesh;
pub mod package;
pub mod session;
pub mod signal;
pub mod wire;
pub use session::{allow_outside_tor, is_joined, join, join_with, JoinOptions, XdcEvent, XdcFrame, XdcPeer, XdcSender, XdcSession};
use crate::types::Attachment;
#[derive(Debug, Clone)]
pub struct AppMessage {
pub chat_id: String,
pub message_id: String,
pub attachment: Attachment,
}
pub async fn find_by_topic_in(chat_id: &str, topic: &str) -> Option<AppMessage> {
{
let state = crate::state::STATE.lock().await;
if let Some(chat) = state.chats.iter().find(|c| c.id == chat_id) {
let hit = chat.messages.iter().find(|m| m.attachments.iter().any(|a| a.webxdc_topic.as_deref() == Some(topic)));
if let Some(compact) = hit {
let msg = compact.to_message(&state.interner);
let attachment = msg.attachments.into_iter().find(|a| a.webxdc_topic.as_deref() == Some(topic))?;
return Some(AppMessage { chat_id: chat_id.to_string(), message_id: msg.id, attachment });
}
}
}
let (message_id, attachment) = crate::db::attachments::find_by_webxdc_topic_in(chat_id, topic).ok().flatten()?;
Some(AppMessage { chat_id: chat_id.to_string(), message_id, attachment })
}
pub async fn on_signal(
chat_id: &str,
npub: &str,
topic: &str,
node_addr: Option<&str>,
event_id: &str,
created_at: u64,
) -> Option<signal::Signal> {
let sig = signal::ingest(chat_id, npub, topic, node_addr, event_id, created_at).await?;
session::apply_signal(&sig).await;
Some(sig)
}
pub fn is_app(att: &Attachment) -> bool {
att.extension.eq_ignore_ascii_case("xdc")
}