From a36debfe020db625835e40233edee46fb0a0986c Mon Sep 17 00:00:00 2001 From: nfebe Date: Sat, 2 May 2026 20:29:02 +0100 Subject: [PATCH] fix(notifications): Send client_id when syncing read state Mark-as-read calls now forward the local client_id and use the existing POST endpoint, so notifications read offline can be linked to their server-side record on next sync instead of staying orphaned. --- .../notification/notification_remote_datasource.dart | 8 +++++--- lib/data/sync/notification_sync_handler.dart | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/data/datasources/notification/notification_remote_datasource.dart b/lib/data/datasources/notification/notification_remote_datasource.dart index 6ca25381..e0c29fab 100644 --- a/lib/data/datasources/notification/notification_remote_datasource.dart +++ b/lib/data/datasources/notification/notification_remote_datasource.dart @@ -10,7 +10,7 @@ abstract class NotificationRemoteDataSource { Future> getAllNotifications( {DateTime? syncedSince, bool? noClientId}); Future getNotification(int id); - Future markAsRead(int id, DateTime readAt); + Future markAsRead(int id, DateTime readAt, {String? clientId}); } @Injectable(as: NotificationRemoteDataSource) @@ -71,11 +71,13 @@ class NotificationRemoteDataSourceImpl implements NotificationRemoteDataSource { } @override - Future markAsRead(int id, DateTime readAt) async { - final response = await dio.put( + Future markAsRead(int id, DateTime readAt, + {String? clientId}) async { + final response = await dio.post( 'notifications/$id/read', data: { 'read_at': formatServerIsoDateTimeString(readAt), + if (clientId != null && clientId.isNotEmpty) 'client_id': clientId, }, ); diff --git a/lib/data/sync/notification_sync_handler.dart b/lib/data/sync/notification_sync_handler.dart index a59f57ca..6a4b72ed 100644 --- a/lib/data/sync/notification_sync_handler.dart +++ b/lib/data/sync/notification_sync_handler.dart @@ -62,7 +62,11 @@ class NotificationSyncHandler extends SyncTypeHandler // For notifications, we typically don't create/update from client // But if read_at is updated, we need to sync it if (entity.readAt != null && entity.id != null) { - return await remoteDataSource.markAsRead(entity.id!, entity.readAt!); + return await remoteDataSource.markAsRead( + entity.id!, + entity.readAt!, + clientId: entity.clientId, + ); } return entity; }