public void getGroupHistory ( final String groupId , final Integer maxMessages , final Date before , final GroupHistoryCompletionListener completionListener ) { if ( ! isConnected ( ) ) { getGroupHistoryError ( completionListener , "Can't complete request when not connected, " + "Please reconnect!" ) ; return ; } if ( ( maxMessages == null ) || ( maxMessages < 1 ) ) { getGroupHistoryError ( completionListener , "maxMessages must be at least 1" ) ; return ; } if ( ( groupId == null ) || groupId . length ( ) == 0 ) { getGroupHistoryError ( completionListener , "groupId cannot be blank" ) ; return ; } Uri . Builder builder = new Uri . Builder ( ) ; builder . appendQueryParameter ( "limit" , maxMessages . toString ( ) ) ; if ( before != null ) { builder . appendQueryParameter ( "before" , Long . toString ( before . getTime ( ) ) ) ; } String urlEndpoint = String . format ( "/v1/groups/%s/history%s" , groupId , builder . build ( ) . toString ( ) ) ; signalingChannel . sendRESTMessage ( "get" , urlEndpoint , null , new RespokeSignalingChannel . RESTListener ( ) { @ Override public void onSuccess ( Object response ) { if ( ! ( response instanceof JSONArray ) ) { getGroupHistoryError ( completionListener , "Invalid response from server" ) ; return ; } final JSONArray json = ( JSONArray ) response ; final ArrayList < RespokeGroupMessage > results = new ArrayList <> ( json . length ( ) ) ; try { for ( int i = 0 ; i < json . length ( ) ; i ++ ) { final JSONObject jsonMessage = json . getJSONObject ( i ) ; final RespokeGroupMessage message = buildGroupMessage ( jsonMessage ) ; results . add ( message ) ; } } catch ( JSONException e ) { getGroupHistoryError ( completionListener , "Error parsing JSON response" ) ; return ; } new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { @ Override public void run ( ) { if ( completionListener != null ) { completionListener . onSuccess ( results ) ; } } } ) ; } @ Override public void onError ( final String errorMessage ) { getGroupHistoryError ( completionListener , errorMessage ) ; } } ) ; }
Retrieve the history of messages that have been persisted for a specific group . Only those messages that have been marked to be persisted when sent will show up in the history .