diff --git a/apiserver/plane/api/views/notification.py b/apiserver/plane/api/views/notification.py index 6c3f3587b..83758484b 100644 --- a/apiserver/plane/api/views/notification.py +++ b/apiserver/plane/api/views/notification.py @@ -9,7 +9,7 @@ from sentry_sdk import capture_exception # Module imports from .base import BaseViewSet -from plane.db.models import Notification +from plane.db.models import Notification, IssueAssignee, IssueSubscriber, Issue from plane.api.serializers import NotificationSerializer @@ -30,12 +30,37 @@ class NotificationViewSet(BaseViewSet): def list(self, request, slug): try: - order_by = request.GET.get("ordeer_by", "-created_at") + order_by = request.GET.get("order_by", "-created_at") snoozed = request.GET.get("snoozed", "false") + + # Filter type + type = request.GET.get("type", "all") + notifications = Notification.objects.filter( - workspace__slug=slug, receiver=request.user + workspace__slug=slug, receiver_id=request.user.id ).order_by(order_by) + # Subscribed issues + if type == "watching": + issue_ids = IssueSubscriber.objects.filter( + workspace__slug=slug, subsriber_id=request.user.id + ).values_list("issue_id", flat=True) + notifications = notifications.filter(entity_id__in=issue_ids) + + # Assigned Issues + if type == "assigned": + issue_ids = IssueAssignee.objects.filter( + workspace__slug=slug, assignee_id=request.user.id + ).values_list("issue_id", flat=True) + notifications = notifications.filter(entity_id__in=issue_ids) + + # Created issues + if type == "created": + issue_ids = Issue.objects.filter( + workspace__slug=slug, created_by=request.user + ).values_list("pk", flat=True) + notifications = notifications.filter(entity_id__in=issue_ids) + if snoozed == "false": notifications = notifications.filter( Q(snoozed_till__gte=timezone.now()) | Q(snoozed_till__isnull=True), diff --git a/apiserver/plane/bgtasks/issue_activites_task.py b/apiserver/plane/bgtasks/issue_activites_task.py index 78be2ae06..d5992256e 100644 --- a/apiserver/plane/bgtasks/issue_activites_task.py +++ b/apiserver/plane/bgtasks/issue_activites_task.py @@ -1034,6 +1034,9 @@ def issue_activity( issue_subscribers = issue_subscribers + issue_assignees + if issue.created_by_id: + issue_subscribers = issue_subscribers + [issue.created_by_id] + issue = Issue.objects.get(project=project, pk=issue_id) for subscriber in issue_subscribers: for issue_activity in issue_activities_created: