[Lists] Check if callbacks are not null.

This commit is contained in:
Christian Pauly 2019-06-25 12:34:03 +02:00
parent e6dd0739d0
commit c3967419e6
2 changed files with 6 additions and 7 deletions

View file

@ -93,12 +93,12 @@ class RoomList {
highlightCount: chatUpdate.highlight_count,
notificationCount: chatUpdate.notification_count);
rooms.insert(position, newRoom);
onInsert(position);
if (onInsert != null) onInsert(position);
}
// If the membership is "leave" then remove the item and stop here
else if (found && chatUpdate.membership == "leave") {
final Room removed = rooms.removeAt(j);
onRemove(j);
if (onRemove != null) onRemove(j);
}
// Update notification and highlight count
else if (found &&
@ -156,7 +156,7 @@ class RoomList {
sortAndUpdate() {
rooms?.sort((a, b) =>
b.timeCreated.toTimeStamp().compareTo(a.timeCreated.toTimeStamp()));
onUpdate();
if (onUpdate != null) onUpdate();
}
}

View file

@ -60,19 +60,18 @@ class Timeline {
Event newEvent = Event.fromJson(eventUpdate.content, room);
events.insert(0, newEvent);
onInsert(0);
if (onInsert != null) onInsert(0);
}
sortAndUpdate();
} catch (e) {
print("[WARNING] ${e.toString()}");
sub.cancel();
print("[WARNING] (_handleEventUpdate) ${e.toString()}");
}
}
sortAndUpdate() {
events
?.sort((a, b) => b.time.toTimeStamp().compareTo(a.time.toTimeStamp()));
onUpdate();
if (onUpdate != null) onUpdate();
}
}