Send Reaction

Last Edit: Feb 02 2020

Stream Chat has built-in support for user Reactions. Common examples are likes, comments, loves, etc. Reactions can be customized so that you are able to use any type of reaction your application requires.

Similar to other objects in Stream Chat, reactions allow you to add custom data to the reaction of your choice. This is helpful if you want to customize the reaction logic.

Custom data for reactions is limited to 1KB.

const reaction = await channel.sendReaction(messageID, {
    type: 'love',
    myCustomField: 123,
});
                    

Reaction reaction = new Reaction();
reaction.setMessageId("message-id-here");
reaction.setType("like");

channel.sendReaction(reaction, new MessageCallback() {
    @Override
    public void onSuccess(MessageResponse response) {
        
    }

    @Override
    public void onError(String errMsg, int errCode) {

    }
});
                    

message.addReaction(.like).subscribe().disposed(by: disposeBag)
                    

val reaction = new Reaction()
reaction.setMessageId("message-id-here");
reaction.setType("like");

channel.sendReaction(reaction, object : MessageCallback {
    override fun onSuccess(response: MessageResponse) {}

    override fun onError(errMsg: String, errCode: Int) {}
})
                    

$response = $channel->sendReaction('message-id',['type'=>'love','myCustomField'=>123],'jenny');
                    

await channel.sendReaction("messageID", "like", extraData: {"customField": 1});
                    

Removing a Reaction


await channel.deleteReaction(messageID, 'love');
                    

channel.deleteReaction(messageID, "like", new MessageCallback() {
    @Override
    public void onSuccess(MessageResponse response) {

    }

    @Override
    public void onError(String errMsg, int errCode) {

    }
});
                    

message.deleteReaction(.like).subscribe().disposed(by: disposeBag)
                    

channel.deleteReaction(messageID, "like", object : MessageCallback {
    override fun onSuccess(response: MessageResponse) {}

    override fun onError(errMsg: String, errCode: Int) {}
})
                    

$response = $channel->deleteReaction('message-id','love','jenny');
                    

await channel.deleteReaction("messageID", "like");
                    

Paginating Reactions

Messages returned by the APIs automatically include the 10 most recent reactions. You can also retrieve more reactions and paginate using the following logic:


// get the first 10 reactions
const response = await channel.getReactions(messageID, { limit: 10 });

// get 3 reactions past the first 10
const response = await channel.getReactions(messageID, { limit: 3, offset: 10 });
                    

// get the first 10 reactions
channel.getReactions(messageID, new GetReactionsCallback(){
        @Override
        public void onSuccess(GetReactionsResponse response) {
        }

        @Override
        public void onError(String errMsg, int errCode) {
        }
    }
);

// get 3 reactions past the first 10
channel.getReactions(messageID, new PaginationOptions.Builder().offset(10).limit(3).build(),
    new GetReactionsCallback(){
        @Override
        public void onSuccess(GetReactionsResponse response) {
        }

        @Override
        public void onError(String errMsg, int errCode) {
        }
    }
);
                    

// TODO
                    

// get the first 10 reactions
channel.getReactions(messageID, object : GetReactionsCallback {
    override fun onSuccess(response: GetReactionsResponse) {

    }

    override fun onError(errMsg: String, errCode: Int) {

    }
})

// get 3 reactions past the first 10
channel.getReactions(messageID, PaginationOptions.Builder().offset(10).limit(3).build(),
  object : GetReactionsCallback {
      fun onSuccess(response: GetReactionsResponse) {

      }

      fun onError(errMsg: String, errCode: Int) {

      }
})
                    

// get the first 10 reactions
$response = $channel->getReactions('message-id',['limit' => 10]);

// get 3 reactions past the first 10
$response = $channel->getReactions('message-id',['limit' => 3, 'offset' => 10]);
                    

// get the first 10 reactions
await channel.getReactions("messageID", PaginationParams(limit: 10));

// get 3 reactions past the first 10
await channel.getReactions("messageID", PaginationParams(limit: 3, offset:10));