voelin-core: files, avatars, icons, pokes, offline messages, contacts
The new UI needs a channel file browser, avatars and icons, pokes, direct messages to anyone, the offline message inbox and a friends list. The voice connection can do all of it; the engine did not offer it. Files (module files): ListFiles, DownloadFile (to disk as <path>.part, renamed when complete, resumable, or into memory), DownloadChatFile for a FileRef from a chat message, UploadFile, CancelTransfer, DeleteFiles, RenameFile, CreateDirectory. Transfers stream in 64 KiB pieces and report Requested/Started/Progress (files.progress_interval_ms)/Done/ Failed/Cancelled; requests and transfers carry an id the caller picks. Avatars and icons are fetched by themselves (cache.fetch_images) into a content-addressed disk cache (module cache: avatars by MD5, icons by id, LRU bounded by cache.max_mb, 0 = no limit, use times kept as file times, concurrent downloads of one file deduplicated across sessions) and reported as AvatarReady / IconReady. SetAvatar uploads ours and announces its hash, or removes it. Pokes are a command and a distinct event (they were stored as private messages before). A failing voice command (e.g. a private message to a client who left) is now an error event instead of ending the connection. Offline messages (module offline) list, read, send, delete and mark. Contacts (module contacts) are engine-wide and stored in the client database: SetContact / RemoveContact, ContactsChanged, FriendPresence across all sessions, last seen time and server, per-person volume and mute applied in every session, blocked authors flagged in chat and their pokes and private messages hidden or flagged (privacy.block_mode), and stream.permissions = friends lets friends watch without asking. ServerDetails and Groups events report the server's details and groups when they change. The book mapping moved to its own module. 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
1eb3c5ecd5
commit
f24da42aab
16 files changed
+3119
-388
No files matched your search
@@ -12,7 +12,7 @@
|
||||
//! cannot. Our own stream's life (live, viewers, ended) goes back to the
|
||||
//! session ([`OwnStreamEvent`]), which keeps its directory entry.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex, PoisonError};
|
||||
@@ -153,6 +153,8 @@ pub(crate) enum StreamInput {
|
||||
RequestFailed(Request, String),
|
||||
/// Clients on the server: channel and `client_is_streaming`.
|
||||
Clients(BTreeMap<u16, ClientState>),
|
||||
/// Clients that are friends (contacts), for `stream.permissions`.
|
||||
Friends(BTreeSet<u16>),
|
||||
/// The registered streams of the gateway's directory (full list).
|
||||
Directory(Vec<StreamInfo>),
|
||||
/// The voice connection is gone.
|
||||
@@ -256,6 +258,7 @@ impl StreamHandle {
|
||||
live: None,
|
||||
viewers: 0,
|
||||
clients: BTreeMap::new(),
|
||||
friends: BTreeSet::new(),
|
||||
gateway,
|
||||
};
|
||||
tokio::spawn(task.run(rx));
|
||||
@@ -293,6 +296,8 @@ struct StreamTask {
|
||||
viewers: u32,
|
||||
/// The clients as of the last update.
|
||||
clients: BTreeMap<u16, ClientState>,
|
||||
/// Friends' client ids (`stream.permissions = friends`).
|
||||
friends: BTreeSet<u16>,
|
||||
gateway: Arc<Mutex<GatewayStreams>>,
|
||||
}
|
||||
|
||||
@@ -368,6 +373,10 @@ impl StreamTask {
|
||||
self.streams.request_failed(&request, &error);
|
||||
Ok(())
|
||||
}
|
||||
StreamInput::Friends(friends) => {
|
||||
self.friends = friends;
|
||||
Ok(())
|
||||
}
|
||||
StreamInput::Clients(clients) => {
|
||||
// Streams of clients that left, stopped streaming or are not
|
||||
// in our channel are gone; unannounced ones are looked up.
|
||||
@@ -525,8 +534,8 @@ impl StreamTask {
|
||||
match *self.settings.current().get_arc(&STREAM_PERMISSIONS) {
|
||||
StreamPermissions::Everyone => Some(true),
|
||||
StreamPermissions::Nobody => Some(false),
|
||||
// No contacts yet: ask for everyone.
|
||||
StreamPermissions::Friends => None,
|
||||
// Friends are let in; others: ask.
|
||||
StreamPermissions::Friends => self.friends.contains(&viewer.0).then_some(true),
|
||||
StreamPermissions::Channel => {
|
||||
let discovery = self.streams.discovery();
|
||||
let own = discovery.own_channel();
|
||||
@@ -989,7 +998,7 @@ mod tests {
|
||||
assert_eq!(parse_kind("game"), StreamKind::Screen);
|
||||
}
|
||||
|
||||
/// `stream.permissions` answers join requests unless it is `friends`.
|
||||
/// `stream.permissions` answers join requests (`friends`: friends only, others are asked).
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn permissions_answer_join_requests() {
|
||||
let in_channels = |streamer: u64, viewer: u64| {
|
||||
@@ -998,12 +1007,13 @@ mod tests {
|
||||
(CLIENTS[1], ClientState { channel: viewer, streaming: Some(false) }),
|
||||
]))
|
||||
};
|
||||
for (permissions, viewer_channel, expected) in [
|
||||
(StreamPermissions::Everyone, 2, Some(true)),
|
||||
(StreamPermissions::Channel, 1, Some(true)),
|
||||
(StreamPermissions::Channel, 2, Some(false)),
|
||||
(StreamPermissions::Nobody, 1, Some(false)),
|
||||
(StreamPermissions::Friends, 1, None),
|
||||
for (permissions, viewer_channel, friend, expected) in [
|
||||
(StreamPermissions::Everyone, 2, false, Some(true)),
|
||||
(StreamPermissions::Channel, 1, false, Some(true)),
|
||||
(StreamPermissions::Channel, 2, false, Some(false)),
|
||||
(StreamPermissions::Nobody, 1, false, Some(false)),
|
||||
(StreamPermissions::Friends, 1, false, None),
|
||||
(StreamPermissions::Friends, 2, true, Some(true)),
|
||||
] {
|
||||
let settings = Settings::in_memory();
|
||||
settings.set(&STREAM_PERMISSIONS, permissions).unwrap();
|
||||
@@ -1011,6 +1021,9 @@ mod tests {
|
||||
for h in handles.iter() {
|
||||
h.send(in_channels(1, viewer_channel));
|
||||
}
|
||||
if friend {
|
||||
handles[0].send(StreamInput::Friends(BTreeSet::from([CLIENTS[1]])));
|
||||
}
|
||||
let setup = StreamSetup { name: "p".into(), ..Default::default() };
|
||||
handles[0].send(StreamInput::Start { setup, auto_accept: false });
|
||||
let (mut live, mut listed) = (false, false);
|
||||
|
||||
Reference in new issue
Block a user