Skip to content

Commit

Permalink
feat(fcm): enhance chat notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
elskow committed Dec 6, 2024
1 parent 1982676 commit 7bce685
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/common/fcm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class FCMService {
async sendChatNotification(
recipientId: string,
senderName: string,
senderId: string,
message: { content: string; type: MessageType },
roomId: string,
): Promise<void> {
Expand All @@ -35,12 +36,16 @@ export class FCMService {

const notificationMessage = {
notification: {
title: `New message from ${senderName}`,
title: `New message from ${senderName || "Unknown User"}`,
body: truncatedPreview,
},
data: {
type: "chat_message",
roomId,
senderName: senderName || "Unknown User",
senderId: senderId || "",
content: truncatedPreview,
title: `New message from ${senderName || "Unknown User"}`,
click_action: "FLUTTER_NOTIFICATION_CLICK",
},
tokens,
Expand Down
2 changes: 2 additions & 0 deletions src/module/chat/chat.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export class ChatRepository {
.select({
room: chatRooms,
learnerName: learners.name,
learnerId: learners.id,
tutorName: tutors.name,
tutorId: tutors.id,
lastMessage: sql<{ content: string; type: MessageType }>`
(SELECT json_build_object(
'content', content,
Expand Down
1 change: 1 addition & 0 deletions src/module/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class ChatService {
this.deps.fcmService.sendChatNotification(
recipientId,
senderName,
senderId,
message,
roomId,
);
Expand Down

0 comments on commit 7bce685

Please sign in to comment.