diff --git a/package.json b/package.json index 9c2c645ea2..0c9054122f 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "dependencies": { "classnames": "^2.1.2", + "favico.js": "^0.3.10", "filesize": "^3.1.2", "flux": "^2.0.3", "glob": "^5.0.14", diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 8ad5b44762..4d1655872f 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -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"); @@ -82,6 +83,10 @@ module.exports = React.createClass({ }; }, + componentWillMount: function() { + this.favicon = new Favico({animation: 'none'}); + }, + componentDidMount: function() { this.dispatcherRef = dis.register(this.onAction); if (this.state.logged_in) { @@ -399,6 +404,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; } @@ -628,6 +634,17 @@ 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) { + notifCount += rooms[i].unread_notification_count; + } + this.favicon.badge(notifCount); + document.title = (notifCount > 0 ? "["+notifCount+"] " : "")+"Vector"; + }, + render: function() { var LeftPanel = sdk.getComponent('structures.LeftPanel'); var RoomView = sdk.getComponent('structures.RoomView');