Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Add a notification for new messages on mobile (#5179) (#5234)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudloff authored and enahum committed Feb 7, 2017
1 parent 6dac8f7 commit f98308a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions components/notify_counts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import ChannelStore from 'stores/channel_store.jsx';
import TeamStore from 'stores/team_store.jsx';

function getCountsStateFromStores() {
let count = 0;
let mentionCount = 0;
let messageCount = 0;
const teamMembers = TeamStore.getMyTeamMembers();
const channels = ChannelStore.getAll();
const members = ChannelStore.getMyMembers();

teamMembers.forEach((member) => {
if (member.team_id !== TeamStore.getCurrentId()) {
count += (member.mention_count || 0);
mentionCount += (member.mention_count || 0);
messageCount += (member.msg_count || 0);
}
});

Expand All @@ -24,13 +26,16 @@ function getCountsStateFromStores() {
}

if (channel.type === 'D') {
count += channel.total_msg_count - channelMember.msg_count;
mentionCount += channel.total_msg_count - channelMember.msg_count;
} else if (channelMember.mention_count > 0) {
count += channelMember.mention_count;
mentionCount += channelMember.mention_count;
}
if (channelMember.notify_props.mark_unread !== 'mention' && channel.total_msg_count - channelMember.msg_count > 0) {
messageCount += 1;
}
});

return {count};
return {mentionCount, messageCount};
}

import React from 'react';
Expand Down Expand Up @@ -63,8 +68,10 @@ export default class NotifyCounts extends React.Component {
}
}
render() {
if (this.state.count) {
return <span className='badge badge-notify'>{this.state.count}</span>;
if (this.state.mentionCount) {
return <span className='badge badge-notify'>{this.state.mentionCount}</span>;
} else if (this.state.messageCount) {
return <span className='badge badge-notify'>{'•'}</span>;
}
return null;
}
Expand Down

0 comments on commit f98308a

Please sign in to comment.