Skip to content

Commit 1a7baf6

Browse files
committed
Avoid enormous type name in GroupSessionManager::encrypt_session_for
1 parent 009ead2 commit 1a7baf6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

crates/matrix-sdk-crypto/src/session_manager/group_sessions.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,21 @@ impl GroupSessionManager {
226226
BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, ShareInfo>>,
227227
Vec<Session>,
228228
)> {
229+
// Use a named type instead of a tuple with rather long type name
230+
struct EncryptResult {
231+
used_session: Option<Session>,
232+
share_info: BTreeMap<Box<UserId>, BTreeMap<Box<DeviceId>, ShareInfo>>,
233+
message:
234+
BTreeMap<Box<UserId>, BTreeMap<DeviceIdOrAllDevices, Raw<AnyToDeviceEventContent>>>,
235+
}
236+
229237
let mut messages = BTreeMap::new();
230238
let mut changed_sessions = Vec::new();
231239
let mut share_infos = BTreeMap::new();
232240

233241
let encrypt = |device: Device, content: AnyToDeviceEventContent| async move {
234242
let mut message = BTreeMap::new();
235-
let mut share_infos = BTreeMap::new();
243+
let mut share_info = BTreeMap::new();
236244

237245
let encrypted = device.encrypt(content.clone()).await;
238246

@@ -246,7 +254,7 @@ impl GroupSessionManager {
246254
Raw::new(&AnyToDeviceEventContent::RoomEncrypted(encrypted))
247255
.expect("Failed to serialize encrypted event"),
248256
);
249-
share_infos
257+
share_info
250258
.entry(device.user_id().to_owned())
251259
.or_insert_with(BTreeMap::new)
252260
.insert(
@@ -265,7 +273,7 @@ impl GroupSessionManager {
265273
Err(e) => return Err(e),
266274
};
267275

268-
Ok((used_session, share_infos, message))
276+
Ok(EncryptResult { used_session, share_info, message })
269277
};
270278

271279
let tasks: Vec<_> =
@@ -274,7 +282,8 @@ impl GroupSessionManager {
274282
let results = join_all(tasks).await;
275283

276284
for result in results {
277-
let (used_session, infos, message) = result.expect("Encryption task panicked")?;
285+
let EncryptResult { used_session, share_info, message } =
286+
result.expect("Encryption task panicked")?;
278287

279288
if let Some(session) = used_session {
280289
changed_sessions.push(session);
@@ -284,7 +293,7 @@ impl GroupSessionManager {
284293
messages.entry(user).or_insert_with(BTreeMap::new).extend(device_messages);
285294
}
286295

287-
for (user, infos) in infos.into_iter() {
296+
for (user, infos) in share_info.into_iter() {
288297
share_infos.entry(user).or_insert_with(BTreeMap::new).extend(infos);
289298
}
290299
}

0 commit comments

Comments
 (0)