getAllWaitingMessages method
Retrieve all waiting messages from the database Decrypts the stored payloads and reconstructs WaitingMessage objects
Implementation
Future<List<WaitingMessage>> getAllWaitingMessages({String? password}) async {
final key = password ?? _defaultPassword;
final results = await _database.query(tableWaitingMessages);
return results.map((map) {
final decryptedFinalPayload = PayloadCipher.getDecodedPayload(
map['final_payload'] as String,
Nonce.fromString("${map['id']}_final"),
ChaCha20(ChaCha20Key.fromString(key)),
);
// Create and configure the waiting message
final message = WaitingMessage(
map['channel']
as String, // Note: PubSub instance needs to be properly handled
map['event'] as String,
decryptedFinalPayload,
);
// Restore the stored properties
message.id = map['id'] as int;
message.timestamp = map['timestamp'] as int;
message.setFinalPayload(decryptedFinalPayload['payload'] as String);
return message;
}).toList();
}