feat(notifications): added push notifications navigation handling and fixed ws notification parsing

This commit is contained in:
misha
2026-03-04 09:05:00 +03:00
parent 58d99424a0
commit 08eeea6ba4
18 changed files with 424 additions and 239 deletions

View File

@@ -147,17 +147,16 @@ void _navigateToBottomNavRoute(BuildContext context, String path, [Object? extra
}
}
void _navigateToEntity(BuildContext context, String type, int id, int? commentId) {
if (type.contains('BlogPost')) {
context.push(RouteConstants.blogPostScreen, extra: {'id': id, 'highlightedCommentId': commentId});
} else if (type.contains('Recipe')) {
// TODO: aboutRecipesScreen требует recipe slug, в уведомлении только id — навигация отключена
} else if (type.contains('Plan')) {
// TODO: aboutPlanScreen требует slug плана, в уведомлении только id — навигация отключена
} else if (type.contains('Diet')) {
if (id > 0) {
context.push(RouteConstants.aboutDietScreen, extra: {'id': id, 'highlightedCommentId': commentId});
}
void _navigateToEntity(BuildContext context, CommentedEntityType type, int id, int? commentId) {
switch (type) {
case CommentedEntityType.blogPost:
context.push(RouteConstants.blogPostScreen, extra: {'id': id, 'highlightedCommentId': commentId});
case CommentedEntityType.diet:
if (id > 0) {
context.push(RouteConstants.aboutDietScreen, extra: {'id': id, 'highlightedCommentId': commentId});
}
case CommentedEntityType.unknown:
break;
}
}
@@ -184,7 +183,6 @@ class _PlanSubscriptionCanceledToAuthorWidget extends StatelessWidget {
final PlanSubscriptionCanceledToAuthorNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Отмена подписки. Клиент ${notification.customerName} отказался от плана "${notification.planName}"',
@@ -201,7 +199,6 @@ class _ChosenPlanStartedToClientWidget extends StatelessWidget {
final ChosenPlanStartedToClientNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Ваш план "${notification.planName}" начался! Удачи! 🚀',
@@ -218,7 +215,6 @@ class _ChosenPlanTomorrowReminderToClientWidget extends StatelessWidget {
final ChosenPlanTomorrowReminderToClientNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Напоминание: Завтра старт плана "${notification.planName}"',
@@ -250,7 +246,6 @@ class _ConsultantLeftCommentWidget extends StatelessWidget {
final ConsultantLeftCommentNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Новый комментарий от консультанта (за ${notification.date.format('dd.MM.yyyy')})',
@@ -283,7 +278,6 @@ class _ChosenPlanFinishedToClientWidget extends StatelessWidget {
final ChosenPlanFinishedToClientNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Поздравляем! План «${notification.planName}» успешно завершен! 🏆',
@@ -297,7 +291,6 @@ class _PlanSubscriptionCanceledToCustomerWidget extends StatelessWidget {
final PlanSubscriptionCanceledToCustomerNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Подписка на план "${notification.planName}" отменена.',
@@ -311,7 +304,6 @@ class _ChosenPlanStartedToConsultantWidget extends StatelessWidget {
final ChosenPlanStartedToConsultantNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Начало работы: План "${notification.planName}" с клиентом ${notification.customerName}',
@@ -325,7 +317,6 @@ class _ChosenPlanTomorrowReminderToConsultantWidget extends StatelessWidget {
final ChosenPlanTomorrowReminderToConsultantNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Напоминание: Завтра старт работы с ${notification.customerName} по плану "${notification.planName}"',
@@ -339,7 +330,6 @@ class _PlanSubscriptionPaidToAuthorWidget extends StatelessWidget {
final PlanSubscriptionPaidToAuthorNotification notification;
@override
Widget build(BuildContext context) {
return _BaseNotificationWidget(
isRead: notification.isRead,
notificationsText: 'Оплата получена! Клиент ${notification.customerName} оплатил план "${notification.planName}" 💰',
@@ -548,11 +538,6 @@ class _ComplaintToModerationForUserWidget extends StatelessWidget {
isRead: notification.isRead,
notificationsText: 'Ваша жалоба принята и находится на модерации.',
createdAt: notification.createdAt,
onTap: (['Plan', 'Recipe'].contains(notification.entityType) || notification.entityId <= 0 || notification.entityType.isEmpty)
? null
: () {
_navigateToEntity(context, notification.entityType, notification.entityId, null);
},
);
}
}
@@ -566,7 +551,7 @@ class _CommentRepliedWidget extends StatelessWidget {
isRead: notification.isRead,
notificationsText: 'Вам ответили в комментариях к: ${notification.entityName}',
createdAt: notification.createdAt,
onTap: (['Plan', 'Recipe'].contains(notification.commentedEntityType) || notification.commentedEntityId <= 0 || notification.commentId == null)
onTap: (notification.commentedEntityType == CommentedEntityType.unknown || notification.commentedEntityId <= 0)
? null
: () {
_navigateToEntity(context, notification.commentedEntityType, notification.commentedEntityId, notification.commentId);
@@ -600,9 +585,11 @@ class _EntityCommentedWidget extends StatelessWidget {
isRead: notification.isRead,
notificationsText: 'Новый комментарий к вашей публикации "${notification.entityTranslatedType}": ${notification.entityName}',
createdAt: notification.createdAt,
onTap: () {
_navigateToEntity(context, notification.entityType, notification.entityId, notification.commentId);
},
onTap: (notification.entityType == CommentedEntityType.unknown || notification.entityId <= 0)
? null
: () {
_navigateToEntity(context, notification.entityType, notification.entityId, notification.commentId);
},
);
}
}