history function
Implementation
Future<List<Message>?> history({
required String threadhash,
String? accountAddress,
int limit = FetchLimit.DEFAULT,
String? pgpPrivateKey,
bool toDecrypt = false,
}) async {
accountAddress ??= getCachedWallet()?.address;
if (accountAddress == null) {
throw Exception('Account address is required.');
}
if (!isValidETHAddress(accountAddress)) {
throw Exception('Invalid address $accountAddress');
}
pgpPrivateKey ??= getCachedWallet()?.pgpPrivateKey;
if (pgpPrivateKey == null) {
throw Exception('Private Key is required.');
}
try {
if (limit < FetchLimit.MIN || limit > FetchLimit.MAX) {
if (limit < FetchLimit.MIN) {
throw Exception('Limit must be more than equal to ${FetchLimit.MIN}');
} else {
throw Exception('Limit must be less than equal to ${FetchLimit.MAX}');
}
}
final List<Message>? messages =
await getMessagesService(threadhash: threadhash, limit: limit);
if (messages == null) {
return null;
}
// final updatedMessages = addDeprecatedInfoToMessages(messages);
final connectedUser =
await getUser(address: pCAIP10ToWallet(accountAddress));
if (toDecrypt) {
return await decryptConversation(
messages: messages,
connectedUser: connectedUser,
pgpPrivateKey: pgpPrivateKey,
);
}
return messages;
} catch (err) {
log('[Push SDK] - API history - : $err');
throw Exception('[Push SDK] - API history - : $err');
}
}