Skip to main content

Customizing Conversation List Data Processing

The data processing mechanism supports the following custom operations for conversation lists:

  • Filter conversations by type. Filtered conversations won't appear in the list.
  • Filter conversations using custom rules. Only filtered data will display.
  • Aggregate specific conversation types. Merge designated conversations into a single display.

Data Processor (Abstract Class)

The data processor is provided as an abstract class, compatible with stable versions in the 5.1.3.x series and all versions after 5.1.5. For other versions, refer to the Data Processing Interface section.

Data Processor Specifications

Name: BaseDataProcessor

This abstract class provides three overridable methods for functional customization:

Return TypeMethod
Conversation.ConversationType[]supportedTypes()
List<T>filtered(List<T> data)
booleanisGathered(Conversation.ConversationType type)
booleanisGathered(ConversationIdentifier identifier)

Method Details

  • supportedTypes()

    Returns an array of supported conversation types. Default: all types.

  • filtered(List<T> data)

    Filters conversation data. Triggered when batch-fetching conversations from database or receiving new messages.

    ParameterTypeDescription
    dataList<T>Data to be filtered
  • isGathered(Conversation.ConversationType type)

    Determines whether conversations of a specific type should be aggregated. Returns true for aggregation.

    When enabled, all conversations of this type will display as a single entry. Clicking it navigates to the aggregated list. See Aggregating Conversations by Type.

  • isGathered(ConversationIdentifier identifier)

    ParameterTypeDescription
    identifierConversationIdentifier(Added in SDK 5.3.0) Contains Conversation.ConversationType and targetId(String).

    (Default method in DataProcessor interface) Controls conversation aggregation. Returns true for aggregation.

    When enabled, conversations will display as a single entry. Clicking navigates to the aggregated list. See Aggregating Conversations by Type.

Custom Data Processing

  1. Create a custom processor. Extend BaseDataProcessor and override methods as needed.

    Example: MyDataProcessor

    public class MyDataProcessor extends BaseDataProcessor<Conversation> {
    /**
    * Customize supported conversation types (only one-to-one and group chats here).
    */
    @Override
    public Conversation.ConversationType[] supportedTypes() {
    Conversation.ConversationType[] types = {Conversation.ConversationType.PRIVATE, Conversation.ConversationType.GROUP};
    return types;
    }

    /**
    * Aggregate system conversations.
    */
    @Override
    public boolean isGathered(Conversation.ConversationType type) {
    return type.equals(Conversation.ConversationType.SYSTEM);
    }

    /**
    * Aggregate system conversations (SDK 5.3.0+).
    */
    @Override
    public boolean isGathered(ConversationIdentifier identifier) {
    return identifier.getType().equals(Conversation.ConversationType.SYSTEM);
    }
    }
  2. Configure the processor. Set your custom processor before opening the conversation list:

    RongConfigCenter.conversationListConfig().setDataProcessor(new MyDataProcessor());

Data Processing Interface

For pre-5.1.5 development versions, use this interface for conversation filtering.

⚠️ Warning: Default null returns in Android Studio implementations may cause empty conversation lists. Always return processed/original data.

We strongly recommend upgrading to stable versions and using the Data Processor instead.

Interface Specifications

public interface DataProcessor<T> {
/**
* Defines supported conversation types.
* @return Array of supported types
*/
Conversation.ConversationType[] supportedTypes();

/**
* Filters conversation data.
* <p>Triggers during batch database fetches and new message arrivals.</p>
* @param data Data to filter
* @return Filtered data (never return null!)
*/
List<T> filtered(List<T> data);

/**
* Checks if a conversation type should be aggregated.
* @param type Conversation type
*/
boolean isGathered(Conversation.ConversationType type);

/**
* Checks if a conversation should be aggregated (SDK 5.3.0+).
* @param identifier Conversation identifier
*/
default boolean isGathered(ConversationIdentifier identifier) {
return identifier != null && isGathered(identifier.getType());
}
}

Custom Implementation

  1. Create a processor class implementing DataProcessor:

    private Conversation.ConversationType[] supportedTypes = {
    Conversation.ConversationType.PRIVATE,
    Conversation.ConversationType.GROUP,
    Conversation.ConversationType.SYSTEM
    };

    public class MyDataProcessor implements DataProcessor<Conversation> {
    @Override
    public Conversation.ConversationType[] supportedTypes() {
    return supportedTypes;
    }

    @Override
    public List<Conversation> filtered(List<Conversation> data) {
    return data; // Never return null!
    }

    @Override
    public boolean isGathered(Conversation.ConversationType type) {
    return type.equals(Conversation.ConversationType.SYSTEM);
    }

    @Override
    public boolean isGathered(ConversationIdentifier identifier) {
    return identifier.getType().equals(Conversation.ConversationType.SYSTEM);
    }
    }
  2. Configure the processor before opening the conversation list:

    RongConfigCenter.conversationListConfig().setDataProcessor(new MyDataProcessor());