[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, highlightCount: chatUpdate.highlight_count,
notificationCount: chatUpdate.notification_count); notificationCount: chatUpdate.notification_count);
rooms.insert(position, newRoom); rooms.insert(position, newRoom);
onInsert(position); if (onInsert != null) onInsert(position);
} }
// If the membership is "leave" then remove the item and stop here // If the membership is "leave" then remove the item and stop here
else if (found && chatUpdate.membership == "leave") { else if (found && chatUpdate.membership == "leave") {
final Room removed = rooms.removeAt(j); final Room removed = rooms.removeAt(j);
onRemove(j); if (onRemove != null) onRemove(j);
} }
// Update notification and highlight count // Update notification and highlight count
else if (found && else if (found &&
@ -156,7 +156,7 @@ class RoomList {
sortAndUpdate() { sortAndUpdate() {
rooms?.sort((a, b) => rooms?.sort((a, b) =>
b.timeCreated.toTimeStamp().compareTo(a.timeCreated.toTimeStamp())); 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); Event newEvent = Event.fromJson(eventUpdate.content, room);
events.insert(0, newEvent); events.insert(0, newEvent);
onInsert(0); if (onInsert != null) onInsert(0);
} }
sortAndUpdate(); sortAndUpdate();
} catch (e) { } catch (e) {
print("[WARNING] ${e.toString()}"); print("[WARNING] (_handleEventUpdate) ${e.toString()}");
sub.cancel();
} }
} }
sortAndUpdate() { sortAndUpdate() {
events events
?.sort((a, b) => b.time.toTimeStamp().compareTo(a.time.toTimeStamp())); ?.sort((a, b) => b.time.toTimeStamp().compareTo(a.time.toTimeStamp()));
onUpdate(); if (onUpdate != null) onUpdate();
} }
} }