crypto: Simplify counting the number of messages a to-device request has
parent
880818a588
commit
75ac29540d
|
@ -63,6 +63,14 @@ impl ToDeviceRequest {
|
||||||
pub fn txn_id_string(&self) -> String {
|
pub fn txn_id_string(&self) -> String {
|
||||||
self.txn_id.to_string()
|
self.txn_id.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the number of unique messages this request contains.
|
||||||
|
///
|
||||||
|
/// *Note*: A single message may be sent to multiple devices, so this may or
|
||||||
|
/// may not be the number of devices that will receive the messages as well.
|
||||||
|
pub fn message_count(&self) -> usize {
|
||||||
|
self.messages.values().map(|d| d.len()).sum()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request that will publish a cross signing identity.
|
/// Request that will publish a cross signing identity.
|
||||||
|
|
|
@ -251,6 +251,12 @@ impl GroupSessionManager {
|
||||||
messages,
|
messages,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
trace!(
|
||||||
|
recipient_count = request.message_count(),
|
||||||
|
transaction_id = ?id,
|
||||||
|
"Created a to-device request carrying a room_key"
|
||||||
|
);
|
||||||
|
|
||||||
Ok((id, request, changed_sessions))
|
Ok((id, request, changed_sessions))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,9 +599,7 @@ mod test {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let event_count = requests.iter().fold(0, |acc, r| {
|
let event_count: usize = requests.iter().map(|r| r.message_count()).sum();
|
||||||
acc + r.messages.values().fold(0, |acc, v| acc + v.len())
|
|
||||||
});
|
|
||||||
|
|
||||||
// The keys claim response has a couple of one-time keys with invalid
|
// The keys claim response has a couple of one-time keys with invalid
|
||||||
// signatures, thus only 148 sessions are actually created, we check
|
// signatures, thus only 148 sessions are actually created, we check
|
||||||
|
|
Loading…
Reference in New Issue