@@ -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