From eb0fcd3235606cbeb5e092cb1fc8dfcd52f970b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 18 Jul 2023 13:12:06 -0400 Subject: [PATCH] feat: closes #11812, add unread public rooms into digest --- public/language/en-GB/email.json | 2 ++ src/user/digest.js | 16 +++++++++++++--- src/views/emails/digest.tpl | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/public/language/en-GB/email.json b/public/language/en-GB/email.json index 15cbf3cf26..3f8043cc67 100644 --- a/public/language/en-GB/email.json +++ b/public/language/en-GB/email.json @@ -30,6 +30,8 @@ "reset.notify.text1": "We are notifying you that on %1, your password was changed successfully.", "reset.notify.text2": "If you did not authorise this, please notify an administrator immediately.", + "digest.unread-rooms": "Unread rooms", + "digest.room-name-unreadcount": "%1 (%2 unread)", "digest.latest_topics": "Latest topics from %1", "digest.top-topics": "Top topics from %1", "digest.popular-topics": "Popular topics from %1", diff --git a/src/user/digest.js b/src/user/digest.js index d45cf8e576..b07f54d1c3 100644 --- a/src/user/digest.js +++ b/src/user/digest.js @@ -8,6 +8,7 @@ const batch = require('../batch'); const meta = require('../meta'); const user = require('./index'); const topics = require('../topics'); +const messaging = require('../messaging'); const plugins = require('../plugins'); const emailer = require('../emailer'); const utils = require('../utils'); @@ -94,13 +95,16 @@ Digest.send = async function (data) { return; } await Promise.all(userData.map(async (userObj) => { - const [notifications, topics] = await Promise.all([ + const [publicRooms, notifications, topics] = await Promise.all([ + getUnreadPublicRooms(userObj.uid), user.notifications.getUnreadInterval(userObj.uid, data.interval), getTermTopics(data.interval, userObj.uid), ]); const unreadNotifs = notifications.filter(Boolean); - // If there are no notifications and no new topics, don't bother sending a digest - if (!unreadNotifs.length && !topics.top.length && !topics.popular.length && !topics.recent.length) { + // If there are no notifications and no new topics and no unread chats, don't bother sending a digest + if (!unreadNotifs.length && + !topics.top.length && !topics.popular.length && !topics.recent.length && + !publicRooms.length) { return; } @@ -120,6 +124,7 @@ Digest.send = async function (data) { username: userObj.username, userslug: userObj.userslug, notifications: unreadNotifs, + publicRooms: publicRooms, recent: topics.recent, topTopics: topics.top, popularTopics: topics.popular, @@ -212,3 +217,8 @@ async function getTermTopics(term, uid) { }); return { top, popular, recent }; } + +async function getUnreadPublicRooms(uid) { + const publicRooms = await messaging.getPublicRooms(uid, uid); + return publicRooms.filter(r => r && r.unread); +} diff --git a/src/views/emails/digest.tpl b/src/views/emails/digest.tpl index b6d827187c..cd278d6c6f 100644 --- a/src/views/emails/digest.tpl +++ b/src/views/emails/digest.tpl @@ -43,6 +43,26 @@ {{{ end }}} + {{{ if publicRooms.length }}} + + +

[[email:digest.unread-rooms]]

+ + + + {{{ end }}} {{{ if topTopics.length }}}