Fix infinite querying when the user has no notifications or DMs

codemagic-setup
Hank Grabowski 2023-03-14 21:31:02 -04:00
rodzic fd222733f6
commit 18cc85e565
4 zmienionych plików z 12 dodań i 4 usunięć

Wyświetl plik

@ -41,8 +41,10 @@ class PagesManager<TResult, TID> {
}
final result = await onRequest(PagingData(limit: limit));
if (result.isSuccess) {
final newPage = result.value.map((data) => idMapper(data));
_pages.add(newPage);
if (result.value.previous != null || result.value.next != null) {
final newPage = result.value.map((data) => idMapper(data));
_pages.add(newPage);
}
}
return result;
}

Wyświetl plik

@ -41,7 +41,6 @@ class NotificationsScreen extends StatelessWidget {
),
];
if (notifications.isEmpty) {
manager.updateNotifications();
title = 'Notifications';
body = Center(
child: Column(

Wyświetl plik

@ -14,10 +14,12 @@ import 'auth_service.dart';
class DirectMessageService extends ChangeNotifier {
static final _logger = Logger('$DirectMessageService');
final _threads = <String, DirectMessageThread>{};
var _firstLoading = true;
List<DirectMessageThread> getThreads({bool unreadyOnly = false}) {
if (_threads.isEmpty) {
if (_threads.isEmpty && _firstLoading) {
updateThreads();
_firstLoading = false;
}
if (unreadyOnly) {

Wyświetl plik

@ -22,8 +22,13 @@ class NotificationsManager extends ChangeNotifier {
idMapper: (nn) => nn.map((n) => n.id).toList(),
onRequest: _clientGetNotificationsRequest,
);
var _firstLoad = true;
List<UserNotification> get notifications {
if (_notifications.isEmpty && _firstLoad) {
updateNotifications();
_firstLoad = false;
}
final result = List<UserNotification>.from(_notifications.values);
result.sort((n1, n2) {
if (n1.dismissed == n2.dismissed) {