Optimizations
The SDK is optimized to avoid waste of resources and improve performance. You can freely choose which optimizations should be enabled or disabled.
Multiple Calls to API
The SDK prevents the user from making multiple calls to the backend. If a call is already running, the SDK merges a new request into the current one and the data is propagated to both request origins of the Call.
You can change the default behavior and force calls to always make new requests to API and never merge two requests into one by using:
ChatClient.Builder(apiKey, context).disableDistinctApiCalls().build()new ChatClient.Builder(apiKey, context).disableDistinctApiCalls().build();If you want to control new requests to API in a more granular way, you can use the extension function:
import io.getstream.result.call.forceNewRequest
Call<T>.forceNewRequest(): Call<T>For example, you can use the snippet presented below for query channels request:
ChatClient.instance().queryChannels(queryChannelsRequest).forceNewRequest().enqueue { result ->
when (result) {
is Result.Success -> {
// Handle success
}
is Result.Failure -> {
// Handle error
}
}
}Call<List<Channel>> queryChannelsCall = CallKt.forceNewRequest(ChatClient.instance().queryChannels(queryChannelsRequest));
queryChannelsCall.enqueue(result -> {
if (result.isSuccess()) {
// Handle success
} else {
// Handle error
}
});The returned Call will be forced to make a new request to API.
QuerySorter
The SDK sorts query results with QuerySortByField. Every SDK model supports it, for its sortable fields and any custom field in extraData:
val sort = QuerySortByField.descByName<Channel>("last_message_at")QuerySortByReflection is deprecated and will be removed in the next major version. Replace it with QuerySortByField: for example, QuerySortByReflection.desc<Channel>("last_message_at") becomes QuerySortByField.descByName<Channel>("last_message_at"), and a property reference such as QuerySortByReflection.desc(Channel::lastMessageAt) becomes the field's name.