Browse Source

misc: Remove RefCell or OnceCell wrapping WeakRefs

merge-requests/1327/merge
Kévin Commaille 4 years ago
parent
commit
d19bb254d5
No known key found for this signature in database
GPG Key ID: DD507DAE96E8245C
  1. 12
      src/application.rs
  2. 11
      src/components/auth_dialog.rs
  3. 9
      src/session/account_settings/devices_page/device.rs
  4. 11
      src/session/account_settings/devices_page/device_list.rs
  5. 14
      src/session/account_settings/mod.rs
  6. 12
      src/session/account_settings/security_page/import_export_keys_subpage.rs
  7. 14
      src/session/account_settings/security_page/mod.rs
  8. 12
      src/session/account_settings/user_page/change_password_subpage.rs
  9. 10
      src/session/account_settings/user_page/deactivate_account_subpage.rs
  10. 12
      src/session/account_settings/user_page/mod.rs
  11. 11
      src/session/avatar.rs
  12. 12
      src/session/content/explore/mod.rs
  13. 12
      src/session/content/explore/public_room_list.rs
  14. 12
      src/session/content/mod.rs
  15. 10
      src/session/content/room_history/item_row.rs
  16. 9
      src/session/content/verification/session_verification.rs
  17. 12
      src/session/media_viewer.rs
  18. 16
      src/session/room/event/mod.rs
  19. 11
      src/session/room/member_list.rs
  20. 9
      src/session/room/mod.rs
  21. 15
      src/session/room/timeline/mod.rs
  22. 14
      src/session/room_creation/mod.rs
  23. 11
      src/session/room_list.rs
  24. 11
      src/session/sidebar/row.rs
  25. 15
      src/session/user.rs
  26. 8
      src/session/verification/identity_verification.rs
  27. 11
      src/session/verification/verification_list.rs

12
src/application.rs

