Take the text of an offline message in before the redraw, not after it
The social split left the offline message's state change in the front end's `rest` events, which `perform` handled after it drew the conversations: `refresh_chats` drew the open message while `dm.mail` was still empty and the inbox row was still unread, and nothing drew the page again. Before the split `social_event` wrote both ahead of `social_refresh`. `Event::OfflineMessage` is now taken in by `social::logic::event` like the other offline events: the text is `Social::mail`, the inbox row turns read, and a failure is the status line. `events::apply` no longer parks the event in `rest`, so a tape test in `voelin-ui-vm` sees it (the mutation that parks it fails the test). `perform` also handles what is left in `rest` (a setting, the studio's stream, the request answers) before it draws, as every such event ran before the redraw ahead of the split. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
81def06144
commit
91d70702f3
6 files changed
+138
-43
No files matched your search
@@ -218,6 +218,11 @@ impl App {
|
||||
notice.uid,
|
||||
);
|
||||
}
|
||||
// What the front end keeps itself comes before the drawing: what
|
||||
// it changes is on screen then.
|
||||
if let Some(event) = rest {
|
||||
self.event_rest(event);
|
||||
}
|
||||
self.refresh_parts(refresh);
|
||||
for (id, target) in chats {
|
||||
self.studio_chat_changed(id, &target);
|
||||
@@ -231,9 +236,6 @@ impl App {
|
||||
if first_client && self.open_client_pending {
|
||||
self.open_first_client();
|
||||
}
|
||||
if let Some(event) = rest {
|
||||
self.event_rest(event);
|
||||
}
|
||||
}
|
||||
|
||||
/// Keep what a transition changed.
|
||||
@@ -307,7 +309,9 @@ impl App {
|
||||
}
|
||||
|
||||
/// The events whose state the view model does not hold: a setting that
|
||||
/// changed, and the studio's stream.
|
||||
/// changed, the studio's stream and the requests of the messages page.
|
||||
/// [`App::perform`] runs this before it draws, so that what these change
|
||||
/// is what is drawn.
|
||||
fn event_rest(&mut self, event: Event) {
|
||||
match event {
|
||||
Event::SettingChanged { key } => self.setting_changed(&key),
|
||||
@@ -318,11 +322,10 @@ impl App {
|
||||
Event::StreamViewers { session, viewers } if self.studio_streams_to(session as i64) => {
|
||||
self.studio_viewers(viewers);
|
||||
}
|
||||
// The messages page keeps the offline messages (messages.rs).
|
||||
// The messages page keeps the offline message requests
|
||||
// (messages.rs); the text of a message is the view model's
|
||||
// (`social::logic::event`).
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use slint::ComponentHandle;
|
||||
use voelin_core::{Command, HistoryMessage, OfflineMessage, OfflineMessageInfo, VoiceState};
|
||||
use voelin_core::{Command, HistoryMessage, OfflineMessageInfo, VoiceState};
|
||||
use voelin_model::ChatTarget;
|
||||
use voelin_store::PageQuery;
|
||||
|
||||
@@ -55,8 +55,6 @@ pub(crate) struct Dms {
|
||||
pub tab: i32,
|
||||
pub filter: String,
|
||||
pub open: Option<Open>,
|
||||
/// The text of the open offline message.
|
||||
pub mail: Option<OfflineMessage>,
|
||||
/// Offline message requests in flight: session and what for.
|
||||
pub requests: HashMap<u64, (i64, &'static str)>,
|
||||
pub next_request: u64,
|
||||
@@ -439,7 +437,7 @@ impl App {
|
||||
mail: None,
|
||||
stored: !live,
|
||||
});
|
||||
self.social.dm.mail = None;
|
||||
self.social.mail = None;
|
||||
self.models.social.dm_lines.sync(&[]);
|
||||
let target = ChatTarget::Private(uid.to_owned());
|
||||
if let (true, Some(id)) = (live, session) {
|
||||
@@ -645,7 +643,6 @@ impl App {
|
||||
mail_subject: mail.as_ref().map(|m| m.subject.clone()).unwrap_or_default().into(),
|
||||
mail_text: self
|
||||
.social
|
||||
.dm
|
||||
.mail
|
||||
.as_ref()
|
||||
.map(|m| plain(&m.text))
|
||||
@@ -763,7 +760,7 @@ impl App {
|
||||
mail: Some((session, m.id)),
|
||||
stored: false,
|
||||
});
|
||||
self.social.dm.mail = None;
|
||||
self.social.mail = None;
|
||||
let request = self.offline_request(session, "get");
|
||||
if !self.demo_ui {
|
||||
self.engine.send(Command::GetOfflineMessage {
|
||||
@@ -775,20 +772,6 @@ impl App {
|
||||
self.refresh_chats();
|
||||
}
|
||||
|
||||
pub(crate) fn mail_arrived(&mut self, session: i64, result: Result<OfflineMessage, String>) {
|
||||
match result {
|
||||
Ok(m) => {
|
||||
if let Some(view) = self.state.sessions.get_mut(&session)
|
||||
&& let Some(info) = view.extra.inbox.iter_mut().find(|i| i.id == m.id)
|
||||
{
|
||||
info.read = true;
|
||||
}
|
||||
self.social.dm.mail = Some(m);
|
||||
}
|
||||
Err(e) => self.set_status(format!("Could not read the offline message: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn request_done(&mut self, session: i64, request: u64, result: Result<(), String>) {
|
||||
let Some((_, what)) = self.social.dm.requests.remove(&request) else { return };
|
||||
match (what, result) {
|
||||
|
||||
Reference in new issue
Block a user