Skip to content
Snippets Groups Projects
Commit 983b0b1e authored by 심재엽's avatar 심재엽
Browse files

feat: 번개모임 참가시, 다른 참가자들한테 푸시 알림

parent 298bd0dd
No related branches found
No related tags found
1 merge request!43배포코드 master브랜치로
......@@ -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);
......
......@@ -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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment