When you send a text, image, or video message, check the initial moderation status:
JavaScript
TypeScript
Report incorrect code
Copy
Ask AI
const textMessage = new CometChat.TextMessage( receiverUID, "Hello, how are you?", CometChat.RECEIVER_TYPE.USER);CometChat.sendMessage(textMessage).then( (message) => { // Check moderation status const status = message.getModerationStatus(); if (status === CometChat.ModerationStatus.PENDING) { console.log("Message is under moderation review"); // Show pending indicator in UI } }, (error) => { console.log("Message sending failed:", error); });
Report incorrect code
Copy
Ask AI
const textMessage = new CometChat.TextMessage( receiverUID, "Hello, how are you?", CometChat.RECEIVER_TYPE.USER);CometChat.sendMessage(textMessage).then( (message: CometChat.TextMessage) => { // Check moderation status const status: string = message.getModerationStatus(); if (status === CometChat.ModerationStatus.PENDING) { console.log("Message is under moderation review"); // Show pending indicator in UI } }, (error: CometChat.CometChatException) => { console.log("Message sending failed:", error); });
When a message is disapproved, you should handle it appropriately in your UI:
Report incorrect code
Copy
Ask AI
function handleDisapprovedMessage(message) { const messageId = message.getId(); // Option 1: Hide the message completely hideMessageFromUI(messageId); // Option 2: Show a placeholder message showBlockedPlaceholder(messageId, "This message was blocked by moderation"); // Option 3: Notify the sender (if it's their message) if (message.getSender().getUid() === currentUserUID) { showNotification("Your message was blocked due to policy violation"); }}
Always remove listeners when they’re no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.