diff --git a/lib/models/notifications/notification.dart b/lib/models/notifications/notification.dart index bb66371a3..5ac152633 100644 --- a/lib/models/notifications/notification.dart +++ b/lib/models/notifications/notification.dart @@ -60,7 +60,7 @@ class OBNotification extends UpdatableModel { contentObjectData: json['content_object'], type: type); } - if (json.containsKey('read')) { + if (json.containsKey('read') && !read) { read = json['read']; } diff --git a/lib/pages/home/pages/notifications/notifications.dart b/lib/pages/home/pages/notifications/notifications.dart index 593931c6a..22b98faa2 100644 --- a/lib/pages/home/pages/notifications/notifications.dart +++ b/lib/pages/home/pages/notifications/notifications.dart @@ -279,6 +279,10 @@ class OBNotificationsPageState extends State } Future> _refreshGeneralNotifications() async { + // TODO[Performance] remove on the _refreshNotifications call is faster + _generalNotificationsListController.items().forEach((OBNotification notification) { + notification.markNotificationAsRead(); + }); List newNotifications = await _refreshNotifications(_generalTypes); await _refreshUnreadGeneralNotificationsCount(); @@ -286,6 +290,11 @@ class OBNotificationsPageState extends State } Future> _refreshRequestNotifications() async { + // TODO[Performance] remove onthe the _refreshNotifications call is faster + _requestsNotificationsListController.items().forEach((OBNotification notification) { + notification.markNotificationAsRead(); + }); + List newNotifications = await _refreshNotifications(_requestTypes); await _refreshUnreadRequestNotificationsCount(); @@ -294,7 +303,9 @@ class OBNotificationsPageState extends State Future> _refreshNotifications( [List types]) async { - await _readNotifications(types: types); + // TODO[Performance] This API call takes ages so we're not awaiting anymore. + // When the perf is improved, make sure to await before requesting new notifications + _readNotifications(types: types); NotificationsList notificationsList = await _userService.getNotifications(types: types); @@ -332,7 +343,7 @@ class OBNotificationsPageState extends State } int maxId = firstItem.id; - await _userService.readNotifications(maxId: maxId, types: types); + return _userService.readNotifications(maxId: maxId, types: types); } Future> _loadMoreGeneralNotifications( diff --git a/lib/widgets/http_list.dart b/lib/widgets/http_list.dart index 46bbd07fe..1be35d99c 100644 --- a/lib/widgets/http_list.dart +++ b/lib/widgets/http_list.dart @@ -676,6 +676,10 @@ class OBHttpListController { return _state._list.isNotEmpty; } + List items() { + return _state._list; + } + T firstItem() { return _state._list.first; }