Split the social controller: the friends, the bell, the search and the social events into voelin-ui-vm
social/logic.rs now has the contacts as rows (contact_item, people), the buttons of a contact and what they ask the window to do next, the bell (notify, the rows, read, clear, open), the search with what each result opens, and what an engine event does to the friends, the pokes, the offline messages and the notices (event). events::handle runs that first, then events::apply, so a front end has one entry point; Social<D> is the state those keep, with what the messages page keeps as D for now. Refresh got people, conversations and dm, the host got dm_shown and now_ms, and Persist.Settings pages are told apart from the new notices. The Slint side (social/bind.rs) writes the Bridge, shows the desktop toasts and navigates. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
52e39f0b5a
commit
2d6cbf66af
12 files changed
+2137
-1063
No files matched your search
@@ -1,15 +1,19 @@
|
||||
//! What the engine's events do to the client's state. [`apply`] takes an
|
||||
//! [`Event`], changes the [`AppState`] and returns an [`Update`]: what to
|
||||
//! draw again, the status line, the commands for the engine, what to keep.
|
||||
//! A front end calls it for every event and then does what the update says;
|
||||
//! it has no dispatch of its own, so the Slint client and a GPUI one change
|
||||
//! the state the same way.
|
||||
//! What the engine's events do to the client's state. [`handle`] takes an
|
||||
//! [`Event`], changes the [`AppState`] and the [`Social`] state and returns
|
||||
//! an [`Update`]: what to draw again, the status line, the commands for the
|
||||
//! engine, what to keep. A front end calls it for every event and then does
|
||||
//! what the update says; it has no dispatch of its own, so the Slint client
|
||||
//! and a GPUI one change the state the same way. [`apply`] is the part that
|
||||
//! changes the [`AppState`] alone; [`handle`] first lets
|
||||
//! [`crate::social::logic::event`] look at the event (the friends, the
|
||||
//! pokes, the notices and the offline messages), which has to see the state
|
||||
//! as it was before the event.
|
||||
//!
|
||||
//! In [`Update::rest`] come back the events whose state is not in the
|
||||
//! [`AppState`]: the Stream Studio's stream (`Host::studio_streams_to`), a
|
||||
//! setting that changed (the settings service), and the friends, pokes and
|
||||
//! offline messages that `social.rs` of the Slint client keeps. They move
|
||||
//! here with their areas (docs/ui.md, "Controllers still to split").
|
||||
//! setting that changed (the settings service), and the offline messages
|
||||
//! and their requests, which the messages page keeps (docs/ui.md,
|
||||
//! "Controllers still to split").
|
||||
|
||||
mod gateway;
|
||||
|
||||
@@ -25,13 +29,34 @@ use crate::host::{Cx, Host, Persist, Update};
|
||||
use crate::previews::fetch_previews;
|
||||
use crate::servers::{AfterConnect, JoinStep, after_connect, join_password};
|
||||
use crate::settings::LastVoice;
|
||||
use crate::social::logic::Social;
|
||||
use crate::state::{AppState, Lines, SessionView};
|
||||
use crate::streams::logic as streams;
|
||||
|
||||
/// Apply an event to the state; see the [module](self).
|
||||
/// Apply an event to the [`AppState`]; see the [module](self).
|
||||
pub fn apply<L: Lines>(state: &mut AppState<L>, host: &dyn Host, event: Event) -> Update {
|
||||
let mut cx = Cx::new(host);
|
||||
dispatch(state, &mut cx, event);
|
||||
finish(state, cx)
|
||||
}
|
||||
|
||||
/// Take an event in: what the social screens make of it first
|
||||
/// ([`crate::social::logic::event`]), then [`apply`]. The one entry point
|
||||
/// of a front end.
|
||||
pub fn handle<L: Lines, D>(
|
||||
state: &mut AppState<L>,
|
||||
social: &mut Social<D>,
|
||||
host: &dyn Host,
|
||||
event: Event,
|
||||
) -> Update {
|
||||
let mut cx = Cx::new(host);
|
||||
crate::social::logic::event(state, social, &mut cx, &event);
|
||||
dispatch(state, &mut cx, event);
|
||||
finish(state, cx)
|
||||
}
|
||||
|
||||
/// The status line shows what the update says.
|
||||
fn finish<L>(state: &mut AppState<L>, cx: Cx<'_>) -> Update {
|
||||
if let Some(text) = &cx.update.status {
|
||||
state.status.clone_from(text);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,15 @@ pub trait Host {
|
||||
/// Pictures on the web are fetched and shown (`cache.fetch_images`).
|
||||
fn fetch_images(&self) -> bool;
|
||||
|
||||
/// The private chat with this peer (unique id) of this session is on
|
||||
/// screen, in the messages page.
|
||||
fn dm_shown(&self, session: i64, uid: &str) -> bool;
|
||||
|
||||
/// Now, in milliseconds since the epoch.
|
||||
fn now_ms(&self) -> i64 {
|
||||
crate::social::now_ms()
|
||||
}
|
||||
|
||||
/// How far the chats of a server were read, from the store.
|
||||
fn chat_reads(&self, server_uid: &str) -> Result<Vec<(StoredTarget, ChatRead)>, String>;
|
||||
|
||||
@@ -79,6 +88,13 @@ pub struct Refresh {
|
||||
pub events: bool,
|
||||
/// The gateway pages of the settings.
|
||||
pub gateways: bool,
|
||||
/// The friends page, home's friends and activity, the block list.
|
||||
pub people: bool,
|
||||
/// The lists of direct messages and the offline messages (asked for
|
||||
/// again when a voice connection came up).
|
||||
pub conversations: bool,
|
||||
/// The peer card of the open direct message.
|
||||
pub dm: bool,
|
||||
}
|
||||
|
||||
impl Refresh {
|
||||
@@ -94,6 +110,9 @@ impl Refresh {
|
||||
home: true,
|
||||
events: true,
|
||||
gateways: true,
|
||||
people: true,
|
||||
conversations: true,
|
||||
dm: true,
|
||||
};
|
||||
|
||||
/// Whether nothing is to be drawn.
|
||||
@@ -279,6 +298,10 @@ pub(crate) mod testing {
|
||||
/// The session the Stream Studio streams to.
|
||||
pub(crate) studio: Option<i64>,
|
||||
pub(crate) limit: u64,
|
||||
/// The private chat on screen: session and peer.
|
||||
pub(crate) dm: Option<(i64, String)>,
|
||||
/// What time it is.
|
||||
pub(crate) now: Cell<i64>,
|
||||
/// What the store has: server unique id, its chats' reads.
|
||||
pub(crate) reads: HashMap<String, Vec<(StoredTarget, ChatRead)>>,
|
||||
/// What was stored.
|
||||
@@ -314,6 +337,14 @@ pub(crate) mod testing {
|
||||
false
|
||||
}
|
||||
|
||||
fn dm_shown(&self, session: i64, uid: &str) -> bool {
|
||||
self.dm.as_ref().is_some_and(|(s, u)| *s == session && u == uid)
|
||||
}
|
||||
|
||||
fn now_ms(&self) -> i64 {
|
||||
self.now.get()
|
||||
}
|
||||
|
||||
fn chat_reads(&self, server_uid: &str) -> Result<Vec<(StoredTarget, ChatRead)>, String> {
|
||||
Ok(self.reads.get(server_uid).cloned().unwrap_or_default())
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -3,6 +3,8 @@
|
||||
//! `vm::bbcode`), mentions, event dates, a poke's message, the private
|
||||
//! chats of the home sidebar; pure, so they are tested here.
|
||||
|
||||
pub mod logic;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use chrono::{DateTime, Local, NaiveDateTime, TimeZone};
|
||||
@@ -11,6 +13,11 @@ use voelin_model::{ChatMessage, ChatTarget};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Now, in milliseconds since the epoch.
|
||||
pub fn now_ms() -> i64 {
|
||||
chrono::Utc::now().timestamp_millis()
|
||||
}
|
||||
|
||||
/// What a notification of the bell is about.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum NoticeKind {
|
||||
@@ -657,16 +657,6 @@ impl App {
|
||||
self.page_setting_changed(key);
|
||||
}
|
||||
|
||||
/// An engine event. What it does to the state is in
|
||||
/// `voelin_ui_vm::events::apply`; the window, the engine and the store
|
||||
/// follow what that says ([`App::perform`]). The friends, pokes and offline
|
||||
/// messages (`social.rs`) look at it before and after.
|
||||
pub(crate) fn handle_event(&mut self, event: Event) {
|
||||
let touched = self.social_event(&event);
|
||||
self.apply_event(event);
|
||||
self.social_refresh(touched);
|
||||
}
|
||||
|
||||
/// Once a second.
|
||||
fn tick(&mut self) {
|
||||
self.tick_streams();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The home page (design mockup 01): where we were with voice last, live
|
||||
//! streams on our servers, what is happening there (events, scheduled
|
||||
//! streams, server news), and the Library of recordings and clips.
|
||||
//! Friends and the unread mentions are in `social.rs`, the recent chats in
|
||||
//! Friends and the unread mentions are in `social/`, the recent chats in
|
||||
//! `messages.rs`.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@@ -10,8 +10,9 @@ use voelin_core::Event;
|
||||
use voelin_core::settings::{AUDIO, CACHE_FETCH_IMAGES, Settings};
|
||||
use voelin_store::{ChatRead, ChatTarget as StoredTarget, Store};
|
||||
|
||||
use crate::app::{App, AppState, Bridge, MainWindow, Nav};
|
||||
use crate::app::{App, AppState, Bridge, MainWindow, Nav, Page};
|
||||
use crate::settings::{CLIENT_PLAYBACK, UI_IMAGE_PREVIEW_KB};
|
||||
use crate::social::Social;
|
||||
use crate::studio::StudioState;
|
||||
use crate::vm::host::{Cx, Host, PasswordPrompt, Persist, Refresh, Update};
|
||||
|
||||
@@ -20,6 +21,8 @@ use crate::vm::host::{Cx, Host, PasswordPrompt, Persist, Refresh, Update};
|
||||
pub(crate) struct SlintHost<'a> {
|
||||
pub demo_ui: bool,
|
||||
pub watching: bool,
|
||||
/// The private chat the messages page has open: session and peer.
|
||||
pub dm: Option<(i64, String)>,
|
||||
pub ui: &'a slint::Weak<MainWindow>,
|
||||
pub store: &'a Store,
|
||||
pub prefs: &'a Settings,
|
||||
@@ -55,6 +58,11 @@ impl Host for SlintHost<'_> {
|
||||
self.prefs.get(&CACHE_FETCH_IMAGES)
|
||||
}
|
||||
|
||||
fn dm_shown(&self, session: i64, uid: &str) -> bool {
|
||||
self.dm.as_ref().is_some_and(|(s, u)| *s == session && u == uid)
|
||||
&& self.ui.upgrade().is_some_and(|ui| ui.global::<Nav>().get_page() == Page::Messages)
|
||||
}
|
||||
|
||||
fn chat_reads(&self, server_uid: &str) -> Result<Vec<(StoredTarget, ChatRead)>, String> {
|
||||
self.store.chat_reads(server_uid).map_err(|e| e.to_string())
|
||||
}
|
||||
@@ -72,21 +80,34 @@ impl Host for SlintHost<'_> {
|
||||
impl App {
|
||||
/// Run `f` with the state and the host, and return what it returns.
|
||||
pub(crate) fn with_host<R>(&mut self, f: impl FnOnce(&mut AppState, &SlintHost<'_>) -> R) -> R {
|
||||
self.with_social(|state, _, host| f(state, host))
|
||||
}
|
||||
|
||||
/// Run `f` with the state, the social state and the host.
|
||||
pub(crate) fn with_social<R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut AppState, &mut Social, &SlintHost<'_>) -> R,
|
||||
) -> R {
|
||||
let host = SlintHost {
|
||||
demo_ui: self.demo_ui,
|
||||
watching: self.state.watch.is_some(),
|
||||
dm: self.social.dm.open.as_ref().and_then(|open| {
|
||||
open.session.filter(|_| open.mail.is_none()).map(|s| (s, open.uid.clone()))
|
||||
}),
|
||||
ui: &self.ui,
|
||||
store: &self.store,
|
||||
prefs: &self.prefs,
|
||||
studio: &self.studio,
|
||||
};
|
||||
f(&mut self.state, &host)
|
||||
f(&mut self.state, &mut self.social, &host)
|
||||
}
|
||||
|
||||
/// An engine event: the state changes in `voelin-ui-vm`
|
||||
/// ([`crate::vm::events::apply`]), then the update is carried out.
|
||||
pub(crate) fn apply_event(&mut self, event: Event) {
|
||||
let update = self.with_host(|state, host| crate::vm::events::apply(state, host, event));
|
||||
/// An engine event: what it does to the state is in `voelin-ui-vm`
|
||||
/// ([`crate::vm::events::handle`]), then the update is carried out.
|
||||
pub(crate) fn handle_event(&mut self, event: Event) {
|
||||
let update = self.with_social(|state, social, host| {
|
||||
crate::vm::events::handle(state, social, host, event)
|
||||
});
|
||||
self.perform(update);
|
||||
}
|
||||
|
||||
@@ -102,6 +123,21 @@ impl App {
|
||||
result
|
||||
}
|
||||
|
||||
/// Like [`App::transition`], for a transition that changes the social
|
||||
/// state too.
|
||||
pub(crate) fn social_transition<R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut AppState, &mut Social, &mut Cx<'_>) -> R,
|
||||
) -> R {
|
||||
let (result, update) = self.with_social(|state, social, host| {
|
||||
let mut cx = Cx::new(host);
|
||||
let result = f(state, social, &mut cx);
|
||||
(result, cx.update)
|
||||
});
|
||||
self.perform(update);
|
||||
result
|
||||
}
|
||||
|
||||
/// Do what a transition asked for: tell the engine, keep what is to be
|
||||
/// kept, draw what changed, and hand the rest back to the code that
|
||||
/// still owns it.
|
||||
@@ -227,7 +263,7 @@ impl App {
|
||||
}
|
||||
|
||||
/// Draw the parts of the window a transition changed.
|
||||
pub(crate) fn refresh_parts(&self, parts: Refresh) {
|
||||
pub(crate) fn refresh_parts(&mut self, parts: Refresh) {
|
||||
if parts.servers {
|
||||
self.refresh_servers();
|
||||
}
|
||||
@@ -249,9 +285,19 @@ impl App {
|
||||
if parts.member_card {
|
||||
self.refresh_member_card();
|
||||
}
|
||||
if parts.people {
|
||||
self.refresh_people();
|
||||
}
|
||||
if parts.conversations {
|
||||
self.ask_inboxes();
|
||||
self.refresh_chats();
|
||||
}
|
||||
if parts.home {
|
||||
self.refresh_home();
|
||||
}
|
||||
if parts.dm {
|
||||
self.refresh_dm();
|
||||
}
|
||||
if parts.events {
|
||||
self.refresh_events();
|
||||
}
|
||||
@@ -272,8 +318,14 @@ impl App {
|
||||
Event::StreamViewers { session, viewers } if self.studio_streams_to(session as i64) => {
|
||||
self.studio_viewers(viewers);
|
||||
}
|
||||
// The rest (friends, pokes, offline messages) is looked at by
|
||||
// social.rs, before and after.
|
||||
// The messages page keeps the offline messages (messages.rs).
|
||||
Event::OfflineMessages { result: Err(e), .. } => debug!("offline messages: {e}"),
|
||||
Event::OfflineMessage { session, result, .. } => {
|
||||
self.mail_arrived(session as i64, result);
|
||||
}
|
||||
Event::RequestDone { session, request, result } => {
|
||||
self.request_done(session as i64, request, result);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use voelin_core::{Command, HistoryMessage, OfflineMessage, OfflineMessageInfo, V
|
||||
use voelin_model::ChatTarget;
|
||||
use voelin_store::PageQuery;
|
||||
|
||||
use crate::app::{App, Bridge, Nav, Page, SessionView, later};
|
||||
use crate::app::{App, Bridge, Page, SessionView, later};
|
||||
use crate::vm;
|
||||
use crate::vm::bridge::{ConversationItem, DmPeer, FileItem, OfflineForm};
|
||||
use crate::vm::social::{ChatRef, ago, list_time, matches, plain, preview};
|
||||
@@ -486,18 +486,6 @@ impl App {
|
||||
self.refresh_dm();
|
||||
}
|
||||
|
||||
/// Whether the private chat with `uid` in `session` is on screen.
|
||||
pub(crate) fn dm_shown(&self, session: i64, uid: &str) -> bool {
|
||||
let page = self.ui.upgrade().map(|ui| ui.global::<Nav>().get_page());
|
||||
page == Some(Page::Messages)
|
||||
&& self
|
||||
.social
|
||||
.dm
|
||||
.open
|
||||
.as_ref()
|
||||
.is_some_and(|o| o.mail.is_none() && o.uid == uid && o.session == Some(session))
|
||||
}
|
||||
|
||||
/// Who the open conversation is with, and what can be done.
|
||||
pub(crate) fn refresh_dm(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
|
||||
@@ -1,993 +0,0 @@
|
||||
//! People across servers: contacts and where they are (Friends, home), the
|
||||
//! bell's notifications, pokes, and the search (Ctrl+K). The direct
|
||||
//! messages are in `messages.rs`, the home page in `home.rs`, a server's
|
||||
//! events in `events.rs`.
|
||||
//!
|
||||
//! Every contact's whereabouts come from the sessions' presence (voice,
|
||||
//! gateway or query), so they are current for friends and the others alike;
|
||||
//! [`Event::FriendPresence`] adds when a friend came online, for "12m ago"
|
||||
//! and the notification.
|
||||
|
||||
use slint::ComponentHandle;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use tracing::debug;
|
||||
use voelin_core::{
|
||||
Command, Contact, Event, FriendSpot, HistoryMessage, HistorySource, Relation, VoiceState,
|
||||
};
|
||||
use voelin_model::{ChatMessage, ChatTarget};
|
||||
|
||||
use crate::app::{App, Bridge, Nav, Page, SettingsSection};
|
||||
use crate::bind::rows::Rows;
|
||||
use crate::settings::{
|
||||
NOTIFY_EVENTS, NOTIFY_FRIENDS, NOTIFY_MENTIONS, NOTIFY_MESSAGES, NOTIFY_POKES, NotifyLevel,
|
||||
};
|
||||
use crate::vm;
|
||||
use crate::vm::bridge::{ContactItem, NoticeItem, SearchItem};
|
||||
use crate::vm::social::{ago, matches, mentions, plain};
|
||||
|
||||
pub(crate) use vm::social::{NoticeKind, NoticeTarget, Poke, Spot};
|
||||
|
||||
/// A notification of the bell.
|
||||
pub(crate) struct Notice {
|
||||
pub key: i32,
|
||||
pub kind: NoticeKind,
|
||||
pub title: String,
|
||||
pub body: String,
|
||||
pub ts_ms: i64,
|
||||
pub unread: bool,
|
||||
pub target: NoticeTarget,
|
||||
/// Whose avatar (initials from the name).
|
||||
pub name: String,
|
||||
pub uid: Option<String>,
|
||||
}
|
||||
|
||||
/// What a search result opens.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) enum Found {
|
||||
Server(i64),
|
||||
Channel(i64, u64),
|
||||
Person(i64, u16, Option<String>),
|
||||
Contact(String),
|
||||
Setting(SettingsSection),
|
||||
}
|
||||
|
||||
/// State of the home, friends, messages, bell and search screens.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Social {
|
||||
/// Friends that are somewhere ([`Event::FriendPresence`]), and since when
|
||||
/// (this run).
|
||||
pub online_since: HashMap<String, i64>,
|
||||
pub pokes: Vec<Poke>,
|
||||
/// Newest first.
|
||||
pub notices: Vec<Notice>,
|
||||
pub next_notice: i32,
|
||||
/// Friends page: the tab (online, all, blocked), the search, the
|
||||
/// selected contact.
|
||||
pub friends_tab: i32,
|
||||
pub contact_filter: String,
|
||||
pub selected: Option<String>,
|
||||
/// What the search results open.
|
||||
pub found: Vec<Found>,
|
||||
/// The direct messages (`messages.rs`).
|
||||
pub dm: crate::messages::Dms,
|
||||
}
|
||||
|
||||
/// The models of these screens, set on the Bridge once.
|
||||
pub(crate) struct SocialModels {
|
||||
pub friends_online: Rows<vm::bridge::ContactItem>,
|
||||
pub friend_activity: Rows<vm::bridge::ContactItem>,
|
||||
pub contacts: Rows<vm::bridge::ContactItem>,
|
||||
pub blocked: Rows<vm::bridge::ContactItem>,
|
||||
pub live: Rows<vm::bridge::LiveItem>,
|
||||
pub recent: Rows<vm::bridge::ConversationItem>,
|
||||
pub sidebar_dms: Rows<vm::bridge::ConversationItem>,
|
||||
pub conversations: Rows<vm::bridge::ConversationItem>,
|
||||
pub dm_lines: Rows<vm::bridge::ChatLine>,
|
||||
pub happenings: Rows<vm::bridge::HappeningItem>,
|
||||
pub recordings: Rows<vm::bridge::RecordingItem>,
|
||||
pub notices: Rows<vm::bridge::NoticeItem>,
|
||||
pub mentions: Rows<vm::bridge::NoticeItem>,
|
||||
pub search: Rows<vm::bridge::SearchItem>,
|
||||
pub events: Rows<vm::bridge::EventItem>,
|
||||
}
|
||||
|
||||
impl SocialModels {
|
||||
pub fn new(bridge: &Bridge) -> Self {
|
||||
let m = Self {
|
||||
friends_online: Rows::default(),
|
||||
friend_activity: Rows::default(),
|
||||
contacts: Rows::default(),
|
||||
blocked: Rows::default(),
|
||||
live: Rows::default(),
|
||||
recent: Rows::default(),
|
||||
sidebar_dms: Rows::default(),
|
||||
conversations: Rows::default(),
|
||||
dm_lines: Rows::default(),
|
||||
happenings: Rows::default(),
|
||||
recordings: Rows::default(),
|
||||
notices: Rows::default(),
|
||||
mentions: Rows::default(),
|
||||
search: Rows::default(),
|
||||
events: Rows::default(),
|
||||
};
|
||||
bridge.set_friends_online(m.friends_online.model());
|
||||
bridge.set_friend_activity(m.friend_activity.model());
|
||||
bridge.set_contacts(m.contacts.model());
|
||||
bridge.set_blocked(m.blocked.model());
|
||||
bridge.set_live_rooms(m.live.model());
|
||||
bridge.set_recent_chats(m.recent.model());
|
||||
bridge.set_sidebar_dms(m.sidebar_dms.model());
|
||||
bridge.set_conversations(m.conversations.model());
|
||||
bridge.set_dm_messages(m.dm_lines.model());
|
||||
bridge.set_happenings(m.happenings.model());
|
||||
bridge.set_recordings(m.recordings.model());
|
||||
bridge.set_notifications(m.notices.model());
|
||||
bridge.set_home_mentions(m.mentions.model());
|
||||
bridge.set_search_results(m.search.model());
|
||||
bridge.set_events(m.events.model());
|
||||
m
|
||||
}
|
||||
}
|
||||
|
||||
/// Which screens an event touched.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub(crate) struct Touched {
|
||||
pub people: bool,
|
||||
pub chats: bool,
|
||||
pub home: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn now_ms() -> i64 {
|
||||
chrono::Utc::now().timestamp_millis()
|
||||
}
|
||||
|
||||
/// The settings pages a search finds, with words that lead to them.
|
||||
const SETTING_PAGES: [(&str, &str, SettingsSection); 11] = [
|
||||
("My Account", "account identity unique id nickname myteamspeak", SettingsSection::Account),
|
||||
("Profiles", "identities import export security level", SettingsSection::Profiles),
|
||||
("Appearance", "theme dark light text size font layout", SettingsSection::Appearance),
|
||||
(
|
||||
"Voice & Video",
|
||||
"microphone speakers output input camera noise echo gain volume quality",
|
||||
SettingsSection::Voice,
|
||||
),
|
||||
(
|
||||
"Streaming",
|
||||
"stream fps bitrate codec layers simulcast audio sources",
|
||||
SettingsSection::Streaming,
|
||||
),
|
||||
("Devices", "devices microphone speakers camera screen capture", SettingsSection::Devices),
|
||||
("Notifications", "notifications bell mentions pokes alerts", SettingsSection::Notifications),
|
||||
("Privacy & Safety", "privacy block blocked pokes messages crash", SettingsSection::Privacy),
|
||||
("Keybinds", "keybinds push to talk hotkey shortcut transmit", SettingsSection::Keybinds),
|
||||
("Integrations", "gateway integrations encoders ffmpeg admin", SettingsSection::Integrations),
|
||||
(
|
||||
"Advanced",
|
||||
"advanced srtp history cache logs settings experimental",
|
||||
SettingsSection::Advanced,
|
||||
),
|
||||
];
|
||||
|
||||
impl App {
|
||||
/// The avatar picture of someone by unique id, from any session.
|
||||
pub(crate) fn avatar_of(&self, uid: &str) -> vm::ImageRef {
|
||||
vm::social::avatar_of(&self.state, uid)
|
||||
}
|
||||
|
||||
/// A server's name: its bookmark's, else what the session calls it.
|
||||
pub(crate) fn server_name(&self, session: i64) -> String {
|
||||
vm::social::server_name(&self.state, session)
|
||||
}
|
||||
|
||||
/// Every session where the client with this unique id is, in bookmark
|
||||
/// order.
|
||||
pub(crate) fn spots_of(&self, uid: &str) -> Vec<Spot> {
|
||||
vm::social::spots_of(&self.state, uid)
|
||||
}
|
||||
|
||||
/// The title of what someone streams, if a directory or the voice
|
||||
/// connection says.
|
||||
fn stream_title(&self, spot: &Spot, uid: &str) -> Option<String> {
|
||||
let view = self.state.sessions.get(&spot.session)?;
|
||||
view.streams
|
||||
.iter()
|
||||
.find(|s| s.streamer == spot.client)
|
||||
.map(|s| s.name.clone())
|
||||
.or_else(|| {
|
||||
view.extra.directory.iter().find(|e| e.streamer.uid == uid).map(|e| e.title.clone())
|
||||
})
|
||||
.filter(|t| !t.is_empty())
|
||||
}
|
||||
|
||||
/// A contact for the screens.
|
||||
pub(crate) fn contact_item(&self, contact: &Contact) -> ContactItem {
|
||||
let spots = self.spots_of(&contact.uid);
|
||||
let first = spots.first();
|
||||
let name = if contact.nickname.is_empty() {
|
||||
first
|
||||
.map(|s| self.state.sessions[&s.session].nickname(s.client))
|
||||
.unwrap_or_else(|| contact.uid.chars().take(8).collect())
|
||||
} else {
|
||||
contact.nickname.clone()
|
||||
};
|
||||
let streaming = spots.iter().find(|s| s.streaming);
|
||||
let status = match (first, streaming) {
|
||||
(_, Some(s)) => match self.stream_title(s, &contact.uid) {
|
||||
Some(title) => format!("Streaming {title}"),
|
||||
None => "Streaming".into(),
|
||||
},
|
||||
(Some(s), None) => match &s.away {
|
||||
Some(m) if !m.is_empty() => format!("Away: {m}"),
|
||||
Some(_) => "Away".into(),
|
||||
None if s.channel_title.is_empty() => "Online".into(),
|
||||
None => format!("In {}", s.channel_title),
|
||||
},
|
||||
(None, None) => "Offline".into(),
|
||||
};
|
||||
let place = match first {
|
||||
Some(s) => s.server.clone(),
|
||||
None if contact.last_seen_ms > 0 => match &contact.last_server {
|
||||
Some(server) => format!("Last seen {} on {server}", ago(contact.last_seen_ms)),
|
||||
None => format!("Last seen {}", ago(contact.last_seen_ms)),
|
||||
},
|
||||
None => String::new(),
|
||||
};
|
||||
let when = match first {
|
||||
Some(_) => {
|
||||
self.social.online_since.get(&contact.uid).map(|t| ago(*t)).unwrap_or_default()
|
||||
}
|
||||
None => ago(contact.last_seen_ms),
|
||||
};
|
||||
let since = chrono::DateTime::from_timestamp_millis(contact.added_ms)
|
||||
.filter(|_| contact.added_ms > 0)
|
||||
.map(|t| {
|
||||
format!("Contact since {}", t.with_timezone(&chrono::Local).format("%-d %b %Y"))
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let spot_texts: Vec<Arc<str>> = spots
|
||||
.iter()
|
||||
.map(|s| {
|
||||
if s.channel_title.is_empty() {
|
||||
s.server.clone().into()
|
||||
} else {
|
||||
format!("{} · {}", s.server, s.channel_title).into()
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
ContactItem {
|
||||
uid: contact.uid.clone().into(),
|
||||
name: name.clone().into(),
|
||||
initials: vm::avatar::initials(&name).into(),
|
||||
tint: vm::avatar::tint(&name),
|
||||
avatar: self.avatar_of(&contact.uid),
|
||||
relation: contact.relation.as_str().into(),
|
||||
online: first.is_some(),
|
||||
away: first.is_some_and(|s| s.away.is_some()),
|
||||
streaming: streaming.is_some(),
|
||||
status: status.into(),
|
||||
place: place.into(),
|
||||
when: when.into(),
|
||||
note: contact.note.clone().into(),
|
||||
volume: contact.volume * 100.0,
|
||||
muted: contact.muted,
|
||||
since: since.into(),
|
||||
spots: spot_texts,
|
||||
reachable: spots.iter().any(|s| s.voice),
|
||||
selected: self.social.selected.as_deref() == Some(contact.uid.as_str()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Contacts sorted for lists: online first (streaming, then present,
|
||||
/// then away), then by name.
|
||||
fn sorted_contacts(&self, items: &mut [ContactItem]) {
|
||||
items.sort_by_key(|c| {
|
||||
(!c.online, !c.streaming, c.away, &*c.relation != "friend", c.name.to_lowercase())
|
||||
});
|
||||
}
|
||||
|
||||
/// Friends page, home's friends and activity, the block list.
|
||||
pub(crate) fn refresh_people(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let m = &self.models.social;
|
||||
let mut all: Vec<ContactItem> =
|
||||
self.state.contacts.values().map(|c| self.contact_item(c)).collect();
|
||||
self.sorted_contacts(&mut all);
|
||||
let friends: Vec<ContactItem> =
|
||||
all.iter().filter(|c| &*c.relation == "friend").cloned().collect();
|
||||
let online: Vec<ContactItem> = friends.iter().filter(|c| c.online).cloned().collect();
|
||||
m.friends_online.sync(&online[..online.len().min(20)]);
|
||||
// Online friends first, then the others by when they were seen.
|
||||
let mut activity = friends.clone();
|
||||
activity.sort_by_key(|c| {
|
||||
let seen = self.state.contacts.get(c.uid.as_ref()).map_or(0, |c| c.last_seen_ms);
|
||||
let since = self.social.online_since.get(c.uid.as_ref()).copied().unwrap_or(0);
|
||||
(!c.online, !c.streaming, std::cmp::Reverse(if c.online { since } else { seen }))
|
||||
});
|
||||
m.friend_activity.sync(&activity[..activity.len().min(7)]);
|
||||
let blocked: Vec<ContactItem> =
|
||||
all.iter().filter(|c| &*c.relation == "blocked").cloned().collect();
|
||||
m.blocked.sync(&blocked);
|
||||
bridge.set_contacts_online(
|
||||
all.iter().filter(|c| c.online && &*c.relation != "blocked").count() as i32,
|
||||
);
|
||||
bridge.set_contacts_all(all.len() as i32);
|
||||
bridge.set_contacts_blocked(blocked.len() as i32);
|
||||
let filter = &self.social.contact_filter;
|
||||
let shown: Vec<ContactItem> = all
|
||||
.iter()
|
||||
.filter(|c| match self.social.friends_tab {
|
||||
0 => c.online && &*c.relation != "blocked",
|
||||
2 => &*c.relation == "blocked",
|
||||
_ => true,
|
||||
})
|
||||
.filter(|c| matches(filter, &[&c.name, &c.uid, &c.note]))
|
||||
.cloned()
|
||||
.collect();
|
||||
m.contacts.sync(&shown);
|
||||
let selected = self
|
||||
.social
|
||||
.selected
|
||||
.as_ref()
|
||||
.and_then(|uid| all.iter().find(|c| c.uid.as_ref() == uid))
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
bridge.set_contact(selected.into());
|
||||
}
|
||||
|
||||
pub(crate) fn friends_tab(&mut self, tab: i32) {
|
||||
self.social.friends_tab = tab;
|
||||
self.refresh_people();
|
||||
}
|
||||
|
||||
pub(crate) fn search_contacts(&mut self, text: String) {
|
||||
self.social.contact_filter = text;
|
||||
self.refresh_people();
|
||||
}
|
||||
|
||||
pub(crate) fn select_contact(&mut self, uid: String) {
|
||||
self.social.selected = (!uid.is_empty()).then_some(uid);
|
||||
self.refresh_people();
|
||||
}
|
||||
|
||||
/// Change a contact (or make one of someone we see).
|
||||
fn update_contact(&mut self, uid: &str, f: impl FnOnce(&mut Contact)) {
|
||||
let mut contact = self.state.contacts.get(uid).cloned().unwrap_or_else(|| {
|
||||
let mut c = Contact::new(uid);
|
||||
if let Some(s) = self.spots_of(uid).first() {
|
||||
c.nickname = self.state.sessions[&s.session].nickname(s.client);
|
||||
}
|
||||
c
|
||||
});
|
||||
f(&mut contact);
|
||||
self.state.contacts.insert(uid.to_owned(), contact.clone());
|
||||
if !self.demo_ui {
|
||||
self.engine.send(Command::SetContact { contact: Box::new(contact) });
|
||||
}
|
||||
self.refresh_people();
|
||||
self.refresh_member_card();
|
||||
self.refresh_dm();
|
||||
}
|
||||
|
||||
/// The buttons of a contact: "message", "poke", "join", "watch",
|
||||
/// "friend", "block", "neutral", "remove", "mute".
|
||||
pub(crate) fn contact_action(&mut self, uid: &str, action: &str) {
|
||||
let spots = self.spots_of(uid);
|
||||
let voice = spots.iter().find(|s| s.voice).cloned();
|
||||
match action {
|
||||
"message" => self.message_person(uid),
|
||||
"poke" => {
|
||||
let Some(s) = voice else {
|
||||
self.set_status("Connect with voice to a server they are on to poke them.");
|
||||
return;
|
||||
};
|
||||
self.ask_poke(s.session, s.client);
|
||||
}
|
||||
"join" => self.join_person(&spots),
|
||||
"watch" => self.watch_person(&spots),
|
||||
"friend" => self.update_contact(uid, |c| c.relation = Relation::Friend),
|
||||
"block" => self.update_contact(uid, |c| c.relation = Relation::Blocked),
|
||||
"neutral" => self.update_contact(uid, |c| c.relation = Relation::Neutral),
|
||||
"mute" => self.update_contact(uid, |c| c.muted = !c.muted),
|
||||
"remove" => {
|
||||
self.state.contacts.remove(uid);
|
||||
if self.social.selected.as_deref() == Some(uid) {
|
||||
self.social.selected = None;
|
||||
}
|
||||
if !self.demo_ui {
|
||||
self.engine.send(Command::RemoveContact { uid: uid.to_owned() });
|
||||
}
|
||||
self.refresh_people();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn contact_note(&mut self, uid: &str, note: String) {
|
||||
self.update_contact(uid, |c| c.note = note);
|
||||
self.set_status("Note saved");
|
||||
}
|
||||
|
||||
pub(crate) fn contact_volume(&mut self, uid: &str, percent: f32) {
|
||||
self.update_contact(uid, |c| c.volume = (percent / 100.0).max(0.0));
|
||||
}
|
||||
|
||||
/// Go to someone's channel: move there with voice, or connect to that
|
||||
/// server into it (`join_channel`, which asks for a password first).
|
||||
fn join_person(&mut self, spots: &[Spot]) {
|
||||
let Some(s) = spots.iter().find(|s| s.voice).or(spots.first()).cloned() else {
|
||||
self.set_status("They are not on any of your servers right now.");
|
||||
return;
|
||||
};
|
||||
self.show_server(s.session);
|
||||
self.join_channel(s.session, s.channel);
|
||||
}
|
||||
|
||||
/// Watch someone's stream: from any channel of a server we are on with
|
||||
/// voice (once the lookup brings it), else join them first and watch it
|
||||
/// when it shows.
|
||||
fn watch_person(&mut self, spots: &[Spot]) {
|
||||
let Some(s) = spots.iter().find(|s| s.streaming).cloned() else { return };
|
||||
self.show_server(s.session);
|
||||
if s.voice {
|
||||
self.watch_client(s.client);
|
||||
} else {
|
||||
self.state.pending_watch = Some((s.session, s.client));
|
||||
self.join_person(&[s]);
|
||||
}
|
||||
}
|
||||
|
||||
/// The server page of a session.
|
||||
pub(crate) fn show_server(&mut self, session: i64) {
|
||||
if self.state.current != Some(session) {
|
||||
self.select_server(session);
|
||||
}
|
||||
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 bell.
|
||||
|
||||
/// Add a notification as the kind's setting says.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn notify(
|
||||
&mut self,
|
||||
kind: NoticeKind,
|
||||
title: String,
|
||||
body: String,
|
||||
target: NoticeTarget,
|
||||
name: String,
|
||||
uid: Option<String>,
|
||||
) {
|
||||
let key = match kind {
|
||||
NoticeKind::Mention => &NOTIFY_MENTIONS,
|
||||
NoticeKind::Poke => &NOTIFY_POKES,
|
||||
NoticeKind::Message => &NOTIFY_MESSAGES,
|
||||
NoticeKind::Event => &NOTIFY_EVENTS,
|
||||
NoticeKind::Friend => &NOTIFY_FRIENDS,
|
||||
};
|
||||
let level = self.prefs.get(key);
|
||||
if level == NotifyLevel::Off {
|
||||
return;
|
||||
}
|
||||
// The sample data of VOELIN_DEMO_UI never reaches the desktop.
|
||||
if level == NotifyLevel::Desktop && !self.demo_ui {
|
||||
let n = voelin_platform::Notification {
|
||||
urgent: kind == NoticeKind::Poke || kind == NoticeKind::Message,
|
||||
..voelin_platform::Notification::new(title.clone(), body.clone())
|
||||
};
|
||||
self.engine.runtime().spawn(async move {
|
||||
if let Err(e) = voelin_platform::notify(&n).await {
|
||||
debug!("no desktop notification: {e}");
|
||||
}
|
||||
});
|
||||
}
|
||||
self.social.next_notice += 1;
|
||||
self.social.notices.insert(
|
||||
0,
|
||||
Notice {
|
||||
key: self.social.next_notice,
|
||||
kind,
|
||||
title,
|
||||
body,
|
||||
ts_ms: now_ms(),
|
||||
unread: true,
|
||||
target,
|
||||
name,
|
||||
uid,
|
||||
},
|
||||
);
|
||||
self.social.notices.truncate(100);
|
||||
self.refresh_notices();
|
||||
}
|
||||
|
||||
/// The bell's notices, and home's unread mentions (the newest three).
|
||||
pub(crate) fn refresh_notices(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let item = |n: &Notice| NoticeItem {
|
||||
key: n.key,
|
||||
kind: n.kind.name().into(),
|
||||
title: n.title.clone().into(),
|
||||
body: n.body.clone().into(),
|
||||
time: ago(n.ts_ms).into(),
|
||||
unread: n.unread,
|
||||
initials: vm::avatar::initials(&n.name).into(),
|
||||
tint: vm::avatar::tint(&n.name),
|
||||
avatar: n.uid.as_deref().map(|u| self.avatar_of(u)).unwrap_or_default(),
|
||||
};
|
||||
let notices = &self.social.notices;
|
||||
let items: Vec<NoticeItem> = notices.iter().map(item).collect();
|
||||
self.models.social.notices.sync(&items);
|
||||
let mentions: Vec<NoticeItem> = notices
|
||||
.iter()
|
||||
.filter(|n| n.unread && n.kind == NoticeKind::Mention)
|
||||
.take(3)
|
||||
.map(item)
|
||||
.collect();
|
||||
self.models.social.mentions.sync(&mentions);
|
||||
let unread = notices.iter().filter(|n| n.unread).count();
|
||||
ui.global::<Bridge>().set_notifications_unread(unread as i32);
|
||||
}
|
||||
|
||||
pub(crate) fn mark_notices_read(&mut self) {
|
||||
for n in &mut self.social.notices {
|
||||
n.unread = false;
|
||||
}
|
||||
self.refresh_notices();
|
||||
}
|
||||
|
||||
pub(crate) fn clear_notices(&mut self) {
|
||||
self.social.notices.clear();
|
||||
self.refresh_notices();
|
||||
}
|
||||
|
||||
/// Open what a notification is about.
|
||||
pub(crate) fn open_notice(&mut self, key: i32) {
|
||||
let Some(n) = self.social.notices.iter_mut().find(|n| n.key == key) else { return };
|
||||
n.unread = false;
|
||||
let target = n.target.clone();
|
||||
self.refresh_notices();
|
||||
match target {
|
||||
NoticeTarget::Chat(session, chat) => {
|
||||
self.show_server(session);
|
||||
self.open_chat(chat, true);
|
||||
}
|
||||
NoticeTarget::Dm(session, uid) => self.open_dm_with(Some(session), &uid),
|
||||
NoticeTarget::Event(session, _) => {
|
||||
self.select_server(session);
|
||||
self.navigate(|nav| nav.invoke_show(Page::Events));
|
||||
}
|
||||
NoticeTarget::Contact(uid) => {
|
||||
self.social.selected = Some(uid);
|
||||
self.refresh_people();
|
||||
self.navigate(|nav| nav.invoke_show(Page::Friends));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Our nickname in a session.
|
||||
fn own_nick(&self, session: i64) -> String {
|
||||
let view = self.state.sessions.get(&session);
|
||||
view.and_then(|v| v.state.own_client.map(|c| v.nickname(c)))
|
||||
.or_else(|| self.bookmark(session).map(|b| b.nickname.clone()))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Whether a message is ours.
|
||||
pub(crate) fn is_own(&self, session: i64, message: &ChatMessage) -> bool {
|
||||
vm::social::is_own(&self.state, session, message)
|
||||
}
|
||||
|
||||
/// A new chat message: a private message, or one that mentions us.
|
||||
fn chat_notice(&mut self, session: i64, message: &ChatMessage) {
|
||||
if message.blocked || self.is_own(session, message) {
|
||||
return;
|
||||
}
|
||||
let server = self.server_name(session);
|
||||
match &message.target {
|
||||
ChatTarget::Private(uid) => {
|
||||
if self.dm_shown(session, uid) {
|
||||
return;
|
||||
}
|
||||
self.notify(
|
||||
NoticeKind::Message,
|
||||
message.author_name.clone(),
|
||||
plain(&message.text),
|
||||
NoticeTarget::Dm(session, uid.clone()),
|
||||
message.author_name.clone(),
|
||||
Some(uid.clone()),
|
||||
);
|
||||
}
|
||||
target => {
|
||||
if !mentions(&message.text, &self.own_nick(session)) {
|
||||
return;
|
||||
}
|
||||
let place = match target {
|
||||
ChatTarget::Channel(cid) => self
|
||||
.state
|
||||
.sessions
|
||||
.get(&session)
|
||||
.and_then(|v| v.presence.channels.get(cid))
|
||||
.map(|c| format!("{} · {server}", vm::tree::channel_title(c).0))
|
||||
.unwrap_or(server),
|
||||
_ => server,
|
||||
};
|
||||
self.notify(
|
||||
NoticeKind::Mention,
|
||||
format!("{} mentioned you", message.author_name),
|
||||
format!("{} — {place}", plain(&message.text)),
|
||||
NoticeTarget::Chat(session, target.clone()),
|
||||
message.author_name.clone(),
|
||||
message.author_uid.clone(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Look at an event before the app handles it: notifications, pokes,
|
||||
/// friends' whereabouts, offline messages. Returns what to refresh after.
|
||||
pub(crate) fn social_event(&mut self, event: &Event) -> Touched {
|
||||
let mut touched = Touched::default();
|
||||
match event {
|
||||
Event::Presence { session, .. } => {
|
||||
let view = self.state.sessions.entry(*session as i64).or_default();
|
||||
if view.extra.presence_since == 0 {
|
||||
view.extra.presence_since = now_ms();
|
||||
}
|
||||
touched.people = true;
|
||||
touched.home = true;
|
||||
}
|
||||
Event::State { session, state } => {
|
||||
let id = *session as i64;
|
||||
let was = self.state.sessions.get(&id).map(|v| v.state.voice);
|
||||
if state.voice != VoiceState::Connected {
|
||||
if let Some(view) = self.state.sessions.get_mut(&id) {
|
||||
view.extra.inbox_asked = false;
|
||||
}
|
||||
} else if was != Some(VoiceState::Connected) {
|
||||
touched.chats = true;
|
||||
}
|
||||
touched.people = true;
|
||||
touched.home = true;
|
||||
}
|
||||
Event::ServerInfo { session, backend, .. } => {
|
||||
self.state.sessions.entry(*session as i64).or_default().extra.product =
|
||||
backend.product.clone();
|
||||
touched.people = true;
|
||||
touched.home = true;
|
||||
}
|
||||
Event::ContactsChanged { .. } | Event::AvatarReady { .. } => {
|
||||
touched.people = true;
|
||||
touched.home = true;
|
||||
touched.chats = true;
|
||||
}
|
||||
Event::StreamsChanged { .. } => {
|
||||
touched.home = true;
|
||||
touched.people = true;
|
||||
}
|
||||
Event::FriendPresence { uid, sessions } => self.friend_presence(uid, sessions),
|
||||
Event::Poke { session, from_uid, from_name, message, .. } => {
|
||||
let id = *session as i64;
|
||||
self.social.pokes.push(Poke {
|
||||
session: id,
|
||||
uid: from_uid.clone(),
|
||||
name: from_name.clone(),
|
||||
message: message.clone(),
|
||||
ts_ms: now_ms(),
|
||||
});
|
||||
let body = if message.is_empty() {
|
||||
format!("on {}", self.server_name(id))
|
||||
} else {
|
||||
message.clone()
|
||||
};
|
||||
let target = match from_uid {
|
||||
Some(uid) => NoticeTarget::Dm(id, uid.clone()),
|
||||
None => NoticeTarget::Chat(id, ChatTarget::Server),
|
||||
};
|
||||
self.notify(
|
||||
NoticeKind::Poke,
|
||||
format!("{from_name} poked you"),
|
||||
body,
|
||||
target,
|
||||
from_name.clone(),
|
||||
from_uid.clone(),
|
||||
);
|
||||
touched.chats = true;
|
||||
}
|
||||
Event::Chat { session, message } => {
|
||||
let id = *session as i64;
|
||||
if !self.state.sessions.get(&id).is_some_and(|v| v.has_history()) {
|
||||
self.chat_notice(id, message);
|
||||
touched.chats = true;
|
||||
}
|
||||
}
|
||||
Event::ChatHistory { session, target, messages, source, .. } => {
|
||||
let id = *session as i64;
|
||||
if *source == HistorySource::Live {
|
||||
let known: HashSet<i64> = self
|
||||
.state
|
||||
.sessions
|
||||
.get(&id)
|
||||
.and_then(|v| v.tabs.iter().find(|t| t.target == *target))
|
||||
.map(|t| t.messages.iter().map(|m| m.message.id).collect())
|
||||
.unwrap_or_default();
|
||||
let fresh: Vec<HistoryMessage> =
|
||||
messages.iter().filter(|m| !known.contains(&m.id)).cloned().collect();
|
||||
for m in &fresh {
|
||||
self.chat_notice(id, &m.message);
|
||||
}
|
||||
}
|
||||
touched.chats = true;
|
||||
}
|
||||
Event::OfflineMessages { session, result, .. } => {
|
||||
match result {
|
||||
Ok(list) => {
|
||||
self.state.sessions.entry(*session as i64).or_default().extra.inbox =
|
||||
list.clone();
|
||||
}
|
||||
Err(e) => debug!("offline messages: {e}"),
|
||||
}
|
||||
touched.chats = true;
|
||||
}
|
||||
Event::OfflineMessage { session, result, .. } => {
|
||||
self.mail_arrived(*session as i64, result.clone());
|
||||
touched.chats = true;
|
||||
}
|
||||
Event::RequestDone { session, request, result } => {
|
||||
self.request_done(*session as i64, *request, result.clone());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
touched
|
||||
}
|
||||
|
||||
/// Refresh what an event touched (after the app handled it).
|
||||
pub(crate) fn social_refresh(&mut self, touched: Touched) {
|
||||
if touched.people {
|
||||
self.refresh_people();
|
||||
}
|
||||
if touched.chats {
|
||||
self.ask_inboxes();
|
||||
self.refresh_chats();
|
||||
}
|
||||
if touched.home {
|
||||
self.refresh_home();
|
||||
}
|
||||
}
|
||||
|
||||
fn friend_presence(&mut self, uid: &str, sessions: &[FriendSpot]) {
|
||||
let was = self.social.online_since.contains_key(uid);
|
||||
if sessions.is_empty() {
|
||||
self.social.online_since.remove(uid);
|
||||
} else if !was {
|
||||
let now = now_ms();
|
||||
self.social.online_since.insert(uid.to_owned(), now);
|
||||
// Friends found in a session's first presence were there before.
|
||||
let new = sessions.iter().all(|s| {
|
||||
self.state.sessions.get(&(s.session as i64)).is_some_and(|v| {
|
||||
v.extra.presence_since > 0 && now - v.extra.presence_since > 10_000
|
||||
})
|
||||
});
|
||||
if new {
|
||||
let s = &sessions[0];
|
||||
let channel = self
|
||||
.state
|
||||
.sessions
|
||||
.get(&(s.session as i64))
|
||||
.and_then(|v| v.presence.channels.get(&s.channel))
|
||||
.map_or(s.channel_name.as_str(), |c| vm::tree::channel_title(c).0);
|
||||
let place = if channel.is_empty() {
|
||||
format!("on {}", self.server_name(s.session as i64))
|
||||
} else {
|
||||
format!("on {} · {channel}", self.server_name(s.session as i64))
|
||||
};
|
||||
self.notify(
|
||||
NoticeKind::Friend,
|
||||
format!("{} is online", s.nickname),
|
||||
place,
|
||||
NoticeTarget::Contact(uid.to_owned()),
|
||||
s.nickname.clone(),
|
||||
Some(uid.to_owned()),
|
||||
);
|
||||
}
|
||||
}
|
||||
self.refresh_people();
|
||||
self.refresh_home();
|
||||
}
|
||||
|
||||
// The search (Ctrl+K).
|
||||
|
||||
/// Fill the results for `text`: servers, channels, people, contacts,
|
||||
/// settings pages ("@…": people only).
|
||||
pub(crate) fn search(&mut self, text: String) {
|
||||
let people_only = text.starts_with('@');
|
||||
let query = text.trim_start_matches('@').trim().to_owned();
|
||||
let mut items: Vec<SearchItem> = Vec::new();
|
||||
let mut found: Vec<Found> = Vec::new();
|
||||
let mut group =
|
||||
|items: &mut Vec<SearchItem>, header: &str, mut add: Vec<(SearchItem, Found)>| {
|
||||
add.truncate(8);
|
||||
for (i, (mut item, f)) in add.into_iter().enumerate() {
|
||||
if i == 0 {
|
||||
item.header = header.into();
|
||||
}
|
||||
items.push(item);
|
||||
found.push(f);
|
||||
}
|
||||
};
|
||||
if !people_only {
|
||||
let servers = self
|
||||
.state
|
||||
.bookmarks
|
||||
.iter()
|
||||
.zip(vm::servers::tints(&self.state.bookmarks))
|
||||
.filter(|(b, _)| matches(&query, &[&b.name, &b.address]))
|
||||
.map(|(b, tint)| {
|
||||
(
|
||||
SearchItem {
|
||||
kind: "server".into(),
|
||||
title: b.name.clone().into(),
|
||||
subtitle: b.address.clone().into(),
|
||||
initials: vm::avatar::initials(&b.name).into(),
|
||||
tint,
|
||||
avatar: self.server_list_icon(b),
|
||||
..Default::default()
|
||||
},
|
||||
Found::Server(b.id),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
group(&mut items, "Servers", servers);
|
||||
}
|
||||
if !query.is_empty() && !people_only {
|
||||
let mut channels = Vec::new();
|
||||
for b in &self.state.bookmarks {
|
||||
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||
for (channel, title) in
|
||||
vm::social::found_channels(view.presence.channels.values(), &query)
|
||||
{
|
||||
channels.push((
|
||||
SearchItem {
|
||||
kind: "channel".into(),
|
||||
title: title.into(),
|
||||
subtitle: b.name.clone().into(),
|
||||
..Default::default()
|
||||
},
|
||||
Found::Channel(b.id, channel),
|
||||
));
|
||||
}
|
||||
}
|
||||
group(&mut items, "Channels", channels);
|
||||
}
|
||||
if !query.is_empty() || people_only {
|
||||
let mut people = Vec::new();
|
||||
let mut seen: HashSet<String> = HashSet::new();
|
||||
for b in &self.state.bookmarks {
|
||||
let Some(view) = self.state.sessions.get(&b.id) else { continue };
|
||||
for c in view.presence.clients.values() {
|
||||
if c.is_query || Some(c.id) == view.state.own_client {
|
||||
continue;
|
||||
}
|
||||
if !matches(&query, &[&c.nickname]) {
|
||||
continue;
|
||||
}
|
||||
if let Some(uid) = &c.uid {
|
||||
seen.insert(uid.clone());
|
||||
}
|
||||
let channel = view
|
||||
.presence
|
||||
.channels
|
||||
.get(&c.channel)
|
||||
.map_or("", |ch| vm::tree::channel_title(ch).0);
|
||||
people.push((
|
||||
SearchItem {
|
||||
kind: "person".into(),
|
||||
title: c.nickname.clone().into(),
|
||||
subtitle: format!("{} · {channel}", b.name).into(),
|
||||
initials: vm::avatar::initials(&c.nickname).into(),
|
||||
tint: vm::avatar::tint(&c.nickname),
|
||||
avatar: vm::avatar::image(view.avatar(c.id)),
|
||||
..Default::default()
|
||||
},
|
||||
Found::Person(b.id, c.id, c.uid.clone()),
|
||||
));
|
||||
}
|
||||
}
|
||||
for c in self.state.contacts.values() {
|
||||
if seen.contains(&c.uid) || !matches(&query, &[&c.nickname, &c.note]) {
|
||||
continue;
|
||||
}
|
||||
let name = if c.nickname.is_empty() { c.uid.clone() } else { c.nickname.clone() };
|
||||
people.push((
|
||||
SearchItem {
|
||||
kind: "contact".into(),
|
||||
title: name.clone().into(),
|
||||
subtitle: match c.relation {
|
||||
Relation::Friend => "Friend · offline".into(),
|
||||
Relation::Blocked => "Blocked".into(),
|
||||
Relation::Neutral => "Contact · offline".into(),
|
||||
},
|
||||
initials: vm::avatar::initials(&name).into(),
|
||||
tint: vm::avatar::tint(&name),
|
||||
avatar: self.avatar_of(&c.uid),
|
||||
..Default::default()
|
||||
},
|
||||
Found::Contact(c.uid.clone()),
|
||||
));
|
||||
}
|
||||
group(&mut items, "People", people);
|
||||
}
|
||||
if !people_only {
|
||||
let pages = SETTING_PAGES
|
||||
.iter()
|
||||
.filter(|(title, words, _)| matches(&query, &[title, words]))
|
||||
.map(|(title, _, section)| {
|
||||
(
|
||||
SearchItem {
|
||||
kind: "setting".into(),
|
||||
title: (*title).into(),
|
||||
subtitle: "Settings".into(),
|
||||
..Default::default()
|
||||
},
|
||||
Found::Setting(*section),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
group(&mut items, "Settings", pages);
|
||||
}
|
||||
self.social.found = found;
|
||||
self.models.social.search.sync(&items);
|
||||
}
|
||||
|
||||
/// Open a search result.
|
||||
pub(crate) fn search_activate(&mut self, index: i32) {
|
||||
let Some(found) =
|
||||
usize::try_from(index).ok().and_then(|i| self.social.found.get(i)).cloned()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
match found {
|
||||
Found::Server(id) => self.show_server(id),
|
||||
Found::Channel(id, channel) => {
|
||||
self.show_server(id);
|
||||
self.open_chat(ChatTarget::Channel(channel), true);
|
||||
}
|
||||
Found::Person(id, client, Some(uid)) => {
|
||||
let _ = client;
|
||||
self.open_dm_with(Some(id), &uid);
|
||||
}
|
||||
Found::Person(id, client, None) => {
|
||||
self.show_server(id);
|
||||
self.open_member(i32::from(client));
|
||||
}
|
||||
Found::Contact(uid) => {
|
||||
self.social.selected = Some(uid);
|
||||
self.refresh_people();
|
||||
self.navigate(|nav| nav.invoke_show(Page::Friends));
|
||||
}
|
||||
Found::Setting(section) => self.navigate(move |nav| nav.invoke_open_settings(section)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn notice_names_and_setting_pages() {
|
||||
assert_eq!(NoticeKind::Poke.name(), "poke");
|
||||
assert!(SETTING_PAGES.iter().any(|(t, _, _)| *t == "Voice & Video"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
//! The Slint side of the social screens: the Bridge writes of the friends,
|
||||
//! the bell and the search, the desktop toasts, the navigation after a move,
|
||||
//! and the callbacks' ways into the transitions of
|
||||
//! `voelin_ui_vm::social::logic`.
|
||||
|
||||
use slint::ComponentHandle;
|
||||
use tracing::debug;
|
||||
use voelin_model::{ChatMessage, ChatTarget};
|
||||
|
||||
use crate::app::{App, Bridge, Nav, Page, SettingsSection};
|
||||
use crate::settings::{
|
||||
NOTIFY_EVENTS, NOTIFY_FRIENDS, NOTIFY_MENTIONS, NOTIFY_MESSAGES, NOTIFY_POKES, NotifyLevel,
|
||||
};
|
||||
use crate::vm;
|
||||
use crate::vm::social::logic::{self, ContactMove, Found, SettingsPage};
|
||||
use crate::vm::social::{NoticeRequest, Spot};
|
||||
|
||||
use super::{NoticeKind, NoticeTarget, now_ms};
|
||||
|
||||
/// The Slint enum for a page of the settings.
|
||||
fn section(page: SettingsPage) -> SettingsSection {
|
||||
match page {
|
||||
SettingsPage::Account => SettingsSection::Account,
|
||||
SettingsPage::Profiles => SettingsSection::Profiles,
|
||||
SettingsPage::Appearance => SettingsSection::Appearance,
|
||||
SettingsPage::Voice => SettingsSection::Voice,
|
||||
SettingsPage::Streaming => SettingsSection::Streaming,
|
||||
SettingsPage::Devices => SettingsSection::Devices,
|
||||
SettingsPage::Notifications => SettingsSection::Notifications,
|
||||
SettingsPage::Privacy => SettingsSection::Privacy,
|
||||
SettingsPage::Keybinds => SettingsSection::Keybinds,
|
||||
SettingsPage::Integrations => SettingsSection::Integrations,
|
||||
SettingsPage::Advanced => SettingsSection::Advanced,
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// The avatar picture of someone by unique id, from any session.
|
||||
pub(crate) fn avatar_of(&self, uid: &str) -> vm::ImageRef {
|
||||
vm::social::avatar_of(&self.state, uid)
|
||||
}
|
||||
|
||||
/// A server's name: its bookmark's, else what the session calls it.
|
||||
pub(crate) fn server_name(&self, session: i64) -> String {
|
||||
vm::social::server_name(&self.state, session)
|
||||
}
|
||||
|
||||
/// Every session where the client with this unique id is, in bookmark
|
||||
/// order.
|
||||
pub(crate) fn spots_of(&self, uid: &str) -> Vec<Spot> {
|
||||
vm::social::spots_of(&self.state, uid)
|
||||
}
|
||||
|
||||
/// Friends page, home's friends and activity, the block list
|
||||
/// ([`logic::people`]).
|
||||
pub(crate) fn refresh_people(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
let m = &self.models.social;
|
||||
let people = logic::people(&self.state, &self.social);
|
||||
m.friends_online.sync(&people.online);
|
||||
m.friend_activity.sync(&people.activity);
|
||||
m.blocked.sync(&people.blocked);
|
||||
bridge.set_contacts_online(people.online_count);
|
||||
bridge.set_contacts_all(people.all_count);
|
||||
bridge.set_contacts_blocked(people.blocked_count);
|
||||
m.contacts.sync(&people.shown);
|
||||
bridge.set_contact(people.selected.into());
|
||||
}
|
||||
|
||||
pub(crate) fn friends_tab(&mut self, tab: i32) {
|
||||
self.social_transition(|_, social, cx| logic::set_friends_tab(social, cx, tab));
|
||||
}
|
||||
|
||||
pub(crate) fn search_contacts(&mut self, text: String) {
|
||||
self.social_transition(|_, social, cx| logic::search_contacts(social, cx, text));
|
||||
}
|
||||
|
||||
pub(crate) fn select_contact(&mut self, uid: String) {
|
||||
self.social_transition(|_, social, cx| logic::select_contact(social, cx, uid));
|
||||
}
|
||||
|
||||
/// The buttons of a contact: "message", "poke", "join", "watch",
|
||||
/// "friend", "block", "neutral", "remove", "mute"
|
||||
/// ([`logic::contact_action`]); what the move needs a window for is done
|
||||
/// here.
|
||||
pub(crate) fn contact_action(&mut self, uid: &str, action: &str) {
|
||||
let next = self.social_transition(|state, social, cx| {
|
||||
logic::contact_action(state, social, cx, uid, action)
|
||||
});
|
||||
match next {
|
||||
Some(ContactMove::Message) => self.message_person(uid),
|
||||
Some(ContactMove::Poke(session, client)) => self.ask_poke(session, client),
|
||||
Some(ContactMove::Join(spot)) => {
|
||||
self.show_server(spot.session);
|
||||
self.join_channel(spot.session, spot.channel);
|
||||
}
|
||||
Some(ContactMove::Watch(spot)) => {
|
||||
self.show_server(spot.session);
|
||||
self.watch_client(spot.client);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn contact_note(&mut self, uid: &str, note: String) {
|
||||
self.transition(|state, cx| logic::contact_note(state, cx, uid, note));
|
||||
}
|
||||
|
||||
pub(crate) fn contact_volume(&mut self, uid: &str, percent: f32) {
|
||||
self.transition(|state, cx| logic::contact_volume(state, cx, uid, percent));
|
||||
}
|
||||
|
||||
/// The server page of a session.
|
||||
pub(crate) fn show_server(&mut self, session: i64) {
|
||||
if self.state.current != Some(session) {
|
||||
self.select_server(session);
|
||||
}
|
||||
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 bell.
|
||||
|
||||
/// Add a notification as the kind's setting says ([`logic::notify`]),
|
||||
/// and show it on the desktop if the setting says so.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn notify(
|
||||
&mut self,
|
||||
kind: NoticeKind,
|
||||
title: String,
|
||||
body: String,
|
||||
target: NoticeTarget,
|
||||
name: String,
|
||||
uid: Option<String>,
|
||||
) {
|
||||
let key = match kind {
|
||||
NoticeKind::Mention => &NOTIFY_MENTIONS,
|
||||
NoticeKind::Poke => &NOTIFY_POKES,
|
||||
NoticeKind::Message => &NOTIFY_MESSAGES,
|
||||
NoticeKind::Event => &NOTIFY_EVENTS,
|
||||
NoticeKind::Friend => &NOTIFY_FRIENDS,
|
||||
};
|
||||
let level = self.prefs.get(key);
|
||||
if level == NotifyLevel::Off {
|
||||
return;
|
||||
}
|
||||
let request = NoticeRequest { kind, title, body, target, name, uid };
|
||||
if let Some(toast) = logic::notify(&mut self.social, level, self.demo_ui, request, now_ms())
|
||||
{
|
||||
let n = voelin_platform::Notification {
|
||||
urgent: toast.urgent,
|
||||
..voelin_platform::Notification::new(toast.title, toast.body)
|
||||
};
|
||||
self.engine.runtime().spawn(async move {
|
||||
if let Err(e) = voelin_platform::notify(&n).await {
|
||||
debug!("no desktop notification: {e}");
|
||||
}
|
||||
});
|
||||
}
|
||||
self.refresh_notices();
|
||||
}
|
||||
|
||||
/// The bell's notices, and home's unread mentions (the newest three).
|
||||
pub(crate) fn refresh_notices(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let rows = logic::notice_rows(&self.state, &self.social);
|
||||
self.models.social.notices.sync(&rows.notices);
|
||||
self.models.social.mentions.sync(&rows.mentions);
|
||||
ui.global::<Bridge>().set_notifications_unread(rows.unread);
|
||||
}
|
||||
|
||||
pub(crate) fn mark_notices_read(&mut self) {
|
||||
logic::mark_notices_read(&mut self.social);
|
||||
self.refresh_notices();
|
||||
}
|
||||
|
||||
pub(crate) fn clear_notices(&mut self) {
|
||||
logic::clear_notices(&mut self.social);
|
||||
self.refresh_notices();
|
||||
}
|
||||
|
||||
/// Open what a notification is about.
|
||||
pub(crate) fn open_notice(&mut self, key: i32) {
|
||||
let Some(target) =
|
||||
self.social_transition(|_, social, cx| logic::open_notice(social, cx, key))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
self.refresh_notices();
|
||||
match target {
|
||||
NoticeTarget::Chat(session, chat) => {
|
||||
self.show_server(session);
|
||||
self.open_chat(chat, true);
|
||||
}
|
||||
NoticeTarget::Dm(session, uid) => self.open_dm_with(Some(session), &uid),
|
||||
NoticeTarget::Event(session, _) => {
|
||||
self.select_server(session);
|
||||
self.navigate(|nav| nav.invoke_show(Page::Events));
|
||||
}
|
||||
NoticeTarget::Contact(_) => self.navigate(|nav| nav.invoke_show(Page::Friends)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a message is ours.
|
||||
pub(crate) fn is_own(&self, session: i64, message: &ChatMessage) -> bool {
|
||||
vm::social::is_own(&self.state, session, message)
|
||||
}
|
||||
|
||||
// The search (Ctrl+K).
|
||||
|
||||
/// Fill the results for `text` ([`logic::search`]).
|
||||
pub(crate) fn search(&mut self, text: String) {
|
||||
let (items, found) = logic::search(&self.state, &text, |b| self.server_list_icon(b));
|
||||
self.social.found = found;
|
||||
self.models.social.search.sync(&items);
|
||||
}
|
||||
|
||||
/// Open a search result.
|
||||
pub(crate) fn search_activate(&mut self, index: i32) {
|
||||
let Some(found) =
|
||||
self.social_transition(|_, social, cx| logic::search_activate(social, cx, index))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
match found {
|
||||
Found::Server(id) => self.show_server(id),
|
||||
Found::Channel(id, channel) => {
|
||||
self.show_server(id);
|
||||
self.open_chat(ChatTarget::Channel(channel), true);
|
||||
}
|
||||
Found::Person(id, _, Some(uid)) => self.open_dm_with(Some(id), &uid),
|
||||
Found::Person(id, client, None) => {
|
||||
self.show_server(id);
|
||||
self.open_member(i32::from(client));
|
||||
}
|
||||
Found::Contact(_) => self.navigate(|nav| nav.invoke_show(Page::Friends)),
|
||||
Found::Setting(page) => {
|
||||
let section = section(page);
|
||||
self.navigate(move |nav| nav.invoke_open_settings(section));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
//! People across servers: contacts and where they are (Friends, home), the
|
||||
//! bell's notifications, pokes, and the search (Ctrl+K). The direct
|
||||
//! messages are in `messages.rs`, the home page in `home.rs`, a server's
|
||||
//! events in `events.rs`.
|
||||
//!
|
||||
//! Every contact's whereabouts come from the sessions' presence (voice,
|
||||
//! gateway or query), so they are current for friends and the others alike;
|
||||
//! [`voelin_core::Event::FriendPresence`] adds when a friend came online, for
|
||||
//! "12m ago" and the notification. What the screens show and what an event
|
||||
//! or a move does to them is in `voelin_ui_vm::social::logic`; `bind` has
|
||||
//! the Bridge writes, the desktop toasts and the navigation.
|
||||
|
||||
mod bind;
|
||||
|
||||
use crate::app::Bridge;
|
||||
use crate::bind::rows::Rows;
|
||||
use crate::vm;
|
||||
|
||||
pub(crate) use vm::social::{NoticeKind, NoticeTarget, now_ms};
|
||||
|
||||
/// State of the home, friends, messages, bell and search screens: the
|
||||
/// view model's, with what the messages page keeps.
|
||||
pub(crate) type Social = vm::social::logic::Social<crate::messages::Dms>;
|
||||
|
||||
/// The models of these screens, set on the Bridge once.
|
||||
pub(crate) struct SocialModels {
|
||||
pub friends_online: Rows<vm::bridge::ContactItem>,
|
||||
pub friend_activity: Rows<vm::bridge::ContactItem>,
|
||||
pub contacts: Rows<vm::bridge::ContactItem>,
|
||||
pub blocked: Rows<vm::bridge::ContactItem>,
|
||||
pub live: Rows<vm::bridge::LiveItem>,
|
||||
pub recent: Rows<vm::bridge::ConversationItem>,
|
||||
pub sidebar_dms: Rows<vm::bridge::ConversationItem>,
|
||||
pub conversations: Rows<vm::bridge::ConversationItem>,
|
||||
pub dm_lines: Rows<vm::bridge::ChatLine>,
|
||||
pub happenings: Rows<vm::bridge::HappeningItem>,
|
||||
pub recordings: Rows<vm::bridge::RecordingItem>,
|
||||
pub notices: Rows<vm::bridge::NoticeItem>,
|
||||
pub mentions: Rows<vm::bridge::NoticeItem>,
|
||||
pub search: Rows<vm::bridge::SearchItem>,
|
||||
pub events: Rows<vm::bridge::EventItem>,
|
||||
}
|
||||
|
||||
impl SocialModels {
|
||||
pub fn new(bridge: &Bridge) -> Self {
|
||||
let m = Self {
|
||||
friends_online: Rows::default(),
|
||||
friend_activity: Rows::default(),
|
||||
contacts: Rows::default(),
|
||||
blocked: Rows::default(),
|
||||
live: Rows::default(),
|
||||
recent: Rows::default(),
|
||||
sidebar_dms: Rows::default(),
|
||||
conversations: Rows::default(),
|
||||
dm_lines: Rows::default(),
|
||||
happenings: Rows::default(),
|
||||
recordings: Rows::default(),
|
||||
notices: Rows::default(),
|
||||
mentions: Rows::default(),
|
||||
search: Rows::default(),
|
||||
events: Rows::default(),
|
||||
};
|
||||
bridge.set_friends_online(m.friends_online.model());
|
||||
bridge.set_friend_activity(m.friend_activity.model());
|
||||
bridge.set_contacts(m.contacts.model());
|
||||
bridge.set_blocked(m.blocked.model());
|
||||
bridge.set_live_rooms(m.live.model());
|
||||
bridge.set_recent_chats(m.recent.model());
|
||||
bridge.set_sidebar_dms(m.sidebar_dms.model());
|
||||
bridge.set_conversations(m.conversations.model());
|
||||
bridge.set_dm_messages(m.dm_lines.model());
|
||||
bridge.set_happenings(m.happenings.model());
|
||||
bridge.set_recordings(m.recordings.model());
|
||||
bridge.set_notifications(m.notices.model());
|
||||
bridge.set_home_mentions(m.mentions.model());
|
||||
bridge.set_search_results(m.search.model());
|
||||
bridge.set_events(m.events.model());
|
||||
m
|
||||
}
|
||||
}
|
||||
+31
-27
@@ -27,7 +27,7 @@ crates/voelin-ui-vm/ view models and state, no UI toolkit
|
||||
events/ events::apply: what an engine event does to the AppState
|
||||
(mod.rs; gateway.rs: the gateway's events and directory)
|
||||
previews.rs pictures linked in chat: which to fetch, the transfers
|
||||
servers/mod.rs tree.rs chat/mod.rs social.rs home.rs streams/mod.rs avatar.rs studio/mod.rs
|
||||
servers/mod.rs tree.rs chat/mod.rs social/mod.rs home.rs streams/mod.rs avatar.rs studio/mod.rs
|
||||
pure view models (engine state → bridge structs), unit-tested
|
||||
chat/logic.rs chat tabs, messages and what is read, pins and topics, files; the
|
||||
chat view (tabs, lines, divider, drawers) and the user's moves
|
||||
@@ -39,6 +39,8 @@ crates/voelin-ui-vm/ view models and state, no UI toolkit
|
||||
settings.rs the UI's settings keys, the audio form
|
||||
settings_pages/logic.rs, studio/logic.rs
|
||||
the decisions of the settings pages and of the Stream Studio
|
||||
social/logic.rs the friends, the bell and the search as rows, what the user's moves on
|
||||
them do, and what an event does to the friends, pokes and notices
|
||||
settings_page/logic.rs
|
||||
the audio settings page (devices, form, microphone test, push to
|
||||
talk), the crash notice and the volume dialog of a client
|
||||
@@ -70,16 +72,17 @@ crates/voelin-ui/ the Slint front end
|
||||
src/
|
||||
app.rs setup, the Slint models (`Models`), the event loop; `App` holds
|
||||
a `voelin_ui_vm::state::AppState` and the window
|
||||
host.rs SlintHost (the answers the transitions ask for), `App::apply_event`,
|
||||
host.rs SlintHost (the answers the transitions ask for), `App::handle_event`,
|
||||
`transition` and `perform`: doing what an `Update` says
|
||||
members.rs appearance.rs
|
||||
home.rs social.rs messages.rs events.rs previews.rs popout.rs
|
||||
the Slint side of each area (social.rs: contacts, the bell and the
|
||||
search; previews.rs: pictures in chat; popout.rs: the stream's own
|
||||
window)
|
||||
home.rs messages.rs events.rs previews.rs popout.rs
|
||||
the Slint side of each area (previews.rs: pictures in chat;
|
||||
popout.rs: the stream's own window)
|
||||
chat/ mod.rs, bind.rs: the chat view's Bridge writes and models
|
||||
servers/ mod.rs, bind.rs: connecting and observing (store, secrets, engine),
|
||||
the rail, the server card and the tree on the Bridge
|
||||
social/ mod.rs (the models), bind.rs: contacts, the bell and the search on
|
||||
the Bridge, the desktop toasts, the navigation after a move
|
||||
settings_page/ mod.rs, bind.rs: the audio devices, the hotkey, the codec download,
|
||||
the crash reports and the Bridge writes of the settings page
|
||||
settings_pages/ mod.rs (Pages), bind.rs: the settings pages on the Bridge
|
||||
@@ -131,35 +134,37 @@ this file is `voelin_ui_vm::chat`. The boundary:
|
||||
`voelin_ui_vm::state`, generic over the list type `L` of a chat tab's
|
||||
lines: the Slint app plugs in `Rows<ChatLine>` (`app::ChatRows`), a front
|
||||
end that re-renders can use a `Vec`. `App.state` is the one `AppState`.
|
||||
- **Events.** `voelin_ui_vm::events::apply(state, host, event)` is the one
|
||||
dispatch: it changes the `AppState` for an engine `Event` and returns an
|
||||
`Update`, which says what the front end has to do: the parts to draw again
|
||||
(`Refresh`, each once however many events set it), the status line, the
|
||||
engine commands in order, what to keep (`Persist`: a bookmark, the UI's
|
||||
settings), pictures to decode again, the password dialog, notices for the
|
||||
bell, the chats that changed and a stream to watch. `Host` is what the
|
||||
transitions ask while they run: whether the chat is on screen, the store's
|
||||
read markers, the preview limit. The Slint client's `App::handle_event` is
|
||||
`social_event`, `apply_event` (`apply`, then `perform`, which carries the
|
||||
update out in `host.rs`) and `social_refresh`; a GPUI client calls `apply`
|
||||
and draws what `Update::refresh` names. The vm tests replay tapes of events
|
||||
against a fake `Host` (`events/tests.rs`). `Update::rest` hands back the
|
||||
- **Events.** `voelin_ui_vm::events::handle(state, social, host, event)` is
|
||||
the one dispatch: it lets `social::logic::event` look at the event first
|
||||
(the friends, pokes, offline messages and the notices, which need the state
|
||||
as it was before the event), then `events::apply` changes the `AppState`,
|
||||
and returns an `Update`, which says what the front end has to do: the parts
|
||||
to draw again (`Refresh`, each once however many events set it), the status
|
||||
line, the engine commands in order, what to keep (`Persist`: a bookmark,
|
||||
the UI's settings, the audio settings, the clients' volumes), pictures to
|
||||
decode again, the password dialog, notices for the bell, the chats that
|
||||
changed and a stream to watch. `Host` is what the transitions ask while
|
||||
they run: whether the chat or a private chat is on screen, the store's read
|
||||
markers, the preview limit, the time. The Slint client's
|
||||
`App::handle_event` is `handle` and then `perform`, which carries the update
|
||||
out in `host.rs`; a GPUI client calls `handle` and draws what
|
||||
`Update::refresh` names. The vm tests replay tapes of events against a fake
|
||||
`Host` (`events/tests.rs`, `social/logic.rs`). `Update::rest` hands back the
|
||||
events whose state is not in the `AppState`: the Stream Studio's stream
|
||||
(`StreamState` and `StreamViewers` while `Host::studio_streams_to`),
|
||||
`SettingChanged`, and the rest that no screen looks at. The streams we
|
||||
`SettingChanged`, the offline messages and their requests (`messages.rs`
|
||||
keeps those for now), and the rest that no screen looks at. The streams we
|
||||
share and watch are in the `AppState` (`share`, `watch`; the capture and
|
||||
the decoder are the front end's, and an update says when to attach or drop
|
||||
them). The friends, pokes, offline messages and notices that `social.rs` keeps
|
||||
(`Poke`, `FriendPresence`, `OfflineMessages`, `OfflineMessage`,
|
||||
`RequestDone`, and the notices of `Chat`, `ChatHistory`, `Presence`,
|
||||
`State`, `ServerInfo`, `ContactsChanged`, `AvatarReady`) are looked at by
|
||||
`social.rs` before and after `apply`. They move with `social.rs`.
|
||||
them). The friends, the pokes, the bell's notices and what the friends page
|
||||
and the search keep are in `Social` (`social::logic`), which a front end
|
||||
passes to `handle` besides the `AppState`.
|
||||
- **Logic and bind.** An area that interleaves decisions with Bridge writes
|
||||
is split into `<area>/logic.rs` in `voelin-ui-vm` (functions over the
|
||||
settings service, the `AppState` and plain rows; they return rows,
|
||||
commands or messages for the status line, and write no Bridge) and
|
||||
`<area>/bind.rs` in `voelin-ui` (the Bridge and model writes, windows,
|
||||
timers, threads, engine commands). Done: `settings_pages`, `studio`, `streams`, `chat`, `servers` and `settings_page`.
|
||||
timers, threads, engine commands). Done: `settings_pages`, `studio`, `streams`, `chat`, `servers`, `settings_page` and `social`.
|
||||
|
||||
The pure code is tested in `voelin-ui-vm` (`cargo test -p voelin-ui-vm`,
|
||||
no display); the Slint crate's tests are what needs the window types.
|
||||
@@ -181,7 +186,6 @@ the same shape as `settings_pages` and `studio`: move the decisions into
|
||||
| File | `.set_` calls | What it mixes |
|
||||
|---|---|---|
|
||||
| `app.rs` | 31 | setup, the status line, the toolbar and tree refreshes (the event dispatch is `vm::events::apply`) |
|
||||
| `social.rs` | 23 | home's contacts, the bell and the search |
|
||||
| `dev.rs` | 23 | development switches and the sample data (the switches stay with the window; the sample rows can move) |
|
||||
| `images.rs` | 13 | the decoded-picture cache |
|
||||
| `messages.rs` | 12 | direct messages |
|
||||
|
||||
Reference in new issue
Block a user