You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Also apply cahnge to '_splitBlockedDevices'
This commit is contained in:
@@ -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
|
* @private
|
||||||
*
|
*
|
||||||
* @param {object} devicesByUser map from userid to list of devices
|
* @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
|
* @return {array<array<object>>} the blocked devices, split into chunks
|
||||||
*/
|
*/
|
||||||
MegolmEncryption.prototype._splitBlockedDevices = function(devicesByUser) {
|
MegolmEncryption.prototype._splitBlockedDevices = function(devicesByUser) {
|
||||||
const maxToDeviceMessagesPerRequest = 20;
|
const maxUsersPerRequest = 20;
|
||||||
|
|
||||||
// use an array where the slices of a content map gets stored
|
// use an array where the slices of a content map gets stored
|
||||||
let currentSlice = [];
|
let currentSlice = [];
|
||||||
@@ -434,17 +437,22 @@ MegolmEncryption.prototype._splitBlockedDevices = function(devicesByUser) {
|
|||||||
const userBlockedDevicesToShareWith = devicesByUser[userId];
|
const userBlockedDevicesToShareWith = devicesByUser[userId];
|
||||||
|
|
||||||
for (const blockedInfo of userBlockedDevicesToShareWith) {
|
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({
|
currentSlice.push({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
blockedInfo: blockedInfo,
|
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) {
|
if (currentSlice.length === 0) {
|
||||||
mapSlices.pop();
|
mapSlices.pop();
|
||||||
|
|||||||
Reference in New Issue
Block a user