refactor: remove unused clientId
This commit is contained in:
parent
42434761e8
commit
77ca7523d0
|
|
@ -220,10 +220,7 @@ class Encryption {
|
||||||
// line *could* throw an error. As that is a future, though, and we call
|
// line *could* throw an error. As that is a future, though, and we call
|
||||||
// it un-awaited here, nothing happens, which is exactly the result we want
|
// it un-awaited here, nothing happens, which is exactly the result we want
|
||||||
client.database?.updateInboundGroupSessionIndexes(
|
client.database?.updateInboundGroupSessionIndexes(
|
||||||
json.encode(inboundGroupSession.indexes),
|
json.encode(inboundGroupSession.indexes), roomId, sessionId);
|
||||||
client.id,
|
|
||||||
roomId,
|
|
||||||
sessionId);
|
|
||||||
}
|
}
|
||||||
decryptedPayload = json.decode(decryptResult.plaintext);
|
decryptedPayload = json.decode(decryptResult.plaintext);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
|
|
@ -301,7 +298,6 @@ class Encryption {
|
||||||
event.room?.setState(event);
|
event.room?.setState(event);
|
||||||
}
|
}
|
||||||
await client.database?.storeEventUpdate(
|
await client.database?.storeEventUpdate(
|
||||||
client.id,
|
|
||||||
EventUpdate(
|
EventUpdate(
|
||||||
content: event.toJson(),
|
content: event.toJson(),
|
||||||
roomID: event.roomId,
|
roomID: event.roomId,
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,6 @@ class KeyManager {
|
||||||
}
|
}
|
||||||
client.database
|
client.database
|
||||||
?.storeInboundGroupSession(
|
?.storeInboundGroupSession(
|
||||||
client.id,
|
|
||||||
roomId,
|
roomId,
|
||||||
sessionId,
|
sessionId,
|
||||||
inboundGroupSession.pickle(client.userID),
|
inboundGroupSession.pickle(client.userID),
|
||||||
|
|
@ -164,8 +163,7 @@ class KeyManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (uploaded) {
|
if (uploaded) {
|
||||||
client.database
|
client.database.markInboundGroupSessionAsUploaded(roomId, sessionId);
|
||||||
.markInboundGroupSessionAsUploaded(client.id, roomId, sessionId);
|
|
||||||
} else {
|
} else {
|
||||||
_haveKeysToUpload = true;
|
_haveKeysToUpload = true;
|
||||||
}
|
}
|
||||||
|
|
@ -238,8 +236,8 @@ class KeyManager {
|
||||||
}
|
}
|
||||||
return sess; // nothing to do
|
return sess; // nothing to do
|
||||||
}
|
}
|
||||||
final session = await client.database
|
final session =
|
||||||
?.getInboundGroupSession(client.id, roomId, sessionId);
|
await client.database?.getInboundGroupSession(roomId, sessionId);
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -382,7 +380,6 @@ class KeyManager {
|
||||||
if (client.database != null) {
|
if (client.database != null) {
|
||||||
await client.database.updateInboundGroupSessionAllowedAtIndex(
|
await client.database.updateInboundGroupSessionAllowedAtIndex(
|
||||||
json.encode(inboundSess.allowedAtIndex),
|
json.encode(inboundSess.allowedAtIndex),
|
||||||
client.id,
|
|
||||||
room.id,
|
room.id,
|
||||||
sess.outboundGroupSession.session_id());
|
sess.outboundGroupSession.session_id());
|
||||||
}
|
}
|
||||||
|
|
@ -401,7 +398,7 @@ class KeyManager {
|
||||||
}
|
}
|
||||||
sess.dispose();
|
sess.dispose();
|
||||||
_outboundGroupSessions.remove(roomId);
|
_outboundGroupSessions.remove(roomId);
|
||||||
await client.database?.removeOutboundGroupSession(client.id, roomId);
|
await client.database?.removeOutboundGroupSession(roomId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,7 +409,6 @@ class KeyManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await client.database?.storeOutboundGroupSession(
|
await client.database?.storeOutboundGroupSession(
|
||||||
client.id,
|
|
||||||
roomId,
|
roomId,
|
||||||
sess.outboundGroupSession.pickle(client.userID),
|
sess.outboundGroupSession.pickle(client.userID),
|
||||||
json.encode(sess.devices),
|
json.encode(sess.devices),
|
||||||
|
|
@ -516,7 +512,6 @@ class KeyManager {
|
||||||
}
|
}
|
||||||
_loadedOutboundGroupSessions.add(roomId);
|
_loadedOutboundGroupSessions.add(roomId);
|
||||||
final sess = await client.database.getOutboundGroupSession(
|
final sess = await client.database.getOutboundGroupSession(
|
||||||
client.id,
|
|
||||||
roomId,
|
roomId,
|
||||||
client.userID,
|
client.userID,
|
||||||
);
|
);
|
||||||
|
|
@ -753,7 +748,7 @@ class KeyManager {
|
||||||
// no need to optimze this, as we only run it so seldomly and almost never with many keys at once
|
// no need to optimze this, as we only run it so seldomly and almost never with many keys at once
|
||||||
for (final dbSession in dbSessions) {
|
for (final dbSession in dbSessions) {
|
||||||
await client.database.markInboundGroupSessionAsUploaded(
|
await client.database.markInboundGroupSessionAsUploaded(
|
||||||
client.id, dbSession.roomId, dbSession.sessionId);
|
dbSession.roomId, dbSession.sessionId);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
decryption.free();
|
decryption.free();
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,9 @@ class OlmManager {
|
||||||
// in case the app gets killed during upload or the upload fails due to bad network
|
// in case the app gets killed during upload or the upload fails due to bad network
|
||||||
// we can still re-try later
|
// we can still re-try later
|
||||||
if (updateDatabase) {
|
if (updateDatabase) {
|
||||||
await client.database?.updateClientKeys(pickledOlmAccount, client.id);
|
await client.database?.updateClientKeys(
|
||||||
|
pickledOlmAccount,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
final response = await client.uploadKeys(
|
final response = await client.uploadKeys(
|
||||||
deviceKeys: uploadDeviceKeys
|
deviceKeys: uploadDeviceKeys
|
||||||
|
|
@ -245,7 +247,7 @@ class OlmManager {
|
||||||
// mark the OTKs as published and save that to datbase
|
// mark the OTKs as published and save that to datbase
|
||||||
_olmAccount.mark_keys_as_published();
|
_olmAccount.mark_keys_as_published();
|
||||||
if (updateDatabase) {
|
if (updateDatabase) {
|
||||||
await client.database?.updateClientKeys(pickledOlmAccount, client.id);
|
await client.database?.updateClientKeys(pickledOlmAccount);
|
||||||
}
|
}
|
||||||
return (uploadedOneTimeKeysCount != null &&
|
return (uploadedOneTimeKeysCount != null &&
|
||||||
response['signed_curve25519'] == uploadedOneTimeKeysCount) ||
|
response['signed_curve25519'] == uploadedOneTimeKeysCount) ||
|
||||||
|
|
@ -309,7 +311,6 @@ class OlmManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await client.database.storeOlmSession(
|
await client.database.storeOlmSession(
|
||||||
client.id,
|
|
||||||
session.identityKey,
|
session.identityKey,
|
||||||
session.sessionId,
|
session.sessionId,
|
||||||
session.pickledSession,
|
session.pickledSession,
|
||||||
|
|
@ -346,7 +347,6 @@ class OlmManager {
|
||||||
device.lastActive = DateTime.now();
|
device.lastActive = DateTime.now();
|
||||||
await client.database?.setLastActiveUserDeviceKey(
|
await client.database?.setLastActiveUserDeviceKey(
|
||||||
device.lastActive.millisecondsSinceEpoch,
|
device.lastActive.millisecondsSinceEpoch,
|
||||||
client.id,
|
|
||||||
device.userId,
|
device.userId,
|
||||||
device.deviceId);
|
device.deviceId);
|
||||||
}
|
}
|
||||||
|
|
@ -383,7 +383,9 @@ class OlmManager {
|
||||||
try {
|
try {
|
||||||
newSession.create_inbound_from(_olmAccount, senderKey, body);
|
newSession.create_inbound_from(_olmAccount, senderKey, body);
|
||||||
_olmAccount.remove_one_time_keys(newSession);
|
_olmAccount.remove_one_time_keys(newSession);
|
||||||
client.database?.updateClientKeys(pickledOlmAccount, client.id);
|
client.database?.updateClientKeys(
|
||||||
|
pickledOlmAccount,
|
||||||
|
);
|
||||||
plaintext = newSession.decrypt(type, body);
|
plaintext = newSession.decrypt(type, body);
|
||||||
runInRoot(() => storeOlmSession(OlmSession(
|
runInRoot(() => storeOlmSession(OlmSession(
|
||||||
key: client.userID,
|
key: client.userID,
|
||||||
|
|
@ -424,8 +426,8 @@ class OlmManager {
|
||||||
if (client.database == null) {
|
if (client.database == null) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
final olmSessions = await client.database
|
final olmSessions =
|
||||||
.getOlmSessions(client.id, senderKey, client.userID);
|
await client.database.getOlmSessions(senderKey, client.userID);
|
||||||
return olmSessions.where((sess) => sess.isValid).toList();
|
return olmSessions.where((sess) => sess.isValid).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -435,7 +437,6 @@ class OlmManager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final rows = await client.database.getOlmSessionsForDevices(
|
final rows = await client.database.getOlmSessionsForDevices(
|
||||||
client.id,
|
|
||||||
senderKeys,
|
senderKeys,
|
||||||
client.userID,
|
client.userID,
|
||||||
);
|
);
|
||||||
|
|
@ -596,7 +597,6 @@ class OlmManager {
|
||||||
'type': type,
|
'type': type,
|
||||||
'content': payload,
|
'content': payload,
|
||||||
}),
|
}),
|
||||||
client.id,
|
|
||||||
device.userId,
|
device.userId,
|
||||||
device.deviceId));
|
device.deviceId));
|
||||||
}
|
}
|
||||||
|
|
@ -660,8 +660,7 @@ class OlmManager {
|
||||||
Logs().v(
|
Logs().v(
|
||||||
'[OlmManager] Device ${device.userId}:${device.deviceId} generated a new olm session, replaying last sent message...');
|
'[OlmManager] Device ${device.userId}:${device.deviceId} generated a new olm session, replaying last sent message...');
|
||||||
final lastSentMessageRes = await client.database
|
final lastSentMessageRes = await client.database
|
||||||
.getLastSentMessageUserDeviceKey(
|
.getLastSentMessageUserDeviceKey(device.userId, device.deviceId);
|
||||||
client.id, device.userId, device.deviceId);
|
|
||||||
if (lastSentMessageRes.isEmpty ||
|
if (lastSentMessageRes.isEmpty ||
|
||||||
(lastSentMessageRes.first?.isEmpty ?? true)) {
|
(lastSentMessageRes.first?.isEmpty ?? true)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class SSSS {
|
||||||
|
|
||||||
// for testing
|
// for testing
|
||||||
Future<void> clearCache() async {
|
Future<void> clearCache() async {
|
||||||
await client.database?.clearSSSSCache(client.id);
|
await client.database?.clearSSSSCache();
|
||||||
_cache.clear();
|
_cache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,7 +282,7 @@ class SSSS {
|
||||||
if (_cache.containsKey(type) && isValid(_cache[type])) {
|
if (_cache.containsKey(type) && isValid(_cache[type])) {
|
||||||
return _cache[type].content;
|
return _cache[type].content;
|
||||||
}
|
}
|
||||||
final ret = await client.database.getSSSSCache(client.id, type);
|
final ret = await client.database.getSSSSCache(type);
|
||||||
if (ret == null) {
|
if (ret == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -311,7 +311,7 @@ class SSSS {
|
||||||
if (cacheTypes.contains(type) && client.database != null) {
|
if (cacheTypes.contains(type) && client.database != null) {
|
||||||
// cache the thing
|
// cache the thing
|
||||||
await client.database
|
await client.database
|
||||||
.storeSSSSCache(client.id, type, keyId, enc['ciphertext'], decrypted);
|
.storeSSSSCache(type, keyId, enc['ciphertext'], decrypted);
|
||||||
if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) {
|
if (_cacheCallbacks.containsKey(type) && await getCached(type) == null) {
|
||||||
_cacheCallbacks[type](decrypted);
|
_cacheCallbacks[type](decrypted);
|
||||||
}
|
}
|
||||||
|
|
@ -344,7 +344,7 @@ class SSSS {
|
||||||
if (cacheTypes.contains(type) && client.database != null) {
|
if (cacheTypes.contains(type) && client.database != null) {
|
||||||
// cache the thing
|
// cache the thing
|
||||||
await client.database
|
await client.database
|
||||||
.storeSSSSCache(client.id, type, keyId, encrypted.ciphertext, secret);
|
.storeSSSSCache(type, keyId, encrypted.ciphertext, secret);
|
||||||
if (triggerCacheCallback) {
|
if (triggerCacheCallback) {
|
||||||
_cacheCallbacks[type](secret);
|
_cacheCallbacks[type](secret);
|
||||||
}
|
}
|
||||||
|
|
@ -369,8 +369,8 @@ class SSSS {
|
||||||
await client.setAccountData(client.userID, type, content);
|
await client.setAccountData(client.userID, type, content);
|
||||||
if (cacheTypes.contains(type) && client.database != null) {
|
if (cacheTypes.contains(type) && client.database != null) {
|
||||||
// cache the thing
|
// cache the thing
|
||||||
await client.database.storeSSSSCache(client.id, type, keyId,
|
await client.database.storeSSSSCache(
|
||||||
content['encrypted'][keyId]['ciphertext'], secret);
|
type, keyId, content['encrypted'][keyId]['ciphertext'], secret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -532,8 +532,8 @@ class SSSS {
|
||||||
if (keyId != null) {
|
if (keyId != null) {
|
||||||
final ciphertext = client.accountData[request.type]
|
final ciphertext = client.accountData[request.type]
|
||||||
.content['encrypted'][keyId]['ciphertext'];
|
.content['encrypted'][keyId]['ciphertext'];
|
||||||
await client.database.storeSSSSCache(
|
await client.database
|
||||||
client.id, request.type, keyId, ciphertext, secret);
|
.storeSSSSCache(request.type, keyId, ciphertext, secret);
|
||||||
if (_cacheCallbacks.containsKey(request.type)) {
|
if (_cacheCallbacks.containsKey(request.type)) {
|
||||||
_cacheCallbacks[request.type](secret);
|
_cacheCallbacks[request.type](secret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -575,7 +575,7 @@ class Bootstrap {
|
||||||
await newSsssKey.store(megolmKey, base64.encode(privKey));
|
await newSsssKey.store(megolmKey, base64.encode(privKey));
|
||||||
Logs().v(
|
Logs().v(
|
||||||
'And finally set all megolm keys as needing to be uploaded again...');
|
'And finally set all megolm keys as needing to be uploaded again...');
|
||||||
await client.database?.markInboundGroupSessionsAsNeedingUpload(client.id);
|
await client.database?.markInboundGroupSessionsAsNeedingUpload();
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('[Bootstrapping] Error setting up online key backup', e, s);
|
Logs().e('[Bootstrapping] Error setting up online key backup', e, s);
|
||||||
state = BootstrapState.error;
|
state = BootstrapState.error;
|
||||||
|
|
|
||||||
|
|
@ -980,7 +980,6 @@ class Client extends MatrixApi {
|
||||||
_deviceName,
|
_deviceName,
|
||||||
prevBatch,
|
prevBatch,
|
||||||
encryption?.pickledOlmAccount,
|
encryption?.pickledOlmAccount,
|
||||||
id,
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
_id = await database.insertClient(
|
_id = await database.insertClient(
|
||||||
|
|
@ -997,7 +996,7 @@ class Client extends MatrixApi {
|
||||||
_userDeviceKeys = await database.getUserDeviceKeys(this);
|
_userDeviceKeys = await database.getUserDeviceKeys(this);
|
||||||
_rooms = await database.getRoomList(this);
|
_rooms = await database.getRoomList(this);
|
||||||
_sortRooms();
|
_sortRooms();
|
||||||
accountData = await database.getAccountData(id);
|
accountData = await database.getAccountData();
|
||||||
presences.clear();
|
presences.clear();
|
||||||
}
|
}
|
||||||
_initLock = false;
|
_initLock = false;
|
||||||
|
|
@ -1030,7 +1029,7 @@ class Client extends MatrixApi {
|
||||||
Logs().outputEvents.clear();
|
Logs().outputEvents.clear();
|
||||||
try {
|
try {
|
||||||
await abortSync();
|
await abortSync();
|
||||||
await database?.clear(id);
|
await database?.clear();
|
||||||
_backgroundSync = true;
|
_backgroundSync = true;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().e('Unable to clear database', e, s);
|
Logs().e('Unable to clear database', e, s);
|
||||||
|
|
@ -1093,7 +1092,7 @@ class Client extends MatrixApi {
|
||||||
Future<void> _checkSyncFilter() async {
|
Future<void> _checkSyncFilter() async {
|
||||||
if (syncFilterId == null) {
|
if (syncFilterId == null) {
|
||||||
syncFilterId = await defineFilter(userID, syncFilter);
|
syncFilterId = await defineFilter(userID, syncFilter);
|
||||||
await database?.storeSyncFilterId(syncFilterId, id);
|
await database?.storeSyncFilterId(syncFilterId);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1132,7 +1131,7 @@ class Client extends MatrixApi {
|
||||||
_currentTransaction = database.transaction(() async {
|
_currentTransaction = database.transaction(() async {
|
||||||
await _handleSync(syncResp);
|
await _handleSync(syncResp);
|
||||||
if (prevBatch != syncResp.nextBatch) {
|
if (prevBatch != syncResp.nextBatch) {
|
||||||
await database.storePrevBatch(syncResp.nextBatch, id);
|
await database.storePrevBatch(syncResp.nextBatch);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await _currentTransaction;
|
await _currentTransaction;
|
||||||
|
|
@ -1218,7 +1217,6 @@ class Client extends MatrixApi {
|
||||||
for (final newAccountData in sync.accountData) {
|
for (final newAccountData in sync.accountData) {
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
await database.storeAccountData(
|
await database.storeAccountData(
|
||||||
id,
|
|
||||||
newAccountData.type,
|
newAccountData.type,
|
||||||
jsonEncode(newAccountData.content),
|
jsonEncode(newAccountData.content),
|
||||||
);
|
);
|
||||||
|
|
@ -1243,7 +1241,7 @@ class Client extends MatrixApi {
|
||||||
if (_userDeviceKeys.containsKey(userId)) {
|
if (_userDeviceKeys.containsKey(userId)) {
|
||||||
_userDeviceKeys[userId].outdated = true;
|
_userDeviceKeys[userId].outdated = true;
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
await database.storeUserDeviceKeysInfo(id, userId, true);
|
await database.storeUserDeviceKeysInfo(userId, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1285,7 +1283,7 @@ class Client extends MatrixApi {
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
// TODO: This method seems to be rather slow for some updates
|
// TODO: This method seems to be rather slow for some updates
|
||||||
// Perhaps don't dynamically build that one query?
|
// Perhaps don't dynamically build that one query?
|
||||||
await database.storeRoomUpdate(this.id, id, room, getRoomById(id));
|
await database.storeRoomUpdate(id, room, getRoomById(id));
|
||||||
}
|
}
|
||||||
_updateRoomsByRoomUpdate(id, room);
|
_updateRoomsByRoomUpdate(id, room);
|
||||||
|
|
||||||
|
|
@ -1427,13 +1425,13 @@ class Client extends MatrixApi {
|
||||||
database != null &&
|
database != null &&
|
||||||
room.getState(EventTypes.RoomMember, event['sender']) == null) {
|
room.getState(EventTypes.RoomMember, event['sender']) == null) {
|
||||||
// In order to correctly render room list previews we need to fetch the member from the database
|
// In order to correctly render room list previews we need to fetch the member from the database
|
||||||
final user = await database.getUser(id, event['sender'], room);
|
final user = await database.getUser(event['sender'], room);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
room.setState(user);
|
room.setState(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type != EventUpdateType.ephemeral && database != null) {
|
if (type != EventUpdateType.ephemeral && database != null) {
|
||||||
await database.storeEventUpdate(id, update);
|
await database.storeEventUpdate(update);
|
||||||
}
|
}
|
||||||
_updateRoomsByEventUpdate(update);
|
_updateRoomsByEventUpdate(update);
|
||||||
if (encryptionEnabled) {
|
if (encryptionEnabled) {
|
||||||
|
|
@ -1708,7 +1706,7 @@ class Client extends MatrixApi {
|
||||||
// Check if deviceId or deviceKeys are known
|
// Check if deviceId or deviceKeys are known
|
||||||
if (!oldKeys.containsKey(deviceId)) {
|
if (!oldKeys.containsKey(deviceId)) {
|
||||||
final oldPublicKeys =
|
final oldPublicKeys =
|
||||||
await database.deviceIdSeen(id, userId, deviceId);
|
await database.deviceIdSeen(userId, deviceId);
|
||||||
if (oldPublicKeys != null &&
|
if (oldPublicKeys != null &&
|
||||||
oldPublicKeys != entry.curve25519Key + entry.ed25519Key) {
|
oldPublicKeys != entry.curve25519Key + entry.ed25519Key) {
|
||||||
Logs().w(
|
Logs().w(
|
||||||
|
|
@ -1716,25 +1714,24 @@ class Client extends MatrixApi {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final oldDeviceId =
|
final oldDeviceId =
|
||||||
await database.publicKeySeen(id, entry.ed25519Key);
|
await database.publicKeySeen(entry.ed25519Key);
|
||||||
if (oldDeviceId != null && oldDeviceId != deviceId) {
|
if (oldDeviceId != null && oldDeviceId != deviceId) {
|
||||||
Logs().w(
|
Logs().w(
|
||||||
'Already seen ED25519 has been added again. This might be an attack!');
|
'Already seen ED25519 has been added again. This might be an attack!');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final oldDeviceId2 =
|
final oldDeviceId2 =
|
||||||
await database.publicKeySeen(id, entry.curve25519Key);
|
await database.publicKeySeen(entry.curve25519Key);
|
||||||
if (oldDeviceId2 != null && oldDeviceId2 != deviceId) {
|
if (oldDeviceId2 != null && oldDeviceId2 != deviceId) {
|
||||||
Logs().w(
|
Logs().w(
|
||||||
'Already seen Curve25519 has been added again. This might be an attack!');
|
'Already seen Curve25519 has been added again. This might be an attack!');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await database.addSeenDeviceId(id, userId, deviceId,
|
await database.addSeenDeviceId(
|
||||||
entry.curve25519Key + entry.ed25519Key);
|
userId, deviceId, entry.curve25519Key + entry.ed25519Key);
|
||||||
|
await database.addSeenPublicKey(entry.ed25519Key, deviceId);
|
||||||
await database.addSeenPublicKey(
|
await database.addSeenPublicKey(
|
||||||
id, entry.ed25519Key, deviceId);
|
entry.curve25519Key, deviceId);
|
||||||
await database.addSeenPublicKey(
|
|
||||||
id, entry.curve25519Key, deviceId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// is this a new key or the same one as an old one?
|
// is this a new key or the same one as an old one?
|
||||||
|
|
@ -1756,7 +1753,6 @@ class Client extends MatrixApi {
|
||||||
entry.setDirectVerified(true);
|
entry.setDirectVerified(true);
|
||||||
}
|
}
|
||||||
dbActions.add(() => database.storeUserDeviceKey(
|
dbActions.add(() => database.storeUserDeviceKey(
|
||||||
id,
|
|
||||||
userId,
|
userId,
|
||||||
deviceId,
|
deviceId,
|
||||||
json.encode(entry.toJson()),
|
json.encode(entry.toJson()),
|
||||||
|
|
@ -1780,14 +1776,14 @@ class Client extends MatrixApi {
|
||||||
final deviceId = oldDeviceKeyEntry.key;
|
final deviceId = oldDeviceKeyEntry.key;
|
||||||
if (!_userDeviceKeys[userId].deviceKeys.containsKey(deviceId)) {
|
if (!_userDeviceKeys[userId].deviceKeys.containsKey(deviceId)) {
|
||||||
// we need to remove an old key
|
// we need to remove an old key
|
||||||
dbActions.add(
|
dbActions
|
||||||
() => database.removeUserDeviceKey(id, userId, deviceId));
|
.add(() => database.removeUserDeviceKey(userId, deviceId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_userDeviceKeys[userId].outdated = false;
|
_userDeviceKeys[userId].outdated = false;
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
dbActions.add(
|
dbActions
|
||||||
() => database.storeUserDeviceKeysInfo(id, userId, false));
|
.add(() => database.storeUserDeviceKeysInfo(userId, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1819,8 +1815,8 @@ class Client extends MatrixApi {
|
||||||
} else if (database != null) {
|
} else if (database != null) {
|
||||||
// There is a previous cross-signing key with this usage, that we no
|
// There is a previous cross-signing key with this usage, that we no
|
||||||
// longer need/use. Clear it from the database.
|
// longer need/use. Clear it from the database.
|
||||||
dbActions.add(() => database.removeUserCrossSigningKey(
|
dbActions.add(() =>
|
||||||
id, userId, oldEntry.key));
|
database.removeUserCrossSigningKey(userId, oldEntry.key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final entry = CrossSigningKey.fromMatrixCrossSigningKey(
|
final entry = CrossSigningKey.fromMatrixCrossSigningKey(
|
||||||
|
|
@ -1845,7 +1841,6 @@ class Client extends MatrixApi {
|
||||||
}
|
}
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
dbActions.add(() => database.storeUserCrossSigningKey(
|
dbActions.add(() => database.storeUserCrossSigningKey(
|
||||||
id,
|
|
||||||
userId,
|
userId,
|
||||||
publicKey,
|
publicKey,
|
||||||
json.encode(entry.toJson()),
|
json.encode(entry.toJson()),
|
||||||
|
|
@ -1856,8 +1851,8 @@ class Client extends MatrixApi {
|
||||||
}
|
}
|
||||||
_userDeviceKeys[userId].outdated = false;
|
_userDeviceKeys[userId].outdated = false;
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
dbActions.add(
|
dbActions
|
||||||
() => database.storeUserDeviceKeysInfo(id, userId, false));
|
.add(() => database.storeUserDeviceKeysInfo(userId, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1892,7 +1887,7 @@ class Client extends MatrixApi {
|
||||||
if (database == null || !_toDeviceQueueNeedsProcessing) {
|
if (database == null || !_toDeviceQueueNeedsProcessing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final entries = await database.getToDeviceEventQueue(id);
|
final entries = await database.getToDeviceEventQueue();
|
||||||
if (entries.isEmpty) {
|
if (entries.isEmpty) {
|
||||||
_toDeviceQueueNeedsProcessing = false;
|
_toDeviceQueueNeedsProcessing = false;
|
||||||
return;
|
return;
|
||||||
|
|
@ -1907,7 +1902,7 @@ class Client extends MatrixApi {
|
||||||
k, Map<String, dynamic>.from(v)))));
|
k, Map<String, dynamic>.from(v)))));
|
||||||
|
|
||||||
await super.sendToDevice(entry.type, entry.txnId, data);
|
await super.sendToDevice(entry.type, entry.txnId, data);
|
||||||
await database.deleteFromToDeviceQueue(id, entry.id);
|
await database.deleteFromToDeviceQueue(entry.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1931,7 +1926,7 @@ class Client extends MatrixApi {
|
||||||
if (database != null) {
|
if (database != null) {
|
||||||
_toDeviceQueueNeedsProcessing = true;
|
_toDeviceQueueNeedsProcessing = true;
|
||||||
await database.insertIntoToDeviceQueue(
|
await database.insertIntoToDeviceQueue(
|
||||||
id, eventType, txnId, json.encode(messages));
|
eventType, txnId, json.encode(messages));
|
||||||
}
|
}
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
@ -2140,7 +2135,7 @@ class Client extends MatrixApi {
|
||||||
await abortSync();
|
await abortSync();
|
||||||
prevBatch = null;
|
prevBatch = null;
|
||||||
rooms.clear();
|
rooms.clear();
|
||||||
await database?.clearCache(id);
|
await database?.clearCache();
|
||||||
encryption?.keyManager?.clearOutboundGroupSessions();
|
encryption?.keyManager?.clearOutboundGroupSessions();
|
||||||
onCacheCleared.add(true);
|
onCacheCleared.add(true);
|
||||||
// Restart the syncloop
|
// Restart the syncloop
|
||||||
|
|
@ -2246,11 +2241,10 @@ class Client extends MatrixApi {
|
||||||
);
|
);
|
||||||
Logs().d('Migrate SSSSCache...');
|
Logs().d('Migrate SSSSCache...');
|
||||||
for (final type in cacheTypes) {
|
for (final type in cacheTypes) {
|
||||||
final ssssCache = await legacyDatabase.getSSSSCache(_id, type);
|
final ssssCache = await legacyDatabase.getSSSSCache(type);
|
||||||
if (ssssCache != null) {
|
if (ssssCache != null) {
|
||||||
Logs().d('Migrate $type...');
|
Logs().d('Migrate $type...');
|
||||||
await database.storeSSSSCache(
|
await database.storeSSSSCache(
|
||||||
_id,
|
|
||||||
type,
|
type,
|
||||||
ssssCache.keyId,
|
ssssCache.keyId,
|
||||||
ssssCache.ciphertext,
|
ssssCache.ciphertext,
|
||||||
|
|
@ -2267,7 +2261,6 @@ class Client extends MatrixApi {
|
||||||
Logs().d(
|
Logs().d(
|
||||||
'Migrate cross signing key with usage ${crossSigningKey.usage} and verified ${crossSigningKey.directVerified}...');
|
'Migrate cross signing key with usage ${crossSigningKey.usage} and verified ${crossSigningKey.directVerified}...');
|
||||||
await database.storeUserCrossSigningKey(
|
await database.storeUserCrossSigningKey(
|
||||||
_id,
|
|
||||||
userId,
|
userId,
|
||||||
crossSigningKey.publicKey,
|
crossSigningKey.publicKey,
|
||||||
jsonEncode(crossSigningKey.toJson()),
|
jsonEncode(crossSigningKey.toJson()),
|
||||||
|
|
@ -2278,7 +2271,6 @@ class Client extends MatrixApi {
|
||||||
for (final deviceKeys in deviceKeysList.deviceKeys.values) {
|
for (final deviceKeys in deviceKeysList.deviceKeys.values) {
|
||||||
Logs().d('Migrate device keys for ${deviceKeys.deviceId}...');
|
Logs().d('Migrate device keys for ${deviceKeys.deviceId}...');
|
||||||
await database.storeUserDeviceKey(
|
await database.storeUserDeviceKey(
|
||||||
_id,
|
|
||||||
userId,
|
userId,
|
||||||
deviceKeys.deviceId,
|
deviceKeys.deviceId,
|
||||||
jsonEncode(deviceKeys.toJson()),
|
jsonEncode(deviceKeys.toJson()),
|
||||||
|
|
@ -2288,17 +2280,15 @@ class Client extends MatrixApi {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Logs().d('Migrate user device keys info...');
|
Logs().d('Migrate user device keys info...');
|
||||||
await database.storeUserDeviceKeysInfo(
|
await database.storeUserDeviceKeysInfo(userId, deviceKeysList.outdated);
|
||||||
_id, userId, deviceKeysList.outdated);
|
|
||||||
}
|
}
|
||||||
Logs().d('Migrate inbound group sessions...');
|
Logs().d('Migrate inbound group sessions...');
|
||||||
try {
|
try {
|
||||||
final sessions = await legacyDatabase.getAllInboundGroupSessions(_id);
|
final sessions = await legacyDatabase.getAllInboundGroupSessions();
|
||||||
for (var i = 0; i < sessions.length; i++) {
|
for (var i = 0; i < sessions.length; i++) {
|
||||||
Logs().d('$i / ${sessions.length}');
|
Logs().d('$i / ${sessions.length}');
|
||||||
final session = sessions[i];
|
final session = sessions[i];
|
||||||
await database.storeInboundGroupSession(
|
await database.storeInboundGroupSession(
|
||||||
_id,
|
|
||||||
session.roomId,
|
session.roomId,
|
||||||
session.sessionId,
|
session.sessionId,
|
||||||
session.pickle,
|
session.pickle,
|
||||||
|
|
@ -2313,7 +2303,7 @@ class Client extends MatrixApi {
|
||||||
Logs().e('Unable to migrate inbound group sessions!', e, s);
|
Logs().e('Unable to migrate inbound group sessions!', e, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
await legacyDatabase.clear(_id);
|
await legacyDatabase.clear();
|
||||||
await legacyDatabaseDestroyer?.call(this);
|
await legacyDatabaseDestroyer?.call(this);
|
||||||
}
|
}
|
||||||
await legacyDatabase.close();
|
await legacyDatabase.close();
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ abstract class DatabaseApi {
|
||||||
String deviceName,
|
String deviceName,
|
||||||
String prevBatch,
|
String prevBatch,
|
||||||
String olmAccount,
|
String olmAccount,
|
||||||
int clientId,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Future insertClient(
|
Future insertClient(
|
||||||
|
|
@ -55,34 +54,32 @@ abstract class DatabaseApi {
|
||||||
|
|
||||||
Future<List<Room>> getRoomList(Client client);
|
Future<List<Room>> getRoomList(Client client);
|
||||||
|
|
||||||
Future<Map<String, BasicEvent>> getAccountData(int clientId);
|
Future<Map<String, BasicEvent>> getAccountData();
|
||||||
|
|
||||||
/// Stores a RoomUpdate object in the database. Must be called inside of
|
/// Stores a RoomUpdate object in the database. Must be called inside of
|
||||||
/// [transaction].
|
/// [transaction].
|
||||||
Future<void> storeRoomUpdate(
|
Future<void> storeRoomUpdate(String roomId, SyncRoomUpdate roomUpdate,
|
||||||
int clientId, String roomId, SyncRoomUpdate roomUpdate,
|
|
||||||
[Room oldRoom]);
|
[Room oldRoom]);
|
||||||
|
|
||||||
/// Stores an EventUpdate object in the database. Must be called inside of
|
/// Stores an EventUpdate object in the database. Must be called inside of
|
||||||
/// [transaction].
|
/// [transaction].
|
||||||
Future<void> storeEventUpdate(int clientId, EventUpdate eventUpdate);
|
Future<void> storeEventUpdate(EventUpdate eventUpdate);
|
||||||
|
|
||||||
Future<Event?> getEventById(int clientId, String eventId, Room room);
|
Future<Event?> getEventById(String eventId, Room room);
|
||||||
|
|
||||||
bool eventIsKnown(int clientId, String eventId, String roomId);
|
bool eventIsKnown(String eventId, String roomId);
|
||||||
|
|
||||||
Future<void> forgetRoom(int clientId, String roomId);
|
Future<void> forgetRoom(String roomId);
|
||||||
|
|
||||||
Future<void> clearCache(int clientId);
|
Future<void> clearCache();
|
||||||
|
|
||||||
Future<void> clear(int clientId);
|
Future<void> clear();
|
||||||
|
|
||||||
Future<User?> getUser(int clientId, String userId, Room room);
|
Future<User?> getUser(String userId, Room room);
|
||||||
|
|
||||||
Future<List<User>> getUsers(int clientId, Room room);
|
Future<List<User>> getUsers(Room room);
|
||||||
|
|
||||||
Future<List<Event>> getEventList(
|
Future<List<Event>> getEventList(
|
||||||
int clientId,
|
|
||||||
Room room, {
|
Room room, {
|
||||||
int start = 0,
|
int start = 0,
|
||||||
int limit,
|
int limit,
|
||||||
|
|
@ -92,39 +89,35 @@ abstract class DatabaseApi {
|
||||||
|
|
||||||
Future storeFile(Uri mxcUri, Uint8List bytes, int time);
|
Future storeFile(Uri mxcUri, Uint8List bytes, int time);
|
||||||
|
|
||||||
Future storeSyncFilterId(String syncFilterId, int clientId);
|
Future storeSyncFilterId(
|
||||||
|
String syncFilterId,
|
||||||
|
);
|
||||||
|
|
||||||
Future storeAccountData(int clientId, String type, String content);
|
Future storeAccountData(String type, String content);
|
||||||
|
|
||||||
Future<Map<String, DeviceKeysList>> getUserDeviceKeys(Client client);
|
Future<Map<String, DeviceKeysList>> getUserDeviceKeys(Client client);
|
||||||
|
|
||||||
Future<SSSSCache?> getSSSSCache(int clientId, String type);
|
Future<SSSSCache?> getSSSSCache(String type);
|
||||||
|
|
||||||
Future<OutboundGroupSession?> getOutboundGroupSession(
|
Future<OutboundGroupSession?> getOutboundGroupSession(
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String userId,
|
String userId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<List<StoredInboundGroupSession>> getAllInboundGroupSessions(
|
Future<List<StoredInboundGroupSession>> getAllInboundGroupSessions();
|
||||||
int clientId,
|
|
||||||
);
|
|
||||||
|
|
||||||
Future<StoredInboundGroupSession?> getInboundGroupSession(
|
Future<StoredInboundGroupSession?> getInboundGroupSession(
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future updateInboundGroupSessionIndexes(
|
Future updateInboundGroupSessionIndexes(
|
||||||
String indexes,
|
String indexes,
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future storeInboundGroupSession(
|
Future storeInboundGroupSession(
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
String pickle,
|
String pickle,
|
||||||
|
|
@ -136,22 +129,19 @@ abstract class DatabaseApi {
|
||||||
);
|
);
|
||||||
|
|
||||||
Future markInboundGroupSessionAsUploaded(
|
Future markInboundGroupSessionAsUploaded(
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future updateInboundGroupSessionAllowedAtIndex(
|
Future updateInboundGroupSessionAllowedAtIndex(
|
||||||
String allowedAtIndex,
|
String allowedAtIndex,
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future removeOutboundGroupSession(int clientId, String roomId);
|
Future removeOutboundGroupSession(String roomId);
|
||||||
|
|
||||||
Future storeOutboundGroupSession(
|
Future storeOutboundGroupSession(
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String pickle,
|
String pickle,
|
||||||
String deviceIds,
|
String deviceIds,
|
||||||
|
|
@ -159,10 +149,11 @@ abstract class DatabaseApi {
|
||||||
int sentMessages,
|
int sentMessages,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future updateClientKeys(String olmAccount, int clientId);
|
Future updateClientKeys(
|
||||||
|
String olmAccount,
|
||||||
|
);
|
||||||
|
|
||||||
Future storeOlmSession(
|
Future storeOlmSession(
|
||||||
int clientId,
|
|
||||||
String identitiyKey,
|
String identitiyKey,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
String pickle,
|
String pickle,
|
||||||
|
|
@ -171,42 +162,39 @@ abstract class DatabaseApi {
|
||||||
|
|
||||||
Future setLastActiveUserDeviceKey(
|
Future setLastActiveUserDeviceKey(
|
||||||
int lastActive,
|
int lastActive,
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future setLastSentMessageUserDeviceKey(
|
Future setLastSentMessageUserDeviceKey(
|
||||||
String lastSentMessage,
|
String lastSentMessage,
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future clearSSSSCache(int clientId);
|
Future clearSSSSCache();
|
||||||
|
|
||||||
Future storeSSSSCache(
|
Future storeSSSSCache(
|
||||||
int clientId,
|
|
||||||
String type,
|
String type,
|
||||||
String keyId,
|
String keyId,
|
||||||
String ciphertext,
|
String ciphertext,
|
||||||
String content,
|
String content,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future markInboundGroupSessionsAsNeedingUpload(int clientId);
|
Future markInboundGroupSessionsAsNeedingUpload();
|
||||||
|
|
||||||
Future storePrevBatch(String prevBatch, int clientId);
|
Future storePrevBatch(
|
||||||
|
String prevBatch,
|
||||||
|
);
|
||||||
|
|
||||||
Future deleteOldFiles(int savedAt);
|
Future deleteOldFiles(int savedAt);
|
||||||
|
|
||||||
Future storeUserDeviceKeysInfo(
|
Future storeUserDeviceKeysInfo(
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
bool outdated,
|
bool outdated,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future storeUserDeviceKey(
|
Future storeUserDeviceKey(
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
String content,
|
String content,
|
||||||
|
|
@ -216,19 +204,16 @@ abstract class DatabaseApi {
|
||||||
);
|
);
|
||||||
|
|
||||||
Future removeUserDeviceKey(
|
Future removeUserDeviceKey(
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future removeUserCrossSigningKey(
|
Future removeUserCrossSigningKey(
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String publicKey,
|
String publicKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future storeUserCrossSigningKey(
|
Future storeUserCrossSigningKey(
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String publicKey,
|
String publicKey,
|
||||||
String content,
|
String content,
|
||||||
|
|
@ -236,84 +221,73 @@ abstract class DatabaseApi {
|
||||||
bool blocked,
|
bool blocked,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future deleteFromToDeviceQueue(int clientId, int id);
|
Future deleteFromToDeviceQueue(int id);
|
||||||
|
|
||||||
Future removeEvent(int clientId, String eventId, String roomId);
|
Future removeEvent(String eventId, String roomId);
|
||||||
|
|
||||||
Future updateRoomSortOrder(
|
Future updateRoomSortOrder(
|
||||||
double oldestSortOrder,
|
double oldestSortOrder,
|
||||||
double newestSortOrder,
|
double newestSortOrder,
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future setRoomPrevBatch(
|
Future setRoomPrevBatch(
|
||||||
String prevBatch,
|
String prevBatch,
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future resetNotificationCount(int clientId, String roomId);
|
Future resetNotificationCount(String roomId);
|
||||||
|
|
||||||
Future setVerifiedUserCrossSigningKey(
|
Future setVerifiedUserCrossSigningKey(
|
||||||
bool verified,
|
bool verified,
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String publicKey,
|
String publicKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future setBlockedUserCrossSigningKey(
|
Future setBlockedUserCrossSigningKey(
|
||||||
bool blocked,
|
bool blocked,
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String publicKey,
|
String publicKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future setVerifiedUserDeviceKey(
|
Future setVerifiedUserDeviceKey(
|
||||||
bool verified,
|
bool verified,
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future setBlockedUserDeviceKey(
|
Future setBlockedUserDeviceKey(
|
||||||
bool blocked,
|
bool blocked,
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<List<Event>> getUnimportantRoomEventStatesForRoom(
|
Future<List<Event>> getUnimportantRoomEventStatesForRoom(
|
||||||
int clientId,
|
|
||||||
List<String> events,
|
List<String> events,
|
||||||
Room room,
|
Room room,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<List<OlmSession>> getOlmSessions(
|
Future<List<OlmSession>> getOlmSessions(
|
||||||
int clientId,
|
|
||||||
String identityKey,
|
String identityKey,
|
||||||
String userId,
|
String userId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<List<OlmSession>> getOlmSessionsForDevices(
|
Future<List<OlmSession>> getOlmSessionsForDevices(
|
||||||
int clientId,
|
|
||||||
List<String> identityKeys,
|
List<String> identityKeys,
|
||||||
String userId,
|
String userId,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<List<QueuedToDeviceEvent>> getToDeviceEventQueue(int clientId);
|
Future<List<QueuedToDeviceEvent>> getToDeviceEventQueue();
|
||||||
|
|
||||||
/// Please do `jsonEncode(content)` in your code to stay compatible with
|
/// Please do `jsonEncode(content)` in your code to stay compatible with
|
||||||
/// auto generated methods here.
|
/// auto generated methods here.
|
||||||
Future insertIntoToDeviceQueue(
|
Future insertIntoToDeviceQueue(
|
||||||
int clientId,
|
|
||||||
String type,
|
String type,
|
||||||
String txnId,
|
String txnId,
|
||||||
String content,
|
String content,
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<List<String>> getLastSentMessageUserDeviceKey(
|
Future<List<String>> getLastSentMessageUserDeviceKey(
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
);
|
);
|
||||||
|
|
@ -321,14 +295,13 @@ abstract class DatabaseApi {
|
||||||
Future<List<StoredInboundGroupSession>> getInboundGroupSessionsToUpload();
|
Future<List<StoredInboundGroupSession>> getInboundGroupSessionsToUpload();
|
||||||
|
|
||||||
Future<void> addSeenDeviceId(
|
Future<void> addSeenDeviceId(
|
||||||
int clientId, String userId, String deviceId, String publicKeys);
|
String userId, String deviceId, String publicKeys);
|
||||||
|
|
||||||
Future<void> addSeenPublicKey(
|
Future<void> addSeenPublicKey(String publicKey, String deviceId);
|
||||||
int clientId, String publicKey, String deviceId);
|
|
||||||
|
|
||||||
Future<String?> deviceIdSeen(int clientId, userId, deviceId);
|
Future<String?> deviceIdSeen(userId, deviceId);
|
||||||
|
|
||||||
Future<String?> publicKeySeen(int clientId, String publicKey);
|
Future<String?> publicKeySeen(String publicKey);
|
||||||
|
|
||||||
Future<dynamic> close();
|
Future<dynamic> close();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -231,22 +231,21 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
convertToJson(raw),
|
convertToJson(raw),
|
||||||
Client(''),
|
Client(''),
|
||||||
);
|
);
|
||||||
await addSeenDeviceId(0, deviceKeys.userId, deviceKeys.deviceId,
|
await addSeenDeviceId(deviceKeys.userId, deviceKeys.deviceId,
|
||||||
deviceKeys.curve25519Key + deviceKeys.ed25519Key);
|
deviceKeys.curve25519Key + deviceKeys.ed25519Key);
|
||||||
await addSeenPublicKey(0, deviceKeys.ed25519Key, deviceKeys.deviceId);
|
await addSeenPublicKey(deviceKeys.ed25519Key, deviceKeys.deviceId);
|
||||||
await addSeenPublicKey(
|
await addSeenPublicKey(deviceKeys.curve25519Key, deviceKeys.deviceId);
|
||||||
0, deviceKeys.curve25519Key, deviceKeys.deviceId);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logs().w('Can not migrate device $key', e);
|
Logs().w('Can not migrate device $key', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await clearCache(0);
|
await clearCache();
|
||||||
await _clientBox.put('version', version);
|
await _clientBox.put('version', version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> clear(int clientId) async {
|
Future<void> clear() async {
|
||||||
Logs().i('Clear and close hive database...');
|
Logs().i('Clear and close hive database...');
|
||||||
await _actionOnAllBoxes((box) async {
|
await _actionOnAllBoxes((box) async {
|
||||||
try {
|
try {
|
||||||
|
|
@ -261,7 +260,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> clearCache(int clientId) async {
|
Future<void> clearCache() async {
|
||||||
await _roomsBox.deleteAll(_roomsBox.keys);
|
await _roomsBox.deleteAll(_roomsBox.keys);
|
||||||
await _accountDataBox.deleteAll(_accountDataBox.keys);
|
await _accountDataBox.deleteAll(_accountDataBox.keys);
|
||||||
await _roomStateBox.deleteAll(_roomStateBox.keys);
|
await _roomStateBox.deleteAll(_roomStateBox.keys);
|
||||||
|
|
@ -274,7 +273,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> clearSSSSCache(int clientId) async {
|
Future<void> clearSSSSCache() async {
|
||||||
await _ssssCacheBox.deleteAll(_ssssCacheBox.keys);
|
await _ssssCacheBox.deleteAll(_ssssCacheBox.keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,7 +281,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
Future<void> close() => _actionOnAllBoxes((box) => box.close());
|
Future<void> close() => _actionOnAllBoxes((box) => box.close());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> deleteFromToDeviceQueue(int clientId, int id) async {
|
Future<void> deleteFromToDeviceQueue(int id) async {
|
||||||
await _toDeviceQueueBox.delete(id);
|
await _toDeviceQueueBox.delete(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -293,7 +292,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> forgetRoom(int clientId, String roomId) async {
|
Future<void> forgetRoom(String roomId) async {
|
||||||
await _timelineFragmentsBox.delete(MultiKey(roomId, '').toString());
|
await _timelineFragmentsBox.delete(MultiKey(roomId, '').toString());
|
||||||
for (final key in _eventsBox.keys) {
|
for (final key in _eventsBox.keys) {
|
||||||
final multiKey = MultiKey.fromString(key);
|
final multiKey = MultiKey.fromString(key);
|
||||||
|
|
@ -319,7 +318,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Map<String, BasicEvent>> getAccountData(int clientId) async {
|
Future<Map<String, BasicEvent>> getAccountData() async {
|
||||||
final accountData = <String, BasicEvent>{};
|
final accountData = <String, BasicEvent>{};
|
||||||
for (final key in _accountDataBox.keys) {
|
for (final key in _accountDataBox.keys) {
|
||||||
final raw = await _accountDataBox.get(key);
|
final raw = await _accountDataBox.get(key);
|
||||||
|
|
@ -343,14 +342,14 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Event?> getEventById(int clientId, String eventId, Room room) async {
|
Future<Event?> getEventById(String eventId, Room room) async {
|
||||||
final raw = await _eventsBox.get(MultiKey(room.id, eventId).toString());
|
final raw = await _eventsBox.get(MultiKey(room.id, eventId).toString());
|
||||||
if (raw == null) return null;
|
if (raw == null) return null;
|
||||||
return Event.fromJson(convertToJson(raw), room);
|
return Event.fromJson(convertToJson(raw), room);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool eventIsKnown(int clientId, String eventId, String roomId) =>
|
bool eventIsKnown(String eventId, String roomId) =>
|
||||||
_eventsBox.keys.contains(MultiKey(roomId, eventId).toString());
|
_eventsBox.keys.contains(MultiKey(roomId, eventId).toString());
|
||||||
|
|
||||||
/// Loads a whole list of events at once from the store for a specific room
|
/// Loads a whole list of events at once from the store for a specific room
|
||||||
|
|
@ -368,7 +367,6 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Event>> getEventList(
|
Future<List<Event>> getEventList(
|
||||||
int clientId,
|
|
||||||
Room room, {
|
Room room, {
|
||||||
int start = 0,
|
int start = 0,
|
||||||
int? limit,
|
int? limit,
|
||||||
|
|
@ -404,7 +402,6 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<StoredInboundGroupSession?> getInboundGroupSession(
|
Future<StoredInboundGroupSession?> getInboundGroupSession(
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
) async {
|
) async {
|
||||||
|
|
@ -432,7 +429,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<String>> getLastSentMessageUserDeviceKey(
|
Future<List<String>> getLastSentMessageUserDeviceKey(
|
||||||
int clientId, String userId, String deviceId) async {
|
String userId, String deviceId) async {
|
||||||
final raw =
|
final raw =
|
||||||
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
||||||
if (raw == null) return <String>[];
|
if (raw == null) return <String>[];
|
||||||
|
|
@ -440,8 +437,8 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeOlmSession(int clientId, String identityKey,
|
Future<void> storeOlmSession(String identityKey, String sessionId,
|
||||||
String sessionId, String pickle, int lastReceived) async {
|
String pickle, int lastReceived) async {
|
||||||
final rawSessions =
|
final rawSessions =
|
||||||
(await _olmSessionsBox.get(identityKey.toHiveKey) as Map?) ?? {};
|
(await _olmSessionsBox.get(identityKey.toHiveKey) as Map?) ?? {};
|
||||||
rawSessions[sessionId] = <String, dynamic>{
|
rawSessions[sessionId] = <String, dynamic>{
|
||||||
|
|
@ -456,7 +453,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<OlmSession>> getOlmSessions(
|
Future<List<OlmSession>> getOlmSessions(
|
||||||
int clientId, String identityKey, String userId) async {
|
String identityKey, String userId) async {
|
||||||
final rawSessions =
|
final rawSessions =
|
||||||
await _olmSessionsBox.get(identityKey.toHiveKey) as Map?;
|
await _olmSessionsBox.get(identityKey.toHiveKey) as Map?;
|
||||||
if (rawSessions == null || rawSessions.isEmpty) return <OlmSession>[];
|
if (rawSessions == null || rawSessions.isEmpty) return <OlmSession>[];
|
||||||
|
|
@ -467,15 +464,15 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<OlmSession>> getOlmSessionsForDevices(
|
Future<List<OlmSession>> getOlmSessionsForDevices(
|
||||||
int clientId, List<String> identityKey, String userId) async {
|
List<String> identityKey, String userId) async {
|
||||||
final sessions = await Future.wait(identityKey
|
final sessions = await Future.wait(
|
||||||
.map((identityKey) => getOlmSessions(clientId, identityKey, userId)));
|
identityKey.map((identityKey) => getOlmSessions(identityKey, userId)));
|
||||||
return <OlmSession>[for (final sublist in sessions) ...sublist];
|
return <OlmSession>[for (final sublist in sessions) ...sublist];
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<OutboundGroupSession?> getOutboundGroupSession(
|
Future<OutboundGroupSession?> getOutboundGroupSession(
|
||||||
int clientId, String roomId, String userId) async {
|
String roomId, String userId) async {
|
||||||
final raw = await _outboundGroupSessionsBox.get(roomId.toHiveKey);
|
final raw = await _outboundGroupSessionsBox.get(roomId.toHiveKey);
|
||||||
if (raw == null) return null;
|
if (raw == null) return null;
|
||||||
return OutboundGroupSession.fromJson(convertToJson(raw), userId);
|
return OutboundGroupSession.fromJson(convertToJson(raw), userId);
|
||||||
|
|
@ -555,14 +552,14 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<SSSSCache?> getSSSSCache(int clientId, String type) async {
|
Future<SSSSCache?> getSSSSCache(String type) async {
|
||||||
final raw = await _ssssCacheBox.get(type);
|
final raw = await _ssssCacheBox.get(type);
|
||||||
if (raw == null) return null;
|
if (raw == null) return null;
|
||||||
return SSSSCache.fromJson(convertToJson(raw));
|
return SSSSCache.fromJson(convertToJson(raw));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<QueuedToDeviceEvent>> getToDeviceEventQueue(int clientId) async =>
|
Future<List<QueuedToDeviceEvent>> getToDeviceEventQueue() async =>
|
||||||
await Future.wait(_toDeviceQueueBox.keys.map((i) async {
|
await Future.wait(_toDeviceQueueBox.keys.map((i) async {
|
||||||
final raw = await _toDeviceQueueBox.get(i);
|
final raw = await _toDeviceQueueBox.get(i);
|
||||||
raw['id'] = i;
|
raw['id'] = i;
|
||||||
|
|
@ -571,7 +568,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Event>> getUnimportantRoomEventStatesForRoom(
|
Future<List<Event>> getUnimportantRoomEventStatesForRoom(
|
||||||
int clientId, List<String> events, Room room) async {
|
List<String> events, Room room) async {
|
||||||
final keys = _roomStateBox.keys.where((key) {
|
final keys = _roomStateBox.keys.where((key) {
|
||||||
final tuple = MultiKey.fromString(key);
|
final tuple = MultiKey.fromString(key);
|
||||||
return tuple.parts.first == room.id && !events.contains(tuple.parts[1]);
|
return tuple.parts.first == room.id && !events.contains(tuple.parts[1]);
|
||||||
|
|
@ -587,7 +584,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<User?> getUser(int clientId, String userId, Room room) async {
|
Future<User?> getUser(String userId, Room room) async {
|
||||||
final state =
|
final state =
|
||||||
await _roomMembersBox.get(MultiKey(room.id, userId).toString());
|
await _roomMembersBox.get(MultiKey(room.id, userId).toString());
|
||||||
if (state == null) return null;
|
if (state == null) return null;
|
||||||
|
|
@ -627,7 +624,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<User>> getUsers(int clientId, Room room) async {
|
Future<List<User>> getUsers(Room room) async {
|
||||||
final users = <User>[];
|
final users = <User>[];
|
||||||
for (final key in _roomMembersBox.keys) {
|
for (final key in _roomMembersBox.keys) {
|
||||||
final statesKey = MultiKey.fromString(key);
|
final statesKey = MultiKey.fromString(key);
|
||||||
|
|
@ -661,7 +658,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<int> insertIntoToDeviceQueue(
|
Future<int> insertIntoToDeviceQueue(
|
||||||
int clientId, String type, String txnId, String content) async {
|
String type, String txnId, String content) async {
|
||||||
return await _toDeviceQueueBox.add(<String, dynamic>{
|
return await _toDeviceQueueBox.add(<String, dynamic>{
|
||||||
'type': type,
|
'type': type,
|
||||||
'txn_id': txnId,
|
'txn_id': txnId,
|
||||||
|
|
@ -671,7 +668,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> markInboundGroupSessionAsUploaded(
|
Future<void> markInboundGroupSessionAsUploaded(
|
||||||
int clientId, String roomId, String sessionId) async {
|
String roomId, String sessionId) async {
|
||||||
final raw = await _inboundGroupSessionsBox.get(sessionId.toHiveKey);
|
final raw = await _inboundGroupSessionsBox.get(sessionId.toHiveKey);
|
||||||
if (raw == null) {
|
if (raw == null) {
|
||||||
Logs().w(
|
Logs().w(
|
||||||
|
|
@ -684,7 +681,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> markInboundGroupSessionsAsNeedingUpload(int clientId) async {
|
Future<void> markInboundGroupSessionsAsNeedingUpload() async {
|
||||||
for (final sessionId in _inboundGroupSessionsBox.keys) {
|
for (final sessionId in _inboundGroupSessionsBox.keys) {
|
||||||
final raw = await _inboundGroupSessionsBox.get(sessionId);
|
final raw = await _inboundGroupSessionsBox.get(sessionId);
|
||||||
raw['uploaded'] = false;
|
raw['uploaded'] = false;
|
||||||
|
|
@ -694,7 +691,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> removeEvent(int clientId, String eventId, String roomId) async {
|
Future<void> removeEvent(String eventId, String roomId) async {
|
||||||
await _eventsBox.delete(MultiKey(roomId, eventId).toString());
|
await _eventsBox.delete(MultiKey(roomId, eventId).toString());
|
||||||
for (final key in _timelineFragmentsBox.keys) {
|
for (final key in _timelineFragmentsBox.keys) {
|
||||||
final multiKey = MultiKey.fromString(key);
|
final multiKey = MultiKey.fromString(key);
|
||||||
|
|
@ -710,28 +707,27 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> removeOutboundGroupSession(int clientId, String roomId) async {
|
Future<void> removeOutboundGroupSession(String roomId) async {
|
||||||
await _outboundGroupSessionsBox.delete(roomId.toHiveKey);
|
await _outboundGroupSessionsBox.delete(roomId.toHiveKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> removeUserCrossSigningKey(
|
Future<void> removeUserCrossSigningKey(
|
||||||
int clientId, String userId, String publicKey) async {
|
String userId, String publicKey) async {
|
||||||
await _userCrossSigningKeysBox
|
await _userCrossSigningKeysBox
|
||||||
.delete(MultiKey(userId, publicKey).toString());
|
.delete(MultiKey(userId, publicKey).toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> removeUserDeviceKey(
|
Future<void> removeUserDeviceKey(String userId, String deviceId) async {
|
||||||
int clientId, String userId, String deviceId) async {
|
|
||||||
await _userDeviceKeysBox.delete(MultiKey(userId, deviceId).toString());
|
await _userDeviceKeysBox.delete(MultiKey(userId, deviceId).toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> resetNotificationCount(int clientId, String roomId) async {
|
Future<void> resetNotificationCount(String roomId) async {
|
||||||
final raw = await _roomsBox.get(roomId.toHiveKey);
|
final raw = await _roomsBox.get(roomId.toHiveKey);
|
||||||
if (raw == null) return;
|
if (raw == null) return;
|
||||||
raw['notification_count'] = raw['highlight_count'] = 0;
|
raw['notification_count'] = raw['highlight_count'] = 0;
|
||||||
|
|
@ -741,7 +737,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setBlockedUserCrossSigningKey(
|
Future<void> setBlockedUserCrossSigningKey(
|
||||||
bool blocked, int clientId, String userId, String publicKey) async {
|
bool blocked, String userId, String publicKey) async {
|
||||||
final raw = await _userCrossSigningKeysBox
|
final raw = await _userCrossSigningKeysBox
|
||||||
.get(MultiKey(userId, publicKey).toString());
|
.get(MultiKey(userId, publicKey).toString());
|
||||||
raw['blocked'] = blocked;
|
raw['blocked'] = blocked;
|
||||||
|
|
@ -754,7 +750,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setBlockedUserDeviceKey(
|
Future<void> setBlockedUserDeviceKey(
|
||||||
bool blocked, int clientId, String userId, String deviceId) async {
|
bool blocked, String userId, String deviceId) async {
|
||||||
final raw =
|
final raw =
|
||||||
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
||||||
raw['blocked'] = blocked;
|
raw['blocked'] = blocked;
|
||||||
|
|
@ -767,7 +763,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setLastActiveUserDeviceKey(
|
Future<void> setLastActiveUserDeviceKey(
|
||||||
int lastActive, int clientId, String userId, String deviceId) async {
|
int lastActive, String userId, String deviceId) async {
|
||||||
final raw =
|
final raw =
|
||||||
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
||||||
raw['last_active'] = lastActive;
|
raw['last_active'] = lastActive;
|
||||||
|
|
@ -778,8 +774,8 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setLastSentMessageUserDeviceKey(String lastSentMessage,
|
Future<void> setLastSentMessageUserDeviceKey(
|
||||||
int clientId, String userId, String deviceId) async {
|
String lastSentMessage, String userId, String deviceId) async {
|
||||||
final raw =
|
final raw =
|
||||||
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
||||||
raw['last_sent_message'] = lastSentMessage;
|
raw['last_sent_message'] = lastSentMessage;
|
||||||
|
|
@ -790,8 +786,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setRoomPrevBatch(
|
Future<void> setRoomPrevBatch(String prevBatch, String roomId) async {
|
||||||
String prevBatch, int clientId, String roomId) async {
|
|
||||||
final raw = await _roomsBox.get(roomId.toHiveKey);
|
final raw = await _roomsBox.get(roomId.toHiveKey);
|
||||||
if (raw == null) return;
|
if (raw == null) return;
|
||||||
final room = Room.fromJson(convertToJson(raw));
|
final room = Room.fromJson(convertToJson(raw));
|
||||||
|
|
@ -802,7 +797,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setVerifiedUserCrossSigningKey(
|
Future<void> setVerifiedUserCrossSigningKey(
|
||||||
bool verified, int clientId, String userId, String publicKey) async {
|
bool verified, String userId, String publicKey) async {
|
||||||
final raw = (await _userCrossSigningKeysBox
|
final raw = (await _userCrossSigningKeysBox
|
||||||
.get(MultiKey(userId, publicKey).toString()) as Map?) ??
|
.get(MultiKey(userId, publicKey).toString()) as Map?) ??
|
||||||
{};
|
{};
|
||||||
|
|
@ -816,7 +811,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setVerifiedUserDeviceKey(
|
Future<void> setVerifiedUserDeviceKey(
|
||||||
bool verified, int clientId, String userId, String deviceId) async {
|
bool verified, String userId, String deviceId) async {
|
||||||
final raw =
|
final raw =
|
||||||
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
await _userDeviceKeysBox.get(MultiKey(userId, deviceId).toString());
|
||||||
raw['verified'] = verified;
|
raw['verified'] = verified;
|
||||||
|
|
@ -828,23 +823,21 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeAccountData(
|
Future<void> storeAccountData(String type, String content) async {
|
||||||
int clientId, String type, String content) async {
|
|
||||||
await _accountDataBox.put(
|
await _accountDataBox.put(
|
||||||
type.toHiveKey, convertToJson(jsonDecode(content)));
|
type.toHiveKey, convertToJson(jsonDecode(content)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeEventUpdate(int clientId, EventUpdate eventUpdate) async {
|
Future<void> storeEventUpdate(EventUpdate eventUpdate) async {
|
||||||
// Ephemerals should not be stored
|
// Ephemerals should not be stored
|
||||||
if (eventUpdate.type == EventUpdateType.ephemeral) return;
|
if (eventUpdate.type == EventUpdateType.ephemeral) return;
|
||||||
|
|
||||||
// In case of this is a redaction event
|
// In case of this is a redaction event
|
||||||
if (eventUpdate.content['type'] == EventTypes.Redaction) {
|
if (eventUpdate.content['type'] == EventTypes.Redaction) {
|
||||||
final tmpRoom = Room(id: eventUpdate.roomID);
|
final tmpRoom = Room(id: eventUpdate.roomID);
|
||||||
final event =
|
final event = await getEventById(eventUpdate.content['redacts'], tmpRoom);
|
||||||
await getEventById(clientId, eventUpdate.content['redacts'], tmpRoom);
|
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom));
|
event.setRedactionEvent(Event.fromJson(eventUpdate.content, tmpRoom));
|
||||||
await _eventsBox.put(
|
await _eventsBox.put(
|
||||||
|
|
@ -922,7 +915,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
// Is there a transaction id? Then delete the event with this id.
|
// Is there a transaction id? Then delete the event with this id.
|
||||||
if (status != -1 && status != 0 && transactionId != null) {
|
if (status != -1 && status != 0 && transactionId != null) {
|
||||||
await removeEvent(clientId, transactionId, eventUpdate.roomID);
|
await removeEvent(transactionId, eventUpdate.roomID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -991,7 +984,6 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeInboundGroupSession(
|
Future<void> storeInboundGroupSession(
|
||||||
int clientId,
|
|
||||||
String roomId,
|
String roomId,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
String pickle,
|
String pickle,
|
||||||
|
|
@ -1003,7 +995,6 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
await _inboundGroupSessionsBox.put(
|
await _inboundGroupSessionsBox.put(
|
||||||
sessionId.toHiveKey,
|
sessionId.toHiveKey,
|
||||||
StoredInboundGroupSession(
|
StoredInboundGroupSession(
|
||||||
clientId: clientId,
|
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
sessionId: sessionId,
|
sessionId: sessionId,
|
||||||
pickle: pickle,
|
pickle: pickle,
|
||||||
|
|
@ -1018,13 +1009,8 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeOutboundGroupSession(
|
Future<void> storeOutboundGroupSession(String roomId, String pickle,
|
||||||
int clientId,
|
String deviceIds, int creationTime, int sentMessages) async {
|
||||||
String roomId,
|
|
||||||
String pickle,
|
|
||||||
String deviceIds,
|
|
||||||
int creationTime,
|
|
||||||
int sentMessages) async {
|
|
||||||
await _outboundGroupSessionsBox.put(roomId.toHiveKey, <String, dynamic>{
|
await _outboundGroupSessionsBox.put(roomId.toHiveKey, <String, dynamic>{
|
||||||
'room_id': roomId,
|
'room_id': roomId,
|
||||||
'pickle': pickle,
|
'pickle': pickle,
|
||||||
|
|
@ -1036,19 +1022,20 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storePrevBatch(String prevBatch, int clientId) async {
|
Future<void> storePrevBatch(
|
||||||
|
String prevBatch,
|
||||||
|
) async {
|
||||||
if (_clientBox.keys.isEmpty) return;
|
if (_clientBox.keys.isEmpty) return;
|
||||||
await _clientBox.put('prev_batch', prevBatch);
|
await _clientBox.put('prev_batch', prevBatch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeRoomUpdate(
|
Future<void> storeRoomUpdate(String roomId, SyncRoomUpdate roomUpdate,
|
||||||
int clientId, String roomId, SyncRoomUpdate roomUpdate,
|
|
||||||
[dynamic _]) async {
|
[dynamic _]) async {
|
||||||
// Leave room if membership is leave
|
// Leave room if membership is leave
|
||||||
if (roomUpdate is LeftRoomUpdate) {
|
if (roomUpdate is LeftRoomUpdate) {
|
||||||
await forgetRoom(clientId, roomId);
|
await forgetRoom(roomId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final membership = roomUpdate is LeftRoomUpdate
|
final membership = roomUpdate is LeftRoomUpdate
|
||||||
|
|
@ -1106,8 +1093,8 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeSSSSCache(int clientId, String type, String keyId,
|
Future<void> storeSSSSCache(
|
||||||
String ciphertext, String content) async {
|
String type, String keyId, String ciphertext, String content) async {
|
||||||
await _ssssCacheBox.put(
|
await _ssssCacheBox.put(
|
||||||
type,
|
type,
|
||||||
SSSSCache(
|
SSSSCache(
|
||||||
|
|
@ -1119,13 +1106,15 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeSyncFilterId(String syncFilterId, int clientId) async {
|
Future<void> storeSyncFilterId(
|
||||||
|
String syncFilterId,
|
||||||
|
) async {
|
||||||
await _clientBox.put('sync_filter_id', syncFilterId);
|
await _clientBox.put('sync_filter_id', syncFilterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeUserCrossSigningKey(int clientId, String userId,
|
Future<void> storeUserCrossSigningKey(String userId, String publicKey,
|
||||||
String publicKey, String content, bool verified, bool blocked) async {
|
String content, bool verified, bool blocked) async {
|
||||||
await _userCrossSigningKeysBox.put(
|
await _userCrossSigningKeysBox.put(
|
||||||
MultiKey(userId, publicKey).toString(),
|
MultiKey(userId, publicKey).toString(),
|
||||||
{
|
{
|
||||||
|
|
@ -1139,7 +1128,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeUserDeviceKey(int clientId, String userId, String deviceId,
|
Future<void> storeUserDeviceKey(String userId, String deviceId,
|
||||||
String content, bool verified, bool blocked, int lastActive) async {
|
String content, bool verified, bool blocked, int lastActive) async {
|
||||||
await _userDeviceKeysBox.put(MultiKey(userId, deviceId).toString(), {
|
await _userDeviceKeysBox.put(MultiKey(userId, deviceId).toString(), {
|
||||||
'user_id': userId,
|
'user_id': userId,
|
||||||
|
|
@ -1154,8 +1143,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> storeUserDeviceKeysInfo(
|
Future<void> storeUserDeviceKeysInfo(String userId, bool outdated) async {
|
||||||
int clientId, String userId, bool outdated) async {
|
|
||||||
await _userDeviceKeysOutdatedBox.put(userId.toHiveKey, outdated);
|
await _userDeviceKeysOutdatedBox.put(userId.toHiveKey, outdated);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1214,14 +1202,14 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateClient(
|
Future<void> updateClient(
|
||||||
String homeserverUrl,
|
String homeserverUrl,
|
||||||
String token,
|
String token,
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
String deviceName,
|
String deviceName,
|
||||||
String prevBatch,
|
String prevBatch,
|
||||||
String olmAccount,
|
String olmAccount,
|
||||||
int clientId) async {
|
) async {
|
||||||
await _clientBox.put('homeserver_url', homeserverUrl);
|
await _clientBox.put('homeserver_url', homeserverUrl);
|
||||||
await _clientBox.put('token', token);
|
await _clientBox.put('token', token);
|
||||||
await _clientBox.put('user_id', userId);
|
await _clientBox.put('user_id', userId);
|
||||||
|
|
@ -1233,14 +1221,16 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateClientKeys(String olmAccount, int clientId) async {
|
Future<void> updateClientKeys(
|
||||||
|
String olmAccount,
|
||||||
|
) async {
|
||||||
await _clientBox.put('olm_account', olmAccount);
|
await _clientBox.put('olm_account', olmAccount);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateInboundGroupSessionAllowedAtIndex(String allowedAtIndex,
|
Future<void> updateInboundGroupSessionAllowedAtIndex(
|
||||||
int clientId, String roomId, String sessionId) async {
|
String allowedAtIndex, String roomId, String sessionId) async {
|
||||||
final raw = await _inboundGroupSessionsBox.get(sessionId.toHiveKey);
|
final raw = await _inboundGroupSessionsBox.get(sessionId.toHiveKey);
|
||||||
if (raw == null) {
|
if (raw == null) {
|
||||||
Logs().w(
|
Logs().w(
|
||||||
|
|
@ -1254,7 +1244,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateInboundGroupSessionIndexes(
|
Future<void> updateInboundGroupSessionIndexes(
|
||||||
String indexes, int clientId, String roomId, String sessionId) async {
|
String indexes, String roomId, String sessionId) async {
|
||||||
final raw = await _inboundGroupSessionsBox.get(sessionId.toHiveKey);
|
final raw = await _inboundGroupSessionsBox.get(sessionId.toHiveKey);
|
||||||
if (raw == null) {
|
if (raw == null) {
|
||||||
Logs().w(
|
Logs().w(
|
||||||
|
|
@ -1267,8 +1257,8 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateRoomSortOrder(double oldestSortOrder,
|
Future<void> updateRoomSortOrder(
|
||||||
double newestSortOrder, int clientId, String roomId) async {
|
double oldestSortOrder, double newestSortOrder, String roomId) async {
|
||||||
final raw = await _roomsBox.get(roomId.toHiveKey);
|
final raw = await _roomsBox.get(roomId.toHiveKey);
|
||||||
raw['oldest_sort_order'] = oldestSortOrder;
|
raw['oldest_sort_order'] = oldestSortOrder;
|
||||||
raw['newest_sort_order'] = newestSortOrder;
|
raw['newest_sort_order'] = newestSortOrder;
|
||||||
|
|
@ -1277,8 +1267,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<StoredInboundGroupSession>> getAllInboundGroupSessions(
|
Future<List<StoredInboundGroupSession>> getAllInboundGroupSessions() async {
|
||||||
int clientId) async {
|
|
||||||
final rawSessions = await Future.wait(_inboundGroupSessionsBox.keys
|
final rawSessions = await Future.wait(_inboundGroupSessionsBox.keys
|
||||||
.map((key) => _inboundGroupSessionsBox.get(key)));
|
.map((key) => _inboundGroupSessionsBox.get(key)));
|
||||||
return rawSessions
|
return rawSessions
|
||||||
|
|
@ -1288,7 +1277,6 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> addSeenDeviceId(
|
Future<void> addSeenDeviceId(
|
||||||
int clientId,
|
|
||||||
String userId,
|
String userId,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
String publicKeysHash,
|
String publicKeysHash,
|
||||||
|
|
@ -1298,14 +1286,13 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> addSeenPublicKey(
|
Future<void> addSeenPublicKey(
|
||||||
int clientId,
|
|
||||||
String publicKey,
|
String publicKey,
|
||||||
String deviceId,
|
String deviceId,
|
||||||
) =>
|
) =>
|
||||||
_seenDeviceKeysBox.put(publicKey.toHiveKey, deviceId);
|
_seenDeviceKeysBox.put(publicKey.toHiveKey, deviceId);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> deviceIdSeen(int clientId, userId, deviceId) async {
|
Future<String?> deviceIdSeen(userId, deviceId) async {
|
||||||
final raw =
|
final raw =
|
||||||
await _seenDeviceIdsBox.get(MultiKey(userId, deviceId).toString());
|
await _seenDeviceIdsBox.get(MultiKey(userId, deviceId).toString());
|
||||||
if (raw == null) return null;
|
if (raw == null) return null;
|
||||||
|
|
@ -1313,7 +1300,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> publicKeySeen(int clientId, String publicKey) async {
|
Future<String?> publicKeySeen(String publicKey) async {
|
||||||
final raw = await _seenDeviceKeysBox.get(publicKey.toHiveKey);
|
final raw = await _seenDeviceKeysBox.get(publicKey.toHiveKey);
|
||||||
if (raw == null) return null;
|
if (raw == null) return null;
|
||||||
return raw as String;
|
return raw as String;
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,7 @@ class Event extends MatrixEvent {
|
||||||
/// from the database and the timelines. Returns false if not removed.
|
/// from the database and the timelines. Returns false if not removed.
|
||||||
Future<bool> remove() async {
|
Future<bool> remove() async {
|
||||||
if (status < 1) {
|
if (status < 1) {
|
||||||
await room.client.database?.removeEvent(room.client.id, eventId, room.id);
|
await room.client.database?.removeEvent(eventId, room.id);
|
||||||
|
|
||||||
room.client.onEvent.add(EventUpdate(
|
room.client.onEvent.add(EventUpdate(
|
||||||
roomID: room.id,
|
roomID: room.id,
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ class Room {
|
||||||
}
|
}
|
||||||
final allStates = await client.database
|
final allStates = await client.database
|
||||||
.getUnimportantRoomEventStatesForRoom(
|
.getUnimportantRoomEventStatesForRoom(
|
||||||
client.id, client.importantStateEvents.toList(), this);
|
client.importantStateEvents.toList(), this);
|
||||||
|
|
||||||
for (final state in allStates) {
|
for (final state in allStates) {
|
||||||
setState(state);
|
setState(state);
|
||||||
|
|
@ -342,7 +342,7 @@ class Room {
|
||||||
if (prevEvent != null &&
|
if (prevEvent != null &&
|
||||||
prevEvent.eventId != state.eventId &&
|
prevEvent.eventId != state.eventId &&
|
||||||
client.database != null &&
|
client.database != null &&
|
||||||
client.database.eventIsKnown(client.id, state.eventId, state.roomId)) {
|
client.database.eventIsKnown(state.eventId, state.roomId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1053,7 +1053,7 @@ class Room {
|
||||||
|
|
||||||
/// Call the Matrix API to forget this room if you already left it.
|
/// Call the Matrix API to forget this room if you already left it.
|
||||||
Future<void> forget() async {
|
Future<void> forget() async {
|
||||||
await client.database?.forgetRoom(client.id, id);
|
await client.database?.forgetRoom(id);
|
||||||
await client.forgetRoom(id);
|
await client.forgetRoom(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1135,7 +1135,7 @@ class Room {
|
||||||
|
|
||||||
if (client.database != null) {
|
if (client.database != null) {
|
||||||
await client.database.transaction(() async {
|
await client.database.transaction(() async {
|
||||||
await client.database.setRoomPrevBatch(resp.end, client.id, id);
|
await client.database.setRoomPrevBatch(resp.end, id);
|
||||||
await loadFn();
|
await loadFn();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1188,7 +1188,7 @@ class Room {
|
||||||
Future<void> setReadMarker(String eventId, {String mRead}) async {
|
Future<void> setReadMarker(String eventId, {String mRead}) async {
|
||||||
if (mRead != null) {
|
if (mRead != null) {
|
||||||
notificationCount = 0;
|
notificationCount = 0;
|
||||||
await client.database?.resetNotificationCount(client.id, id);
|
await client.database?.resetNotificationCount(id);
|
||||||
}
|
}
|
||||||
await client.setReadMarker(
|
await client.setReadMarker(
|
||||||
id,
|
id,
|
||||||
|
|
@ -1202,7 +1202,7 @@ class Room {
|
||||||
/// specified.
|
/// specified.
|
||||||
Future<void> postReceipt(String eventId) async {
|
Future<void> postReceipt(String eventId) async {
|
||||||
notificationCount = 0;
|
notificationCount = 0;
|
||||||
await client.database?.resetNotificationCount(client.id, id);
|
await client.database?.resetNotificationCount(id);
|
||||||
await client.postReceipt(
|
await client.postReceipt(
|
||||||
id,
|
id,
|
||||||
ReceiptType.mRead,
|
ReceiptType.mRead,
|
||||||
|
|
@ -1216,7 +1216,7 @@ class Room {
|
||||||
@Deprecated('Use sendReadMarker instead')
|
@Deprecated('Use sendReadMarker instead')
|
||||||
Future<void> sendReadReceipt(String eventID) async {
|
Future<void> sendReadReceipt(String eventID) async {
|
||||||
notificationCount = 0;
|
notificationCount = 0;
|
||||||
await client.database?.resetNotificationCount(client.id, id);
|
await client.database?.resetNotificationCount(id);
|
||||||
await client.setReadMarker(
|
await client.setReadMarker(
|
||||||
id,
|
id,
|
||||||
eventID,
|
eventID,
|
||||||
|
|
@ -1232,7 +1232,6 @@ class Room {
|
||||||
var events;
|
var events;
|
||||||
if (client.database != null) {
|
if (client.database != null) {
|
||||||
events = await client.database.getEventList(
|
events = await client.database.getEventList(
|
||||||
client.id,
|
|
||||||
this,
|
this,
|
||||||
limit: defaultHistoryCount,
|
limit: defaultHistoryCount,
|
||||||
);
|
);
|
||||||
|
|
@ -1286,7 +1285,7 @@ class Room {
|
||||||
Future<List<User>> requestParticipants() async {
|
Future<List<User>> requestParticipants() async {
|
||||||
if (!participantListComplete && partial && client.database != null) {
|
if (!participantListComplete && partial && client.database != null) {
|
||||||
// we aren't fully loaded, maybe the users are in the database
|
// we aren't fully loaded, maybe the users are in the database
|
||||||
final users = await client.database.getUsers(client.id, this);
|
final users = await client.database.getUsers(this);
|
||||||
for (final user in users) {
|
for (final user in users) {
|
||||||
setState(user);
|
setState(user);
|
||||||
}
|
}
|
||||||
|
|
@ -1362,7 +1361,7 @@ class Room {
|
||||||
}
|
}
|
||||||
if (client.database != null) {
|
if (client.database != null) {
|
||||||
// it may be in the database
|
// it may be in the database
|
||||||
final user = await client.database.getUser(client.id, mxID, this);
|
final user = await client.database.getUser(mxID, this);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
setState(user);
|
setState(user);
|
||||||
onUpdate.add(id);
|
onUpdate.add(id);
|
||||||
|
|
@ -1419,7 +1418,6 @@ class Room {
|
||||||
'state_key': mxID,
|
'state_key': mxID,
|
||||||
};
|
};
|
||||||
await client.database.storeEventUpdate(
|
await client.database.storeEventUpdate(
|
||||||
client.id,
|
|
||||||
EventUpdate(
|
EventUpdate(
|
||||||
content: content,
|
content: content,
|
||||||
roomID: id,
|
roomID: id,
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,6 @@ class Timeline {
|
||||||
try {
|
try {
|
||||||
// Look up for events in hive first
|
// Look up for events in hive first
|
||||||
final eventsFromStore = await room.client.database?.getEventList(
|
final eventsFromStore = await room.client.database?.getEventList(
|
||||||
room.client.id,
|
|
||||||
room,
|
room,
|
||||||
start: events.length,
|
start: events.length,
|
||||||
limit: Room.defaultHistoryCount,
|
limit: Room.defaultHistoryCount,
|
||||||
|
|
|
||||||
|
|
@ -358,15 +358,15 @@ class CrossSigningKey extends SignableKey {
|
||||||
@override
|
@override
|
||||||
Future<void> setVerified(bool newVerified, [bool sign = true]) async {
|
Future<void> setVerified(bool newVerified, [bool sign = true]) async {
|
||||||
await super.setVerified(newVerified, sign);
|
await super.setVerified(newVerified, sign);
|
||||||
return client.database?.setVerifiedUserCrossSigningKey(
|
return client.database
|
||||||
newVerified, client.id, userId, publicKey);
|
?.setVerifiedUserCrossSigningKey(newVerified, userId, publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setBlocked(bool newBlocked) {
|
Future<void> setBlocked(bool newBlocked) {
|
||||||
blocked = newBlocked;
|
blocked = newBlocked;
|
||||||
return client.database?.setBlockedUserCrossSigningKey(
|
return client.database
|
||||||
newBlocked, client.id, userId, publicKey);
|
?.setBlockedUserCrossSigningKey(newBlocked, userId, publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
CrossSigningKey.fromMatrixCrossSigningKey(MatrixCrossSigningKey k, Client cl)
|
CrossSigningKey.fromMatrixCrossSigningKey(MatrixCrossSigningKey k, Client cl)
|
||||||
|
|
@ -433,14 +433,14 @@ class DeviceKeys extends SignableKey {
|
||||||
Future<void> setVerified(bool newVerified, [bool sign = true]) async {
|
Future<void> setVerified(bool newVerified, [bool sign = true]) async {
|
||||||
await super.setVerified(newVerified, sign);
|
await super.setVerified(newVerified, sign);
|
||||||
return client?.database
|
return client?.database
|
||||||
?.setVerifiedUserDeviceKey(newVerified, client.id, userId, deviceId);
|
?.setVerifiedUserDeviceKey(newVerified, userId, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> setBlocked(bool newBlocked) {
|
Future<void> setBlocked(bool newBlocked) {
|
||||||
blocked = newBlocked;
|
blocked = newBlocked;
|
||||||
return client?.database
|
return client?.database
|
||||||
?.setBlockedUserDeviceKey(newBlocked, client.id, userId, deviceId);
|
?.setBlockedUserDeviceKey(newBlocked, userId, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceKeys.fromMatrixDeviceKeys(MatrixDeviceKeys k, Client cl,
|
DeviceKeys.fromMatrixDeviceKeys(MatrixDeviceKeys k, Client cl,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@ import 'fake_database.dart';
|
||||||
void main() {
|
void main() {
|
||||||
/// All Tests related to the ChatTime
|
/// All Tests related to the ChatTime
|
||||||
group('Hive Database Test', () {
|
group('Hive Database Test', () {
|
||||||
testDatabase(getHiveDatabase(null), 0);
|
testDatabase(
|
||||||
|
getHiveDatabase(null),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +46,9 @@ Future<bool> olmEnabled() async {
|
||||||
return olmEnabled;
|
return olmEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
void testDatabase(
|
||||||
|
Future<DatabaseApi> futureDatabase,
|
||||||
|
) {
|
||||||
DatabaseApi database;
|
DatabaseApi database;
|
||||||
int toDeviceQueueIndex;
|
int toDeviceQueueIndex;
|
||||||
test('Open', () async {
|
test('Open', () async {
|
||||||
|
|
@ -76,19 +80,18 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('insertIntoToDeviceQueue', () async {
|
test('insertIntoToDeviceQueue', () async {
|
||||||
toDeviceQueueIndex = await database.insertIntoToDeviceQueue(
|
toDeviceQueueIndex = await database.insertIntoToDeviceQueue(
|
||||||
clientId,
|
|
||||||
'm.test',
|
'm.test',
|
||||||
'txnId',
|
'txnId',
|
||||||
'{"foo":"bar"}',
|
'{"foo":"bar"}',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('getToDeviceEventQueue', () async {
|
test('getToDeviceEventQueue', () async {
|
||||||
final toDeviceQueue = await database.getToDeviceEventQueue(clientId);
|
final toDeviceQueue = await database.getToDeviceEventQueue();
|
||||||
expect(toDeviceQueue.first.type, 'm.test');
|
expect(toDeviceQueue.first.type, 'm.test');
|
||||||
});
|
});
|
||||||
test('deleteFromToDeviceQueue', () async {
|
test('deleteFromToDeviceQueue', () async {
|
||||||
await database.deleteFromToDeviceQueue(clientId, toDeviceQueueIndex);
|
await database.deleteFromToDeviceQueue(toDeviceQueueIndex);
|
||||||
final toDeviceQueue = await database.getToDeviceEventQueue(clientId);
|
final toDeviceQueue = await database.getToDeviceEventQueue();
|
||||||
expect(toDeviceQueue.isEmpty, true);
|
expect(toDeviceQueue.isEmpty, true);
|
||||||
});
|
});
|
||||||
test('storeFile', () async {
|
test('storeFile', () async {
|
||||||
|
|
@ -112,7 +115,7 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
'limited_timeline': false,
|
'limited_timeline': false,
|
||||||
'membership': Membership.join,
|
'membership': Membership.join,
|
||||||
});
|
});
|
||||||
await database.storeRoomUpdate(clientId, '!testroom', roomUpdate);
|
await database.storeRoomUpdate('!testroom', roomUpdate);
|
||||||
final rooms = await database.getRoomList(Client('testclient'));
|
final rooms = await database.getRoomList(Client('testclient'));
|
||||||
expect(rooms.single.id, '!testroom');
|
expect(rooms.single.id, '!testroom');
|
||||||
});
|
});
|
||||||
|
|
@ -121,12 +124,12 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
expect(list.single.id, '!testroom');
|
expect(list.single.id, '!testroom');
|
||||||
});
|
});
|
||||||
test('setRoomPrevBatch', () async {
|
test('setRoomPrevBatch', () async {
|
||||||
await database.setRoomPrevBatch('1234', clientId, '!testroom');
|
await database.setRoomPrevBatch('1234', '!testroom');
|
||||||
final rooms = await database.getRoomList(Client('testclient'));
|
final rooms = await database.getRoomList(Client('testclient'));
|
||||||
expect(rooms.single.prev_batch, '1234');
|
expect(rooms.single.prev_batch, '1234');
|
||||||
});
|
});
|
||||||
test('forgetRoom', () async {
|
test('forgetRoom', () async {
|
||||||
await database.forgetRoom(clientId, '!testroom');
|
await database.forgetRoom('!testroom');
|
||||||
final rooms = await database.getRoomList(Client('testclient'));
|
final rooms = await database.getRoomList(Client('testclient'));
|
||||||
expect(rooms.isEmpty, true);
|
expect(rooms.isEmpty, true);
|
||||||
});
|
});
|
||||||
|
|
@ -134,7 +137,7 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
await database.getClient('name');
|
await database.getClient('name');
|
||||||
});
|
});
|
||||||
test('insertClient', () async {
|
test('insertClient', () async {
|
||||||
clientId = await database.insertClient(
|
await database.insertClient(
|
||||||
'name',
|
'name',
|
||||||
'homeserverUrl',
|
'homeserverUrl',
|
||||||
'token',
|
'token',
|
||||||
|
|
@ -144,6 +147,7 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
'prevBatch',
|
'prevBatch',
|
||||||
'olmAccount',
|
'olmAccount',
|
||||||
);
|
);
|
||||||
|
|
||||||
final client = await database.getClient('name');
|
final client = await database.getClient('name');
|
||||||
expect(client['token'], 'token');
|
expect(client['token'], 'token');
|
||||||
});
|
});
|
||||||
|
|
@ -156,36 +160,38 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
'deviceName',
|
'deviceName',
|
||||||
'prevBatch',
|
'prevBatch',
|
||||||
'olmAccount',
|
'olmAccount',
|
||||||
clientId,
|
|
||||||
);
|
);
|
||||||
final client = await database.getClient('name');
|
final client = await database.getClient('name');
|
||||||
expect(client['token'], 'token_different');
|
expect(client['token'], 'token_different');
|
||||||
});
|
});
|
||||||
test('updateClientKeys', () async {
|
test('updateClientKeys', () async {
|
||||||
await database.updateClientKeys('olmAccount2', clientId);
|
await database.updateClientKeys(
|
||||||
|
'olmAccount2',
|
||||||
|
);
|
||||||
final client = await database.getClient('name');
|
final client = await database.getClient('name');
|
||||||
expect(client['olm_account'], 'olmAccount2');
|
expect(client['olm_account'], 'olmAccount2');
|
||||||
});
|
});
|
||||||
test('storeSyncFilterId', () async {
|
test('storeSyncFilterId', () async {
|
||||||
await database.storeSyncFilterId('1234', clientId);
|
await database.storeSyncFilterId(
|
||||||
|
'1234',
|
||||||
|
);
|
||||||
final client = await database.getClient('name');
|
final client = await database.getClient('name');
|
||||||
expect(client['sync_filter_id'], '1234');
|
expect(client['sync_filter_id'], '1234');
|
||||||
});
|
});
|
||||||
test('getAccountData', () async {
|
test('getAccountData', () async {
|
||||||
await database.getAccountData(clientId);
|
await database.getAccountData();
|
||||||
});
|
});
|
||||||
test('storeAccountData', () async {
|
test('storeAccountData', () async {
|
||||||
await database.storeAccountData(clientId, 'm.test', '{"foo":"bar"}');
|
await database.storeAccountData('m.test', '{"foo":"bar"}');
|
||||||
final events = await database.getAccountData(clientId);
|
final events = await database.getAccountData();
|
||||||
expect(events.values.single.type, 'm.test');
|
expect(events.values.single.type, 'm.test');
|
||||||
|
|
||||||
await database.storeAccountData(clientId, 'm.abc+de', '{"foo":"bar"}');
|
await database.storeAccountData('m.abc+de', '{"foo":"bar"}');
|
||||||
final events2 = await database.getAccountData(clientId);
|
final events2 = await database.getAccountData();
|
||||||
expect(events2.values.any((element) => element.type == 'm.abc+de'), true);
|
expect(events2.values.any((element) => element.type == 'm.abc+de'), true);
|
||||||
});
|
});
|
||||||
test('storeEventUpdate', () async {
|
test('storeEventUpdate', () async {
|
||||||
await database.storeEventUpdate(
|
await database.storeEventUpdate(
|
||||||
clientId,
|
|
||||||
EventUpdate(
|
EventUpdate(
|
||||||
roomID: '!testroom:example.com',
|
roomID: '!testroom:example.com',
|
||||||
type: EventUpdateType.timeline,
|
type: EventUpdateType.timeline,
|
||||||
|
|
@ -211,45 +217,41 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('getEventById', () async {
|
test('getEventById', () async {
|
||||||
final event = await database.getEventById(
|
final event = await database.getEventById(
|
||||||
clientId, '\$event:example.com', Room(id: '!testroom:example.com'));
|
'\$event:example.com', Room(id: '!testroom:example.com'));
|
||||||
expect(event.type, EventTypes.Message);
|
expect(event.type, EventTypes.Message);
|
||||||
});
|
});
|
||||||
test('getEventList', () async {
|
test('getEventList', () async {
|
||||||
final events = await database.getEventList(
|
final events =
|
||||||
clientId, Room(id: '!testroom:example.com'));
|
await database.getEventList(Room(id: '!testroom:example.com'));
|
||||||
expect(events.single.type, EventTypes.Message);
|
expect(events.single.type, EventTypes.Message);
|
||||||
});
|
});
|
||||||
test('getUser', () async {
|
test('getUser', () async {
|
||||||
final user = await database.getUser(
|
final user = await database.getUser(
|
||||||
clientId, '@bob:example.org', Room(id: '!testroom:example.com'));
|
'@bob:example.org', Room(id: '!testroom:example.com'));
|
||||||
expect(user, null);
|
expect(user, null);
|
||||||
});
|
});
|
||||||
test('getUsers', () async {
|
test('getUsers', () async {
|
||||||
final users =
|
final users = await database.getUsers(Room(id: '!testroom:example.com'));
|
||||||
await database.getUsers(clientId, Room(id: '!testroom:example.com'));
|
|
||||||
expect(users.isEmpty, true);
|
expect(users.isEmpty, true);
|
||||||
});
|
});
|
||||||
test('removeEvent', () async {
|
test('removeEvent', () async {
|
||||||
await database.removeEvent(
|
await database.removeEvent('\$event:example.com', '!testroom:example.com');
|
||||||
clientId, '\$event:example.com', '!testroom:example.com');
|
|
||||||
final event = await database.getEventById(
|
final event = await database.getEventById(
|
||||||
clientId, '\$event:example.com', Room(id: '!testroom:example.com'));
|
'\$event:example.com', Room(id: '!testroom:example.com'));
|
||||||
expect(event, null);
|
expect(event, null);
|
||||||
});
|
});
|
||||||
test('getAllInboundGroupSessions', () async {
|
test('getAllInboundGroupSessions', () async {
|
||||||
final result = await database.getAllInboundGroupSessions(clientId);
|
final result = await database.getAllInboundGroupSessions();
|
||||||
expect(result.isEmpty, true);
|
expect(result.isEmpty, true);
|
||||||
});
|
});
|
||||||
test('getInboundGroupSession', () async {
|
test('getInboundGroupSession', () async {
|
||||||
await database.getInboundGroupSession(
|
await database.getInboundGroupSession('!testroom:example.com', 'sessionId');
|
||||||
clientId, '!testroom:example.com', 'sessionId');
|
|
||||||
});
|
});
|
||||||
test('getInboundGroupSessionsToUpload', () async {
|
test('getInboundGroupSessionsToUpload', () async {
|
||||||
await database.getInboundGroupSessionsToUpload();
|
await database.getInboundGroupSessionsToUpload();
|
||||||
});
|
});
|
||||||
test('storeInboundGroupSession', () async {
|
test('storeInboundGroupSession', () async {
|
||||||
await database.storeInboundGroupSession(
|
await database.storeInboundGroupSession(
|
||||||
clientId,
|
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'sessionId',
|
'sessionId',
|
||||||
'pickle',
|
'pickle',
|
||||||
|
|
@ -260,7 +262,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
'{}',
|
'{}',
|
||||||
);
|
);
|
||||||
final session = await database.getInboundGroupSession(
|
final session = await database.getInboundGroupSession(
|
||||||
clientId,
|
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'sessionId',
|
'sessionId',
|
||||||
);
|
);
|
||||||
|
|
@ -268,15 +269,14 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('markInboundGroupSessionAsUploaded', () async {
|
test('markInboundGroupSessionAsUploaded', () async {
|
||||||
await database.markInboundGroupSessionAsUploaded(
|
await database.markInboundGroupSessionAsUploaded(
|
||||||
clientId, '!testroom:example.com', 'sessionId');
|
'!testroom:example.com', 'sessionId');
|
||||||
});
|
});
|
||||||
test('markInboundGroupSessionsAsNeedingUpload', () async {
|
test('markInboundGroupSessionsAsNeedingUpload', () async {
|
||||||
await database.markInboundGroupSessionsAsNeedingUpload(clientId);
|
await database.markInboundGroupSessionsAsNeedingUpload();
|
||||||
});
|
});
|
||||||
test('updateInboundGroupSessionAllowedAtIndex', () async {
|
test('updateInboundGroupSessionAllowedAtIndex', () async {
|
||||||
await database.updateInboundGroupSessionAllowedAtIndex(
|
await database.updateInboundGroupSessionAllowedAtIndex(
|
||||||
'{}',
|
'{}',
|
||||||
clientId,
|
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'sessionId',
|
'sessionId',
|
||||||
);
|
);
|
||||||
|
|
@ -284,19 +284,17 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
test('updateInboundGroupSessionIndexes', () async {
|
test('updateInboundGroupSessionIndexes', () async {
|
||||||
await database.updateInboundGroupSessionIndexes(
|
await database.updateInboundGroupSessionIndexes(
|
||||||
'{}',
|
'{}',
|
||||||
clientId,
|
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'sessionId',
|
'sessionId',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('getSSSSCache', () async {
|
test('getSSSSCache', () async {
|
||||||
final cache = await database.getSSSSCache(clientId, 'type');
|
final cache = await database.getSSSSCache('type');
|
||||||
expect(cache, null);
|
expect(cache, null);
|
||||||
});
|
});
|
||||||
test('storeSSSSCache', () async {
|
test('storeSSSSCache', () async {
|
||||||
await database.storeSSSSCache(
|
await database.storeSSSSCache('type', 'keyId', 'ciphertext', '{}');
|
||||||
clientId, 'type', 'keyId', 'ciphertext', '{}');
|
final cache = await database.getSSSSCache('type');
|
||||||
final cache = await database.getSSSSCache(clientId, 'type');
|
|
||||||
expect(cache.type, 'type');
|
expect(cache.type, 'type');
|
||||||
expect(cache.keyId, 'keyId');
|
expect(cache.keyId, 'keyId');
|
||||||
expect(cache.ciphertext, 'ciphertext');
|
expect(cache.ciphertext, 'ciphertext');
|
||||||
|
|
@ -304,7 +302,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('getOlmSessions', () async {
|
test('getOlmSessions', () async {
|
||||||
final olm = await database.getOlmSessions(
|
final olm = await database.getOlmSessions(
|
||||||
clientId,
|
|
||||||
'identityKey',
|
'identityKey',
|
||||||
'userId',
|
'userId',
|
||||||
);
|
);
|
||||||
|
|
@ -312,7 +309,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('getOlmSessionsForDevices', () async {
|
test('getOlmSessionsForDevices', () async {
|
||||||
final olm = await database.getOlmSessionsForDevices(
|
final olm = await database.getOlmSessionsForDevices(
|
||||||
clientId,
|
|
||||||
['identityKeys'],
|
['identityKeys'],
|
||||||
'userId',
|
'userId',
|
||||||
);
|
);
|
||||||
|
|
@ -321,14 +317,12 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
test('storeOlmSession', () async {
|
test('storeOlmSession', () async {
|
||||||
if (!(await olmEnabled())) return;
|
if (!(await olmEnabled())) return;
|
||||||
await database.storeOlmSession(
|
await database.storeOlmSession(
|
||||||
clientId,
|
|
||||||
'identityKey',
|
'identityKey',
|
||||||
'sessionId',
|
'sessionId',
|
||||||
'pickle',
|
'pickle',
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
final olm = await database.getOlmSessions(
|
final olm = await database.getOlmSessions(
|
||||||
clientId,
|
|
||||||
'identityKey',
|
'identityKey',
|
||||||
'userId',
|
'userId',
|
||||||
);
|
);
|
||||||
|
|
@ -336,7 +330,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('getOutboundGroupSession', () async {
|
test('getOutboundGroupSession', () async {
|
||||||
final session = await database.getOutboundGroupSession(
|
final session = await database.getOutboundGroupSession(
|
||||||
clientId,
|
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
);
|
);
|
||||||
|
|
@ -345,7 +338,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
test('storeOutboundGroupSession', () async {
|
test('storeOutboundGroupSession', () async {
|
||||||
if (!(await olmEnabled())) return;
|
if (!(await olmEnabled())) return;
|
||||||
await database.storeOutboundGroupSession(
|
await database.storeOutboundGroupSession(
|
||||||
clientId,
|
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'pickle',
|
'pickle',
|
||||||
'{}',
|
'{}',
|
||||||
|
|
@ -353,7 +345,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
final session = await database.getOutboundGroupSession(
|
final session = await database.getOutboundGroupSession(
|
||||||
clientId,
|
|
||||||
'!testroom:example.com',
|
'!testroom:example.com',
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
);
|
);
|
||||||
|
|
@ -361,7 +352,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('getLastSentMessageUserDeviceKey', () async {
|
test('getLastSentMessageUserDeviceKey', () async {
|
||||||
final list = await database.getLastSentMessageUserDeviceKey(
|
final list = await database.getLastSentMessageUserDeviceKey(
|
||||||
clientId,
|
|
||||||
'userId',
|
'userId',
|
||||||
'deviceId',
|
'deviceId',
|
||||||
);
|
);
|
||||||
|
|
@ -369,7 +359,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('getUnimportantRoomEventStatesForRoom', () async {
|
test('getUnimportantRoomEventStatesForRoom', () async {
|
||||||
final events = await database.getUnimportantRoomEventStatesForRoom(
|
final events = await database.getUnimportantRoomEventStatesForRoom(
|
||||||
clientId,
|
|
||||||
['events'],
|
['events'],
|
||||||
Room(id: '!mep'),
|
Room(id: '!mep'),
|
||||||
);
|
);
|
||||||
|
|
@ -380,7 +369,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
});
|
});
|
||||||
test('storeUserCrossSigningKey', () async {
|
test('storeUserCrossSigningKey', () async {
|
||||||
await database.storeUserCrossSigningKey(
|
await database.storeUserCrossSigningKey(
|
||||||
clientId,
|
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
'publicKey',
|
'publicKey',
|
||||||
'{}',
|
'{}',
|
||||||
|
|
@ -391,7 +379,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
test('setVerifiedUserCrossSigningKey', () async {
|
test('setVerifiedUserCrossSigningKey', () async {
|
||||||
await database.setVerifiedUserCrossSigningKey(
|
await database.setVerifiedUserCrossSigningKey(
|
||||||
true,
|
true,
|
||||||
clientId,
|
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
'publicKey',
|
'publicKey',
|
||||||
);
|
);
|
||||||
|
|
@ -399,28 +386,24 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
test('setBlockedUserCrossSigningKey', () async {
|
test('setBlockedUserCrossSigningKey', () async {
|
||||||
await database.setBlockedUserCrossSigningKey(
|
await database.setBlockedUserCrossSigningKey(
|
||||||
true,
|
true,
|
||||||
clientId,
|
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
'publicKey',
|
'publicKey',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('removeUserCrossSigningKey', () async {
|
test('removeUserCrossSigningKey', () async {
|
||||||
await database.removeUserCrossSigningKey(
|
await database.removeUserCrossSigningKey(
|
||||||
clientId,
|
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
'publicKey',
|
'publicKey',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('storeUserDeviceKeysInfo', () async {
|
test('storeUserDeviceKeysInfo', () async {
|
||||||
await database.storeUserDeviceKeysInfo(
|
await database.storeUserDeviceKeysInfo(
|
||||||
clientId,
|
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('storeUserDeviceKey', () async {
|
test('storeUserDeviceKey', () async {
|
||||||
await database.storeUserDeviceKey(
|
await database.storeUserDeviceKey(
|
||||||
clientId,
|
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
'deviceId',
|
'deviceId',
|
||||||
'{}',
|
'{}',
|
||||||
|
|
@ -432,7 +415,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
test('setVerifiedUserDeviceKey', () async {
|
test('setVerifiedUserDeviceKey', () async {
|
||||||
await database.setVerifiedUserDeviceKey(
|
await database.setVerifiedUserDeviceKey(
|
||||||
true,
|
true,
|
||||||
clientId,
|
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
'deviceId',
|
'deviceId',
|
||||||
);
|
);
|
||||||
|
|
@ -440,7 +422,6 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
test('setBlockedUserDeviceKey', () async {
|
test('setBlockedUserDeviceKey', () async {
|
||||||
await database.setBlockedUserDeviceKey(
|
await database.setBlockedUserDeviceKey(
|
||||||
true,
|
true,
|
||||||
clientId,
|
|
||||||
'@alice:example.com',
|
'@alice:example.com',
|
||||||
'deviceId',
|
'deviceId',
|
||||||
);
|
);
|
||||||
|
|
@ -448,13 +429,13 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
|
||||||
|
|
||||||
// Clearing up from here
|
// Clearing up from here
|
||||||
test('clearSSSSCache', () async {
|
test('clearSSSSCache', () async {
|
||||||
await database.clearSSSSCache(clientId);
|
await database.clearSSSSCache();
|
||||||
});
|
});
|
||||||
test('clearCache', () async {
|
test('clearCache', () async {
|
||||||
await database.clearCache(clientId);
|
await database.clearCache();
|
||||||
});
|
});
|
||||||
test('clear', () async {
|
test('clear', () async {
|
||||||
await database.clear(clientId);
|
await database.clear();
|
||||||
});
|
});
|
||||||
test('Close', () async {
|
test('Close', () async {
|
||||||
await database.close();
|
await database.close();
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,6 @@ void main() {
|
||||||
'floof': 'foxhole',
|
'floof': 'foxhole',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
client.id,
|
|
||||||
userId,
|
userId,
|
||||||
deviceId);
|
deviceId);
|
||||||
var event = ToDeviceEvent(
|
var event = ToDeviceEvent(
|
||||||
|
|
@ -194,7 +193,6 @@ void main() {
|
||||||
'floof': 'foxhole',
|
'floof': 'foxhole',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
client.id,
|
|
||||||
userId,
|
userId,
|
||||||
deviceId);
|
deviceId);
|
||||||
event = ToDeviceEvent(
|
event = ToDeviceEvent(
|
||||||
|
|
@ -218,7 +216,6 @@ void main() {
|
||||||
'floof': 'foxhole',
|
'floof': 'foxhole',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
client.id,
|
|
||||||
userId,
|
userId,
|
||||||
deviceId);
|
deviceId);
|
||||||
event = ToDeviceEvent(
|
event = ToDeviceEvent(
|
||||||
|
|
@ -242,7 +239,6 @@ void main() {
|
||||||
'type': 'm.dummy',
|
'type': 'm.dummy',
|
||||||
'content': {},
|
'content': {},
|
||||||
}),
|
}),
|
||||||
client.id,
|
|
||||||
userId,
|
userId,
|
||||||
deviceId);
|
deviceId);
|
||||||
event = ToDeviceEvent(
|
event = ToDeviceEvent(
|
||||||
|
|
|
||||||
|
|
@ -26,20 +26,21 @@ import 'fake_database.dart';
|
||||||
void main() {
|
void main() {
|
||||||
group('Databse', () {
|
group('Databse', () {
|
||||||
Logs().level = Level.error;
|
Logs().level = Level.error;
|
||||||
var clientId = -1;
|
|
||||||
final room = Room(id: '!room:blubb');
|
final room = Room(id: '!room:blubb');
|
||||||
test('setupDatabase', () async {
|
test('setupDatabase', () async {
|
||||||
final database = await getDatabase(null);
|
final database = await getDatabase(null);
|
||||||
clientId = await database.insertClient(
|
await database.insertClient(
|
||||||
'testclient',
|
'testclient',
|
||||||
'https://example.org',
|
'https://example.org',
|
||||||
'blubb',
|
'blubb',
|
||||||
'@test:example.org',
|
'@test:example.org',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null);
|
null,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('storeEventUpdate', () async {
|
test('storeEventUpdate', () async {
|
||||||
final database = await getDatabase(null);
|
final database = await getDatabase(null);
|
||||||
// store a simple update
|
// store a simple update
|
||||||
|
|
@ -54,8 +55,8 @@ void main() {
|
||||||
'sender': '@blah:blubb',
|
'sender': '@blah:blubb',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await database.storeEventUpdate(clientId, update);
|
await database.storeEventUpdate(update);
|
||||||
var event = await database.getEventById(clientId, '\$event-1', room);
|
var event = await database.getEventById('\$event-1', room);
|
||||||
expect(event.eventId, '\$event-1');
|
expect(event.eventId, '\$event-1');
|
||||||
|
|
||||||
// insert a transaction id
|
// insert a transaction id
|
||||||
|
|
@ -71,8 +72,8 @@ void main() {
|
||||||
'status': 0,
|
'status': 0,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await database.storeEventUpdate(clientId, update);
|
await database.storeEventUpdate(update);
|
||||||
event = await database.getEventById(clientId, 'transaction-1', room);
|
event = await database.getEventById('transaction-1', room);
|
||||||
expect(event.eventId, 'transaction-1');
|
expect(event.eventId, 'transaction-1');
|
||||||
update = EventUpdate(
|
update = EventUpdate(
|
||||||
type: EventUpdateType.timeline,
|
type: EventUpdateType.timeline,
|
||||||
|
|
@ -89,10 +90,10 @@ void main() {
|
||||||
'status': 1,
|
'status': 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await database.storeEventUpdate(clientId, update);
|
await database.storeEventUpdate(update);
|
||||||
event = await database.getEventById(clientId, 'transaction-1', room);
|
event = await database.getEventById('transaction-1', room);
|
||||||
expect(event, null);
|
expect(event, null);
|
||||||
event = await database.getEventById(clientId, '\$event-2', room);
|
event = await database.getEventById('\$event-2', room);
|
||||||
|
|
||||||
// insert a transaction id if the event id for it already exists
|
// insert a transaction id if the event id for it already exists
|
||||||
update = EventUpdate(
|
update = EventUpdate(
|
||||||
|
|
@ -107,8 +108,8 @@ void main() {
|
||||||
'status': 0,
|
'status': 0,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await database.storeEventUpdate(clientId, update);
|
await database.storeEventUpdate(update);
|
||||||
event = await database.getEventById(clientId, '\$event-3', room);
|
event = await database.getEventById('\$event-3', room);
|
||||||
expect(event.eventId, '\$event-3');
|
expect(event.eventId, '\$event-3');
|
||||||
update = EventUpdate(
|
update = EventUpdate(
|
||||||
type: EventUpdateType.timeline,
|
type: EventUpdateType.timeline,
|
||||||
|
|
@ -125,11 +126,11 @@ void main() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await database.storeEventUpdate(clientId, update);
|
await database.storeEventUpdate(update);
|
||||||
event = await database.getEventById(clientId, '\$event-3', room);
|
event = await database.getEventById('\$event-3', room);
|
||||||
expect(event.eventId, '\$event-3');
|
expect(event.eventId, '\$event-3');
|
||||||
expect(event.status, 1);
|
expect(event.status, 1);
|
||||||
event = await database.getEventById(clientId, 'transaction-2', room);
|
event = await database.getEventById('transaction-2', room);
|
||||||
expect(event, null);
|
expect(event, null);
|
||||||
|
|
||||||
// insert transaction id and not update status
|
// insert transaction id and not update status
|
||||||
|
|
@ -145,8 +146,8 @@ void main() {
|
||||||
'status': 2,
|
'status': 2,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await database.storeEventUpdate(clientId, update);
|
await database.storeEventUpdate(update);
|
||||||
event = await database.getEventById(clientId, '\$event-4', room);
|
event = await database.getEventById('\$event-4', room);
|
||||||
expect(event.eventId, '\$event-4');
|
expect(event.eventId, '\$event-4');
|
||||||
update = EventUpdate(
|
update = EventUpdate(
|
||||||
type: EventUpdateType.timeline,
|
type: EventUpdateType.timeline,
|
||||||
|
|
@ -163,11 +164,11 @@ void main() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await database.storeEventUpdate(clientId, update);
|
await database.storeEventUpdate(update);
|
||||||
event = await database.getEventById(clientId, '\$event-4', room);
|
event = await database.getEventById('\$event-4', room);
|
||||||
expect(event.eventId, '\$event-4');
|
expect(event.eventId, '\$event-4');
|
||||||
expect(event.status, 2);
|
expect(event.status, 2);
|
||||||
event = await database.getEventById(clientId, 'transaction-3', room);
|
event = await database.getEventById('transaction-3', room);
|
||||||
expect(event, null);
|
expect(event, null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue