pubnub / dart

PubNub Dart SDK
Other
28 stars 15 forks source link

MessageAction event listener for updating delivery and read receipts #9

Closed devopsokdone closed 4 years ago

devopsokdone commented 4 years ago

Our use-case involves all recipients in the channel to send a Delivery and Read receipt for each received message, to the message sender. Like we have in popular messengers like Whatsapp.

We have used message transaction type messageAction for the same and able to update message as delivered and read on the server, once this is done server needs to relay this message to message sender client where delivery and read receipt need to be updated in the sent message record.

As per documentation of PubNub Event Listeners - Use event listener message action events that are published to notify clients when Message Actions are added to or removed from messages. To receive these events, clients should be subscribed to the channel, and add a messageAction listener.

We tried to implement messageAction listener but this option does not exist in Dart SDK or we may be missing something. For us message delivery and read receipts features are critical and we would like to implement it using messageAction, please suggest how this can be achieved with Dart SDK.

mohitpubnub commented 4 years ago

Hi, thanks for drawing our attention! Subscription will get the event messages for messageAction operations. From dart v1.4.1 onwards, To filter out notifications, You can try something like:

  var subscription = await pubnub.subscribe(channels: {'my_channel'});

  subscription.messages.listen((envelope) {
    if (envelope.messageType == MessageType.messageAction) {
      // Do something with messageAction event data
      // print(envelope.payload['data']);
    }
  });