voelin-core: chat history and the gateway's features in the engine
Chat lived only in the UI's memory. Every chat message a session sees (voice, gateway pushes, query relays, our own sends) is now stored under the server's unique id through a writer thread that batches writes, and opening a chat or reconnecting emits the stored page at once, then syncs with the gateway: the latest page on first contact, afterwards everything past the chat's revision cursor, in pages of chat.history_page. LoadOlderHistory pages back, merging the gateway's page for that range. Copies of one message from different sources become one row, so the UI upserts by local id (Event::ChatHistory). The session's gateway now runs on the typed client, keeping presence and relayed chat as they were, and takes Command::Gateway requests (pins, reactions, topics and topic history, events with RSVP, the stream directory, activity, permissions, runtime config and permission rules), answered and pushed as Event::Gateway updates. It subscribes to events, streams and activity when offered. Our own TeamSpeak 6 stream registers itself in the directory when it goes live and leaves it when it ends, and the directory's registered entries feed stream discovery (also as a StreamLookup), so streams that started before we joined are found even when the server's lookup does not answer. The voice connection now reports the server's unique id (SHA-1 or SHA-256 of its key, per server generation) and ours, and files our own private messages under the receiver. Settings: chat.store_history, chat.history_page, chat.dedupe_tolerance_ms, chat.retention_days. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
1 parent
19c47b95c7
commit
7d92d391dc
8 files changed
+2236
-66
No files matched your search
@@ -712,9 +712,24 @@ impl Store {
|
||||
pub fn prune_messages(&self, before_ms: i64) -> Result<usize> {
|
||||
Ok(self
|
||||
.db
|
||||
.prepare_cached("DELETE FROM messages WHERE ts_ms < ?1 AND pinned = 0")?
|
||||
.prepare_cached(
|
||||
"DELETE FROM messages WHERE ts_ms < ?1 AND pinned = 0 AND server_uid <> ''",
|
||||
)?
|
||||
.execute([before_ms])?)
|
||||
}
|
||||
|
||||
/// Give new messages ids from `first` on (e.g. negative ones, for a
|
||||
/// database whose ids must not be confused with another's). SQLite
|
||||
/// numbers a new row one above the largest id, so this keeps a hidden
|
||||
/// row (no server) just below `first`. For an empty chat table.
|
||||
pub fn start_message_ids_at(&self, first: i64) -> Result<()> {
|
||||
self.db.execute(
|
||||
"INSERT INTO messages (id, server_uid, target, ts, author_name, text)
|
||||
VALUES (?1, '', '', 0, '', '')",
|
||||
[first.saturating_sub(1)],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -947,6 +962,19 @@ mod tests {
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ids_can_start_elsewhere() {
|
||||
let mut store = Store::open_in_memory().unwrap();
|
||||
store.start_message_ids_at(-1000).unwrap();
|
||||
let w = store.write_messages(&[msg(MessageSource::Voice, "a", "x", 1)], 0).unwrap();
|
||||
assert_eq!(w[0].message.id, -1000);
|
||||
let w = store.write_messages(&[msg(MessageSource::Voice, "a", "y", 2)], 0).unwrap();
|
||||
assert_eq!(w[0].message.id, -999);
|
||||
assert_eq!(store.prune_messages(i64::MAX).unwrap(), 2, "the hidden row stays");
|
||||
let w = store.write_messages(&[msg(MessageSource::Voice, "a", "z", 3)], 0).unwrap();
|
||||
assert_eq!(w[0].message.id, -1000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keys_round_trip() {
|
||||
for t in [ChatTarget::Server, ChatTarget::Channel(12), ChatTarget::Private("a/b=".into())] {
|
||||
|
||||
Reference in new issue
Block a user