Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

// Get available flag reasons
CometChat.getFlagReasons { reasons in } onError: { error in }

// Flag a message
let detail = FlagDetail(messageId: 12345, reasonId: "spam", remark: "Promotional content")
CometChat.flagMessage(messageId: 12345, detail: detail) { response in } onError: { error in }

Overview

Flagging messages allows users to report inappropriate content to moderators or administrators. When a message is flagged, it appears in the CometChat Dashboard under Moderation > Flagged Messages for review.
For a complete understanding of how flagged messages are reviewed and managed, see the Flagged Messages documentation.

Prerequisites

RequirementLocation
Enable ModerationCometChat Dashboard > App Settings
Configure Flag ReasonsDashboard > Moderation > Advanced Settings

How It Works

Get Flag Reasons

Before flagging a message, retrieve the list of available flag reasons configured in your Dashboard:
CometChat.getFlagReasons { reasons in
    print("Flag reasons: \(reasons)")
    for reason in reasons {
        print("ID: \(reason.id ?? "")")
    }
} onError: { error in
    print("Error: \(error?.errorDescription)")
}

Flag a Message

Use flagMessage() with the message ID and a FlagDetail object:
let flagDetail = FlagDetail(
    messageId: 12345,
    reasonId: "spam",
    remark: "This message contains promotional content"
)

CometChat.flagMessage(messageId: 12345, detail: flagDetail) { response in
    print("Message flagged: \(response)")
} onError: { error in
    print("Error: \(error?.errorDescription)")
}

Parameters

ParameterTypeRequiredDescription
messageIdIntYesID of the BaseMessage to flag
reasonIdStringYesID from getFlagReasons()
remarkStringNoAdditional context

Complete Example

class ReportMessageHandler {
    private var flagReasons: [FlagReason] = []

    func loadFlagReasons(completion: @escaping ([FlagReason]) -> Void) {
        CometChat.getFlagReasons { [weak self] reasons in
            self?.flagReasons = reasons
            completion(reasons)
        } onError: { error in
            completion([])
        }
    }

    func flagMessage(messageId: Int, reasonId: String, remark: String?) {
        let flagDetail = FlagDetail(
            messageId: messageId,
            reasonId: reasonId,
            remark: remark ?? ""
        )

        CometChat.flagMessage(messageId: messageId, detail: flagDetail) { response in
            print("Success: \(response)")
        } onError: { error in
            print("Error: \(error?.errorDescription ?? "")")
        }
    }
}

Next Steps

AI Moderation

Automate content moderation with AI

Delete a Message

Remove messages from conversations

Receive Messages

Listen for incoming messages in real time

Send Messages

Send text, media, and custom messages