Like / Unlike Push Notifications issue

I have an app with a like functionality. Each time user A likes content X of user B:

  • It creates a notification request in my Firebase Database
  • Firebase functions observes the path on write & creates a push notification for user B

But when user A likes -> unlikes -> likes content X, user B gets another push notification.

How is it possible to decline further notification requests by user A for content X?

This is the Firebase Functions code:

exports.sendLikeNotification = likeRef.onWrite(event => {

  if ( {

  var notificationId = event.params.likeNotificationId;
  var notificationRequest =;
  var receiverId = notificationRequest.receiverId;
  var message = notificationRequest.message
  var data =

  var topic = '/topics/user_' + receiverId;

  var payload = {
    notification: {
      body: message,
      sound: 'default'
    data: { data }

  var options = {
    priority: "high",
    contentAvailable: true

  // Send a message to devices subscribed to the provided topic.
  admin.messaging().sendToTopic(topic, payload, options)
    .then(function(response) {
      console.log("Successfully sent message:", response);
    .catch(function(error) {
      console.log("Error sending message:", error);

Thank you!