1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Also apply cahnge to '_splitBlockedDevices'

This commit is contained in:
Erik Johnston
2020-01-14 10:08:46 +00:00
parent 260040b919
commit b4a93d2dc3

View File

@@ -417,6 +417,9 @@ MegolmEncryption.prototype._splitUserDeviceMap = function(
};
/**
* Splits the user device map into multiple chunks to reduce the number of
* devices we encrypt to per API call.
*
* @private
*
* @param {object} devicesByUser map from userid to list of devices
@@ -424,7 +427,7 @@ MegolmEncryption.prototype._splitUserDeviceMap = function(
* @return {array<array<object>>} the blocked devices, split into chunks
*/
MegolmEncryption.prototype._splitBlockedDevices = function(devicesByUser) {
const maxToDeviceMessagesPerRequest = 20;
const maxUsersPerRequest = 20;
// use an array where the slices of a content map gets stored
let currentSlice = [];
@@ -434,17 +437,22 @@ MegolmEncryption.prototype._splitBlockedDevices = function(devicesByUser) {
const userBlockedDevicesToShareWith = devicesByUser[userId];
for (const blockedInfo of userBlockedDevicesToShareWith) {
if (currentSlice.length > maxToDeviceMessagesPerRequest) {
// the current slice is filled up. Start inserting into the next slice
currentSlice = [];
mapSlices.push(currentSlice);
}
currentSlice.push({
userId: userId,
blockedInfo: blockedInfo,
});
}
// We do this in the per-user loop as we prefer that all messages to the
// same user end up in the same API call to make it easier for the
// server (e.g. only have to send one EDU if a remote user, etc). This
// does mean that if a user has many devices we may go over the desired
// limit, but its not a hard limit so that is fine.
if (currentSlice.length > maxUsersPerRequest) {
// the current slice is filled up. Start inserting into the next slice
currentSlice = [];
mapSlices.push(currentSlice);
}
}
if (currentSlice.length === 0) {
mapSlices.pop();