Skip to main content

tuwunel_core/config/
typing.rs

1//! Configures typing notifications.
2//!
3//! Federation delivery has separate incoming and outgoing controls. Local
4//! and remote timeout bounds constrain typing indications.
5
6use serde::Deserialize;
7use tuwunel_macros::config_example_generator;
8
9use super::true_fn;
10
11/// Typing notifications
12///
13/// Controls whether typing notifications are exchanged with other servers
14/// and how long a typing indicator lasts when no stop request arrives.
15/// Federation is on in both directions by default.
16///
17/// Tips:
18/// - `client_timeout_min_s` must not exceed `client_timeout_max_s`. Startup
19///   and reload refuse an inverted pair.
20#[expect(rustdoc::broken_intra_doc_links, rustdoc::bare_urls)]
21#[derive(Clone, Copy, Debug, Deserialize)]
22#[config_example_generator(
23	filename = "tuwunel-example.toml",
24	section = "global.typing",
25	group = "true"
26)]
27pub struct Typing {
28	/// Allows sending typing updates over federation.
29	///
30	/// reloadable: yes
31	/// legacy: allow_outgoing_typing
32	#[serde(default = "true_fn")]
33	pub allow_outgoing: bool,
34
35	/// Allows receiving typing updates over federation.
36	///
37	/// reloadable: yes
38	/// legacy: allow_incoming_typing
39	#[serde(default = "true_fn")]
40	pub allow_incoming: bool,
41
42	/// Limits how long a federated user can indicate typing.
43	///
44	/// reloadable: yes
45	/// default: 30
46	/// legacy: typing_federation_timeout_s
47	#[serde(default = "default_federation_timeout_s")]
48	pub federation_timeout_s: u64,
49
50	/// Sets the minimum time a local client can indicate typing.
51	///
52	/// A request to stop typing still takes effect. The minimum applies only
53	/// when no stop request arrives.
54	///
55	/// reloadable: yes
56	/// default: 15
57	/// legacy: typing_client_timeout_min_s
58	#[serde(default = "default_client_timeout_min_s")]
59	pub client_timeout_min_s: u64,
60
61	/// Limits how long a local client can indicate typing.
62	///
63	/// reloadable: yes
64	/// default: 45
65	/// legacy: typing_client_timeout_max_s
66	#[serde(default = "default_client_timeout_max_s")]
67	pub client_timeout_max_s: u64,
68}
69
70impl Default for Typing {
71	fn default() -> Self {
72		Self {
73			allow_outgoing: true_fn(),
74			allow_incoming: true_fn(),
75			federation_timeout_s: default_federation_timeout_s(),
76			client_timeout_min_s: default_client_timeout_min_s(),
77			client_timeout_max_s: default_client_timeout_max_s(),
78		}
79	}
80}
81
82fn default_federation_timeout_s() -> u64 { 30 }
83
84fn default_client_timeout_min_s() -> u64 { 15 }
85
86fn default_client_timeout_max_s() -> u64 { 45 }