fractal/session_list/
failed_session.rs1use gtk::{glib, subclass::prelude::*};
2
3use super::{SessionInfo, SessionInfoImpl};
4use crate::{
5 components::AvatarData, prelude::*, secret::StoredSession, utils::matrix::ClientSetupError,
6};
7
8mod imp {
9 use std::cell::OnceCell;
10
11 use super::*;
12
13 #[derive(Debug, Default)]
14 pub struct FailedSession {
15 error: OnceCell<ClientSetupError>,
17 avatar_data: OnceCell<AvatarData>,
19 }
20
21 #[glib::object_subclass]
22 impl ObjectSubclass for FailedSession {
23 const NAME: &'static str = "FailedSession";
24 type Type = super::FailedSession;
25 type ParentType = SessionInfo;
26 }
27
28 impl ObjectImpl for FailedSession {}
29
30 impl SessionInfoImpl for FailedSession {
31 fn avatar_data(&self) -> AvatarData {
32 self.avatar_data
33 .get_or_init(|| {
34 let avatar_data = AvatarData::new();
35 avatar_data.set_display_name(self.obj().user_id().to_string());
36 avatar_data
37 })
38 .clone()
39 }
40 }
41
42 impl FailedSession {
43 pub(super) fn set_error(&self, error: ClientSetupError) {
45 self.error
46 .set(error)
47 .expect("error should not be initialized");
48 }
49
50 pub(super) fn error(&self) -> &ClientSetupError {
52 self.error.get().expect("error should be initialized")
53 }
54 }
55}
56
57glib::wrapper! {
58 pub struct FailedSession(ObjectSubclass<imp::FailedSession>)
60 @extends SessionInfo;
61}
62
63impl FailedSession {
64 pub(crate) fn new(stored_session: &StoredSession, error: ClientSetupError) -> Self {
66 let obj = glib::Object::builder::<Self>()
67 .property("info", stored_session)
68 .build();
69 obj.imp().set_error(error);
70 obj
71 }
72
73 pub(crate) fn error(&self) -> &ClientSetupError {
75 self.imp().error()
76 }
77}