Skip to main content

Leave Chatroom

The LikeMinds iOS SDK allows users to leave chatrooms, whether open or secret. This guide outlines the steps to leave either type of chatroom using the SDK.

Steps to Leave an Open Chatroom

  1. Create an object of the FollowChatroomRequest class using its builder pattern. Pass false to the value parameter to indicate leaving the chatroom.
  2. Call the followChatroom() function in the LMChatClient class, passing the constructed request object.
  3. Process the LMResponse<NoData> response to confirm whether the user successfully left the chatroom or handle any errors.
let request = FollowChatroomRequest.builder()
.chatroomId("ENTER_CHATROOM_ID")
.uuid("ENTER_UUID")
.value(false) // Indicating the user wants to leave
.build()

LMChatClient.shared.followChatroom(request: request) { response in
if response?.error == nil {
// Handle success
print("Successfully left the open chatroom.")
} else {
// Handle error
print("Error leaving the open chatroom: \(response?.error?.localizedDescription ?? "Unknown error")")
}
}

Steps to Leave a Secret Chatroom

  1. Create a LeaveSecretChatroomRequest object using its builder pattern.
  2. Call the leaveSecretChatroom() function in the LMChatClient class, passing the constructed request object.
  3. Process the LMResponse<NoData> response to confirm whether the user successfully left the chatroom or handle any errors.
let request = LeaveSecretChatroomRequest.builder()
.chatroomId("ENTER_CHATROOM_ID")
.uuid("ENTER_UUID")
.isSecret(true) // Ensure this is set for secret chatrooms
.build()

LMChatClient.shared.leaveSecretChatroom(request: request) { response in
if response?.error == nil {
// Handle success
print("Successfully left the secret chatroom.")
} else {
// Handle error
print("Error leaving the secret chatroom: \(response?.error?.localizedDescription ?? "Unknown error")")
}
}

Models

LeaveSecretChatroomRequest

VARIABLETYPEDESCRIPTIONOPTIONAL
chatroomIdStringID of the chatroom to leave
isSecretBoolFlag to indicate that the chatroom is secret
uuidStringUnique identifier for the user leaving the chatroom