Filtering Messages

By filtering messages, we can get messages that only match certain criteria:

  • with the includingTags and excludingTags parameters you can filter messages based on the tags set (or not set) in each message

  • with the messageParentFilter parameter you can filter messages according to their relationship:

    • if no .noParentis passed, any message will match

    • if parent(id: String?) is passed without id, search all messages without a parent

    • if a non-zero id id passed: query for all messages with the parentId as parent.

  • with the type parameter you can filter messages according to their type

    • if no type is passed, any message will match

    • if an AmityMessageType is passed, query for all messages with the specific type

      • AmityMessageType.text for text messages

      • AmityMessageType.image for image messages

      • AmityMessageType.file for file messages

      • AmityMessageType.audio for audio messages

      • AmityMessageType.video for video messages

      • AmityMessageType.custom for custom messages

// queries for messages tagged as "games", and not tagged as "staff-only"
let messageQueryOptions = AmityMessageQueryOptions(channelId: "channel-123", includingTags: ["games"], excludingTags: ["staff-only"], orderBy: .descending)
let messagesCollection = messageRepository.getMessages(options: messageQueryOptions)

// queries for messages without a parent
let messageQueryOptions = AmityMessageQueryOptions(channelId: "channel-123", messageParentFilter: .noParent, orderBy: .descending)
let messagesCollection2 = messageRepository.getMessages(options: messageQueryOptions)

// queries for children messages of a message with id "999"
let messageQueryOptions = AmityMessageQueryOptions(channelId: "channel-123", messageParentFilter: .parent(id: "999"), orderBy: .descending)
let messagesCollection3 = messageRepository.getMessages(options: messageQueryOptions)

Last updated