Merge pull request #68 from matrix-org/notif_sync

Set room highlight from unread_notification_count
This commit is contained in:
David Baker 2016-01-21 10:31:42 +00:00
commit 99a491bb0e
3 changed files with 37 additions and 8 deletions

View file

@ -16,6 +16,7 @@ limitations under the License.
var React = require('react');
var Matrix = require("matrix-js-sdk");
var url = require('url');
var Favico = require('favico.js');
var MatrixClientPeg = require("../../MatrixClientPeg");
var Notifier = require("../../Notifier");
@ -85,6 +86,10 @@ module.exports = React.createClass({
};
},
componentWillMount: function() {
this.favicon = new Favico({animation: 'none'});
},
componentDidMount: function() {
this._autoRegisterAsGuest = false;
if (this.props.enableGuest) {
@ -498,6 +503,7 @@ module.exports = React.createClass({
var cli = MatrixClientPeg.get();
var self = this;
cli.on('sync', function(state, prevState) {
self.updateFavicon();
if (state === "SYNCING" && prevState === "SYNCING") {
return;
}
@ -756,6 +762,21 @@ module.exports = React.createClass({
this.showScreen("settings");
},
updateFavicon: function() {
var notifCount = 0;
var rooms = MatrixClientPeg.get().getRooms();
for (var i = 0; i < rooms.length; ++i) {
if (rooms[i].hasMembershipState(MatrixClientPeg.get().credentials.userId, 'invite')) {
++notifCount;
} else if (rooms[i].getUnreadNotificationCount()) {
notifCount += rooms[i].getUnreadNotificationCount();
}
}
this.favicon.badge(notifCount);
document.title = (notifCount > 0 ? "["+notifCount+"] " : "")+"Vector";
},
onUserSettingsClose: function() {
// XXX: use browser history instead to find the previous room?
if (this.state.currentRoom) {