Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 10시 리마인드 중복 알림 방지 로직 구현 #427

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions functions/scheduler/funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,40 @@ const sendRemind = async () => {
const now = dayjs().add(9, 'hour');
const today = now.format('YYYY-MM-DD');

let remindUsers = await recordDB.getPushRemindUsers(client, today);
const remindUsers = await recordDB.getPushRemindUsers(client, today);

if (remindUsers.length) {
let messages = [];
remindUsers.map((u) => {
if (u.status == 'NONE' || u.status == 'CONSIDER') {
const { title, body, category } = alarmMessage.REMIND_ALERT_NONE(u.roomName);
messages.push(pushAlarm.getMessage(title, body, u.deviceToken, category, null, u.roomId));
} else {
const { title, body, category } = alarmMessage.REMIND_ALERT_DONE(u.roomName);
messages.push(pushAlarm.getMessage(title, body, u.deviceToken, category, null, u.roomId));
}
const messages = [];

/**
* @임시_로직 (10시 리마인드 중복 알림 방지 / deviceToken DISTINCT 처리)
*/
const userIds = [];
const tokenGroups = _.groupBy(remindUsers, 'deviceToken');
const tokens = Object.keys(tokenGroups);
tokens.map((t) => {
const obj = tokenGroups[t][0];
userIds.push(obj.userId);
const { title, body, category } = alarmMessage.REMIND_ALERT_NONE(obj.roomName);
messages.push(pushAlarm.getMessage(title, body, t, category, null, obj.roomId));
});

/**
* @실제_로직
*/
// remindUsers.map((u) => {
// if (u.status == 'NONE' || u.status == 'CONSIDER') {
// const { title, body, category } = alarmMessage.REMIND_ALERT_NONE(u.roomName);
// messages.push(pushAlarm.getMessage(title, body, u.deviceToken, category, null, u.roomId));
// } else {
// const { title, body, category } = alarmMessage.REMIND_ALERT_DONE(u.roomName);
// messages.push(pushAlarm.getMessage(title, body, u.deviceToken, category, null, u.roomId));
// }
// });

pushAlarm.sendMessages(null, null, messages);

const slackMessage = `[REMIND SEND SUCCESS]`;
// const slackMessage = `[REMIND SEND SUCCESS]: To ${.length} users: ${remindUsers.map((u) => u.nickname)}`;
const slackMessage = `[REMIND SEND SUCCESS]: To ${tokens.length} users: ${userIds.sort()}`;
slackAPI.sendMessageToSlack(slackMessage, slackAPI.DEV_WEB_HOOK_ERROR_MONITORING);
return;
}
Expand Down