Class ChatQuery


  • public class ChatQuery
    extends Query<KSChatMessage,​ChatQuery>
    ChatQuery is a chainable query builder for filtering and processing collections of KSChatMessages using various criteria such as message content, type, sender, timestamps, and more. It safely caches the original data internally and applies dynamic filters on-demand using a composite Predicate.
    • Constructor Detail

      • ChatQuery

        public ChatQuery​(java.util.Collection<KSChatMessage> messages)
        Constructs a new ChatQuery from a collection of chat messages.
        Parameters:
        chats - The collection of chat messages to initialize the query with.
    • Method Detail

      • contains

        public ChatQuery contains​(java.lang.String string)
        Filters messages that contain a specified string in their message content.
        Parameters:
        string - The substring or wildcard pattern to match.
        Returns:
        The updated ChatQuery instance.
      • withType

        public ChatQuery withType​(KSChatMessage.MessageTypes type)
        Filters messages of a specific chat type.
        Parameters:
        type - The desired MessageTypes enum.
        Returns:
        The updated ChatQuery instance.
      • withoutType

        public ChatQuery withoutType​(KSChatMessage.MessageTypes type)
        Excludes messages of a specific chat type.
        Parameters:
        type - The MessageTypes to exclude.
        Returns:
        The updated ChatQuery instance.
      • betweenTimestamps

        public ChatQuery betweenTimestamps​(long startTimestamp,
                                           long endTimestamp)
        Filters messages between two timestamps (inclusive lower bound, exclusive upper).
        Parameters:
        startTimestamp - The start timestamp (inclusive).
        endTimestamp - The end timestamp (exclusive).
        Returns:
        The updated ChatQuery instance.
      • messagesAgo

        public ChatQuery messagesAgo​(long duration,
                                     java.util.concurrent.TimeUnit timeUnit)
        Filters messages sent within the given time duration from now.
        Parameters:
        duration - The duration to look back.
        timeUnit - The unit of time (e.g., SECONDS, MINUTES).
        Returns:
        The updated ChatQuery instance.