2020-02-04 13:41:13 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import '../client.dart';
|
|
|
|
|
|
|
|
class DeviceKeysList {
|
|
|
|
String userId;
|
|
|
|
bool outdated = true;
|
|
|
|
Map<String, DeviceKeys> deviceKeys = {};
|
|
|
|
|
|
|
|
DeviceKeysList.fromJson(Map<String, dynamic> json) {
|
|
|
|
userId = json['user_id'];
|
|
|
|
outdated = json['outdated'];
|
|
|
|
deviceKeys = {};
|
|
|
|
for (final rawDeviceKeyEntry in json['device_keys'].entries) {
|
|
|
|
deviceKeys[rawDeviceKeyEntry.key] =
|
|
|
|
DeviceKeys.fromJson(rawDeviceKeyEntry.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
final Map<String, dynamic> data = Map<String, dynamic>();
|
|
|
|
data['user_id'] = this.userId;
|
|
|
|
data['outdated'] = this.outdated;
|
|
|
|
|
|
|
|
Map<String, dynamic> rawDeviceKeys = {};
|
|
|
|
for (final deviceKeyEntry in this.deviceKeys.entries) {
|
|
|
|
rawDeviceKeys[deviceKeyEntry.key] = deviceKeyEntry.value.toJson();
|
|
|
|
}
|
|
|
|
data['device_keys'] = rawDeviceKeys;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
String toString() => json.encode(toJson());
|
|
|
|
|
|
|
|
DeviceKeysList(this.userId);
|
|
|
|
}
|
|
|
|
|
|
|
|
class DeviceKeys {
|
|
|
|
String userId;
|
|
|
|
String deviceId;
|
|
|
|
List<String> algorithms;
|
|
|
|
Map<String, String> keys;
|
|
|
|
Map<String, dynamic> signatures;
|
|
|
|
Map<String, dynamic> unsigned;
|
|
|
|
bool verified;
|
|
|
|
bool blocked;
|
|
|
|
|
2020-02-15 07:48:41 +00:00
|
|
|
String get curve25519Key => keys["curve25519:$deviceId"];
|
|
|
|
String get ed25519Key => keys["ed25519:$deviceId"];
|
|
|
|
|
2020-02-04 13:41:13 +00:00
|
|
|
Future<void> setVerified(bool newVerified, Client client) {
|
|
|
|
verified = newVerified;
|
|
|
|
return client.storeAPI.storeUserDeviceKeys(client.userDeviceKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> setBlocked(bool newBlocked, Client client) {
|
|
|
|
blocked = newBlocked;
|
|
|
|
return client.storeAPI.storeUserDeviceKeys(client.userDeviceKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceKeys({
|
|
|
|
this.userId,
|
|
|
|
this.deviceId,
|
|
|
|
this.algorithms,
|
|
|
|
this.keys,
|
|
|
|
this.signatures,
|
|
|
|
this.unsigned,
|
|
|
|
this.verified,
|
|
|
|
this.blocked,
|
|
|
|
});
|
|
|
|
|
|
|
|
DeviceKeys.fromJson(Map<String, dynamic> json) {
|
|
|
|
userId = json['user_id'];
|
|
|
|
deviceId = json['device_id'];
|
|
|
|
algorithms = json['algorithms'].cast<String>();
|
|
|
|
keys = json['keys'] != null ? Map<String, String>.from(json['keys']) : null;
|
|
|
|
signatures = json['signatures'] != null
|
|
|
|
? Map<String, dynamic>.from(json['signatures'])
|
|
|
|
: null;
|
|
|
|
unsigned = json['unsigned'] != null
|
|
|
|
? Map<String, dynamic>.from(json['unsigned'])
|
|
|
|
: null;
|
|
|
|
verified = json['verified'] ?? false;
|
|
|
|
blocked = json['blocked'] ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
final Map<String, dynamic> data = Map<String, dynamic>();
|
|
|
|
data['user_id'] = this.userId;
|
|
|
|
data['device_id'] = this.deviceId;
|
|
|
|
data['algorithms'] = this.algorithms;
|
|
|
|
if (this.keys != null) {
|
|
|
|
data['keys'] = this.keys;
|
|
|
|
}
|
|
|
|
if (this.signatures != null) {
|
|
|
|
data['signatures'] = this.signatures;
|
|
|
|
}
|
|
|
|
if (this.unsigned != null) {
|
|
|
|
data['unsigned'] = this.unsigned;
|
|
|
|
}
|
|
|
|
data['verified'] = this.verified;
|
|
|
|
data['blocked'] = this.blocked;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|