mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
Improve handling for sending mention notifications
This commit is contained in:
@@ -513,7 +513,7 @@ schema.methods.getMemberCount = async function getMemberCount () {
|
||||
};
|
||||
|
||||
schema.methods.sendChat = function sendChat (options = {}) {
|
||||
const {message, user, metaData, client, flagCount = 0, info = {}, translate} = options;
|
||||
const {message, user, metaData, client, flagCount = 0, info = {}, translate, mentions, mentionedMembers} = options;
|
||||
let newMessage = messageDefaults(message, user, client, flagCount, info);
|
||||
let newChatMessage = new Chat();
|
||||
newChatMessage = Object.assign(newChatMessage, newMessage);
|
||||
@@ -576,8 +576,29 @@ schema.methods.sendChat = function sendChat (options = {}) {
|
||||
});
|
||||
|
||||
if (this.type === 'party' && user) {
|
||||
sendChatPushNotifications(user, this, newChatMessage, translate);
|
||||
sendChatPushNotifications(user, this, newChatMessage, mentions, translate);
|
||||
}
|
||||
mentionedMembers.forEach((member) => {
|
||||
if (member._id === user._id) return;
|
||||
const pushNotifPrefs = member.preferences.pushNotifications;
|
||||
if (this.type === 'party') {
|
||||
if (pushNotifPrefs.mentionParty !== true) {
|
||||
return;
|
||||
}
|
||||
} else if (member.guilds && member.guilds.includes(this._id)) {
|
||||
if (pushNotifPrefs.mentionJoinedGuild !== true) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (this.privacy !== 'public') {
|
||||
return;
|
||||
}
|
||||
if (pushNotifPrefs.mentionUnjoinedGuild !== true) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendPushNotification(member, {identifier: 'chatMention', title: `${user.profile.name} mentioned you in ${this.name}`, message});
|
||||
});
|
||||
|
||||
return newChatMessage;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user