Skip to content

Commit 8494f10

Browse files
committed
Merge branch 'up-ruma'
2 parents a628e84 + 5824cb6 commit 8494f10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1032
-1031
lines changed

crates/matrix-qrcode/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ byteorder = "1.4.3"
2727
image = { version = "0.23.14", optional = true }
2828
qrcode = { version = "0.12.0", default-features = false }
2929
rqrr = { version = "0.4.0", optional = true }
30-
ruma-identifiers = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5" }
30+
ruma-identifiers = { git = "https://github.com/ruma/ruma", rev = "6c4892664" }
3131
thiserror = "1.0.25"

crates/matrix-qrcode/src/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::{
16-
convert::TryFrom,
16+
convert::{TryFrom, TryInto},
1717
io::{Cursor, Read},
1818
};
1919

@@ -316,7 +316,7 @@ impl QrVerificationData {
316316

317317
match mode {
318318
VerificationData::QR_MODE => {
319-
let event_id = EventId::try_from(flow_id)?;
319+
let event_id = flow_id.try_into()?;
320320
Ok(VerificationData::new(event_id, first_key, second_key, shared_secret).into())
321321
}
322322
SelfVerificationData::QR_MODE => {
@@ -375,7 +375,7 @@ impl QrVerificationData {
375375
/// cross signing keys.
376376
#[derive(Clone, Debug, PartialEq)]
377377
pub struct VerificationData {
378-
event_id: EventId,
378+
event_id: Box<EventId>,
379379
first_master_key: String,
380380
second_master_key: String,
381381
shared_secret: String,
@@ -398,7 +398,7 @@ impl VerificationData {
398398
/// * ` shared_secret` - A random bytestring encoded as unpadded base64,
399399
/// needs to be at least 8 bytes long.
400400
pub fn new(
401-
event_id: EventId,
401+
event_id: Box<EventId>,
402402
first_key: String,
403403
second_key: String,
404404
shared_secret: String,

crates/matrix-sdk-appservice/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ warp = { version = "0.3.1", optional = true, default-features = false }
3838

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

4444
[dev-dependencies]

crates/matrix-sdk-appservice/examples/appservice_autojoin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub async fn handle_room_member(
2121
if !appservice.user_id_is_in_namespace(&event.state_key)? {
2222
trace!("not an appservice user: {}", event.state_key);
2323
} else if let MembershipState::Invite = event.content.membership {
24-
let user_id = UserId::try_from(event.state_key.as_str())?;
24+
let user_id = Box::<UserId>::try_from(event.state_key.as_str())?;
2525
appservice.register_virtual_user(user_id.localpart()).await?;
2626

2727
let client = appservice.virtual_user_client(user_id.localpart()).await?;

crates/matrix-sdk-appservice/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ use ruma::{
107107
},
108108
client::r0::account::register,
109109
},
110-
assign, identifiers, DeviceId, ServerNameBox, UserId,
110+
assign, identifiers, DeviceId, ServerName, UserId,
111111
};
112112
use serde::de::DeserializeOwned;
113113
use tracing::info;
@@ -203,7 +203,7 @@ pub type VirtualUser = ();
203203
#[derive(Debug, Clone)]
204204
pub struct AppService {
205205
homeserver_url: Url,
206-
server_name: ServerNameBox,
206+
server_name: Box<ServerName>,
207207
registration: Arc<AppServiceRegistration>,
208208
clients: Arc<DashMap<Localpart, Client>>,
209209
event_handler: event_handler::EventHandler,
@@ -227,7 +227,7 @@ impl AppService {
227227
/// [AppService Registration]: https://matrix.org/docs/spec/application_service/r0.1.2#registration
228228
pub async fn new(
229229
homeserver_url: impl TryInto<Url, Error = url::ParseError>,
230-
server_name: impl TryInto<ServerNameBox, Error = identifiers::Error>,
230+
server_name: impl TryInto<Box<ServerName>, Error = identifiers::Error>,
231231
registration: AppServiceRegistration,
232232
) -> Result<Self> {
233233
let appservice = Self::new_with_config(
@@ -245,7 +245,7 @@ impl AppService {
245245
/// [`Client`]
246246
pub async fn new_with_config(
247247
homeserver_url: impl TryInto<Url, Error = url::ParseError>,
248-
server_name: impl TryInto<ServerNameBox, Error = identifiers::Error>,
248+
server_name: impl TryInto<Box<ServerName>, Error = identifiers::Error>,
249249
registration: AppServiceRegistration,
250250
client_config: ClientConfig,
251251
) -> Result<Self> {

crates/matrix-sdk-appservice/tests/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ async fn test_appservice_on_sub_path() -> Result<()> {
294294

295295
let members = appservice
296296
.get_cached_client(None)?
297-
.get_room(&room_id)
297+
.get_room(room_id)
298298
.expect("Expected room to be available")
299299
.members_no_sync()
300300
.await?;

crates/matrix-sdk-base/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" }
3535
matrix-sdk-crypto = { version = "0.4.0", path = "../matrix-sdk-crypto", optional = true }
3636
pbkdf2 = { version = "0.9.0", default-features = false, optional = true }
3737
rand = { version = "0.8.4", optional = true }
38-
ruma = { git = "https://github.com/ruma/ruma", rev = "ac6ecc3e5", features = ["client-api-c", "unstable-pre-spec"] }
38+
ruma = { git = "https://github.com/ruma/ruma", rev = "6c4892664", features = ["client-api-c", "unstable-pre-spec"] }
3939
serde = { version = "1.0.126", features = ["rc"] }
4040
serde_json = "1.0.64"
4141
sha2 = { version = "0.9.5", optional = true }

crates/matrix-sdk-base/examples/state_inspector.rs

+22-14
Original file line numberDiff line numberDiff line change
@@ -223,27 +223,27 @@ impl Inspector {
223223
match matches.subcommand() {
224224
("get-profiles", args) => {
225225
let args = args.expect("No args provided for get-state");
226-
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
226+
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
227227

228228
self.get_profiles(room_id).await;
229229
}
230230

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

235235
self.get_members(room_id).await;
236236
}
237237
("list-rooms", _) => self.list_rooms().await,
238238
("get-display-names", args) => {
239239
let args = args.expect("No args provided for get-state");
240-
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
240+
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
241241
let display_name = args.value_of("display-name").unwrap().to_string();
242242
self.get_display_name_owners(room_id, display_name).await;
243243
}
244244
("get-state", args) => {
245245
let args = args.expect("No args provided for get-state");
246-
let room_id = RoomId::try_from(args.value_of("room-id").unwrap()).unwrap();
246+
let room_id = Box::<RoomId>::try_from(args.value_of("room-id").unwrap()).unwrap();
247247
let event_type = EventType::try_from(args.value_of("event-type").unwrap()).unwrap();
248248
self.get_state(room_id, event_type).await;
249249
}
@@ -256,30 +256,30 @@ impl Inspector {
256256
self.printer.pretty_print_struct(&rooms);
257257
}
258258

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

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

267267
for member in joined {
268268
let event = self.store.get_profile(&room_id, &member).await.unwrap();
269269
self.printer.pretty_print_struct(&event);
270270
}
271271
}
272272

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

276276
for member in joined {
277277
let event = self.store.get_member_event(&room_id, &member).await.unwrap();
278278
self.printer.pretty_print_struct(&event);
279279
}
280280
}
281281

282-
async fn get_state(&self, room_id: RoomId, event_type: EventType) {
282+
async fn get_state(&self, room_id: Box<RoomId>, event_type: EventType) {
283283
self.printer.pretty_print_struct(
284284
&self.store.get_state_event(&room_id, event_type, "").await.unwrap(),
285285
);
@@ -290,22 +290,30 @@ impl Inspector {
290290
SubCommand::with_name("list-rooms"),
291291
SubCommand::with_name("get-members").arg(
292292
Arg::with_name("room-id").required(true).validator(|r| {
293-
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
293+
Box::<RoomId>::try_from(r)
294+
.map(|_| ())
295+
.map_err(|_| "Invalid room id given".to_owned())
294296
}),
295297
),
296298
SubCommand::with_name("get-profiles").arg(
297299
Arg::with_name("room-id").required(true).validator(|r| {
298-
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
300+
Box::<RoomId>::try_from(r)
301+
.map(|_| ())
302+
.map_err(|_| "Invalid room id given".to_owned())
299303
}),
300304
),
301305
SubCommand::with_name("get-display-names")
302306
.arg(Arg::with_name("room-id").required(true).validator(|r| {
303-
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
307+
Box::<RoomId>::try_from(r)
308+
.map(|_| ())
309+
.map_err(|_| "Invalid room id given".to_owned())
304310
}))
305311
.arg(Arg::with_name("display-name").required(true)),
306312
SubCommand::with_name("get-state")
307313
.arg(Arg::with_name("room-id").required(true).validator(|r| {
308-
RoomId::try_from(r).map(|_| ()).map_err(|_| "Invalid room id given".to_owned())
314+
Box::<RoomId>::try_from(r)
315+
.map(|_| ())
316+
.map_err(|_| "Invalid room id given".to_owned())
309317
}))
310318
.arg(Arg::with_name("event-type").required(true).validator(|e| {
311319
EventType::try_from(e).map(|_| ()).map_err(|_| "Invalid event type".to_string())

crates/matrix-sdk-base/src/client.rs

+26-22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
#[cfg(feature = "encryption")]
17+
use std::ops::Deref;
1618
use std::{
1719
collections::{BTreeMap, BTreeSet},
1820
convert::TryFrom,
@@ -352,7 +354,7 @@ impl BaseClient {
352354
room_info: &mut RoomInfo,
353355
changes: &mut StateChanges,
354356
ambiguity_cache: &mut AmbiguityCache,
355-
user_ids: &mut BTreeSet<UserId>,
357+
user_ids: &mut BTreeSet<Box<UserId>>,
356358
) -> Result<Timeline> {
357359
let room_id = room.room_id();
358360
let user_id = room.own_user_id();
@@ -388,14 +390,14 @@ impl BaseClient {
388390
if member.state_key == member.sender {
389391
changes
390392
.profiles
391-
.entry(room_id.clone())
393+
.entry(room_id.to_owned())
392394
.or_insert_with(BTreeMap::new)
393395
.insert(member.sender.clone(), member.content.clone());
394396
}
395397

396398
changes
397399
.members
398-
.entry(room_id.clone())
400+
.entry(room_id.to_owned())
399401
.or_insert_with(BTreeMap::new)
400402
.insert(member.state_key.clone(), member);
401403
}
@@ -443,7 +445,7 @@ impl BaseClient {
443445
actions,
444446
event.event.clone(),
445447
false,
446-
room_id.clone(),
448+
room_id.to_owned(),
447449
MilliSecondsSinceUnixEpoch::now(),
448450
),
449451
);
@@ -475,7 +477,7 @@ impl BaseClient {
475477
events: &[Raw<AnyStrippedStateEvent>],
476478
room_info: &mut RoomInfo,
477479
) -> (
478-
BTreeMap<UserId, StrippedMemberEvent>,
480+
BTreeMap<Box<UserId>, StrippedMemberEvent>,
479481
BTreeMap<String, BTreeMap<String, Raw<AnyStrippedStateEvent>>>,
480482
) {
481483
events.iter().fold(
@@ -520,7 +522,7 @@ impl BaseClient {
520522
ambiguity_cache: &mut AmbiguityCache,
521523
events: &[Raw<AnySyncStateEvent>],
522524
room_info: &mut RoomInfo,
523-
) -> StoreResult<BTreeSet<UserId>> {
525+
) -> StoreResult<BTreeSet<Box<UserId>>> {
524526
let mut members = BTreeMap::new();
525527
let mut state_events = BTreeMap::new();
526528
let mut user_ids = BTreeSet::new();
@@ -577,9 +579,9 @@ impl BaseClient {
577579
}
578580
}
579581

580-
changes.members.insert(room_id.as_ref().clone(), members);
581-
changes.profiles.insert(room_id.as_ref().clone(), profiles);
582-
changes.state.insert(room_id.as_ref().clone(), state_events);
582+
changes.members.insert((&*room_id).to_owned(), members);
583+
changes.profiles.insert((&*room_id).to_owned(), profiles);
584+
changes.state.insert((&*room_id).to_owned(), state_events);
583585

584586
Ok(user_ids)
585587
}
@@ -748,11 +750,12 @@ impl BaseClient {
748750
let joined = self.store.get_joined_user_ids(&room_id).await?;
749751
let invited = self.store.get_invited_user_ids(&room_id).await?;
750752

751-
let user_ids: Vec<&UserId> = joined.iter().chain(&invited).collect();
753+
let user_ids: Vec<&UserId> =
754+
joined.iter().chain(&invited).map(Deref::deref).collect();
752755
o.update_tracked_users(user_ids).await
753756
}
754757

755-
o.update_tracked_users(&user_ids).await
758+
o.update_tracked_users(user_ids.iter().map(Deref::deref)).await;
756759
}
757760
}
758761

@@ -923,14 +926,14 @@ impl BaseClient {
923926
if member.state_key == member.sender {
924927
changes
925928
.profiles
926-
.entry(room_id.clone())
929+
.entry(room_id.to_owned())
927930
.or_insert_with(BTreeMap::new)
928931
.insert(member.sender.clone(), member.content.clone());
929932
}
930933

931934
changes
932935
.members
933-
.entry(room_id.clone())
936+
.entry(room_id.to_owned())
934937
.or_insert_with(BTreeMap::new)
935938
.insert(member.state_key.clone(), member.clone());
936939
}
@@ -939,7 +942,7 @@ impl BaseClient {
939942
#[cfg(feature = "encryption")]
940943
if room_info.is_encrypted() {
941944
if let Some(o) = self.olm_machine().await {
942-
o.update_tracked_users(&user_ids).await
945+
o.update_tracked_users(user_ids.iter().map(Deref::deref)).await
943946
}
944947
}
945948

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

1080-
Ok(o.share_group_session(room_id, members, settings).await?)
1083+
Ok(o.share_group_session(room_id, members.map(Deref::deref), settings).await?)
10811084
}
10821085
None => panic!("Olm machine wasn't started"),
10831086
}
@@ -1143,12 +1146,12 @@ impl BaseClient {
11431146
/// ```
11441147
/// # use std::convert::TryFrom;
11451148
/// # use matrix_sdk_base::BaseClient;
1146-
/// # use ruma::UserId;
1149+
/// # use ruma::{device_id, user_id};
11471150
/// # use futures::executor::block_on;
1148-
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
1151+
/// # let alice = user_id!("@alice:example.org").to_owned();
11491152
/// # let client = BaseClient::new().unwrap();
11501153
/// # block_on(async {
1151-
/// let device = client.get_device(&alice, "DEVICEID".into()).await;
1154+
/// let device = client.get_device(&alice, device_id!("DEVICEID")).await;
11521155
///
11531156
/// println!("{:?}", device);
11541157
/// # });
@@ -1201,7 +1204,7 @@ impl BaseClient {
12011204
/// # use matrix_sdk_base::BaseClient;
12021205
/// # use ruma::UserId;
12031206
/// # use futures::executor::block_on;
1204-
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
1207+
/// # let alice = Box::<UserId>::try_from("@alice:example.org").unwrap();
12051208
/// # let client = BaseClient::new().unwrap();
12061209
/// # block_on(async {
12071210
/// let devices = client.get_user_devices(&alice).await.unwrap();
@@ -1307,7 +1310,7 @@ impl BaseClient {
13071310
};
13081311

13091312
Ok(Some(PushConditionRoomCtx {
1310-
room_id: room_id.clone(),
1313+
room_id: room_id.to_owned(),
13111314
member_count: UInt::new(member_count).unwrap_or(UInt::MAX),
13121315
user_display_name,
13131316
users_power_levels: room_power_levels.users,
@@ -1330,15 +1333,16 @@ impl BaseClient {
13301333

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

1333-
if let Some(member) = changes.members.get(room_id).and_then(|members| members.get(user_id))
1336+
if let Some(member) =
1337+
changes.members.get(&**room_id).and_then(|members| members.get(user_id))
13341338
{
13351339
push_rules.user_display_name =
13361340
member.content.displayname.clone().unwrap_or_else(|| user_id.localpart().to_owned())
13371341
}
13381342

13391343
if let Some(AnySyncStateEvent::RoomPowerLevels(event)) = changes
13401344
.state
1341-
.get(room_id)
1345+
.get(&**room_id)
13421346
.and_then(|types| types.get(EventType::RoomPowerLevels.as_str()))
13431347
.and_then(|events| events.get(""))
13441348
.and_then(|e| e.deserialize().ok())

0 commit comments

Comments
 (0)