Skip to main content

xmpp_parsers/muc/
mav.rs

1// Copyright (c) 2026 Link Mauve <linkmauve@linkmauve.fr>
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 xso::{AsXml, FromXml};
8
9use crate::ns;
10
11generate_id!(
12    /// Unique and opaque string, indicating the last affiliation version sent by the server that
13    /// the client has seen, and cached.
14    Version
15);
16
17/// A `<mav/>` element sent by the client on join, if it wants to keep track of the affiliations in
18/// the room.
19#[derive(FromXml, AsXml, Debug, Clone, PartialEq)]
20#[xml(namespace = ns::MAV, name = "mav")]
21pub struct AffiliationsVersioning {
22    /// Unique and opaque string, indicating the last affiliation version sent by the server that
23    /// the client has seen, and cached.  Sending the mav element without a since attribute is a
24    /// called bootstrap request, which asks the server for a full response.
25    #[xml(attribute(default))]
26    since: Option<Version>,
27
28    /// The latest version the server has.
29    #[xml(attribute(default))]
30    until: Option<Version>,
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36    use minidom::Element;
37
38    #[cfg(target_pointer_width = "32")]
39    #[test]
40    fn test_size() {
41        assert_size!(Version, 12);
42        assert_size!(AffiliationsVersioning, 24);
43    }
44
45    #[cfg(target_pointer_width = "64")]
46    #[test]
47    fn test_size() {
48        assert_size!(Version, 24);
49        assert_size!(AffiliationsVersioning, 48);
50    }
51
52    #[test]
53    fn test_simple() {
54        let elem: Element = "<mav xmlns='urn:xmpp:muc:affiliations:1'/>"
55            .parse()
56            .unwrap();
57        let ver = AffiliationsVersioning::try_from(elem).unwrap();
58        assert!(ver.since.is_none());
59        assert!(ver.until.is_none());
60
61        let elem: Element =
62            "<mav xmlns='urn:xmpp:muc:affiliations:1' since='9pacabr2q1' until='ruz41312vw'/>"
63                .parse()
64                .unwrap();
65        let ver = AffiliationsVersioning::try_from(elem).unwrap();
66        assert_eq!(ver.since.unwrap().0, "9pacabr2q1");
67        assert_eq!(ver.until.unwrap().0, "ruz41312vw");
68    }
69}