From 983b0b1eb03535c3a2d92fffb82087b341e02b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=AC=EC=9E=AC=EC=97=BD?= <jysim0326@ajou.ac.kr> Date: Tue, 10 Dec 2024 03:34:33 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=B2=88=EA=B0=9C=EB=AA=A8=EC=9E=84=20?= =?UTF-8?q?=EC=B0=B8=EA=B0=80=EC=8B=9C,=20=EB=8B=A4=EB=A5=B8=20=EC=B0=B8?= =?UTF-8?q?=EA=B0=80=EC=9E=90=EB=93=A4=ED=95=9C=ED=85=8C=20=ED=91=B8?= =?UTF-8?q?=EC=8B=9C=20=EC=95=8C=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pushServer.js | 44 +++++++++++++++++++++++++++----------- services/meetingService.js | 34 ++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/pushServer.js b/pushServer.js index b57e92d..c280bfd 100644 --- a/pushServer.js +++ b/pushServer.js @@ -71,24 +71,42 @@ async function startPushServer() { channel.consume(meetingQueue, async (msg) => { if (msg !== null) { const event = JSON.parse(msg.content.toString()); - const { meetingTitle, inviterName, inviteeTokens } = event; + const { meetingTitle, inviterName, inviteeTokens, type } = event; console.log('Meeting �몄떆 �뚮┝ �붿껌 �섏떊:', event); console.log("�몄떆 �뚮┝ 蹂대궡�� fcmToken", inviteeTokens); if (inviteeTokens.length > 0) { - const message = { - tokens: inviteeTokens, - notification: { - title: '踰덇컻 紐⑥엫 珥덈�', - body: `${inviterName}�섏씠 ${meetingTitle} 紐⑥엫�� 珥덈��덉뒿�덈떎.`, - }, - data: { - click_action: `${process.env.FRONT_URL}/meeting`, // �대┃ �� �대룞�� URL - }, - android: { priority: 'high' }, - apns: { payload: { aps: { sound: 'default' } } }, - }; + let message; + + // �대깽�� ���낆뿉 �곕씪 �뚮┝ �댁슜 援ъ꽦 + if (type === 'invite') { + message = { + tokens: inviteeTokens, + notification: { + title: '踰덇컻 紐⑥엫 珥덈�', + body: `${inviterName}�섏씠 ${meetingTitle} 踰덇컻紐⑥엫�� 珥덈��덉뒿�덈떎.`, + }, + data: { + click_action: `${process.env.FRONT_URL}/meeting`, // �대┃ �� �대룞�� URL + }, + android: { priority: 'high' }, + apns: { payload: { aps: { sound: 'default' } } }, + }; + } else if (type === 'join') { + message = { + tokens: inviteeTokens, + notification: { + title: `${meetingTitle}`, + body: `${inviterName}�섏씠 ${meetingTitle} 紐⑥엫�� 李멸��덉뒿�덈떎.`, + }, + data: { + click_action: `${process.env.FRONT_URL}/meeting`, // �대┃ �� �대룞�� URL + }, + android: { priority: 'high' }, + apns: { payload: { aps: { sound: 'default' } } }, + }; + } try { const response = await admin.messaging().sendEachForMulticast(message); diff --git a/services/meetingService.js b/services/meetingService.js index 2da1a7e..2d64e75 100644 --- a/services/meetingService.js +++ b/services/meetingService.js @@ -39,13 +39,22 @@ class MeetingService { return totalIdx; } - async sendMeetingPushNotificationRequest(meetingTitle, inviterName, inviteeTokens) { + // async sendMeetingPushNotificationRequest(meetingTitle, inviterName, inviteeTokens) { + // const event = { + // meetingTitle, + // inviterName, + // inviteeTokens, + // }; + // await this.publishToQueue('meeting_push_notifications', event); // meeting_push_notifications �먯뿉 硫붿떆吏� 諛쒗뻾 + // } + async sendMeetingPushNotificationRequest(meetingTitle, inviterName, inviteeTokens, type) { const event = { meetingTitle, inviterName, inviteeTokens, + type, // �대깽�� ���� ('invite' �먮뒗 'join') }; - await this.publishToQueue('meeting_push_notifications', event); // meeting_push_notifications �먯뿉 硫붿떆吏� 諛쒗뻾 + await this.publishToQueue('meeting_push_notifications', event); // �먯뿉 硫붿떆吏� 諛쒗뻾 } @@ -147,7 +156,12 @@ class MeetingService { // RabbitMQ 硫붿떆吏� 諛쒗뻾 (�몄떆 �뚮┝ �붿껌) if (inviteeTokens.length > 0) { - await this.sendMeetingPushNotificationRequest(title, user.name, inviteeTokens); + await this.sendMeetingPushNotificationRequest( + title, + user.name, + inviteeTokens, + 'invite' + ); } const chatRoom = await ChatRooms.findOne({ chatRoomId: chatRoomId }); @@ -312,6 +326,20 @@ class MeetingService { chatRoom.messages.push(joinMessage); + // 湲곗〈 李멸��� FCM �좏겙 媛��몄삤湲� + const otherParticipants = chatRoom.participants.filter(participant => participant.name !== user.name); + const otherParticipantTokens = otherParticipants.flatMap(participant => participant.fcmTokens); + + if (otherParticipantTokens.length > 0) { + // RabbitMQ 硫붿떆吏� 諛쒗뻾 + await this.sendMeetingPushNotificationRequest( + meeting.title, + user.name, + otherParticipantTokens, + 'join' + ); + } + await chatRoom.save(); } -- GitLab