1pub mod mesh;
14pub mod package;
15pub mod session;
16pub mod signal;
17pub mod wire;
18
19pub use session::{allow_outside_tor, allow_outside_transport, is_joined, join, join_with, JoinOptions, XdcEvent, XdcFrame, XdcPeer, XdcSender, XdcSession};
20
21use crate::types::Attachment;
22
23#[derive(Debug, Clone)]
25pub struct AppMessage {
26 pub chat_id: String,
28 pub message_id: String,
29 pub attachment: Attachment,
30}
31
32pub async fn find_by_topic_in(chat_id: &str, topic: &str) -> Option<AppMessage> {
35 {
36 let state = crate::state::STATE.lock().await;
37 if let Some(chat) = state.chats.iter().find(|c| c.id == chat_id) {
38 let hit = chat.messages.iter().find(|m| m.attachments.iter().any(|a| a.webxdc_topic() == Some(topic)));
39 if let Some(compact) = hit {
40 let msg = compact.to_message(&state.interner);
41 let attachment = msg.attachments.into_iter().find(|a| a.webxdc_topic.as_deref() == Some(topic))?;
42 return Some(AppMessage { chat_id: chat_id.to_string(), message_id: msg.id, attachment });
43 }
44 }
45 }
46 let (message_id, attachment) = crate::db::attachments::find_by_webxdc_topic_in(chat_id, topic).ok().flatten()?;
47 Some(AppMessage { chat_id: chat_id.to_string(), message_id, attachment })
48}
49
50pub async fn on_signal(
54 chat_id: &str,
55 npub: &str,
56 topic: &str,
57 node_addr: Option<&str>,
58 event_id: &str,
59 created_at: u64,
60) -> Option<signal::Signal> {
61 let sig = signal::ingest(chat_id, npub, topic, node_addr, event_id, created_at).await?;
62 session::apply_signal(&sig).await;
63 Some(sig)
64}
65
66pub fn is_app(att: &Attachment) -> bool {
68 att.extension.eq_ignore_ascii_case("xdc")
69}