mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
Add push notification for party activity (#11319)
* 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
This commit is contained in:
committed by
Matteo Pagliazzi
parent
f3fb09f4f9
commit
bbbe0cca09
@@ -487,5 +487,6 @@
|
|||||||
"recurringCompletion": "None - Group task does not complete",
|
"recurringCompletion": "None - Group task does not complete",
|
||||||
"singleCompletion": "Single - Completes when any assigned user finishes",
|
"singleCompletion": "Single - Completes when any assigned user finishes",
|
||||||
"allAssignedCompletion": "All - Completes when all assigned users finish",
|
"allAssignedCompletion": "All - Completes when all assigned users finish",
|
||||||
"suggestedGroup": "Suggested because you’re new to Habitica."
|
"suggestedGroup": "Suggested because you’re new to Habitica.",
|
||||||
|
"groupActivityNotificationTitle": "<%= user %> posted in <%= group %>"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import {
|
|||||||
import { removeFromArray } from '../../libs/collectionManipulators';
|
import { removeFromArray } from '../../libs/collectionManipulators';
|
||||||
import { getUserInfo, getGroupUrl, sendTxn } from '../../libs/email';
|
import { getUserInfo, getGroupUrl, sendTxn } from '../../libs/email';
|
||||||
import slack from '../../libs/slack';
|
import slack from '../../libs/slack';
|
||||||
import { getAuthorEmailFromMessage } from '../../libs/chat';
|
|
||||||
import { chatReporterFactory } from '../../libs/chatReporting/chatReporterFactory';
|
import { chatReporterFactory } from '../../libs/chatReporting/chatReporterFactory';
|
||||||
|
import { getAuthorEmailFromMessage} from '../../libs/chat';
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
import bannedWords from '../../libs/bannedWords';
|
import bannedWords from '../../libs/bannedWords';
|
||||||
import guildsAllowingBannedWords from '../../libs/guildsAllowingBannedWords';
|
import guildsAllowingBannedWords from '../../libs/guildsAllowingBannedWords';
|
||||||
@@ -223,7 +223,7 @@ api.postChat = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const newChatMessage = group.sendChat({message: req.body.message, user, flagCount, metaData: null, client});
|
const newChatMessage = group.sendChat({message: req.body.message, user, flagCount, metaData: null, client, translate: res.t});
|
||||||
let toSave = [newChatMessage.save()];
|
let toSave = [newChatMessage.save()];
|
||||||
|
|
||||||
if (group.type === 'party') {
|
if (group.type === 'party') {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { model as User } from '../models/user';
|
import { model as User } from '../models/user';
|
||||||
import { getUserInfo } from './email';
|
import { getUserInfo } from './email';
|
||||||
|
import {sendNotification as sendPushNotification} from './pushNotifications';
|
||||||
|
|
||||||
export async function getAuthorEmailFromMessage (message) {
|
export async function getAuthorEmailFromMessage (message) {
|
||||||
let authorId = message.uuid;
|
let authorId = message.uuid;
|
||||||
@@ -16,3 +17,26 @@ export async function getAuthorEmailFromMessage (message) {
|
|||||||
return 'Author Account Deleted';
|
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},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -6,10 +6,11 @@ const PM_PER_PAGE = 10;
|
|||||||
|
|
||||||
export async function sentMessage (sender, receiver, message, translate) {
|
export async function sentMessage (sender, receiver, message, translate) {
|
||||||
const messageSent = await sender.sendMessage(receiver, { receiverMsg: message });
|
const messageSent = await sender.sendMessage(receiver, { receiverMsg: message });
|
||||||
|
const senderName = getUserInfo(sender, ['name']).name;
|
||||||
|
|
||||||
if (receiver.preferences.emailNotifications.newPM !== false) {
|
if (receiver.preferences.emailNotifications.newPM !== false) {
|
||||||
sendTxnEmail(receiver, 'new-pm', [
|
sendTxnEmail(receiver, 'new-pm', [
|
||||||
{name: 'SENDER', content: getUserInfo(sender, ['name']).name},
|
{name: 'SENDER', content: senderName},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ export async function sentMessage (sender, receiver, message, translate) {
|
|||||||
message,
|
message,
|
||||||
identifier: 'newPM',
|
identifier: 'newPM',
|
||||||
category: 'newPM',
|
category: 'newPM',
|
||||||
payload: {replyTo: sender._id},
|
payload: {replyTo: sender._id, senderName, message},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import amazonPayments from '../libs/payments/amazon';
|
|||||||
import stripePayments from '../libs/payments/stripe';
|
import stripePayments from '../libs/payments/stripe';
|
||||||
import { getGroupChat, translateMessage } from '../libs/chat/group-chat';
|
import { getGroupChat, translateMessage } from '../libs/chat/group-chat';
|
||||||
import { model as UserNotification } from './userNotification';
|
import { model as UserNotification } from './userNotification';
|
||||||
|
import { sendChatPushNotifications } from '../libs/chat';
|
||||||
|
|
||||||
const questScrolls = shared.content.quests;
|
const questScrolls = shared.content.quests;
|
||||||
const questSeriesAchievements = shared.content.questSeriesAchievements;
|
const questSeriesAchievements = shared.content.questSeriesAchievements;
|
||||||
@@ -512,7 +513,7 @@ schema.methods.getMemberCount = async function getMemberCount () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
schema.methods.sendChat = function sendChat (options = {}) {
|
schema.methods.sendChat = function sendChat (options = {}) {
|
||||||
const {message, user, metaData, client, flagCount = 0, info = {}} = options;
|
const {message, user, metaData, client, flagCount = 0, info = {}, translate} = options;
|
||||||
let newMessage = messageDefaults(message, user, client, flagCount, info);
|
let newMessage = messageDefaults(message, user, client, flagCount, info);
|
||||||
let newChatMessage = new Chat();
|
let newChatMessage = new Chat();
|
||||||
newChatMessage = Object.assign(newChatMessage, newMessage);
|
newChatMessage = Object.assign(newChatMessage, newMessage);
|
||||||
@@ -574,6 +575,10 @@ schema.methods.sendChat = function sendChat (options = {}) {
|
|||||||
User.update(query, lastSeenUpdateAddNew, {multi: true}).exec();
|
User.update(query, lastSeenUpdateAddNew, {multi: true}).exec();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.type === 'party' && user) {
|
||||||
|
sendChatPushNotifications(user, this, newChatMessage, translate);
|
||||||
|
}
|
||||||
|
|
||||||
return newChatMessage;
|
return newChatMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -503,6 +503,7 @@ let schema = new Schema({
|
|||||||
questStarted: {$type: Boolean, default: true},
|
questStarted: {$type: Boolean, default: true},
|
||||||
invitedQuest: {$type: Boolean, default: true},
|
invitedQuest: {$type: Boolean, default: true},
|
||||||
majorUpdates: {$type: Boolean, default: true},
|
majorUpdates: {$type: Boolean, default: true},
|
||||||
|
partyActivity: {$type: Boolean, default: true},
|
||||||
},
|
},
|
||||||
suppressModals: {
|
suppressModals: {
|
||||||
levelUp: {$type: Boolean, default: false},
|
levelUp: {$type: Boolean, default: false},
|
||||||
|
|||||||
Reference in New Issue
Block a user