fractal/components/pill/
at_room.rs1use gettextrs::gettext;
2use gtk::{glib, subclass::prelude::*};
3use ruma::OwnedRoomId;
4
5use crate::{components::PillSource, prelude::*};
6
7mod imp {
8 use std::cell::OnceCell;
9
10 use super::*;
11
12 #[derive(Debug, Default)]
13 pub struct AtRoom {
14 room_id: OnceCell<OwnedRoomId>,
16 }
17
18 #[glib::object_subclass]
19 impl ObjectSubclass for AtRoom {
20 const NAME: &'static str = "AtRoom";
21 type Type = super::AtRoom;
22 type ParentType = PillSource;
23 }
24
25 impl ObjectImpl for AtRoom {}
26
27 impl PillSourceImpl for AtRoom {
28 fn identifier(&self) -> String {
29 gettext("Notify the whole room")
30 }
31 }
32
33 impl AtRoom {
34 pub(super) fn set_room_id(&self, room_id: OwnedRoomId) {
36 self.room_id.set(room_id).expect("room ID is uninitialized");
37 }
38
39 pub(super) fn room_id(&self) -> &OwnedRoomId {
41 self.room_id.get().expect("room ID is initialized")
42 }
43 }
44}
45
46glib::wrapper! {
47 pub struct AtRoom(ObjectSubclass<imp::AtRoom>) @extends PillSource;
49}
50
51impl AtRoom {
52 pub fn new(room_id: OwnedRoomId) -> Self {
54 let obj = glib::Object::builder::<Self>()
55 .property("display-name", "@room")
56 .build();
57
58 obj.imp().set_room_id(room_id);
59
60 obj
61 }
62
63 pub fn room_id(&self) -> &OwnedRoomId {
65 self.imp().room_id()
66 }
67}