[Event] Key sharing with all users in a room

This commit is contained in:
Christian Pauly 2020-02-22 09:08:01 +01:00
parent 8a3547a1ee
commit 8a7468db01
2 changed files with 20 additions and 6 deletions

View file

@ -1708,8 +1708,12 @@ class Client {
/// Sends an encrypted [message] of this [type] to these [deviceKeys]. To send /// Sends an encrypted [message] of this [type] to these [deviceKeys]. To send
/// the request to all devices of the current user, pass an empty list to [deviceKeys]. /// the request to all devices of the current user, pass an empty list to [deviceKeys].
Future<void> sendToDevice( Future<void> sendToDevice(
List<DeviceKeys> deviceKeys, String type, Map<String, dynamic> message, List<DeviceKeys> deviceKeys,
{bool encrypted = true}) async { String type,
Map<String, dynamic> message, {
bool encrypted = true,
List<User> toUsers,
}) async {
if (encrypted && !encryptionEnabled) return; if (encrypted && !encryptionEnabled) return;
// Don't send this message to blocked devices. // Don't send this message to blocked devices.
if (deviceKeys.isNotEmpty) { if (deviceKeys.isNotEmpty) {
@ -1764,8 +1768,15 @@ class Client {
"messages": Map<String, dynamic>(), "messages": Map<String, dynamic>(),
}; };
if (deviceKeys.isEmpty) { if (deviceKeys.isEmpty) {
data["messages"][this.userID] = Map<String, dynamic>(); if (toUsers == null) {
data["messages"][this.userID]["*"] = sendToDeviceMessage; data["messages"][this.userID] = Map<String, dynamic>();
data["messages"][this.userID]["*"] = sendToDeviceMessage;
} else {
for (User user in toUsers) {
data["messages"][user.id] = Map<String, dynamic>();
data["messages"][user.id]["*"] = sendToDeviceMessage;
}
}
} else { } else {
for (int i = 0; i < deviceKeys.length; i++) { for (int i = 0; i < deviceKeys.length; i++) {
DeviceKeys device = deviceKeys[i]; DeviceKeys device = deviceKeys[i];

View file

@ -399,6 +399,7 @@ class Event {
this.content["body"] != DecryptError.UNKNOWN_SESSION) { this.content["body"] != DecryptError.UNKNOWN_SESSION) {
throw ("Session key not unknown"); throw ("Session key not unknown");
} }
final List<User> users = await room.requestParticipants();
await room.client.sendToDevice( await room.client.sendToDevice(
[], [],
"m.room_key_request", "m.room_key_request",
@ -406,7 +407,8 @@ class Event {
"action": "request_cancellation", "action": "request_cancellation",
"request_id": base64.encode(utf8.encode(content["session_id"])), "request_id": base64.encode(utf8.encode(content["session_id"])),
"requesting_device_id": room.client.deviceID, "requesting_device_id": room.client.deviceID,
}); },
toUsers: users);
await room.client.sendToDevice( await room.client.sendToDevice(
[], [],
"m.room_key_request", "m.room_key_request",
@ -421,7 +423,8 @@ class Event {
"request_id": base64.encode(utf8.encode(content["session_id"])), "request_id": base64.encode(utf8.encode(content["session_id"])),
"requesting_device_id": room.client.deviceID, "requesting_device_id": room.client.deviceID,
}, },
encrypted: false); encrypted: false,
toUsers: users);
return; return;
} }
} }