send method
To send a Message in the Conversation.
Set transient
with true
means message
will not be stored, default is false
.
Set receipt
with true
means Client.onMessageDelivered and Client.onMessageRead will be invoked when other Client receive and read the message
, default is false
.
Set will
with true
means other Client will receive the message
when Conversation.client is offline, default is false
.
priority
only be used for the Message which send in the ChatRoom, default is MessagePriority.high.
pushData
is used for customizing offline-notification-content, default is null
.
Returns the sent Message which has Message.id and Message.sentTimestamp.
Implementation
Future<Message> send({
required Message message,
bool? transient,
bool? receipt,
bool? will,
MessagePriority? priority,
Map? pushData,
}) async {
var options = {};
if (receipt ?? false) {
options['receipt'] = true;
}
if (will ?? false) {
options['will'] = true;
message._will = true;
}
if (_type == _ConversationType.transient && priority != null) {
options['priority'] = priority.index + 1;
}
if (pushData != null) {
options['pushData'] = pushData;
}
if (transient ?? false) {
message._transient = true;
}
message._currentClientID = client.id;
var args = {
'clientId': client.id,
'conversationId': id,
'message': message._toMap(),
};
if (options.isNotEmpty) {
args['options'] = options;
}
if (message is FileMessage) {
var fileMap = {};
fileMap['path'] = message._filePath;
fileMap['data'] = message._fileData;
fileMap['url'] = message._fileUrl;
fileMap['format'] = message._fileFormat;
fileMap['name'] = message._fileName;
args['file'] = fileMap;
}
message._status = MessageStatus.sending;
try {
final Map rawData = await call(
method: 'sendMessage',
arguments: args,
);
message._loadMap(rawData);
message._status = MessageStatus.sent;
} catch (e) {
message._status = MessageStatus.failed;
rethrow;
}
_updateLastMessage(
message: message,
);
return message;
}