ui: private chats on the Direct Messages page, not in the chat tabs
The server's chat strip shows the server chat and the channel chats. Private chats stay tabs of their session, so history, the composer and previews keep working, but the strip leaves them out (vm::chat::strip) and a private chat is current only while the Direct Messages page shows it; leaving the page goes back to the strip's last chat. The rail and the Chats tab count only the server's and channels' unread messages; private ones count on Direct Messages and, on the phone, on the Home tab. Closing a tab left of the selected one no longer selects the next chat. Voice connecting while a private chat is open keeps that conversation (it became the voice channel's chat, and the composer sent there). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
14 files changed
+414
-64
No files matched your search
+159
-3
@@ -205,6 +205,11 @@ impl Tab {
|
||||
}
|
||||
}
|
||||
|
||||
/// A private chat (on the Direct Messages page, not in the chat strip).
|
||||
pub fn is_private(&self) -> bool {
|
||||
matches!(self.target, ChatTarget::Private(_))
|
||||
}
|
||||
|
||||
/// A handle for a message that has none yet.
|
||||
pub fn take_key(&mut self) -> i32 {
|
||||
self.next_key += 1;
|
||||
@@ -269,6 +274,10 @@ pub(crate) struct SessionView {
|
||||
pub talking: HashSet<u16>,
|
||||
pub tabs: Vec<Tab>,
|
||||
pub current_tab: usize,
|
||||
/// The chat strip's chat last current (the server's or a channel's): a
|
||||
/// private chat is current only on the Direct Messages page, and this
|
||||
/// one is current again when that page is left.
|
||||
pub channel_tab: ChatTarget,
|
||||
/// The own channel's tab was focused for this voice connection.
|
||||
pub focused_own_channel: bool,
|
||||
/// The streams in our channel (TeamSpeak 6).
|
||||
@@ -325,6 +334,7 @@ impl Default for SessionView {
|
||||
talking: HashSet::new(),
|
||||
tabs: vec![Tab::new(ChatTarget::Server, "Server".into())],
|
||||
current_tab: 0,
|
||||
channel_tab: ChatTarget::Server,
|
||||
focused_own_channel: false,
|
||||
streams: Vec::new(),
|
||||
applied_playback: HashSet::new(),
|
||||
@@ -376,9 +386,62 @@ impl SessionView {
|
||||
.map_or_else(|| format!("client {client}"), |c| c.nickname.clone())
|
||||
}
|
||||
|
||||
/// Unread messages in all chats.
|
||||
pub fn unread(&self) -> i32 {
|
||||
self.tabs.iter().map(|t| t.unread).sum()
|
||||
/// Unread messages in the server's and the channels' chats (the rail and
|
||||
/// the chat strip count them; private chats count on the Direct
|
||||
/// Messages page).
|
||||
pub fn channel_unread(&self) -> i32 {
|
||||
self.tabs.iter().filter(|t| !t.is_private()).map(|t| t.unread).sum()
|
||||
}
|
||||
|
||||
/// Unread messages in private chats.
|
||||
pub fn private_unread(&self) -> i32 {
|
||||
self.tabs.iter().filter(|t| t.is_private()).map(|t| t.unread).sum()
|
||||
}
|
||||
|
||||
/// Make tab `index` the current one; the chat strip remembers it unless
|
||||
/// it is a private chat.
|
||||
pub fn set_current_tab(&mut self, index: usize) {
|
||||
self.current_tab = index;
|
||||
if let Some(tab) = self.tabs.get(index).filter(|t| !t.is_private()) {
|
||||
self.channel_tab = tab.target.clone();
|
||||
}
|
||||
}
|
||||
|
||||
/// Focus tab `index`. While a private chat is current (the Direct
|
||||
/// Messages page shows it, and its composer sends there), a chat of the
|
||||
/// strip does not take its place: it is the strip's chat, current once
|
||||
/// that page is left (voice connecting focuses its channel's chat).
|
||||
pub fn focus_tab(&mut self, index: usize) {
|
||||
let Some(tab) = self.tabs.get(index) else { return };
|
||||
if !tab.is_private() && self.tabs.get(self.current_tab).is_some_and(Tab::is_private) {
|
||||
self.channel_tab = tab.target.clone();
|
||||
} else {
|
||||
self.set_current_tab(index);
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove tab `index`. The current tab stays; when it is this one, the
|
||||
/// chat strip's next tab takes its place, else its last.
|
||||
pub fn remove_tab(&mut self, index: usize) -> Tab {
|
||||
let tab = self.tabs.remove(index);
|
||||
if self.current_tab > index {
|
||||
self.current_tab -= 1;
|
||||
} else if self.current_tab == index {
|
||||
let (strip, _) = crate::vm::chat::strip(self.tabs.iter().map(|t| &t.target), 0);
|
||||
let next = strip.iter().find(|&&i| i >= index).or(strip.last()).copied();
|
||||
self.set_current_tab(next.unwrap_or(0));
|
||||
}
|
||||
tab
|
||||
}
|
||||
|
||||
/// Leave a current private chat for the chat strip's last one (the
|
||||
/// Direct Messages page was left); `true` if the current tab changed.
|
||||
pub fn leave_private(&mut self) -> bool {
|
||||
if !self.tabs.get(self.current_tab).is_some_and(Tab::is_private) {
|
||||
return false;
|
||||
}
|
||||
self.current_tab = self.tabs.iter().position(|t| t.target == self.channel_tab).unwrap_or(0);
|
||||
true
|
||||
}
|
||||
|
||||
/// A new tab for `target`, read as far as the store says.
|
||||
@@ -431,7 +494,10 @@ pub(crate) struct Models {
|
||||
pub tree: Rc<VecModel<TreeItem>>,
|
||||
pub members: Rc<VecModel<MemberItem>>,
|
||||
pub server_members: Rc<VecModel<MemberItem>>,
|
||||
/// The chat strip: the current session's tabs without its private chats.
|
||||
pub tabs: Rc<VecModel<ChatTab>>,
|
||||
/// Which of the session's tabs each of `tabs` is ([`crate::vm::chat::strip`]).
|
||||
pub strip: RefCell<Vec<usize>>,
|
||||
pub streams: Rc<VecModel<StreamItem>>,
|
||||
pub viewers: Rc<VecModel<ViewerItem>>,
|
||||
pub pins: Rc<VecModel<PinItem>>,
|
||||
@@ -460,6 +526,7 @@ impl Models {
|
||||
members: Rc::default(),
|
||||
server_members: Rc::default(),
|
||||
tabs: Rc::default(),
|
||||
strip: RefCell::new(vec![0]),
|
||||
streams: Rc::default(),
|
||||
viewers: Rc::default(),
|
||||
pins: Rc::default(),
|
||||
@@ -1261,3 +1328,92 @@ impl App {
|
||||
self.refresh_streams();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn channel_unread_ignores_private_tabs() {
|
||||
let mut view = SessionView::default();
|
||||
view.tabs.push(Tab::new(ChatTarget::Channel(1), "Lobby".into()));
|
||||
view.tabs.push(Tab::new(ChatTarget::Private("a".into()), "@Nova".into()));
|
||||
for (tab, unread) in view.tabs.iter_mut().zip([1, 2, 4]) {
|
||||
tab.unread = unread;
|
||||
}
|
||||
assert_eq!(view.channel_unread(), 3);
|
||||
assert_eq!(view.private_unread(), 4);
|
||||
}
|
||||
|
||||
/// Closing a tab keeps the current chat, or selects the strip's next
|
||||
/// one (never a private chat).
|
||||
#[test]
|
||||
fn closing_a_tab_keeps_the_current_chat() {
|
||||
let mut view = SessionView::default();
|
||||
for target in [
|
||||
ChatTarget::Channel(1),
|
||||
ChatTarget::Channel(2),
|
||||
ChatTarget::Private("a".into()),
|
||||
ChatTarget::Channel(3),
|
||||
] {
|
||||
view.tabs.push(Tab::new(target, String::new()));
|
||||
}
|
||||
let current = |v: &SessionView| v.tabs[v.current_tab].target.clone();
|
||||
view.set_current_tab(2);
|
||||
view.remove_tab(1);
|
||||
assert_eq!(current(&view), ChatTarget::Channel(2));
|
||||
// [Server, 2, @a, 3]: the next tab of the strip, past the private chat.
|
||||
view.remove_tab(1);
|
||||
assert_eq!(current(&view), ChatTarget::Channel(3));
|
||||
assert_eq!(view.channel_tab, ChatTarget::Channel(3));
|
||||
// The last one: the strip's last, the server chat.
|
||||
view.remove_tab(2);
|
||||
assert_eq!(current(&view), ChatTarget::Server);
|
||||
}
|
||||
|
||||
/// A private chat is current only on the Direct Messages page: leaving
|
||||
/// it goes back to the strip's last chat.
|
||||
#[test]
|
||||
fn leaving_a_private_chat_restores_the_strip_tab() {
|
||||
let mut view = SessionView::default();
|
||||
view.tabs.push(Tab::new(ChatTarget::Channel(1), "Lobby".into()));
|
||||
view.tabs.push(Tab::new(ChatTarget::Private("a".into()), "@Nova".into()));
|
||||
view.set_current_tab(1);
|
||||
assert!(!view.leave_private());
|
||||
view.set_current_tab(2);
|
||||
assert_eq!(view.channel_tab, ChatTarget::Channel(1));
|
||||
assert!(view.leave_private());
|
||||
assert_eq!(view.current_tab, 1);
|
||||
// The strip's chat was closed meanwhile: the server chat.
|
||||
view.set_current_tab(2);
|
||||
view.tabs.remove(1);
|
||||
view.current_tab = 1;
|
||||
assert!(view.leave_private());
|
||||
assert_eq!(view.current_tab, 0);
|
||||
}
|
||||
|
||||
/// A channel's chat focused while a private chat is current (voice
|
||||
/// connecting on the Direct Messages page) waits for the page to be
|
||||
/// left: the conversation and its composer stay the private chat's.
|
||||
#[test]
|
||||
fn a_strip_chat_does_not_replace_a_current_private_chat() {
|
||||
let mut view = SessionView::default();
|
||||
view.tabs.push(Tab::new(ChatTarget::Channel(1), "Lobby".into()));
|
||||
view.tabs.push(Tab::new(ChatTarget::Private("a".into()), "@Nova".into()));
|
||||
view.tabs.push(Tab::new(ChatTarget::Private("b".into()), "@Ivy".into()));
|
||||
view.focus_tab(2);
|
||||
assert_eq!(view.current_tab, 2);
|
||||
view.focus_tab(1);
|
||||
assert_eq!((view.current_tab, &view.channel_tab), (2, &ChatTarget::Channel(1)));
|
||||
// Another private chat does.
|
||||
view.focus_tab(3);
|
||||
assert_eq!(view.current_tab, 3);
|
||||
assert!(view.leave_private());
|
||||
assert_eq!(view.current_tab, 1);
|
||||
// Without a private chat current, any chat.
|
||||
view.focus_tab(0);
|
||||
assert_eq!((view.current_tab, &view.channel_tab), (0, &ChatTarget::Server));
|
||||
view.focus_tab(9);
|
||||
assert_eq!(view.current_tab, 0);
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,20 @@ pub(super) fn wire(ui: &MainWindow) {
|
||||
bridge.on_open_channel_chat(|cid| {
|
||||
with_app(|app| app.open_chat(ChatTarget::Channel(cid as ChannelId), true));
|
||||
});
|
||||
// A tab of the chat strip, which leaves out private chats.
|
||||
bridge.on_select_tab(|i| {
|
||||
with_app(|app| app.select_tab(i as usize));
|
||||
with_app(|app| {
|
||||
if let Some(index) = app.strip_tab(i) {
|
||||
app.select_tab(index);
|
||||
}
|
||||
});
|
||||
});
|
||||
bridge.on_close_tab(|i| {
|
||||
with_app(|app| app.close_tab(i as usize));
|
||||
with_app(|app| {
|
||||
if let Some(index) = app.strip_tab(i) {
|
||||
app.close_tab(index);
|
||||
}
|
||||
});
|
||||
});
|
||||
bridge.on_send_message(|text| {
|
||||
with_app(|app| app.send_message(text.to_string()));
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use slint::ComponentHandle;
|
||||
|
||||
use crate::app::{Bridge, MainWindow, with_app};
|
||||
use crate::app::{App, Bridge, MainWindow, with_app};
|
||||
|
||||
pub(super) fn wire(ui: &MainWindow) {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
@@ -111,9 +111,16 @@ pub(super) fn wire(ui: &MainWindow) {
|
||||
with_app(|app| app.open_preview(key, index)).unwrap_or_default()
|
||||
});
|
||||
|
||||
// Opening the messages or the Library loads what they list.
|
||||
// Opening the messages or the Library loads what they list; the open
|
||||
// private chat is the current chat while the messages page shows it.
|
||||
bridge.on_open_messages(|| {
|
||||
with_app(|app| app.load_recent_chats());
|
||||
with_app(|app| {
|
||||
app.messages_shown();
|
||||
app.load_recent_chats();
|
||||
});
|
||||
});
|
||||
bridge.on_close_messages(|| {
|
||||
with_app(App::close_messages);
|
||||
});
|
||||
bridge.on_open_library(|| {
|
||||
with_app(|app| app.load_library());
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
//! Chat: tabs per session (server, channels, private chats), their
|
||||
//! messages, and what a gateway adds to them (pins, reactions, topics).
|
||||
//! The chat strip shows the server's and the channels' tabs; a private chat
|
||||
//! is the current tab only while the messages page shows it (messages.rs).
|
||||
//!
|
||||
//! The engine keeps the history: [`Event::ChatHistory`] is an upsert of
|
||||
//! messages by their local id (see `voelin_core::history`), so a tab holds
|
||||
@@ -103,25 +105,9 @@ fn ago(ts_ms: i64) -> String {
|
||||
impl App {
|
||||
pub(crate) fn open_chat(&mut self, target: ChatTarget, focus: bool) {
|
||||
let Some(id) = self.current else { return };
|
||||
let peer = match &target {
|
||||
ChatTarget::Private(uid) => self.peer_name(uid, None),
|
||||
_ => String::new(),
|
||||
};
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let title = vm::chat::tab_title(&view.presence, &target, &peer);
|
||||
let index = match view.tabs.iter().position(|t| t.target == target) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
let tab = view.new_tab(target.clone(), title);
|
||||
view.tabs.push(tab);
|
||||
if !self.demo_ui {
|
||||
self.engine.send(Command::OpenChat { session: id as u64, target });
|
||||
}
|
||||
view.tabs.len() - 1
|
||||
}
|
||||
};
|
||||
let index = self.chat_tab(id, target);
|
||||
if focus {
|
||||
view.current_tab = index;
|
||||
self.sessions.entry(id).or_default().focus_tab(index);
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
}
|
||||
@@ -129,11 +115,37 @@ impl App {
|
||||
self.refresh_servers();
|
||||
}
|
||||
|
||||
/// The index of `target`'s tab in session `id`, opened if new (the
|
||||
/// engine then sends its history).
|
||||
pub(crate) fn chat_tab(&mut self, id: i64, target: ChatTarget) -> usize {
|
||||
let peer = match &target {
|
||||
ChatTarget::Private(uid) => self.peer_name(uid, None),
|
||||
_ => String::new(),
|
||||
};
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
if let Some(i) = view.tabs.iter().position(|t| t.target == target) {
|
||||
return i;
|
||||
}
|
||||
let title = vm::chat::tab_title(&view.presence, &target, &peer);
|
||||
let tab = view.new_tab(target.clone(), title);
|
||||
view.tabs.push(tab);
|
||||
if !self.demo_ui {
|
||||
self.engine.send(Command::OpenChat { session: id as u64, target });
|
||||
}
|
||||
view.tabs.len() - 1
|
||||
}
|
||||
|
||||
/// The session's tab that tab `index` of the chat strip is
|
||||
/// (`Bridge.tabs`, [`vm::chat::strip`]).
|
||||
pub(crate) fn strip_tab(&self, index: i32) -> Option<usize> {
|
||||
self.models.strip.borrow().get(usize::try_from(index).ok()?).copied()
|
||||
}
|
||||
|
||||
pub(crate) fn select_tab(&mut self, index: usize) {
|
||||
if let Some(view) = self.view_mut()
|
||||
&& index < view.tabs.len()
|
||||
{
|
||||
view.current_tab = index;
|
||||
view.set_current_tab(index);
|
||||
view.tabs[index].topic = None;
|
||||
}
|
||||
if let Some(id) = self.current {
|
||||
@@ -152,9 +164,7 @@ impl App {
|
||||
return;
|
||||
}
|
||||
self.save_read(id, index);
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let tab = view.tabs.remove(index);
|
||||
view.current_tab = view.current_tab.min(view.tabs.len() - 1);
|
||||
let tab = self.sessions.entry(id).or_default().remove_tab(index);
|
||||
self.engine.send(Command::CloseChat { session: id as u64, target: tab.target });
|
||||
self.prefetch_counts();
|
||||
self.track_reading();
|
||||
@@ -460,6 +470,9 @@ impl App {
|
||||
&self.models.tabs,
|
||||
&[ChatTab { title: "Server".into(), ..Default::default() }],
|
||||
);
|
||||
*self.models.strip.borrow_mut() = vec![0];
|
||||
bridge.set_current_tab(0);
|
||||
bridge.set_current_chat(0);
|
||||
let empty = ModelRc::from(self.models.no_chat.clone());
|
||||
if bridge.get_messages() != empty {
|
||||
bridge.set_messages(empty);
|
||||
@@ -467,9 +480,12 @@ impl App {
|
||||
bridge.set_unread_index(-1);
|
||||
return;
|
||||
};
|
||||
let tabs: Vec<ChatTab> = view
|
||||
.tabs
|
||||
// Private chats are on the messages page, not in the strip.
|
||||
let (strip, current) =
|
||||
vm::chat::strip(view.tabs.iter().map(|t| &t.target), view.current_tab);
|
||||
let tabs: Vec<ChatTab> = strip
|
||||
.iter()
|
||||
.map(|&i| &view.tabs[i])
|
||||
.map(|t| {
|
||||
let (last, time) = t
|
||||
.messages
|
||||
@@ -508,10 +524,11 @@ impl App {
|
||||
})
|
||||
.collect();
|
||||
vm::list::sync(&self.models.tabs, &tabs);
|
||||
let current = view.current_tab as i32;
|
||||
*self.models.strip.borrow_mut() = strip;
|
||||
if bridge.get_current_tab() != current {
|
||||
bridge.set_current_tab(current);
|
||||
}
|
||||
bridge.set_current_chat(view.current_tab as i32);
|
||||
let tab = &view.tabs[view.current_tab];
|
||||
// Sessions without stored history push their lines themselves.
|
||||
let mut divider = None;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
use slint::ComponentHandle;
|
||||
use voelin_core::{Command, Contact, Relation};
|
||||
use voelin_model::ChatTarget;
|
||||
|
||||
use crate::app::{App, Bridge, MemberCard, Nav};
|
||||
use crate::settings::ClientPlayback;
|
||||
@@ -88,10 +87,11 @@ impl App {
|
||||
};
|
||||
let (client_id, nickname, uid) = (client.id, client.nickname.clone(), client.uid.clone());
|
||||
match action {
|
||||
// Private chats are on the messages page.
|
||||
"message" => {
|
||||
if let Some(uid) = uid {
|
||||
self.open_chat(ChatTarget::Private(uid), true);
|
||||
self.open_member(-1);
|
||||
self.open_dm_with(Some(id), &uid);
|
||||
}
|
||||
}
|
||||
"watch" => {
|
||||
|
||||
@@ -6,8 +6,12 @@
|
||||
//! A private chat is a chat tab of its session (`ChatTarget::Private`
|
||||
//! stored under the peer's unique id), so opening one selects its server
|
||||
//! and its tab: the chat view's machinery (history pages, the composer)
|
||||
//! serves it. A chat only in the store (its server is not connected, or no
|
||||
//! longer a bookmark) is read from there and shown read-only.
|
||||
//! serves it. The chat strip of the server page leaves these tabs out, so
|
||||
//! leaving the messages page makes the strip's chat current again
|
||||
//! ([`App::close_messages`]), and coming back the open one
|
||||
//! ([`App::messages_shown`]). A chat only in the store (its server is not
|
||||
//! connected, or no longer a bookmark) is read from there and shown
|
||||
//! read-only.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -16,7 +20,9 @@ use voelin_core::{Command, HistoryMessage, OfflineMessage, OfflineMessageInfo, V
|
||||
use voelin_model::ChatTarget;
|
||||
use voelin_store::PageQuery;
|
||||
|
||||
use crate::app::{App, Bridge, ConversationItem, DmPeer, FileItem, Nav, OfflineForm, Page, later};
|
||||
use crate::app::{
|
||||
App, Bridge, ConversationItem, DmPeer, FileItem, Nav, OfflineForm, Page, SessionView, later,
|
||||
};
|
||||
use crate::vm;
|
||||
use crate::vm::social::{ago, list_time, matches, plain, preview};
|
||||
|
||||
@@ -305,11 +311,77 @@ impl App {
|
||||
.collect()
|
||||
};
|
||||
vm::list::sync(&self.models.social.conversations, &items);
|
||||
let unread: i32 = dm.chats.iter().filter(private).map(|c| c.unread).sum();
|
||||
bridge.set_dm_unread(unread);
|
||||
bridge.set_dm_unread(self.dm_unread());
|
||||
bridge.set_inbox_unread(dm.inbox.iter().filter(|(_, m)| !m.read).count() as i32);
|
||||
}
|
||||
|
||||
/// Unread messages in the private chats of every server (the rail and
|
||||
/// the chat strip leave them out).
|
||||
pub(crate) fn dm_unread(&self) -> i32 {
|
||||
self.bookmarks
|
||||
.iter()
|
||||
.filter_map(|b| self.sessions.get(&b.id))
|
||||
.map(SessionView::private_unread)
|
||||
.sum()
|
||||
}
|
||||
|
||||
/// The messages page is shown: the open private chat a session holds is
|
||||
/// the current chat again (leaving the page made the strip's current).
|
||||
pub(crate) fn messages_shown(&mut self) {
|
||||
let Some(Open { session: Some(id), uid, mail: None, stored: false, .. }) =
|
||||
self.social.dm.open.clone()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let target = ChatTarget::Private(uid);
|
||||
// Not for a session that is gone (its server was deleted).
|
||||
let Some(view) = self.sessions.get(&id) else { return };
|
||||
if !view.tabs.iter().any(|t| t.target == target)
|
||||
|| (self.current == Some(id)
|
||||
&& view.tabs.get(view.current_tab).is_some_and(|t| t.target == target))
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.focus_private(id, target);
|
||||
}
|
||||
|
||||
/// Make the private chat `target` session `id`'s current chat, and that
|
||||
/// server the current one. The tab first: selecting the server reads
|
||||
/// the chat it shows, which must not be the strip's.
|
||||
fn focus_private(&mut self, id: i64, target: ChatTarget) {
|
||||
let index = self.chat_tab(id, target.clone());
|
||||
self.sessions.entry(id).or_default().set_current_tab(index);
|
||||
if self.current != Some(id) {
|
||||
self.select_server(id);
|
||||
}
|
||||
self.open_chat(target, true);
|
||||
}
|
||||
|
||||
/// The messages page was left: a session whose current chat is a
|
||||
/// private one goes back to the chat strip's
|
||||
/// ([`SessionView::channel_tab`]).
|
||||
pub(crate) fn close_messages(&mut self) {
|
||||
let mut changed = false;
|
||||
for view in self.sessions.values_mut() {
|
||||
changed |= view.leave_private();
|
||||
}
|
||||
if !changed {
|
||||
return;
|
||||
}
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
// What is read after the callback: a server picked on the rail
|
||||
// (`Nav.select-server` leaves the page first) is selected by then,
|
||||
// and the chat that came back here was never on screen.
|
||||
later(|app| {
|
||||
if let Some(id) = app.current {
|
||||
app.fetch_previews(id);
|
||||
}
|
||||
app.prefetch_counts();
|
||||
app.chat_shown_changed();
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn dm_tab(&mut self, tab: i32) {
|
||||
self.social.dm.tab = tab;
|
||||
if tab == 2 {
|
||||
@@ -397,10 +469,7 @@ impl App {
|
||||
vm::list::sync(&self.models.social.dm_lines, &[]);
|
||||
let target = ChatTarget::Private(uid.to_owned());
|
||||
if let (true, Some(id)) = (live, session) {
|
||||
if self.current != Some(id) {
|
||||
self.select_server(id);
|
||||
}
|
||||
self.open_chat(target, true);
|
||||
self.focus_private(id, target);
|
||||
} else if let Some(server_uid) = server_uid.filter(|_| !self.demo_ui) {
|
||||
let history = self.engine.history();
|
||||
let uid = uid.to_owned();
|
||||
|
||||
@@ -383,7 +383,9 @@ impl App {
|
||||
self.bookmarks.iter().position(|b| b.id == id).map(|i| tints[i]).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The rail: servers with their state, unread count and streams.
|
||||
/// The rail: servers with their state, unread count (without private
|
||||
/// chats) and streams; what the chat strip and the private chats have
|
||||
/// unread.
|
||||
pub(crate) fn refresh_servers(&self) {
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let bridge = ui.global::<Bridge>();
|
||||
@@ -395,7 +397,7 @@ impl App {
|
||||
.map(|(b, tint)| {
|
||||
let view = self.sessions.get(&b.id);
|
||||
let state = view.map(|v| v.state.clone()).unwrap_or_default();
|
||||
let unread = view.map_or(0, |v| v.unread());
|
||||
let unread = view.map_or(0, SessionView::channel_unread);
|
||||
let live = view.is_some_and(|v| v.streams_available() && !v.streams.is_empty());
|
||||
let detail = view
|
||||
.filter(|v| !v.presence.channels.is_empty())
|
||||
@@ -409,7 +411,9 @@ impl App {
|
||||
vm::list::sync(&self.models.servers, &items);
|
||||
bridge.set_last_place(self.last_place(&items));
|
||||
bridge.set_current_server(self.current.map_or(-1, |id| id as i32));
|
||||
bridge.set_unread_total(self.view().map_or(0, |v| v.unread()));
|
||||
// Private chats count on the messages page (and the phone's Home).
|
||||
bridge.set_unread_total(self.view().map_or(0, SessionView::channel_unread));
|
||||
bridge.set_dm_unread(self.dm_unread());
|
||||
}
|
||||
|
||||
/// The server card, the voice controls and who we are.
|
||||
|
||||
@@ -424,6 +424,25 @@ pub fn tab_title(presence: &Presence, target: &ChatTarget, peer: &str) -> String
|
||||
}
|
||||
}
|
||||
|
||||
/// The chat strip of a session's tabs (by their chats, in order): which
|
||||
/// tabs it shows, by their index among all, and which of those is the
|
||||
/// current one (-1 when the current tab is not shown). The server chat and
|
||||
/// the channels' chats are shown; a private chat is on the Direct Messages
|
||||
/// page.
|
||||
pub fn strip<'a>(
|
||||
targets: impl IntoIterator<Item = &'a ChatTarget>,
|
||||
current: usize,
|
||||
) -> (Vec<usize>, i32) {
|
||||
let shown: Vec<usize> = targets
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.filter(|(_, t)| !matches!(t, ChatTarget::Private(_)))
|
||||
.map(|(i, _)| i)
|
||||
.collect();
|
||||
let selected = shown.iter().position(|&i| i == current).map_or(-1, |i| i as i32);
|
||||
(shown, selected)
|
||||
}
|
||||
|
||||
/// A chat tab's name for its header: the title without a private chat's
|
||||
/// "@" (a channel may start with one).
|
||||
pub fn tab_name<'a>(title: &'a str, target: &ChatTarget) -> &'a str {
|
||||
@@ -843,6 +862,44 @@ mod tests {
|
||||
assert_eq!(tab_name("@home", &ChatTarget::Channel(4)), "@home");
|
||||
}
|
||||
|
||||
fn targets() -> Vec<ChatTarget> {
|
||||
vec![
|
||||
ChatTarget::Server,
|
||||
ChatTarget::Private("a".into()),
|
||||
ChatTarget::Channel(1),
|
||||
ChatTarget::Private("b".into()),
|
||||
ChatTarget::Channel(2),
|
||||
]
|
||||
}
|
||||
|
||||
/// Private chats are on the Direct Messages page, not in the strip.
|
||||
#[test]
|
||||
fn strip_hides_private() {
|
||||
let targets = targets();
|
||||
assert_eq!(strip(&targets, 2), (vec![0, 2, 4], 1));
|
||||
assert_eq!(strip(&targets, 4), (vec![0, 2, 4], 2));
|
||||
assert_eq!(strip(&[], 0), (vec![], -1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_current_private_is_minus_one() {
|
||||
let targets = targets();
|
||||
assert_eq!(strip(&targets, 1).1, -1);
|
||||
assert_eq!(strip(&targets, 3).1, -1);
|
||||
// A current tab that is gone selects nothing either.
|
||||
assert_eq!(strip(&targets, 9).1, -1);
|
||||
}
|
||||
|
||||
/// The server chat is the strip's first tab, before private chats too.
|
||||
#[test]
|
||||
fn strip_server_tab_first() {
|
||||
let targets = targets();
|
||||
let (shown, selected) = strip(&targets, 0);
|
||||
assert_eq!((shown[0], selected), (0, 0));
|
||||
let only = [ChatTarget::Server, ChatTarget::Private("a".into())];
|
||||
assert_eq!(strip(&only, 0), (vec![0], 0));
|
||||
}
|
||||
|
||||
/// The header counts pins and topics only once the gateway sent them.
|
||||
#[test]
|
||||
fn counts_are_unknown_until_loaded() {
|
||||
|
||||
Reference in new issue
Block a user