public void getGroupHistories ( final List < String > groupIds , final Integer maxMessages , final GroupHistoriesCompletionListener completionListener ) { if ( ! isConnected ( ) ) { getGroupHistoriesError ( completionListener , "Can't complete request when not connected, " + "Please reconnect!" ) ; return ; } if ( ( maxMessages == null ) || ( maxMessages < 1 ) ) { getGroupHistoriesError ( completionListener , "maxMessages must be at least 1" ) ; return ; } if ( ( groupIds == null ) || ( groupIds . size ( ) == 0 ) ) { getGroupHistoriesError ( completionListener , "At least 1 group must be specified" ) ; return ; } JSONObject body = new JSONObject ( ) ; try { body . put ( "limit" , maxMessages . toString ( ) ) ; JSONArray groupIdParams = new JSONArray ( groupIds ) ; body . put ( "groupIds" , groupIdParams ) ; } catch ( JSONException e ) { getGroupHistoriesError ( completionListener , "Error forming JSON body to send." ) ; return ; } // This has been modifed to use the newer group-history-search route over the // deprecated group-histories route. String urlEndpoint = "/v1/group-history-search" ; signalingChannel . sendRESTMessage ( "post" , urlEndpoint , body , new RespokeSignalingChannel . RESTListener ( ) { @ Override public void onSuccess ( Object response ) { if ( ! ( response instanceof JSONObject ) ) { getGroupHistoriesError ( completionListener , "Invalid response from server" ) ; return ; } final JSONObject json = ( JSONObject ) response ; final HashMap < String , List < RespokeGroupMessage > > results = new HashMap <> ( ) ; for ( Iterator < String > keys = json . keys ( ) ; keys . hasNext ( ) ; ) { final String key = keys . next ( ) ; try { final JSONArray jsonMessages = json . getJSONArray ( key ) ; final ArrayList < RespokeGroupMessage > messageList = new ArrayList <> ( jsonMessages . length ( ) ) ; for ( int i = 0 ; i < jsonMessages . length ( ) ; i ++ ) { final JSONObject jsonMessage = jsonMessages . getJSONObject ( i ) ; final RespokeGroupMessage message = buildGroupMessage ( jsonMessage ) ; messageList . add ( message ) ; } results . put ( key , messageList ) ; } catch ( JSONException e ) { getGroupHistoriesError ( 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 ) { getGroupHistoriesError ( completionListener , errorMessage ) ; } } ) ; }
Retrieve the history of messages that have been persisted for 1 or more groups . Only those messages that have been marked to be persisted when sent will show up in the history .