mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-26 08:49:55 +02:00
feat: add new notif type for public rooms
change notification text to display more users * user1 wrote in general * user1 and user2 wrote in general * user1, user2 and user3 wrote in general * user1. user2 and 2 others wrote in general
This commit is contained in:
@@ -14,6 +14,7 @@ notificationsController.get = async function (req, res, next) {
|
||||
{ name: '[[notifications:replies]]', filter: 'new-reply' },
|
||||
{ name: '[[notifications:chat]]', filter: 'new-chat' },
|
||||
{ name: '[[notifications:group-chat]]', filter: 'new-group-chat' },
|
||||
{ name: '[[notifications:public-chat]]', filter: 'new-public-chat' },
|
||||
{ name: '[[notifications:follows]]', filter: 'follow' },
|
||||
{ name: '[[notifications:upvote]]', filter: 'upvote' },
|
||||
];
|
||||
|
||||
@@ -100,7 +100,7 @@ module.exports = function (Messaging) {
|
||||
|
||||
const [settings, roomData] = await Promise.all([
|
||||
db.getObject(`chat:room:${roomId}:notification:settings`),
|
||||
Messaging.getRoomData(roomId, ['notificationSetting']),
|
||||
Messaging.getRoomData(roomId),
|
||||
]);
|
||||
const roomDefault = roomData.notificationSetting;
|
||||
const uidsToNotify = [];
|
||||
@@ -121,7 +121,7 @@ module.exports = function (Messaging) {
|
||||
if (uidsToNotify.length) {
|
||||
const { displayname } = messageObj.fromUser;
|
||||
const isGroupChat = await Messaging.isGroupChat(roomId);
|
||||
const notification = await notifications.create({
|
||||
const notifData = {
|
||||
type: isGroupChat ? 'new-group-chat' : 'new-chat',
|
||||
subject: `[[email:notif.chat.subject, ${displayname}]]`,
|
||||
bodyShort: `[[notifications:new_message_from, ${displayname}]]`,
|
||||
@@ -129,7 +129,18 @@ module.exports = function (Messaging) {
|
||||
nid: `chat_${roomId}_${fromUid}`,
|
||||
from: fromUid,
|
||||
path: `/chats/${messageObj.roomId}`,
|
||||
});
|
||||
};
|
||||
if (roomData.public) {
|
||||
const icon = Messaging.getRoomIcon(roomData);
|
||||
const roomName = roomData.roomName || `[[modules:chat.room-id, ${roomId}]]`;
|
||||
notifData.type = 'new-public-chat';
|
||||
notifData.roomName = roomName;
|
||||
notifData.roomIcon = icon;
|
||||
notifData.subject = `[[email:notif.chat.public-chat-subject, ${displayname}, ${roomName}]]`;
|
||||
notifData.bodyShort = `[[notifications:user_posted_in_public_room, ${displayname}, ${icon}, ${roomName}]]`;
|
||||
notifData.mergeId = `notifications:user_posted_in_public_room|${roomId}`;
|
||||
}
|
||||
const notification = await notifications.create(notifData);
|
||||
await notifications.push(notification, uidsToNotify);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ Notifications.baseTypes = [
|
||||
'notificationType_follow',
|
||||
'notificationType_new-chat',
|
||||
'notificationType_new-group-chat',
|
||||
'notificationType_new-public-chat',
|
||||
'notificationType_group-invite',
|
||||
'notificationType_group-leave',
|
||||
'notificationType_group-request-membership',
|
||||
@@ -365,6 +366,7 @@ Notifications.merge = async function (notifications) {
|
||||
'notifications:user_posted_to',
|
||||
'notifications:user_flagged_post_in',
|
||||
'notifications:user_flagged_user',
|
||||
'notifications:user_posted_in_public_room',
|
||||
'new_register',
|
||||
'post-queue',
|
||||
];
|
||||
@@ -386,6 +388,14 @@ Notifications.merge = async function (notifications) {
|
||||
}, []);
|
||||
|
||||
differentiators.forEach((differentiator) => {
|
||||
function typeFromUsernames(usernames) {
|
||||
if (usernames.length === 2) {
|
||||
return 'dual';
|
||||
} else if (usernames.length === 3) {
|
||||
return 'triple';
|
||||
}
|
||||
return 'multiple';
|
||||
}
|
||||
let set;
|
||||
if (differentiator === 0 && differentiators.length === 1) {
|
||||
set = isolated;
|
||||
@@ -397,8 +407,19 @@ Notifications.merge = async function (notifications) {
|
||||
if (modifyIndex === -1 || set.length === 1) {
|
||||
return notifications;
|
||||
}
|
||||
|
||||
const notifObj = notifications[modifyIndex];
|
||||
switch (mergeId) {
|
||||
case 'notifications:user_posted_in_public_room': {
|
||||
const usernames = _.uniq(set.map(notifObj => notifObj && notifObj.user && notifObj.user.displayname));
|
||||
if (usernames.length === 2 || usernames.length === 3) {
|
||||
notifObj.bodyShort = `[[${mergeId}_${typeFromUsernames(usernames)}, ${usernames.join(', ')}, ${notifObj.roomIcon}, ${notifObj.roomName}]]`;
|
||||
} else if (usernames.length > 3) {
|
||||
notifObj.bodyShort = `[[${mergeId}_${typeFromUsernames(usernames)}, ${usernames.slice(0, 2).join(', ')}, ${usernames.length - 2}, ${notifObj.roomIcon}, ${notifObj.roomName}]]`;
|
||||
}
|
||||
|
||||
notifObj.path = set[set.length - 1].path;
|
||||
break;
|
||||
}
|
||||
case 'notifications:upvoted_your_post_in':
|
||||
case 'notifications:user_started_following_you':
|
||||
case 'notifications:user_posted_to':
|
||||
@@ -411,10 +432,10 @@ Notifications.merge = async function (notifications) {
|
||||
let titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
|
||||
titleEscaped = titleEscaped ? (`, ${titleEscaped}`) : '';
|
||||
|
||||
if (numUsers === 2) {
|
||||
notifications[modifyIndex].bodyShort = `[[${mergeId}_dual, ${usernames.join(', ')}${titleEscaped}]]`;
|
||||
if (numUsers === 2 || numUsers === 3) {
|
||||
notifications[modifyIndex].bodyShort = `[[${mergeId}_${typeFromUsernames(usernames)}, ${usernames.join(', ')}${titleEscaped}]]`;
|
||||
} else if (numUsers > 2) {
|
||||
notifications[modifyIndex].bodyShort = `[[${mergeId}_multiple, ${usernames[0]}, ${numUsers - 1}${titleEscaped}]]`;
|
||||
notifications[modifyIndex].bodyShort = `[[${mergeId}_${typeFromUsernames(usernames)}, ${usernames.slice(0, 2).join(', ')}, ${numUsers - 2}${titleEscaped}]]`;
|
||||
}
|
||||
|
||||
notifications[modifyIndex].path = set[set.length - 1].path;
|
||||
|
||||
Reference in New Issue
Block a user