From cc20ffc85f7fb36f267305ae2362ad12d86323a3 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 26 Mar 2023 14:59:03 -0600 Subject: [PATCH] Fix addressed to WFC count --- core/message_area.js | 16 ++++++++++++---- core/new_scan.js | 3 ++- core/stat_log.js | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/core/message_area.js b/core/message_area.js index 7bb13306..11572217 100644 --- a/core/message_area.js +++ b/core/message_area.js @@ -519,8 +519,13 @@ function filterMessageListByReadACS(client, messageList) { }); } -function getNewMessageCountInAreaForUser(userId, areaTag, cb) { - getMessageAreaLastReadId(userId, areaTag, (err, lastMessageId) => { +function getNewMessageCountInAreaForUser( + user, + areaTag, + options = { addrToOnly: false }, + cb +) { + getMessageAreaLastReadId(user.userId, areaTag, (err, lastMessageId) => { lastMessageId = lastMessageId || 0; const filter = { @@ -530,7 +535,9 @@ function getNewMessageCountInAreaForUser(userId, areaTag, cb) { }; if (Message.isPrivateAreaTag(areaTag)) { - filter.privateTagUserId = userId; + filter.privateTagUserId = user.userId; + } else if (options.addrToOnly) { + filter.toUserName = user.username; } Message.findMessages(filter, (err, count) => { @@ -554,8 +561,9 @@ function getNewMessageCountAddressedToUser(client, cb) { getMessageAreaLastReadId(client.user.userId, areaTag, (_, lastMessageId) => { lastMessageId = lastMessageId || 0; // eslint-disable-line no-unused-vars getNewMessageCountInAreaForUser( - client.user.userId, + client.user, areaTag, + { addrToOnly: true }, (err, count) => { newMessageCount += count; return nextAreaTag(err); diff --git a/core/new_scan.js b/core/new_scan.js index 8a0c195c..178f1e34 100644 --- a/core/new_scan.js +++ b/core/new_scan.js @@ -157,8 +157,9 @@ exports.getModule = class NewScanModule extends MenuModule { }, function getNewMessagesCountInArea(callback) { msgArea.getNewMessageCountInAreaForUser( - self.client.user.userId, + self.client.user, currentArea.areaTag, + { addrToOnly: false }, (err, newMessageCount) => { callback(err, newMessageCount); } diff --git a/core/stat_log.js b/core/stat_log.js index 923abe7a..ce67aaf9 100644 --- a/core/stat_log.js +++ b/core/stat_log.js @@ -461,8 +461,9 @@ class StatLog { _refreshUserPrivateMailCount(client) { const MsgArea = require('./message_area'); MsgArea.getNewMessageCountInAreaForUser( - client.user.userId, + client.user, Message.WellKnownAreaTags.Private, + { addrToOnly: false }, (err, count) => { if (!err) { client.user.setProperty(UserProps.NewPrivateMailCount, count);