Strip markdown from push notifications
This commit is contained in:
@@ -35,6 +35,7 @@ export async function sendChatPushNotifications (user, group, message, mentions,
|
||||
{
|
||||
title: translate('groupActivityNotificationTitle', { user: message.user, group: group.name }, member.preferences.language),
|
||||
message: message.text,
|
||||
isUserGenerated: true,
|
||||
identifier: 'groupActivity',
|
||||
category: 'groupActivity',
|
||||
payload: {
|
||||
|
||||
@@ -24,6 +24,7 @@ export async function sentMessage (sender, receiver, message, translate) {
|
||||
receiver.preferences.language,
|
||||
),
|
||||
message,
|
||||
isUserGenerated: true,
|
||||
identifier: 'newPM',
|
||||
category: 'newPM',
|
||||
payload: { replyTo: sender._id, senderName, message },
|
||||
|
||||
@@ -3,6 +3,7 @@ import nconf from 'nconf';
|
||||
import apn from 'apn';
|
||||
import gcmLib from 'node-gcm'; // works with FCM notifications too
|
||||
import logger from './logger';
|
||||
import md from 'habitica-markdown';
|
||||
|
||||
const FCM_API_KEY = nconf.get('PUSH_CONFIGS_FCM_SERVER_API_KEY');
|
||||
|
||||
@@ -32,6 +33,13 @@ function sendNotification (user, details = {}) {
|
||||
if (!details.title) throw new Error('details.title is required.');
|
||||
if (!details.message) throw new Error('details.message is required.');
|
||||
|
||||
let title = details.title
|
||||
let message = details.message
|
||||
if (details.isUserGenerated) {
|
||||
title = md.render(title).replace(/<[^>]+>/g, '').replace(/\n$/, '')
|
||||
message = md.render(details.message).replace(/<[^>]+>/g, '').replace(/\n$/, '')
|
||||
}
|
||||
|
||||
const payload = details.payload ? details.payload : {};
|
||||
payload.identifier = details.identifier;
|
||||
|
||||
@@ -39,8 +47,8 @@ function sendNotification (user, details = {}) {
|
||||
switch (pushDevice.type) { // eslint-disable-line default-case
|
||||
case 'android':
|
||||
// Required for fcm to be received in background
|
||||
payload.title = details.title;
|
||||
payload.body = details.message;
|
||||
payload.title = title;
|
||||
payload.body = message;
|
||||
|
||||
if (fcmSender) {
|
||||
const message = new gcmLib.Message({
|
||||
@@ -57,8 +65,8 @@ function sendNotification (user, details = {}) {
|
||||
if (apnProvider) {
|
||||
const notification = new apn.Notification({
|
||||
alert: {
|
||||
title: details.title,
|
||||
body: details.message,
|
||||
title: title,
|
||||
body: message,
|
||||
},
|
||||
sound: 'default',
|
||||
category: details.category,
|
||||
|
||||
@@ -634,7 +634,7 @@ schema.methods.sendChat = function sendChat (options = {}) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendPushNotification(member, { identifier: 'chatMention', title: `${user.profile.name} mentioned you in ${this.name}`, message });
|
||||
sendPushNotification(member, { identifier: 'chatMention', title: `${user.profile.name} mentioned you in ${this.name}`, message, isUserGenerated: true });
|
||||
});
|
||||
}
|
||||
return newChatMessage;
|
||||
|
||||
Reference in New Issue
Block a user