Skip to main content
Quick Reference for AI Agents & Developers
  • Get flag reasons: CometChat.getFlagReasons(onSuccess:onError:)
  • Flag message: CometChat.flagMessage(messageId:detail:onSuccess:onError:)
  • Review flagged: CometChat Dashboard → Moderation → Flagged Messages
  • Related: Moderation · AI Moderation · Messaging Overview

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

Before using the flag message feature:
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)")
}
Method: CometChat.getFlagReasons(onSuccess:onError:)No parameters required.

Flag a Message

To flag a message, use the flagMessage() method 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)")
}
Method: CometChat.flagMessage(messageId:detail:onSuccess:onError:)
ParameterTypeValue
messageIdInt12345
reasonIdString"spam"
remarkString"This message contains promotional content"
FlagDetail Object:
ParameterTypeRequiredDescription
messageIdIntYESID of message to flag
reasonIdStringYESID from getFlagReasons()
remarkStringNOAdditional context
Request:
ParameterTypeValue
messageIdInt12345
reasonIdString"harassment"
remarkString"Inappropriate behavior towards other users"
Swift Code:
let flagDetail = FlagDetail(
    messageId: 12345,
    reasonId: "harassment",
    remark: "Inappropriate behavior towards other users"
)
CometChat.flagMessage(messageId: 12345, detail: flagDetail) { response in
    print("Message flagged: \(response)")
} onError: { error in
    print("Error: \(error?.errorDescription)")
}

Implementation Flow

StepActionMethod
1Load flag reasons on app initCometChat.getFlagReasons()
2Cache reasons for UIStore in array/state
3Show reason picker to userDisplay cached reasons
4User selects reason + remarkCapture selection
5Submit flagCometChat.flagMessage()
6Review in DashboardModeration > Flagged

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 ?? "")")
        }
    }
}

Common Error Codes

Error CodeDescriptionResolution
ERR_NOT_LOGGED_INUser is not logged inLogin first
ERR_MESSAGE_NOT_FOUNDMessage doesn’t existVerify message ID
ERR_INVALID_REASON_IDInvalid flag reason IDUse ID from getFlagReasons()
ERR_FEATURE_NOT_ACCESSIBLEModeration not enabledEnable in Dashboard or upgrade plan