Show mention count badge and unread * badge.
This commit is contained in:
@@ -23,7 +23,8 @@ var MainPage = React.createClass({
|
|||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
key: 0,
|
key: 0,
|
||||||
unreadCounts: new Array(this.props.teams.length)
|
unreadCounts: new Array(this.props.teams.length),
|
||||||
|
mentionCounts: new Array(this.props.teams.length)
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
@@ -44,17 +45,23 @@ var MainPage = React.createClass({
|
|||||||
key: key
|
key: key
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleUnreadCountChange: function(index, count) {
|
handleUnreadCountChange: function(index, unreadCount, mentionCount) {
|
||||||
var counts = this.state.unreadCounts;
|
var unreadCounts = this.state.unreadCounts;
|
||||||
counts[index] = count;
|
var mentionCounts = this.state.mentionCounts;
|
||||||
|
unreadCounts[index] = unreadCount;
|
||||||
|
mentionCounts[index] = mentionCount;
|
||||||
this.setState({
|
this.setState({
|
||||||
unreadCounts: counts
|
unreadCounts: unreadCounts,
|
||||||
|
mentionCounts: mentionCounts
|
||||||
});
|
});
|
||||||
if (this.props.onUnreadCountChange) {
|
if (this.props.onUnreadCountChange) {
|
||||||
var c = counts.reduce(function(prev, curr) {
|
var allUnreadCount = unreadCounts.reduce(function(prev, curr) {
|
||||||
return prev + curr;
|
return prev + curr;
|
||||||
});
|
});
|
||||||
this.props.onUnreadCountChange(c);
|
var allMentionCount = mentionCounts.reduce(function(prev, curr) {
|
||||||
|
return prev + curr;
|
||||||
|
});
|
||||||
|
this.props.onUnreadCountChange(allUnreadCount, allMentionCount);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
visibleStyle: function(visible) {
|
visibleStyle: function(visible) {
|
||||||
@@ -75,14 +82,14 @@ 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 } activeKey={ this.state.key } onSelect={ this.handleSelect }></TabBar>
|
<TabBar id="tabBar" teams={ this.props.teams } unreadCounts={ this.state.unreadCounts } mentionCounts={ this.state.mentionCounts } activeKey={ this.state.key } onSelect={ this.handleSelect }></TabBar>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var views = this.props.teams.map(function(team, index) {
|
var views = this.props.teams.map(function(team, index) {
|
||||||
var handleUnreadCountChange = function(count) {
|
var handleUnreadCountChange = function(unreadCount, mentionCount) {
|
||||||
thisObj.handleUnreadCountChange(index, count);
|
thisObj.handleUnreadCountChange(index, unreadCount, mentionCount);
|
||||||
};
|
};
|
||||||
var handleNotificationClick = function() {
|
var handleNotificationClick = function() {
|
||||||
thisObj.handleSelect(index);
|
thisObj.handleSelect(index);
|
||||||
@@ -107,9 +114,13 @@ var TabBar = React.createClass({
|
|||||||
var thisObj = this;
|
var thisObj = this;
|
||||||
var tabs = this.props.teams.map(function(team, index) {
|
var tabs = this.props.teams.map(function(team, index) {
|
||||||
var badge;
|
var badge;
|
||||||
if (thisObj.props.unreadCounts[index] != 0) {
|
if (thisObj.props.mentionCounts[index] != 0) {
|
||||||
badge = (<Badge>
|
badge = (<Badge>
|
||||||
{ thisObj.props.unreadCounts[index] }
|
{ thisObj.props.mentionCounts[index] }
|
||||||
|
</Badge>);
|
||||||
|
} else if (thisObj.props.unreadCounts[index] != 0) {
|
||||||
|
badge = (<Badge>
|
||||||
|
*
|
||||||
</Badge>);
|
</Badge>);
|
||||||
}
|
}
|
||||||
return (<NavItem className="teamTabItem" id={ 'teamTabItem' + index } eventKey={ index }>
|
return (<NavItem className="teamTabItem" id={ 'teamTabItem' + index } eventKey={ index }>
|
||||||
@@ -132,12 +143,13 @@ var MattermostView = React.createClass({
|
|||||||
unreadCount: 0
|
unreadCount: 0
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleUnreadCountChange: function(count) {
|
handleUnreadCountChange: function(unreadCount, mentionCount) {
|
||||||
this.setState({
|
this.setState({
|
||||||
unreadCount: count
|
unreadCount: unreadCount,
|
||||||
|
mentionCount: mentionCount
|
||||||
});
|
});
|
||||||
if (this.props.onUnreadCountChange) {
|
if (this.props.onUnreadCountChange) {
|
||||||
this.props.onUnreadCountChange(count);
|
this.props.onUnreadCountChange(unreadCount, mentionCount);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
@@ -187,10 +199,15 @@ var MattermostView = React.createClass({
|
|||||||
switch (event.channel) {
|
switch (event.channel) {
|
||||||
case 'onUnreadCountChange':
|
case 'onUnreadCountChange':
|
||||||
var unreadCount = event.args[0];
|
var unreadCount = event.args[0];
|
||||||
thisObj.handleUnreadCountChange(unreadCount);
|
var mentionCount = event.args[1];
|
||||||
|
thisObj.handleUnreadCountChange(unreadCount, mentionCount);
|
||||||
break;
|
break;
|
||||||
case 'onNotificationClick':
|
case 'onNotificationClick':
|
||||||
thisObj.props.onNotificationClick();
|
thisObj.props.onNotificationClick();
|
||||||
|
break;
|
||||||
|
case 'console':
|
||||||
|
console.log(event.args[0]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -220,19 +237,21 @@ window.addEventListener('contextmenu', function(e) {
|
|||||||
menu.popup(remote.getCurrentWindow());
|
menu.popup(remote.getCurrentWindow());
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
var showUnreadBadge = function(unreadCount) {
|
var showUnreadBadge = function(unreadCount, mentionCount) {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
var window = remote.getCurrentWindow();
|
var window = remote.getCurrentWindow();
|
||||||
if (unreadCount > 0) {
|
if (unreadCount > 0 || mentionCount > 0) {
|
||||||
window.setOverlayIcon(path.join(__dirname, '../resources/badge.png'), 'You have unread channels.');
|
window.setOverlayIcon(path.join(__dirname, '../resources/badge.png'), 'You have unread channels.');
|
||||||
} else {
|
} else {
|
||||||
window.setOverlayIcon(null, '');
|
window.setOverlayIcon(null, '');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
if (unreadCount > 0) {
|
if (mentionCount > 0) {
|
||||||
remote.app.dock.setBadge(unreadCount.toString());
|
remote.app.dock.setBadge(mentionCount.toString());
|
||||||
|
} else if (mentionCount < unreadCount) {
|
||||||
|
remote.app.dock.setBadge('*');
|
||||||
} else {
|
} else {
|
||||||
remote.app.dock.setBadge('');
|
remote.app.dock.setBadge('');
|
||||||
}
|
}
|
||||||
|
@@ -5,25 +5,51 @@ const ipc = electron.ipcRenderer;
|
|||||||
const NativeNotification = Notification;
|
const NativeNotification = Notification;
|
||||||
|
|
||||||
var unreadCountTimer = setInterval(function() {
|
var unreadCountTimer = setInterval(function() {
|
||||||
if (!this.count) {
|
if (!this.unreadCount) {
|
||||||
this.count = 0;
|
this.unreadCount = 0;
|
||||||
|
}
|
||||||
|
if (!this.mentionCount) {
|
||||||
|
this.mentionCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// count in sidebar
|
// unreadCount in sidebar
|
||||||
var unreadCount = document.getElementsByClassName('unread-title').length;
|
var unreadCount = document.getElementsByClassName('unread-title').length;
|
||||||
|
// mentionCount in sidebar
|
||||||
|
var elem = document.getElementsByClassName('badge')
|
||||||
|
var mentionCount = 0;
|
||||||
|
for (var i = 0; i < elem.length; i++) {
|
||||||
|
if (elem[i].offsetHeight != 0) {
|
||||||
|
mentionCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ipc.sendToHost('console', "sidebar(unread=" + unreadCount +", mention=" + mentionCount + ")");
|
||||||
|
|
||||||
// count for active channel
|
// unreadCount for active channel
|
||||||
var newSeparators = document.getElementsByClassName('new-separator');
|
var newSeparators = document.getElementsByClassName('new-separator');
|
||||||
|
var post;
|
||||||
for (var i = 0; i < newSeparators.length; i++) {
|
for (var i = 0; i < newSeparators.length; i++) {
|
||||||
if (newSeparators[i].offsetParent !== null) {
|
if (newSeparators[i].offsetParent !== null) {
|
||||||
unreadCount += 1;
|
unreadCount += 1;
|
||||||
|
post = newSeparators[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// mentionCount for active channel
|
||||||
if (this.count != unreadCount) {
|
if (post != null) {
|
||||||
ipc.sendToHost('onUnreadCountChange', unreadCount);
|
while (post = post.nextSibling) {
|
||||||
|
var highlight = post.getElementsByClassName('mention-highlight');
|
||||||
|
if (highlight.length != 0 && highlight[0].offsetHeight != null) {
|
||||||
|
mentionCount++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.count = unreadCount;
|
ipc.sendToHost('console', "sidebar + active(unread=" + unreadCount +", mention=" + mentionCount + ")");
|
||||||
|
|
||||||
|
if (this.unreadCount != unreadCount || this.mentionCount != mentionCount) {
|
||||||
|
ipc.sendToHost('onUnreadCountChange', unreadCount, mentionCount);
|
||||||
|
}
|
||||||
|
this.unreadCount = unreadCount;
|
||||||
|
this.mentionCount = mentionCount;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
// On Windows 8.1 and Windows 8, a shortcut with a Application User Model ID must be installed to the Start screen.
|
// On Windows 8.1 and Windows 8, a shortcut with a Application User Model ID must be installed to the Start screen.
|
||||||
|
Reference in New Issue
Block a user