Message Reactions API for PubNub Android SDK

Add or remove actions on published messages to build features like receipts, reactions, or to associate custom metadata to messages. Clients can subscribe to a channel to receive message reaction events on that channel. They can also fetch past message reactions from Message Persistence independently or when they fetch original messages.

Terminology

All message reactions in code are collectively called message reactions in the docs and the term applies both to reacting to a message (through emojis) and acting on a message (by deleting it).

Add Message Reaction

Requires Message Persistence

This method requires that Message Persistence is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Add an action on a published message. Returns the added action in the response.

Method(s)

To Add a Message Reaction you can use the following method(s) in the Android SDK:

this.pubnub.addMessageAction()
.channel(String)
.messageAction(PNMessageAction);
ParameterTypeRequiredDescription
channelStringYesSpecifies channel name to publish message reactions to.
messageActionPNMessageActionYesThe message reaction object containing the message reaction's type, value and the publish timetoken of the original message.
asyncPNCallbackYesPNCallback of type PNAddMessageActionResult.

Basic Usage

pubnub.addMessageAction()
.channel("my_channel")
.messageAction(new PNMessageAction()
.setType("reaction")
.setValue("smiley_face")
.setMessageTimetoken(15701761818730000L)
)
.async(new PNCallback<PNAddMessageActionResult>() {
@Override
public void onResponse(PNAddMessageActionResult result, PNStatus status) {
if (!status.isError()) {
System.out.println(result.getType());
System.out.println(result.getValue());
System.out.println(result.getUuid());
System.out.println(result.getActionTimetoken());
show all 21 lines

Returns

The addMessageAction() operation returns a PNAddMessageActionResult which contains the following operations:

MethodTypeDescription
getType()StringMessage reaction's type.
getValue()StringMessage reaction's value.
getUuid()StringPublisher of the message reaction.
getActionTimetoken()LongTimestamp when the message reaction was created.
getMessageTimetoken()LongTimestamp when the actual message was created the message reaction belongs to.

NMessageAction

MethodTypeDescription
setType()StringMessage reaction's type.
setValue()StringMessage reaction's value.
setMessageTimetoken()LongTimestamp of the actual message was created the message reaction belongs to.

Remove Message Reaction

Requires Message Persistence

This method requires that Message Persistence is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Remove a previously added action on a published message. Returns an empty response.

Method(s)

To remove a Message Reaction you can use the following method(s) in the Android SDK:

this.pubnub.removeMessageAction()
.channel(String)
.messageTimetoken(Long)
.actionTimetoken(Long);
ParameterTypeRequiredDescription
channelStringYesSpecifies channel name to publish message reactions to.
messageTimetokenLongYesPublish timetoken of the original message
actionTimetokenLongYesPublish timetoken of the message reaction to be removed.
asyncPNCallbackYesPNCallback of type PNRemoveMessageActionResult.

Basic Usage

pubnub.removeMessageAction()
.channel("my_channel")
.messageTimetoken(15701761818730000L)
.actionTimetoken(15701775691010000L)
.async(new PNCallback<PNRemoveMessageActionResult>() {
@Override
public void onResponse(PNRemoveMessageActionResult result, PNStatus status) {
if (!status.isError()) {
// result has no actionable data
// it's enough to check if the status itself is not an error
} else {
status.getErrorData().getThrowable().printStackTrace();
}
}
});

Returns

The removeMessageAction() operation returns a no actionable data.

Get Message Reactions

Requires Message Persistence

This method requires that Message Persistence is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.

Get a list of message reaction in a channel. Returns a list of actions sorted by the action's timetoken in ascending order.

Truncated response

Number of message reactions in the response may be truncated when internal limits are hit. If the response is truncated, a more property will be returned with additional parameters. Send iterative calls to Message Persistence adjusting the parameters to fetch more message reactions.

Method(s)

To Get Message Reactions you can use the following method(s) in the Android SDK:

this.pubnub.getMessageActions()
.channel(String)
.start(Long)
.end(Long)
.limit(Integer);
ParameterTypeRequiredDefaultDescription
channelStringYesThe channel name.
startLongOptionalMessage Reaction timetoken denoting the start of the range requested (return values will be less than start).
endLongOptionalMessage Reaction timetoken denoting the end of the range requested (return values will be greater than or equal to end).
limitIntegerOptional100Specifies the number of actions to return in response. Default/Maximum is 100.
asyncPNCallbackYesPNCallback of type PNGetMessageActionsResult.

Basic Usage

pubnub.getMessageActions()
.channel("my_channel")
.async(new PNCallback<PNGetMessageActionsResult>() {
@Override
public void onResponse(PNGetMessageActionsResult result, PNStatus status) {
if (!status.isError()) {
List<PNMessageAction> actions = result.getActions();
for (PNMessageAction action : actions) {
System.out.println(action.getType());
System.out.println(action.getValue());
System.out.println(action.getUuid());
System.out.println(action.getActionTimetoken());
System.out.println(action.getMessageTimetoken());
}
} else {
show all 19 lines

Returns

The getMessageActions() operation returns a list of PNGetMessageActionsResult objects, each containing the following operations:

MethodTypeDescription
getType()StringMessage reaction's type.
getValue()StringMessage reaction's value.
getUuid()StringPublisher of the message reaction.
getActionTimetoken()LongTimestamp when the message reaction was created.
getMessageTimetoken()LongTimestamp when the actual message was created the message reaction belongs to.

Other Examples

Fetch Messages with paging

public static void main(String args[]){
getMessageActionsWithPaging("my_channel", System.currentTimeMillis() * 10_000L, new Callback() {
@Override
public void onMore(List<PNMessageAction> actions) {
System.out.println("Next set of actions: " + actions.size());
}

@Override
public void onDone() {
System.out.println("All actions fetched");
}
});
}

/**
show all 45 lines
Last updated on