feat: Add fallback keys support

This commit is contained in:
Sorunome 2021-02-15 16:23:33 +01:00
parent 0b7a0dffb9
commit 8573e1915f
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 27 additions and 9 deletions

View File

@ -1,17 +1,17 @@
/* MIT License /* MIT License
* *
* Copyright (C) 2019, 2020, 2021 Famedly GmbH * Copyright (C) 2019, 2020, 2021 Famedly GmbH
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -1427,13 +1427,19 @@ class MatrixApi {
/// Publishes end-to-end encryption keys for the device. /// Publishes end-to-end encryption keys for the device.
/// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-query /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-query
Future<Map<String, int>> uploadDeviceKeys( Future<Map<String, int>> uploadDeviceKeys(
{MatrixDeviceKeys deviceKeys, Map<String, dynamic> oneTimeKeys}) async { {MatrixDeviceKeys deviceKeys,
Map<String, dynamic> oneTimeKeys,
Map<String, dynamic> fallbackKeys}) async {
final response = await request( final response = await request(
RequestType.POST, RequestType.POST,
'/client/r0/keys/upload', '/client/r0/keys/upload',
data: { data: {
if (deviceKeys != null) 'device_keys': deviceKeys.toJson(), if (deviceKeys != null) 'device_keys': deviceKeys.toJson(),
if (oneTimeKeys != null) 'one_time_keys': oneTimeKeys, if (oneTimeKeys != null) 'one_time_keys': oneTimeKeys,
if (fallbackKeys != null) ...{
'fallback_keys': fallbackKeys,
'org.matrix.msc2732.fallback_keys': fallbackKeys,
},
}, },
); );
return Map<String, int>.from(response['one_time_key_counts']); return Map<String, int>.from(response['one_time_key_counts']);

View File

@ -1,17 +1,17 @@
/* MIT License /* MIT License
* *
* Copyright (C) 2019, 2020, 2021 Famedly GmbH * Copyright (C) 2019, 2020, 2021 Famedly GmbH
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -37,6 +37,7 @@ class SyncUpdate {
List<BasicEventWithSender> toDevice; List<BasicEventWithSender> toDevice;
DeviceListsUpdate deviceLists; DeviceListsUpdate deviceLists;
Map<String, int> deviceOneTimeKeysCount; Map<String, int> deviceOneTimeKeysCount;
List<String> deviceUnusedFallbackKeyTypes;
SyncUpdate(); SyncUpdate();
@ -66,6 +67,12 @@ class SyncUpdate {
deviceOneTimeKeysCount = json['device_one_time_keys_count'] != null deviceOneTimeKeysCount = json['device_one_time_keys_count'] != null
? Map<String, int>.from(json['device_one_time_keys_count']) ? Map<String, int>.from(json['device_one_time_keys_count'])
: null; : null;
deviceUnusedFallbackKeyTypes = (json['device_unused_fallback_key_types'] ??
json['org.matrix.msc2732.device_unused_fallback_key_types']) !=
null
? List<String>.from(json['device_unused_fallback_key_types'] ??
json['org.matrix.msc2732.device_unused_fallback_key_types'])
: null;
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -95,6 +102,11 @@ class SyncUpdate {
if (deviceOneTimeKeysCount != null) { if (deviceOneTimeKeysCount != null) {
data['device_one_time_keys_count'] = deviceOneTimeKeysCount; data['device_one_time_keys_count'] = deviceOneTimeKeysCount;
} }
if (deviceUnusedFallbackKeyTypes != null) {
data['device_unused_fallback_key_types'] = deviceUnusedFallbackKeyTypes;
data['org.matrix.msc2732.device_unused_fallback_key_types'] =
deviceUnusedFallbackKeyTypes;
}
return data; return data;
} }
} }