Phase 2: E2EE for DM + Slint migration + dead code cleanup

- E2EE crypto (src/e2ee.rs) with X25519 key derivation from Ed25519,
  HKDF shared secret, ChaCha20-Poly1305 encrypt/decrypt
- E2EE net layer: PID 0x0071-0x0074, JSON payloads, dispatch, session handlers
- E2EE UI: lock icons in DM header and sidebar
- Slint migration: all .slint files, bridge.rs, update.rs, main.rs
- Removed egui UI (~50 files), cleaned all dead code
- Clean cargo clippy -- -D warnings
This commit is contained in:
Loki 2026-07-14 13:25:15 +02:00
parent f361b037cb
commit 03d94e0465
Signed by: boba
GPG key ID: 253067914055423B
83 changed files with 5055 additions and 9202 deletions

267
src/ui/bridge.rs Normal file
View file

@ -0,0 +1,267 @@
use std::rc::Rc;
use slint::{SharedString, VecModel};
use crate::ui::state::{ConnState, UiState};
type MainWindow = crate::ui::slint::MainWindow;
type BookmarkItem = crate::ui::slint::BookmarkItem;
type ChannelItem = crate::ui::slint::ChannelItem;
type GuildItem = crate::ui::slint::GuildItem;
type MessageItem = crate::ui::slint::MessageItem;
type MemberItem = crate::ui::slint::MemberItem;
type FriendItem = crate::ui::slint::FriendItem;
type VoiceMemberItem = crate::ui::slint::VoiceMemberItem;
fn fmt_ts(ts: i64) -> String {
let secs = (ts / 1000).abs() % 86400;
format!("{:02}:{:02}", secs / 3600, (secs % 3600) / 60)
}
fn set_messages(window: &MainWindow, msgs: &[crate::ui::state::ChatMessage], own_user_id: &str) {
let items: Vec<MessageItem> = msgs
.iter()
.map(|m| MessageItem {
message_id: SharedString::from(m.message_id.as_str()),
sender_id: SharedString::from(m.sender_id.as_str()),
sender_name: SharedString::from(m.sender_id.as_str()),
content: SharedString::from(m.content.as_str()),
timestamp: SharedString::from(fmt_ts(m.timestamp)),
is_own: m.sender_id == own_user_id,
edited: m.edited,
reply_to: SharedString::from(m.reply_to.as_deref().unwrap_or("")),
})
.collect();
window.set_messages(Rc::new(VecModel::from(items)).into());
}
fn set_members_state(window: &MainWindow, state: &UiState, ch_id: &str) {
if let Some(ch) = state.channels.iter().find(|c| c.id == ch_id) {
let items: Vec<MemberItem> = ch
.members
.iter()
.map(|nick| {
let user_id = state
.user_names
.iter()
.find(|(_, n)| *n == nick)
.map(|(id, _)| id.clone())
.unwrap_or_else(|| nick.clone());
let status = state
.presences
.get(&user_id)
.map(|p| p.status.as_str())
.unwrap_or("offline");
MemberItem {
user_id: SharedString::from(user_id),
nickname: SharedString::from(nick.as_str()),
status: SharedString::from(status),
}
})
.collect();
window.set_members(Rc::new(VecModel::from(items)).into());
}
}
fn sync_sidebar(window: &MainWindow, state: &UiState) {
let channels: Vec<ChannelItem> = state
.channels
.iter()
.map(|c| ChannelItem {
channel_id: SharedString::from(c.id.as_str()),
name: SharedString::from(c.name.as_str()),
kind: SharedString::from(c.kind.as_str()),
})
.collect();
window.set_channels(Rc::new(VecModel::from(channels)).into());
let guilds: Vec<GuildItem> = state
.guilds
.iter()
.map(|g| GuildItem {
guild_id: SharedString::from(g.guild_id.as_str()),
name: SharedString::from(g.name.as_str()),
})
.collect();
window.set_guilds(Rc::new(VecModel::from(guilds)).into());
let dms: Vec<SharedString> = state
.dm_conversations
.iter()
.map(|c| SharedString::from(c.other_nickname.as_str()))
.collect();
window.set_dm_conversations(Rc::new(VecModel::from(dms)).into());
window.set_username(SharedString::from("user"));
window.set_user_status(SharedString::from("online"));
window.set_active_channel_id(SharedString::from(
state.active_channel.as_deref().unwrap_or(""),
));
window.set_active_guild_idx(state.active_guild_id.clone().map_or(-1, |id| {
state
.guilds
.iter()
.position(|g| g.guild_id == id)
.map_or(-1, |i| i as i32)
}));
}
fn sync_chat(window: &MainWindow, state: &UiState, own_user_id: &str) {
if let Some(ch_id) = &state.active_channel {
if let Some(ch) = state.channels.iter().find(|c| &c.id == ch_id) {
window.set_active_channel_name(SharedString::from(ch.name.as_str()));
if ch.kind == "voice" {
window.set_show_chat(false);
window.set_show_voice(true);
window.set_show_friends(false);
} else {
window.set_show_chat(true);
window.set_show_voice(false);
window.set_show_friends(false);
if let Some(msgs) = state.messages.get(ch_id) {
set_messages(window, msgs, own_user_id);
} else {
window.set_messages(Rc::new(VecModel::from(vec![])).into());
}
set_members_state(window, state, ch_id);
}
}
} else {
window.set_show_chat(false);
window.set_show_voice(false);
window.set_show_friends(true);
}
window.set_input_text(SharedString::from(state.chat_input.as_str()));
}
fn sync_friends(window: &MainWindow, state: &UiState) {
let friends: Vec<FriendItem> = state
.friends
.iter()
.map(|f| FriendItem {
user_id: SharedString::from(f.user_id.as_str()),
nickname: SharedString::from(f.nickname.as_str()),
status: SharedString::from(
state
.presences
.get(&f.user_id)
.map(|p| p.status.as_str())
.unwrap_or("offline"),
),
})
.collect();
window.set_friends(Rc::new(VecModel::from(friends)).into());
let pending: Vec<FriendItem> = state
.pending_friend_requests
.iter()
.map(|f| FriendItem {
user_id: SharedString::from(f.user_id.as_str()),
nickname: SharedString::from(f.nickname.as_str()),
status: SharedString::from("pending"),
})
.collect();
window.set_pending_requests(Rc::new(VecModel::from(pending)).into());
let blocked: Vec<SharedString> = state
.blocked_users
.iter()
.map(|u| SharedString::from(u.as_str()))
.collect();
window.set_blocked_users(Rc::new(VecModel::from(blocked)).into());
window.set_friends_active_tab(SharedString::from(state.friends_tab.as_str()));
}
pub fn sync_voice(window: &MainWindow, state: &UiState) {
let members: Vec<VoiceMemberItem> = state
.channels
.iter()
.filter(|c| {
matches!(
&state.voice,
crate::ui::state::VoiceUiState::Active { channel } if channel == &c.id
)
})
.flat_map(|c| c.members.iter())
.map(|nick| {
let user_id = state
.user_names
.iter()
.find(|(_, n)| *n == nick)
.map(|(id, _)| id.clone())
.unwrap_or_else(|| nick.clone());
VoiceMemberItem {
user_id: SharedString::from(user_id.clone()),
nickname: SharedString::from(nick.as_str()),
speaking: state.last_remote_speaker_id == user_id,
}
})
.collect();
window.set_voice_members(Rc::new(VecModel::from(members)).into());
window.set_mic_enabled(state.mic_enabled);
window.set_deafened(state.deafen);
if let crate::ui::state::VoiceUiState::Active { channel } = &state.voice {
if let Some(ch) = state.channels.iter().find(|c| &c.id == channel) {
window.set_voice_channel_name(SharedString::from(ch.name.as_str()));
}
}
let banner = match (state.local_speaking, state.remote_speaking) {
(true, true) => "you and others are talking".to_string(),
(true, false) => "you are talking".to_string(),
(false, true) => format!(
"{} is talking",
state.nick_for(&state.last_remote_speaker_id)
),
_ => String::new(),
};
window.set_activity_banner(SharedString::from(banner));
}
pub fn sync_connect(window: &MainWindow, state: &UiState) {
let bookmarks: Vec<BookmarkItem> = state
.bookmarks
.iter()
.map(|bm| BookmarkItem {
name: SharedString::from(bm.label.as_str()),
address: SharedString::from(bm.address.as_str()),
})
.collect();
window.set_bookmarks(Rc::new(VecModel::from(bookmarks)).into());
window.set_address_input(SharedString::from(state.connect_input.as_str()));
window.set_status_text(SharedString::from(
state.status_msg.as_deref().unwrap_or(""),
));
window.set_connecting(matches!(
state.conn,
ConnState::Connecting | ConnState::Reconnecting { .. }
));
window.set_auto_reconnect(state.auto_reconnect);
if let ConnState::Connected { ref node_name, .. } = state.conn {
window.set_node_name(SharedString::from(node_name.as_str()));
} else {
window.set_node_name(SharedString::from(""));
}
}
pub fn sync_settings(window: &MainWindow, state: &UiState) {
window.set_identity_pubkey(SharedString::from(""));
window.set_vault_enabled(false);
window.set_voice_input_device(SharedString::from(""));
window.set_voice_output_device(SharedString::from(""));
window.set_voice_bitrate(state.voice_bitrate);
window.set_vad_mode(state.vad_mode as i32);
window.set_volume(state.output_volume);
window.set_active_tab(SharedString::from("audio"));
}
pub fn sync_ui(window: &MainWindow, state: &UiState, own_user_id: &str) {
sync_sidebar(window, state);
sync_chat(window, state, own_user_id);
sync_friends(window, state);
sync_voice(window, state);
sync_connect(window, state);
sync_settings(window, state);
}