openReaction method
Implementation
Future<void> openReaction(MessageReactionEventModel event) async {
final MessageReactionEventModel(:deviceKey, :body, :timestamp) = event;
final MessageReactionEventBodyModel(:ciphertext, :hash) = body;
final device = await _db.devices.id(deviceKey).get();
if (device == null) {
throw StateError('Missing reaction device');
}
final messageEvent = await _db.events.id<MessageEventModel>(hash).get();
if (messageEvent == null) {
throw StateError('Missing message event for reaction');
}
if (!messageEvent.body.peers.contains(device.peerKey)) {
_logger.log('Rejected reaction from non-participant ${device.peerKey}');
return;
}
final secretKey = await openSecretKey(messageEvent);
if (secretKey == null) {
throw StateError('Missing message secret key for reaction');
}
final symbol = await _encryption.decryptSecret(secretKey, ciphertext);
await _db.messageReactions.insert(
MessageReactionModel(
hash: hash,
peerKey: device.peerKey,
symbol: symbol,
timestamp: timestamp,
),
);
}