listMailboxes method

Future<List<MailboxInfo>> listMailboxes()

List all mailboxes owned by this client

Implementation

Future<List<MailboxInfo>> listMailboxes() async {
  _logger.fine('Listing mailboxes for ${host.id.toBase58()}');

  final request = ListMailboxesRequest(ownerId: host.id);

  final response = await _sendRequest(request);
  if (!response.success) {
    throw MailboxManagementError(
      response.errorMessage ?? 'Failed to list mailboxes',
    );
  }

  // go-ricochet answers in `mailboxes`; reading `data` alone gave an
  // empty list whatever the owner had.
  final entries = response.mailboxes;
  if (entries == null) {
    return response.data == null ? [] : AdminFrame.decodeMailboxInfoList(response.data as List<dynamic>);
  }
  return [for (final e in entries.cast<Map<String, dynamic>>()) MailboxInfo.fromListEntry(e, ownerId: host.id)];
}