sendMessage method
Future<SendResult>
sendMessage({
- required PeerId recipient,
- required Uint8List payload,
- String? folderPath,
- MessagePriority priority = MessagePriority.normal,
- Duration? expiry,
- bool persistent = false,
- bool tryDirectFirst = true,
- String? messageId,
- SFMessageFlags flags = SFMessageFlags.none,
Send message with automatic retry and failover
Implementation
Future<SendResult> sendMessage({
required PeerId recipient,
required Uint8List payload,
String? folderPath, // Target folder
MessagePriority priority = MessagePriority.normal,
Duration? expiry,
bool persistent = false, // Keep after reading
bool tryDirectFirst = true,
String? messageId,
SFMessageFlags flags = SFMessageFlags.none,
}) async {
_sendAttempts++;
// Try direct delivery first if requested
if (tryDirectFirst) {
final directResult = await sendDirect(
recipient,
payload,
priority,
expiry,
folderPath: folderPath,
persistent: persistent,
);
if (directResult.success) {
_successfulSends++;
_directDeliveries++;
return directResult;
}
}
// Fallback to S&F server storage
final sfResult = await _sendViaServerWithRetry(
recipient,
payload,
priority,
expiry,
folderPath: folderPath,
persistent: persistent,
messageId: messageId,
flags: flags,
);
if (sfResult.success) {
_successfulSends++;
_storedMessages++;
} else {
_failedSends++;
}
return sfResult;
}