appendFeedEntry method
Append an entry to a feed
ownerPeerId Optional: feed owner's peer ID (for collaborative feeds).
If omitted, defaults to this client's own peer ID.
Implementation
Future<FeedAppendResult?> appendFeedEntry({
required String path,
required Uint8List content,
String? entryType,
PeerId? ownerPeerId,
PeerId? toServer,
}) async {
final serverId = toServer ?? await _serverSelector.selectServer(config.preferredServers);
if (serverId == null) {
_logger.warning('No S&F server available for feed append');
return null;
}
try {
final context = Context();
final stream = await host.newStream(
serverId,
[FeedHandler.protocolId],
context,
).timeout(config.connectionTimeout);
final effectiveOwner = ownerPeerId ?? host.id;
_logger.info('APPEND feed $path owner=$effectiveOwner caller=${host.id} (ownerPeerId param ${ownerPeerId != null ? "provided" : "NULL/defaulting to self"})');
final response = await FeedHandler.appendFeedEntry(
stream,
ownerPeerId: effectiveOwner,
path: path,
content: content,
entryType: entryType,
).timeout(config.messageTimeout);
await stream.close();
if (!response.isSuccess) {
_logger.warning('APPEND feed $path owner=$effectiveOwner: ${response.status} ${response.error}');
return null;
}
return FeedAppendResult(
status: response.status,
sequence: response.sequence ?? 0,
etag: response.etag ?? '',
);
} on TimeoutException {
_logger.warning('APPEND feed timed out');
return null;
} catch (e) {
_logger.warning('Failed to APPEND feed: $e');
return null;
}
}