fix mention count bug.

This commit is contained in:
Tatsuya Niwa
2016-02-01 23:58:59 +09:00
parent 49ef1d42e6
commit fc0459ee29
2 changed files with 15 additions and 15 deletions

View File

@@ -26,7 +26,7 @@ var MainPage = React.createClass({
unreadCounts: new Array(this.props.teams.length), unreadCounts: new Array(this.props.teams.length),
mentionCounts: new Array(this.props.teams.length), mentionCounts: new Array(this.props.teams.length),
unreadAtActive: new Array(this.props.teams.length), unreadAtActive: new Array(this.props.teams.length),
mentionAtActive: new Array(this.props.teams.length) mentionAtActiveCounts: new Array(this.props.teams.length)
}; };
}, },
componentDidMount: function() { componentDidMount: function() {
@@ -54,30 +54,32 @@ var MainPage = React.createClass({
var unreadCounts = this.state.unreadCounts; var unreadCounts = this.state.unreadCounts;
var mentionCounts = this.state.mentionCounts; var mentionCounts = this.state.mentionCounts;
var unreadAtActive = this.state.unreadAtActive; var unreadAtActive = this.state.unreadAtActive;
var mentionAtActive = this.state.mentionAtActive; var mentionAtActiveCounts = this.state.mentionAtActiveCounts;
unreadCounts[index] = unreadCount; unreadCounts[index] = unreadCount;
mentionCounts[index] = mentionCount; mentionCounts[index] = mentionCount;
// Never turn on the unreadAtActive flag at current focused tab. // Never turn on the unreadAtActive flag at current focused tab.
if (this.state.key !== index || !remote.getCurrentWindow().isFocused()) { if (this.state.key !== index || !remote.getCurrentWindow().isFocused()) {
unreadAtActive[index] = unreadAtActive[index] || isUnread; unreadAtActive[index] = unreadAtActive[index] || isUnread;
mentionAtActive[index] = mentionAtActive[index] || isMentioned; if (isMentioned) {
mentionAtActiveCounts[index]++;
}
} }
this.setState({ this.setState({
unreadCounts: unreadCounts, unreadCounts: unreadCounts,
mentionCounts: mentionCounts, mentionCounts: mentionCounts,
unreadAtActive: unreadAtActive, unreadAtActive: unreadAtActive,
mentionAtActive: mentionAtActive mentionAtActiveCounts: mentionAtActiveCounts
}); });
this.handleUnreadCountTotalChange(); this.handleUnreadCountTotalChange();
}, },
markReadAtActive: function(index) { markReadAtActive: function(index) {
var unreadAtActive = this.state.unreadAtActive; var unreadAtActive = this.state.unreadAtActive;
var mentionAtActive = this.state.mentionAtActive; var mentionAtActiveCounts = this.state.mentionAtActiveCounts;
unreadAtActive[index] = false; unreadAtActive[index] = false;
mentionAtActive[index] = false; mentionAtActiveCounts[index] = 0;
this.setState({ this.setState({
unreadAtActive: unreadAtActive, unreadAtActive: unreadAtActive,
mentionAtActive: mentionAtActive mentionAtActiveCounts: mentionAtActiveCounts
}); });
this.handleUnreadCountTotalChange(); this.handleUnreadCountTotalChange();
}, },
@@ -94,10 +96,8 @@ var MainPage = React.createClass({
var allMentionCount = this.state.mentionCounts.reduce(function(prev, curr) { var allMentionCount = this.state.mentionCounts.reduce(function(prev, curr) {
return prev + curr; return prev + curr;
}, 0); }, 0);
this.state.mentionAtActive.forEach(function(state) { this.state.mentionAtActiveCounts.forEach(function(count) {
if (state) { allMentionCount += count;
allMentionCount += 1;
}
}); });
this.props.onUnreadCountChange(allUnreadCount, allMentionCount); this.props.onUnreadCountChange(allUnreadCount, allMentionCount);
} }
@@ -125,7 +125,7 @@ var MainPage = React.createClass({
if (this.props.teams.length > 1) { if (this.props.teams.length > 1) {
tabs_row = ( tabs_row = (
<Row> <Row>
<TabBar id="tabBar" teams={ this.props.teams } unreadCounts={ this.state.unreadCounts } mentionCounts={ this.state.mentionCounts } unreadAtActive={ this.state.unreadAtActive } mentionAtActive={ this.state.mentionAtActive } <TabBar id="tabBar" teams={ this.props.teams } unreadCounts={ this.state.unreadCounts } mentionCounts={ this.state.mentionCounts } unreadAtActive={ this.state.unreadAtActive } mentionAtActiveCounts={ this.state.mentionAtActiveCounts }
activeKey={ this.state.key } onSelect={ this.handleSelect }></TabBar> activeKey={ this.state.key } onSelect={ this.handleSelect }></TabBar>
</Row> </Row>
); );
@@ -169,8 +169,8 @@ var TabBar = React.createClass({
if (thisObj.props.mentionCounts[index] > 0) { if (thisObj.props.mentionCounts[index] > 0) {
mentionCount = thisObj.props.mentionCounts[index]; mentionCount = thisObj.props.mentionCounts[index];
} }
if (thisObj.props.mentionAtActive[index] === true) { if (thisObj.props.mentionAtActiveCounts[index] > 0) {
mentionCount += 1; mentionCount += thisObj.props.mentionAtActiveCounts;
} }
var badge; var badge;

View File

@@ -20,7 +20,7 @@ var unreadCountTimer = setInterval(function() {
var mentionCount = 0; var mentionCount = 0;
for (var i = 0; i < elem.length; i++) { for (var i = 0; i < elem.length; i++) {
if (isElementVisible(elem[i])) { if (isElementVisible(elem[i])) {
mentionCount++; mentionCount += Number(elem[i].innerHTML);
} }
} }