[fractal/fractal-next] Upadte the matrix rust sdk



commit 5177c47c909597ac50ff1f955d24b580591703dc
Author: Julian Sparber <julian sparber net>
Date:   Mon Jan 17 17:26:08 2022 +0100

    Upadte the matrix rust sdk

 Cargo.lock                                         | 41 +++++++++++-----------
 src/secret.rs                                      | 11 +++---
 src/session/avatar.rs                              | 12 +++----
 src/session/content/explore/public_room.rs         | 15 ++++----
 src/session/content/explore/public_room_list.rs    |  8 +++--
 .../content/room_details/invite_subpage/invitee.rs |  4 +--
 .../room_details/invite_subpage/invitee_list.rs    |  4 +--
 src/session/mod.rs                                 |  8 ++---
 src/session/room/event.rs                          | 12 +++----
 src/session/room/item.rs                           |  4 +--
 src/session/room/member.rs                         |  7 ++--
 src/session/room/member_list.rs                    |  6 ++--
 src/session/room/mod.rs                            | 26 ++++++++------
 src/session/room/timeline.rs                       | 29 +++++++--------
 src/session/room_list.rs                           | 36 +++++++++----------
 src/session/user.rs                                |  4 +--
 src/session/verification/verification_list.rs      |  4 +--
 17 files changed, 116 insertions(+), 115 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index e68590ea..fd7abb20 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2208,7 +2208,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
 [[package]]
 name = "matrix-qrcode"
 version = "0.2.0"
