Skip to content

setUser callback, ClientState and add/remove channel members

Compare
Choose a tag to compare
@tschellenbach tschellenbach released this 10 Oct 21:07
e1d9b33
  • Added a callback as an optional last argument for setUser functions
  • Added ClientState which stores users, current user, unreadCount and the current user's mutes
  • Added notification.mutes_updated event
  • Add support for add/remove channel members

setUser

Adds an optional callback argument to all setUser functions. For example:

client.setUser(user, USER_TOKEN, new ClientConnectionCallback() {
            @Override
            public void onSuccess(User user) {
                Log.i(TAG, String.format("Connection established for user %s", user.getName()));
            }

            @Override
            public void onError(String errMsg, int errCode) {
                Log.e(TAG, String.format("Failed to establish websocket connection. Code %d message %s", errCode, errMsg));
            }
        });

The setUser call with a token provider also allows you to add a callback.

Related #118

ClientState

Implements client state similar to the JS client so you can work with mutes, unread count, and user presence

client.getState().getCurrentUser().getMutes()
client.getState().getUnreadChannels()
client.getState().getTotalUnreadCount()
// note that the above 2 give you the up to date unread count, it automatically updates when there are new event. it however doesn't expose a livedata object
// for live data see `StreamChat.getUnreadChannels` and `StreamChat.getTotalUnreadMessages`

StreamChat LiveData

        StreamChat.getTotalUnreadMessages().observe(this, (Number count) -> {
            Log.i(TAG, String.format("Total unread message count is now %d", count));
        });
        StreamChat.getUnreadChannels().observe(this, (Number count) -> {
            Log.i(TAG, String.format("There are %d channels with unread messages", count));
        });