How to filter state messages in a chatroom?
With the LikeMinds Chat SDK, you have full control over which state messages show up in a chatroom. Whether it's join/leave notifications, system alerts, or other updates, you can decide what stays and what gets filtered out. This guide will walk you through the simple steps to customize message visibility, so your chatroom stays clean, relevant, and free from unnecessary distractions.
Prerequisites
- LikeMinds Chat iOS SDK: The SDK must be properly installed and initialized in your iOS project. Refer to the installation guide if needed.
Steps to Filter State Messages in Chatroom
Step 1: Create List of States to Filter
First, define the list of state messages you want to filter using the ConversationState
enum. This ensures only relevant messages appear in the chatroom, keeping conversations clean and focused.
var excludedConversationStates: [ConversationState] = []
You can choose the states to filter out using the table below:
States | Type |
---|---|
normal | Normal message |
firstConversation | Chatroom first message |
memberJoinedOpenChatRoom | Member joins open chatroom |
memberLeftOpenChatRoom | Member leaves open chatroom |
memberAddedToChatRoom | Member added in chatroom |
memberLeftSecretRoom | Member leaves secret chatroom |
memberRemovedFromChatRoom | Member is removed from a chatroom |
poll | Poll message |
allMembersAdded | All members added in a chatroom |
topicChanged | Chatroom topic changed |
directMessageMemberRequestRejected | Direct Messaging Request rejected |
directMessageMemberRequestApproved | Direct Messaging Request accepted |
chatRoomCreater | Chatroom creator message |
chatRoomEdited | Chatroom settings edited |
chatRoomJoined | Member joins via guest mode |
directMessageCMRemoved | Community manager removed from DM |
directMessageMemberBecomesCMDisableChat | Member becomes CM (chat disabled) |
directMessageCMBecomesMemberEnableChat | CM becomes member (chat enabled) |
directMessageMemberBecomesCMEnableChat | Member becomes CM (chat enabled) |
Step 2: Pass This List in the SetupChat() Function
Next, pass the filtered state list into the LMChatCore.setupChat()
function present in application
of your AppDelegate.swift class file. This applies your preferences, ensuring unwanted state messages are hidden when the chatroom loads.
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
LMChatCore.shared.setupChat(
deviceId: "YOUR_DEVICE_ID",
excludedConversationStates: excludedConversationStates
)
return true
}
Conclusion
By filtering state messages, you can create a cleaner and more focused chat experience. With just a few steps, you control what appears in the chatroom, ensuring users see only the most relevant updates.