added new response data from notifications api

This commit is contained in:
llsajjad
2025-09-27 13:02:12 +03:30
parent 7e58a694ff
commit fa974bc4a2
16 changed files with 1226 additions and 869 deletions
+24 -36
View File
@@ -87,11 +87,9 @@ class NotificationViewModel with ChangeNotifier {
case Ok<NotificationResponseModel>():
final data = result.value;
if (isPagination && allNotificationResponse != null) {
final old = allNotificationResponse?.data?.notifications ?? [];
final fresh = data.data?.notifications ?? [];
allNotificationResponse = data.copyWith(
data: data.data?.copyWith(notifications: [...old, ...fresh]),
);
final old = allNotificationResponse?.data ?? [];
final fresh = data.data ?? [];
allNotificationResponse = data.copyWith(data: [...old, ...fresh]);
} else {
allNotificationResponse = data;
}
@@ -99,8 +97,8 @@ class NotificationViewModel with ChangeNotifier {
_updateImportantFromAll();
currentPageAll = page;
totalPagesAll = data.data?.meta?.pages ?? 1;
hasMoreAll = (data.data?.notifications?.length ?? 0) >= _pageSize;
totalPagesAll = data.meta?.pages ?? 1;
hasMoreAll = (data.data?.length ?? 0) >= _pageSize;
break;
case Error<NotificationResponseModel>():
@@ -134,18 +132,16 @@ class NotificationViewModel with ChangeNotifier {
case Ok<NotificationResponseModel>():
final data = result.value;
if (isPagination && unreadNotificationResponse != null) {
final old = unreadNotificationResponse?.data?.notifications ?? [];
final fresh = data.data?.notifications ?? [];
unreadNotificationResponse = data.copyWith(
data: data.data?.copyWith(notifications: [...old, ...fresh]),
);
final old = unreadNotificationResponse?.data ?? [];
final fresh = data.data ?? [];
unreadNotificationResponse = data.copyWith(data: [...old, ...fresh]);
} else {
unreadNotificationResponse = data;
}
currentPageUnread = page;
totalPagesUnread = data.data?.meta?.pages ?? 1;
hasMoreUnread = (data.data?.notifications?.length ?? 0) >= _pageSize;
totalPagesUnread = data.meta?.pages ?? 1;
hasMoreUnread = (data.data?.length ?? 0) >= _pageSize;
break;
case Error<NotificationResponseModel>():
@@ -180,18 +176,18 @@ class NotificationViewModel with ChangeNotifier {
case Ok<NotificationResponseModel>():
final data = result.value;
if (isPagination && importantNotificationResponse != null) {
final old = importantNotificationResponse?.data?.notifications ?? [];
final fresh = data.data?.notifications ?? [];
final old = importantNotificationResponse?.data ?? [];
final fresh = data.data ?? [];
importantNotificationResponse = data.copyWith(
data: data.data?.copyWith(notifications: [...old, ...fresh]),
data: [...old, ...fresh],
);
} else {
importantNotificationResponse = data;
}
currentPageImportant = page;
totalPagesImportant = data.data?.meta?.pages ?? 1;
hasMoreImportant = (data.data?.notifications?.length ?? 0) >= _pageSize;
totalPagesImportant = data.meta?.pages ?? 1;
hasMoreImportant = (data.data?.length ?? 0) >= _pageSize;
break;
case Error<NotificationResponseModel>():
@@ -207,7 +203,7 @@ class NotificationViewModel with ChangeNotifier {
}
void _updateImportantFromAll() {
final all = allNotificationResponse?.data?.notifications ?? [];
final all = allNotificationResponse?.data ?? [];
final filtered =
(all.where((n) {
final p = n.priority ?? '';
@@ -216,7 +212,7 @@ class NotificationViewModel with ChangeNotifier {
if (allNotificationResponse != null) {
importantNotificationResponse = allNotificationResponse!.copyWith(
data: allNotificationResponse!.data!.copyWith(notifications: filtered),
data: filtered,
);
} else {
importantNotificationResponse = null;
@@ -264,36 +260,28 @@ class NotificationViewModel with ChangeNotifier {
NotificationStrings.unknownResponse;
if (success) {
if (allNotificationResponse?.data?.notifications != null) {
if (allNotificationResponse?.data != null) {
final updatedNotifications =
allNotificationResponse!.data!.notifications!
allNotificationResponse!.data!
.map((n) => n.copyWith(seen: true))
.toList();
allNotificationResponse = allNotificationResponse!.copyWith(
data: allNotificationResponse!.data!.copyWith(
notifications: updatedNotifications,
),
data: updatedNotifications,
);
unreadNotificationResponse = unreadNotificationResponse?.copyWith(
data: unreadNotificationResponse?.data?.copyWith(
notifications: [],
),
data: [],
);
if (importantNotificationResponse?.data?.notifications != null) {
if (importantNotificationResponse?.data != null) {
final updatedImportant =
importantNotificationResponse!.data!.notifications!
importantNotificationResponse!.data!
.map((n) => n.copyWith(seen: true))
.toList();
importantNotificationResponse = importantNotificationResponse!
.copyWith(
data: importantNotificationResponse!.data!.copyWith(
notifications: updatedImportant,
),
);
.copyWith(data: updatedImportant);
}
}