Merge branch 'soru/fix-last-event' into 'master'

fix lastEvent

See merge request famedly/famedlysdk!301
This commit is contained in:
Christian Pauly 2020-05-18 11:42:38 +00:00
commit e50f6cc6c0
1 changed files with 4 additions and 5 deletions

View File

@ -370,16 +370,15 @@ class Room {
String notificationSettings;
Event get lastEvent {
var lastTime = DateTime.fromMillisecondsSinceEpoch(0);
var lastSortOrder = -1e32; // this bound to be small enough
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.time != null &&
state.time.millisecondsSinceEpoch >
lastTime.millisecondsSinceEpoch) {
lastTime = state.time;
if (state.sortOrder != null &&
state.sortOrder > lastSortOrder) {
lastSortOrder = state.sortOrder;
lastEvent = state;
}
});