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
onMessageReported() monitors report events for moderation dashboards via a closure. You can also use channel.stream.reports() for an AsyncStream-based approach.
Deprecation
streamMessageReports() is deprecated. Use onMessageReported() (closure-based) or channel.stream.reports() (AsyncStream-based) instead.
Events documentation
To read more about the events of type Report, refer to the Chat events documentation.
Method signature
1channel.onMessageReported(
2 callback: @escaping (Report) -> Void
3) -> AutoCloseable
The Report struct carries the report payload:
1public struct Report {
2 public let reason: String
3 public let text: String?
4 public let messageTimetoken: Timetoken?
5 public let reportedMessageChannelId: String?
6 public let reportedUserId: String?
7 public let autoModerationId: String?
8}
Input
| Parameter | Description |
|---|---|
callback *Type: (Report) -> VoidDefault: n/a | Closure called with a Report whenever a message is reported on the channel. |
Output
| Parameter | Description |
|---|---|
AutoCloseable | An object you must retain. When released or closed, the listener stops. |
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