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

val excludeConversationStates: List<ConversationState> = emptyList()

You can choose the states to filtered out using the below table

EnumTypeExample
NORMALNormal messageHey
FIRST_CONVERSATIONChatroom first messageTony Stark started this chatroom
MEMBER_JOINED_OPEN_CHATROOMMember joins open chatroomTony Stark joined this chatroom
MEMBER_LEFT_OPEN_CHATROOMMember leaves open chatroomTony Stark left this chatroom
MEMBER_ADDED_TO_CHATROOMMember added in chatroomNick Fury added Tony Stark
MEMBER_LEFT_SECRET_CHATROOMMember leaves secret chatroomTony Stark left this chatroom
MEMBER_REMOVED_FROM_CHATROOMMember is removed from a chatroomNick Fury removed Tony Stark
POLLPoll messageNick Fury created a poll: "Who should lead the Avengers?"
ALL_MEMBERS_ADDEDAll members are added in a chatroomNick Fury added all members
TOPIC_CHANGEDChatroom topic changedNick Fury changed current to topic Hey
DM_REQUEST_REJECTEDDirect Messaging Request is rejectedNick Fury and Tony Stark are connected
DM_REQUEST_ACCEPTEDDirect Messaging Request is acceptedNick 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.

LMChatCore.setup(
application = application,
theme = lmChatTheme,
lmChatCoreCallback = lmChatCoreCallback,
lmChatAppearanceRequest = lmChatAppearanceRequest,
domain = domain,
enablePushNotifications = enablePushNotifications,
deviceId = deviceId,
shareLogsWithLM = shareLogsWithLM,
excludeConversationStates = 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.