diff --git a/pushServer.js b/pushServer.js index b57e92dae5da5eb4d37d6e73390a158f70198e90..c280bfdb9e7fcfb2a54be3ca31aa62b9324afe89 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 2da1a7e88bcdc0ccd1b82c74fd1133c2b1725e41..2d64e7505efc92d0c8dc27d8aa00fb988666fa02 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(); }