1use crate::actions::AppAction;
2use crate::state::{AppState, MutualGroupsSnapshot, PeerProfileDebugSnapshot};
3use crate::DesktopNearbySnapshot;
4use flume::Sender;
5use nostr_sdk::prelude::{Event, RelayStatus};
6
7#[derive(uniffi::Enum, Clone, Debug)]
8#[allow(clippy::large_enum_variant)]
9pub enum AppUpdate {
10 FullState(AppState),
11 PersistAccountBundle {
12 rev: u64,
13 owner_nsec: Option<String>,
14 owner_pubkey_hex: String,
15 device_nsec: String,
16 },
17 NearbyPublishedEvent {
18 event_id: String,
19 kind: u32,
20 created_at_secs: u64,
21 event_json: String,
22 },
23 NearbyPeersChanged {
24 snapshot: DesktopNearbySnapshot,
25 bluetooth_peer_ids: Vec<String>,
26 lan_peer_ids: Vec<String>,
27 },
28}
29
30pub(crate) fn enqueue_update_for_delivery(
31 update: AppUpdate,
32 latest_full_state: &mut Option<AppUpdate>,
33 before_full_state: &mut Vec<AppUpdate>,
34 after_full_state: &mut Vec<AppUpdate>,
35) {
36 match update {
37 full @ AppUpdate::FullState(_) => *latest_full_state = Some(full),
38 nearby
39 @ (AppUpdate::NearbyPublishedEvent { .. } | AppUpdate::NearbyPeersChanged { .. }) => {
40 after_full_state.push(nearby)
41 }
42 other => before_full_state.push(other),
43 }
44}
45
46#[derive(Clone, Debug, PartialEq, Eq)]
47pub(crate) struct FipsNearbyLinkSnapshot {
48 pub(crate) device_pubkey_hex: String,
49 pub(crate) transport_type: String,
50}
51
52#[derive(Debug)]
53pub(crate) enum CoreMsg {
54 Action(AppAction),
55 Internal(Box<InternalEvent>),
56 ExportSupportBundle(Sender<String>),
57 PeerProfileDebug {
58 owner_input: String,
59 reply_tx: Sender<Option<PeerProfileDebugSnapshot>>,
60 },
61 MutualGroups {
62 owner_input: String,
63 reply_tx: Sender<MutualGroupsSnapshot>,
64 },
65 AttachHostBle {
66 attachment: crate::core::HostBleAttachment,
67 reply_tx: Sender<Result<(), String>>,
68 },
69 DetachHostBle(Sender<()>),
70 PrepareForSuspend(Sender<()>),
71 CorePerfCounters(Sender<CorePerfCountersSnapshot>),
76 Shutdown(Option<Sender<()>>),
77 #[cfg(test)]
78 PanicForTest,
79}
80
81#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
82pub(crate) struct CorePerfCountersSnapshot {
83 pub debug_snapshot_builds: u64,
85}
86
87#[derive(Debug)]
88pub(crate) enum InternalEvent {
89 RelayEvent(Event),
90 FipsNearbyPacket {
91 source_pubkey_hex: String,
92 source_port: u16,
93 data: Vec<u8>,
94 },
95 FipsNearbyPeersChanged(Vec<FipsNearbyLinkSnapshot>),
96 FetchTrackedPeerCatchUp {
97 token: u64,
98 },
99 ProtocolSubscriptionLivenessCheck {
100 token: u64,
101 },
102 PollPendingDeviceInvites {
103 token: u64,
104 },
105 PruneExpiredMessages {
106 token: u64,
107 },
108 FetchCatchUpEvents(Vec<Event>),
109 ProfileMetadataFetchFinished {
110 owner_pubkey_hex: String,
111 events: Vec<Event>,
112 error: Option<String>,
113 },
114 RelayStatusChanged {
115 relay_url: String,
116 status: RelayStatus,
117 generation: u64,
118 },
119 ProtocolSubscriptionReconcileCompleted {
120 generation: u64,
121 token: u64,
122 reason: String,
123 plan: Option<crate::core::ProtocolSubscriptionPlan>,
124 success: bool,
125 error: Option<String>,
126 relay_statuses: Vec<(String, RelayStatus)>,
127 connected_before: u64,
128 connected_after: u64,
129 filter_count: u64,
130 },
131 RelayTransportConnectionFinished {
132 token: u64,
133 reason: String,
134 relay_statuses: Vec<(String, RelayStatus)>,
135 connected_count: u64,
136 },
137 #[cfg(not(target_os = "ios"))]
138 DebugSnapshotWriteFinished {
139 generation: u64,
140 },
141 DebugLog {
142 category: String,
143 detail: String,
144 },
145 TypingIndicatorExpired {
146 chat_id: String,
147 author: String,
148 },
149 FlushPendingDeliveredReceipts {
150 token: u64,
151 },
152 RelayPublishDrainFinished {
153 token: u64,
154 results: Vec<RelayPublishDrainResult>,
155 },
156 RelayPublishDrainProgress {
157 token: u64,
158 result: RelayPublishDrainResult,
159 },
160 SessionStartupFollowUp,
161 RetryPendingRelayPublishes {
162 reason: String,
163 },
164 AttachmentUploadFinished {
165 chat_id: String,
166 result: Result<String, String>,
167 },
168 AttachmentUploadProgress {
169 bytes_uploaded: u64,
170 total_bytes: u64,
171 },
172 ProfilePictureUploadFinished {
173 result: Result<String, String>,
174 },
175 GroupPictureUploadFinished {
176 group_id: String,
177 result: Result<String, String>,
178 },
179 SyncComplete,
180 ProtocolAuthorBackfillComplete {
181 reason: String,
182 },
183 OpenChatFinalize {
188 chat_id: String,
189 },
190 DeviceSyncPacket {
191 source_pubkey_hex: String,
192 source_port: u16,
193 data: Vec<u8>,
194 },
195}
196
197#[derive(Debug)]
198pub(crate) struct RelayPublishDrainResult {
199 pub(crate) event_id: String,
200 pub(crate) success: bool,
201 pub(crate) relay_urls: Vec<String>,
202 pub(crate) detail: String,
203}