session: Move room encryption event handler to Room
This commit is contained in:
parent
ad9deced91
commit
deaa6e6166
|
@ -26,6 +26,7 @@ use ruma::{
|
||||||
receipt::{ReceiptEventContent, ReceiptType},
|
receipt::{ReceiptEventContent, ReceiptType},
|
||||||
relation::Annotation,
|
relation::Annotation,
|
||||||
room::{
|
room::{
|
||||||
|
encryption::SyncRoomEncryptionEvent,
|
||||||
join_rules::JoinRule,
|
join_rules::JoinRule,
|
||||||
power_levels::{PowerLevelAction, RoomPowerLevelsEventContent},
|
power_levels::{PowerLevelAction, RoomPowerLevelsEventContent},
|
||||||
},
|
},
|
||||||
|
@ -296,6 +297,7 @@ impl Room {
|
||||||
self.set_up_receipts();
|
self.set_up_receipts();
|
||||||
self.set_up_typing();
|
self.set_up_typing();
|
||||||
self.init_timeline();
|
self.init_timeline();
|
||||||
|
self.set_up_is_encrypted();
|
||||||
|
|
||||||
spawn!(
|
spawn!(
|
||||||
glib::Priority::DEFAULT_IDLE,
|
glib::Priority::DEFAULT_IDLE,
|
||||||
|
@ -338,13 +340,6 @@ impl Room {
|
||||||
obj.init_power_levels().await;
|
obj.init_power_levels().await;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
spawn!(
|
|
||||||
glib::Priority::DEFAULT_IDLE,
|
|
||||||
clone!(@weak self as obj => async move {
|
|
||||||
obj.load_is_encrypted().await;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_timeline(&self) {
|
fn init_timeline(&self) {
|
||||||
|
@ -1500,7 +1495,7 @@ impl Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set whether this room is encrypted.
|
/// Set whether this room is encrypted.
|
||||||
pub fn set_is_encrypted(&self, is_encrypted: bool) {
|
fn set_is_encrypted(&self, is_encrypted: bool) {
|
||||||
let was_encrypted = self.encrypted();
|
let was_encrypted = self.encrypted();
|
||||||
if was_encrypted == is_encrypted {
|
if was_encrypted == is_encrypted {
|
||||||
return;
|
return;
|
||||||
|
@ -1520,6 +1515,31 @@ impl Room {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Listen to changes in room encryption.
|
||||||
|
fn set_up_is_encrypted(&self) {
|
||||||
|
let matrix_room = self.matrix_room();
|
||||||
|
|
||||||
|
let obj_weak = glib::SendWeakRef::from(self.downgrade());
|
||||||
|
matrix_room.add_event_handler(move |_: SyncRoomEncryptionEvent| {
|
||||||
|
let obj_weak = obj_weak.clone();
|
||||||
|
async move {
|
||||||
|
let ctx = glib::MainContext::default();
|
||||||
|
ctx.spawn(async move {
|
||||||
|
if let Some(obj) = obj_weak.upgrade() {
|
||||||
|
obj.set_is_encrypted(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
spawn!(
|
||||||
|
glib::Priority::DEFAULT_IDLE,
|
||||||
|
clone!(@weak self as obj => async move {
|
||||||
|
obj.load_is_encrypted().await;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Load whether the room is encrypted from the SDK.
|
/// Load whether the room is encrypted from the SDK.
|
||||||
async fn load_is_encrypted(&self) {
|
async fn load_is_encrypted(&self) {
|
||||||
let matrix_room = self.matrix_room().clone();
|
let matrix_room = self.matrix_room().clone();
|
||||||
|
|
|
@ -8,10 +8,7 @@ use gtk::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
subclass::prelude::*,
|
subclass::prelude::*,
|
||||||
};
|
};
|
||||||
use matrix_sdk::{
|
use matrix_sdk::{config::SyncSettings, matrix_auth::MatrixSession, sync::SyncResponse, Client};
|
||||||
config::SyncSettings, matrix_auth::MatrixSession, room::Room as MatrixRoom, sync::SyncResponse,
|
|
||||||
Client,
|
|
||||||
};
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{
|
api::client::{
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
|
@ -19,10 +16,7 @@ use ruma::{
|
||||||
session::logout,
|
session::logout,
|
||||||
},
|
},
|
||||||
assign,
|
assign,
|
||||||
events::{
|
events::{direct::DirectEventContent, GlobalAccountDataEvent},
|
||||||
direct::DirectEventContent, room::encryption::SyncRoomEncryptionEvent,
|
|
||||||
GlobalAccountDataEvent,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
|
@ -219,7 +213,6 @@ impl Session {
|
||||||
|
|
||||||
self.room_list().load().await;
|
self.room_list().load().await;
|
||||||
self.setup_direct_room_handler();
|
self.setup_direct_room_handler();
|
||||||
self.setup_room_encrypted_changes();
|
|
||||||
|
|
||||||
self.set_state(SessionState::InitialSync);
|
self.set_state(SessionState::InitialSync);
|
||||||
self.sync();
|
self.sync();
|
||||||
|
@ -512,23 +505,4 @@ impl Session {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_room_encrypted_changes(&self) {
|
|
||||||
let session_weak = glib::SendWeakRef::from(self.downgrade());
|
|
||||||
self.client().add_event_handler(
|
|
||||||
move |_: SyncRoomEncryptionEvent, matrix_room: MatrixRoom| {
|
|
||||||
let session_weak = session_weak.clone();
|
|
||||||
async move {
|
|
||||||
let ctx = glib::MainContext::default();
|
|
||||||
ctx.spawn(async move {
|
|
||||||
if let Some(session) = session_weak.upgrade() {
|
|
||||||
if let Some(room) = session.room_list().get(matrix_room.room_id()) {
|
|
||||||
room.set_is_encrypted(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue