Skip to content

Commit

Permalink
Add new_reply_notification endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
noxethiems committed Dec 7, 2023
1 parent 5e7067f commit db51509
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions identity_socializer/services/push_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,37 @@ async def new_like(

self.send(notification)

async def new_reply(
self,
from_id: str,
to_id: str,
snap: Any,
user_dao: UserDAO,
push_token_dao: PushTokenDAO,
) -> None:
"""Send push notification for new reply."""
username = await user_dao.get_username_by_id(from_id) or "unknown"

# Create and save notification to database
title = "Your snap have a new reply!"
body = f"@{username} replied your snap!"
notif_type = "NewCommentNotification"

self.save_notification(to_id, title, body, notif_type, snap["id"])

# Send push notification to user
push_tokens = await push_token_dao.get_push_tokens_by_user(to_id)

for push_token in push_tokens:
data = {
"screen": notif_type,
"params": {"snap": snap},
}

notification = _create_push_notification(push_token, title, body, data)

self.send(notification)

async def new_follower(
self,
from_id: str,
Expand Down
17 changes: 17 additions & 0 deletions identity_socializer/web/api/notification/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ async def new_like_notification(
)


@router.post("/new_reply", response_model=None)
async def new_reply_notification(
body: NotificationDTO,
user_dao: UserDAO = Depends(),
push_token_dao: PushTokenDAO = Depends(),
push_notifications: PushNotifications = Depends(),
) -> None:
"""Creates a notification for new reply event."""
await push_notifications.new_reply(
body.from_id,
body.to_id,
body.snap,
user_dao,
push_token_dao,
)


@router.post("/new_mention", response_model=None)
async def new_mention_notification(
body: NotificationDTO,
Expand Down

0 comments on commit db51509

Please sign in to comment.