addReaction static method
- int messageId,
- String reaction,
- {required dynamic onSuccess( )?,
- required dynamic onError(
- CometChatException excep
Add a reaction to a message.
The messageId
parameter specifies the ID of the message to add the reaction to.
The reaction
parameter specifies the reaction to add.
The onSuccess
function is called with the added BaseMessage
when the reaction is added successfully.
The onError
function is called with a CometChatException object when there is an error while adding the reaction.
Returns a Future that resolves to the added BaseMessage
or null if there was an error.
Implementation
static Future<BaseMessage?> addReaction(int messageId, String reaction, {required Function(BaseMessage)? onSuccess, required Function(CometChatException excep)? onError}) async {
try {
final result = await channel.invokeMethod('addReaction', {'messageId': messageId, 'reaction': reaction});
final BaseMessage res = BaseMessage.fromMap(result);
if(onSuccess != null) onSuccess(res);
return res;
} on PlatformException catch (platformException) {
if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
} catch (e) {
debugPrint("Error: $e");
if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
}
return null;
}