Pictures in chat as inline cards; navigate after callbacks

A linked picture whose bytes arrived shows as a picture card in the
message (a click opens it larger) instead of the file card.

Navigating from the app (opening a conversation, a notification, a
search result) ran Nav's functions inside a callback, and Nav calls back
into the app, which was borrowed: the app panicked. Such navigation now
runs after the callback, as the Stream Studio's does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 12:29:25 +03:00
1 parent 673e41542c
commit c7455977f6
5 files changed
+72 -24

No files matched your search

+2 -4
View File
@@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};
use slint::ComponentHandle;
use voelin_core::VoiceState;
use crate::app::{App, Bridge, HappeningItem, LiveItem, Nav, Page, RecordingItem};
use crate::app::{App, Bridge, HappeningItem, LiveItem, Page, RecordingItem};
use crate::vm;
use crate::vm::social::{event_when, plain};
@@ -234,9 +234,7 @@ impl App {
match target {
Happening::Event(session, _) => {
self.select_server(session);
if let Some(ui) = self.ui.upgrade() {
ui.global::<Nav>().invoke_show(Page::Events);
}
self.navigate(|nav| nav.invoke_show(Page::Events));
}
Happening::News(session) => self.show_server(session),
}
+11
View File
@@ -180,6 +180,17 @@ mod tests {
assert_eq!(lru.get_or_load("none", || None), None);
}
#[test]
fn pictures_decode() {
let mut png = Vec::new();
let mut encoder = png::Encoder::new(&mut png, 4, 2);
encoder.set_color(png::ColorType::Rgba);
encoder.set_depth(png::BitDepth::Eight);
encoder.write_header().unwrap().write_image_data(&[200; 32]).unwrap();
assert_eq!(picture("test:4x2", &png).size().width, 4);
assert_eq!(picture("test:junk", b"not a picture").size().width, 0);
}
#[test]
fn emoji_images_decode() {
let image = emoji("1f600");
+1 -3
View File
@@ -391,9 +391,7 @@ impl App {
later(move |app| app.stored_dm(&uid, page.unwrap_or_default()));
});
}
if let Some(ui) = self.ui.upgrade() {
ui.global::<Nav>().invoke_show(Page::Messages);
}
self.navigate(|nav| nav.invoke_show(Page::Messages));
self.refresh_chats();
}
+16 -13
View File
@@ -576,9 +576,18 @@ impl App {
if self.current != Some(session) {
self.select_server(session);
}
if let Some(ui) = self.ui.upgrade() {
ui.global::<Nav>().invoke_show(Page::Server);
}
self.navigate(|nav| nav.invoke_show(Page::Server));
}
/// Navigate after the current callback: `Nav`'s functions call back
/// into the app (`Bridge.open-*`), which is borrowed now.
pub(crate) fn navigate(&self, f: impl FnOnce(&Nav) + Send + 'static) {
let weak = self.ui.clone();
let _ = slint::invoke_from_event_loop(move || {
if let Some(ui) = weak.upgrade() {
f(&ui.global::<Nav>());
}
});
}
/// The pending watch (see [`Self::watch_person`]) once its stream shows.
@@ -700,16 +709,12 @@ impl App {
NoticeTarget::Dm(session, uid) => self.open_dm_with(Some(session), &uid),
NoticeTarget::Event(session, _) => {
self.select_server(session);
if let Some(ui) = self.ui.upgrade() {
ui.global::<Nav>().invoke_show(Page::Events);
}
self.navigate(|nav| nav.invoke_show(Page::Events));
}
NoticeTarget::Contact(uid) => {
self.social.selected = Some(uid);
self.refresh_people();
if let Some(ui) = self.ui.upgrade() {
ui.global::<Nav>().invoke_show(Page::Friends);
}
self.navigate(|nav| nav.invoke_show(Page::Friends));
}
}
}
@@ -1090,8 +1095,6 @@ impl App {
else {
return;
};
let Some(ui) = self.ui.upgrade() else { return };
let nav = ui.global::<Nav>();
match found {
Found::Server(id) => self.show_server(id),
Found::Channel(id, channel) => {
@@ -1109,9 +1112,9 @@ impl App {
Found::Contact(uid) => {
self.social.selected = Some(uid);
self.refresh_people();
nav.invoke_show(Page::Friends);
self.navigate(|nav| nav.invoke_show(Page::Friends));
}
Found::Setting(section) => nav.invoke_open_settings(section),
Found::Setting(section) => self.navigate(move |nav| nav.invoke_open_settings(section)),
}
}
}