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 bea6b335fa
commit 6962074326
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)),
}
}
}
+42 -4
View File
@@ -202,6 +202,37 @@ component FileCard inherits Rectangle {
}
}
// A picture a message links, shown inline (downloaded into memory); a
// click opens it larger.
component ImageCard inherits Rectangle {
in property <int> key;
in property <FileItem> file;
// As wide as the column allows, up to 520 px, keeping the picture's
// shape (at most 340 px high).
property <float> ratio: file.preview.height > 0 ? file.preview.width / file.preview.height : 1.6;
max-width: min(520px, 340px * ratio);
preferred-width: self.max-width;
height: min(self.width, self.max-width) / ratio;
border-radius: Theme.radius-lg;
clip: true;
background: Theme.surface-2;
border-width: 1px;
border-color: touch.has-hover ? Theme.border-strong : Theme.border;
accessible-role: AccessibleRole.image;
accessible-label: file.name;
accessible-action-default => { Nav.open-picture(root.key, root.file.index); }
Image {
width: parent.width;
height: parent.height;
source: root.file.preview;
image-fit: cover;
}
touch := TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => { Nav.open-picture(root.key, root.file.index); }
}
}
// Quick reactions, pin and "start a topic" on a hovered message.
component MessageActions inherits Rectangle {
in property <int> key;
@@ -353,10 +384,17 @@ export component MessageRow inherits Rectangle {
padding-top: Theme.space-2;
padding-bottom: Theme.space-1;
spacing: Theme.space-2;
for file in line.files: FileCard {
key: line.key;
file: file;
max-width: 440px;
for file in line.files: HorizontalLayout {
alignment: start;
if file.preview.width > 0: ImageCard {
key: line.key;
file: file;
}
if file.preview.width == 0: FileCard {
key: line.key;
file: file;
max-width: 440px;
}
}
}
if line.reactions.length > 0: VerticalLayout {