Always send push notifications in recipients language (#11307)

* Load data needed for members when inviting to quest

* Always send push notifications in recipients language. Fixes #8718

* Remove console.log
This commit is contained in:
Phillip Thelen
2019-08-15 17:00:46 +02:00
committed by Sabe Jones
parent 14106ec5bf
commit 04420aa60e
5 changed files with 11 additions and 13 deletions

View File

@@ -617,7 +617,7 @@ schema.methods.startQuest = async function startQuest (user) {
await User.find({
_id: {$in: Object.keys(this.quest.members)},
})
.select('party.quest party._id items.quests auth preferences.emailNotifications preferences.pushNotifications pushDevices profile.name webhooks')
.select('party.quest party._id items.quests auth preferences.emailNotifications preferences.pushNotifications preferences.language pushDevices profile.name webhooks')
.lean()
.exec()
.then(partyMembers => {
@@ -685,8 +685,6 @@ schema.methods.startQuest = async function startQuest (user) {
await newMessage.save();
const membersToEmail = [];
const pushTitle = quest.text();
const pushMessage = `${shared.i18n.t('questStarted')}: ${quest.text()}`;
// send notifications and webhooks in the background without blocking
members.forEach(member => {
@@ -698,9 +696,10 @@ schema.methods.startQuest = async function startQuest (user) {
// send push notifications and filter users that disabled emails
if (member.preferences.pushNotifications.questStarted !== false) {
const memberLang = member.preferences.language;
sendPushNotification(member, {
title: pushTitle,
message: pushMessage,
title: quest.text(memberLang),
message: `${shared.i18n.t('questStarted', memberLang)}: ${quest.text(memberLang)}`,
identifier: 'questStarted',
});
}