mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01: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:
@@ -46,6 +46,7 @@
|
||||
"digest.title.month": "Your Monthly Digest",
|
||||
|
||||
"notif.chat.subject": "New chat message received from %1",
|
||||
"notif.chat.public-chat-subject": "New message from %1 in room %2",
|
||||
"notif.chat.cta": "Click here to continue the conversation",
|
||||
"notif.chat.unsub.info": "This chat notification was sent to you due to your subscription settings.",
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"chat.room-id": "Room %1",
|
||||
"chat.chatting_with": "Chat with",
|
||||
"chat.placeholder": "Type chat message here, drag & drop images, press enter to send",
|
||||
"chat.placeholder.mobile": "Type chat message here",
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"replies": "Replies",
|
||||
"chat": "Chats",
|
||||
"group-chat": "Group Chats",
|
||||
"public-chat": "Public Chats",
|
||||
"follows": "Follows",
|
||||
"upvote": "Upvotes",
|
||||
"new-flags": "New Flags",
|
||||
@@ -25,25 +26,34 @@
|
||||
|
||||
|
||||
"new_message_from": "New message from <strong>%1</strong>",
|
||||
"user_posted_in_public_room": "<strong>%1</strong> wrote in <strong><i class=\"fa %2\"></i>%3</strong>",
|
||||
"user_posted_in_public_room_dual": "<strong>%1</strong> and <strong>%2</strong> wrote in <strong><i class=\"fa %3\"></i>%4</strong>",
|
||||
"user_posted_in_public_room_triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> wrote in <strong><i class=\"fa %4\"></i>%5</strong>",
|
||||
"user_posted_in_public_room_multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others wrote in <strong><i class=\"fa %4\"></i>%5</strong>",
|
||||
"upvoted_your_post_in": "<strong>%1</strong> has upvoted your post in <strong>%2</strong>.",
|
||||
"upvoted_your_post_in_dual": "<strong>%1</strong> and <strong>%2</strong> have upvoted your post in <strong>%3</strong>.",
|
||||
"upvoted_your_post_in_multiple": "<strong>%1</strong> and %2 others have upvoted your post in <strong>%3</strong>.",
|
||||
"upvoted_your_post_in_triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> have upvoted your post in <strong>%4</strong>.",
|
||||
"upvoted_your_post_in_multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others have upvoted your post in <strong>%4</strong>.",
|
||||
"moved_your_post": "<strong>%1</strong> has moved your post to <strong>%2</strong>",
|
||||
"moved_your_topic": "<strong>%1</strong> has moved <strong>%2</strong>",
|
||||
"user_flagged_post_in": "<strong>%1</strong> flagged a post in <strong>%2</strong>",
|
||||
"user_flagged_post_in_dual": "<strong>%1</strong> and <strong>%2</strong> flagged a post in <strong>%3</strong>",
|
||||
"user_flagged_post_in_multiple": "<strong>%1</strong> and %2 others flagged a post in <strong>%3</strong>",
|
||||
"user_flagged_post_in_triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a post in <strong>%4</strong>",
|
||||
"user_flagged_post_in_multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a post in <strong>%4</strong>",
|
||||
"user_flagged_user": "<strong>%1</strong> flagged a user profile (%2)",
|
||||
"user_flagged_user_dual": "<strong>%1</strong> and <strong>%2</strong> flagged a user profile (%3)",
|
||||
"user_flagged_user_multiple": "<strong>%1</strong> and %2 others flagged a user profile (%3)",
|
||||
"user_flagged_user_triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> flagged a user profile (%4)",
|
||||
"user_flagged_user_multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others flagged a user profile (%4)",
|
||||
"user_posted_to" : "<strong>%1</strong> has posted a reply to: <strong>%2</strong>",
|
||||
"user_posted_to_dual" : "<strong>%1</strong> and <strong>%2</strong> have posted replies to: <strong>%3</strong>",
|
||||
"user_posted_to_multiple" : "<strong>%1</strong> and %2 others have posted replies to: <strong>%3</strong>",
|
||||
"user_posted_to_triple" : "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> others have posted replies to: <strong>%4</strong>",
|
||||
"user_posted_to_multiple" : "<strong>%1</strong>, <strong>%2</strong> and %3 others have posted replies to: <strong>%4</strong>",
|
||||
"user_posted_topic": "<strong>%1</strong> has posted a new topic: <strong>%2</strong>",
|
||||
"user_edited_post" : "<strong>%1</strong> has edited a post in <strong>%2</strong>",
|
||||
"user_started_following_you": "<strong>%1</strong> started following you.",
|
||||
"user_started_following_you_dual": "<strong>%1</strong> and <strong>%2</strong> started following you.",
|
||||
"user_started_following_you_multiple": "<strong>%1</strong> and %2 others started following you.",
|
||||
"user_started_following_you_triple": "<strong>%1</strong>, <strong>%2</strong> and <strong>%3</strong> started following you.",
|
||||
"user_started_following_you_multiple": "<strong>%1</strong>, <strong>%2</strong> and %3 others started following you.",
|
||||
"new_register": "<strong>%1</strong> sent a registration request.",
|
||||
"new_register_multiple": "There are <strong>%1</strong> registration requests awaiting review.",
|
||||
"flag_assigned_to_you": "<strong>Flag %1</strong> has been assigned to you",
|
||||
@@ -72,6 +82,7 @@
|
||||
"notificationType_follow": "When someone starts following you",
|
||||
"notificationType_new-chat": "When you receive a chat message",
|
||||
"notificationType_new-group-chat": "When you receive a group chat message",
|
||||
"notificationType_new-public-chat": "When you receive a public group chat message",
|
||||
"notificationType_group-invite": "When you receive a group invite",
|
||||
"notificationType_group-leave": "When a user leaves your group",
|
||||
"notificationType_group-request-membership": "When someone requests to join a group you own",
|
||||
|
||||
@@ -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