2019-10-10 18:11:50 +00:00
|
|
|
import { model as User } from '../models/user'; // eslint-disable-line import/no-cycle
|
|
|
|
|
import { getUserInfo } from './email'; // eslint-disable-line import/no-cycle
|
2019-10-08 14:57:10 +00:00
|
|
|
import { sendNotification as sendPushNotification } from './pushNotifications';
|
2018-02-11 15:35:24 +00:00
|
|
|
|
|
|
|
|
export async function getAuthorEmailFromMessage (message) {
|
2019-10-08 14:57:10 +00:00
|
|
|
const authorId = message.uuid;
|
2018-02-11 15:35:24 +00:00
|
|
|
|
|
|
|
|
if (authorId === 'system') {
|
|
|
|
|
return 'system';
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 14:57:10 +00:00
|
|
|
const author = await User.findOne({ _id: authorId }, { auth: 1 }).exec();
|
2018-02-11 15:35:24 +00:00
|
|
|
|
|
|
|
|
if (author) {
|
|
|
|
|
return getUserInfo(author, ['email']).email;
|
|
|
|
|
}
|
2019-10-08 14:57:10 +00:00
|
|
|
return 'Author Account Deleted';
|
2018-02-11 15:35:24 +00:00
|
|
|
}
|
2019-09-30 17:36:22 +00:00
|
|
|
|
2019-10-01 11:26:38 +00:00
|
|
|
export async function sendChatPushNotifications (user, group, message, mentions, translate) {
|
2019-10-08 14:57:10 +00:00
|
|
|
const members = await User.find({
|
2019-09-30 17:36:22 +00:00
|
|
|
'party._id': group._id,
|
2019-10-08 14:57:10 +00:00
|
|
|
_id: { $ne: user._id },
|
2019-09-30 17:36:22 +00:00
|
|
|
})
|
2019-10-01 11:26:38 +00:00
|
|
|
.select('preferences.pushNotifications preferences.language profile.name pushDevices auth.local.username')
|
2019-09-30 17:36:22 +00:00
|
|
|
.exec();
|
2019-10-18 18:26:12 +00:00
|
|
|
|
2019-09-30 17:36:22 +00:00
|
|
|
members.forEach(member => {
|
|
|
|
|
if (member.preferences.pushNotifications.partyActivity !== false) {
|
2019-10-01 11:26:38 +00:00
|
|
|
if (mentions && mentions.includes(`@${member.auth.local.username}`) && member.preferences.pushNotifications.mentionParty !== false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-09-30 17:36:22 +00:00
|
|
|
sendPushNotification(
|
|
|
|
|
member,
|
|
|
|
|
{
|
2019-10-08 14:57:10 +00:00
|
|
|
title: translate('groupActivityNotificationTitle', { user: message.user, group: group.name }, member.preferences.language),
|
2019-09-30 17:36:22 +00:00
|
|
|
message: message.text,
|
|
|
|
|
identifier: 'groupActivity',
|
|
|
|
|
category: 'groupActivity',
|
2019-10-08 14:57:10 +00:00
|
|
|
payload: {
|
2019-10-10 18:11:50 +00:00
|
|
|
groupID: group._id,
|
|
|
|
|
type: group.type,
|
|
|
|
|
groupName: group.name,
|
|
|
|
|
message: message.text,
|
|
|
|
|
timestamp: message.timestamp,
|
|
|
|
|
senderName: message.user,
|
2019-10-08 14:57:10 +00:00
|
|
|
},
|
|
|
|
|
},
|
2019-09-30 17:36:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-10-08 14:57:10 +00:00
|
|
|
}
|