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 Android SDK: The SDK must be properly installed and initialized in your Android project. Refer to the installation guide if needed.
Steps to Filter State Messages in Chatroom
Step 1: Create List of States to filtered
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.
- Kotlin
- Java
val excludeConversationStates: List<ConversationState> = emptyList()
List<ConversationState> excludeConversationStates = new ArrayList<>();
You can choose the states to filtered out using the below table
Enum | Type | Example |
---|---|---|
NORMAL | Normal message | Hey |
FIRST_CONVERSATION | Chatroom first message | Tony Stark started this chatroom |
MEMBER_JOINED_OPEN_CHATROOM | Member joins open chatroom | Tony Stark joined this chatroom |
MEMBER_LEFT_OPEN_CHATROOM | Member leaves open chatroom | Tony Stark left this chatroom |
MEMBER_ADDED_TO_CHATROOM | Member added in chatroom | Nick Fury added Tony Stark |
MEMBER_LEFT_SECRET_CHATROOM | Member leaves secret chatroom | Tony Stark left this chatroom |
MEMBER_REMOVED_FROM_CHATROOM | Member is removed from a chatroom | Nick Fury removed Tony Stark |
POLL | Poll message | Nick Fury created a poll: "Who should lead the Avengers?" |
ALL_MEMBERS_ADDED | All members are added in a chatroom | Nick Fury added all members |
TOPIC_CHANGED | Chatroom topic changed | Nick Fury changed current to topic Hey |
DM_REQUEST_REJECTED | Direct Messaging Request is rejected | Nick Fury and Tony Stark are connected |
DM_REQUEST_ACCEPTED | Direct Messaging Request is accepted | Nick Fury rejected our request |
Step 2: Pass this list in the setup() function
Next, pass the filtered state list into the LMChatCore.setup()
function present in onCreate()
of your Application class. This applies your preferences, ensuring unwanted state messages are hidden when the chatroom loads.
- Kotlin
- Java
LMChatCore.setup(
application = application,
theme = lmChatTheme,
lmChatCoreCallback = lmChatCoreCallback,
lmChatAppearanceRequest = lmChatAppearanceRequest,
domain = domain,
enablePushNotifications = enablePushNotifications,
deviceId = deviceId,
shareLogsWithLM = shareLogsWithLM,
excludeConversationStates = excludeConversationStates
)
LMChatCore.INSTANCE.setup(
application,
lmChatTheme,
lmChatCoreCallback,
lmChatAppearanceRequest,
domain,
enablePushNotifications,
deviceId,
shareLogsWithLM,
excludeConversationStates
);
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.