From 5f6fe74ca81431ef865db3aecad5a0d9e6c1131b Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 18 Dec 2015 17:51:17 +0000 Subject: [PATCH 1/6] Highlight status is now taken from the server's unread notif count --- src/components/views/rooms/RoomList.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index 6a19e21d27..f60cc3a08a 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -52,6 +52,7 @@ module.exports = React.createClass({ cli.on("Room.timeline", this.onRoomTimeline); cli.on("Room.name", this.onRoomName); cli.on("Room.tags", this.onRoomTags); + cli.on("Room.receipt", this.onRoomReceipt); cli.on("RoomState.events", this.onRoomStateEvents); cli.on("RoomMember.name", this.onRoomMemberName); @@ -93,6 +94,7 @@ module.exports = React.createClass({ if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener("Room", this.onRoom); MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline); + MatrixClientPeg.get().removeListener("Room.receipt", this.onRoomReceipt); MatrixClientPeg.get().removeListener("Room.name", this.onRoomName); MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents); } @@ -139,14 +141,6 @@ module.exports = React.createClass({ if (UnreadStatus.eventTriggersUnreadCount(ev)) { hl = 1; } - - var me = room.getMember(MatrixClientPeg.get().credentials.userId); - var actions = MatrixClientPeg.get().getPushActionsForEvent(ev); - if ((actions && actions.tweaks && actions.tweaks.highlight) || - (me && me.membership == "invite")) - { - hl = 2; - } } var newState = this.getRoomLists(); @@ -163,6 +157,11 @@ module.exports = React.createClass({ this.setState(newState); }, + onRoomReceipt: function(receiptEvent, room) { + // because if we read a notification, it will affect notification count + this.refreshRoomList(); + }, + onRoomName: function(room) { this._delayedRefreshRoomList(); }, From 6ea3f21a8eb5574f28847c9eb19d6c6f43067ae5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 21 Dec 2015 12:55:13 +0000 Subject: [PATCH 2/6] Favicon badges --- package.json | 1 + src/components/structures/MatrixChat.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) 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'); From 287da54fbcea493a93027fc946b85179cae508fe Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 7 Jan 2016 10:38:44 +0000 Subject: [PATCH 3/6] Address PR comments --- src/components/structures/MatrixChat.js | 4 +++- src/components/views/rooms/RoomList.js | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 4d1655872f..205eb10c4a 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -639,7 +639,9 @@ module.exports = React.createClass({ var rooms = MatrixClientPeg.get().getRooms(); for (var i = 0; i < rooms.length; ++i) { - notifCount += rooms[i].unread_notification_count; + if (rooms[i].unread_notification_count) { + notifCount += rooms[i].unread_notification_count; + } } this.favicon.badge(notifCount); document.title = (notifCount > 0 ? "["+notifCount+"] " : "")+"Vector"; diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index f60cc3a08a..9f85c053ee 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -159,7 +159,15 @@ module.exports = React.createClass({ onRoomReceipt: function(receiptEvent, room) { // because if we read a notification, it will affect notification count - this.refreshRoomList(); + // only bother updating if there's a receipt from us + var receiptKeys = Object.keys(receiptEvent.getContent()); + for (var i = 0; i < receiptKeys.length; ++i) { + var rcpt = receiptEvent.getContent()[receiptKeys[i]]; + if (rcpt['m.read'] && rcpt['m.read'][MatrixClientPeg.get().credentials.userId]) { + this.refreshRoomList(); + break; + } + } }, onRoomName: function(room) { From 67ff769962b9b95e4e68417eee45adfc40596fc0 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 13 Jan 2016 13:00:03 +0000 Subject: [PATCH 4/6] Include invites in the badge count --- src/components/structures/MatrixChat.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index adb2ba14b5..97a699292d 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -639,7 +639,9 @@ module.exports = React.createClass({ var rooms = MatrixClientPeg.get().getRooms(); for (var i = 0; i < rooms.length; ++i) { - if (rooms[i].unread_notification_count) { + if (rooms[i].hasMembershipState(MatrixClientPeg.get().credentials.userId, 'invite')) { + ++notifCount; + } else if (rooms[i].unread_notification_count) { notifCount += rooms[i].unread_notification_count; } } From 83634bf93040918e1605891fd3e268ea7a74bc26 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 20 Jan 2016 15:56:11 +0000 Subject: [PATCH 5/6] Update for new unread count format --- src/components/structures/MatrixChat.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 97a699292d..975ea37aab 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -641,8 +641,8 @@ module.exports = React.createClass({ for (var i = 0; i < rooms.length; ++i) { if (rooms[i].hasMembershipState(MatrixClientPeg.get().credentials.userId, 'invite')) { ++notifCount; - } else if (rooms[i].unread_notification_count) { - notifCount += rooms[i].unread_notification_count; + } else if (rooms[i].unread_notifications && rooms[i].unread_notifications['notification_count']) { + notifCount += rooms[i].unread_notifications['notification_count']; } } this.favicon.badge(notifCount); From acce08194d64bd9d2347f3b290ececbf20c144f1 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 21 Jan 2016 10:23:18 +0000 Subject: [PATCH 6/6] Apply patch to the right branch: update for new count format --- src/components/structures/MatrixChat.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 975ea37aab..b45ab93ea5 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -641,8 +641,8 @@ module.exports = React.createClass({ for (var i = 0; i < rooms.length; ++i) { if (rooms[i].hasMembershipState(MatrixClientPeg.get().credentials.userId, 'invite')) { ++notifCount; - } else if (rooms[i].unread_notifications && rooms[i].unread_notifications['notification_count']) { - notifCount += rooms[i].unread_notifications['notification_count']; + } else if (rooms[i].getUnreadNotificationCount()) { + notifCount += rooms[i].getUnreadNotificationCount(); } } this.favicon.badge(notifCount);