-source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a3ac0be5a2bad8d6f0252662695bfa10d2da679b";
+source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a4a50db4f31da7b9116f77c71f318fcc859de8fc";
 dependencies = [
  "base64",
  "byteorder",
@@ -2222,7 +2222,7 @@ dependencies = [
 [[package]]
 name = "matrix-sdk"
 version = "0.4.1"
-source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a3ac0be5a2bad8d6f0252662695bfa10d2da679b";
+source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a4a50db4f31da7b9116f77c71f318fcc859de8fc";
 dependencies = [
  "anymap2",
  "async-stream",
@@ -2251,7 +2251,7 @@ dependencies = [
 [[package]]
 name = "matrix-sdk-base"
 version = "0.4.1"
-source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a3ac0be5a2bad8d6f0252662695bfa10d2da679b";
+source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a4a50db4f31da7b9116f77c71f318fcc859de8fc";
 dependencies = [
  "chacha20poly1305",
  "dashmap",
@@ -2277,7 +2277,7 @@ dependencies = [
 [[package]]
 name = "matrix-sdk-common"
 version = "0.4.1"
-source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a3ac0be5a2bad8d6f0252662695bfa10d2da679b";
+source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a4a50db4f31da7b9116f77c71f318fcc859de8fc";
 dependencies = [
  "async-lock",
  "async-trait",
@@ -2293,7 +2293,7 @@ dependencies = [
 [[package]]
 name = "matrix-sdk-crypto"
 version = "0.4.1"
-source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a3ac0be5a2bad8d6f0252662695bfa10d2da679b";
+source = 
"git+https://github.com/jsparber/matrix-rust-sdk.git?branch=messages-api#a4a50db4f31da7b9116f77c71f318fcc859de8fc";
 dependencies = [
  "aes 0.7.5",
  "aes-gcm",
@@ -3301,7 +3301,7 @@ dependencies = [
 [[package]]
 name = "ruma"
 version = "0.4.0"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "assign",
  "js_int",
@@ -3319,7 +3319,7 @@ dependencies = [
 [[package]]
 name = "ruma-api"
 version = "0.18.5"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "bytes",
  "http",
@@ -3335,7 +3335,7 @@ dependencies = [
 [[package]]
 name = "ruma-api-macros"
 version = "0.18.5"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "proc-macro-crate 1.1.0",
  "proc-macro2 1.0.30",
@@ -3346,7 +3346,7 @@ dependencies = [
 [[package]]
 name = "ruma-client-api"
 version = "0.12.3"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "assign",
  "bytes",
@@ -3366,7 +3366,7 @@ dependencies = [
 [[package]]
 name = "ruma-common"
 version = "0.6.0"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "indexmap",
  "js_int",
@@ -3381,7 +3381,7 @@ dependencies = [
 [[package]]
 name = "ruma-events"
 version = "0.24.6"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "indoc",
  "js_int",
@@ -3398,7 +3398,7 @@ dependencies = [
 [[package]]
 name = "ruma-events-macros"
 version = "0.24.6"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "proc-macro-crate 1.1.0",
  "proc-macro2 1.0.30",
@@ -3409,7 +3409,7 @@ dependencies = [
 [[package]]
 name = "ruma-federation-api"
 version = "0.3.1"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "js_int",
  "ruma-api",
@@ -3424,9 +3424,8 @@ dependencies = [
 [[package]]
 name = "ruma-identifiers"
 version = "0.20.0"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
- "paste",
  "percent-encoding",
  "ruma-identifiers-macros",
  "ruma-identifiers-validation",
@@ -3438,7 +3437,7 @@ dependencies = [
 [[package]]
 name = "ruma-identifiers-macros"
 version = "0.20.0"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "quote 1.0.10",
  "ruma-identifiers-validation",
@@ -3448,7 +3447,7 @@ dependencies = [
 [[package]]
 name = "ruma-identifiers-validation"
 version = "0.5.0"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "thiserror",
 ]
@@ -3456,7 +3455,7 @@ dependencies = [
 [[package]]
 name = "ruma-serde"
 version = "0.5.0"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "bytes",
  "form_urlencoded",
@@ -3470,7 +3469,7 @@ dependencies = [
 [[package]]
 name = "ruma-serde-macros"
 version = "0.5.0"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "proc-macro-crate 1.1.0",
  "proc-macro2 1.0.30",
@@ -3481,7 +3480,7 @@ dependencies = [
 [[package]]
 name = "ruma-signatures"
 version = "0.9.0"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "base64",
  "ed25519-dalek",
@@ -3498,7 +3497,7 @@ dependencies = [
 [[package]]
 name = "ruma-state-res"
 version = "0.4.1"
-source = "git+https://github.com/ruma/ruma?rev=ac6ecc3e5#ac6ecc3e5e28197765f345c4d5a7732b41b057e7";
+source = 
"git+https://github.com/ruma/ruma/?rev=fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d#fdbc4d6d1dd273c8a6ac95b329943ed8c68df70d";
 dependencies = [
  "itertools",
  "js_int",
diff --git a/src/secret.rs b/src/secret.rs
index 117e0d30..a5f9bb38 100644
--- a/src/secret.rs
+++ b/src/secret.rs
@@ -1,10 +1,9 @@
 use gettextrs::gettext;
-use matrix_sdk::ruma::identifiers::{DeviceIdBox, UserId};
+use matrix_sdk::ruma::identifiers::{DeviceId, UserId};
 use secret_service::EncryptionType;
 use secret_service::SecretService;
 use serde::{Deserialize, Serialize};
 use serde_json::error::Error as JsonError;
-use std::convert::TryFrom;
 use std::path::PathBuf;
 use std::string::FromUtf8Error;
 use url::Url;
@@ -14,8 +13,8 @@ use crate::config::APP_ID;
 #[derive(Debug, Clone)]
 pub struct StoredSession {
     pub homeserver: Url,
-    pub user_id: UserId,
-    pub device_id: DeviceIdBox,
+    pub user_id: Box<UserId>,
+    pub device_id: Box<DeviceId>,
     pub path: PathBuf,
     pub secret: Secret,
 }
@@ -73,8 +72,8 @@ pub fn restore_sessions() -> Result<Vec<StoredSession>, secret_service::Error> {
             let attr = item.get_attributes().ok()?;
 
             let homeserver = Url::parse(&attr.get("homeserver")?).ok()?;
-            let user_id = UserId::try_from(attr.get("user")?.to_string()).ok()?;
-            let device_id = DeviceIdBox::try_from(attr.get("device-id")?.to_string()).ok()?;
+            let user_id = UserId::parse(attr.get("user")?.as_str()).ok()?;
+            let device_id = <&DeviceId>::from(attr.get("device-id")?.as_str()).to_owned();
             let path = PathBuf::from(attr.get("db-path")?);
             let secret = Secret::from_utf8(item.get_secret().ok()?).ok()?;
 
diff --git a/src/session/avatar.rs b/src/session/avatar.rs
index 85abd403..f152fe28 100644
--- a/src/session/avatar.rs
+++ b/src/session/avatar.rs
@@ -26,7 +26,7 @@ mod imp {
     pub struct Avatar {
         pub image: RefCell<Option<gdk::Paintable>>,
         pub needed_size: Cell<i32>,
-        pub url: RefCell<Option<MxcUri>>,
+        pub url: RefCell<Option<Box<MxcUri>>>,
         pub display_name: RefCell<Option<String>>,
         pub session: OnceCell<WeakRef<Session>>,
     }
@@ -130,7 +130,7 @@ glib::wrapper! {
 }
 
 impl Avatar {
-    pub fn new(session: &Session, url: Option<MxcUri>) -> Self {
+    pub fn new(session: &Session, url: Option<&MxcUri>) -> Self {
         glib::Object::new(&[
             ("session", session),
             ("url", &url.map(|url| url.to_string())),
@@ -234,7 +234,7 @@ impl Avatar {
         priv_.needed_size.get()
     }
 
-    pub fn set_url(&self, url: Option<MxcUri>) {
+    pub fn set_url(&self, url: Option<Box<MxcUri>>) {
         let priv_ = imp::Avatar::from_instance(self);
 
         if priv_.url.borrow().as_ref() == url.as_ref() {
@@ -253,7 +253,7 @@ impl Avatar {
         self.notify("url");
     }
 
-    pub fn url(&self) -> Option<MxcUri> {
+    pub fn url(&self) -> Option<Box<MxcUri>> {
         let priv_ = imp::Avatar::from_instance(self);
         priv_.url.borrow().to_owned()
     }
@@ -266,7 +266,7 @@ pub async fn update_room_avatar_from_file<P>(
     matrix_client: &Client,
     matrix_room: &MatrixRoom,
     filename: Option<&P>,
-) -> Result<Option<MxcUri>, AvatarError>
+) -> Result<Option<Box<MxcUri>>, AvatarError>
 where
     P: AsRef<Path> + std::fmt::Debug,
 {
@@ -292,7 +292,7 @@ where
 }
 
 /// Returns the URI of the room avatar after uploading it.
-async fn upload_avatar<P>(matrix_client: &Client, filename: &P) -> Result<MxcUri, AvatarError>
+async fn upload_avatar<P>(matrix_client: &Client, filename: &P) -> Result<Box<MxcUri>, AvatarError>
 where
     P: AsRef<Path> + std::fmt::Debug,
 {
diff --git a/src/session/content/explore/public_room.rs b/src/session/content/explore/public_room.rs
index 2de298bb..e49ad226 100644
--- a/src/session/content/explore/public_room.rs
+++ b/src/session/content/explore/public_room.rs
@@ -1,5 +1,8 @@
 use gtk::{glib, glib::clone, prelude::*, subclass::prelude::*};
-use matrix_sdk::ruma::directory::PublicRoomsChunk;
+use matrix_sdk::ruma::{
+    directory::PublicRoomsChunk,
+    identifiers::{RoomId, RoomOrAliasId},
+};
 
 use crate::session::{room::Room, Avatar, RoomList};
 
@@ -102,7 +105,7 @@ mod imp {
                     if let Some(matrix_public_room) = obj.matrix_public_room() {
                         obj.set_pending(obj.room_list().session()
                         .room_list()
-                        .is_pending_room(&matrix_public_room.room_id.clone().into()));
+                        .is_pending_room((&*matrix_public_room.room_id).into()));
                     }
                 }));
         }
@@ -188,10 +191,7 @@ impl PublicRoom {
             priv_.room_handler.replace(Some(handler_id));
         }
 
-        self.set_pending(
-            self.room_list()
-                .is_pending_room(&room.room_id.clone().into()),
-        );
+        self.set_pending(self.room_list().is_pending_room((&*room.room_id).into()));
 
         priv_.matrix_public_room.set(room).unwrap();
     }
@@ -205,8 +205,9 @@ impl PublicRoom {
         if let Some(room) = self.room() {
             self.room_list().session().select_room(Some(room.clone()));
         } else if let Some(matrix_public_room) = self.matrix_public_room() {
+            let room_id: &RoomId = matrix_public_room.room_id.as_ref();
             self.room_list()
-                .join_by_id_or_alias(matrix_public_room.room_id.clone().into());
+                .join_by_id_or_alias(<&RoomOrAliasId>::from(room_id).to_owned());
         }
     }
 }
diff --git a/src/session/content/explore/public_room_list.rs b/src/session/content/explore/public_room_list.rs
index f144e224..b00c7817 100644
--- a/src/session/content/explore/public_room_list.rs
+++ b/src/session/content/explore/public_room_list.rs
@@ -11,7 +11,7 @@ use matrix_sdk::ruma::{
     },
     assign,
     directory::{Filter, RoomNetwork},
-    identifiers::ServerNameBox,
+    identifiers::ServerName,
     uint,
 };
 use std::convert::TryFrom;
@@ -304,13 +304,15 @@ impl PublicRoomList {
                 Some(custom) => RoomNetwork::ThirdParty(custom),
                 _ => RoomNetwork::default(),
             };
-            let server = server.and_then(|server| ServerNameBox::try_from(server).ok());
+            let server = server
+                .as_deref()
+                .and_then(|server| <&ServerName>::try_from(server).ok());
 
             let request = assign!(PublicRoomsRequest::new(), {
               limit: Some(uint!(20)),
               since: next_batch.as_deref(),
               room_network,
-              server: server.as_deref(),
+              server,
               filter: assign!(Filter::new(), { generic_search_term: search_term.as_deref() }),
             });
             client.public_rooms_filtered(request).await
diff --git a/src/session/content/room_details/invite_subpage/invitee.rs 
b/src/session/content/room_details/invite_subpage/invitee.rs
index 16928116..fb9ea8a6 100644
--- a/src/session/content/room_details/invite_subpage/invitee.rs
+++ b/src/session/content/room_details/invite_subpage/invitee.rs
@@ -82,7 +82,7 @@ impl Invitee {
         session: &Session,
         user_id: &UserId,
         display_name: Option<&str>,
-        avatar_url: Option<MxcUri>,
+        avatar_url: Option<&MxcUri>,
     ) -> Self {
         let obj: Self = glib::Object::new(&[
             ("session", session),
@@ -91,7 +91,7 @@ impl Invitee {
         ])
         .expect("Failed to create Invitee");
         // FIXME: we should make the avatar_url settable as property
-        obj.set_avatar_url(avatar_url);
+        obj.set_avatar_url(avatar_url.map(std::borrow::ToOwned::to_owned));
         obj
     }
 
diff --git a/src/session/content/room_details/invite_subpage/invitee_list.rs 
b/src/session/content/room_details/invite_subpage/invitee_list.rs
index d88713ec..ccc31e5b 100644
--- a/src/session/content/room_details/invite_subpage/invitee_list.rs
+++ b/src/session/content/room_details/invite_subpage/invitee_list.rs
@@ -40,7 +40,7 @@ mod imp {
         pub room: OnceCell<Room>,
         pub state: Cell<InviteeListState>,
         pub search_term: RefCell<Option<String>>,
-        pub invitee_list: RefCell<HashMap<UserId, Invitee>>,
+        pub invitee_list: RefCell<HashMap<Box<UserId>, Invitee>>,
         pub abort_handle: RefCell<Option<AbortHandle>>,
     }
 
@@ -256,7 +256,7 @@ impl InviteeList {
                                 &session,
                                 &item.user_id,
                                 item.display_name.as_deref(),
-                                item.avatar_url,
+                                item.avatar_url.as_deref(),
                             );
 
                             user.connect_notify_local(
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 54c22e58..1304430e 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -111,7 +111,7 @@ mod imp {
                 Some("s"),
                 move |session, _, parameter| {
                     if let Ok(room_id) =
-                        RoomId::try_from(parameter.unwrap().get::<String>().unwrap())
+                        <&RoomId>::try_from(&*parameter.unwrap().get::<String>().unwrap())
                     {
                         session.select_room_by_id(room_id);
                     } else {
@@ -275,8 +275,8 @@ impl Session {
         priv_.sidebar.set_selected_item(item);
     }
 
-    pub fn select_room_by_id(&self, room_id: RoomId) {
-        if let Some(room) = self.room_list().get(&room_id) {
+    pub fn select_room_by_id(&self, room_id: &RoomId) {
+        if let Some(room) = self.room_list().get(room_id) {
             self.select_room(Some(room));
         } else {
             warn!("A room with id {} couldn't be found", room_id);
@@ -397,7 +397,7 @@ impl Session {
                     match handle.await.unwrap() {
                         Ok((display_name, avatar_url)) => {
                             user.set_display_name(display_name);
-                            user.set_avatar_url(avatar_url);
+                            user.set_avatar_url(avatar_url)
                         }
                         Err(error) => error!("Couldn’t fetch account metadata: {}", error),
                     }
diff --git a/src/session/room/event.rs b/src/session/room/event.rs
index 784a3bc0..df466648 100644
--- a/src/session/room/event.rs
+++ b/src/session/room/event.rs
@@ -210,7 +210,7 @@ impl Event {
         self.notify("can-view-media");
     }
 
-    pub fn matrix_sender(&self) -> UserId {
+    pub fn matrix_sender(&self) -> Box<UserId> {
         let priv_ = imp::Event::from_instance(self);
 
         if let Some(event) = priv_.event.borrow().as_ref() {
@@ -222,13 +222,13 @@ impl Event {
                 .as_ref()
                 .unwrap()
                 .event
-                .get_field::<UserId>("sender")
+                .get_field::<Box<UserId>>("sender")
                 .unwrap()
                 .unwrap()
         }
     }
 
-    pub fn matrix_event_id(&self) -> EventId {
+    pub fn matrix_event_id(&self) -> Box<EventId> {
         let priv_ = imp::Event::from_instance(self);
 
         if let Some(event) = priv_.event.borrow().as_ref() {
@@ -240,7 +240,7 @@ impl Event {
                 .as_ref()
                 .unwrap()
                 .event
-                .get_field::<EventId>("event_id")
+                .get_field::<Box<EventId>>("event_id")
                 .unwrap()
                 .unwrap()
         }
@@ -329,7 +329,7 @@ impl Event {
     }
 
     /// Find the related event if any
-    pub fn related_matrix_event(&self) -> Option<EventId> {
+    pub fn related_matrix_event(&self) -> Option<Box<EventId>> {
         let priv_ = imp::Event::from_instance(self);
 
         match priv_.event.borrow().as_ref()? {
@@ -709,7 +709,7 @@ impl Event {
     }
 
     /// Get the id of the event this `Event` replies to, if any.
-    pub fn reply_to_id(&self) -> Option<EventId> {
+    pub fn reply_to_id(&self) -> Option<Box<EventId>> {
         match self.original_content()? {
             AnyMessageEventContent::RoomMessage(message) => {
                 if let Some(Relation::Reply { in_reply_to }) = message.relates_to {
diff --git a/src/session/room/item.rs b/src/session/room/item.rs
index ccb32b4e..9359c715 100644
--- a/src/session/room/item.rs
+++ b/src/session/room/item.rs
@@ -182,7 +182,7 @@ impl Item {
         }
     }
 
-    pub fn matrix_sender(&self) -> Option<UserId> {
+    pub fn matrix_sender(&self) -> Option<Box<UserId>> {
         let priv_ = imp::Item::from_instance(self);
         if let ItemType::Event(event) = priv_.type_.get().unwrap() {
             Some(event.matrix_sender())
@@ -191,7 +191,7 @@ impl Item {
         }
     }
 
-    pub fn matrix_event_id(&self) -> Option<EventId> {
+    pub fn matrix_event_id(&self) -> Option<Box<EventId>> {
         let priv_ = imp::Item::from_instance(self);
 
         if let ItemType::Event(event) = priv_.type_.get().unwrap() {
diff --git a/src/session/room/member.rs b/src/session/room/member.rs
index e63cca8b..dfc3f73a 100644
--- a/src/session/room/member.rs
+++ b/src/session/room/member.rs
@@ -104,7 +104,8 @@ impl Member {
         };
 
         self.set_display_name(member.display_name().map(String::from));
-        self.avatar().set_url(member.avatar_url().cloned());
+        self.avatar()
+            .set_url(member.avatar_url().map(std::borrow::ToOwned::to_owned));
         self.set_power_level(member.power_level());
     }
 
@@ -124,8 +125,8 @@ pub trait MemberEvent {
     fn sender(&self) -> &UserId;
     fn content(&self) -> &RoomMemberEventContent;
 
-    fn avatar_url(&self) -> Option<MxcUri> {
-        self.content().avatar_url.clone()
+    fn avatar_url(&self) -> Option<Box<MxcUri>> {
+        self.content().avatar_url.to_owned()
     }
 
     fn display_name(&self) -> Option<String> {
diff --git a/src/session/room/member_list.rs b/src/session/room/member_list.rs
index a3e9895b..5158eb1a 100644
--- a/src/session/room/member_list.rs
+++ b/src/session/room/member_list.rs
@@ -13,7 +13,7 @@ mod imp {
 
     #[derive(Debug, Default)]
     pub struct MemberList {
-        pub members: RefCell<IndexMap<UserId, Member>>,
+        pub members: RefCell<IndexMap<Box<UserId>, Member>>,
         pub room: OnceCell<WeakRef<Room>>,
     }
 
@@ -108,7 +108,7 @@ impl MemberList {
         let prev_len = members.len();
         for member in new_members {
             members
-                .entry(member.user_id().clone())
+                .entry(member.user_id().to_owned())
                 .or_insert_with(|| Member::new(&self.room(), member.user_id()))
                 .update_from_room_member(&member);
         }
@@ -131,7 +131,7 @@ impl MemberList {
         let mut was_member_added = false;
         let prev_len = members.len();
         let member = members
-            .entry(user_id.clone())
+            .entry(user_id.to_owned())
             .or_insert_with(|| {
                 was_member_added = true;
                 Member::new(&self.room(), user_id)
diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs
index 87532a00..3dd37614 100644
--- a/src/session/room/mod.rs
+++ b/src/session/room/mod.rs
@@ -49,7 +49,7 @@ use matrix_sdk::{
 };
 use serde_json::value::RawValue;
 use std::cell::RefCell;
-use std::convert::{TryFrom, TryInto};
+use std::convert::TryInto;
 use std::path::PathBuf;
 
 use crate::components::{LabelWithWidgets, Pill};
@@ -69,7 +69,7 @@ mod imp {
 
     #[derive(Debug, Default)]
     pub struct Room {
-        pub room_id: OnceCell<RoomId>,
+        pub room_id: OnceCell<Box<RoomId>>,
         pub matrix_room: RefCell<Option<MatrixRoom>>,
         pub session: OnceCell<WeakRef<Session>>,
         pub name: RefCell<Option<String>>,
@@ -82,8 +82,8 @@ mod imp {
         pub members_loaded: Cell<bool>,
         pub power_levels: RefCell<PowerLevels>,
         pub latest_change: RefCell<Option<glib::DateTime>>,
-        pub predecessor: OnceCell<RoomId>,
-        pub successor: OnceCell<RoomId>,
+        pub predecessor: OnceCell<Box<RoomId>>,
+        pub successor: OnceCell<Box<RoomId>>,
     }
 
     #[glib::object_subclass]
@@ -227,7 +227,7 @@ mod imp {
                 }
                 "room-id" => self
                     .room_id
-                    .set(RoomId::try_from(value.get::<&str>().unwrap()).unwrap())
+                    .set(RoomId::parse(value.get::<&str>().unwrap()).unwrap())
                     .unwrap(),
                 "topic" => {
                     let topic = value.get().unwrap();
@@ -295,7 +295,10 @@ mod imp {
             self.timeline.set(Timeline::new(obj)).unwrap();
             self.members.set(MemberList::new(obj)).unwrap();
             self.avatar
-                .set(Avatar::new(&obj.session(), obj.matrix_room().avatar_url()))
+                .set(Avatar::new(
+                    &obj.session(),
+                    obj.matrix_room().avatar_url().as_deref(),
+                ))
                 .unwrap();
 
             obj.load_power_levels();
@@ -847,8 +850,8 @@ impl Room {
         let txn_id = Uuid::new_v4();
         let event = AnySyncMessageEvent::RoomMessage(SyncMessageEvent {
             content: content.clone(),
-            event_id: EventId::try_from(format!("${}:fractal.gnome.org", txn_id)).unwrap(),
-            sender: self.session().user().unwrap().user_id().clone(),
+            event_id: EventId::parse(format!("${}:fractal.gnome.org", txn_id).as_str()).unwrap(),
+            sender: self.session().user().unwrap().user_id().to_owned(),
             origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
             unsigned: Unsigned::default(),
         });
@@ -1031,7 +1034,7 @@ impl Room {
 
     pub fn predecessor(&self) -> Option<&RoomId> {
         let priv_ = imp::Room::from_instance(self);
-        priv_.predecessor.get()
+        priv_.predecessor.get().map(std::ops::Deref::deref)
     }
 
     fn load_predecessor(&self) -> Option<()> {
@@ -1051,7 +1054,7 @@ impl Room {
 
     pub fn successor(&self) -> Option<&RoomId> {
         let priv_ = imp::Room::from_instance(self);
-        priv_.successor.get()
+        priv_.successor.get().map(std::ops::Deref::deref)
     }
 
     pub fn load_successor(&self) -> Option<()> {
@@ -1072,7 +1075,8 @@ impl Room {
 
     pub async fn invite(&self, users: &[User]) {
         let matrix_room = self.matrix_room();
-        let user_ids: Vec<UserId> = users.iter().map(|user| user.user_id().to_owned()).collect();
+        let user_ids: Vec<Box<UserId>> =
+            users.iter().map(|user| user.user_id().to_owned()).collect();
 
         if let MatrixRoom::Joined(matrix_room) = matrix_room {
             let handle = spawn_tokio!(async move {
diff --git a/src/session/room/timeline.rs b/src/session/room/timeline.rs
index eb46d04c..67ffada1 100644
--- a/src/session/room/timeline.rs
+++ b/src/session/room/timeline.rs
@@ -4,9 +4,7 @@ use gtk::{gio, glib, glib::clone, prelude::*, subclass::prelude::*};
 use log::{error, warn};
 use matrix_sdk::{
     ruma::{
-        api::client::r0::{
-            message::get_message_events::Direction, room::get_room_event::Request as EventRequest,
-        },
+        api::client::r0::message::get_message_events::Direction,
         events::{
             room::message::MessageType, AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
         },
@@ -34,16 +32,16 @@ mod imp {
     pub struct Timeline {
         pub room: OnceCell<WeakRef<Room>>,
         /// A store to keep track of related events that aren't known
-        pub relates_to_events: RefCell<HashMap<EventId, Vec<EventId>>>,
+        pub relates_to_events: RefCell<HashMap<Box<EventId>, Vec<Box<EventId>>>>,
         /// All events shown in the room history
         pub list: RefCell<VecDeque<Item>>,
         /// A Hashmap linking `EventId` to corresponding `Event`
-        pub event_map: RefCell<HashMap<EventId, Event>>,
+        pub event_map: RefCell<HashMap<Box<EventId>, Event>>,
         /// Maps the temporary `EventId` of the pending Event to the real `EventId`
-        pub pending_events: RefCell<HashMap<String, EventId>>,
+        pub pending_events: RefCell<HashMap<String, Box<EventId>>>,
         pub loading: Cell<bool>,
         pub complete: Cell<bool>,
-        pub oldest_event: RefCell<Option<EventId>>,
+        pub oldest_event: RefCell<Option<Box<EventId>>>,
         /// The most recent verification reuqest event
         pub verification: RefCell<Option<IdentityVerification>>,
     }
@@ -313,7 +311,7 @@ impl Timeline {
         let mut relates_to_events = priv_.relates_to_events.borrow_mut();
 
         // Group events by related event
-        let mut new_relations: HashMap<EventId, Vec<Event>> = HashMap::new();
+        let mut new_relations: HashMap<Box<EventId>, Vec<Event>> = HashMap::new();
         for event in events {
             if let Some(relates_to) = relates_to_events.remove(&event.matrix_event_id()) {
                 let replacing_events = relates_to
@@ -373,7 +371,7 @@ impl Timeline {
                 // Store the new event if the `related_to` event isn't known, we will update the 
`relates_to` once
                 // the `related_to` event is added to the list
                 let relates_to_event = relates_to_events.entry(relates_to_event_id).or_default();
-                let replacing_events_ids: Vec<EventId> = relations
+                let replacing_events_ids: Vec<Box<EventId>> = relations
                     .iter()
                     .filter(|event| event.is_replacing_event())
                     .map(|event| event.matrix_event_id())
@@ -507,12 +505,9 @@ impl Timeline {
         } else {
             let room = self.room();
             let matrix_room = room.matrix_room();
-            let event_id_clone = event_id.clone();
-            let handle = spawn_tokio!(async move {
-                matrix_room
-                    .event(EventRequest::new(matrix_room.room_id(), &event_id_clone))
-                    .await
-            });
+            let event_id_clone = event_id.to_owned();
+            let handle =
+                spawn_tokio!(async move { matrix_room.event(event_id_clone.as_ref()).await });
             match handle.await.unwrap() {
                 Ok(room_event) => Ok(Event::new(room_event.event.into(), &room)),
                 Err(error) => {
@@ -609,7 +604,7 @@ impl Timeline {
         priv_.list.borrow().is_empty() || (priv_.list.borrow().len() == 1 && self.loading())
     }
 
-    fn oldest_event(&self) -> Option<EventId> {
+    fn oldest_event(&self) -> Option<Box<EventId>> {
         let priv_ = imp::Timeline::from_instance(self);
         priv_.oldest_event.borrow().clone()
     }
@@ -642,7 +637,7 @@ impl Timeline {
 
         let handle = spawn_tokio!(async move {
             matrix_room
-                .messages(last_event.as_ref(), None, 20, Direction::Backward)
+                .messages(last_event.as_deref(), None, 20, Direction::Backward)
                 .await
         });
 
diff --git a/src/session/room_list.rs b/src/session/room_list.rs
index 573de2df..934989d6 100644
--- a/src/session/room_list.rs
+++ b/src/session/room_list.rs
@@ -2,7 +2,7 @@ use gtk::{gio, glib, glib::clone, prelude::*, subclass::prelude::*};
 use indexmap::map::IndexMap;
 use matrix_sdk::{
     deserialized_responses::Rooms as ResponseRooms,
-    ruma::identifiers::{RoomId, RoomIdOrAliasId},
+    ruma::identifiers::{RoomId, RoomOrAliasId},
 };
 
 use crate::{
@@ -24,8 +24,8 @@ mod imp {
 
     #[derive(Debug, Default)]
     pub struct RoomList {
-        pub list: RefCell<IndexMap<RoomId, Room>>,
-        pub pending_rooms: RefCell<HashSet<RoomIdOrAliasId>>,
+        pub list: RefCell<IndexMap<Box<RoomId>, Room>>,
+        pub pending_rooms: RefCell<HashSet<Box<RoomOrAliasId>>>,
         pub session: OnceCell<WeakRef<Session>>,
     }
 
@@ -127,30 +127,30 @@ impl RoomList {
         priv_.session.get().unwrap().upgrade().unwrap()
     }
 
-    pub fn is_pending_room(&self, identifier: &RoomIdOrAliasId) -> bool {
+    pub fn is_pending_room(&self, identifier: &RoomOrAliasId) -> bool {
         let priv_ = imp::RoomList::from_instance(self);
         priv_.pending_rooms.borrow().contains(identifier)
     }
 
-    fn pending_rooms_remove(&self, identifier: &RoomIdOrAliasId) {
+    fn pending_rooms_remove(&self, identifier: &RoomOrAliasId) {
         let priv_ = imp::RoomList::from_instance(self);
         priv_.pending_rooms.borrow_mut().remove(identifier);
         self.emit_by_name("pending-rooms-changed", &[]).unwrap();
     }
 
-    fn pending_rooms_insert(&self, identifier: RoomIdOrAliasId) {
+    fn pending_rooms_insert(&self, identifier: Box<RoomOrAliasId>) {
         let priv_ = imp::RoomList::from_instance(self);
         priv_.pending_rooms.borrow_mut().insert(identifier);
         self.emit_by_name("pending-rooms-changed", &[]).unwrap();
     }
 
-    fn pending_rooms_replace_or_remove(&self, identifier: &RoomIdOrAliasId, room_id: RoomId) {
+    fn pending_rooms_replace_or_remove(&self, identifier: &RoomOrAliasId, room_id: &RoomId) {
         let priv_ = imp::RoomList::from_instance(self);
         {
             let mut pending_rooms = priv_.pending_rooms.borrow_mut();
             pending_rooms.remove(identifier);
-            if !self.contains_key(&room_id) {
-                pending_rooms.insert(room_id.into());
+            if !self.contains_key(room_id) {
+                pending_rooms.insert(room_id.to_owned().into());
             }
         }
         self.emit_by_name("pending-rooms-changed", &[]).unwrap();
@@ -162,9 +162,9 @@ impl RoomList {
     }
 
     /// Waits till the Room becomes available
-    pub async fn get_wait(&self, room_id: RoomId) -> Option<Room> {
+    pub async fn get_wait(&self, room_id: Box<RoomId>) -> Option<Room> {
         let priv_ = imp::RoomList::from_instance(self);
-        if let Some(room) = priv_.list.borrow().get(&room_id) {
+        if let Some(room) = priv_.list.borrow().get(&*room_id) {
             Some(room.clone())
         } else {
             let (sender, receiver) = futures::channel::oneshot::channel();
@@ -172,7 +172,7 @@ impl RoomList {
             let sender = Cell::new(Some(sender));
             // FIXME: add a timeout
             let handler_id = self.connect_items_changed(move |obj, _, _, _| {
-                if let Some(room) = obj.get(&room_id) {
+                if let Some(room) = obj.get(&*room_id) {
                     if let Some(sender) = sender.take() {
                         sender.send(Some(room)).unwrap();
                     }
@@ -185,7 +185,7 @@ impl RoomList {
         }
     }
 
-    fn get_full(&self, room_id: &RoomId) -> Option<(usize, RoomId, Room)> {
+    fn get_full(&self, room_id: &RoomId) -> Option<(usize, Box<RoomId>, Room)> {
         let priv_ = imp::RoomList::from_instance(self);
         priv_
             .list
@@ -273,7 +273,7 @@ impl RoomList {
                 })
                 .clone();
 
-            self.pending_rooms_remove(&room_id.into());
+            self.pending_rooms_remove((&*room_id).into());
             room.handle_left_response(left_room);
         }
 
@@ -288,7 +288,7 @@ impl RoomList {
                 })
                 .clone();
 
-            self.pending_rooms_remove(&room_id.into());
+            self.pending_rooms_remove((&*room_id).into());
             room.handle_joined_response(joined_room);
         }
 
@@ -303,7 +303,7 @@ impl RoomList {
                 })
                 .clone();
 
-            self.pending_rooms_remove(&room_id.into());
+            self.pending_rooms_remove((&*room_id).into());
             room.handle_invited_response(invited_room);
         }
 
@@ -312,7 +312,7 @@ impl RoomList {
         }
     }
 
-    pub fn join_by_id_or_alias(&self, identifier: RoomIdOrAliasId) {
+    pub fn join_by_id_or_alias(&self, identifier: Box<RoomOrAliasId>) {
         let client = self.session().client();
         let identifier_clone = identifier.clone();
 
@@ -328,7 +328,7 @@ impl RoomList {
             glib::PRIORITY_DEFAULT_IDLE,
             clone!(@weak self as obj => async move {
                 match handle.await.unwrap() {
-                    Ok(response) => obj.pending_rooms_replace_or_remove(&identifier, response.room_id),
+                    Ok(response) => obj.pending_rooms_replace_or_remove(&identifier, 
response.room_id.as_ref()),
                     Err(error) => {
                         obj.pending_rooms_remove(&identifier);
                         error!("Joining room {} failed: {}", identifier, error);
diff --git a/src/session/user.rs b/src/session/user.rs
index 28c72119..94aaae0a 100644
--- a/src/session/user.rs
+++ b/src/session/user.rs
@@ -15,7 +15,7 @@ mod imp {
 
     #[derive(Debug, Default)]
     pub struct User {
-        pub user_id: OnceCell<UserId>,
+        pub user_id: OnceCell<Box<UserId>>,
         pub display_name: RefCell<Option<String>>,
         pub session: OnceCell<WeakRef<Session>>,
         pub avatar: OnceCell<Avatar>,
@@ -174,7 +174,7 @@ pub trait UserExt: IsA<User> {
         priv_.avatar.get().unwrap()
     }
 
-    fn set_avatar_url(&self, url: Option<MxcUri>) {
+    fn set_avatar_url(&self, url: Option<Box<MxcUri>>) {
         self.avatar().set_url(url);
     }
 }
diff --git a/src/session/verification/verification_list.rs b/src/session/verification/verification_list.rs
index 14e39905..ce07d0a7 100644
--- a/src/session/verification/verification_list.rs
+++ b/src/session/verification/verification_list.rs
@@ -11,12 +11,12 @@ use matrix_sdk::ruma::{
 
 #[derive(Hash, PartialEq, Eq, Debug)]
 pub struct FlowId {
-    user_id: UserId,
+    user_id: Box<UserId>,
     flow_id: String,
 }
 
 impl FlowId {
-    pub fn new(user_id: UserId, flow_id: String) -> Self {
+    pub fn new(user_id: Box<UserId>, flow_id: String) -> Self {
         Self { user_id, flow_id }
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]