Skip to main content

iris_chat_core/
updates.rs

1use crate::actions::AppAction;
2use crate::state::{AppState, MutualGroupsSnapshot, PeerProfileDebugSnapshot};
3use flume::Sender;
4use nostr_sdk::prelude::{Event, RelayStatus};
5
6#[derive(uniffi::Enum, Clone, Debug)]
7#[allow(clippy::large_enum_variant)]
8pub enum AppUpdate {
9    FullState(AppState),
10    PersistAccountBundle {
11        rev: u64,
12        owner_nsec: Option<String>,
13        owner_pubkey_hex: String,
14        device_nsec: String,
15    },
16    NearbyPublishedEvent {
17        event_id: String,
18        kind: u32,
19        created_at_secs: u64,
20        event_json: String,
21    },
22}
23
24#[derive(Debug)]
25pub(crate) enum CoreMsg {
26    Action(AppAction),
27    Internal(Box<InternalEvent>),
28    BuildNearbyPresenceEvent {
29        peer_id: String,
30        my_nonce: String,
31        their_nonce: String,
32        profile_event_id: String,
33        reply_tx: Sender<String>,
34    },
35    ExportSupportBundle(Sender<String>),
36    PeerProfileDebug {
37        owner_input: String,
38        reply_tx: Sender<Option<PeerProfileDebugSnapshot>>,
39    },
40    MutualGroups {
41        owner_input: String,
42        reply_tx: Sender<MutualGroupsSnapshot>,
43    },
44    PrepareForSuspend(Sender<()>),
45    /// Snapshot of core-internal perf counters (debug-snapshot
46    /// rebuild count etc.) — read by `FfiApp::core_perf_counters()`
47    /// so the release-gate budget tests can assert on internal hot
48    /// loops, not just FFI surface traffic.
49    CorePerfCounters(Sender<CorePerfCountersSnapshot>),
50    Shutdown(Option<Sender<()>>),
51    #[cfg(test)]
52    PanicForTest,
53}
54
55#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
56pub(crate) struct CorePerfCountersSnapshot {
57    /// `build_runtime_debug_snapshot` calls since core start.
58    pub debug_snapshot_builds: u64,
59}
60
61#[derive(Debug)]
62pub(crate) enum InternalEvent {
63    RelayEvent(Event),
64    NearbyEvent {
65        event: Event,
66        transport: String,
67    },
68    FetchTrackedPeerCatchUp {
69        token: u64,
70    },
71    ProtocolSubscriptionLivenessCheck {
72        token: u64,
73    },
74    PollPendingDeviceInvites {
75        token: u64,
76    },
77    PruneExpiredMessages {
78        token: u64,
79    },
80    FetchCatchUpEvents(Vec<Event>),
81    RelayStatusChanged {
82        relay_url: String,
83        status: RelayStatus,
84        generation: u64,
85    },
86    ProtocolSubscriptionReconcileCompleted {
87        generation: u64,
88        token: u64,
89        reason: String,
90        plan: Option<crate::core::ProtocolSubscriptionPlan>,
91        success: bool,
92        error: Option<String>,
93        relay_statuses: Vec<(String, RelayStatus)>,
94        connected_before: u64,
95        connected_after: u64,
96        filter_count: u64,
97    },
98    RelayTransportConnectionFinished {
99        token: u64,
100        reason: String,
101        relay_statuses: Vec<(String, RelayStatus)>,
102        connected_count: u64,
103    },
104    #[cfg(not(target_os = "ios"))]
105    DebugSnapshotWriteFinished {
106        generation: u64,
107    },
108    DebugLog {
109        category: String,
110        detail: String,
111    },
112    TypingIndicatorExpired {
113        chat_id: String,
114        author: String,
115    },
116    RelayPublishDrainFinished {
117        token: u64,
118        results: Vec<RelayPublishDrainResult>,
119    },
120    RetryPendingRelayPublishes {
121        reason: String,
122    },
123    AttachmentUploadFinished {
124        chat_id: String,
125        result: Result<String, String>,
126    },
127    AttachmentUploadProgress {
128        bytes_uploaded: u64,
129        total_bytes: u64,
130    },
131    ProfilePictureUploadFinished {
132        result: Result<String, String>,
133    },
134    SyncComplete,
135    // Heavy tail of `open_chat` — DB page load, identity republish,
136    // persist, protocol refresh. Runs on the same event loop as a
137    // queued follow-up so subsequent UI actions (back, switch chat)
138    // can interleave between the screen flip and the load.
139    OpenChatFinalize {
140        chat_id: String,
141    },
142}
143
144#[derive(Debug)]
145pub(crate) struct RelayPublishDrainResult {
146    pub(crate) event_id: String,
147    pub(crate) message_id: Option<String>,
148    pub(crate) chat_id: Option<String>,
149    pub(crate) success: bool,
150    pub(crate) relay_urls: Vec<String>,
151    pub(crate) detail: String,
152}