xmpp/
config.rs

1// Copyright (c) 2025 Crate authors
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7use crate::RoomNick;
8use core::str::FromStr;
9
10/// [Disco](https://xmpp.org/registrar/disco-categories.html#client) identity type
11#[derive(Debug, Clone)]
12pub enum ClientType {
13    Bot,
14    Pc,
15}
16
17impl Default for ClientType {
18    fn default() -> Self {
19        ClientType::Bot
20    }
21}
22
23impl ToString for ClientType {
24    fn to_string(&self) -> String {
25        String::from(match self {
26            ClientType::Bot => "bot",
27            ClientType::Pc => "pc",
28        })
29    }
30}
31
32/// Store Agent configuration. Differs from state which is generated at runtime
33#[derive(Debug, Clone)]
34pub struct Config {
35    /// Synchronize bookmarks based on autojoin flag.
36    /// The client will join and leave based on the value of the `autojoin` flag on the (pubsub)
37    /// bookmark item.
38    /// If this `bookmarks_autojoin` attribute is set to false, `autojoin` set to false won't make
39    /// the client leave a room, neither will the removal of a bookmark item. This will only happen
40    /// after the client is restarted, as these items won't be automatically joined anymore.
41    /// <https://xmpp.org/extensions/xep-0402.html#notification>
42    pub bookmarks_autojoin: bool,
43
44    /// Nickname to use if no other is specified.
45    pub default_nick: RoomNick,
46
47    /// Client “Disco” identity.
48    pub disco: (ClientType, String),
49
50    /// Default language conveyed in stanza. Mostly useful for messages content.
51    pub lang: Vec<String>,
52
53    /// Project website advertized in client capabilities.
54    pub website: String,
55}
56
57impl Default for Config {
58    fn default() -> Self {
59        Self::new()
60    }
61}
62
63impl Config {
64    fn new() -> Self {
65        Config {
66            bookmarks_autojoin: true,
67            default_nick: RoomNick::from_str("xmpp-rs").unwrap(),
68            disco: (ClientType::default(), String::from("tokio-xmpp")),
69            lang: vec![String::from("en")],
70            website: String::from("https://gitlab.com/xmpp-rs/tokio-xmpp"),
71        }
72    }
73}