When a user sends a message, likely you are publishing that message so that actively subscribed users will receive that message in realtime and also as a mobile push notification (APNS or FCM) so that offline users (that were actively subscribed) get the message as a mobile push message. But if the sender backgrounds the app very quickly after sending the message, it is possible that they will get a push notification for the message they just sent. This is not likely the behavior you intended.


Using the pn_exceptions attribute, you can prevent this from happening. For any message that gets published, create the message payload so that the sending device's push token is added to this key. Notice that each type of push notification has its own pn_exceptions attribute.

{
    "pn_apns" : {
        "aps" : {
            "alert" : {
                "body" : "hello (via APNS)"
            }
        },
        "pn_exceptions" : [
            "da284603e1e96ac453541cd1942659808a69c09fb1dbb2e3c11aba6cdcaec642"
        ]
    },
    "pn_gcm" : {
        "alert" : "hello (via FCM)",
        "pn_exceptions" : [
            "2643d955c7f2506e55f225b56da7eb8676cced80de93df51aad7569ee833b92f"
        ]
    },
    text : "hello (in realtime)"
}


If you need to exclude more than just the sender device, you can add as many device push tokens as required. Perhaps a user has multiple devices and you do not want to send the user's message (as a push notification) to any of that user's devices.


You can also do this for the realtime messages, too, using a Stream Filter.