voelin-core: offline messages to the unique id's bytes; voelinctl checks

messageadd carries the recipient's unique id as bytes (base64 on the
wire); the engine passed the base64 text itself, which the server
refused as an invalid client id.

voelinctl engine can now wait for an icon or a flagged poke (listen
--expect matches pokes, chat and icons), for a friend to be seen online
(contacts ls --expect-online), and identity show prints the unique id a
TeamSpeak 6 server knows the identity by (uid6), which offline messages
there need. Contacts commands wait for the stored contacts to load
instead of for an event they could miss.

Verified against 3.13.8 and 6.0.0-beta13.1: file upload, listing,
download, a chat link downloaded by another client, avatars (the a-p
file name on both), channel icons, pokes, private messages, offline
messages, friend presence and blocked pokes (flagged and hidden).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
Claude committed 2026-09-29 00:51:41 +00:00
1 parent 43d3468e47
commit 6dce4ee8e9
3 files changed
+48 -20

No files matched your search

+12 -1
View File
@@ -10,6 +10,7 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::time::Duration;
use base64::Engine as _;
use futures::prelude::*;
use tokio::sync::{broadcast, mpsc};
use tokio::task::AbortHandle;
@@ -861,7 +862,17 @@ impl Voice {
self.send(cmd, Pending::OfflineGet { request, id, message: None })?;
}
VoiceCmd::OfflineAdd { request, to_uid, subject, text } => {
let uid = tsclientlib::UidBuf(to_uid.into_bytes());
// The command carries the unique id's bytes (base64 on the wire).
let bytes = base64::engine::general_purpose::STANDARD
.decode(to_uid.trim())
.map_err(|_| anyhow::anyhow!("offline message: invalid unique id {to_uid:?}"));
let uid = match bytes {
Ok(bytes) => tsclientlib::UidBuf(bytes),
Err(e) => {
self.link.done(request, Err(e.to_string()));
return Ok(());
}
};
let cmd = c2s::OutOfflineMessageAddMessage::new(&mut std::iter::once(
c2s::OutOfflineMessageAddPart {
client_uid: std::borrow::Cow::Borrowed(uid.as_ref()),
+31 -18
View File
@@ -207,8 +207,12 @@ pub enum ContactsCommand {
Rm {
uid: String,
},
/// Print the contacts, and friends' presence while connected.
Ls,
/// Connect, print the contacts and friends' presence.
Ls {
/// Succeed once this friend (unique id) is seen online.
#[arg(long)]
expect_online: Option<String>,
},
}
/// What the action waits for.
@@ -241,7 +245,7 @@ pub async fn run(args: EngineArgs) -> Result<()> {
// Contacts need no server.
if let EngineAction::Contacts { command } = &args.action
&& !matches!(command, ContactsCommand::Ls)
&& !matches!(command, ContactsCommand::Ls { .. })
{
let result = contacts(&engine, command, &mut events, deadline).await;
engine.history().flush();
@@ -400,11 +404,12 @@ impl Runner<'_> {
}
}
Event::Poke { from_name, message, blocked, .. } => {
println!(
let line = format!(
"poke from {from_name}: {message}{}",
if blocked { " (blocked)" } else { "" }
);
return Ok(self.expected(&message));
println!("{line}");
return Ok(self.expected(&line));
}
Event::Chat { session: SESSION, message } => {
println!(
@@ -441,7 +446,7 @@ impl Runner<'_> {
if let EngineAction::Dm { message: sent, .. } = &self.args.action {
return Ok(private && message.text == *sent);
}
return Ok(private && self.expected(&message.text));
return Ok(self.expected(&message.text));
}
Event::AvatarReady { client_uid, path, hash, .. } => {
let nick = self
@@ -467,7 +472,10 @@ impl Runner<'_> {
return Ok(true);
}
}
Event::IconReady { icon, path, .. } => println!("icon {icon} {}", path.display()),
Event::IconReady { icon, path, .. } => {
println!("icon {icon} {}", path.display());
return Ok(self.expected(&format!("icon {icon}")));
}
Event::OfflineMessages { result, .. } => {
let list = result.map_err(|e| anyhow::anyhow!("messagelist: {e}"))?;
println!("offline inbox n={}", list.len());
@@ -524,6 +532,12 @@ impl Runner<'_> {
.map(|s| format!("{} as {} in {}", s.server_name, s.nickname, s.channel_name))
.collect();
println!("friend {uid}: [{}]", spots.join(", "));
if let EngineAction::Contacts {
command: ContactsCommand::Ls { expect_online: Some(want) },
} = &self.args.action
{
return Ok(*want == uid && !sessions.is_empty());
}
}
Event::ServerDetails { details, .. } => {
println!(
@@ -682,10 +696,13 @@ impl Runner<'_> {
self.send(Command::ListOfflineMessages { session, request: 1 });
}
},
EngineAction::Contacts { .. } => {
EngineAction::Contacts { command } => {
for c in self.engine.contacts() {
println!("contact {} {:?} {:?}", c.uid, c.relation, c.nickname);
}
if matches!(command, ContactsCommand::Ls { expect_online: None }) {
self.finish_at = Some(Instant::now() + Duration::from_secs(2));
}
}
EngineAction::Listen { .. } => {}
}
@@ -729,15 +746,10 @@ async fn contacts(
events: &mut tokio::sync::broadcast::Receiver<Event>,
deadline: Instant,
) -> Result<()> {
// The stored contacts are loaded first.
let _ = timeout_at(deadline, async {
while let Ok(e) = events.recv().await {
if matches!(e, Event::ContactsChanged { .. }) {
break;
}
}
})
.await;
// The stored contacts are loaded first (on the database thread).
let history = engine.history();
tokio::task::spawn_blocking(move || history.flush()).await?;
while events.try_recv().is_ok() {}
match command {
ContactsCommand::Set { uid, relation, nickname, note } => {
let relation = match relation.as_str() {
@@ -754,7 +766,7 @@ async fn contacts(
engine.send(Command::SetContact { contact: Box::new(contact) });
}
ContactsCommand::Rm { uid } => engine.send(Command::RemoveContact { uid: uid.clone() }),
ContactsCommand::Ls => {}
ContactsCommand::Ls { .. } => {}
}
let changed = timeout_at(deadline, async {
while let Ok(e) = events.recv().await {
@@ -768,6 +780,7 @@ async fn contacts(
.ok()
.flatten()
.context("no contacts update")?;
println!("contacts n={}", changed.len());
for c in changed.iter() {
println!("contact {} {:?} {:?} {:?}", c.uid, c.relation, c.nickname, c.note);
}
+5 -1
View File
@@ -252,7 +252,11 @@ fn run_identity(command: IdentityCommand) -> Result<()> {
let id = identity::load(&path)?;
println!("uid: {}", identity::uid(&id));
println!("level: {}", id.level());
println!("omega: {}", id.key().to_pub().to_ts());
let omega = id.key().to_pub().to_ts();
// TeamSpeak 6 servers know the identity by another unique id.
let ids = voelin_gateway_proto::UniqueIds::from_omega(&omega);
println!("uid6: {}", ids.ts6);
println!("omega: {omega}");
Ok(())
}
}