Skip to main content

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

  1. 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:

StatesType
normalNormal message
firstConversationChatroom first message
memberJoinedOpenChatRoomMember joins open chatroom
memberLeftOpenChatRoomMember leaves open chatroom
memberAddedToChatRoomMember added in chatroom
memberLeftSecretRoomMember leaves secret chatroom
memberRemovedFromChatRoomMember is removed from a chatroom
pollPoll message
allMembersAddedAll members added in a chatroom
topicChangedChatroom topic changed
directMessageMemberRequestRejectedDirect Messaging Request rejected
directMessageMemberRequestApprovedDirect Messaging Request accepted
chatRoomCreaterChatroom creator message
chatRoomEditedChatroom settings edited
chatRoomJoinedMember joins via guest mode
directMessageCMRemovedCommunity manager removed from DM
directMessageMemberBecomesCMDisableChatMember becomes CM (chat disabled)
directMessageCMBecomesMemberEnableChatCM becomes member (chat enabled)
directMessageMemberBecomesCMEnableChatMember 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.