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
180 lines
6.3 KiB
Rust
180 lines
6.3 KiB
Rust
//! The members panel: the card over a member row and what it can do
|
|
//! (private chat, poke, contacts, per-client volume). The rows themselves
|
|
//! are built in `vm::tree::members`.
|
|
|
|
use slint::ComponentHandle;
|
|
use voelin_core::{Command, Contact, Relation};
|
|
|
|
use crate::app::{App, Bridge, MemberCard, Nav};
|
|
use crate::settings::ClientPlayback;
|
|
use crate::vm;
|
|
|
|
impl App {
|
|
/// `VOELIN_OPEN=member`: the card of the first person that is not us.
|
|
pub(crate) fn open_first_member(&mut self) {
|
|
let Some(view) = self.view() else { return };
|
|
let own = view.state.own_client;
|
|
let mut others: Vec<u16> = view
|
|
.presence
|
|
.members(view.state.own_channel.unwrap_or_default())
|
|
.filter(|c| Some(c.id) != own)
|
|
.map(|c| c.id)
|
|
.collect();
|
|
others.sort_unstable();
|
|
if let Some(id) = others.first().copied() {
|
|
self.open_member(i32::from(id));
|
|
}
|
|
}
|
|
|
|
/// Open the card of a client (`-1` closes it).
|
|
pub(crate) fn open_member(&mut self, client: i32) {
|
|
if let Some(view) = self.view_mut() {
|
|
view.member_card = u16::try_from(client).ok();
|
|
}
|
|
self.refresh_member_card();
|
|
}
|
|
|
|
pub(crate) fn refresh_member_card(&self) {
|
|
let Some(ui) = self.ui.upgrade() else { return };
|
|
let bridge = ui.global::<Bridge>();
|
|
let card = self
|
|
.view()
|
|
.and_then(|view| {
|
|
let id = view.member_card?;
|
|
let client = view.presence.clients.get(&id)?;
|
|
let uid = client.uid.clone();
|
|
let contact = uid.as_ref().and_then(|u| self.contacts.get(u));
|
|
let playback =
|
|
uid.as_ref().and_then(|u| self.playback.get(u)).copied().unwrap_or_default();
|
|
let groups: Vec<slint::SharedString> = client
|
|
.server_groups
|
|
.iter()
|
|
.filter_map(|g| view.server_groups.iter().find(|i| i.id == *g))
|
|
.map(|g| g.name.clone().into())
|
|
.collect();
|
|
let badges = vm::tree::badge_items(&client.badges, &view.pictures);
|
|
Some(MemberCard {
|
|
open: true,
|
|
id: i32::from(id),
|
|
name: client.nickname.clone().into(),
|
|
initials: vm::avatar::initials(&client.nickname).into(),
|
|
tint: vm::avatar::tint(&client.nickname),
|
|
avatar: vm::avatar::image(view.avatar(id)),
|
|
status: vm::tree::status_of(client, view.talking.contains(&id)).into(),
|
|
description: client.description.clone().unwrap_or_default().into(),
|
|
groups: crate::app::model(groups),
|
|
badges: crate::app::model(badges),
|
|
country: client.country.clone().unwrap_or_default().into(),
|
|
talk_power: client.talk_power,
|
|
friend: contact.is_some_and(|c| c.relation == Relation::Friend),
|
|
blocked: contact.is_some_and(|c| c.relation == Relation::Blocked),
|
|
volume: playback.volume * 100.0,
|
|
muted: playback.muted,
|
|
known: uid.is_some(),
|
|
streaming: client.streaming == Some(true),
|
|
})
|
|
})
|
|
.unwrap_or_default();
|
|
bridge.set_member_card(card);
|
|
}
|
|
|
|
/// The card's buttons: "message", "poke", "friend", "blocked", "mute".
|
|
pub(crate) fn member_action(&mut self, action: &str) {
|
|
let Some(id) = self.current else { return };
|
|
let Some(view) = self.sessions.get(&id) else { return };
|
|
let Some(client) = view.member_card.and_then(|c| view.presence.clients.get(&c)) else {
|
|
return;
|
|
};
|
|
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_member(-1);
|
|
self.open_dm_with(Some(id), &uid);
|
|
}
|
|
}
|
|
"watch" => {
|
|
self.open_member(-1);
|
|
self.watch_client(client_id);
|
|
}
|
|
"poke" => self.ask_poke(id, client_id),
|
|
"friend" | "blocked" => {
|
|
let Some(uid) = uid else { return };
|
|
let wanted = if action == "friend" { Relation::Friend } else { Relation::Blocked };
|
|
let current = self.contacts.get(&uid).map(|c| c.relation);
|
|
let mut contact =
|
|
self.contacts.get(&uid).cloned().unwrap_or_else(|| Contact::new(uid.clone()));
|
|
contact.nickname = nickname;
|
|
contact.relation = if current == Some(wanted) { Relation::Neutral } else { wanted };
|
|
self.contacts.insert(uid, contact.clone());
|
|
self.engine.send(Command::SetContact { contact: Box::new(contact) });
|
|
self.refresh_member_card();
|
|
}
|
|
"mute" => {
|
|
let Some(uid) = uid else { return };
|
|
let mut playback = self.playback.get(&uid).copied().unwrap_or_default();
|
|
playback.muted = !playback.muted;
|
|
self.set_playback(&uid, client_id, playback);
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
/// Open the poke dialog for a client (the member card, a contact).
|
|
pub(crate) fn ask_poke(&mut self, session: i64, client: u16) {
|
|
let Some(view) = self.sessions.get(&session) else { return };
|
|
let name = view.nickname(client);
|
|
self.poke_target = Some((session, client, name.clone()));
|
|
let Some(ui) = self.ui.upgrade() else { return };
|
|
let nav = ui.global::<Nav>();
|
|
nav.set_poke_name(name.into());
|
|
nav.set_poke_open(true);
|
|
}
|
|
|
|
/// The poke dialog's Send, with its message (may be empty).
|
|
pub(crate) fn send_poke(&mut self, text: &str) {
|
|
let Some((session, client, name)) = self.poke_target.take() else { return };
|
|
if !self.demo_ui {
|
|
self.engine.send(Command::Poke {
|
|
session: session as u64,
|
|
client,
|
|
message: vm::social::poke_message(text),
|
|
});
|
|
}
|
|
self.set_status(format!("Poked {name}"));
|
|
}
|
|
|
|
/// The card's volume slider, in percent.
|
|
pub(crate) fn member_volume(&mut self, percent: f32) {
|
|
let Some(view) = self.view() else { return };
|
|
let Some(client) = view.member_card.and_then(|c| view.presence.clients.get(&c)) else {
|
|
return;
|
|
};
|
|
let (client_id, Some(uid)) = (client.id, client.uid.clone()) else { return };
|
|
let mut playback = self.playback.get(&uid).copied().unwrap_or_default();
|
|
playback.volume = (percent / 100.0).clamp(0.0, 4.0);
|
|
self.set_playback(&uid, client_id, playback);
|
|
}
|
|
|
|
/// Store one client's playback and apply it to the session.
|
|
fn set_playback(&mut self, uid: &str, client: u16, playback: ClientPlayback) {
|
|
if playback.is_default() {
|
|
self.playback.remove(uid);
|
|
} else {
|
|
self.playback.insert(uid.to_owned(), playback);
|
|
}
|
|
if let Err(e) = self.prefs.set(&crate::settings::CLIENT_PLAYBACK, self.playback.clone()) {
|
|
tracing::warn!(%e, "could not store client volumes");
|
|
}
|
|
self.command(|session| Command::SetClientMuted { session, client, muted: playback.muted });
|
|
self.command(|session| Command::SetClientVolume {
|
|
session,
|
|
client,
|
|
volume: playback.volume,
|
|
});
|
|
self.refresh_tree();
|
|
self.refresh_member_card();
|
|
}
|
|
}
|