diff --git a/public/language/en-GB/email.json b/public/language/en-GB/email.json index 3f8043cc67..3b6709697e 100644 --- a/public/language/en-GB/email.json +++ b/public/language/en-GB/email.json @@ -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.", diff --git a/public/language/en-GB/modules.json b/public/language/en-GB/modules.json index 0fd767d049..f952a5f2d8 100644 --- a/public/language/en-GB/modules.json +++ b/public/language/en-GB/modules.json @@ -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", diff --git a/public/language/en-GB/notifications.json b/public/language/en-GB/notifications.json index c4beb75c30..133617d9de 100644 --- a/public/language/en-GB/notifications.json +++ b/public/language/en-GB/notifications.json @@ -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 %1", + "user_posted_in_public_room": "%1 wrote in %3", + "user_posted_in_public_room_dual": "%1 and %2 wrote in %4", + "user_posted_in_public_room_triple": "%1, %2 and %3 wrote in %5", + "user_posted_in_public_room_multiple": "%1, %2 and %3 others wrote in %5", "upvoted_your_post_in": "%1 has upvoted your post in %2.", "upvoted_your_post_in_dual": "%1 and %2 have upvoted your post in %3.", - "upvoted_your_post_in_multiple": "%1 and %2 others have upvoted your post in %3.", + "upvoted_your_post_in_triple": "%1, %2 and %3 have upvoted your post in %4.", + "upvoted_your_post_in_multiple": "%1, %2 and %3 others have upvoted your post in %4.", "moved_your_post": "%1 has moved your post to %2", "moved_your_topic": "%1 has moved %2", "user_flagged_post_in": "%1 flagged a post in %2", "user_flagged_post_in_dual": "%1 and %2 flagged a post in %3", - "user_flagged_post_in_multiple": "%1 and %2 others flagged a post in %3", + "user_flagged_post_in_triple": "%1, %2 and %3 flagged a post in %4", + "user_flagged_post_in_multiple": "%1, %2 and %3 others flagged a post in %4", "user_flagged_user": "%1 flagged a user profile (%2)", "user_flagged_user_dual": "%1 and %2 flagged a user profile (%3)", - "user_flagged_user_multiple": "%1 and %2 others flagged a user profile (%3)", + "user_flagged_user_triple": "%1, %2 and %3 flagged a user profile (%4)", + "user_flagged_user_multiple": "%1, %2 and %3 others flagged a user profile (%4)", "user_posted_to" : "%1 has posted a reply to: %2", "user_posted_to_dual" : "%1 and %2 have posted replies to: %3", - "user_posted_to_multiple" : "%1 and %2 others have posted replies to: %3", + "user_posted_to_triple" : "%1, %2 and %3 others have posted replies to: %4", + "user_posted_to_multiple" : "%1, %2 and %3 others have posted replies to: %4", "user_posted_topic": "%1 has posted a new topic: %2", "user_edited_post" : "%1 has edited a post in %2", "user_started_following_you": "%1 started following you.", "user_started_following_you_dual": "%1 and %2 started following you.", - "user_started_following_you_multiple": "%1 and %2 others started following you.", + "user_started_following_you_triple": "%1, %2 and %3 started following you.", + "user_started_following_you_multiple": "%1, %2 and %3 others started following you.", "new_register": "%1 sent a registration request.", "new_register_multiple": "There are %1 registration requests awaiting review.", "flag_assigned_to_you": "Flag %1 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", diff --git a/src/controllers/accounts/notifications.js b/src/controllers/accounts/notifications.js index c059aa4283..ff9a21a550 100644 --- a/src/controllers/accounts/notifications.js +++ b/src/controllers/accounts/notifications.js @@ -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' }, ]; diff --git a/src/messaging/notifications.js b/src/messaging/notifications.js index 2295dcd58a..b790649416 100644 --- a/src/messaging/notifications.js +++ b/src/messaging/notifications.js @@ -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); } } diff --git a/src/notifications.js b/src/notifications.js index b4a8aeff63..85fd2be0e1 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -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;