Report offensive messages
PubNub provides a mechanism for users to report offensive content in messages directly from their applications. A moderator can then fetch these flagged messages from Message Persistence and either delete them or take appropriate action against the users who sent the messages.
User ID / UUID
User ID is also referred to as UUID
/uuid
in some APIs and server responses but holds the value of the userId
parameter you set during initialization.
Flag Messages
Use the addMessageAction
method to add a flag as an action to a published message. The flag is stored and linked to the original message, so you can see if messages are flagged or not when you fetch them from Message Persistence.
- JavaScript
- Swift
- Java
- Unity
pubnub.addMessageAction(
{
channel: 'ch-1'
messageTimetoken: '15610547826970040',
action: {
type: 'flagged',
value: 'message is inappropriate',
},
},
function(status, response) {
}
);
extension MyAppMessageAction: MessageAction {}
let action = MyAppMessageAction(type: "flagged", value: "message is inappropriate")
pubnub.addMessageAction(
channel: "ch-1",
message: action,
messageTimetoken: 15610547826969050
) { result in
switch result {
case let .success(response):
print("Successfully Message Action Add Response: \(response)")
case let .failure(error):
print("Error from failed response: \(error.localizedDescription)")
}
show all 16 linespubnub.addMessageAction()
.channel("ch-1")
.messageAction(new PNMessageAction()
.setType("flagged")
.setValue("message is inappropriate")
.setMessageTimetoken(15701761818730000L)
)
.async(result -> {
result.onSuccess(res -> {
System.out.println(res.getType());
System.out.println(res.getValue());
System.out.println(res.getUserId());
System.out.println(res.getActionTimetoken());
System.out.println(res.getMessageTimetoken());
}).onFailure(exception -> {
show all 18 linesMessageActionAdd messageAct = new MessageActionAdd();
messageAct.ActionType = "flagged";
messageAct.ActionValue = "message is inappropriate";
pubnub.AddMessageActions().Channel("ch-1").MessageAction(messageAct).MessageTimetoken(15701761818730000).Async((result, status) => {
if (!status.Error) {
Debug.Log("result.ActionTimetoken: " + result.ActionTimetoken);
Debug.Log("result.ActionType: " + result.ActionType);
Debug.Log("result.ActionValue: " + result.ActionValue);
Debug.Log("result.MessageTimetoken: " + result.MessageTimetoken);
Debug.Log("result.UserID: " + result.UserID);
} else {
Debug.Log(status.Error);
Debug.Log(status.ErrorData.Info);
}
show all 16 linesUnflag Messages
Use the removeMessageAction
method to remove a flag from a message.
- JavaScript
- Swift
- Java
- Unity
pubnub.removeMessageAction(
{
channel: 'ch-1'
messageTimetoken: '15610547826970040',
actionTimetoken: '15610547826970040',
},
function(status, response) {
}
);
pubnub.removeMessageActions(
channel: "ch-1",
message: 15610547826969050,
action: 15610547826970050
) { result in
switch result {
case let .success(response):
print("Successfully Message Action Remove Response: \(response)")
case let .failure(error):
print("Error from failed response: \(error.localizedDescription)")
}
})
pubnub.removeMessageAction()
.channel("ch-1")
.messageTimetoken(15701761818730000L)
.actionTimetoken(15701775691010000L)
.async(result -> { /* check result */ });
pubnub.RemoveMessageActions().ActionTimetoken(15701775691010000).Channel("ch-1").MessageTimetoken(15701761818730000).Async((result, status) => {
if (!status.Error) {
// result has no actionable data
} else {
Debug.Log(status.Error);
Debug.Log(status.ErrorData.Info);
}
});
Flagging Events
PubNub triggers events when flags are added or removed. Users that are subscribed to channels will receive these events.
Message action added:
{
"channel":"my_channel",
"subscription":null,
"timetoken":"15871508399473609",
"publisher":"user-1",
"message":{
"source":"actions",
"version":"1.0",
"action":"added",
"data":{
"type":"flagged",
"value":"message is inappropriate",
"messageTimetoken":"15632184115444390",
"actionTimetoken":"15632184115444394"
}
show all 17 linesMessage action removed:
{
"channel":"my_channel",
"subscription":null,
"timetoken":"15871508399473609",
"publisher":"user-1",
"message":{
"source":"actions",
"version":"1.0",
"action":"removed",
"data":{
"type":"flagged",
"value":"message is inappropriate",
"messageTimetoken":"15632184115444390",
"actionTimetoken":"15632184115444394"
}
show all 17 lines