feat: Add room_key content
This commit is contained in:
parent
0c77539291
commit
81c86a6c05
|
|
@ -81,6 +81,7 @@ export 'src/model/auth/authentication_types.dart';
|
|||
export 'src/model/auth/authentication_user_identifier.dart';
|
||||
export 'src/model/events/room_encrypted_content.dart';
|
||||
export 'src/model/events/room_encryption_content.dart';
|
||||
export 'src/model/events/room_key_content.dart';
|
||||
export 'src/model/events/secret_storage_default_key_content.dart';
|
||||
export 'src/model/events/secret_storage_key_content.dart';
|
||||
export 'src/model/events/tombstone_content.dart';
|
||||
|
|
|
|||
|
|
@ -21,10 +21,14 @@ class RoomEncryptedContent {
|
|||
senderKey = json.tryGet<String>('sender_key', ''),
|
||||
deviceId = json.tryGet<String>('device_id'),
|
||||
sessionId = json.tryGet<String>('session_id'),
|
||||
ciphertextMegolm = json.tryGet<String>('ciphertext'),
|
||||
ciphertextOlm = json
|
||||
.tryGet<Map<String, dynamic>>('ciphertext')
|
||||
?.map((k, v) => MapEntry(k, CiphertextInfo.fromJson(v)));
|
||||
ciphertextMegolm = json['ciphertext'] is String
|
||||
? json.tryGet<String>('ciphertext')
|
||||
: null,
|
||||
ciphertextOlm = json['ciphertext'] is Map<String, dynamic>
|
||||
? json
|
||||
.tryGet<Map<String, dynamic>>('ciphertext')
|
||||
?.map((k, v) => MapEntry(k, CiphertextInfo.fromJson(v)))
|
||||
: null;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
import '../basic_event.dart';
|
||||
import '../../utils/try_get_map_extension.dart';
|
||||
|
||||
extension RoomKeyContentBasicEventExtension on BasicEvent {
|
||||
RoomKeyContent get parsedRoomKeyContent => RoomKeyContent.fromJson(content);
|
||||
}
|
||||
|
||||
class RoomKeyContent {
|
||||
String algorithm;
|
||||
String roomId;
|
||||
String sessionId;
|
||||
String sessionKey;
|
||||
|
||||
RoomKeyContent.fromJson(Map<String, dynamic> json)
|
||||
: algorithm = json.tryGet<String>('algorithm', ''),
|
||||
roomId = json.tryGet<String>('room_id', ''),
|
||||
sessionId = json.tryGet<String>('session_id', ''),
|
||||
sessionKey = json.tryGet<String>('session_key', '');
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
data['algorithm'] = algorithm;
|
||||
data['room_id'] = roomId;
|
||||
data['session_id'] = sessionId;
|
||||
data['session_key'] = sessionKey;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -78,5 +78,18 @@ void main() {
|
|||
expect(MatrixEvent.fromJson(json).parsedRoomEncryptedContent.toJson(),
|
||||
json['content']);
|
||||
});
|
||||
test('Room Key Content', () {
|
||||
var json = <String, dynamic>{
|
||||
'content': {
|
||||
'algorithm': 'm.megolm.v1.aes-sha2',
|
||||
'room_id': '!Cuyf34gef24t:localhost',
|
||||
'session_id': 'X3lUlvLELLYxeTx4yOVu6UDpasGEVO0Jbu+QFnm0cKQ',
|
||||
'session_key': 'AgAAAADxKHa9uFxcXzwYoNueL5Xqi69IkD4sni8LlfJL7qNBEY...'
|
||||
},
|
||||
'type': 'm.room_key'
|
||||
};
|
||||
expect(BasicEvent.fromJson(json).parsedRoomKeyContent.toJson(),
|
||||
json['content']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:matrix_api_lite/matrix_api_lite.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('Try-get-map-extension', () {
|
||||
Logs().level = Level.error;
|
||||
test('it should work', () {
|
||||
final data = <String, dynamic>{
|
||||
'str': 'foxies',
|
||||
|
|
|
|||
Loading…
Reference in New Issue