setCollectionVisibility method
Future<CollectionFrameResponse?>
setCollectionVisibility({
- required String path,
- required CollectionVisibility visibility,
- PeerId? toServer,
Set who may read one of your own collections.
Returns the server's response, whose CollectionFrameResponse.visibility is the collection's visibility afterwards (404 if there is no such collection), or null if the request could not be made.
Implementation
Future<CollectionFrameResponse?> setCollectionVisibility({
required String path,
required CollectionVisibility visibility,
PeerId? toServer,
}) async {
final serverId = toServer ?? await _serverSelector.selectServer(config.preferredServers);
if (serverId == null) {
_logger.warning('No S&F server available for collection access');
return null;
}
try {
final context = Context();
final stream = await host.newStream(
serverId,
[CollectionHandler.protocolId],
context,
).timeout(config.connectionTimeout);
final response = await CollectionHandler.setCollectionVisibility(
stream,
ownerPeerId: host.id,
path: path,
visibility: visibility,
).timeout(config.messageTimeout);
await stream.close();
_logger.info('ACCESS set ${host.id.toBase58().substring(0, 12)}.../coll/$path ${visibility.name}: ${response.status}');
return response;
} on TimeoutException {
_logger.warning('Collection ACCESS timed out');
return null;
} catch (e) {
_logger.warning('Failed to set collection visibility: $e');
return null;
}
}