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

@@ -79,7 +79,7 @@ api.inviteToQuest = {
'party._id': group._id, 'party._id': group._id,
_id: {$ne: user._id}, _id: {$ne: user._id},
}) })
.select('auth.facebook auth.google auth.local preferences.emailNotifications profile.name pushDevices') .select('auth.facebook auth.google auth.local preferences.emailNotifications preferences.pushNotifications preferences.language profile.name pushDevices')
.exec(); .exec();
group.markModified('quest'); group.markModified('quest');
@@ -124,12 +124,11 @@ api.inviteToQuest = {
sendPushNotification( sendPushNotification(
member, member,
{ {
title: res.t('questInvitationTitle'), title: res.t('questInvitationTitle', member.preferences.language),
message: res.t('questInvitationInfo', {quest: quest.text(req.language)}), message: res.t('questInvitationInfo', {quest: quest.text(member.preferences.language)}, member.preferences.language),
identifier: 'questInvitation', identifier: 'questInvitation',
category: 'questInvitation', category: 'questInvitation',
} }
); );
} }

View File

@@ -18,8 +18,8 @@ export async function sentMessage (sender, receiver, message, translate) {
sendPushNotification( sendPushNotification(
receiver, receiver,
{ {
title: translate('newPM'), title: translate('newPM', receiver.preferences.language),
message: translate('newPMInfo', {name: getUserInfo(sender, ['name']).name, message}), message: translate('newPMInfo', {name: getUserInfo(sender, ['name']).name, message}, receiver.preferences.language),
identifier: 'newPM', identifier: 'newPM',
category: 'newPM', category: 'newPM',
payload: {replyTo: sender._id}, payload: {replyTo: sender._id},

View File

@@ -25,7 +25,7 @@ function sendInvitePushNotification (userToInvite, groupLabel, group, publicGuil
userToInvite, userToInvite,
{ {
title: group.name, title: group.name,
message: res.t(identifier), message: res.t(identifier, userToInvite.preferences.language),
identifier, identifier,
payload: {groupID: group._id, publicGuild}, payload: {groupID: group._id, publicGuild},
} }

View File

@@ -346,7 +346,7 @@ schema.methods.closeChal = async function closeChal (broken = {}) {
sendPushNotification(savedWinner, sendPushNotification(savedWinner,
{ {
title: challenge.name, title: challenge.name,
message: shared.i18n.t('wonChallenge'), message: shared.i18n.t('wonChallenge', savedWinner.preferences.language),
identifier: 'wonChallenge', identifier: 'wonChallenge',
}); });
} }

View File

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