ui: a New line above the first unread message, and read markers kept on disk
Messages count as read only while their chat is on screen (Nav.chat-shown) in the focused window: winit's focus events, through slint's unstable-winit-030 on the desktop; Android counts a chat on screen as read. A tab keeps the newest message read and counts what came after it, not our own. Entering a tab with new messages puts a red New line above the first one until the tab is left (so does a stored or gateway page that brings them while the tab is on screen), and while that line is above the view a bar over the list counts them, with Jump and Mark as read. voelin-store migration 5 adds chat_reads (Store::chat_read, set_chat_read, chat_reads). Markers are loaded once a session's server is known and written when a tab is left, marked read, its session ends and on exit, never per message; a restart counts what came while away again, gateway pages included. Dev switch VOELIN_OPEN=unread[:end]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
20 files changed
+877
-128
No files matched your search
@@ -16,7 +16,8 @@
|
||||
//! of the other, or (without both unique ids) the same nickname.
|
||||
//!
|
||||
//! Pages are by time: `(ts_ms, id)` orders a chat ([`PageQuery`]). A
|
||||
//! [`ChatCursor`] remembers how far a chat is synced with a gateway.
|
||||
//! [`ChatCursor`] remembers how far a chat is synced with a gateway, a
|
||||
//! [`ChatRead`] how far it was read on this device.
|
||||
|
||||
use rusqlite::{OptionalExtension, Row, Transaction, params};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -226,6 +227,31 @@ pub struct ChatCursor {
|
||||
pub updated_ms: i64,
|
||||
}
|
||||
|
||||
/// How far a chat was read on this device: the newest message read, by
|
||||
/// `(ts_ms, id)` as a chat is ordered. TeamSpeak has no read receipts, so
|
||||
/// this stays on the device.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct ChatRead {
|
||||
/// Unix milliseconds of the message.
|
||||
pub ts_ms: i64,
|
||||
/// Its local id ([`StoredMessage::id`]).
|
||||
pub id: i64,
|
||||
/// Unix milliseconds of the last change.
|
||||
pub updated_ms: i64,
|
||||
}
|
||||
|
||||
/// Version 5: how far each chat was read ([`ChatRead`]).
|
||||
pub(crate) const SCHEMA_5: &str = r#"
|
||||
CREATE TABLE chat_reads (
|
||||
server_uid TEXT NOT NULL,
|
||||
target TEXT NOT NULL,
|
||||
read_ms INTEGER NOT NULL,
|
||||
read_id INTEGER NOT NULL DEFAULT 0,
|
||||
updated_ms INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (server_uid, target)
|
||||
) WITHOUT ROWID;
|
||||
"#;
|
||||
|
||||
/// Version 2: times in milliseconds, sources, gateway ids and metadata,
|
||||
/// dedupe keys, sync cursors and server aliases. Old messages keep their
|
||||
/// data (source `local`, their second times in milliseconds).
|
||||
@@ -686,6 +712,53 @@ impl Store {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// How far a chat was read on this device.
|
||||
pub fn chat_read(&self, server_uid: &str, target: &ChatTarget) -> Result<Option<ChatRead>> {
|
||||
Ok(self
|
||||
.db
|
||||
.prepare_cached(
|
||||
"SELECT read_ms, read_id, updated_ms FROM chat_reads
|
||||
WHERE server_uid = ?1 AND target = ?2",
|
||||
)?
|
||||
.query_row(params![server_uid, target.key()], |r| {
|
||||
Ok(ChatRead { ts_ms: r.get(0)?, id: r.get(1)?, updated_ms: r.get(2)? })
|
||||
})
|
||||
.optional()?)
|
||||
}
|
||||
|
||||
/// How far each chat of a server was read on this device.
|
||||
pub fn chat_reads(&self, server_uid: &str) -> Result<Vec<(ChatTarget, ChatRead)>> {
|
||||
let mut stmt = self.db.prepare_cached(
|
||||
"SELECT target, read_ms, read_id, updated_ms FROM chat_reads
|
||||
WHERE server_uid = ?1 ORDER BY target",
|
||||
)?;
|
||||
let rows = stmt.query_map([server_uid], |r| {
|
||||
let target: String = r.get(0)?;
|
||||
let read = ChatRead { ts_ms: r.get(1)?, id: r.get(2)?, updated_ms: r.get(3)? };
|
||||
Ok((ChatTarget::from_key(&target), read))
|
||||
})?;
|
||||
Ok(rows.collect::<rusqlite::Result<_>>()?)
|
||||
}
|
||||
|
||||
/// Remember how far a chat was read on this device (replacing what was
|
||||
/// there).
|
||||
pub fn set_chat_read(
|
||||
&self,
|
||||
server_uid: &str,
|
||||
target: &ChatTarget,
|
||||
read: &ChatRead,
|
||||
) -> Result<()> {
|
||||
self.db
|
||||
.prepare_cached(
|
||||
"INSERT INTO chat_reads (server_uid, target, read_ms, read_id, updated_ms)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5)
|
||||
ON CONFLICT (server_uid, target) DO UPDATE SET read_ms = excluded.read_ms,
|
||||
read_id = excluded.read_id, updated_ms = excluded.updated_ms",
|
||||
)?
|
||||
.execute(params![server_uid, target.key(), read.ts_ms, read.id, read.updated_ms])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Forget the gateway ids of a chat (another gateway numbers its
|
||||
/// messages differently) and its cursor; the rows stay, as seen by this
|
||||
/// device, and are matched again with the new gateway's copies.
|
||||
@@ -962,6 +1035,25 @@ mod tests {
|
||||
assert_eq!(store.server_alias("voice:host").unwrap().as_deref(), Some("uid2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_markers() {
|
||||
let store = Store::open_in_memory().unwrap();
|
||||
let (channel, dm) = (ChatTarget::Channel(1), ChatTarget::Private("uid-b".into()));
|
||||
assert_eq!(store.chat_read(SRV, &channel).unwrap(), None);
|
||||
assert!(store.chat_reads(SRV).unwrap().is_empty());
|
||||
let read = ChatRead { ts_ms: 1_000, id: 7, updated_ms: 5 };
|
||||
store.set_chat_read(SRV, &channel, &read).unwrap();
|
||||
assert_eq!(store.chat_read(SRV, &channel).unwrap(), Some(read));
|
||||
// Set again: the same row, moved.
|
||||
let later = ChatRead { ts_ms: 2_000, id: 9, updated_ms: 6 };
|
||||
store.set_chat_read(SRV, &channel, &later).unwrap();
|
||||
assert_eq!(store.chat_read(SRV, &channel).unwrap(), Some(later));
|
||||
store.set_chat_read(SRV, &dm, &read).unwrap();
|
||||
store.set_chat_read("other", &channel, &read).unwrap();
|
||||
assert_eq!(store.chat_reads(SRV).unwrap(), [(channel.clone(), later), (dm, read)]);
|
||||
assert_eq!(store.chat_reads("other").unwrap(), [(channel, read)]);
|
||||
}
|
||||
|
||||
/// A database of version 1 with messages is upgraded in place.
|
||||
#[test]
|
||||
fn migrates_version_1_with_data() {
|
||||
|
||||
@@ -14,7 +14,7 @@ mod secrets;
|
||||
mod store;
|
||||
|
||||
pub use chat::{
|
||||
ChatCursor, ChatTarget, MessageSource, NewMessage, PageQuery, Reaction, RemoteInfo,
|
||||
ChatCursor, ChatRead, ChatTarget, MessageSource, NewMessage, PageQuery, Reaction, RemoteInfo,
|
||||
StoredMessage, SyncState, WriteOutcome, Written,
|
||||
};
|
||||
pub use contacts::{Contact, ContactSeen, Relation};
|
||||
|
||||
@@ -23,6 +23,7 @@ const MIGRATIONS: &[Migration] = &[
|
||||
Migration::Code(crate::chat::migrate_2),
|
||||
Migration::Sql(crate::contacts::SCHEMA_3),
|
||||
Migration::Sql(SCHEMA_4),
|
||||
Migration::Sql(crate::chat::SCHEMA_5),
|
||||
];
|
||||
|
||||
/// Version 4: where each identity came from ([`IdentityOrigin`]) and which
|
||||
@@ -531,6 +532,48 @@ mod tests {
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
/// A database of version 4 learns where its chats were read, keeping
|
||||
/// its messages; nothing is read yet.
|
||||
#[test]
|
||||
fn migrates_version_4_read_markers() {
|
||||
use crate::{ChatRead, ChatTarget, PageQuery};
|
||||
let dir = std::env::temp_dir().join(format!("voelin-store-v4-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("client.db");
|
||||
{
|
||||
let mut db = rusqlite::Connection::open(&path).unwrap();
|
||||
db.execute_batch(SCHEMA_1).unwrap();
|
||||
let tx = db.transaction().unwrap();
|
||||
crate::chat::migrate_2(&tx).unwrap();
|
||||
tx.commit().unwrap();
|
||||
db.execute_batch(crate::contacts::SCHEMA_3).unwrap();
|
||||
db.execute_batch(SCHEMA_4).unwrap();
|
||||
db.pragma_update(None, "user_version", 4).unwrap();
|
||||
db.execute(
|
||||
"INSERT INTO messages (server_uid, target, ts, ts_ms, author_name, text)
|
||||
VALUES ('srv', 'channel/1', 1, 1000, 'a', 'kept')",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let store = Store::open(&path).unwrap();
|
||||
assert_eq!(Store::SCHEMA_VERSION, 5);
|
||||
assert_eq!(store.schema_version().unwrap(), Store::SCHEMA_VERSION);
|
||||
let channel = ChatTarget::Channel(1);
|
||||
let rows = store.messages("srv", &channel, PageQuery::default()).unwrap();
|
||||
assert_eq!(rows.len(), 1);
|
||||
assert!(store.chat_reads("srv").unwrap().is_empty());
|
||||
let read = ChatRead { ts_ms: rows[0].ts_ms, id: rows[0].id, updated_ms: 1 };
|
||||
store.set_chat_read("srv", &channel, &read).unwrap();
|
||||
drop(store);
|
||||
// Opened again: the marker is there and nothing runs twice.
|
||||
let store = Store::open(&path).unwrap();
|
||||
assert_eq!(store.chat_read("srv", &channel).unwrap(), Some(read));
|
||||
drop(store);
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bookmarks_keep_order_and_fields() {
|
||||
let store = Store::open_in_memory().unwrap();
|
||||
|
||||
@@ -50,7 +50,9 @@ tsclientlib = { path = "../proto/tsclientlib" }
|
||||
# and PipeWire, global hotkeys through the portal and X11.
|
||||
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||
voelin-myts = { path = "../voelin-myts" }
|
||||
slint = { version = "1.18", features = ["renderer-software"] }
|
||||
# winit's focus events (an unstable API, so this minor version only):
|
||||
# messages are read only while the window has the focus (`app::watch_focus`).
|
||||
slint = { version = "~1.18", features = ["renderer-software", "unstable-winit-030"] }
|
||||
voelin-core = { path = "../voelin-core", default-features = false, features = ["media-desktop"] }
|
||||
voelin-platform = { path = "../voelin-platform" }
|
||||
voelin-store = { path = "../voelin-store", features = ["keyring"] }
|
||||
|
||||
+115
-2
@@ -24,9 +24,10 @@ use voelin_core::settings::{
|
||||
};
|
||||
use voelin_core::stream::StreamInfo;
|
||||
use voelin_core::{
|
||||
AudioSettings, Command, Engine, Event, History, HistoryMessage, SessionState, VoiceState,
|
||||
AudioSettings, Command, Engine, Event, History, HistoryMessage, ObserveState, SessionState,
|
||||
VoiceState,
|
||||
};
|
||||
use voelin_model::{Capabilities, ChannelId, ChatTarget, GroupInfo, Presence};
|
||||
use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, GroupInfo, Presence};
|
||||
use voelin_platform::crash;
|
||||
use voelin_store::{Bookmark, MemorySecrets, Secrets, Store};
|
||||
|
||||
@@ -144,7 +145,17 @@ pub(crate) struct Tab {
|
||||
/// Live messages of a session that keeps no history (no server unique
|
||||
/// id yet): grouped from the message before, without ids.
|
||||
pub last: Option<Previous>,
|
||||
/// Messages not read, not ours: those after `read` (without stored
|
||||
/// history, those that came while the tab was not on screen).
|
||||
pub unread: i32,
|
||||
/// The newest message read, by `(ts_ms, id)`: kept in the store
|
||||
/// (`chat_reads`) when the tab is left, the session closes and on exit
|
||||
/// (`App::save_read`). `stored_read` is what the store has.
|
||||
pub read: Option<(i64, i64)>,
|
||||
pub stored_read: Option<(i64, i64)>,
|
||||
/// The message the "New" divider is above: the first that was new when
|
||||
/// the tab came on screen. It stays until the tab is left.
|
||||
pub divider: Option<i64>,
|
||||
/// Nothing older exists as far as the engine can tell.
|
||||
pub complete: bool,
|
||||
/// A gateway page arrived: the chat is not only what we saw.
|
||||
@@ -176,6 +187,9 @@ impl Tab {
|
||||
messages: Vec::new(),
|
||||
last: None,
|
||||
unread: 0,
|
||||
read: None,
|
||||
stored_read: None,
|
||||
divider: None,
|
||||
complete: false,
|
||||
synced: false,
|
||||
loading: false,
|
||||
@@ -200,6 +214,50 @@ impl Tab {
|
||||
pub fn message(&self, key: i32) -> Option<&HistoryMessage> {
|
||||
self.messages.iter().chain(&self.topic_messages).find(|m| m.key == key).map(|m| &m.message)
|
||||
}
|
||||
|
||||
/// Where each message is and whether it is ours (`own`), for the read
|
||||
/// markers ([`crate::vm::chat::first_unread`]).
|
||||
pub fn positions(&self, own: impl Fn(&ChatMessage) -> bool) -> Vec<(i64, i64, bool)> {
|
||||
self.messages
|
||||
.iter()
|
||||
.map(|m| (m.message.message.ts_ms, m.message.id, own(&m.message.message)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Where the newest message is.
|
||||
pub fn newest(&self) -> Option<(i64, i64)> {
|
||||
self.messages.last().map(|m| (m.message.message.ts_ms, m.message.id))
|
||||
}
|
||||
|
||||
/// The tab came on screen: the first new message gets the divider
|
||||
/// (unless one shows), and everything is read.
|
||||
pub fn enter(&mut self, own: impl Fn(&ChatMessage) -> bool) {
|
||||
if self.unread > 0 && self.divider.is_none() {
|
||||
let first = crate::vm::chat::first_unread(&self.positions(own), self.read);
|
||||
self.divider = first.map(|i| self.messages[i].message.id);
|
||||
}
|
||||
self.catch_up();
|
||||
}
|
||||
|
||||
/// Everything in the tab is read (it is on screen).
|
||||
pub fn catch_up(&mut self) {
|
||||
self.read = self.read.max(self.newest());
|
||||
self.unread = 0;
|
||||
}
|
||||
|
||||
/// Count what is not read: what came after `read`, not ours.
|
||||
pub fn count_unread(&mut self, own: impl Fn(&ChatMessage) -> bool) {
|
||||
self.unread = crate::vm::chat::unread_count(&self.positions(own), self.read);
|
||||
}
|
||||
|
||||
/// Start from where the store says the chat was read (`reads`: by the
|
||||
/// store's name of the chat).
|
||||
pub fn read_from(&mut self, reads: &HashMap<String, (i64, i64)>) {
|
||||
if let Some(&read) = reads.get(&crate::chat::store_target(&self.target).key()) {
|
||||
self.read = self.read.max(Some(read));
|
||||
self.stored_read = Some(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What we know about one server session.
|
||||
@@ -251,6 +309,10 @@ pub(crate) struct SessionView {
|
||||
pub next_transfer: u64,
|
||||
/// What the home, messages and events screens keep of the session.
|
||||
pub extra: crate::social::SessionExtra,
|
||||
/// Where its chats were read, from the store (by the store's name of
|
||||
/// the chat), for the server unique id `reads_of`.
|
||||
pub reads: HashMap<String, (i64, i64)>,
|
||||
pub reads_of: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for SessionView {
|
||||
@@ -281,6 +343,8 @@ impl Default for SessionView {
|
||||
downloads: HashMap::new(),
|
||||
next_transfer: 1,
|
||||
extra: Default::default(),
|
||||
reads: HashMap::new(),
|
||||
reads_of: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -317,6 +381,13 @@ impl SessionView {
|
||||
self.tabs.iter().map(|t| t.unread).sum()
|
||||
}
|
||||
|
||||
/// A new tab for `target`, read as far as the store says.
|
||||
pub fn new_tab(&self, target: ChatTarget, title: String) -> Tab {
|
||||
let mut tab = Tab::new(target, title);
|
||||
tab.read_from(&self.reads);
|
||||
tab
|
||||
}
|
||||
|
||||
/// The session's gateway offers this feature
|
||||
/// (`voelin_gateway_proto::feature`).
|
||||
pub fn gateway_has(&self, feature: &str) -> bool {
|
||||
@@ -469,6 +540,12 @@ pub(crate) struct App {
|
||||
pub join_target: Option<(i64, ChannelId)>,
|
||||
/// Who the poke dialog pokes: session, client, nickname.
|
||||
pub poke_target: Option<(i64, u16, String)>,
|
||||
/// The window has the focus (desktop: winit tells; elsewhere assumed):
|
||||
/// messages are read only then.
|
||||
pub focused: bool,
|
||||
/// The chat whose messages are on screen (session, target): when it is
|
||||
/// left, it is stored and loses its divider (`App::track_reading`).
|
||||
pub reading: Option<(i64, ChatTarget)>,
|
||||
pub mic_test: bool,
|
||||
pub ptt: GlobalPtt,
|
||||
pub video: Video,
|
||||
@@ -662,6 +739,8 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
bridge.set_app_name(voelin_platform::APP_NAME.into());
|
||||
bridge.set_app_version(env!("CARGO_PKG_VERSION").into());
|
||||
bridge.set_desktop(cfg!(not(target_os = "android")));
|
||||
#[cfg(not(target_os = "android"))]
|
||||
watch_focus(&ui);
|
||||
let models = Models::new(&bridge);
|
||||
// Wayland and X11 find the desktop file (and icon) by this id.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
@@ -712,6 +791,8 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
playback_dialog: None,
|
||||
join_target: None,
|
||||
poke_target: None,
|
||||
focused: true,
|
||||
reading: None,
|
||||
mic_test: false,
|
||||
ptt,
|
||||
video,
|
||||
@@ -786,6 +867,10 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
if let Err(e) = app.prefs.flush() {
|
||||
warn!(%e, "could not store settings");
|
||||
}
|
||||
let ids: Vec<i64> = app.sessions.keys().copied().collect();
|
||||
for id in ids {
|
||||
app.save_reads(id);
|
||||
}
|
||||
app.watch = None;
|
||||
app.share = None;
|
||||
if own && !app.demo_ui {
|
||||
@@ -805,6 +890,20 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Tell the app when the window gains or loses the focus: messages are read
|
||||
/// only while it has it. (winit's focus events; without them, as on
|
||||
/// Android, the window counts as focused.)
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn watch_focus(ui: &MainWindow) {
|
||||
use slint::winit_030::{EventResult, WinitWindowAccessor, winit::event::WindowEvent};
|
||||
ui.window().on_winit_window_event(|_, event| {
|
||||
if let WindowEvent::Focused(focused) = *event {
|
||||
later(move |app| app.window_focused(focused));
|
||||
}
|
||||
EventResult::Propagate
|
||||
});
|
||||
}
|
||||
|
||||
/// Open a file or folder with the desktop's default application.
|
||||
pub(crate) fn open_path(path: &Path) -> std::io::Result<()> {
|
||||
open_target(path.as_os_str())
|
||||
@@ -922,6 +1021,7 @@ impl App {
|
||||
let id = session as i64;
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let was_voice = view.state.voice;
|
||||
let was_observe = view.state.observe;
|
||||
view.state = state.clone();
|
||||
if state.voice != VoiceState::Connected {
|
||||
view.focused_own_channel = false;
|
||||
@@ -935,11 +1035,24 @@ impl App {
|
||||
// A new connection: volumes are sent again.
|
||||
view.applied_playback.clear();
|
||||
}
|
||||
// Where its chats were read, once the server is known; kept
|
||||
// when the session ends.
|
||||
self.load_reads(id);
|
||||
let off = |voice: VoiceState, observe: ObserveState| {
|
||||
voice == VoiceState::Disconnected && observe == ObserveState::Off
|
||||
};
|
||||
if off(state.voice, state.observe) && !off(was_voice, was_observe) {
|
||||
self.save_reads(id);
|
||||
}
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let focus = !view.focused_own_channel;
|
||||
if state.voice == VoiceState::Connected && was_voice != VoiceState::Connected {
|
||||
self.set_status("Connected");
|
||||
}
|
||||
if self.current == Some(id) {
|
||||
if self.track_reading() {
|
||||
self.refresh_chat();
|
||||
}
|
||||
// The voice channel's chat is always at hand, and focused
|
||||
// once per connection.
|
||||
if let (Some(cid), VoiceState::Connected) = (state.own_channel, state.voice) {
|
||||
|
||||
@@ -25,6 +25,12 @@ pub(super) fn wire(ui: &MainWindow) {
|
||||
bridge.on_load_older(|| {
|
||||
with_app(App::load_older);
|
||||
});
|
||||
bridge.on_mark_read(|| {
|
||||
with_app(App::mark_read);
|
||||
});
|
||||
bridge.on_chat_shown_changed(|| {
|
||||
with_app(App::chat_shown_changed);
|
||||
});
|
||||
bridge.on_react(|key, emoji| {
|
||||
with_app(|app| app.react(key, emoji.to_string()));
|
||||
});
|
||||
|
||||
+226
-16
@@ -7,6 +7,12 @@
|
||||
//! the selected tab are rebuilt from them with [`vm::list::sync`], which
|
||||
//! touches only the rows that changed. Sessions the engine keeps no history
|
||||
//! for (it does not know the server yet) fall back to [`Event::Chat`].
|
||||
//!
|
||||
//! Messages are read while their tab is on screen in the focused window
|
||||
//! ([`App::track_reading`]). A tab remembers the newest message read
|
||||
//! (`Tab::read`, kept in the store's `chat_reads`), counts what came after
|
||||
//! it, and when it comes on screen shows a "New" divider above the first
|
||||
//! of those until it is left.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
@@ -20,6 +26,7 @@ use voelin_core::{
|
||||
};
|
||||
use voelin_gateway_proto::{ErrorCode, TopicInfo, feature};
|
||||
use voelin_model::{ChatMessage, ChatTarget, HostMessageMode, ServerDetails};
|
||||
use voelin_store::ChatRead;
|
||||
|
||||
use crate::app::{App, Bridge, ChatLine, ChatTab, FileItem, Msg, Nav, PinItem, SessionView, Tab};
|
||||
use crate::settings::UI_IMAGE_PREVIEW_KB;
|
||||
@@ -52,6 +59,15 @@ pub(crate) fn server_text<'a>(view: &'a SessionView, tab: &Tab, key: i32) -> Opt
|
||||
server_texts(&view.presence.server).get((-1 - key) as usize).map(|(text, _)| *text)
|
||||
}
|
||||
|
||||
/// The store's name of a chat.
|
||||
pub(crate) fn store_target(target: &ChatTarget) -> voelin_store::ChatTarget {
|
||||
match target {
|
||||
ChatTarget::Server => voelin_store::ChatTarget::Server,
|
||||
ChatTarget::Channel(cid) => voelin_store::ChatTarget::Channel(*cid),
|
||||
ChatTarget::Private(uid) => voelin_store::ChatTarget::Private(uid.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
/// A file being downloaded from a chat message.
|
||||
pub(crate) struct Download {
|
||||
/// The message's handle and which of its links this is.
|
||||
@@ -103,7 +119,8 @@ impl App {
|
||||
let index = match view.tabs.iter().position(|t| t.target == target) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
view.tabs.push(Tab::new(target.clone(), title));
|
||||
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 });
|
||||
}
|
||||
@@ -112,7 +129,7 @@ impl App {
|
||||
};
|
||||
if focus {
|
||||
view.current_tab = index;
|
||||
view.tabs[index].unread = 0;
|
||||
self.track_reading();
|
||||
}
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
@@ -123,12 +140,12 @@ impl App {
|
||||
&& index < view.tabs.len()
|
||||
{
|
||||
view.current_tab = index;
|
||||
view.tabs[index].unread = 0;
|
||||
view.tabs[index].topic = None;
|
||||
}
|
||||
if let Some(id) = self.current {
|
||||
self.fetch_previews(id);
|
||||
}
|
||||
self.track_reading();
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
}
|
||||
@@ -139,10 +156,14 @@ impl App {
|
||||
if index == 0 || index >= view.tabs.len() {
|
||||
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);
|
||||
self.engine.send(Command::CloseChat { session: id as u64, target: tab.target });
|
||||
self.track_reading();
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
}
|
||||
|
||||
pub(crate) fn send_message(&mut self, text: String) {
|
||||
@@ -161,7 +182,8 @@ impl App {
|
||||
match view.tabs.iter().position(|t| t.target == *target) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
view.tabs.push(Tab::new(target.clone(), title()));
|
||||
let tab = view.new_tab(target.clone(), title());
|
||||
view.tabs.push(tab);
|
||||
view.tabs.len() - 1
|
||||
}
|
||||
}
|
||||
@@ -186,21 +208,24 @@ impl App {
|
||||
/// comes, without an id.
|
||||
pub(crate) fn add_message(&mut self, id: i64, message: ChatMessage) {
|
||||
let current = self.current == Some(id);
|
||||
let reading = self.reads_now(id);
|
||||
let new = !self.is_own(id, &message);
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let title = Self::tab_title(view, &message.target, &message.author_name);
|
||||
let index = Self::tab_for(view, &message.target, || title);
|
||||
let shown = current && view.current_tab == index;
|
||||
let seen = reading && view.current_tab == index;
|
||||
let tab = &mut view.tabs[index];
|
||||
let line = vm::chat::line(&message, tab.last.as_ref());
|
||||
tab.last = Some(Previous::of(&message));
|
||||
tab.lines.push(line);
|
||||
if !shown {
|
||||
let counted = new && !seen;
|
||||
if counted {
|
||||
tab.unread += 1;
|
||||
}
|
||||
if current {
|
||||
self.refresh_chat();
|
||||
}
|
||||
if !shown {
|
||||
if counted {
|
||||
self.refresh_servers();
|
||||
}
|
||||
self.studio_chat_changed(id, &message.target);
|
||||
@@ -216,6 +241,7 @@ impl App {
|
||||
complete: bool,
|
||||
) {
|
||||
let current = self.current == Some(id);
|
||||
let reading = self.reads_now(id);
|
||||
// A private chat is named after the peer, whoever wrote first.
|
||||
let peer = match target {
|
||||
ChatTarget::Private(uid) => Some(format!(
|
||||
@@ -231,7 +257,8 @@ impl App {
|
||||
let author = messages.first().map_or("", |m| m.message.author_name.as_str());
|
||||
let title = peer.unwrap_or_else(|| Self::tab_title(view, target, author));
|
||||
let index = Self::tab_for(view, target, || title);
|
||||
let shown = current && view.current_tab == index;
|
||||
let seen = reading && view.current_tab == index;
|
||||
let own_client = view.state.own_client;
|
||||
let tab = &mut view.tabs[index];
|
||||
if source == HistorySource::Gateway {
|
||||
tab.synced = true;
|
||||
@@ -240,28 +267,49 @@ impl App {
|
||||
tab.loading = false;
|
||||
tab.complete = tab.complete || complete;
|
||||
}
|
||||
let mut fresh = 0;
|
||||
// Without a marker, what the tab holds was read.
|
||||
if tab.read.is_none() {
|
||||
tab.read = tab.newest();
|
||||
}
|
||||
for message in messages {
|
||||
match tab.messages.iter().position(|m| m.message.id == message.id) {
|
||||
Some(i) => tab.messages[i].message = message,
|
||||
None => {
|
||||
let key = tab.take_key();
|
||||
if source == HistorySource::Live {
|
||||
fresh += 1;
|
||||
}
|
||||
tab.messages.push(Msg { key, message });
|
||||
}
|
||||
}
|
||||
}
|
||||
tab.messages.sort_by_key(|m| (m.message.message.ts_ms, m.message.id));
|
||||
if !shown {
|
||||
tab.unread += fresh;
|
||||
// ...and so is a first stored page; a first live message is new.
|
||||
if tab.read.is_none() {
|
||||
tab.read = match source {
|
||||
HistorySource::Live => tab
|
||||
.messages
|
||||
.first()
|
||||
.map(|m| (m.message.message.ts_ms, m.message.id.saturating_sub(1))),
|
||||
_ => tab.newest(),
|
||||
};
|
||||
}
|
||||
let unread = tab.unread;
|
||||
let own =
|
||||
|m: &ChatMessage| crate::social::own_message(&self.social.own_uids, own_client, m);
|
||||
if seen && source == HistorySource::Live {
|
||||
tab.catch_up();
|
||||
} else {
|
||||
tab.count_unread(own);
|
||||
// What came while away (a stored or gateway page) gets the
|
||||
// divider also when its chat is on screen already.
|
||||
if seen {
|
||||
tab.enter(own);
|
||||
}
|
||||
}
|
||||
let counted = tab.unread != unread;
|
||||
if current {
|
||||
self.fetch_previews(id);
|
||||
self.refresh_chat();
|
||||
}
|
||||
if fresh > 0 && !shown {
|
||||
if counted {
|
||||
self.refresh_servers();
|
||||
}
|
||||
self.studio_chat_changed(id, target);
|
||||
@@ -332,6 +380,7 @@ impl App {
|
||||
previews,
|
||||
pictures,
|
||||
cache,
|
||||
unread_start: main && tab.divider == Some(m.message.id),
|
||||
};
|
||||
lines.push((
|
||||
m.message.message.ts_ms,
|
||||
@@ -434,6 +483,7 @@ impl App {
|
||||
if bridge.get_messages() != empty {
|
||||
bridge.set_messages(empty);
|
||||
}
|
||||
bridge.set_unread_index(-1);
|
||||
return;
|
||||
};
|
||||
let tabs: Vec<ChatTab> = view
|
||||
@@ -483,13 +533,31 @@ impl App {
|
||||
}
|
||||
let tab = &view.tabs[view.current_tab];
|
||||
// Sessions without stored history push their lines themselves.
|
||||
let mut divider = None;
|
||||
if view.has_history() {
|
||||
vm::list::sync(&tab.lines, &self.lines_of(view, tab, true));
|
||||
let lines = self.lines_of(view, tab, true);
|
||||
divider = lines.iter().position(|l| l.unread_start);
|
||||
vm::list::sync(&tab.lines, &lines);
|
||||
}
|
||||
let lines = ModelRc::from(tab.lines.clone());
|
||||
if bridge.get_messages() != lines {
|
||||
bridge.set_messages(lines);
|
||||
}
|
||||
// The "New" divider: how many came from there on, and when.
|
||||
let new = tab
|
||||
.divider
|
||||
.and_then(|d| tab.messages.iter().position(|m| m.message.id == d))
|
||||
.map_or(&[][..], |i| &tab.messages[i..]);
|
||||
let session = self.current.unwrap_or_default();
|
||||
let count = new.iter().filter(|m| !self.is_own(session, &m.message.message)).count();
|
||||
bridge.set_unread_index(divider.map_or(-1, |i| i as i32));
|
||||
bridge.set_unread_count(count as i32);
|
||||
bridge.set_unread_since(
|
||||
new.first()
|
||||
.map(|m| vm::chat::since_time(m.message.message.ts_ms))
|
||||
.unwrap_or_default()
|
||||
.into(),
|
||||
);
|
||||
bridge.set_more_history(view.has_history() && !tab.complete);
|
||||
bridge.set_loading_history(tab.loading);
|
||||
bridge.set_local_history(
|
||||
@@ -584,6 +652,148 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
// What is read.
|
||||
|
||||
/// The current chat's messages are on screen (`Nav.chat-shown`).
|
||||
fn chat_shown(&self) -> bool {
|
||||
self.ui.upgrade().is_some_and(|ui| ui.global::<Nav>().get_chat_shown())
|
||||
}
|
||||
|
||||
/// New messages of session `id` in its current tab are read as they
|
||||
/// come: they are on screen in the focused window.
|
||||
fn reads_now(&self, id: i64) -> bool {
|
||||
self.focused && self.current == Some(id) && self.chat_shown()
|
||||
}
|
||||
|
||||
/// After anything that can change which chat is on screen (a tab, a
|
||||
/// server, the page, the window's focus): the chat left is stored and
|
||||
/// loses its divider; the one on screen, in the focused window, is read
|
||||
/// (its divider above what was new). `true` if a tab changed.
|
||||
pub(crate) fn track_reading(&mut self) -> bool {
|
||||
let open = self.current.filter(|_| self.chat_shown()).and_then(|id| {
|
||||
let view = self.sessions.get(&id)?;
|
||||
Some((id, view.tabs.get(view.current_tab)?.target.clone()))
|
||||
});
|
||||
let mut changed = false;
|
||||
if open != self.reading {
|
||||
if let Some((id, target)) = self.reading.take()
|
||||
&& let Some(index) = self.tab_index(id, &target)
|
||||
{
|
||||
let tab = &mut self.sessions.entry(id).or_default().tabs[index];
|
||||
changed |= tab.divider.take().is_some();
|
||||
self.save_read(id, index);
|
||||
}
|
||||
self.reading = open.clone();
|
||||
}
|
||||
if let (true, Some((id, target))) = (self.focused, open)
|
||||
&& let Some(index) = self.tab_index(id, &target)
|
||||
{
|
||||
let own_uids = &self.social.own_uids;
|
||||
let view = self.sessions.entry(id).or_default();
|
||||
let own_client = view.state.own_client;
|
||||
let tab = &mut view.tabs[index];
|
||||
let before = (tab.unread, tab.divider);
|
||||
tab.enter(|m| crate::social::own_message(own_uids, own_client, m));
|
||||
changed |= (tab.unread, tab.divider) != before;
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
/// Where the tab of `target` is in session `id`.
|
||||
fn tab_index(&self, id: i64, target: &ChatTarget) -> Option<usize> {
|
||||
self.sessions.get(&id)?.tabs.iter().position(|t| t.target == *target)
|
||||
}
|
||||
|
||||
/// The current chat came on screen or left it (`Nav.chat-shown`).
|
||||
pub(crate) fn chat_shown_changed(&mut self) {
|
||||
if self.track_reading() {
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
}
|
||||
}
|
||||
|
||||
/// The window gained or lost the focus (winit's events: the desktop
|
||||
/// only).
|
||||
#[cfg(not(target_os = "android"))]
|
||||
pub(crate) fn window_focused(&mut self, focused: bool) {
|
||||
self.focused = focused;
|
||||
if self.track_reading() {
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
}
|
||||
}
|
||||
|
||||
/// The current chat is read (the bar over its messages): the divider
|
||||
/// goes.
|
||||
pub(crate) fn mark_read(&mut self) {
|
||||
let Some(id) = self.current else { return };
|
||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
||||
let index = view.current_tab;
|
||||
let tab = &mut view.tabs[index];
|
||||
tab.divider = None;
|
||||
tab.catch_up();
|
||||
self.save_read(id, index);
|
||||
self.refresh_chat();
|
||||
self.refresh_servers();
|
||||
}
|
||||
|
||||
/// Store where tab `index` of session `id` was read, if that moved (not
|
||||
/// for the sample data of VOELIN_DEMO_UI).
|
||||
pub(crate) fn save_read(&mut self, id: i64, index: usize) {
|
||||
if self.demo_ui {
|
||||
return;
|
||||
}
|
||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
||||
let Some(server_uid) = view.state.server_uid.as_deref() else { return };
|
||||
let Some(tab) = view.tabs.get_mut(index) else { return };
|
||||
let Some((ts_ms, message)) = tab.read.filter(|r| tab.stored_read != Some(*r)) else {
|
||||
return;
|
||||
};
|
||||
let read =
|
||||
ChatRead { ts_ms, id: message, updated_ms: chrono::Utc::now().timestamp_millis() };
|
||||
let target = store_target(&tab.target);
|
||||
match self.store.set_chat_read(server_uid, &target, &read) {
|
||||
Ok(()) => {
|
||||
tab.stored_read = tab.read;
|
||||
// A tab closed and opened again starts from here.
|
||||
view.reads.insert(target.key(), (ts_ms, message));
|
||||
}
|
||||
Err(e) => tracing::warn!(%e, "could not keep where a chat was read"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Store where every chat of session `id` was read (it ended, or the
|
||||
/// app exits).
|
||||
pub(crate) fn save_reads(&mut self, id: i64) {
|
||||
let count = self.sessions.get(&id).map_or(0, |v| v.tabs.len());
|
||||
for index in 0..count {
|
||||
self.save_read(id, index);
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the chats of session `id` were read, from the store, once its
|
||||
/// server is known (or another one: the gateway's id wins): its tabs
|
||||
/// start from there, now and when they open.
|
||||
pub(crate) fn load_reads(&mut self, id: i64) {
|
||||
let Some(view) = self.sessions.get_mut(&id) else { return };
|
||||
if self.demo_ui || view.state.server_uid.is_none() || view.reads_of == view.state.server_uid
|
||||
{
|
||||
return;
|
||||
}
|
||||
view.reads_of = view.state.server_uid.clone();
|
||||
let server_uid = view.reads_of.as_deref().unwrap_or_default();
|
||||
view.reads = match self.store.chat_reads(server_uid) {
|
||||
Ok(reads) => reads.into_iter().map(|(t, r)| (t.key(), (r.ts_ms, r.id))).collect(),
|
||||
Err(e) => {
|
||||
tracing::warn!(%e, "could not read where the chats were read");
|
||||
HashMap::new()
|
||||
}
|
||||
};
|
||||
for tab in &mut view.tabs {
|
||||
tab.read_from(&view.reads);
|
||||
}
|
||||
}
|
||||
|
||||
// Gateway features of a chat.
|
||||
|
||||
/// A request to the current session's gateway.
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
//! `channel-password` (the password dialog of the first locked channel,
|
||||
//! the sample's Officers; `channel-password:wrong` as after a refused
|
||||
//! one), `actions` (the last message's actions, as if hovered),
|
||||
//! `unread` (the current chat read up to five messages before its end:
|
||||
//! the "New" divider, scrolled up to; `unread:end` ten messages before,
|
||||
//! at the list's end, under the bar that counts the new messages),
|
||||
//! `link-confirm[:<url>]` (the question before a masked link opens, by
|
||||
//! default the sample's raid board), `watch` (the first stream; with
|
||||
//! sample data the local test pattern in its place), `popout` (the same,
|
||||
@@ -154,6 +157,7 @@ fn mobile_tab(name: &str) -> MobileTab {
|
||||
pub(crate) struct Running {
|
||||
_screenshot: Option<slint::Timer>,
|
||||
_resize: Option<slint::Timer>,
|
||||
_scroll: Option<slint::Timer>,
|
||||
}
|
||||
|
||||
/// Apply the switches once the app is set up.
|
||||
@@ -289,6 +293,10 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
}
|
||||
// A screenshot cannot hover.
|
||||
"actions" => nav.set_show_actions(true),
|
||||
// `end`: further back, so the divider is above the view.
|
||||
"unread" => {
|
||||
with_app(|app| open_unread(app, if arg == "end" { 10 } else { 5 }));
|
||||
}
|
||||
"link-confirm" => {
|
||||
let url = if arg.is_empty() { DEMO_RAID_BOARD } else { arg };
|
||||
with_app(|app| app.open_link_text(url, true));
|
||||
@@ -362,6 +370,24 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
);
|
||||
timer
|
||||
});
|
||||
// `unread`: up to the divider once the list is laid out (after the
|
||||
// resize above).
|
||||
let scroll = switches.open.iter().any(|o| o == "unread").then(|| {
|
||||
let weak = ui.as_weak();
|
||||
let timer = slint::Timer::default();
|
||||
timer.start(
|
||||
slint::TimerMode::SingleShot,
|
||||
Duration::from_millis(switches.screenshot_delay * 1000 * 3 / 4),
|
||||
move || {
|
||||
if let Some(ui) = weak.upgrade() {
|
||||
let bridge = ui.global::<Bridge>();
|
||||
bridge.set_jump_index(bridge.get_unread_index());
|
||||
bridge.set_jump_requests(bridge.get_jump_requests().wrapping_add(1));
|
||||
}
|
||||
},
|
||||
);
|
||||
timer
|
||||
});
|
||||
let screenshot = switches.screenshot.clone().map(|path| {
|
||||
let weak = ui.as_weak();
|
||||
let timer = slint::Timer::default();
|
||||
@@ -381,7 +407,27 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
);
|
||||
timer
|
||||
});
|
||||
Running { _screenshot: screenshot, _resize: resize }
|
||||
Running { _screenshot: screenshot, _resize: resize, _scroll: scroll }
|
||||
}
|
||||
|
||||
/// The current chat's read marker `back` messages before its end, as if
|
||||
/// they came while away, its "New" divider shown (`VOELIN_OPEN=unread`).
|
||||
fn open_unread(app: &mut App, back: usize) {
|
||||
let Some(id) = app.current else { return };
|
||||
let own_uids = app.social.own_uids.clone();
|
||||
let Some(view) = app.sessions.get_mut(&id) else { return };
|
||||
let own_client = view.state.own_client;
|
||||
let own = |m: &ChatMessage| crate::social::own_message(&own_uids, own_client, m);
|
||||
let index = view.current_tab;
|
||||
let tab = &mut view.tabs[index];
|
||||
let Some(at) = tab.messages.len().checked_sub(back + 1) else { return };
|
||||
let read = &tab.messages[at].message;
|
||||
tab.read = Some((read.message.ts_ms, read.id));
|
||||
tab.divider = None;
|
||||
tab.count_unread(own);
|
||||
tab.enter(own);
|
||||
app.refresh_chat();
|
||||
app.refresh_servers();
|
||||
}
|
||||
|
||||
fn save_screenshot(ui: &MainWindow, path: &std::path::Path) -> Result<()> {
|
||||
@@ -848,14 +894,19 @@ fn demo_social(app: &mut App) {
|
||||
neon.message.author_id = None;
|
||||
app.social.dm.stored.push(("demo-dev".into(), neon));
|
||||
app.social.dm.bookmark_of.insert("demo-dev".into(), DEMO + 2);
|
||||
// Unread: Mira's and Lumen's messages came while away.
|
||||
if let Some(view) = app.sessions.get_mut(&DEMO) {
|
||||
// The samples came one by one, as new ones do: all are read (no "New"
|
||||
// line, which a gateway page on screen gets), but for Mira's and
|
||||
// Lumen's messages, which came while away.
|
||||
for view in app.sessions.values_mut() {
|
||||
for tab in &mut view.tabs {
|
||||
tab.divider = None;
|
||||
tab.catch_up();
|
||||
match &tab.target {
|
||||
ChatTarget::Private(uid) if uid == "demo-4" => tab.unread = 1,
|
||||
ChatTarget::Private(uid) if uid == "demo-2" => tab.unread = 2,
|
||||
_ => {}
|
||||
_ => continue,
|
||||
}
|
||||
tab.read = None;
|
||||
}
|
||||
}
|
||||
// A poke from Kairo, shown among the messages and in the bell.
|
||||
|
||||
@@ -256,6 +256,7 @@ impl App {
|
||||
/// Show a server, and observe it.
|
||||
pub(crate) fn select_server(&mut self, id: i64) {
|
||||
self.current = Some(id);
|
||||
self.track_reading();
|
||||
self.refresh_all();
|
||||
self.observe(id);
|
||||
}
|
||||
@@ -325,10 +326,12 @@ impl App {
|
||||
let _ = self.secrets.delete(&b.query_password_key());
|
||||
}
|
||||
let _ = self.store.delete_bookmark(id);
|
||||
self.save_reads(id);
|
||||
self.sessions.remove(&id);
|
||||
self.gateways_looked_up.remove(&id);
|
||||
self.bookmarks = self.store.bookmarks().unwrap_or_default();
|
||||
self.current = self.bookmarks.first().map(|b| b.id);
|
||||
self.track_reading();
|
||||
self.refresh_all();
|
||||
}
|
||||
|
||||
|
||||
@@ -224,6 +224,17 @@ pub(crate) fn now_ms() -> i64 {
|
||||
chrono::Utc::now().timestamp_millis()
|
||||
}
|
||||
|
||||
/// Whether a message is ours: by one of our unique ids, or by our client in
|
||||
/// its session (`own_client`).
|
||||
pub(crate) fn own_message(
|
||||
own_uids: &HashSet<String>,
|
||||
own_client: Option<u16>,
|
||||
message: &ChatMessage,
|
||||
) -> bool {
|
||||
message.author_uid.as_ref().is_some_and(|u| own_uids.contains(u))
|
||||
|| (own_client.is_some() && message.author_id == own_client)
|
||||
}
|
||||
|
||||
/// 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),
|
||||
@@ -688,10 +699,8 @@ impl App {
|
||||
|
||||
/// Whether a message is ours.
|
||||
pub(crate) fn is_own(&self, session: i64, message: &ChatMessage) -> bool {
|
||||
message.author_uid.as_ref().is_some_and(|u| self.social.own_uids.contains(u))
|
||||
|| self.sessions.get(&session).is_some_and(|v| {
|
||||
v.state.own_client.is_some() && message.author_id == v.state.own_client
|
||||
})
|
||||
let own_client = self.sessions.get(&session).and_then(|v| v.state.own_client);
|
||||
own_message(&self.social.own_uids, own_client, message)
|
||||
}
|
||||
|
||||
/// A new chat message: a private message, or one that mentions us.
|
||||
|
||||
@@ -48,7 +48,7 @@ use voelin_store::MessageSource;
|
||||
use crate::app::{
|
||||
App, ChatLine, Nav, Page, StudioAudio, StudioBridge, StudioForm, StudioLayer, StudioNav,
|
||||
StudioPick, StudioScene, StudioSettingsForm, StudioSource, StudioSourceForm, StudioStatus,
|
||||
StudioViewer, StudioWindow, Tab, Theme, later, with_app,
|
||||
StudioViewer, StudioWindow, Theme, later, with_app,
|
||||
};
|
||||
use crate::settings::parse_positive;
|
||||
use crate::video::CaptureRequest;
|
||||
@@ -936,7 +936,8 @@ impl App {
|
||||
.map(|c| vm::tree::channel_title(c).0.to_owned())
|
||||
.unwrap_or_default();
|
||||
if !view.tabs.iter().any(|t| t.target == target) {
|
||||
view.tabs.push(Tab::new(target.clone(), format!("#{name}")));
|
||||
let tab = view.new_tab(target.clone(), format!("#{name}"));
|
||||
view.tabs.push(tab);
|
||||
if !demo {
|
||||
self.engine.send(Command::OpenChat { session: id as u64, target });
|
||||
}
|
||||
|
||||
@@ -57,6 +57,46 @@ pub struct LineCtx<'a> {
|
||||
pub pictures: Option<&'a HashMap<String, PathBuf>>,
|
||||
/// What earlier lines of the chat were built from, to reuse.
|
||||
pub cache: Option<&'a LineCache>,
|
||||
/// The first new message: the "New" divider is above it, so it starts
|
||||
/// a group of its own.
|
||||
pub unread_start: bool,
|
||||
}
|
||||
|
||||
/// The first message after `read` (by `(ts_ms, id)`, as a chat is ordered)
|
||||
/// that is not ours: where the "New" divider goes. `messages` are
|
||||
/// `(ts_ms, id, ours)` in order; `None` read: nothing was.
|
||||
pub fn first_unread(messages: &[(i64, i64, bool)], read: Option<(i64, i64)>) -> Option<usize> {
|
||||
messages.iter().position(|&(ts, id, own)| !own && read.is_none_or(|r| (ts, id) > r))
|
||||
}
|
||||
|
||||
/// How many of `messages` (as for [`first_unread`]) came after `read` and
|
||||
/// are not ours.
|
||||
pub fn unread_count(messages: &[(i64, i64, bool)], read: Option<(i64, i64)>) -> i32 {
|
||||
let new = |&&(ts, id, own): &&(i64, i64, bool)| !own && read.is_none_or(|r| (ts, id) > r);
|
||||
messages.iter().filter(new).count() as i32
|
||||
}
|
||||
|
||||
/// Since when messages are new, for "5 new messages since 10:14" (see
|
||||
/// [`since`]).
|
||||
pub fn since_time(ts_ms: i64) -> String {
|
||||
chrono::DateTime::from_timestamp_millis(ts_ms)
|
||||
.map(|t| {
|
||||
since(t.with_timezone(&chrono::Local).naive_local(), chrono::Local::now().naive_local())
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// "10:14" today, "12 Mar 10:14" before, with the year when it is not this
|
||||
/// one.
|
||||
pub fn since(then: chrono::NaiveDateTime, now: chrono::NaiveDateTime) -> String {
|
||||
use chrono::Datelike;
|
||||
if then.date() == now.date() {
|
||||
then.format("%H:%M").to_string()
|
||||
} else if then.year() == now.year() {
|
||||
then.format("%-d %b %H:%M").to_string()
|
||||
} else {
|
||||
then.format("%-d %b %Y %H:%M").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// When a message was sent, for its header (see [`stamp`]).
|
||||
@@ -469,9 +509,10 @@ fn line_of(
|
||||
parts: Option<&mut Parts>,
|
||||
reactions: Vec<ReactionItem>,
|
||||
) -> ChatLine {
|
||||
let continued = previous.is_some_and(|p| {
|
||||
p.author == message.author_name && (0..GROUP_MS).contains(&(message.ts_ms - p.ts_ms))
|
||||
});
|
||||
let continued = !ctx.unread_start
|
||||
&& previous.is_some_and(|p| {
|
||||
p.author == message.author_name && (0..GROUP_MS).contains(&(message.ts_ms - p.ts_ms))
|
||||
});
|
||||
let cached = parts.is_some();
|
||||
let mut own = Parts::default();
|
||||
let parts = parts.unwrap_or(&mut own);
|
||||
@@ -546,6 +587,7 @@ fn line_of(
|
||||
topic: ctx.topic.clone().into(),
|
||||
marked: ctx.marked,
|
||||
link: body.link.into(),
|
||||
unread_start: ctx.unread_start,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,6 +650,51 @@ mod tests {
|
||||
assert!(!line(&message("Alice", "later", 1_000_000 + GROUP_MS), Some(&prev)).continued);
|
||||
}
|
||||
|
||||
/// The "New" divider is above its line, so the line has its header even
|
||||
/// right after the same author.
|
||||
#[test]
|
||||
fn the_first_new_line_is_not_continued() {
|
||||
let prev = Previous::of(&message("Alice", "hi", 1_000_000));
|
||||
let again = stored(message("Alice", "again", 1_060_000));
|
||||
let line = history_line(&again, Some(&prev), &LineCtx::default());
|
||||
assert!(line.continued && !line.unread_start);
|
||||
let ctx = LineCtx { unread_start: true, ..Default::default() };
|
||||
let line = history_line(&again, Some(&prev), &ctx);
|
||||
assert!(line.unread_start && !line.continued);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn first_unread_messages() {
|
||||
// (ts_ms, id, ours), in order.
|
||||
let chat = [(10, 1, false), (20, 2, true), (20, 3, false), (30, 4, false)];
|
||||
// Nothing read: everything not ours is new.
|
||||
assert_eq!((first_unread(&chat, None), unread_count(&chat, None)), (Some(0), 3));
|
||||
// Our own messages are skipped.
|
||||
assert_eq!(first_unread(&chat, Some((10, 1))), Some(2));
|
||||
assert_eq!(unread_count(&chat, Some((10, 1))), 2);
|
||||
// At the same time the id decides.
|
||||
assert_eq!(first_unread(&chat, Some((20, 2))), Some(2));
|
||||
assert_eq!(first_unread(&chat, Some((20, 3))), Some(3));
|
||||
assert_eq!(first_unread(&[(20, 5, false), (20, 6, false)], Some((20, 5))), Some(1));
|
||||
// Everything read, or read past the end.
|
||||
for read in [(30, 4), (40, 0)] {
|
||||
assert_eq!(
|
||||
(first_unread(&chat, Some(read)), unread_count(&chat, Some(read))),
|
||||
(None, 0)
|
||||
);
|
||||
}
|
||||
assert_eq!(first_unread(&[], None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_since() {
|
||||
let at = |d: &str| chrono::NaiveDateTime::parse_from_str(d, "%Y-%m-%d %H:%M").unwrap();
|
||||
let now = at("2026-10-03 09:00");
|
||||
assert_eq!(since(at("2026-10-03 08:05"), now), "08:05");
|
||||
assert_eq!(since(at("2026-03-12 10:14"), now), "12 Mar 10:14");
|
||||
assert_eq!(since(at("2025-12-31 10:14"), now), "31 Dec 2025 10:14");
|
||||
}
|
||||
|
||||
/// The runs of block `i` of a line, as (text, emoji).
|
||||
fn runs(line: &ChatLine, i: usize) -> Vec<TextRun> {
|
||||
line.blocks.row_data(i).unwrap().runs.iter().collect()
|
||||
|
||||
@@ -105,6 +105,10 @@ export component MainWindow inherits Window {
|
||||
property <length> panel-width: Nav.right-panel-width;
|
||||
changed panel-width => { Bridge.panel-resized(panel-width / 1px); }
|
||||
|
||||
// Messages are read while the chat is on screen.
|
||||
property <bool> chat-shown: Nav.chat-shown;
|
||||
changed chat-shown => { Bridge.chat-shown-changed(); }
|
||||
|
||||
// Compatibility with callers from before the navigation global.
|
||||
public function open-share-dialog() {
|
||||
Nav.open-share();
|
||||
|
||||
@@ -262,6 +262,9 @@ export struct ChatLine {
|
||||
marked: bool,
|
||||
// The first web address it links to, "" if none.
|
||||
link: string,
|
||||
// The first new message: the "New" divider is above it (never
|
||||
// `continued`).
|
||||
unread-start: bool,
|
||||
}
|
||||
|
||||
// A pinned message in the pins drawer.
|
||||
@@ -886,6 +889,12 @@ export global Bridge {
|
||||
// that changes with every jump.
|
||||
in property <int> jump-index: -1;
|
||||
in property <int> jump-requests;
|
||||
// The "New" divider of the current chat: its row in `messages` (-1:
|
||||
// none), how many messages are new from there, and since when
|
||||
// ("10:14"). It stays until the chat is left or marked read.
|
||||
in property <int> unread-index: -1;
|
||||
in property <int> unread-count;
|
||||
in property <string> unread-since;
|
||||
in property <string> status-text;
|
||||
// Unread messages in all chats of the current server.
|
||||
in property <int> unread-total;
|
||||
@@ -1017,6 +1026,11 @@ export global Bridge {
|
||||
callback send-message(string);
|
||||
// The page before the oldest shown message.
|
||||
callback load-older();
|
||||
// The current chat is read: its "New" divider goes.
|
||||
callback mark-read();
|
||||
// The current chat's messages came on screen or left it
|
||||
// (Nav.chat-shown): messages are read only while they are shown.
|
||||
callback chat-shown-changed();
|
||||
// A message of the current chat, by its `key`.
|
||||
callback react(int, string);
|
||||
callback pin(int, bool);
|
||||
|
||||
@@ -131,6 +131,11 @@ export global Nav {
|
||||
// The voice channel screen (design mockup 02) instead of a tab: the
|
||||
// voice channel view, or a stream we watch.
|
||||
out property <bool> phone-voice: narrow && page == Page.server && Bridge.voice-connected && (voice-view || Bridge.viewer-open);
|
||||
// The current chat's messages are on screen: the server page (on the
|
||||
// phone its Chats tab or the voice screen), or a private chat open on
|
||||
// the messages page. Only then are new messages read.
|
||||
out property <bool> chat-shown: (page == Page.server && (!narrow || phone-voice || mobile-tab == MobileTab.chat))
|
||||
|| (page == Page.messages && Bridge.dm.open && !Bridge.dm.mail && !Bridge.dm.stored);
|
||||
|
||||
// Settings were opened (so leaving them tells Rust).
|
||||
property <bool> settings-active;
|
||||
|
||||
@@ -319,6 +319,34 @@ component MessageActions inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// Where the messages not read yet start: a red line with "New" at its end.
|
||||
component NewDivider inherits HorizontalLayout {
|
||||
padding-left: Theme.space-6;
|
||||
padding-right: Theme.space-6;
|
||||
padding-top: Theme.space-3;
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
Rectangle {
|
||||
height: 1px;
|
||||
background: Theme.danger;
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
width: new.preferred-width + 2 * Theme.space-2;
|
||||
height: 16px;
|
||||
border-radius: Theme.radius-xs;
|
||||
background: Theme.danger;
|
||||
accessible-role: AccessibleRole.text;
|
||||
accessible-label: @tr("New messages");
|
||||
new := Text {
|
||||
text: @tr("New");
|
||||
color: Theme.on-accent;
|
||||
font-size: Theme.font-xs;
|
||||
font-weight: Theme.weight-bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One message; `continued` lines (same author just before) omit the header.
|
||||
export component MessageRow inherits Rectangle {
|
||||
in property <ChatLine> line;
|
||||
@@ -334,7 +362,7 @@ export component MessageRow inherits Rectangle {
|
||||
property <bool> can-act: root.actions && !line.blocked && (line.text != "" || line.remote);
|
||||
// The pointer on the message or on its actions (above its top).
|
||||
property <bool> active: hover.has-hover || bar.hovered;
|
||||
min-height: body.preferred-height;
|
||||
min-height: column.preferred-height;
|
||||
background: line.marked ? Theme.accent-soft : root.active ? Theme.surface-2.transparentize(0.6) : transparent;
|
||||
accessible-role: AccessibleRole.list-item;
|
||||
accessible-label: line.author + ": " + line.text;
|
||||
@@ -349,90 +377,94 @@ export component MessageRow inherits Rectangle {
|
||||
menu.show(self.mouse-x, self.mouse-y);
|
||||
}
|
||||
}
|
||||
body := HorizontalLayout {
|
||||
padding-left: Theme.space-6;
|
||||
padding-right: Theme.space-6;
|
||||
padding-top: line.continued ? 2px : Theme.space-5;
|
||||
padding-bottom: 2px;
|
||||
spacing: Theme.space-4;
|
||||
VerticalLayout {
|
||||
width: root.avatar;
|
||||
alignment: start;
|
||||
if !line.continued: Avatar {
|
||||
size: root.avatar;
|
||||
initials: line.initials;
|
||||
tint: line.tint;
|
||||
image: line.avatar;
|
||||
label: line.author;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
spacing: 2px;
|
||||
if !line.continued: HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
column := VerticalLayout {
|
||||
if line.unread-start: NewDivider { }
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-6;
|
||||
padding-right: Theme.space-6;
|
||||
padding-top: line.continued ? 2px : line.unread-start ? Theme.space-3 : Theme.space-5;
|
||||
padding-bottom: 2px;
|
||||
spacing: Theme.space-4;
|
||||
VerticalLayout {
|
||||
width: root.avatar;
|
||||
alignment: start;
|
||||
Text {
|
||||
text: line.author;
|
||||
color: Theme.name-text;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-medium;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Text {
|
||||
text: line.time;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if line.pinned: Chip {
|
||||
text: @tr("pinned");
|
||||
icon: Icons.pin;
|
||||
tint: Theme.warning;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
if line.topic != "": Chip {
|
||||
text: line.topic;
|
||||
icon: Icons.messages-square;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
if !line.continued: Avatar {
|
||||
size: root.avatar;
|
||||
initials: line.initials;
|
||||
tint: line.tint;
|
||||
image: line.avatar;
|
||||
label: line.author;
|
||||
}
|
||||
}
|
||||
MessageText {
|
||||
line: line;
|
||||
font-size: Theme.font-md;
|
||||
}
|
||||
if line.files.length > 0 && !line.blocked: VerticalLayout {
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-1;
|
||||
spacing: Theme.space-2;
|
||||
for file in line.files: HorizontalLayout {
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
spacing: 2px;
|
||||
if !line.continued: HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
alignment: start;
|
||||
if file.preview.width > 0: ImageCard {
|
||||
key: line.key;
|
||||
file: file;
|
||||
Text {
|
||||
text: line.author;
|
||||
color: Theme.name-text;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-medium;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if file.preview.width == 0: FileCard {
|
||||
key: line.key;
|
||||
file: file;
|
||||
max-width: 440px;
|
||||
Text {
|
||||
text: line.time;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if line.pinned: Chip {
|
||||
text: @tr("pinned");
|
||||
icon: Icons.pin;
|
||||
tint: Theme.warning;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
if line.topic != "": Chip {
|
||||
text: line.topic;
|
||||
icon: Icons.messages-square;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if line.reactions.length > 0: VerticalLayout {
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-1;
|
||||
Reactions {
|
||||
key: line.key;
|
||||
model: line.reactions;
|
||||
MessageText {
|
||||
line: line;
|
||||
font-size: Theme.font-md;
|
||||
}
|
||||
if line.files.length > 0 && !line.blocked: VerticalLayout {
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-1;
|
||||
spacing: Theme.space-2;
|
||||
for file in line.files: HorizontalLayout {
|
||||
alignment: start;
|
||||
if file.preview.width > 0: ImageCard {
|
||||
key: line.key;
|
||||
file: file;
|
||||
}
|
||||
if file.preview.width == 0: FileCard {
|
||||
key: line.key;
|
||||
file: file;
|
||||
max-width: 440px;
|
||||
}
|
||||
}
|
||||
}
|
||||
if line.reactions.length > 0: VerticalLayout {
|
||||
padding-top: Theme.space-2;
|
||||
padding-bottom: Theme.space-1;
|
||||
Reactions {
|
||||
key: line.key;
|
||||
model: line.reactions;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Below the "New" divider (`NewDivider`) when the message has one.
|
||||
bar := MessageActions {
|
||||
x: parent.width - self.width - Theme.space-6;
|
||||
y: root.first ? 2px : -12px;
|
||||
y: root.first || line.unread-start ? (line.unread-start ? Theme.space-3 + 16px : 0px) + 2px : -12px;
|
||||
line: line;
|
||||
shown: root.can-act && (root.active || root.show-actions);
|
||||
}
|
||||
@@ -467,6 +499,54 @@ export component MessageRow inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// Over a chat whose "New" divider is above the view: how many messages
|
||||
// are new and since when, a jump to the first, and Mark as read.
|
||||
component UnreadBar inherits Rectangle {
|
||||
callback jump();
|
||||
height: 36px;
|
||||
border-radius: Theme.radius-pill;
|
||||
background: Theme.surface-3;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border-popup;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-5;
|
||||
padding-right: Theme.space-2;
|
||||
spacing: Theme.space-3;
|
||||
Rectangle {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: 4px;
|
||||
background: Theme.danger;
|
||||
}
|
||||
Text {
|
||||
text: @tr("{n} new message since {}" | "{n} new messages since {}" % Bridge.unread-count, Bridge.unread-since);
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-sm;
|
||||
font-weight: Theme.weight-semibold;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
Button {
|
||||
small: true;
|
||||
kind: ButtonKind.primary;
|
||||
icon: Icons.arrow-up;
|
||||
text: @tr("Jump");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { root.jump(); }
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.x;
|
||||
label: @tr("Mark as read");
|
||||
size: 28px;
|
||||
icon-size: Theme.icon-sm;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.mark-read(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The top of a chat with older messages: the button that loads them, or a
|
||||
// spinner while they load.
|
||||
component OlderRow inherits HorizontalLayout {
|
||||
@@ -491,7 +571,8 @@ component OlderRow inherits HorizontalLayout {
|
||||
// scrolling to within a screen of the top loads the page before, and the
|
||||
// rows on screen stay where they are while it comes in above them. The
|
||||
// button above the oldest message is for a chat too short to scroll, and
|
||||
// for after a page that brought nothing.
|
||||
// for after a page that brought nothing. While the "New" divider is above
|
||||
// the view, a bar over the list says how many messages are new.
|
||||
export component MessageList inherits VerticalLayout {
|
||||
in property <[ChatLine]> model;
|
||||
in property <bool> older;
|
||||
@@ -585,16 +666,21 @@ export component MessageList inherits VerticalLayout {
|
||||
changed tab => { root.reset(); }
|
||||
property <int> server: Bridge.current-server;
|
||||
changed server => { root.reset(); }
|
||||
// A pinned message was jumped to: scroll to where its row is. Rows
|
||||
// differ in height, so this is the place of an average row (as the
|
||||
// standard list estimates it); the row itself is highlighted.
|
||||
property <int> jumps: Bridge.jump-requests;
|
||||
changed jumps => {
|
||||
// Scroll to where row `index` is, a third down the view. Rows differ in
|
||||
// height, so this is the place of an average row (as the standard list
|
||||
// estimates it).
|
||||
function jump-to(index: int) {
|
||||
if root.older && root.model.length > 0 {
|
||||
root.settle = 0;
|
||||
list.content-y = max(root.end, min(0px, list.visible-height / 3 - Bridge.jump-index * list.content-height / root.model.length));
|
||||
list.content-y = max(root.end, min(0px, list.visible-height / 3 - index * list.content-height / root.model.length));
|
||||
}
|
||||
}
|
||||
// A pinned message was jumped to (the row is highlighted).
|
||||
property <int> jumps: Bridge.jump-requests;
|
||||
changed jumps => { root.jump-to(Bridge.jump-index); }
|
||||
// The "New" divider is above the view (as estimated for a jump).
|
||||
property <bool> new-above: root.older && Bridge.unread-index >= 0 && root.model.length > 0
|
||||
&& list.content-y + Bridge.unread-index * list.content-height / root.model.length < 0;
|
||||
if Bridge.local-history: Rectangle {
|
||||
height: 30px;
|
||||
background: Theme.warning-soft;
|
||||
@@ -619,23 +705,33 @@ export component MessageList inherits VerticalLayout {
|
||||
if root.older && Bridge.more-history && root.model.length == 0: OlderRow {
|
||||
load => { root.load(); }
|
||||
}
|
||||
list := ListView {
|
||||
Rectangle {
|
||||
vertical-stretch: 1;
|
||||
// A long chat must not make the window taller: the list scrolls.
|
||||
preferred-height: 0px;
|
||||
accessible-label: @tr("Messages");
|
||||
// Scrolled by hand: the view is where the user put it.
|
||||
scrolled => { root.settle = 0; }
|
||||
for line[i] in root.model: VerticalLayout {
|
||||
if i == 0 && root.older && Bridge.more-history: OlderRow {
|
||||
load => { root.load(); }
|
||||
}
|
||||
MessageRow {
|
||||
line: line;
|
||||
show-actions: Nav.show-actions && i == root.model.length - 1;
|
||||
first: i == 0;
|
||||
list := ListView {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
accessible-label: @tr("Messages");
|
||||
// Scrolled by hand: the view is where the user put it.
|
||||
scrolled => { root.settle = 0; }
|
||||
for line[i] in root.model: VerticalLayout {
|
||||
if i == 0 && root.older && Bridge.more-history: OlderRow {
|
||||
load => { root.load(); }
|
||||
}
|
||||
MessageRow {
|
||||
line: line;
|
||||
show-actions: Nav.show-actions && i == root.model.length - 1;
|
||||
first: i == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if root.new-above: UnreadBar {
|
||||
x: Theme.space-5;
|
||||
y: Theme.space-3;
|
||||
width: parent.width - 2 * Theme.space-5;
|
||||
jump => { root.jump-to(Bridge.unread-index); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user