Report offensive messages
Users can report offensive messages directly from your app. Reported messages publish to PUBNUB_INTERNAL_MODERATION_{channel_id} and emit Report events.
Add custom logic using emitted events to handle reported messages (e.g., delete them).
Message Persistence
Enable Message Persistence in the Admin Portal.
Flag/Report messages
report() flags a message for admin review. Reports publish to PUBNUB_INTERNAL_MODERATION_{channel_id} (e.g., reporting on support sends to PUBNUB_INTERNAL_MODERATION_support).
Method signature
This method takes the following parameters:
1message.report(
2 reason: String
3) async throws -> Timetoken
Input
| Parameter | Description |
|---|---|
reason *Type: StringDefault: n/a | Reason for reporting/flagging a given message. |
Output
| Parameter | Description |
|---|---|
Timetoken | The Timetoken value of the reported message. |
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Report the last message on the support channel as offensive.
1
Get historical reported messages
getMessageReportsHistory() fetches reported message events for a channel with optional time and count filters.
Method signature
This method takes the following parameters:
1channel.getMessageReportsHistory(
2 startTimetoken: Timetoken? = nil,
3 endTimetoken: Timetoken? = nil,
4 count: Int = 25
5) async throws -> (events: [EventWrapper<EventContent>], isMore: Bool)
Input
| Parameter | Description |
|---|---|
startTimetokenType: TimetokenDefault: n/a | The start timetoken for fetching the history of reported messages, which allows specifying the point in time where the history retrieval should begin. |
endTimetokenType: TimetokenDefault: n/a | The end time token for fetching the history of reported messages, which allows specifying the point in time where the history retrieval should end. |
countType: IntDefault: 25 | The number of reported message events to fetch from the history. |
Output
| Parameter | Description |
|---|---|
(events: [EventWrapper<EventContent>], isMore: Bool) | Returned tuple containing these fields: events and isMore. |
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Fetch historical messages reported on the support channel between the 1725100800000 (July 1, 2024, 00:00:00 UTC) and 1726780799000 (July 21, 2024, 23:59:59 UTC) timetokens.
1
Listen to Report events
streamMessageReports() monitors report events for moderation dashboards.
Events documentation
To read more about the events of type Report, refer to the Chat events documentation.
Method signature
This method has the following parameters:
1channel.streamMessageReports() -> AsyncStream<EventWrapper<EventContent.Report>>
Input
This method doesn't take any parameters.
Output
| Parameter | Description |
|---|---|
AsyncStream<EventWrapper<EventContent.Report>> | An asynchronous stream that emits a new value whenever a message is reported. |
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Print a notification for an offensive message reported on the support channel.
1