Move SessionView, Tab, Msg and the App data fields into voelin-ui-vm::state
The sessions and their chat tabs, the downloads, pins and linked pictures, and the data the screens share (the servers, the settings, the dialogs' targets, the share and watch bookkeeping) no longer live in the Slint crate. `SessionView<L>` and `Tab<L>` are generic over the list type of a tab's chat lines: the Slint app plugs in `Rows<ChatLine>` (`app::ChatRows`), a GPUI view can use a plain `Vec`. `App` keeps one `AppState` in `state` and the Slint models; every `self.sessions`, `self.current`, `self.bookmarks`, ... becomes `self.state.<field>`. server_icon and server_icon_for stay with the session: `ImageRef` is toolkit-free now, so they need no adapter. Tests for the tab and session logic (private chat focus, tab removal, read markers, the divider) are new, since that logic could not be tested without the Slint crate before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ce7ec3afb7
commit
ac4cee0a8f
21 files changed
+1163
-864
No files matched your search
+12
-12
@@ -184,7 +184,7 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
}
|
||||
Some("observe") => {
|
||||
with_app(|app| {
|
||||
if let Some(id) = app.current {
|
||||
if let Some(id) = app.state.current {
|
||||
app.observe(id);
|
||||
}
|
||||
});
|
||||
@@ -214,7 +214,7 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
}
|
||||
// The current server's dialog, Advanced open.
|
||||
"bookmark" if arg == "edit" => {
|
||||
if let Some(id) = with_app(|app| app.current).flatten() {
|
||||
if let Some(id) = with_app(|app| app.state.current).flatten() {
|
||||
nav.invoke_edit_server(id as i32);
|
||||
}
|
||||
}
|
||||
@@ -425,9 +425,9 @@ fn late(
|
||||
/// The current chat's read marker `back` messages before its end, as if
|
||||
/// they came while away, its "New" divider shown (`VOELIN_OPEN=unread`).
|
||||
fn open_unread(app: &mut App, back: usize) {
|
||||
let Some(id) = app.current else { return };
|
||||
let Some(id) = app.state.current else { return };
|
||||
let own_uids = app.social.own_uids.clone();
|
||||
let Some(view) = app.sessions.get_mut(&id) else { return };
|
||||
let Some(view) = app.state.sessions.get_mut(&id) else { return };
|
||||
let own_client = view.state.own_client;
|
||||
let own = |m: &ChatMessage| crate::social::own_message(&own_uids, own_client, m);
|
||||
let index = view.current_tab;
|
||||
@@ -483,7 +483,7 @@ fn save_png(image: &SharedPixelBuffer<Rgba8Pixel>, path: &std::path::Path) -> Re
|
||||
/// channel, which asks for its password; `wrong` as if the server had
|
||||
/// refused one.
|
||||
fn open_channel_password(app: &mut App, wrong: bool) {
|
||||
let Some(session) = app.current else { return };
|
||||
let Some(session) = app.state.current else { return };
|
||||
let locked = app
|
||||
.view()
|
||||
.and_then(|v| v.presence.channels.values().filter(|c| c.has_password).map(|c| c.id).min());
|
||||
@@ -549,7 +549,7 @@ fn demo_ui(app: &mut App) {
|
||||
client_version: None,
|
||||
cached_server_icon: None,
|
||||
};
|
||||
app.bookmarks = vec![
|
||||
app.state.bookmarks = vec![
|
||||
Bookmark {
|
||||
gateway_url: Some("wss://gw.nightfall.example/v1".into()),
|
||||
..bookmark(DEMO, "Nightfall Guild", "ts.nightfall.example:9987")
|
||||
@@ -559,12 +559,12 @@ fn demo_ui(app: &mut App) {
|
||||
];
|
||||
// Home's "Continue where you left off": a channel of a server without
|
||||
// voice, so it shows Join.
|
||||
app.settings.last_voice = Some(LastVoice {
|
||||
app.state.settings.last_voice = Some(LastVoice {
|
||||
bookmark: DEMO + 1,
|
||||
address: "pixel.example".into(),
|
||||
channel: vec!["Art Corner".into()],
|
||||
});
|
||||
app.current = Some(DEMO);
|
||||
app.state.current = Some(DEMO);
|
||||
let session = DEMO as u64;
|
||||
|
||||
let mut p = Presence { server_name: "Nightfall Guild".into(), ..Default::default() };
|
||||
@@ -940,7 +940,7 @@ fn demo_social(app: &mut App) {
|
||||
// The samples came one by one, as new ones do: all are read (no "New"
|
||||
// line, which a gateway page on screen gets), but for Mira's and
|
||||
// Lumen's messages, which came while away.
|
||||
for view in app.sessions.values_mut() {
|
||||
for view in app.state.sessions.values_mut() {
|
||||
for tab in &mut view.tabs {
|
||||
tab.divider = None;
|
||||
tab.catch_up();
|
||||
@@ -983,7 +983,7 @@ fn demo_social(app: &mut App) {
|
||||
});
|
||||
|
||||
// The pictures of the links, as if downloaded.
|
||||
if let Some(view) = app.sessions.get_mut(&DEMO) {
|
||||
if let Some(view) = app.state.sessions.get_mut(&DEMO) {
|
||||
for (channel, name) in
|
||||
[(2, "night-castle.png"), (2, "guild-banner.png"), (2, "map-notes.png")]
|
||||
{
|
||||
@@ -995,7 +995,7 @@ fn demo_social(app: &mut App) {
|
||||
};
|
||||
view.extra.previews.insert(
|
||||
crate::previews::link_key(&file),
|
||||
crate::previews::Preview::Ready(voelin_core::Bytes(
|
||||
crate::vm::state::Preview::Ready(voelin_core::Bytes(
|
||||
demo_picture(640, 360, name.len() as u32).into(),
|
||||
)),
|
||||
);
|
||||
@@ -1242,7 +1242,7 @@ fn demo_pictures(app: &mut App) {
|
||||
};
|
||||
let mut events = vec![Event::ServerDetails {
|
||||
session,
|
||||
address: app.bookmarks.iter().find(|b| b.id == DEMO).unwrap().address.clone(),
|
||||
address: app.state.bookmarks.iter().find(|b| b.id == DEMO).unwrap().address.clone(),
|
||||
details: Arc::new(voelin_model::ServerDetails {
|
||||
icon: DEMO_SERVER_ICON,
|
||||
..Default::default()
|
||||
|
||||
Reference in new issue
Block a user