1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use gettextrs::gettext;
use gtk::{glib, subclass::prelude::*};
use ruma::OwnedRoomId;

use crate::{components::PillSource, prelude::*};

mod imp {
    use std::cell::OnceCell;

    use super::*;

    #[derive(Debug, Default)]
    pub struct AtRoom {
        /// The ID of the room currently represented.
        pub room_id: OnceCell<OwnedRoomId>,
    }

    #[glib::object_subclass]
    impl ObjectSubclass for AtRoom {
        const NAME: &'static str = "AtRoom";
        type Type = super::AtRoom;
        type ParentType = PillSource;
    }

    impl ObjectImpl for AtRoom {}

    impl PillSourceImpl for AtRoom {
        fn identifier(&self) -> String {
            gettext("Notify the whole room")
        }
    }
}

glib::wrapper! {
    /// A helper `PillSource` to represent an `@room` mention.
    pub struct AtRoom(ObjectSubclass<imp::AtRoom>) @extends PillSource;
}

impl AtRoom {
    /// Constructs an empty `@room` mention.
    pub fn new(room_id: OwnedRoomId) -> Self {
        let obj = glib::Object::builder::<Self>()
            .property("display-name", "@room")
            .build();

        obj.imp().room_id.set(room_id).unwrap();

        obj
    }

    /// The ID of the room currently represented.
    pub fn room_id(&self) -> &OwnedRoomId {
        self.imp().room_id.get().unwrap()
    }
}