[WEB-1764] chore: revamp workspace notifications (#4947)

* chore: Initialised store and updated the components

* chore: updated store and types

* chore: updated notifications in the side and updated store

* chore: handled notification center

* chore: updates store request

* chore: notifications filter changed

* chore: updated filter logic and handled bulk read

* chore: handled filter dropdown

* chore: handled ui

* chore: resolved build error

* chore: implemented applied filters

* chore: removed old notifications

* chore: added redirection from sidebar

* chore: updated notification as read when we see the notification preview

* chore: updated read and unread validation

* chore: handled custom snooze dropdown

* chore: resolved git comments

* chore: updated structure and typos

* chore: import and prop changes

* chore: updated avatar props

* chore: updated avatar

* chore: notification unread count on the app sidebar

---------

Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
This commit is contained in:
guru_sainath 2024-06-28 19:00:48 +05:30 committed by GitHub
parent 8d5d0422e9
commit 209dc57307
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
59 changed files with 2337 additions and 1623 deletions

View file

@ -43,8 +43,9 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
# Get query parameters
snoozed = request.GET.get("snoozed", "false")
archived = request.GET.get("archived", "false")
read = request.GET.get("read", "true")
read = request.GET.get("read", None)
type = request.GET.get("type", "all")
q_filters = Q()
notifications = (
Notification.objects.filter(
@ -74,8 +75,12 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
if read == "false":
notifications = notifications.filter(read_at__isnull=True)
if read == "true":
notifications = notifications.filter(read_at__isnull=False)
type = type.split(",")
# Subscribed issues
if type == "watching":
if "subscribed" in type:
issue_ids = (
IssueSubscriber.objects.filter(
workspace__slug=slug, subscriber_id=request.user.id
@ -97,35 +102,32 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
.filter(created=False, assigned=False)
.values_list("issue_id", flat=True)
)
notifications = notifications.filter(
entity_identifier__in=issue_ids,
)
q_filters |= Q(entity_identifier__in=issue_ids)
# Assigned Issues
if type == "assigned":
if "assigned" in type:
issue_ids = IssueAssignee.objects.filter(
workspace__slug=slug, assignee_id=request.user.id
).values_list("issue_id", flat=True)
notifications = notifications.filter(
entity_identifier__in=issue_ids
)
q_filters |= Q(entity_identifier__in=issue_ids)
# Created issues
if type == "created":
if "created" in type:
if WorkspaceMember.objects.filter(
workspace__slug=slug,
member=request.user,
role__lt=15,
is_active=True,
).exists():
notifications = Notification.objects.none()
notifications = notifications.none()
else:
issue_ids = Issue.objects.filter(
workspace__slug=slug, created_by=request.user
).values_list("pk", flat=True)
notifications = notifications.filter(
entity_identifier__in=issue_ids
)
q_filters |= Q(entity_identifier__in=issue_ids)
# Apply the combined Q object filters
notifications = notifications.filter(q_filters)
# Pagination
if request.GET.get("per_page", False) and request.GET.get(
@ -200,11 +202,12 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
class UnreadNotificationEndpoint(BaseAPIView):
def get(self, request, slug):
# Watching Issues Count
watching_issues_count = Notification.objects.filter(
subscribed_issues_count = Notification.objects.filter(
workspace__slug=slug,
receiver_id=request.user.id,
read_at__isnull=True,
archived_at__isnull=True,
snoozed_till__isnull=True,
entity_identifier__in=IssueSubscriber.objects.filter(
workspace__slug=slug, subscriber_id=request.user.id
).values_list("issue_id", flat=True),
@ -216,6 +219,7 @@ class UnreadNotificationEndpoint(BaseAPIView):
receiver_id=request.user.id,
read_at__isnull=True,
archived_at__isnull=True,
snoozed_till__isnull=True,
entity_identifier__in=IssueAssignee.objects.filter(
workspace__slug=slug, assignee_id=request.user.id
).values_list("issue_id", flat=True),
@ -227,6 +231,7 @@ class UnreadNotificationEndpoint(BaseAPIView):
receiver_id=request.user.id,
read_at__isnull=True,
archived_at__isnull=True,
snoozed_till__isnull=True,
entity_identifier__in=Issue.objects.filter(
workspace__slug=slug, created_by=request.user
).values_list("pk", flat=True),
@ -234,7 +239,7 @@ class UnreadNotificationEndpoint(BaseAPIView):
return Response(
{
"watching_issues": watching_issues_count,
"subscribed_issues": subscribed_issues_count,
"my_issues": my_issues_count,
"created_issues": created_issues_count,
},