Dismiss a notification for the current user.
(self, request, pk=None)
| 667 | |
| 668 | @action(detail=True, methods=['post'], url_path='dismiss') |
| 669 | def dismiss(self, request, pk=None): |
| 670 | """Dismiss a notification for the current user.""" |
| 671 | notification = self.get_object() |
| 672 | action_taken = request.data.get('action_taken', None) |
| 673 | |
| 674 | dismissal, created = NotificationDismissal.objects.get_or_create( |
| 675 | user=request.user, |
| 676 | notification=notification, |
| 677 | defaults={'action_taken': action_taken} |
| 678 | ) |
| 679 | |
| 680 | if not created and action_taken: |
| 681 | dismissal.action_taken = action_taken |
| 682 | dismissal.save() |
| 683 | |
| 684 | return Response({ |
| 685 | 'success': True, |
| 686 | 'message': 'Notification dismissed', |
| 687 | 'notification_key': notification.notification_key |
| 688 | }) |
| 689 | |
| 690 | @action(detail=False, methods=['post'], url_path='dismiss-all') |
| 691 | def dismiss_all(self, request): |