@@ -24,6 +24,7 @@ var Modal = require("matrix-react-sdk/lib/Modal");
2424var sdk = require ( 'matrix-react-sdk/lib/index' ) ;
2525var CallHandler = require ( 'matrix-react-sdk/lib/CallHandler' ) ;
2626var VectorConferenceHandler = require ( '../../modules/VectorConferenceHandler' ) ;
27+ var Resend = require ( "../../Resend" ) ;
2728
2829var dis = require ( "matrix-react-sdk/lib/dispatcher" ) ;
2930
@@ -32,15 +33,18 @@ var INITIAL_SIZE = 20;
3233
3334module . exports = {
3435 getInitialState : function ( ) {
36+ var room = this . props . roomId ? MatrixClientPeg . get ( ) . getRoom ( this . props . roomId ) : null ;
3537 return {
36- room : this . props . roomId ? MatrixClientPeg . get ( ) . getRoom ( this . props . roomId ) : null ,
38+ room : room ,
3739 messageCap : INITIAL_SIZE ,
3840 editingRoomSettings : false ,
3941 uploadingRoomSettings : false ,
4042 numUnreadMessages : 0 ,
4143 draggingFile : false ,
4244 searching : false ,
4345 searchResults : null ,
46+ syncState : MatrixClientPeg . get ( ) . getSyncState ( ) ,
47+ hasUnsentMessages : this . _hasUnsentMessages ( room )
4448 }
4549 } ,
4650
@@ -50,6 +54,7 @@ module.exports = {
5054 MatrixClientPeg . get ( ) . on ( "Room.name" , this . onRoomName ) ;
5155 MatrixClientPeg . get ( ) . on ( "RoomMember.typing" , this . onRoomMemberTyping ) ;
5256 MatrixClientPeg . get ( ) . on ( "RoomState.members" , this . onRoomStateMember ) ;
57+ MatrixClientPeg . get ( ) . on ( "sync" , this . onSyncStateChange ) ;
5358 this . atBottom = true ;
5459 } ,
5560
@@ -67,13 +72,17 @@ module.exports = {
6772 MatrixClientPeg . get ( ) . removeListener ( "Room.name" , this . onRoomName ) ;
6873 MatrixClientPeg . get ( ) . removeListener ( "RoomMember.typing" , this . onRoomMemberTyping ) ;
6974 MatrixClientPeg . get ( ) . removeListener ( "RoomState.members" , this . onRoomStateMember ) ;
75+ MatrixClientPeg . get ( ) . removeListener ( "sync" , this . onSyncStateChange ) ;
7076 }
7177 } ,
7278
7379 onAction : function ( payload ) {
7480 switch ( payload . action ) {
7581 case 'message_send_failed' :
7682 case 'message_sent' :
83+ this . setState ( {
84+ hasUnsentMessages : this . _hasUnsentMessages ( this . state . room )
85+ } ) ;
7786 case 'message_resend_started' :
7887 this . setState ( {
7988 room : MatrixClientPeg . get ( ) . getRoom ( this . props . roomId )
@@ -102,6 +111,12 @@ module.exports = {
102111 }
103112 } ,
104113
114+ onSyncStateChange : function ( state ) {
115+ this . setState ( {
116+ syncState : state
117+ } ) ;
118+ } ,
119+
105120 // MatrixRoom still showing the messages from the old room?
106121 // Set the key to the room_id. Sadly you can no longer get at
107122 // the key from inside the component, or we'd check this in code.
@@ -173,6 +188,19 @@ module.exports = {
173188 this . _updateConfCallNotification ( ) ;
174189 } ,
175190
191+ _hasUnsentMessages : function ( room ) {
192+ return this . _getUnsentMessages ( room ) . length > 0 ;
193+ } ,
194+
195+ _getUnsentMessages : function ( room ) {
196+ if ( ! room ) { return [ ] ; }
197+ // TODO: It would be nice if the JS SDK provided nicer constant-time
198+ // constructs rather than O(N) (N=num msgs) on this.
199+ return room . timeline . filter ( function ( ev ) {
200+ return ev . status === Matrix . EventStatus . NOT_SENT ;
201+ } ) ;
202+ } ,
203+
176204 _updateConfCallNotification : function ( ) {
177205 var room = MatrixClientPeg . get ( ) . getRoom ( this . props . roomId ) ;
178206 if ( ! room ) return ;
@@ -265,6 +293,13 @@ module.exports = {
265293 return false ;
266294 } ,
267295
296+ onResendAllClick : function ( ) {
297+ var eventsToResend = this . _getUnsentMessages ( this . state . room ) ;
298+ eventsToResend . forEach ( function ( event ) {
299+ Resend . resend ( event ) ;
300+ } ) ;
301+ } ,
302+
268303 onJoinButtonClicked : function ( ev ) {
269304 var self = this ;
270305 MatrixClientPeg . get ( ) . joinRoom ( this . props . roomId ) . then ( function ( ) {
0 commit comments