Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Ruma #433

Merged
merged 4 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/matrix-qrcode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ byteorder = "1.4.3"
image = { version = "0.23.14", optional = true }
qrcode = { version = "0.12.0", default-features = false }
rqrr = { version = "0.4.0", optional = true }
ruma-identifiers = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5" }
ruma-identifiers = { git = "https://github.com/ruma/ruma", rev = "6c4892664" }
thiserror = "1.0.25"
8 changes: 4 additions & 4 deletions crates/matrix-qrcode/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use std::{
convert::TryFrom,
convert::{TryFrom, TryInto},
io::{Cursor, Read},
};

Expand Down Expand Up @@ -316,7 +316,7 @@ impl QrVerificationData {

match mode {
VerificationData::QR_MODE => {
let event_id = EventId::try_from(flow_id)?;
let event_id = flow_id.try_into()?;
Ok(VerificationData::new(event_id, first_key, second_key, shared_secret).into())
}
SelfVerificationData::QR_MODE => {
Expand Down Expand Up @@ -375,7 +375,7 @@ impl QrVerificationData {
/// cross signing keys.
#[derive(Clone, Debug, PartialEq)]
pub struct VerificationData {
event_id: EventId,
event_id: Box<EventId>,
first_master_key: String,
second_master_key: String,
shared_secret: String,
Expand All @@ -398,7 +398,7 @@ impl VerificationData {
/// * ` shared_secret` - A random bytestring encoded as unpadded base64,
/// needs to be at least 8 bytes long.
pub fn new(
event_id: EventId,
event_id: Box<EventId>,
first_key: String,
second_key: String,
shared_secret: String,
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-appservice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ warp = { version = "0.3.1", optional = true, default-features = false }

[dependencies.ruma]
git = "https://github.com/ruma/ruma"
rev = "ac6ecc3e5"
rev = "6c4892664"
features = ["client-api-c", "appservice-api-s", "unstable-pre-spec"]

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn handle_room_member(
if !appservice.user_id_is_in_namespace(&event.state_key)? {
trace!("not an appservice user: {}", event.state_key);
} else if let MembershipState::Invite = event.content.membership {
let user_id = UserId::try_from(event.state_key.as_str())?;
let user_id = Box::<UserId>::try_from(event.state_key.as_str())?;
appservice.register_virtual_user(user_id.localpart()).await?;

let client = appservice.virtual_user_client(user_id.localpart()).await?;
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-appservice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ use ruma::{
},
client::r0::account::register,
},
assign, identifiers, DeviceId, ServerNameBox, UserId,
assign, identifiers, DeviceId, ServerName, UserId,
};
use serde::de::DeserializeOwned;
use tracing::info;
Expand Down Expand Up @@ -203,7 +203,7 @@ pub type VirtualUser = ();
#[derive(Debug, Clone)]
pub struct AppService {
homeserver_url: Url,
server_name: ServerNameBox,
server_name: Box<ServerName>,
registration: Arc<AppServiceRegistration>,
clients: Arc<DashMap<Localpart, Client>>,
event_handler: event_handler::EventHandler,
Expand All @@ -227,7 +227,7 @@ impl AppService {
/// [AppService Registration]: https://matrix.org/docs/spec/application_service/r0.1.2#registration
pub async fn new(
homeserver_url: impl TryInto<Url, Error = url::ParseError>,
server_name: impl TryInto<ServerNameBox, Error = identifiers::Error>,
server_name: impl TryInto<Box<ServerName>, Error = identifiers::Error>,
registration: AppServiceRegistration,
) -> Result<Self> {
let appservice = Self::new_with_config(
Expand All @@ -245,7 +245,7 @@ impl AppService {
/// [`Client`]
pub async fn new_with_config(
homeserver_url: impl TryInto<Url, Error = url::ParseError>,
server_name: impl TryInto<ServerNameBox, Error = identifiers::Error>,
server_name: impl TryInto<Box<ServerName>, Error = identifiers::Error>,
registration: AppServiceRegistration,
client_config: ClientConfig,
) -> Result<Self> {
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-appservice/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ async fn test_appservice_on_sub_path() -> Result<()> {

let members = appservice
.get_cached_client(None)?
.get_room(&room_id)
.get_room(room_id)
.expect("Expected room to be available")
.members_no_sync()
.await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" }
matrix-sdk-crypto = { version = "0.4.0", path = "../matrix-sdk-crypto", optional = true }
pbkdf2 = { version = "0.9.0", default-features = false, optional = true }
rand = { version = "0.8.4", optional = true }
ruma = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5", features = ["client-api-c", "unstable-pre-spec"] }
ruma = { git = "https://github.com/ruma/ruma", rev = "6c4892664", features = ["client-api-c", "unstable-pre-spec"] }
serde = { version = "1.0.126", features = ["rc"] }
serde_json = "1.0.64"
sha2 = { version = "0.9.5", optional = true }
Expand Down
36 changes: 22 additions & 14 deletions crates/matrix-sdk-base/examples/state_inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,27 @@ impl Inspector {
match matches.subcommand() {
("get-profiles", args) => {
let args = args.expect("No args provided for get-state");
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();

self.get_profiles(room_id).await;
}

("get-members", args) => {
let args = args.expect("No args provided for get-state");
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();

self.get_members(room_id).await;
}
("list-rooms", _) => self.list_rooms().await,
("get-display-names", args) => {
let args = args.expect("No args provided for get-state");
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
let display_name = args.value_of("display-name").unwrap().to_string();
self.get_display_name_owners(room_id, display_name).await;
}
("get-state", args) => {
let args = args.expect("No args provided for get-state");
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
let event_type = EventType::try_from(args.value_of("event-type").unwrap()).unwrap();
self.get_state(room_id, event_type).await;
}
Expand All @@ -256,30 +256,30 @@ impl Inspector {
self.printer.pretty_print_struct(&rooms);
}

async fn get_display_name_owners(&self, room_id: RoomId, display_name: String) {
async fn get_display_name_owners(&self, room_id: Box<RoomId>, display_name: String) {
let users = self.store.get_users_with_display_name(&room_id, &display_name).await.unwrap();
self.printer.pretty_print_struct(&users);
}

async fn get_profiles(&self, room_id: RoomId) {
let joined: Vec<UserId> = self.store.get_joined_user_ids(&room_id).await.unwrap();
async fn get_profiles(&self, room_id: Box<RoomId>) {
let joined: Vec<Box<UserId>> = self.store.get_joined_user_ids(&room_id).await.unwrap();

for member in joined {
let event = self.store.get_profile(&room_id, &member).await.unwrap();
self.printer.pretty_print_struct(&event);
}
}

async fn get_members(&self, room_id: RoomId) {
let joined: Vec<UserId> = self.store.get_joined_user_ids(&room_id).await.unwrap();
async fn get_members(&self, room_id: Box<RoomId>) {
let joined: Vec<Box<UserId>> = self.store.get_joined_user_ids(&room_id).await.unwrap();

for member in joined {
let event = self.store.get_member_event(&room_id, &member).await.unwrap();
self.printer.pretty_print_struct(&event);
}
}

async fn get_state(&self, room_id: RoomId, event_type: EventType) {
async fn get_state(&self, room_id: Box<RoomId>, event_type: EventType) {
self.printer.pretty_print_struct(
&self.store.get_state_event(&room_id, event_type, "").await.unwrap(),
);
Expand All @@ -290,22 +290,30 @@ impl Inspector {
SubCommand::with_name("list-rooms"),
SubCommand::with_name("get-members").arg(
Arg::with_name("room-id").required(true).validator(|r| {
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
Box::<RoomId>::try_from(r)
.map(|_| ())
.map_err(|_| "Invalid room id given".to_owned())
}),
),
SubCommand::with_name("get-profiles").arg(
Arg::with_name("room-id").required(true).validator(|r| {
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
Box::<RoomId>::try_from(r)
.map(|_| ())
.map_err(|_| "Invalid room id given".to_owned())
}),
),
SubCommand::with_name("get-display-names")
.arg(Arg::with_name("room-id").required(true).validator(|r| {
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
Box::<RoomId>::try_from(r)
.map(|_| ())
.map_err(|_| "Invalid room id given".to_owned())
}))
.arg(Arg::with_name("display-name").required(true)),
SubCommand::with_name("get-state")
.arg(Arg::with_name("room-id").required(true).validator(|r| {
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
Box::<RoomId>::try_from(r)
.map(|_| ())
.map_err(|_| "Invalid room id given".to_owned())
}))
.arg(Arg::with_name("event-type").required(true).validator(|e| {
EventType::try_from(e).map(|_| ()).map_err(|_| "Invalid event type".to_string())
Expand Down
48 changes: 26 additions & 22 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(feature = "encryption")]
use std::ops::Deref;
use std::{
collections::{BTreeMap, BTreeSet},
convert::TryFrom,
Expand Down Expand Up @@ -352,7 +354,7 @@ impl BaseClient {
room_info: &mut RoomInfo,
changes: &mut StateChanges,
ambiguity_cache: &mut AmbiguityCache,
user_ids: &mut BTreeSet<UserId>,
user_ids: &mut BTreeSet<Box<UserId>>,
) -> Result<Timeline> {
let room_id = room.room_id();
let user_id = room.own_user_id();
Expand Down Expand Up @@ -388,14 +390,14 @@ impl BaseClient {
if member.state_key == member.sender {
changes
.profiles
.entry(room_id.clone())
.entry(room_id.to_owned())
.or_insert_with(BTreeMap::new)
.insert(member.sender.clone(), member.content.clone());
}

changes
.members
.entry(room_id.clone())
.entry(room_id.to_owned())
.or_insert_with(BTreeMap::new)
.insert(member.state_key.clone(), member);
}
Expand Down Expand Up @@ -443,7 +445,7 @@ impl BaseClient {
actions,
event.event.clone(),
false,
room_id.clone(),
room_id.to_owned(),
MilliSecondsSinceUnixEpoch::now(),
),
);
Expand Down Expand Up @@ -475,7 +477,7 @@ impl BaseClient {
events: &[Raw<AnyStrippedStateEvent>],
room_info: &mut RoomInfo,
) -> (
BTreeMap<UserId, StrippedMemberEvent>,
BTreeMap<Box<UserId>, StrippedMemberEvent>,
BTreeMap<String, BTreeMap<String, Raw<AnyStrippedStateEvent>>>,
) {
events.iter().fold(
Expand Down Expand Up @@ -520,7 +522,7 @@ impl BaseClient {
ambiguity_cache: &mut AmbiguityCache,
events: &[Raw<AnySyncStateEvent>],
room_info: &mut RoomInfo,
) -> StoreResult<BTreeSet<UserId>> {
) -> StoreResult<BTreeSet<Box<UserId>>> {
let mut members = BTreeMap::new();
let mut state_events = BTreeMap::new();
let mut user_ids = BTreeSet::new();
Expand Down Expand Up @@ -577,9 +579,9 @@ impl BaseClient {
}
}

changes.members.insert(room_id.as_ref().clone(), members);
changes.profiles.insert(room_id.as_ref().clone(), profiles);
changes.state.insert(room_id.as_ref().clone(), state_events);
changes.members.insert((&*room_id).to_owned(), members);
changes.profiles.insert((&*room_id).to_owned(), profiles);
changes.state.insert((&*room_id).to_owned(), state_events);

Ok(user_ids)
}
Expand Down Expand Up @@ -748,11 +750,12 @@ impl BaseClient {
let joined = self.store.get_joined_user_ids(&room_id).await?;
let invited = self.store.get_invited_user_ids(&room_id).await?;

let user_ids: Vec<&UserId> = joined.iter().chain(&invited).collect();
let user_ids: Vec<&UserId> =
joined.iter().chain(&invited).map(Deref::deref).collect();
o.update_tracked_users(user_ids).await
}

o.update_tracked_users(&user_ids).await
o.update_tracked_users(user_ids.iter().map(Deref::deref)).await;
}
}

Expand Down Expand Up @@ -923,14 +926,14 @@ impl BaseClient {
if member.state_key == member.sender {
changes
.profiles
.entry(room_id.clone())
.entry(room_id.to_owned())
.or_insert_with(BTreeMap::new)
.insert(member.sender.clone(), member.content.clone());
}

changes
.members
.entry(room_id.clone())
.entry(room_id.to_owned())
.or_insert_with(BTreeMap::new)
.insert(member.state_key.clone(), member.clone());
}
Expand All @@ -939,7 +942,7 @@ impl BaseClient {
#[cfg(feature = "encryption")]
if room_info.is_encrypted() {
if let Some(o) = self.olm_machine().await {
o.update_tracked_users(&user_ids).await
o.update_tracked_users(user_ids.iter().map(Deref::deref)).await
}
}

Expand Down Expand Up @@ -1077,7 +1080,7 @@ impl BaseClient {
let settings = settings.ok_or(MegolmError::EncryptionNotEnabled)?;
let settings = EncryptionSettings::new(settings, history_visibility);

Ok(o.share_group_session(room_id, members, settings).await?)
Ok(o.share_group_session(room_id, members.map(Deref::deref), settings).await?)
}
None => panic!("Olm machine wasn't started"),
}
Expand Down Expand Up @@ -1143,12 +1146,12 @@ impl BaseClient {
/// ```
/// # use std::convert::TryFrom;
/// # use matrix_sdk_base::BaseClient;
/// # use ruma::UserId;
/// # use ruma::{device_id, user_id};
/// # use futures::executor::block_on;
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
/// # let alice = user_id!("@alice:example.org").to_owned();
/// # let client = BaseClient::new().unwrap();
/// # block_on(async {
/// let device = client.get_device(&alice, "DEVICEID".into()).await;
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await;
///
/// println!("{:?}", device);
/// # });
Expand Down Expand Up @@ -1201,7 +1204,7 @@ impl BaseClient {
/// # use matrix_sdk_base::BaseClient;
/// # use ruma::UserId;
/// # use futures::executor::block_on;
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
/// # let client = BaseClient::new().unwrap();
/// # block_on(async {
/// let devices = client.get_user_devices(&alice).await.unwrap();
Expand Down Expand Up @@ -1307,7 +1310,7 @@ impl BaseClient {
};

Ok(Some(PushConditionRoomCtx {
room_id: room_id.clone(),
room_id: room_id.to_owned(),
member_count: UInt::new(member_count).unwrap_or(UInt::MAX),
user_display_name,
users_power_levels: room_power_levels.users,
Expand All @@ -1330,15 +1333,16 @@ impl BaseClient {

push_rules.member_count = UInt::new(room_info.active_members_count()).unwrap_or(UInt::MAX);

if let Some(member) = changes.members.get(room_id).and_then(|members| members.get(user_id))
if let Some(member) =
changes.members.get(&**room_id).and_then(|members| members.get(user_id))
{
push_rules.user_display_name =
member.content.displayname.clone().unwrap_or_else(|| user_id.localpart().to_owned())
}

if let Some(AnySyncStateEvent::RoomPowerLevels(event)) = changes
.state
.get(room_id)
.get(&**room_id)
.and_then(|types| types.get(EventType::RoomPowerLevels.as_str()))
.and_then(|events| events.get(""))
.and_then(|e| e.deserialize().ok())
Expand Down
Loading