From 8573e1915f5cf2a53f48bcd2bdcb30f25355747d Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 15 Feb 2021 16:23:33 +0100 Subject: [PATCH] feat: Add fallback keys support --- lib/src/matrix_api.dart | 16 +++++++++++----- lib/src/model/sync_update.dart | 20 ++++++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/src/matrix_api.dart b/lib/src/matrix_api.dart index 91e11475..5042d01e 100644 --- a/lib/src/matrix_api.dart +++ b/lib/src/matrix_api.dart @@ -1,17 +1,17 @@ /* MIT License -* +* * Copyright (C) 2019, 2020, 2021 Famedly GmbH -* +* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: -* +* * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. -* +* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * 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. /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-query Future> uploadDeviceKeys( - {MatrixDeviceKeys deviceKeys, Map oneTimeKeys}) async { + {MatrixDeviceKeys deviceKeys, + Map oneTimeKeys, + Map fallbackKeys}) async { final response = await request( RequestType.POST, '/client/r0/keys/upload', data: { if (deviceKeys != null) 'device_keys': deviceKeys.toJson(), if (oneTimeKeys != null) 'one_time_keys': oneTimeKeys, + if (fallbackKeys != null) ...{ + 'fallback_keys': fallbackKeys, + 'org.matrix.msc2732.fallback_keys': fallbackKeys, + }, }, ); return Map.from(response['one_time_key_counts']); diff --git a/lib/src/model/sync_update.dart b/lib/src/model/sync_update.dart index 0be0150d..741b3405 100644 --- a/lib/src/model/sync_update.dart +++ b/lib/src/model/sync_update.dart @@ -1,17 +1,17 @@ /* MIT License -* +* * Copyright (C) 2019, 2020, 2021 Famedly GmbH -* +* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: -* +* * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. -* +* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -37,6 +37,7 @@ class SyncUpdate { List toDevice; DeviceListsUpdate deviceLists; Map deviceOneTimeKeysCount; + List deviceUnusedFallbackKeyTypes; SyncUpdate(); @@ -66,6 +67,12 @@ class SyncUpdate { deviceOneTimeKeysCount = json['device_one_time_keys_count'] != null ? Map.from(json['device_one_time_keys_count']) : null; + deviceUnusedFallbackKeyTypes = (json['device_unused_fallback_key_types'] ?? + json['org.matrix.msc2732.device_unused_fallback_key_types']) != + null + ? List.from(json['device_unused_fallback_key_types'] ?? + json['org.matrix.msc2732.device_unused_fallback_key_types']) + : null; } Map toJson() { @@ -95,6 +102,11 @@ class SyncUpdate { if (deviceOneTimeKeysCount != null) { 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; } }