@ -9,13 +9,12 @@ use crate::{config, Window};
mod imp {
use adw::subclass::prelude::AdwApplicationImpl;
use once_cell::unsync::OnceCell;
use super::*;
#[derive(Debug)]
pub struct Application {
pub window: OnceCell<WeakRef<Window>>,
pub window: WeakRef<Window>,
pub settings: Settings,
}
@ -41,17 +40,14 @@ mod imp {
fn activate(&self, app: &Self::Type) {
debug!("GtkApplication<Application>::activate");
if let Some(window) = self.window.get() {
let window = window.upgrade().unwrap();
if let Some(window) = self.window.upgrade() {
window.show();
window.present();
return;
}
let window = Window::new(app);
self.window
.set(window.downgrade())
.expect("Window already set.");
self.window.set(Some(&window));
app.setup_gactions();
app.setup_accels();
@ -100,7 +96,7 @@ impl Application {
}
fn get_main_window(&self) -> Window {
self.imp().window.get().unwrap().upgrade().unwrap()
self.imp().window.upgrade().unwrap()
}
pub fn settings(&self) -> Settings {

11
src/components/auth_dialog.rs

@ -85,14 +85,14 @@ mod imp {
subclass::{InitializingObject, Signal},
SignalHandlerId,
};
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/components-auth-dialog.ui")]
pub struct AuthDialog {
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
#[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
@ -155,10 +155,7 @@ mod imp {
pspec: &glib::ParamSpec,
) {
match pspec.name() {
"session" => self
.session
.set(value.get::<Session>().unwrap().downgrade())
.unwrap(),
"session" => self.session.set(value.get::<Session>().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -222,7 +219,7 @@ impl AuthDialog {
}
pub fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
/// Authenticates the user to the server via an authentication flow.

9
src/session/account_settings/devices_page/device.rs

@ -22,7 +22,7 @@ mod imp {
pub struct Device {
pub device: OnceCell<MatrixDevice>,
pub crypto_device: OnceCell<CryptoDevice>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
}
#[glib::object_subclass]
@ -91,10 +91,7 @@ mod imp {
pspec: &glib::ParamSpec,
) {
match pspec.name() {
"session" => self
.session
.set(value.get::<Session>().unwrap().downgrade())
.unwrap(),
"session" => self.session.set(value.get().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -133,7 +130,7 @@ impl Device {
}
pub fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
fn set_matrix_device(&self, device: MatrixDevice, crypto_device: Option<CryptoDevice>) {

11
src/session/account_settings/devices_page/device_list.rs

@ -13,14 +13,14 @@ mod imp {
use std::cell::{Cell, RefCell};
use glib::object::WeakRef;
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
#[derive(Debug, Default)]
pub struct DeviceList {
pub list: RefCell<Vec<DeviceItem>>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
pub current_device: RefCell<Option<DeviceItem>>,
pub loading: Cell<bool>,
}
@ -64,10 +64,7 @@ mod imp {
pspec: &glib::ParamSpec,
) {
match pspec.name() {
"session" => self
.session
.set(value.get::<Session>().unwrap().downgrade())
.unwrap(),
"session" => self.session.set(value.get().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -115,7 +112,7 @@ impl DeviceList {
}
pub fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
fn set_loading(&self, loading: bool) {

14
src/session/account_settings/mod.rs

@ -24,7 +24,7 @@ mod imp {
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/account-settings.ui")]
pub struct AccountSettings {
pub session: RefCell<Option<WeakRef<Session>>>,
pub session: WeakRef<Session>,
pub session_handler: RefCell<Option<glib::SignalHandlerId>>,
}
@ -98,7 +98,7 @@ mod imp {
}
fn dispose(&self, _obj: &Self::Type) {
if let Some(session) = self.session.take().and_then(|session| session.upgrade()) {
if let Some(session) = self.session.upgrade() {
if let Some(handler) = self.session_handler.take() {
session.disconnect(handler);
}
@ -125,11 +125,7 @@ impl AccountSettings {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.borrow()
.clone()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn set_session(&self, session: Option<Session>) {
@ -155,9 +151,7 @@ impl AccountSettings {
)));
}
self.imp()
.session
.replace(session.map(|session| session.downgrade()));
self.imp().session.set(session.as_ref());
self.notify("session");
}
}

12
src/session/account_settings/security_page/import_export_keys_subpage.rs

@ -33,14 +33,13 @@ mod imp {
use std::cell::{Cell, RefCell};
use glib::{subclass::InitializingObject, WeakRef};
use once_cell::unsync::OnceCell;
use super::*;
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/account-settings-import-export-keys-subpage.ui")]
pub struct ImportExportKeysSubpage {
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
#[template_child]
pub title: TemplateChild<gtk::Label>,
#[template_child]
@ -181,16 +180,11 @@ impl ImportExportKeysSubpage {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.get()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn set_session(&self, session: Option<Session>) {
if let Some(session) = session {
self.imp().session.set(session.downgrade()).unwrap();
}
self.imp().session.set(session.as_ref());
}
pub fn file_path(&self) -> Option<gio::File> {

14
src/session/account_settings/security_page/mod.rs

@ -7,8 +7,6 @@ mod import_export_keys_subpage;
use import_export_keys_subpage::{ImportExportKeysSubpage, KeysSubpageMode};
mod imp {
use std::cell::RefCell;
use glib::{subclass::InitializingObject, WeakRef};
use super::*;
@ -16,7 +14,7 @@ mod imp {
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/account-settings-security-page.ui")]
pub struct SecurityPage {
pub session: RefCell<Option<WeakRef<Session>>>,
pub session: WeakRef<Session>,
#[template_child]
pub import_export_keys_subpage: TemplateChild<ImportExportKeysSubpage>,
}
@ -93,11 +91,7 @@ impl SecurityPage {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.borrow()
.clone()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn set_session(&self, session: Option<Session>) {
@ -105,9 +99,7 @@ impl SecurityPage {
return;
}
self.imp()
.session
.replace(session.map(|session| session.downgrade()));
self.imp().session.set(session.as_ref());
self.notify("session");
}

12
src/session/account_settings/user_page/change_password_subpage.rs

@ -25,14 +25,13 @@ use crate::{
mod imp {
use glib::{subclass::InitializingObject, WeakRef};
use once_cell::unsync::OnceCell;
use super::*;
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/account-settings-change-password-subpage.ui")]
pub struct ChangePasswordSubpage {
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
#[template_child]
pub password: TemplateChild<PasswordEntryRow>,
#[template_child]
@ -177,16 +176,11 @@ impl ChangePasswordSubpage {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.get()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn set_session(&self, session: Option<Session>) {
if let Some(session) = session {
self.imp().session.set(session.downgrade()).unwrap();
}
self.imp().session.set(session.as_ref());
}
fn validate_password(&self) {

10
src/session/account_settings/user_page/deactivate_account_subpage.rs

@ -15,14 +15,13 @@ use crate::{
mod imp {
use glib::{subclass::InitializingObject, WeakRef};
use once_cell::unsync::OnceCell;
use super::*;
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/account-settings-deactivate-account-subpage.ui")]
pub struct DeactivateAccountSubpage {
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
#[template_child]
pub confirmation: TemplateChild<adw::EntryRow>,
#[template_child]
@ -123,16 +122,13 @@ impl DeactivateAccountSubpage {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.get()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn set_session(&self, session: Option<Session>) {
if let Some(session) = session {
let priv_ = self.imp();
priv_.session.set(session.downgrade()).unwrap();
priv_.session.set(Some(&session));
priv_.confirmation.set_title(&self.user_id());
}
}

12
src/session/account_settings/user_page/mod.rs

@ -33,7 +33,7 @@ mod imp {
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/account-settings-user-page.ui")]
pub struct UserPage {
pub session: RefCell<Option<WeakRef<Session>>>,
pub session: WeakRef<Session>,
#[template_child]
pub avatar: TemplateChild<EditableAvatar>,
#[template_child]
@ -141,20 +141,14 @@ impl UserPage {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.borrow()
.clone()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn set_session(&self, session: Option<Session>) {
if self.session() == session {
return;
}
self.imp()
.session
.replace(session.map(|session| session.downgrade()));
self.imp().session.set(session.as_ref());
self.notify("session");
self.user().avatar().connect_notify_local(

11
src/session/avatar.rs

@ -19,7 +19,7 @@ mod imp {
use std::cell::{Cell, RefCell};
use glib::object::WeakRef;
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
@ -29,7 +29,7 @@ mod imp {
pub needed_size: Cell<u32>,
pub url: RefCell<Option<OwnedMxcUri>>,
pub display_name: RefCell<Option<String>>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
}
#[glib::object_subclass]
@ -95,10 +95,7 @@ mod imp {
match pspec.name() {
"needed-size" => obj.set_needed_size(value.get().unwrap()),
"url" => obj.set_url(value.get::<Option<&str>>().unwrap().map(Into::into)),
"session" => self
.session
.set(value.get::<Session>().unwrap().downgrade())
.unwrap(),
"session" => self.session.set(value.get::<Session>().ok().as_ref()),
"display-name" => obj.set_display_name(value.get().unwrap()),
_ => unimplemented!(),
}
@ -137,7 +134,7 @@ impl Avatar {
}
fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
pub fn image(&self) -> Option<gdk::Paintable> {

12
src/session/content/explore/mod.rs

@ -24,7 +24,7 @@ mod imp {
#[template(resource = "/org/gnome/Fractal/content-explore.ui")]
pub struct Explore {
pub compact: Cell<bool>,
pub session: RefCell<Option<WeakRef<Session>>>,
pub session: WeakRef<Session>,
#[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child]
@ -146,11 +146,7 @@ impl Explore {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.borrow()
.as_ref()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn init(&self) {
@ -192,9 +188,7 @@ impl Explore {
priv_.public_room_list.replace(Some(public_room_list));
}
priv_
.session
.replace(session.map(|session| session.downgrade()));
priv_.session.set(session.as_ref());
self.notify("session");
}

12
src/session/content/explore/public_room_list.rs

@ -34,7 +34,7 @@ mod imp {
pub loading: Cell<bool>,
pub request_sent: Cell<bool>,
pub total_room_count_estimate: Cell<Option<u64>>,
pub session: RefCell<Option<WeakRef<Session>>>,
pub session: WeakRef<Session>,
}
#[glib::object_subclass]
@ -134,11 +134,7 @@ impl PublicRoomList {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.borrow()
.as_ref()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn set_session(&self, session: Option<Session>) {
@ -146,9 +142,7 @@ impl PublicRoomList {
return;
}
self.imp()
.session
.replace(session.map(|session| session.downgrade()));
self.imp().session.set(session.as_ref());
self.notify("session");
}

12
src/session/content/mod.rs

@ -31,7 +31,7 @@ mod imp {
#[template(resource = "/org/gnome/Fractal/content.ui")]
pub struct Content {
pub compact: Cell<bool>,
pub session: RefCell<Option<WeakRef<Session>>>,
pub session: WeakRef<Session>,
pub item: RefCell<Option<glib::Object>>,
pub signal_handler: RefCell<Option<SignalHandlerId>>,
#[template_child]
@ -171,11 +171,7 @@ impl Content {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.borrow()
.as_ref()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
pub fn set_session(&self, session: Option<Session>) {
@ -183,9 +179,7 @@ impl Content {
return;
}
self.imp()
.session
.replace(session.map(|session| session.downgrade()));
self.imp().session.set(session.as_ref());
self.notify("session");
}

10
src/session/content/room_history/item_row.rs

@ -19,13 +19,12 @@ mod imp {
use std::{cell::RefCell, rc::Rc};
use glib::{signal::SignalHandlerId, WeakRef};
use once_cell::unsync::OnceCell;
use super::*;
#[derive(Debug, Default)]
pub struct ItemRow {
pub room_history: OnceCell<WeakRef<RoomHistory>>,
pub room_history: WeakRef<RoomHistory>,
pub item: RefCell<Option<TimelineItem>>,
pub action_group: RefCell<Option<gio::SimpleActionGroup>>,
pub notify_handler: RefCell<Option<SignalHandlerId>>,
@ -75,10 +74,7 @@ mod imp {
) {
match pspec.name() {
"item" => obj.set_item(value.get().unwrap()),
"room-history" => self
.room_history
.set(value.get::<RoomHistory>().unwrap().downgrade())
.unwrap(),
"room-history" => self.room_history.set(value.get().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -179,7 +175,7 @@ impl ItemRow {
}
pub fn room_history(&self) -> RoomHistory {
self.imp().room_history.get().unwrap().upgrade().unwrap()
self.imp().room_history.upgrade().unwrap()
}
pub fn action_group(&self) -> Option<gio::SimpleActionGroup> {

9
src/session/content/verification/session_verification.rs

@ -14,7 +14,6 @@ mod imp {
use std::cell::RefCell;
use glib::{subclass::InitializingObject, SignalHandlerId, WeakRef};
use once_cell::unsync::OnceCell;
use super::*;
@ -22,7 +21,7 @@ mod imp {
#[template(resource = "/org/gnome/Fractal/session-verification.ui")]
pub struct SessionVerification {
pub request: RefCell<Option<IdentityVerification>>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
#[template_child]
pub bootstrap_button: TemplateChild<SpinnerButton>,
#[template_child]
@ -143,11 +142,11 @@ impl SessionVerification {
/// The current `Session`.
pub fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
fn set_session(&self, session: Session) {
self.imp().session.set(session.downgrade()).unwrap()
fn set_session(&self, session: Option<Session>) {
self.imp().session.set(session.as_ref())
}
fn request(&self) -> Option<IdentityVerification> {

12
src/session/media_viewer.rs

@ -24,7 +24,7 @@ mod imp {
#[template(resource = "/org/gnome/Fractal/media-viewer.ui")]
pub struct MediaViewer {
pub fullscreened: Cell<bool>,
pub event: RefCell<Option<WeakRef<SupportedEvent>>>,
pub event: WeakRef<SupportedEvent>,
pub body: RefCell<Option<String>>,
#[template_child]
pub flap: TemplateChild<adw::Flap>,
@ -154,11 +154,7 @@ impl MediaViewer {
}
pub fn event(&self) -> Option<SupportedEvent> {
self.imp()
.event
.borrow()
.as_ref()
.and_then(|event| event.upgrade())
self.imp().event.upgrade()
}
pub fn set_event(&self, event: Option<SupportedEvent>) {
@ -166,9 +162,7 @@ impl MediaViewer {
return;
}
self.imp()
.event
.replace(event.map(|event| event.downgrade()));
self.imp().event.set(event.as_ref());
self.build();
self.notify("event");
}

16
src/session/room/event/mod.rs

@ -24,7 +24,7 @@ mod imp {
use std::cell::RefCell;
use glib::{object::WeakRef, Class};
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
@ -70,7 +70,7 @@ mod imp {
pub pure_event: RefCell<Option<SyncTimelineEvent>>,
/// The room containing this `Event`.
pub room: OnceCell<WeakRef<Room>>,
pub room: WeakRef<Room>,
}
#[glib::object_subclass]
@ -133,9 +133,7 @@ mod imp {
obj.set_pure_event(event.0);
}
"room" => {
self.room
.set(value.get::<Room>().unwrap().downgrade())
.unwrap();
self.room.set(value.get().ok().as_ref());
}
_ => unimplemented!(),
}
@ -248,13 +246,7 @@ pub trait EventExt: 'static {
impl<O: IsA<Event>> EventExt for O {
fn room(&self) -> Room {
self.upcast_ref()
.imp()
.room
.get()
.unwrap()
.upgrade()
.unwrap()
self.upcast_ref().imp().room.upgrade().unwrap()
}
fn pure_event(&self) -> SyncTimelineEvent {

11
src/session/room/member_list.rs

@ -11,14 +11,14 @@ mod imp {
use std::cell::RefCell;
use glib::object::WeakRef;
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
#[derive(Debug, Default)]
pub struct MemberList {
pub members: RefCell<IndexMap<OwnedUserId, Member>>,
pub room: OnceCell<WeakRef<Room>>,
pub room: WeakRef<Room>,
}
#[glib::object_subclass]
@ -51,10 +51,7 @@ mod imp {
pspec: &glib::ParamSpec,
) {
match pspec.name() {
"room" => self
.room
.set(value.get::<Room>().unwrap().downgrade())
.unwrap(),
"room" => self.room.set(value.get().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -98,7 +95,7 @@ impl MemberList {
}
pub fn room(&self) -> Room {
self.imp().room.get().unwrap().upgrade().unwrap()
self.imp().room.upgrade().unwrap()
}
/// Updates members with the given RoomMember values.

9
src/session/room/mod.rs

@ -82,7 +82,7 @@ mod imp {
pub struct Room {
pub room_id: OnceCell<OwnedRoomId>,
pub matrix_room: RefCell<Option<MatrixRoom>>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
pub name: RefCell<Option<String>>,
pub avatar: OnceCell<Avatar>,
pub category: Cell<RoomType>,
@ -259,10 +259,7 @@ mod imp {
pspec: &glib::ParamSpec,
) {
match pspec.name() {
"session" => self
.session
.set(value.get::<Session>().unwrap().downgrade())
.unwrap(),
"session" => self.session.set(value.get().ok().as_ref()),
"display-name" => {
let room_name = value.get().unwrap();
obj.store_room_name(room_name)
@ -380,7 +377,7 @@ impl Room {
}
pub fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
pub fn room_id(&self) -> &RoomId {

15
src/session/room/timeline/mod.rs

@ -51,13 +51,13 @@ mod imp {
use std::cell::{Cell, RefCell};
use glib::object::WeakRef;
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
#[derive(Debug, Default)]
pub struct Timeline {
pub room: OnceCell<WeakRef<Room>>,
pub room: WeakRef<Room>,
/// A store to keep track of related events that aren't known
pub relates_to_events: RefCell<HashMap<OwnedEventId, Vec<OwnedEventId>>>,
/// All events shown in the room history
@ -121,10 +121,7 @@ mod imp {
pspec: &glib::ParamSpec,
) {
match pspec.name() {
"room" => {
let room = value.get::<Room>().unwrap();
obj.set_room(room);
}
"room" => obj.set_room(value.get().unwrap()),
_ => unimplemented!(),
}
}
@ -837,12 +834,12 @@ impl Timeline {
self.items_changed(0, 0, added as u32);
}
fn set_room(&self, room: Room) {
self.imp().room.set(room.downgrade()).unwrap();
fn set_room(&self, room: Option<Room>) {
self.imp().room.set(room.as_ref());
}
pub fn room(&self) -> Room {
self.imp().room.get().unwrap().upgrade().unwrap()
self.imp().room.upgrade().unwrap()
}
fn set_state(&self, state: TimelineState) {

14
src/session/room_creation/mod.rs

@ -26,8 +26,6 @@ use crate::{
const MAX_BYTES: usize = 255;
mod imp {
use std::cell::RefCell;
use glib::{object::WeakRef, subclass::InitializingObject};
use super::*;
@ -35,7 +33,7 @@ mod imp {
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/room-creation.ui")]
pub struct RoomCreation {
pub session: RefCell<Option<WeakRef<Session>>>,
pub session: WeakRef<Session>,
#[template_child]
pub content: TemplateChild<gtk::ListBox>,
#[template_child]
@ -164,11 +162,7 @@ impl RoomCreation {
}
pub fn session(&self) -> Option<Session> {
self.imp()
.session
.borrow()
.as_ref()
.and_then(|session| session.upgrade())
self.imp().session.upgrade()
}
fn set_session(&self, session: Option<Session>) {
@ -184,9 +178,7 @@ impl RoomCreation {
.set_label(&[":", user.user_id().server_name().as_str()].concat());
}
priv_
.session
.replace(session.map(|session| session.downgrade()));
priv_.session.set(session.as_ref());
self.notify("session");
}

11
src/session/room_list.rs

@ -18,7 +18,7 @@ mod imp {
use std::cell::RefCell;
use glib::{object::WeakRef, subclass::Signal};
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
@ -26,7 +26,7 @@ mod imp {
pub struct RoomList {
pub list: RefCell<IndexMap<OwnedRoomId, Room>>,
pub pending_rooms: RefCell<HashSet<OwnedRoomOrAliasId>>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
}
#[glib::object_subclass]
@ -59,10 +59,7 @@ mod imp {
pspec: &glib::ParamSpec,
) {
match pspec.name() {
"session" => self
.session
.set(value.get::<Session>().unwrap().downgrade())
.unwrap(),
"session" => self.session.set(value.get().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -122,7 +119,7 @@ impl RoomList {
}
pub fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
pub fn is_pending_room(&self, identifier: &RoomOrAliasId) -> bool {

11
src/session/sidebar/row.rs

@ -16,13 +16,13 @@ mod imp {
use std::cell::RefCell;
use glib::WeakRef;
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
#[derive(Debug, Default)]
pub struct Row {
pub sidebar: OnceCell<WeakRef<Sidebar>>,
pub sidebar: WeakRef<Sidebar>,
pub list_row: RefCell<Option<gtk::TreeListRow>>,
pub bindings: RefCell<Vec<glib::Binding>>,
}
@ -78,10 +78,7 @@ mod imp {
) {
match pspec.name() {
"list-row" => obj.set_list_row(value.get().unwrap()),
"sidebar" => self
.sidebar
.set(value.get::<Sidebar>().unwrap().downgrade())
.unwrap(),
"sidebar" => self.sidebar.set(value.get().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -133,7 +130,7 @@ impl Row {
}
pub fn sidebar(&self) -> Sidebar {
self.imp().sidebar.get().unwrap().upgrade().unwrap()
self.imp().sidebar.upgrade().unwrap()
}
pub fn item(&self) -> Option<SidebarItem> {

15
src/session/user.rs

@ -38,7 +38,7 @@ mod imp {
pub struct User {
pub user_id: OnceCell<OwnedUserId>,
pub display_name: RefCell<Option<String>>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
pub avatar: OnceCell<Avatar>,
pub is_verified: Cell<bool>,
}
@ -118,10 +118,7 @@ mod imp {
"display-name" => {
obj.set_display_name(value.get::<Option<String>>().unwrap());
}
"session" => self
.session
.set(value.get::<Session>().unwrap().downgrade())
.unwrap(),
"session" => self.session.set(value.get().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -214,13 +211,7 @@ impl User {
pub trait UserExt: IsA<User> {
fn session(&self) -> Session {
self.upcast_ref()
.imp()
.session
.get()
.unwrap()
.upgrade()
.unwrap()
self.upcast_ref().imp().session.upgrade().unwrap()
}
fn user_id(&self) -> OwnedUserId {

8
src/session/verification/identity_verification.rs

@ -171,7 +171,7 @@ mod imp {
#[derive(Default)]
pub struct IdentityVerification {
pub user: OnceCell<User>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
pub state: Cell<State>,
pub mode: OnceCell<Mode>,
pub supported_methods: Cell<SupportedMethods>,
@ -524,11 +524,11 @@ impl IdentityVerification {
/// The current `Session`.
pub fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
fn set_session(&self, session: Session) {
self.imp().session.set(session.downgrade()).unwrap()
fn set_session(&self, session: Option<Session>) {
self.imp().session.set(session.as_ref())
}
fn setup_timeout(&self) {

11
src/session/verification/verification_list.rs

@ -50,14 +50,14 @@ mod imp {
use glib::object::WeakRef;
use indexmap::IndexMap;
use once_cell::{sync::Lazy, unsync::OnceCell};
use once_cell::sync::Lazy;
use super::*;
#[derive(Debug, Default)]
pub struct VerificationList {
pub list: RefCell<IndexMap<FlowId, IdentityVerification>>,
pub session: OnceCell<WeakRef<Session>>,
pub session: WeakRef<Session>,
}
#[glib::object_subclass]
@ -90,10 +90,7 @@ mod imp {
pspec: &glib::ParamSpec,
) {
match pspec.name() {
"session" => self
.session
.set(value.get::<Session>().unwrap().downgrade())
.unwrap(),
"session" => self.session.set(value.get().ok().as_ref()),
_ => unimplemented!(),
}
}
@ -133,7 +130,7 @@ impl VerificationList {
}
pub fn session(&self) -> Session {
self.imp().session.get().unwrap().upgrade().unwrap()
self.imp().session.upgrade().unwrap()
}
pub fn handle_response_to_device(&self, to_device: ToDevice) {

Loading…
Cancel
Save