getSpaceInboxList function

Future<List<SpaceFeeds>> getSpaceInboxList({
  1. required List<SpaceFeeds> feedsList,
  2. required String user,
  3. required String? pgpPrivateKey,
  4. required bool toDecrypt,
})

Implementation

Future<List<SpaceFeeds>> getSpaceInboxList({
  required List<SpaceFeeds> feedsList,
  required String user,
  required String? pgpPrivateKey,
  required bool toDecrypt,
}) async {
  final List<SpaceFeeds> feedsOutputlist = [];
  for (var feed in feedsList) {
    Message? message;
    if (feed.threadhash != null) {
      message = await getCID(cid: feed.threadhash!);
    }
    // This is for groups that are created without any message
    message ??= Message(
      encType: 'PlainText',
      encryptedSecret: '',
      fromCAIP10: '',
      fromDID: '',
      link: '',
      messageContent: '',
      messageType: '',
      sigType: '',
      signature: '',
      toCAIP10: '',
      toDID: '',
    );

    feed.msg = message;

    feedsOutputlist.add(feed);
  }

  if (toDecrypt) {
    final connectedUser = await getUser(address: pCAIP10ToWallet(user));
    if (connectedUser == null) {
      throw Exception('Cannot find user');
    }

    if (pgpPrivateKey == null) {
      throw Exception('Cannot find pgpPrivateKey');
    }
    return decryptSpaceFeeds(
      feeds: feedsOutputlist,
      connectedUser: connectedUser,
      pgpPrivateKey: pgpPrivateKey,
    );
  }

  return feedsOutputlist;
}