Chat Rooms

Engagement SDK allows you to create chat rooms . The SDK also provides certain features to manage the chat room and its member.

A guide for managing Chat Rooms

Creating a Chat Room

Users can create a chat room with an optional title and optional visibility.
Parameters: Title(Optional) , Visibility(Optional,Default value: everyone)
Response: ChatRoomInfo Object, it contains the newly created chatroom Id and title

sdk.chat().createChatRoom(
                title,
                            Visibility.everyone,
                object : LiveLikeCallback<ChatRoomInfo>() {
                    override fun onResponse(result: ChatRoomInfo?, error: String?) {
                        val response = when {
                            result != null -> "${result.title ?: "No Title"}(${result.id})"
                            else -> error
                        }
                        response?.let { it1 -> showToast(it1) }
                    }
                })
sdk.chat().createChatRoom(
                title,
                            Visibility.everyone,
                new LiveLikeCallback<ChatRoomInfo>() {
                    @override
                    void onResponse(ChatRoomInfo result,String error){
                        // if result is null then error has some value to show 
                    }
                });

Update Chat Room

Users can update the chat room with title and visibility.
Parameters: Title(Optional) , Visibility(Optional)
Response: ChatRoomInfo Object, it contains the updated chatroom Id and title

sdk.chat().updateChatRoom(groupId,
                            title,
                            visibility,
                            object : LiveLikeCallback<ChatRoomInfo>() {
                                override fun onResponse(result: ChatRoomInfo?, error: String?) {
                                    
                                    error?.let {
                                        showToast(it)
                                    }
                                }
                            })
sdk.chat().updateChatRoom(groupId,
                            title,
                            visibility,
                            new LiveLikeCallback<ChatRoomInfo>() {
                    @override
                    void onResponse(ChatRoomInfo result,String error){
                        // if result is null then error has some value to show 
                    }
                });

Join Chat Room

User can join the chat room by providing the chatroom Id
Parameters: chatRoom id
Response: ChatRoomMembership object which contains the membership id and user details

sdk.chat().addCurrentUserToChatRoom(id,
                object : LiveLikeCallback<ChatRoomMembership>() {
                    override fun onResponse(result: ChatRoomMembership?, error: String?) {
                        result?.let {
                            showToast("User Added Successfully")
                        }
                        error?.let {
                            showToast(it)
                        }
                    }
                })
sdk.chat().addCurrentUserToChatRoom(id,
                 new LiveLikeCallback<ChatRoomMembership>() {
                    @override
                    void onResponse(ChatRoomMembership result,String error){
                        // if result is null then error has some value to show 
                    }
                });

UnJoin Chat Room

User can unjoin the group by providing the chatroom Id
Parameters: chatRoom id
Response: Boolean response

sdk.chat().deleteCurrentUserFromChatRoom(id,
                    object : LiveLikeCallback<Boolean>() {
                        override fun onResponse(result: Boolean?, error: String?) {
                            result?.let {
                                showToast("Deleted ChatRoom")                     
                            }
                        }
                    })
sdk.chat().deleteCurrentUserFromChatRoom(id,
                    new LiveLikeCallback<boolean>() {
                            @override 
                          void onResponse(boolean result,String error) {
                           
                        }
                    });

Get List of Current User from Chat Room

User can get the list of chatrooms(currently joined)
Parameters: LiveLikePagination(enum) FIRST(default),PREVIOUS,NEXT
Response: List of ChatRoomInfo(chatRoom id ,title)

sdk.chat().getCurrentUserChatRoomList(
                LiveLikePagination.FIRST,
                object : LiveLikeCallback<List<ChatRoomInfo>>() {
                    override fun onResponse(result: List<ChatRoomInfo>?, error: String?) {
                        
                        result?.let { it1 ->
                            chatRoomList.addAll(it1)
                        }
                        error?.let {
                            showToast(it)
                        }
                    }
                })
sdk.chat().getCurrentUserChatRoomList(
                LiveLikePagination.FIRST,
                new LiveLikeCallback<List<ChatRoomInfo>>() {
                   @override 
                     void onResponse(List<ChatRoomInfo> result,String error) {
                       
                    }
                });

Get List Of Members(Users) of Chat Room

User can view the members of the ChatRoom
Parameter: chatRoom Id and LiveLikePagination(enum) FIRST(default),PREVIOUS,NEXT
Response: List of User(LiveLikeUser)

sdk.chat().getMembersOfChatRoom(id,
                    LiveLikePagination.FIRST,
                    object : LiveLikeCallback<List<LiveLikeUser>>() {
                        override fun onResponse(result: List<LiveLikeUser>?, error: String?) {
                            result?.let { list ->
                                if (list.isNotEmpty()) {
                                    AlertDialog.Builder([email protected]).apply {
                                        setTitle("Room Members")
                                        setItems(list.map { it.nickname }
                                            .toTypedArray()) { _, which ->
                                            // On change of theme we need to create the session in order to pass new attribute of theme to widgets and chat
                                        }
                                        create()
                                    }.show()
                                }
                            }
                        }
                    })
sdk.chat().getMembersOfChatRoom(id,
                    LiveLikePagination.FIRST,
                    new LiveLikeCallback<List<LiveLikeUser>>() {
                        @override 
                          void onResponse(List<LiveLikeUser> result,String error) {

                                }
                            }
                        }
                    });

Chat Room User Mute

Using our producer suite website, a producer has the ability to mute a user. Muting a user disables their ability to send messages to the room they were muted in.
As an integrator you have the option to query our backend to find out whether a user is muted or not inside a chat room .

sdk.chat().getProfileMutedStatus(<chatroom id>,
                object : LiveLikeCallback<ChatUserMuteStatus>() {
                    override fun onResponse(result: ChatUserMuteStatus?, error: String?) {
                       
                    }
                })

Listening to ChatRoom Update

Whether you decide to make the user aware of their status or not, the SDK will show an alert to a muted user once they try to send a message in a room. For more information about chat moderation please see the Chat Moderation page.

To subscribe to listen to updates/changes to the chatRoom, you can use the method setChatRoomListener, the interface ChatRoomListener contains the method onChatRoomUpdate

val chatRoomListener = object : ChatRoomListener {
            override fun onChatRoomUpdate(chatRoom: ChatRoomInfo) {
                // method will auto call when new changes cames from Produceer Side
            }
        }

chatsession.setChatRoomListener(chatRoomListener)

Add User to ChatRoom

In Order to add user to chatRoom by the member of the chatRoom.

sdk.chat().addUserToChatRoom(chatRoomId,
                userId,
                object : LiveLikeCallback<ChatRoomMembership>() {
                    override fun onResponse(result: ChatRoomMembership?, error: String?) {
                        result?.let {
                            showToast("User Added Successfully")
                        }
                       
                        error?.let {
                            showToast(it)
                        }
                       
                    }
                })