Merge commit '74bd1d331b77f45ab0793af7c9e607795b8c16f0' into yiffed

This commit is contained in:
Inex Code 2020-10-04 18:57:23 +03:00
commit 8d3fb1d64b
14 changed files with 713 additions and 313 deletions

View file

@ -362,10 +362,10 @@ class Encryption {
}
void dispose() {
_backgroundTasksRunning = false;
keyManager.dispose();
olmManager.dispose();
keyVerificationManager.dispose();
_backgroundTasksRunning = false;
}
}

View file

@ -286,7 +286,7 @@ class KeyManager {
roomId,
sess.outboundGroupSession.pickle(client.userID),
json.encode(sess.devices),
sess.creationTime,
sess.creationTime.millisecondsSinceEpoch,
sess.sentMessages);
}

View file

@ -238,8 +238,12 @@ class OlmManager {
// update an existing session
_olmSessions[session.identityKey][ix] = session;
}
client.database.storeOlmSession(client.id, session.identityKey,
session.sessionId, session.pickledSession, session.lastReceived);
client.database.storeOlmSession(
client.id,
session.identityKey,
session.sessionId,
session.pickledSession,
session.lastReceived.millisecondsSinceEpoch);
}
ToDeviceEvent _decryptToDeviceEvent(ToDeviceEvent event) {

View file

@ -46,7 +46,7 @@ class OlmSession {
identityKey = dbEntry.identityKey;
sessionId = dbEntry.sessionId;
lastReceived =
dbEntry.lastReceived ?? DateTime.fromMillisecondsSinceEpoch(0);
DateTime.fromMillisecondsSinceEpoch(dbEntry.lastReceived ?? 0);
assert(sessionId == session.session_id());
} catch (e, s) {
Logs.error('[LibOlm] Could not unpickle olm session: ' + e.toString(), s);

View file

@ -44,7 +44,7 @@ class OutboundGroupSession {
try {
outboundGroupSession.unpickle(key, dbEntry.pickle);
devices = List<String>.from(json.decode(dbEntry.deviceIds));
creationTime = dbEntry.creationTime;
creationTime = DateTime.fromMillisecondsSinceEpoch(dbEntry.creationTime);
sentMessages = dbEntry.sentMessages;
} catch (e, s) {
dispose();

View file

@ -1597,10 +1597,14 @@ sort order of ${prevState.sortOrder}. This should never happen...''');
} catch (_) {
// No-OP
}
if (closeDatabase) await database?.close();
database = null;
encryption?.dispose();
encryption = null;
try {
if (closeDatabase) await database?.close();
} catch (error, stacktrace) {
Logs.warning('Failed to close database: ' + error.toString(), stacktrace);
}
database = null;
return;
}
}

View file

@ -55,7 +55,7 @@ class Database extends _$Database {
Database.connect(DatabaseConnection connection) : super.connect(connection);
@override
int get schemaVersion => 6;
int get schemaVersion => 7;
int get maxFileSize => 1 * 1024 * 1024;
@ -117,6 +117,27 @@ class Database extends _$Database {
inboundGroupSessions, inboundGroupSessions.senderClaimedKeys);
from++;
}
if (from == 6) {
// DATETIME was internally an int, so we should be able to re-use the
// olm_sessions table.
await m.deleteTable('outbound_group_sessions');
await m.createTable(outboundGroupSessions);
await m.deleteTable('events');
await m.createTable(events);
await m.deleteTable('room_states');
await m.createTable(roomStates);
await m.deleteTable('files');
await m.createTable(files);
// and now clear cache
await delete(presences).go();
await delete(roomAccountData).go();
await delete(accountData).go();
await delete(roomStates).go();
await delete(events).go();
await delete(rooms).go();
await delete(outboundGroupSessions).go();
await customStatement('UPDATE clients SET prev_batch = null');
}
} catch (e, s) {
Logs.error(e, s);
onError.add(SdkError(exception: e, stackTrace: s));
@ -484,10 +505,8 @@ class Database extends _$Database {
eventContent['event_id'],
chatId,
oldEvent?.sortOrder ?? eventUpdate.sortOrder,
eventContent['origin_server_ts'] != null
? DateTime.fromMillisecondsSinceEpoch(
eventContent['origin_server_ts'])
: DateTime.now(),
eventContent['origin_server_ts'] ??
DateTime.now().millisecondsSinceEpoch,
eventContent['sender'],
eventContent['type'],
json.encode(eventContent['unsigned'] ?? ''),
@ -520,10 +539,7 @@ class Database extends _$Database {
eventContent['event_id'] ?? now.millisecondsSinceEpoch.toString(),
chatId,
eventUpdate.sortOrder ?? 0.0,
eventContent['origin_server_ts'] != null
? DateTime.fromMillisecondsSinceEpoch(
eventContent['origin_server_ts'])
: now,
eventContent['origin_server_ts'] ?? now.millisecondsSinceEpoch,
eventContent['sender'],
eventContent['type'],
json.encode(eventContent['unsigned'] ?? ''),

File diff suppressed because it is too large Load diff

View file

@ -48,7 +48,7 @@ CREATE TABLE olm_sessions (
identity_key TEXT NOT NULL,
session_id TEXT NOT NULL,
pickle TEXT NOT NULL,
last_received DATETIME,
last_received BIGINT,
UNIQUE(client_id, identity_key, session_id)
) AS DbOlmSessions;
CREATE INDEX olm_sessions_index ON olm_sessions(client_id);
@ -58,7 +58,7 @@ CREATE TABLE outbound_group_sessions (
room_id TEXT NOT NULL,
pickle TEXT NOT NULL,
device_ids TEXT NOT NULL,
creation_time DATETIME NOT NULL,
creation_time BIGINT NOT NULL,
sent_messages INTEGER NOT NULL DEFAULT '0',
UNIQUE(client_id, room_id)
) AS DbOutboundGroupSession;
@ -108,7 +108,7 @@ CREATE TABLE events (
event_id TEXT NOT NULL,
room_id TEXT NOT NULL,
sort_order DOUBLE NOT NULL,
origin_server_ts DATETIME NOT NULL,
origin_server_ts BIGINT NOT NULL,
sender TEXT NOT NULL,
type TEXT NOT NULL,
unsigned TEXT,
@ -125,7 +125,7 @@ CREATE TABLE room_states (
event_id TEXT NOT NULL,
room_id TEXT NOT NULL,
sort_order DOUBLE NOT NULL,
origin_server_ts DATETIME NOT NULL,
origin_server_ts BIGINT NOT NULL,
sender TEXT NOT NULL,
type TEXT NOT NULL,
unsigned TEXT,
@ -166,7 +166,7 @@ CREATE INDEX presences_index ON presences(client_id);
CREATE TABLE files (
mxc_uri TEXT NOT NULL PRIMARY KEY,
bytes BLOB,
saved_at DATETIME,
saved_at BIGINT,
UNIQUE(mxc_uri)
) AS DbFile;

View file

@ -192,7 +192,9 @@ class Event extends MatrixEvent {
eventId: dbEntry.eventId,
roomId: dbEntry.roomId,
senderId: dbEntry.sender,
originServerTs: dbEntry.originServerTs ?? DateTime.now(),
originServerTs: dbEntry.originServerTs != null
? DateTime.fromMillisecondsSinceEpoch(dbEntry.originServerTs)
: DateTime.now(),
unsigned: unsigned,
room: room,
sortOrder: dbEntry.sortOrder ?? 0.0,
@ -425,8 +427,8 @@ class Event extends MatrixEvent {
storeable = storeable &&
uint8list.lengthInBytes < room.client.database.maxFileSize;
if (storeable) {
await room.client.database
.storeFile(mxContent.toString(), uint8list, DateTime.now());
await room.client.database.storeFile(mxContent.toString(), uint8list,
DateTime.now().millisecondsSinceEpoch);
}
}

View file

@ -1620,7 +1620,8 @@ class Room {
var deviceKeys = <DeviceKeys>[];
var users = await requestParticipants();
for (final user in users) {
if (client.userDeviceKeys.containsKey(user.id)) {
if ([Membership.invite, Membership.join].contains(user.membership) &&
client.userDeviceKeys.containsKey(user.id)) {
for (var deviceKeyEntry
in client.userDeviceKeys[user.id].deviceKeys.values) {
deviceKeys.add(deviceKeyEntry);

View file

@ -31,3 +31,7 @@ dev_dependencies:
build_runner: ^1.5.2
pedantic: ^1.9.0
moor_ffi: ^0.5.0
dependency_overrides:
# See https://github.com/flutter/flutter/issues/62240
analyzer: '0.39.14'

View file

@ -73,7 +73,7 @@ void main() {
eventId: '143273582443PhrSn:example.org',
roomId: id,
sortOrder: 0.0,
originServerTs: DateTime.fromMillisecondsSinceEpoch(1432735824653),
originServerTs: 1432735824653,
sender: '@example:example.org',
type: 'm.room.join_rules',
unsigned: '{"age": 1234}',

View file

@ -133,7 +133,7 @@ void main() {
expect(user1.canChangePowerLevel, false);
});
test('dispose client', () async {
await client.dispose();
await client.dispose(closeDatabase: true);
});
});
}