Message Reactions API for PubNub Objective-C SDK

Add or remove reactions 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.

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.

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).

Method(s)

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

- (void)addMessageActionWithRequest:(PNAddMessageActionRequest *)request 
completion:(nullable PNAddMessageActionCompletionBlock)block;
ParameterTypeRequiredDescription
requestPNAddMessageActionRequestYesAdd message reaction request with all information about new message reaction which will be passed to PubNub service.
blockPNAddMessageActionCompletionBlockNoAdd message reaction request completion block.

PNAddMessageActionRequest

ParameterTypeRequiredDescription
typeNSStringYesWhat feature this message reaction represents. Maximum 15 characters.
valueNSStringYesValue which should be added with message reaction type.
channelNSStringYesName of channel which stores the message for which action should be added.
messageTimetokenNSNumberYesTimetoken (PubNub's high precision timestamp) of message to which action should be added.

Basic Usage

PNAddMessageActionRequest *request = [PNAddMessageActionRequest requestWithChannel:@"chat"
messageTimetoken:@(1234567890)];
request.type = @"reaction";
request.value = @"smile";

[self.client addMessageActionWithRequest:request completion:^(PNAddMessageActionStatus *status) {
if (!status.isError) {
/**
* Message reaction successfully added.
* Created message reaction information available here: status.data.action
*/
} else {
if (status.statusCode == 207) {
// Message reaction has been added, but event not published.
} else {
show all 24 lines

Response

Response objects which is returned by client when add message reaction Message Reaction API is used:

@interface PNAddMessageActionData : PNServiceData

// Added message reaction.
@property (nonatomic, nullable, readonly, strong) PNMessageAction *action;

@end

@interface PNAddMessageActionStatus : PNAcknowledgmentStatus

// Add message reaction request processed information.
@property (nonatomic, readonly, strong) PNAddMessageActionData *data;

@end

Add Message Reaction (Builder Pattern)

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 Objective-C SDK:

addMessageAction()
.channel(NSString *)
.messageTimetoken(NSNumber *)
.type(NSString *)
.value(NSString *)
.performWithCompletion(nullable PNAddMessageActionCompletionBlock);
ParameterTypeRequiredDescription
channelNSStringYesName of channel which store message for which action should be added.
messageTimetokenNSNumberYesTimetoken of message for which action should be added.
typeNSStringYesWhat feature this message reaction represents.
valueNSStringYesValue which should be stored along with message reaction.
blockPNAddMessageActionCompletionBlockNoAdd message reaction request completion block.

Basic Usage

self.client.addMessageAction()
.channel(@"chat")
.messageTimetoken(@(1234567890))
.type(@"reaction")
.value(@"smile")
.performWithCompletion(^(PNAddMessageActionStatus *status) {
if (!status.isError) {
/**
* Message reaction successfully added.
* Created message reaction information available here: status.data.action
*/
} else {
if (status.statusCode == 207) {
// Message reaction has been added, but event not published.
} else {
show all 24 lines

Response

Response objects which is returned by client when add message reaction Message Reaction API is used:

@interface PNAddMessageActionData : PNServiceData

// Added message reaction.
@property (nonatomic, nullable, readonly, strong) PNMessageAction *action;

@end

@interface PNAddMessageActionStatus : PNAcknowledgmentStatus

// Add message reaction request processed information.
@property (nonatomic, readonly, strong) PNAddMessageActionData *data;

@end

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 Objective-C SDK:

- (void)removeMessageActionWithRequest:(PNRemoveMessageActionRequest *)request 
completion:(nullable PNRemoveMessageActionCompletionBlock)block;
ParameterTypeRequiredDescription
requestPNRemoveMessageActionRequestYesRemove message reaction request with information about existing message reaction.
blockPNRemoveMessageActionCompletionBlockNoRemove message reaction request completion block.

PNRemoveMessageActionRequest

ParameterTypeRequiredDescription
actionTimetokenNSNumberYesMessage reaction addition timetoken.
channelNSStringYesName of channel which store message for which action should be removed.
messageTimetokenNSNumberYesTimetoken (PubNub's high precision timestamp) of message to which action should be removed.

Basic Usage

PNRemoveMessageActionRequest *request = [PNRemoveMessageActionRequest requestWithChannel:@"chat"
messageTimetoken:@(1234567890)];
request.actionTimetoken = @(1234567891);

[self.client removeMessageActionWithRequest:request
completion:^(PNAcknowledgmentStatus *status) {

if (!status.isError) {
// Message reaction successfully removed.
} else {
/**
* Handle remove message reaction error. Check 'category' property to find out possible
* issue because of which request did fail.
*
* Request can be resent using: [status retry]
show all 18 lines

Response

Response objects which is returned by client when remove message reaction Message Reaction API is used:

@interface PNErrorData : PNServiceData

// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;

@end

@interface PNAcknowledgmentStatus : PNErrorStatus

// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;

// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;

show all 16 lines

Remove Message Reaction (Builder Pattern)

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)

removeMessageAction()
.channel(NSString *)
.messageTimetoken(NSNumber *)
.actionTimetoken(NSNumber *)
.performWithCompletion(nullable PNRemoveMessageActionCompletionBlock);
ParameterTypeRequiredDescription
channelNSStringYesName of channel which store message for which reaction should be removed.
messageTimetokenNSNumberYesTimetoken of message for which action should be removed.
actionTimetokenNSNumberYesAction addition timetoken.
blockPNRemoveMessageActionCompletionBlockNoRemove message reaction request completion block.

Basic Usage

self.client.removeMessageAction()
.channel("chat")
.messageTimetoken(@(1234567890))
.actionTimetoken(@(1234567891))
.performWithCompletion(^(PNCreateSpaceStatus *status) {
if (!status.isError) {
// Message reaction successfully removed.
} else {
/**
* Handle remove message reaction error. Check 'category' property to find out possible
* issue because of which request did fail.
*
* Request can be resent using: [status retry]
*/
}
show all 16 lines

Response

Response objects which is returned by client when remove message reaction Message Reaction API is used:

@interface PNErrorData : PNServiceData

// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;

@end

@interface PNAcknowledgmentStatus : PNErrorStatus

// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;

// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;

show all 16 lines

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 reactions in a channel. Returns a list of actions sorted by the action's timetoken in ascending order.

Method(s)

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

- (void)fetchMessagesActionsWithRequest:(PNFetchMessagesActionsRequest *)request 
completion:(PNFetchMessageActionsCompletionBlock)block;
ParameterTypeRequiredDescription
requestPNFetchMessageActionsRequestYesFetch message reactions request with all information which should be used to fetch existing messages actions.
blockPNFetchMessageActionsCompletionBlockYesFetch message reactions request completion block.

PNFetchMessageActionsRequest

ParameterTypeRequiredDescription
startNSNumberYesReturn values will be less than start.
endNSNumberYesReturn values will be greater than or equal to end.
limitNSUIntegerYesNumber of messages actions to return in response.
channelNSStringYesName of channel from which list of message reactions should be retrieved.

Basic Usage

PNFetchMessageActionsRequest *request = [PNFetchMessageActionsRequest requestWithChannel:@"chat"];
request.start = @(1234567891);
request.limit = 200;

[self.client fetchMessageActionsWithRequest:request
completion:^(PNFetchMessageActionsResult *result,
PNErrorStatus *status) {

if (!status.isError) {
/**
* Message reactions successfully fetched.
* Result object has following information:
* result.data.actions - list of message reaction instances
* result.data.start - fetched messages reactions time range start (oldest message
* action timetoken).
show all 26 lines

Response

Response objects which is returned by client when fetch message reactions Message Reaction API is used:

@interface PNFetchMessageActionsData : PNServiceData

// List of fetched messages actions.
@property (nonatomic, readonly, strong) NSArray<PNMessageAction *> *actions;

/**
* Fetched messages actions time range start (oldest message reaction timetoken).
*
* This timetoken can be used as 'start' value to fetch older messages reactions.
*/
@property (nonatomic, readonly, strong) NSNumber *start;

// Fetched messages actions time range end (newest action timetoken).
@property (nonatomic, readonly, strong) NSNumber *end;

show all 23 lines

Error response which is used in case of Message Reaction API call failure:

@interface PNErrorData : PNServiceData

// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;

@end

@interface PNErrorStatus : PNStatus

// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;

// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;

show all 16 lines

Get Message Reactions (Builder Pattern)

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 reactions in a channel. Returns a list of actions sorted by the action's timetoken in ascending order.

Method(s)

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

fetchMessageActions()
.channel(NSString *)
.start(NSNumber *)
.end(NSNumber *)
.limit(NSUInteger)
.performWithCompletion(PNFetchMessageActionsCompletionBlock);
ParameterTypeRequiredDescription
channelNSStringYesName of channel from which list of messages actions should be retrieved.
startNSNumberNoMessage reaction timetoken denoting the start of the range requested. Return values will be less than start.
endNSNumberNoMessage reaction timetoken denoting the end of the range requested. Return values will be greater than or equal to end.
limitNSUIntegerNoNumber of message reactions to return in response.
blockPNFetchMessageActionsCompletionBlockYesFetch message reactions request completion block.

Basic Usage

self.client.fetchMessageActions()
.channel(@"chat")
.start(@(1234567891))
.limit(200)
.performWithCompletion(^(PNFetchMessageActionsResult *result,
NErrorStatus *status) {

if (!status.isError) {
/**
* Message reaction successfully added.
* Result object has following information:
* result.data.actions - list of message reaction instances
* result.data.start - fetched messages actions time range start (oldest message
* action timetoken).
* result.data.end - fetched messages reactions time range end (newest action timetoken).
show all 25 lines

Response

Response objects which is returned by client when fetch message reactions Message Reaction API is used:

@interface PNFetchMessageActionsData : PNServiceData

// List of fetched messages actions.
@property (nonatomic, readonly, strong) NSArray<PNMessageAction *> *actions;

/**
* Fetched messages actions time range start (oldest message reaction timetoken).
*
* This timetoken can be used as 'start' value to fetch older messages reactions.
*/
@property (nonatomic, readonly, strong) NSNumber *start;

// Fetched messages actions time range end (newest reaction timetoken).
@property (nonatomic, readonly, strong) NSNumber *end;

show all 23 lines

Error response which is used in case of Message Reaction API call failure:

@interface PNErrorData : PNServiceData

// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;

@end

@interface PNErrorStatus : PNStatus

// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;

// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;

show all 16 lines
Last updated on