ui: older messages load when scrolling up, the rows on screen staying put
Scrolling to within a screen of the top asks for the page before; the list keeps the rows from the top of the view to the end and goes back to them once the page is in (rows, as the list places them by an average height, then up to two corrections by their real heights). After a page that brought nothing it waits until the list was a screen away. The Older messages button moves to the top of the list, above the oldest message (a spinner while loading), for a chat too short to scroll. A short chat after a longer one no longer starts with its first rows above the view, and another server's chat at the same tab starts at its end too (it kept the last chat's place, and now its loading state). Demo mode answers with two sample pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
This commit is contained in:
1 parent
1435d9c909
commit
2f3c2433b4
5 files changed
+253
-28
No files matched your search
@@ -65,6 +65,9 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows
|
||||
emoji picker and the notifications panel dim the window behind them.
|
||||
- Double-clicking a channel of a server without voice connects into it
|
||||
(it said "not connected with voice").
|
||||
- Older chat messages load when scrolling up, above the messages on screen,
|
||||
which stay in place; the Older messages button remains for a chat that
|
||||
fits on the screen.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -277,8 +277,14 @@ impl App {
|
||||
}
|
||||
tab.loading = true;
|
||||
let target = tab.target.clone();
|
||||
let before = tab.messages.first().map(|m| m.message.id);
|
||||
self.engine.send(Command::LoadOlderHistory { session: id as u64, target, before });
|
||||
let oldest = tab.messages.first().map(|m| &m.message);
|
||||
if self.demo_ui {
|
||||
// No engine answers in demo mode.
|
||||
crate::dev::answer_older(id, target, oldest.cloned());
|
||||
} else {
|
||||
let before = oldest.map(|m| m.id);
|
||||
self.engine.send(Command::LoadOlderHistory { session: id as u64, target, before });
|
||||
}
|
||||
self.refresh_chat();
|
||||
}
|
||||
|
||||
|
||||
+122
-2
@@ -7,8 +7,9 @@
|
||||
//! `VOELIN_SCREENSHOT_DELAY` seconds (default 4) and exit.
|
||||
//! - `VOELIN_WINDOW_SIZE=<w>x<h>`: the window's size (e.g. `390x844` for the
|
||||
//! phone layout).
|
||||
//! - `VOELIN_DEMO_UI=1`: sample servers, channels, chat and streams, no
|
||||
//! server needed (nothing is stored).
|
||||
//! - `VOELIN_DEMO_UI=1`: sample servers, channels, chat (two pages of older
|
||||
//! messages answer scrolling up) and streams, no server needed (nothing is
|
||||
//! stored).
|
||||
//! - `VOELIN_DEMO_STREAM=1`: a local test stream in the viewer.
|
||||
//! - `VOELIN_OPEN=<what>[,<what>...]`: open screens on start: `home`,
|
||||
//! `server` (`server:chat`: its server chat), `settings[:<section>]`
|
||||
@@ -1722,3 +1723,122 @@ fn demo_topic(app: &mut App) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/// The sample messages before the sample chats' first ones: how many, how
|
||||
/// many a page, and their ids (the sample chats use ids below 500).
|
||||
const OLDER: i64 = 30;
|
||||
const OLDER_PAGE: i64 = 15;
|
||||
const OLDER_ID: i64 = 500;
|
||||
|
||||
/// The page before `oldest` of a sample chat, as the engine answers
|
||||
/// `Command::LoadOlderHistory`: older small talk, a page at a time, the last
|
||||
/// one `complete`. The first page goes back from `oldest` (from `now_ms` in
|
||||
/// an empty chat), the next ones from the sample message before.
|
||||
pub(crate) fn demo_older(
|
||||
target: &ChatTarget,
|
||||
oldest: Option<&HistoryMessage>,
|
||||
now_ms: i64,
|
||||
) -> (Vec<HistoryMessage>, bool) {
|
||||
const PEOPLE: [(&str, u16); 6] =
|
||||
[("Nova", 1), ("Kairo", 3), ("Mira", 4), ("dex", 5), ("Talon", 6), ("Lumen", 2)];
|
||||
const TEXTS: [&str; 10] = [
|
||||
"Anyone still around?",
|
||||
"Patch notes are up, the healer changes look good.",
|
||||
"Who has the key for the vault run?",
|
||||
"I can do Thursday, not Friday.",
|
||||
"Lag spike on my side, back in a sec.",
|
||||
"gg everyone, that was close 😅",
|
||||
"Is the new map in the rotation yet?",
|
||||
"Uploading the clip from last night.",
|
||||
"Coffee first, then raids ☕",
|
||||
"Same time next week?",
|
||||
];
|
||||
let (first, from_ms) = match oldest {
|
||||
Some(m) if m.id >= OLDER_ID => (m.id - OLDER_ID + 1, m.message.ts_ms),
|
||||
Some(m) => (0, m.message.ts_ms),
|
||||
None => (0, now_ms),
|
||||
};
|
||||
let last = (first + OLDER_PAGE).min(OLDER);
|
||||
let messages = (first..last)
|
||||
.map(|n| {
|
||||
// Two in a row by each person.
|
||||
let (author, client) = PEOPLE[(n / 2 % 6) as usize];
|
||||
HistoryMessage {
|
||||
id: OLDER_ID + n,
|
||||
message: ChatMessage {
|
||||
target: target.clone(),
|
||||
author_name: author.into(),
|
||||
author_uid: Some(format!("demo-{client}")),
|
||||
author_id: Some(client),
|
||||
text: TEXTS[(n % 10) as usize].into(),
|
||||
ts_ms: from_ms - (n - first + 1) * 23 * 60_000,
|
||||
via_relay: false,
|
||||
blocked: false,
|
||||
},
|
||||
source: MessageSource::Voice,
|
||||
remote_id: Some(OLDER_ID + n),
|
||||
topic_id: None,
|
||||
reactions: Vec::new(),
|
||||
pinned: false,
|
||||
rev: 1,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
(messages, last >= OLDER)
|
||||
}
|
||||
|
||||
/// Answer [`App::load_older`] in demo mode (no engine runs) with
|
||||
/// [`demo_older`], a moment later as a server would.
|
||||
pub(crate) fn answer_older(session: i64, target: ChatTarget, oldest: Option<HistoryMessage>) {
|
||||
slint::Timer::single_shot(Duration::from_millis(600), move || {
|
||||
let now = chrono::Utc::now().timestamp_millis();
|
||||
let (messages, complete) = demo_older(&target, oldest.as_ref(), now);
|
||||
with_app(|app| {
|
||||
app.handle_event(Event::ChatHistory {
|
||||
session: session as u64,
|
||||
target,
|
||||
messages,
|
||||
source: HistorySource::Gateway,
|
||||
complete,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Two pages back from the sample chat's first message, each older than
|
||||
/// the one before, the second one the last.
|
||||
#[test]
|
||||
fn demo_older_pages_in_order_and_completes() {
|
||||
let target = ChatTarget::Channel(2);
|
||||
let (first, complete) = demo_older(&target, None, 1_000_000_000);
|
||||
assert_eq!(first.len(), OLDER_PAGE as usize);
|
||||
assert!(!complete, "a second page follows");
|
||||
let ids: Vec<i64> = first.iter().map(|m| m.id).collect();
|
||||
assert_eq!(ids, (OLDER_ID..OLDER_ID + OLDER_PAGE).collect::<Vec<_>>());
|
||||
assert!(first.windows(2).all(|w| w[1].message.ts_ms < w[0].message.ts_ms));
|
||||
assert!(
|
||||
first.iter().all(|m| m.message.target == target && m.message.ts_ms < 1_000_000_000)
|
||||
);
|
||||
|
||||
let oldest = first.last().unwrap();
|
||||
let (second, complete) = demo_older(&target, Some(oldest), 0);
|
||||
assert!(complete);
|
||||
assert_eq!(second.len(), (OLDER - OLDER_PAGE) as usize);
|
||||
assert_eq!(second[0].id, oldest.id + 1);
|
||||
assert!(second.iter().all(|m| m.message.ts_ms < oldest.message.ts_ms));
|
||||
|
||||
// A sample chat's own message: back from it.
|
||||
let sample = HistoryMessage { id: 3, ..oldest.clone() };
|
||||
let (again, _) = demo_older(&target, Some(&sample), 0);
|
||||
assert_eq!(again[0].id, OLDER_ID);
|
||||
assert!(again[0].message.ts_ms < sample.message.ts_ms);
|
||||
|
||||
// Nothing after the last page.
|
||||
let (rest, complete) = demo_older(&target, second.last(), 0);
|
||||
assert!(rest.is_empty() && complete);
|
||||
}
|
||||
}
|
||||
@@ -467,33 +467,131 @@ export component MessageRow inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
// The top of a chat with older messages: the button that loads them, or a
|
||||
// spinner while they load.
|
||||
component OlderRow inherits HorizontalLayout {
|
||||
callback load();
|
||||
height: 40px;
|
||||
alignment: center;
|
||||
if Bridge.loading-history: Spinner {
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
if !Bridge.loading-history: Button {
|
||||
small: true;
|
||||
icon: Icons.chevron-up;
|
||||
text: @tr("Older messages");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { root.load(); }
|
||||
}
|
||||
}
|
||||
|
||||
// The messages of the current chat (or of an open topic). The list starts
|
||||
// at the newest message and follows new ones while it is at the end;
|
||||
// scrolling up stops that until the end is reached again.
|
||||
// scrolling up stops that until the end is reached again. With `older`,
|
||||
// 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.
|
||||
export component MessageList inherits VerticalLayout {
|
||||
in property <[ChatLine]> model;
|
||||
in property <bool> older;
|
||||
property <bool> follow: true;
|
||||
property <length> end: min(0px, list.visible-height - list.content-height);
|
||||
property <length> scrolled: list.content-y;
|
||||
// While a page of older messages loads: how many rows there are from
|
||||
// the top of the view to the end (rows, not pixels: the list places
|
||||
// rows by their average height), and the row count then (-1: no page
|
||||
// to make room for).
|
||||
property <float> keep;
|
||||
property <int> kept-rows: -1;
|
||||
// The page came in and the view went back to `keep` (`restored`). The
|
||||
// list then places the rows by their real heights, a little off: the
|
||||
// view goes back up to twice more (`settle`), until it stays put.
|
||||
property <int> settle;
|
||||
property <length> restored;
|
||||
// A page brought nothing (the gateway may be away): no more loading by
|
||||
// scrolling until the list is a screen away from where that was.
|
||||
property <bool> paused;
|
||||
property <length> paused-at;
|
||||
function rows-to-end() -> float {
|
||||
return list.content-height > 0 ? root.model.length * (list.content-y + list.content-height) / list.content-height : 0;
|
||||
}
|
||||
function restore() {
|
||||
root.restored = max(root.end, min(0px, list.content-height * (root.keep / root.model.length - 1)));
|
||||
list.content-y = root.restored;
|
||||
}
|
||||
function load() {
|
||||
root.keep = root.rows-to-end();
|
||||
root.kept-rows = root.follow ? -1 : root.model.length;
|
||||
Bridge.load-older();
|
||||
}
|
||||
// Scrolled up to within a screen of the top, and no page on its way or
|
||||
// still to be placed.
|
||||
function load-near-top() {
|
||||
if root.older && Bridge.more-history && !Bridge.loading-history && !root.paused && !root.follow && root.kept-rows < 0 && list.content-y > -list.visible-height {
|
||||
root.load();
|
||||
}
|
||||
}
|
||||
changed end => {
|
||||
if root.follow {
|
||||
list.content-y = root.end;
|
||||
} else if root.kept-rows >= 0 && root.model.length != root.kept-rows && root.model.length > 0 {
|
||||
// Older rows came in above: back to the rows that were shown.
|
||||
root.restore();
|
||||
root.settle = 2;
|
||||
root.kept-rows = Bridge.loading-history ? root.model.length : -1;
|
||||
root.load-near-top();
|
||||
}
|
||||
}
|
||||
changed scrolled => { root.follow = root.scrolled <= root.end + 2px; }
|
||||
// Another chat: start at its end.
|
||||
property <int> tab: Bridge.current-tab;
|
||||
changed tab => {
|
||||
changed scrolled => {
|
||||
// After a longer chat the list can leave a short one's first rows
|
||||
// above the view (it places rows by their estimated heights).
|
||||
if root.scrolled < root.end - 1px {
|
||||
list.content-y = root.end;
|
||||
}
|
||||
root.follow = root.scrolled <= root.end + 2px;
|
||||
if root.settle > 0 && root.scrolled != root.restored {
|
||||
root.settle -= 1;
|
||||
root.restore();
|
||||
} else if root.follow {
|
||||
root.kept-rows = -1;
|
||||
} else if root.kept-rows >= 0 && root.model.length == root.kept-rows {
|
||||
// Scrolled while the page loads: keep this place instead.
|
||||
root.keep = root.rows-to-end();
|
||||
}
|
||||
if root.paused && abs(root.scrolled - root.paused-at) > list.visible-height {
|
||||
root.paused = false;
|
||||
}
|
||||
root.load-near-top();
|
||||
}
|
||||
property <bool> loading: Bridge.loading-history;
|
||||
changed loading => {
|
||||
if !root.loading && root.kept-rows >= 0 && root.model.length == root.kept-rows {
|
||||
root.paused = true;
|
||||
root.paused-at = list.content-y;
|
||||
root.kept-rows = -1;
|
||||
}
|
||||
}
|
||||
// Another chat (another tab, or another server's tab at the same
|
||||
// place): start at its end, with nothing of the last one's loading.
|
||||
function reset() {
|
||||
root.follow = true;
|
||||
root.kept-rows = -1;
|
||||
root.settle = 0;
|
||||
root.paused = false;
|
||||
list.content-y = root.end;
|
||||
}
|
||||
property <int> tab: Bridge.current-tab;
|
||||
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 => {
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -517,29 +615,26 @@ export component MessageList inherits VerticalLayout {
|
||||
}
|
||||
}
|
||||
}
|
||||
if root.older && Bridge.more-history: Rectangle {
|
||||
height: 40px;
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
Button {
|
||||
small: true;
|
||||
icon: Icons.chevron-up;
|
||||
text: Bridge.loading-history ? @tr("Loading…") : @tr("Older messages");
|
||||
enabled: !Bridge.loading-history;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Bridge.load-older(); }
|
||||
}
|
||||
}
|
||||
// An empty chat: the button on its own.
|
||||
if root.older && Bridge.more-history && root.model.length == 0: OlderRow {
|
||||
load => { root.load(); }
|
||||
}
|
||||
list := ListView {
|
||||
vertical-stretch: 1;
|
||||
// A long chat must not make the window taller: the list scrolls.
|
||||
preferred-height: 0px;
|
||||
accessible-label: @tr("Messages");
|
||||
for line[i] in root.model: MessageRow {
|
||||
line: line;
|
||||
show-actions: Nav.show-actions && i == root.model.length - 1;
|
||||
first: i == 0;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -146,7 +146,7 @@ comes from the engine's events; what a gateway adds is hidden without it.
|
||||
|
||||
| Part | `VOELIN_OPEN` | What it shows | Engine data |
|
||||
|---|---|---|---|
|
||||
| Chat | `server` (`server:chat`: the server chat), `actions`, `link-confirm[:<url>]` | Header with Pinned Messages, Topics, the voice channel and the members button; chat tabs; messages grouped by author ("Today at 10:14"), avatars, BBCode formatting (see Formatting below), emoji, reactions with an add button, pin and topic marks, file cards with download; composer with attach, emoji and send. A link opens in the browser; one whose text is not its address (a masked link) first shows where it goes in `LinkDialog` (the host, the whole address; Open, Copy link, Cancel); a TeamSpeak link is copied for now; a right-click on a link offers Open link and Copy link. Every message has actions on hover (`MessageActions`; `actions` shows the last one's): Quote (`> Author: …` lines at the start of the composer, which takes the focus to write below them and grows to show up to about eight lines) and Copy text, and with a gateway quick reactions, pin and Start a topic; a right-click on a message shows Copy text, Copy link (its first web address), Quote, and with a gateway React… and Pin. The server chat starts with the server's welcome message (and its host message when the server puts it in the chat log). Opens at the newest message and follows new ones while at the end | `ChatHistory` (and `Chat` for servers without history), `Presence` (welcome and host message), `AvatarReady`, `Transfer`, `Gateway` (pins; reactions arrive as stored messages); `Command::LoadOlderHistory`, `DownloadChatFile`, `UploadFile`, `GatewayRequest::React`, `Unreact`, `Pin`, `Unpin` |
|
||||
| Chat | `server` (`server:chat`: the server chat), `actions`, `link-confirm[:<url>]` | Header with Pinned Messages, Topics, the voice channel and the members button; chat tabs; messages grouped by author ("Today at 10:14"), avatars, BBCode formatting (see Formatting below), emoji, reactions with an add button, pin and topic marks, file cards with download; composer with attach, emoji and send. A link opens in the browser; one whose text is not its address (a masked link) first shows where it goes in `LinkDialog` (the host, the whole address; Open, Copy link, Cancel); a TeamSpeak link is copied for now; a right-click on a link offers Open link and Copy link. Every message has actions on hover (`MessageActions`; `actions` shows the last one's): Quote (`> Author: …` lines at the start of the composer, which takes the focus to write below them and grows to show up to about eight lines) and Copy text, and with a gateway quick reactions, pin and Start a topic; a right-click on a message shows Copy text, Copy link (its first web address), Quote, and with a gateway React… and Pin. The server chat starts with the server's welcome message (and its host message when the server puts it in the chat log). Opens at the newest message and follows new ones while at the end. Scrolling up to within a screen of the top loads the page before, above the rows on screen, which stay in place (a spinner above the oldest message while it loads). The Older messages button there is for a chat too short to scroll, and for after a page that brought nothing (scrolling loads again once the list was a screen away). The voice view, the phone's voice screen and private chats load the same way | `ChatHistory` (and `Chat` for servers without history), `Presence` (welcome and host message), `AvatarReady`, `Transfer`, `Gateway` (pins; reactions arrive as stored messages); `Command::LoadOlderHistory`, `DownloadChatFile`, `UploadFile`, `GatewayRequest::React`, `Unreact`, `Pin`, `Unpin` |
|
||||
| Members panel | `server` (`panel`, `no-panel`) | "Members — N" and a search; those streaming first (the people in our channel while the voice channel or a stream is shown), then each server group in the server's order with its icon, then those without a group. Rows: avatar with status, name, crown (admin groups), priority speaker, channel commander, recording, up to three myTeamSpeak badges, moderator role, talk power, what they do or the channel they are in. Resizable: the width is `ui.members_width` | `Presence`, `Groups`, `Talking`, `IconReady`, `PictureReady` |
|
||||
| Member card | `member` | Description, groups, badges (up to three chips in the client's order, what each is for on hover; "Badge" for one the app does not know), talk power, country; private message, poke, friend, block; volume and mute for us | `ContactsChanged`, `PictureReady` (badges); `Command::SetContact`, `SetClientVolume`, `SetClientMuted`, `Poke` |
|
||||
| Poke | `poke` (the first other member's, card open; after `friends` a contact's) | `PokeDialog`, from the member card, a friend's row and the direct message header: an optional message with a "12/100" count, Send off above 100 characters, Enter sends, Escape cancels | `Command::Poke` (trimmed, cut to 100 characters; the engine cuts too) |
|
||||
@@ -426,7 +426,8 @@ notifications and the home's news show the text on one line
|
||||
Environment variables (see `src/dev.rs`):
|
||||
|
||||
- `VOELIN_DEMO_UI=1`: sample servers, channels, members, chat with
|
||||
formatting and emoji, and a stream, without a server (nothing is stored).
|
||||
formatting and emoji (and two pages of older messages, which load when
|
||||
scrolled up), and a stream, without a server (nothing is stored).
|
||||
- `VOELIN_OPEN=<what>[,<what>...]`: `home`, `server` (`server:chat`: the server chat), `settings[:voice|keybinds|streaming|privacy|appearance|profiles]` (`identities` is the same as `profiles`),
|
||||
`about`, `share[:live]`, `bookmark[:edit]`, `emoji`, `client`, `panel`, `no-panel`,
|
||||
`voice`, `pins`, `topics`, `topic:<id>`, `member`, `poke`,
|
||||
|
||||
Reference in new issue
Block a user