Use our read receipt to calculate whether rooms are unread.

This commit is contained in:
David Baker 2016-01-06 18:07:24 +00:00
parent 05d9e1261c
commit 04c7792b51
2 changed files with 22 additions and 40 deletions

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
var MatrixClientPeg = require('./MatrixClientPeg');
module.exports = { module.exports = {
/** /**
* Returns true iff this event arriving in a room should affect the room's * Returns true iff this event arriving in a room should affect the room's
@ -26,5 +28,22 @@ module.exports = {
return false; return false;
} }
return true; return true;
},
doesRoomHaveUnreadMessages: function(room) {
var readUpToId = room.getEventReadUpTo(MatrixClientPeg.get().credentials.userId);
var unread = false;
for (var i = room.timeline.length - 1; i >= 0; --i) {
var ev = room.timeline[i];
if (ev.getId() == readUpToId) {
break;
}
if (this.eventTriggersUnreadCount(ev)) {
unread = true;
}
}
return unread;
} }
}; };

View file

@ -21,7 +21,7 @@ var GeminiScrollbar = require('react-gemini-scrollbar');
var MatrixClientPeg = require("../../../MatrixClientPeg"); var MatrixClientPeg = require("../../../MatrixClientPeg");
var CallHandler = require('../../../CallHandler'); var CallHandler = require('../../../CallHandler');
var RoomListSorter = require("../../../RoomListSorter"); var RoomListSorter = require("../../../RoomListSorter");
var UnreadStatus = require('../../../UnreadStatus'); var Unread = require('../../../Unread');
var dis = require("../../../dispatcher"); var dis = require("../../../dispatcher");
var sdk = require('../../../index'); var sdk = require('../../../index');
@ -38,7 +38,6 @@ module.exports = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
activityMap: null,
isLoadingLeftRooms: false, isLoadingLeftRooms: false,
lists: {}, lists: {},
incomingCall: null, incomingCall: null,
@ -57,7 +56,6 @@ module.exports = React.createClass({
cli.on("RoomMember.name", this.onRoomMemberName); cli.on("RoomMember.name", this.onRoomMemberName);
var s = this.getRoomLists(); var s = this.getRoomLists();
s.activityMap = {};
this.setState(s); this.setState(s);
}, },
@ -100,13 +98,6 @@ module.exports = React.createClass({
} }
}, },
componentWillReceiveProps: function(newProps) {
this.state.activityMap[newProps.selectedRoom] = undefined;
this.setState({
activityMap: this.state.activityMap
});
},
onRoom: function(room) { onRoom: function(room) {
this._delayedRefreshRoomList(); this._delayedRefreshRoomList();
}, },
@ -132,33 +123,11 @@ module.exports = React.createClass({
onRoomTimeline: function(ev, room, toStartOfTimeline) { onRoomTimeline: function(ev, room, toStartOfTimeline) {
if (toStartOfTimeline) return; if (toStartOfTimeline) return;
this.refreshRoomList();
var hl = 0;
if (
room.roomId != this.props.selectedRoom &&
ev.getSender() != MatrixClientPeg.get().credentials.userId)
{
if (UnreadStatus.eventTriggersUnreadCount(ev)) {
hl = 1;
}
}
var newState = this.getRoomLists();
if (hl > 0) {
// obviously this won't deep copy but this shouldn't be necessary
var amap = this.state.activityMap;
amap[room.roomId] = Math.max(amap[room.roomId] || 0, hl);
newState.activityMap = amap;
}
// still want to update the list even if the highlight status
// hasn't changed because the ordering may have
this.setState(newState);
}, },
onRoomReceipt: function(receiptEvent, room) { onRoomReceipt: function(receiptEvent, room) {
// because if we read a notification, it will affect notification count // because if we read a message it will affect notification / unread counts
this.refreshRoomList(); this.refreshRoomList();
}, },
@ -365,7 +334,6 @@ module.exports = React.createClass({
label="Invites" label="Invites"
editable={ false } editable={ false }
order="recent" order="recent"
activityMap={ self.state.activityMap }
selectedRoom={ self.props.selectedRoom } selectedRoom={ self.props.selectedRoom }
incomingCall={ self.state.incomingCall } incomingCall={ self.state.incomingCall }
collapsed={ self.props.collapsed } /> collapsed={ self.props.collapsed } />
@ -376,7 +344,6 @@ module.exports = React.createClass({
verb="favourite" verb="favourite"
editable={ true } editable={ true }
order="manual" order="manual"
activityMap={ self.state.activityMap }
selectedRoom={ self.props.selectedRoom } selectedRoom={ self.props.selectedRoom }
incomingCall={ self.state.incomingCall } incomingCall={ self.state.incomingCall }
collapsed={ self.props.collapsed } /> collapsed={ self.props.collapsed } />
@ -386,7 +353,6 @@ module.exports = React.createClass({
editable={ true } editable={ true }
verb="restore" verb="restore"
order="recent" order="recent"
activityMap={ self.state.activityMap }
selectedRoom={ self.props.selectedRoom } selectedRoom={ self.props.selectedRoom }
incomingCall={ self.state.incomingCall } incomingCall={ self.state.incomingCall }
collapsed={ self.props.collapsed } /> collapsed={ self.props.collapsed } />
@ -400,7 +366,6 @@ module.exports = React.createClass({
verb={ "tag as " + tagName } verb={ "tag as " + tagName }
editable={ true } editable={ true }
order="manual" order="manual"
activityMap={ self.state.activityMap }
selectedRoom={ self.props.selectedRoom } selectedRoom={ self.props.selectedRoom }
incomingCall={ self.state.incomingCall } incomingCall={ self.state.incomingCall }
collapsed={ self.props.collapsed } /> collapsed={ self.props.collapsed } />
@ -414,7 +379,6 @@ module.exports = React.createClass({
verb="demote" verb="demote"
editable={ true } editable={ true }
order="recent" order="recent"
activityMap={ self.state.activityMap }
selectedRoom={ self.props.selectedRoom } selectedRoom={ self.props.selectedRoom }
incomingCall={ self.state.incomingCall } incomingCall={ self.state.incomingCall }
collapsed={ self.props.collapsed } /> collapsed={ self.props.collapsed } />
@ -423,7 +387,6 @@ module.exports = React.createClass({
label="Historical" label="Historical"
editable={ false } editable={ false }
order="recent" order="recent"
activityMap={ self.state.activityMap }
selectedRoom={ self.props.selectedRoom } selectedRoom={ self.props.selectedRoom }
collapsed={ self.props.collapsed } collapsed={ self.props.collapsed }
alwaysShowHeader={ true } alwaysShowHeader={ true }