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 {
|
||||
Reference in new issue
Block a user