Merge branch 'master' into soru/cross-signing

This commit is contained in:
Sorunome 2020-05-26 10:00:59 +02:00
commit c23e38a9c9
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
3 changed files with 21 additions and 11 deletions

View File

@ -428,10 +428,10 @@ class Event {
/// Trys to decrypt this event and persists it in the database afterwards
Future<Event> decryptAndStore([String updateType = 'timeline']) async {
final newEvent = decrypted;
if (newEvent.type == EventTypes.Encrypted || room.client.database == null) {
return newEvent; // decryption failed or we don't have a database
if (newEvent.type == EventTypes.Encrypted) {
return newEvent; // decryption failed
}
await room.client.database.storeEventUpdate(
await room.client.database?.storeEventUpdate(
room.client.id,
EventUpdate(
eventType: newEvent.typeKey,
@ -441,6 +441,9 @@ class Event {
sortOrder: newEvent.sortOrder,
),
);
if (updateType != 'history') {
room.setState(newEvent);
}
return newEvent;
}

View File

@ -273,10 +273,7 @@ class Room {
Future<void> _tryAgainDecryptLastMessage() async {
if (getState('m.room.encrypted') != null) {
final decrypted = await getState('m.room.encrypted').decryptAndStore();
if (decrypted.type != EventTypes.Encrypted) {
setState(decrypted);
}
await getState('m.room.encrypted').decryptAndStore();
}
}
@ -405,14 +402,22 @@ class Room {
String notificationSettings;
Event get lastEvent {
var lastSortOrder = -1e32; // this bound to be small enough
// as lastEvent calculation is based on the state events we unfortunately cannot
// use sortOrder here: With many state events we just know which ones are the
// newest ones, without knowing in which order they actually happened. As such,
// using the origin_server_ts is the best guess for this algorithm. While not
// perfect, it is only used for the room preview in the room list and sorting
// said room list, so it should be good enough.
var lastTime = DateTime.fromMillisecondsSinceEpoch(0);
var lastEvent = getState('m.room.message');
if (lastEvent == null) {
states.forEach((final String key, final entry) {
if (!entry.containsKey('')) return;
final Event state = entry[''];
if (state.sortOrder != null && state.sortOrder > lastSortOrder) {
lastSortOrder = state.sortOrder;
if (state.time != null &&
state.time.millisecondsSinceEpoch >
lastTime.millisecondsSinceEpoch) {
lastTime = state.time;
lastEvent = state;
}
});

View File

@ -19,5 +19,7 @@ class Profile {
@override
bool operator ==(dynamic other) =>
avatarUrl == other.avatarUrl && displayname == other.displayname;
(other is Profile) &&
avatarUrl == other.avatarUrl &&
displayname == other.displayname;
}