diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index aafeb63..b3bc816 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -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(); } } diff --git a/lib/src/Timeline.dart b/lib/src/Timeline.dart index 1749999..911465a 100644 --- a/lib/src/Timeline.dart +++ b/lib/src/Timeline.dart @@ -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(); } }