summaryrefslogtreecommitdiffstats
path: root/webapp/utils
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-05-10 07:41:12 -0400
committerGitHub <noreply@github.com>2017-05-10 07:41:12 -0400
commit9625362494888c9423bb6503b7e18557b6b9cc79 (patch)
tree976611e0ee7fff14dd13e044c571c370f5895392 /webapp/utils
parent6e642036f460fb2e28572d46ca29aa81fbc8c8d1 (diff)
downloadchat-9625362494888c9423bb6503b7e18557b6b9cc79.tar.gz
chat-9625362494888c9423bb6503b7e18557b6b9cc79.tar.bz2
chat-9625362494888c9423bb6503b7e18557b6b9cc79.zip
Fix DM getting marked unread from your own message (#6373)
Diffstat (limited to 'webapp/utils')
-rw-r--r--webapp/utils/channel_utils.jsx25
1 files changed, 25 insertions, 0 deletions
diff --git a/webapp/utils/channel_utils.jsx b/webapp/utils/channel_utils.jsx
index 10d06fbe1..1afce39b4 100644
--- a/webapp/utils/channel_utils.jsx
+++ b/webapp/utils/channel_utils.jsx
@@ -5,6 +5,8 @@ const Preferences = Constants.Preferences;
import * as Utils from 'utils/utils.jsx';
import UserStore from 'stores/user_store.jsx';
+import ChannelStore from 'stores/channel_store.jsx';
+import TeamStore from 'stores/team_store.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import LocalizationStore from 'stores/localization_store.jsx';
@@ -251,6 +253,29 @@ export function buildGroupChannelName(channelId) {
return displayName;
}
+export function getCountsStateFromStores(team = TeamStore.getCurrent(), teamMembers = TeamStore.getMyTeamMembers(), unreadCounts = ChannelStore.getUnreadCounts()) {
+ let mentionCount = 0;
+ let messageCount = 0;
+
+ teamMembers.forEach((member) => {
+ if (member.team_id !== TeamStore.getCurrentId()) {
+ mentionCount += (member.mention_count || 0);
+ messageCount += (member.msg_count || 0);
+ }
+ });
+
+ Object.keys(unreadCounts).forEach((chId) => {
+ const channel = ChannelStore.get(chId);
+
+ if (channel && (channel.type === Constants.DM_CHANNEL || channel.type === Constants.GM_CHANNEL || channel.team_id === team.id)) {
+ messageCount += unreadCounts[chId].msgs;
+ mentionCount += unreadCounts[chId].mentions;
+ }
+ });
+
+ return {mentionCount, messageCount};
+}
+
/*
* not exported helpers
*/