@@ -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,16 +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 ,
44- syncState : MatrixClientPeg . get ( ) . getSyncState ( )
46+ syncState : MatrixClientPeg . get ( ) . getSyncState ( ) ,
47+ hasUnsentMessages : this . _hasUnsentMessages ( room )
4548 }
4649 } ,
4750
@@ -77,6 +80,9 @@ module.exports = {
7780 switch ( payload . action ) {
7881 case 'message_send_failed' :
7982 case 'message_sent' :
83+ this . setState ( {
84+ hasUnsentMessages : this . _hasUnsentMessages ( this . state . room )
85+ } ) ;
8086 case 'message_resend_started' :
8187 this . setState ( {
8288 room : MatrixClientPeg . get ( ) . getRoom ( this . props . roomId )
@@ -182,6 +188,19 @@ module.exports = {
182188 this . _updateConfCallNotification ( ) ;
183189 } ,
184190
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+
185204 _updateConfCallNotification : function ( ) {
186205 var room = MatrixClientPeg . get ( ) . getRoom ( this . props . roomId ) ;
187206 if ( ! room ) return ;
@@ -274,6 +293,13 @@ module.exports = {
274293 return false ;
275294 } ,
276295
296+ onResendAllClick : function ( ) {
297+ var eventsToResend = this . _getUnsentMessages ( this . state . room ) ;
298+ eventsToResend . forEach ( function ( event ) {
299+ Resend . resend ( event ) ;
300+ } ) ;
301+ } ,
302+
277303 onJoinButtonClicked : function ( ev ) {
278304 var self = this ;
279305 MatrixClientPeg . get ( ) . joinRoom ( this . props . roomId ) . then ( function ( ) {
0 commit comments