getFeed method
Future<FeedInfo?>
getFeed({
- required PeerId ownerPeerId,
- required String path,
- PeerId? fromServer,
Get feed metadata
Implementation
Future<FeedInfo?> getFeed({
required PeerId ownerPeerId,
required String path,
PeerId? fromServer,
}) async {
final serverId = fromServer ?? await _serverSelector.selectServer(config.preferredServers);
if (serverId == null) {
_logger.warning('No S&F server available for feed retrieval');
return null;
}
try {
final context = Context();
final stream = await host.newStream(
serverId,
[FeedHandler.protocolId],
context,
).timeout(config.connectionTimeout);
final response = await FeedHandler.getFeed(
stream,
ownerPeerId: ownerPeerId,
path: path,
).timeout(config.messageTimeout);
await stream.close();
if (!response.isSuccess) {
_logger.warning('GET feed $path: ${response.status} ${response.error}');
return null;
}
final body = jsonDecode(utf8.decode(response.body!)) as Map<String, dynamic>;
return FeedInfo(
path: body['path'] as String? ?? path,
title: body['title'] as String? ?? '',
description: body['description'] as String? ?? '',
currentSequence: body['currentSequence'] as int? ?? 0,
lastEntryAt: body['lastEntryAt'] as int?,
createdAt: body['createdAt'] as int? ?? 0,
);
} on TimeoutException {
_logger.warning('GET feed timed out');
return null;
} catch (e) {
_logger.warning('Failed to GET feed: $e');
return null;
}
}