Skip to content

Commit fbb6775

Browse files
committed
Implement unread message status when scrolled up.
1 parent 8b0db49 commit fbb6775

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎skins/base/views/organisms/RoomView.js‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ module.exports = React.createClass({
6464
);
6565
},
6666

67+
getUnreadMessagesString: function() {
68+
if (!this.state.numUnreadMessages) {
69+
return "";
70+
}
71+
return this.state.numUnreadMessages + " unread messages";
72+
},
73+
6774
render: function() {
6875
if (!this.state.room) {
6976
return (
@@ -120,7 +127,18 @@ module.exports = React.createClass({
120127
);
121128
} else {
122129
var typingString = this.getWhoIsTypingString();
123-
if (typingString) {
130+
var unreadMsgs = this.getUnreadMessagesString();
131+
// unread count trumps who is typing since the unread count is only
132+
// set when you've scrolled up
133+
if (unreadMsgs) {
134+
statusBar = (
135+
<div className="mx_RoomView_typingBar">
136+
<img src="img/typing.png" width="40" height="40" alt=""/>
137+
{unreadMsgs}
138+
</div>
139+
);
140+
}
141+
else if (typingString) {
124142
statusBar = (
125143
<div className="mx_RoomView_typingBar">
126144
<img src="img/typing.png" width="40" height="40" alt=""/>

‎src/controllers/organisms/RoomView.js‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = {
5252
messageCap: INITIAL_SIZE,
5353
editingRoomSettings: false,
5454
uploadingRoomSettings: false,
55+
numUnreadMessages: 0
5556
}
5657
},
5758

@@ -130,8 +131,23 @@ module.exports = {
130131
(messageWrapper.clientHeight + 150)
131132
);
132133
}
134+
135+
var currentUnread = this.state.numUnreadMessages;
136+
if (!toStartOfTimeline &&
137+
(ev.getSender() !== MatrixClientPeg.get().credentials.userId)) {
138+
// update unread count when scrolled up
139+
if (this.atBottom) {
140+
currentUnread = 0;
141+
}
142+
else {
143+
currentUnread += 1;
144+
}
145+
}
146+
147+
133148
this.setState({
134-
room: MatrixClientPeg.get().getRoom(this.props.roomId)
149+
room: MatrixClientPeg.get().getRoom(this.props.roomId),
150+
numUnreadMessages: currentUnread
135151
});
136152

137153
if (toStartOfTimeline && !this.state.paginating) {
@@ -178,6 +194,9 @@ module.exports = {
178194
}
179195
} else if (this.atBottom) {
180196
messageWrapper.scrollTop = messageWrapper.scrollHeight;
197+
if (this.state.numUnreadMessages !== 0) {
198+
this.setState({numUnreadMessages: 0});
199+
}
181200
}
182201
},
183202

@@ -234,7 +253,11 @@ module.exports = {
234253
onMessageListScroll: function(ev) {
235254
if (this.refs.messageWrapper) {
236255
var messageWrapper = this.refs.messageWrapper.getDOMNode();
256+
var wasAtBottom = this.atBottom;
237257
this.atBottom = messageWrapper.scrollHeight - messageWrapper.scrollTop <= messageWrapper.clientHeight;
258+
if (this.atBottom && !wasAtBottom) {
259+
this.forceUpdate(); // remove unread msg count
260+
}
238261
}
239262
if (!this.state.paginating) this.fillSpace();
240263
},

0 commit comments

Comments
 (0)