mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
* Add push notification for party activity * Improve inbox notifications * move sendChatPushNotifications method * Fix import * Fix failing test * Improve notification display on iOS * correctly set push notification environment
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import { model as User } from '../models/user';
|
|
import { getUserInfo } from './email';
|
|
import {sendNotification as sendPushNotification} from './pushNotifications';
|
|
|
|
export async function getAuthorEmailFromMessage (message) {
|
|
let authorId = message.uuid;
|
|
|
|
if (authorId === 'system') {
|
|
return 'system';
|
|
}
|
|
|
|
let author = await User.findOne({_id: authorId}, {auth: 1}).exec();
|
|
|
|
if (author) {
|
|
return getUserInfo(author, ['email']).email;
|
|
} else {
|
|
return 'Author Account Deleted';
|
|
}
|
|
}
|
|
|
|
export async function sendChatPushNotifications (user, group, message, translate) {
|
|
let members = await User.find({
|
|
'party._id': group._id,
|
|
_id: {$ne: user._id},
|
|
})
|
|
.select('preferences.pushNotifications preferences.language profile.name pushDevices')
|
|
.exec();
|
|
members.forEach(member => {
|
|
if (member.preferences.pushNotifications.partyActivity !== false) {
|
|
sendPushNotification(
|
|
member,
|
|
{
|
|
title: translate('groupActivityNotificationTitle', {user: message.user, group: group.name}, member.preferences.language),
|
|
message: message.text,
|
|
identifier: 'groupActivity',
|
|
category: 'groupActivity',
|
|
payload: {groupID: group._id, type: group.type, groupName: group.name, message: message.text, timestamp: message.timestamp, senderName: message.user},
|
|
}
|
|
);
|
|
}
|
|
});
|
|
} |