[Client] Add debug prints

This commit is contained in:
Christian Pauly 2020-02-20 07:28:15 +00:00
parent 6dd3b879b6
commit 49e643625c
2 changed files with 21 additions and 21 deletions

View file

@ -920,7 +920,7 @@ class Client {
_sortRooms(); _sortRooms();
} }
this.prevBatch = syncResp["next_batch"]; this.prevBatch = syncResp["next_batch"];
unawaited(_updateUserDeviceKeys()); await _updateUserDeviceKeys();
if (hash == _syncRequest.hashCode) unawaited(_sync()); if (hash == _syncRequest.hashCode) unawaited(_sync());
} on MatrixException catch (exception) { } on MatrixException catch (exception) {
onError.add(exception); onError.add(exception);
@ -997,7 +997,6 @@ class Client {
void _handleDeviceListsEvents(Map<String, dynamic> deviceLists) { void _handleDeviceListsEvents(Map<String, dynamic> deviceLists) {
if (deviceLists["changed"] is List) { if (deviceLists["changed"] is List) {
for (final userId in deviceLists["changed"]) { for (final userId in deviceLists["changed"]) {
_clearOutboundGroupSessionsByUserId(userId);
if (_userDeviceKeys.containsKey(userId)) { if (_userDeviceKeys.containsKey(userId)) {
_userDeviceKeys[userId].outdated = true; _userDeviceKeys[userId].outdated = true;
} }
@ -1403,34 +1402,34 @@ class Client {
type: HTTPType.POST, type: HTTPType.POST,
action: "/client/r0/keys/query", action: "/client/r0/keys/query",
data: {"timeout": 10000, "device_keys": outdatedLists}); data: {"timeout": 10000, "device_keys": outdatedLists});
final Map<String, DeviceKeysList> oldUserDeviceKeys =
Map<String, DeviceKeysList>.from(_userDeviceKeys);
for (final rawDeviceKeyListEntry in response["device_keys"].entries) { for (final rawDeviceKeyListEntry in response["device_keys"].entries) {
final String userId = rawDeviceKeyListEntry.key; final String userId = rawDeviceKeyListEntry.key;
final Map<String, DeviceKeys> oldKeys =
Map<String, DeviceKeys>.from(_userDeviceKeys[userId].deviceKeys);
_userDeviceKeys[userId].deviceKeys = {}; _userDeviceKeys[userId].deviceKeys = {};
for (final rawDeviceKeyEntry in rawDeviceKeyListEntry.value.entries) { for (final rawDeviceKeyEntry in rawDeviceKeyListEntry.value.entries) {
final String deviceId = rawDeviceKeyEntry.key; final String deviceId = rawDeviceKeyEntry.key;
// Set the new device key for this device // Set the new device key for this device
if (!oldKeys.containsKey(deviceId)) {
_userDeviceKeys[userId].deviceKeys[deviceId] = _userDeviceKeys[userId].deviceKeys[deviceId] =
DeviceKeys.fromJson(rawDeviceKeyEntry.value); DeviceKeys.fromJson(rawDeviceKeyEntry.value);
// Restore verified and blocked flags
if (oldUserDeviceKeys.containsKey(userId) &&
_userDeviceKeys[userId].deviceKeys.containsKey(deviceId)) {
_userDeviceKeys[userId].deviceKeys[deviceId].verified =
_userDeviceKeys[userId].deviceKeys[deviceId].verified;
_userDeviceKeys[userId].deviceKeys[deviceId].blocked =
_userDeviceKeys[userId].deviceKeys[deviceId].blocked;
}
if (deviceId == this.deviceID && if (deviceId == this.deviceID &&
_userDeviceKeys[userId].deviceKeys[deviceId].ed25519Key == _userDeviceKeys[userId].deviceKeys[deviceId].ed25519Key ==
this.fingerprintKey) { this.fingerprintKey) {
// Always trust the own device // Always trust the own device
_userDeviceKeys[userId].deviceKeys[deviceId].verified = true; _userDeviceKeys[userId].deviceKeys[deviceId].verified = true;
} }
} else {
_userDeviceKeys[userId].deviceKeys[deviceId] = oldKeys[deviceId];
}
} }
_userDeviceKeys[userId].outdated = false; _userDeviceKeys[userId].outdated = false;
if (_userDeviceKeys[userId].deviceKeys.toString() !=
oldKeys.toString()) {
_clearOutboundGroupSessionsByUserId(userId);
}
} }
} }
await this.storeAPI?.storeUserDeviceKeys(userDeviceKeys); await this.storeAPI?.storeUserDeviceKeys(userDeviceKeys);

View file

@ -557,11 +557,12 @@ void main() {
} }
}); });
await Future.delayed(Duration(milliseconds: 50)); await Future.delayed(Duration(milliseconds: 50));
expect(matrix.rooms[1].outboundGroupSession == null, true); expect(matrix.rooms[1].outboundGroupSession != null, true);
} }
}); });
test('Test invalidate outboundGroupSessions', () async { test('Test invalidate outboundGroupSessions', () async {
if (matrix.encryptionEnabled) { if (matrix.encryptionEnabled) {
await matrix.rooms[1].clearOutboundGroupSession();
expect(matrix.rooms[1].outboundGroupSession == null, true); expect(matrix.rooms[1].outboundGroupSession == null, true);
await matrix.rooms[1].createOutboundGroupSession(); await matrix.rooms[1].createOutboundGroupSession();
expect(matrix.rooms[1].outboundGroupSession != null, true); expect(matrix.rooms[1].outboundGroupSession != null, true);