events::apply(state, host, event) changes the AppState for an engine Event and returns an Update: the parts to draw again (Refresh, each once), the status line, the engine commands, what to keep (Persist), pictures to decode again, the password dialog, notices for the bell, the chats that changed, a stream to watch. Host is what a transition asks while it runs (is the chat on screen, the store's read markers, the preview limit); the Slint client answers it in host.rs and carries the update out there, so App::handle_event is social_event, apply_event and social_refresh. The chat transitions (tabs, messages, what is read, pins and topics, files), the pictures linked in chats, the server's name, icon and gateway, joining again and the password prompt, the last place of voice and the stored volumes moved with it; Spot, the notice types, own_uids and peer_name moved to the view model crate. Update::rest hands back the events whose state is not in the AppState yet (the streams we share and watch, the studio's stream, a setting that changed); the friends, pokes and offline messages are still looked at by social.rs before and after. The vm tests replay tapes of events against a fake Host. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
49 lines
2.0 KiB
Rust
49 lines
2.0 KiB
Rust
//! Pictures linked in chat, shown inline: a link to a PNG, JPEG, GIF or
|
|
//! WebP file (by name) up to `ui.image_preview_kb` is downloaded into
|
|
//! memory once (`Command::DownloadChatFile` with `DownloadTo::Memory`,
|
|
//! voice connections only) and decoded once into the image cache
|
|
//! (`images.rs`); the chat shows it as a picture card, and a click opens
|
|
//! it larger. A picture on the web a message shows (`[img]`) comes the way
|
|
//! banners do, into the engine's cache (`Command::FetchPicture`, up to the
|
|
//! same size, only with `cache.fetch_images`), and until it is there the
|
|
//! message shows its address.
|
|
|
|
use std::borrow::Cow;
|
|
|
|
use crate::app::App;
|
|
use crate::bind::convert;
|
|
use crate::vm;
|
|
|
|
impl App {
|
|
/// Download the pictures linked in the current chat of `session` that
|
|
/// are not there yet ([`vm::previews::fetch_previews`]).
|
|
pub(crate) fn fetch_previews(&mut self, session: i64) {
|
|
self.transition(|state, cx| vm::previews::fetch_previews(state, cx, session));
|
|
}
|
|
|
|
/// The picture of link `index` of a message of the current chat (its
|
|
/// files, then its pictures on the web), for the large view.
|
|
pub(crate) fn open_preview(&self, key: i32, index: i32) -> slint::Image {
|
|
let Some(view) = self.view() else { return slint::Image::default() };
|
|
let Some(tab) = view.tabs.get(view.current_tab) else { return slint::Image::default() };
|
|
let message = match tab.message(key) {
|
|
Some(message) => Cow::Borrowed(&message.message),
|
|
// A line of the server.
|
|
None => match vm::chat::server_text(view, tab, key) {
|
|
Some(text) => Cow::Owned(vm::chat::server_message("", text)),
|
|
None => return slint::Image::default(),
|
|
},
|
|
};
|
|
let index = index.max(0) as usize;
|
|
match message.file_refs().get(index) {
|
|
Some(file) => {
|
|
vm::previews::image_of(view, file).map(|i| convert::image(&i)).unwrap_or_default()
|
|
}
|
|
None => vm::chat::picture_link(&message, index)
|
|
.and_then(|url| view.pictures.get(&url))
|
|
.map(|path| crate::images::file(path))
|
|
.unwrap_or_default(),
|
|
}
|
|
}
|
|
}
|