Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Set room highlight from unread_notification_count #68

Merged
merged 8 commits into from
Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want an undefined guard here to avoid risk of NaN.

if (rooms[i].unread_notification_count) {
  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');
Expand Down
15 changes: 7 additions & 8 deletions src/components/views/rooms/RoomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check if it is the user's receipt and not someone else then in order to prevent refreshing the room list for every receipt.

},

onRoomName: function(room) {
this._delayedRefreshRoomList();
},
Expand Down