Merge branch 'notifications-update-fixes' into 'main'

Fix don't mark connection requests as unread on "markAllUnread" since they...

See merge request mysocialportal/relatica!73
main
HankG 2025-10-13 21:21:13 +00:00
commit 6997bc60fe
3 zmienionych plików z 77 dodań i 64 usunięć

Wyświetl plik

@ -27,7 +27,8 @@ class AppBottomNavBar extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final profile = ref.watch(activeProfileProvider);
ref.watch(notificationsManagerProvider(profile));
final hasNotifications = ref.read(hasNotificationsProvider(profile, false));
final hasNotifications =
ref.watch(hasNotificationsProvider(profile, false));
return BottomNavigationBar(
onTap: (index) {

Wyświetl plik

@ -48,17 +48,23 @@ class _NotificationsStore extends _$NotificationsStore {
}
void markAllRead() {
final connectionRequests = _values
.where((n) => n.type == NotificationType.follow_request)
.toList();
final updated = _values.map((n) => n.copy(dismissed: true)).toList();
_values.clear();
_values.addAll(connectionRequests);
_values.addAll(updated);
state = _rval;
}
List<UserNotification> get _rval => _values.toList()..sort();
List<UserNotification> get _rval =>
_values.toList()
..sort();
@override
bool updateShouldNotify(
List<UserNotification> previous, List<UserNotification> next) {
bool updateShouldNotify(List<UserNotification> previous,
List<UserNotification> next) {
final rval = !listEqualsWithComparer(
previous,
next,
@ -70,8 +76,8 @@ class _NotificationsStore extends _$NotificationsStore {
}
@riverpod
List<UserNotification> userNotificationsByType(
Ref ref, Profile profile, NotificationType type, bool isRead) {
List<UserNotification> userNotificationsByType(Ref ref, Profile profile,
NotificationType type, bool isRead) {
_logger.fine('Build userNotificationsByTypeProvider($type,$isRead,$profile)');
final notifications = ref.watch(_NotificationsStoreProvider(profile, type));
return notifications.where((n) => n.dismissed == isRead).toList();
@ -161,8 +167,8 @@ class NotificationsManager extends _$NotificationsManager {
_logger.info('clearConnectionRequestNotifications');
ref
.read(_NotificationsStoreProvider(
profile, NotificationType.follow_request)
.notifier)
profile, NotificationType.follow_request)
.notifier)
.clear();
state = const AsyncData(true);
}
@ -181,8 +187,8 @@ class NotificationsManager extends _$NotificationsManager {
_logger.info('refreshDms');
ref
.read(_NotificationsStoreProvider(
profile, NotificationType.direct_message)
.notifier)
profile, NotificationType.direct_message)
.notifier)
.clear();
await _postFetchOperations(
[],
@ -205,20 +211,21 @@ class NotificationsManager extends _$NotificationsManager {
var count = 0;
while (hasMore && count < maxCalls) {
final result =
first ? await pm.initialize(_itemsPerQuery) : await pm.nextFromEnd();
first ? await pm.initialize(_itemsPerQuery) : await pm.nextFromEnd();
first = false;
result.match(
onSuccess: (nd) =>
_logger.fine('Got ${nd.data.length} notifications'),
onError: (e) => _logger.severe(
onError: (e) =>
_logger.severe(
'Error getting notification: $e',
Trace.current(),
));
final response = result.getValueOrElse(() => PagedResponse([]));
response.data
.where((n) =>
!useActualRequests || n.type != NotificationType.follow_request)
!useActualRequests || n.type != NotificationType.follow_request)
.forEach(notificationsFromRefresh.add);
hasMore = response.next != null;
count++;
@ -235,10 +242,10 @@ class NotificationsManager extends _$NotificationsManager {
}
FutureResult<List<UserNotification>, ExecError> _postFetchOperations(
List<UserNotification> notificationsFromRefresh, {
bool updateDms = true,
bool updateFollowRequests = true,
}) async {
List<UserNotification> notificationsFromRefresh, {
bool updateDms = true,
bool updateFollowRequests = true,
}) async {
if (updateDms) {
if (DateTime.now().difference(lastDmsUpdate) >
_minimumDmsAndCrsUpdateDuration) {
@ -266,7 +273,7 @@ class NotificationsManager extends _$NotificationsManager {
final notifications = <String, UserNotification>{};
notificationsFromRefresh.removeWhere((n) =>
n.type == NotificationType.direct_message ||
n.type == NotificationType.direct_message ||
(useActualRequests && n.type == NotificationType.follow_request));
for (final n in notificationsFromRefresh) {
notifications[n.id] = n;
@ -292,24 +299,24 @@ class NotificationsManager extends _$NotificationsManager {
initialPages: hasNoNotifications
? []
: [
PagedResponse(
<String>[],
previous: PagingData(
minId: highestId,
limit: _itemsPerQuery,
),
)
],
PagedResponse(
<String>[],
previous: PagingData(
minId: highestId,
limit: _itemsPerQuery,
),
)
],
);
final stillNoNotifications =
!ref.read(hasAnyNotificationsProvider(profile));
!ref.read(hasAnyNotificationsProvider(profile));
final result = await (stillNoNotifications
? pm.initialize(_itemsPerQuery)
: pm.previousFromBeginning())
? pm.initialize(_itemsPerQuery)
: pm.previousFromBeginning())
.andThenAsync(
(page) async => await _postFetchOperations(page.data),
)
)
.withError(
(error) => _logger.info('Error getting more updates: $error'));
return result.mapValue((value) => value.isNotEmpty).execErrorCast();
@ -322,8 +329,8 @@ class NotificationsManager extends _$NotificationsManager {
final nonDmAndConnectionNotifications = result
.getValueOrElse(() => [])
.where((n) =>
n.type != NotificationType.follow_request &&
n.type != NotificationType.direct_message)
n.type != NotificationType.follow_request &&
n.type != NotificationType.direct_message)
.toList();
if (nonDmAndConnectionNotifications.isNotEmpty) {
return Result.ok(true);
@ -341,7 +348,7 @@ class NotificationsManager extends _$NotificationsManager {
.withResult((_) {
ref
.read(
_NotificationsStoreProvider(profile, notification.type).notifier)
_NotificationsStoreProvider(profile, notification.type).notifier)
.upsert(notification.copy(dismissed: true));
});
@ -375,7 +382,7 @@ class NotificationsManager extends _$NotificationsManager {
.watch(connectionByIdProvider(profile, fromAccountId))
.getValueOrElse(() => Connection());
final latestMessage =
t.messages.reduce((s, m) => s.createdAt > m.createdAt ? s : m);
t.messages.reduce((s, m) => s.createdAt > m.createdAt ? s : m);
return UserNotification(
id: (fromAccount.hashCode ^ t.parentUri.hashCode ^ t.title.hashCode)
.toString(),
@ -393,16 +400,17 @@ class NotificationsManager extends _$NotificationsManager {
final followRequestResult = !useActualRequests
? <UserNotification>[]
: ref
.watch(followRequestListProvider(profile))
.map((r) => r.toUserNotification())
.toList();
.watch(followRequestListProvider(profile))
.map((r) => r.toUserNotification())
.toList();
return [...dmsResult, ...followRequestResult];
}
Future<void> _processNewNotifications(
Iterable<UserNotification> notifications) async {
final st = Stopwatch()..start();
final st = Stopwatch()
..start();
for (final n in notifications) {
if (st.elapsedMilliseconds > maxProcessingMillis) {
@ -413,7 +421,7 @@ class NotificationsManager extends _$NotificationsManager {
}
FutureResult<List<UserNotification>, ExecError>
_loadOlderUnreadNotifications() async {
_loadOlderUnreadNotifications() async {
_logger.finest('Loading Older Unread Notifications');
final (lowestId, _) = ref.read(lowHighIdProvider(profile, false));
final pm = _buildPageManager(
@ -435,17 +443,19 @@ class NotificationsManager extends _$NotificationsManager {
.nextFromEnd()
.andThenAsync(
(page) async => await _postFetchOperations(page.data),
)
)
.withError(
(error) => _logger.info('Error getting more updates: $error'));
_logger.finest(
'Loaded Older Unread Notifications: ${result.getValueOrElse(() => []).length}');
'Loaded Older Unread Notifications: ${result
.getValueOrElse(() => [])
.length}');
return result.execErrorCast();
}
FutureResult<List<UserNotification>, ExecError>
_loadOlderReadAndUnreadNotifications() async {
_loadOlderReadAndUnreadNotifications() async {
_logger.finest('Loading Older Read and Unread Notifications');
final hasNoNotifications = !ref.read(hasAnyNotificationsProvider(profile));
final useIsRead = ref.read(hasNotificationsProvider(profile, true));
@ -457,25 +467,27 @@ class NotificationsManager extends _$NotificationsManager {
initialPages: hasNoNotifications
? []
: [
PagedResponse(
<String>[],
next: PagingData(
maxId: lowestId,
limit: _itemsPerQuery,
),
)
],
PagedResponse(
<String>[],
next: PagingData(
maxId: lowestId,
limit: _itemsPerQuery,
),
)
],
);
final result = await (hasNoNotifications
? pm.initialize(_itemsPerQuery)
: pm.nextFromEnd())
? pm.initialize(_itemsPerQuery)
: pm.nextFromEnd())
.andThenAsync(
(page) async => await _postFetchOperations(page.data),
)
)
.withError(
(error) => _logger.info('Error getting more updates: $error'));
_logger.finest(
'Loaded Older Read and Unread Notifications: ${result.getValueOrElse(() => []).length}');
'Loaded Older Read and Unread Notifications: ${result
.getValueOrElse(() => [])
.length}');
return result.execErrorCast();
}
}
@ -485,8 +497,8 @@ class NotificationsManager extends _$NotificationsManager {
int lowestNotificationId = 0x7FFFFFFFFFFFFFFF;
final ids = notifications
.where((n) =>
n.type != NotificationType.direct_message &&
n.type != NotificationType.follow_request)
n.type != NotificationType.direct_message &&
n.type != NotificationType.follow_request)
.map((n) => int.parse(n.id));
for (var id in ids) {
@ -502,15 +514,15 @@ class NotificationsManager extends _$NotificationsManager {
return (lowestNotificationId, highestNotificationId);
}
PagesManager<List<UserNotification>, String> _buildPageManager(
Ref ref,
Profile profile,
bool includeAll, {
List<PagedResponse> initialPages = const [],
}) =>
PagesManager<List<UserNotification>, String> _buildPageManager(Ref ref,
Profile profile,
bool includeAll, {
List<PagedResponse> initialPages = const [],
}) =>
PagesManager<List<UserNotification>, String>(
initialPages: initialPages,
idMapper: (nn) => nn.map((n) => n.id).toList(),
onRequest: (pd) async => await ref
onRequest: (pd) async =>
await ref
.read(notificationsClientProvider(profile, pd, includeAll).future),
);

Wyświetl plik

@ -2,7 +2,7 @@ name: relatica
description: A mobile and desktop client for interacting with the Friendica social network
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.1.0+17
version: 1.1.1+18
environment:
sdk: '>=3.2.0 <4.0.0'