Invite User to ChatRoom

Below are the APIs which allow integrators to embed invite users to chatroom functionality.

Send invite to User

This API allows the user to send an invite to another user which will send a Pubnub event to the other user also

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

Receive invite real-time

In order to receive the invite in real-time, the integrator has to provide value to delegate which has a method that allows the user to receive the invitation.

sdk.chat().chatRoomDelegate =
            object : ChatRoomDelegate() {
                override fun onNewChatRoomAdded(chatRoomAdd: ChatRoomAdd) {
                    
                }

                override fun onReceiveInvitation(invitation: ChatRoomInvitation) {
                    showToast("Receive invitation from ${invitation.invited_by.nickname} => ${invitation.invited_by.userId}")
                }
            }

Update the user invitation status

Once the user receives the invitation he can either accept or reject the invitation in order to do so, integrator can use the below api. User can choose between ACCEPTED/PENDING/REJECTED

sdk.chat().updateChatRoomInviteStatus(
            chatRoomInvitation,
            ChatRoomInvitationStatus.ACCEPTED,
            object : LiveLikeCallback<ChatRoomInvitation>() {
                override fun onResponse(result: ChatRoomInvitation?, error: String?) {
                    result?.let {
                        showToast("Status: ${it.status}")
                    }
                    error?.let {
                        showToast(it)
                    }
                
                }
            })

Get List of Receive Invitations for Current User Profile With Status

By this API user can see the list of invitations received by the user with status.
The ChatRoomInvitationStatus is an enum and contains values PENDING,ACCEPTED,REJECTED

sdk.chat().getInvitationsForCurrentProfileWithInvitationStatus(
            pagination,
            ChatRoomInvitationStatus.PENDING,
            object : LiveLikeCallback<List<ChatRoomInvitation>>() {
                override fun onResponse(result: List<ChatRoomInvitation>?, error: String?) {
                    result?.let {
                       
                    }
                    error?.let {
                        showToast(it)
                    }
                    
                }
            })

Get List of Sent Invitation by Current User Profile With Status

This API allows the user to see the list of invitations sent by the current user to other users with invitation status.

sdk.chat().getInvitationsByCurrentProfileWithInvitationStatus(
                LiveLikePagination.FIRST,
                ChatRoomInvitationStatus.PENDING,
                object : LiveLikeCallback<List<ChatRoomInvitation>>() {
                    override fun onResponse(result: List<ChatRoomInvitation>?, error: String?) {
                        result?.let {
                           
                        }
                        error?.let {
                            showToast(it)
                        }
                        
                    }
                })