gateway: invisible to users, and tried again when away
Users never hear of the gateway:
- relayed messages look like everyone else's (no "via relay", no accent
colour) and group with the author's other messages;
- a gateway that cannot be reached or drops is tried again by itself
(after 2, 5, 15, 30, then every 60 s) with the open chats opened again
and messages written meanwhile sent, instead of a WebSocket error
("connection refused") on screen; it is logged with its URL, once per
cause;
- a server whose gateway is away is offline, not connecting, so it can
always be joined;
- failed requests the app made by itself are quiet; what the user did and
failed is told in plain words; query relay errors are logged;
- no status line about a found gateway; events and streams texts do not
mention it.
The gateway is looked up once per run even when one is stored: what the
server publishes takes the place of a stored URL (one that moved, or one
typed into an older version that showed the field, which cannot be
edited any more).
The admin guide says a _tsgws record must point at TLS, not at tsgw's own
plain port.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VZBWxxMsxUzp4PSTKVzbZN
This commit is contained in:
1 parent
f8dcfaf0f5
commit
266148d9cd
16 files changed
+384
-78
No files matched your search
@@ -470,6 +470,8 @@ pub(crate) struct App {
|
||||
pub demo: bool,
|
||||
/// `VOELIN_DEMO_UI`: sample servers, channels and chat (dev.rs).
|
||||
pub demo_ui: bool,
|
||||
/// Servers whose gateway was looked up in this run (`discover_gateway`).
|
||||
pub gateways_looked_up: HashSet<i64>,
|
||||
/// `VOELIN_AUTOSHARE=test-pattern`: share the test pattern once streams work.
|
||||
pub autoshare: bool,
|
||||
/// `VOELIN_OPEN=client`: open the volume dialog of the first other client.
|
||||
@@ -699,6 +701,7 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
stream_volume: 100.0,
|
||||
demo: switches.demo_stream,
|
||||
demo_ui: switches.demo_ui,
|
||||
gateways_looked_up: HashSet::new(),
|
||||
autoshare: switches.autoshare,
|
||||
open_client_pending: switches.open_client,
|
||||
notices_loaded: false,
|
||||
|
||||
@@ -16,7 +16,7 @@ use voelin_core::{
|
||||
Command, DownloadTo, GatewayRequest, GatewayUpdate, HistoryMessage, HistorySource,
|
||||
TransferState,
|
||||
};
|
||||
use voelin_gateway_proto::{TopicInfo, feature};
|
||||
use voelin_gateway_proto::{ErrorCode, TopicInfo, feature};
|
||||
use voelin_model::{ChatMessage, ChatTarget};
|
||||
|
||||
use crate::app::{App, Bridge, ChatLine, ChatTab, FileItem, Msg, PinItem, SessionView, Tab};
|
||||
@@ -546,8 +546,11 @@ impl App {
|
||||
}
|
||||
tab.topic_messages.sort_by_key(|m| (m.message.message.ts_ms, m.message.id));
|
||||
}
|
||||
GatewayUpdate::Failed { request, message, .. } => {
|
||||
self.set_status(format!("{request}: {message}"));
|
||||
GatewayUpdate::Failed { request, code, message } => {
|
||||
tracing::warn!(%request, ?code, %message, "gateway request failed");
|
||||
if let Some(text) = failure_text(&request, code, &message) {
|
||||
self.set_status(text);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// The stream directory: how many watch each stream.
|
||||
@@ -809,6 +812,40 @@ impl App {
|
||||
}
|
||||
|
||||
/// A directory entry's stream id and viewer count, when it has both.
|
||||
/// What a failed gateway request tells the user. What the app asked for by
|
||||
/// itself (history, lists, subscriptions) fails quietly; what the user did
|
||||
/// says so in plain words, never the gateway's; the gateway's own
|
||||
/// administration page shows its message as it is.
|
||||
fn failure_text(request: &str, code: Option<ErrorCode>, message: &str) -> Option<String> {
|
||||
if request.starts_with("config_") || request.starts_with("perm_") {
|
||||
return Some(format!("{request}: {message}"));
|
||||
}
|
||||
let done_by_user = matches!(
|
||||
request,
|
||||
"post"
|
||||
| "pin" | "unpin"
|
||||
| "react" | "unreact"
|
||||
| "create_topic"
|
||||
| "update_topic"
|
||||
| "create_event"
|
||||
| "update_event"
|
||||
| "delete_event"
|
||||
| "rsvp"
|
||||
);
|
||||
if !done_by_user {
|
||||
return None;
|
||||
}
|
||||
let text = match code {
|
||||
Some(ErrorCode::Forbidden) => "Not allowed on this server.",
|
||||
Some(ErrorCode::RateLimited) => "Too many requests; try again in a moment.",
|
||||
Some(ErrorCode::QuotaExceeded) => "This server's limit is reached.",
|
||||
Some(ErrorCode::NotFound) => "That is no longer there.",
|
||||
Some(ErrorCode::FeatureDisabled) => "This server does not offer that.",
|
||||
_ => "That did not work; try again later.",
|
||||
};
|
||||
Some(text.to_owned())
|
||||
}
|
||||
|
||||
fn viewers_of(entry: &voelin_gateway_proto::StreamEntry) -> Option<(String, u32)> {
|
||||
Some((entry.stream_id.clone()?, entry.viewers?))
|
||||
}
|
||||
@@ -836,4 +873,25 @@ mod tests {
|
||||
assert_eq!(ago(now - 3 * 3_600_000), "3 hours ago");
|
||||
assert_eq!(ago(now - 36 * 3_600_000), "yesterday");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failures_say_what_the_user_did_never_the_gateway() {
|
||||
let lost = "websocket: IO error: Connection refused (os error 111)";
|
||||
// The app's own requests fail quietly.
|
||||
for request in ["history", "sync", "pins", "events", "subscribe_streams"] {
|
||||
assert_eq!(failure_text(request, None, lost), None, "{request}");
|
||||
}
|
||||
// The user's own, in plain words.
|
||||
assert_eq!(
|
||||
failure_text("pin", Some(ErrorCode::Forbidden), "no b_pin").as_deref(),
|
||||
Some("Not allowed on this server.")
|
||||
);
|
||||
let text = failure_text("post", None, lost).unwrap();
|
||||
assert!(!text.contains("websocket") && !text.to_lowercase().contains("gateway"), "{text}");
|
||||
// The gateway's administration page shows its message.
|
||||
assert_eq!(
|
||||
failure_text("config_set", Some(ErrorCode::BadRequest), "bad value").as_deref(),
|
||||
Some("config_set: bad value")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
//! server card and the channel tree.
|
||||
|
||||
use slint::{ComponentHandle, SharedString};
|
||||
use tracing::warn;
|
||||
use tracing::{info, warn};
|
||||
use voelin_core::identity::LaunchImport;
|
||||
use voelin_core::{Command, ObserveState, Source, VoiceOptions, VoiceState};
|
||||
use voelin_store::{Bookmark, QueryTransport};
|
||||
@@ -134,12 +134,16 @@ impl App {
|
||||
.unwrap_or_else(|| "Voelin user".to_owned())
|
||||
}
|
||||
|
||||
/// Look up the gateway of a server that has none in DNS
|
||||
/// ([`voelin_core::discover`]); one found is kept as if typed.
|
||||
pub(crate) fn discover_gateway(&self, id: i64) {
|
||||
let Some(b) = self.bookmark(id).filter(|b| b.gateway_url.is_none() && !self.demo_ui) else {
|
||||
/// Look up the gateway of a server ([`voelin_core::discover`]), once a
|
||||
/// run: one found is kept as if typed, and takes the place of a stored
|
||||
/// one that is no longer what the server publishes (a gateway that
|
||||
/// moved, or one typed into an older version, which showed the field).
|
||||
/// Nothing found keeps what is stored.
|
||||
pub(crate) fn discover_gateway(&mut self, id: i64) {
|
||||
if self.demo_ui || !self.gateways_looked_up.insert(id) {
|
||||
return;
|
||||
};
|
||||
}
|
||||
let Some(b) = self.bookmark(id) else { return };
|
||||
let address = b.address.clone();
|
||||
self.engine.runtime().spawn(async move {
|
||||
if let Some(url) = voelin_core::discover::gateway(&address).await {
|
||||
@@ -150,23 +154,28 @@ impl App {
|
||||
|
||||
/// A gateway was found for the server at `address`; it is kept unless
|
||||
/// the server changed meanwhile, and the server is observed through it
|
||||
/// if it is the one shown.
|
||||
/// if it is the one shown. Users never hear of it (logged only).
|
||||
fn gateway_found(&mut self, id: i64, address: &str, url: String) {
|
||||
let Some(b) = self
|
||||
.bookmarks
|
||||
.iter_mut()
|
||||
.find(|b| b.id == id && b.address == address && b.gateway_url.is_none())
|
||||
else {
|
||||
let Some(b) = self.bookmarks.iter_mut().find(|b| b.id == id && b.address == address) else {
|
||||
return;
|
||||
};
|
||||
b.gateway_url = Some(url.clone());
|
||||
let name = b.name.clone();
|
||||
if b.gateway_url.as_deref() == Some(url.as_str()) {
|
||||
return;
|
||||
}
|
||||
let previous = b.gateway_url.replace(url.clone());
|
||||
if let Err(e) = self.store.update_bookmark(b) {
|
||||
warn!(%e, "could not keep the gateway found");
|
||||
return;
|
||||
}
|
||||
self.set_status(format!("Found the gateway of {name}: {url}"));
|
||||
info!(server = %b.address, %url, ?previous, "gateway found");
|
||||
self.refresh_toolbar();
|
||||
// Observed through the old one: through this one now.
|
||||
if previous.is_some() {
|
||||
self.engine.send(Command::StopObserving { session: id as u64 });
|
||||
if let Some(view) = self.sessions.get_mut(&id) {
|
||||
view.state.observe = ObserveState::Off;
|
||||
}
|
||||
}
|
||||
if self.current == Some(id) {
|
||||
self.observe(id);
|
||||
}
|
||||
@@ -210,6 +219,8 @@ impl App {
|
||||
url: url.clone(),
|
||||
identity: Box::new(self.identity_for(Some(b.id))),
|
||||
});
|
||||
// Still the one the server publishes?
|
||||
self.discover_gateway(b.id);
|
||||
} else if let Some(q) = &b.query {
|
||||
let secret = self.secrets.get(&b.query_password_key()).ok().flatten();
|
||||
let transport = match q.transport {
|
||||
@@ -283,11 +294,13 @@ impl App {
|
||||
if let Err(e) = result {
|
||||
warn!(%e, "could not store secret");
|
||||
}
|
||||
// Another server: what was observed is the old one's.
|
||||
// Another server: what was observed is the old one's, and its
|
||||
// gateway is looked up anew.
|
||||
if let Some(old) = old.filter(|old| old.address != bookmark.address) {
|
||||
if old.query.is_some() {
|
||||
let _ = self.secrets.delete(&old.query_password_key());
|
||||
}
|
||||
self.gateways_looked_up.remove(&bookmark.id);
|
||||
self.engine.send(Command::StopObserving { session: bookmark.id as u64 });
|
||||
if let Some(view) = self.sessions.get_mut(&bookmark.id) {
|
||||
view.state.observe = ObserveState::Off;
|
||||
@@ -305,6 +318,7 @@ impl App {
|
||||
}
|
||||
let _ = self.store.delete_bookmark(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.refresh_all();
|
||||
|
||||
@@ -18,17 +18,12 @@ const GROUP_MS: i64 = 5 * 60 * 1000;
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Previous {
|
||||
pub author: String,
|
||||
pub relayed: bool,
|
||||
pub ts_ms: i64,
|
||||
}
|
||||
|
||||
impl Previous {
|
||||
pub fn of(message: &ChatMessage) -> Self {
|
||||
Self {
|
||||
author: message.author_name.clone(),
|
||||
relayed: message.via_relay,
|
||||
ts_ms: message.ts_ms,
|
||||
}
|
||||
Self { author: message.author_name.clone(), ts_ms: message.ts_ms }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,9 +169,7 @@ fn line_of(
|
||||
files: &[FileRef],
|
||||
) -> ChatLine {
|
||||
let continued = previous.is_some_and(|p| {
|
||||
p.author == message.author_name
|
||||
&& p.relayed == message.via_relay
|
||||
&& (0..GROUP_MS).contains(&(message.ts_ms - p.ts_ms))
|
||||
p.author == message.author_name && (0..GROUP_MS).contains(&(message.ts_ms - p.ts_ms))
|
||||
});
|
||||
let text =
|
||||
if files.is_empty() { message.text.clone() } else { without_links(&message.text, files) };
|
||||
@@ -210,7 +203,6 @@ fn line_of(
|
||||
author: message.author_name.clone().into(),
|
||||
text: text.clone().into(),
|
||||
time: time_of(message.ts_ms).into(),
|
||||
relayed: message.via_relay,
|
||||
runs: runs.as_deref().map(runs_model).unwrap_or_default(),
|
||||
rich: runs.is_some(),
|
||||
jumbo,
|
||||
|
||||
@@ -12,11 +12,13 @@ pub fn cached_icon(bookmark: &Bookmark, cache: &voelin_core::Cache) -> slint::Im
|
||||
avatar::image(bookmark.server_icon_id().and_then(|id| cache.icon(id)).as_ref())
|
||||
}
|
||||
|
||||
/// "offline", "connecting", "observing" or "connected".
|
||||
/// "offline", "connecting", "observing" or "connected". "connecting" is
|
||||
/// voice only: observing that is not there yet (a gateway that is away and
|
||||
/// tried again) is "offline", as users never hear of the gateway.
|
||||
pub fn status(state: &SessionState) -> &'static str {
|
||||
match (state.voice, state.observe) {
|
||||
(VoiceState::Connected, _) => "connected",
|
||||
(VoiceState::Connecting, _) | (_, ObserveState::Connecting) => "connecting",
|
||||
(VoiceState::Connecting, _) => "connecting",
|
||||
(_, ObserveState::Observing) => "observing",
|
||||
_ => "offline",
|
||||
}
|
||||
@@ -152,6 +154,8 @@ mod tests {
|
||||
fn states() {
|
||||
let mut s = SessionState::default();
|
||||
assert_eq!(status(&s), "offline");
|
||||
s.observe = ObserveState::Connecting;
|
||||
assert_eq!(status(&s), "offline");
|
||||
s.observe = ObserveState::Observing;
|
||||
assert_eq!(status(&s), "observing");
|
||||
s.voice = VoiceState::Connecting;
|
||||
|
||||
@@ -189,7 +189,6 @@ export struct ChatLine {
|
||||
author: string,
|
||||
text: string,
|
||||
time: string,
|
||||
relayed: bool,
|
||||
// The text split into runs; only filled when it has emoji (`rich`).
|
||||
runs: [TextRun],
|
||||
rich: bool,
|
||||
|
||||
@@ -337,7 +337,7 @@ export component MessageRow inherits Rectangle {
|
||||
alignment: start;
|
||||
Text {
|
||||
text: line.author;
|
||||
color: line.relayed ? Theme.accent-text : Theme.name-text;
|
||||
color: Theme.name-text;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-medium;
|
||||
vertical-alignment: center;
|
||||
@@ -348,12 +348,6 @@ export component MessageRow inherits Rectangle {
|
||||
font-size: Theme.font-sm;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
if line.relayed: Chip {
|
||||
text: @tr("via relay");
|
||||
icon: Icons.radio;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
if line.pinned: Chip {
|
||||
text: @tr("pinned");
|
||||
icon: Icons.pin;
|
||||
|
||||
@@ -319,7 +319,7 @@ export component EventsPage inherits VerticalLayout {
|
||||
}
|
||||
}
|
||||
if !Bridge.has-events: Banner {
|
||||
text: @tr("This server's gateway does not keep events (or there is no gateway).");
|
||||
text: @tr("This server does not keep events.");
|
||||
icon: Icons.info;
|
||||
tone: Theme.info;
|
||||
}
|
||||
|
||||
@@ -1024,7 +1024,7 @@ export component HomePage inherits Rectangle {
|
||||
action-clicked => { root.more-live(); }
|
||||
}
|
||||
if Bridge.live-rooms.length == 0: Text {
|
||||
text: @tr("No one is live on your servers right now. Streams of TeamSpeak 6 servers and those a gateway lists show up here.");
|
||||
text: @tr("No one is live on your servers right now. Streams on your servers show up here.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
wrap: word-wrap;
|
||||
|
||||
@@ -882,7 +882,7 @@ export component IntegrationsSection inherits VerticalLayout {
|
||||
icon: Icons.plug;
|
||||
subtitle: @tr("A gateway gives a server invisible presence, chat without joining, history, pins, reactions, topics, events and the stream directory.");
|
||||
if Bridge.gateways.length == 0: Hint {
|
||||
text: @tr("None of your servers has a gateway. Add its URL to a server's bookmark (Edit server).");
|
||||
text: @tr("None of your servers has a gateway. Voelin finds one by the server's address when the server's admin publishes it.");
|
||||
}
|
||||
for gw in Bridge.gateways: VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
|
||||
@@ -943,7 +943,7 @@ component ChatRow inherits Rectangle {
|
||||
alignment: start;
|
||||
Text {
|
||||
text: line.author;
|
||||
color: line.relayed ? Theme.accent-text : Theme.name-text;
|
||||
color: Theme.name-text;
|
||||
font-size: Theme.font-body;
|
||||
font-weight: Theme.weight-medium;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user