deleteMessage method
Deletes messageId as a tombstone (03 6.5); a second delete changes nothing (idempotent
204). Throws 404 or 403 forbidden for another author's message.
Implementation
void deleteMessage(String principalId, String messageId) {
final m = visibleMessage(principalId, messageId);
if (m['deleted_at'] != null) return;
if ((m['author']! as JsonMap)['id'] != principalId) {
throw const FakeProblem(403, 'forbidden');
}
final at = stamp();
m
..['content_md'] = ''
..['attachments'] = <Object?>[]
..['mention_ids'] = <Object?>[]
..['reactions'] = <Object?>[]
..['components'] = <Object?>[]
..remove('my_reactions')
..['deleted_at'] = at
..['version'] = (m['version']! as int) + 1;
append(
'message.deleted',
resource: {'kind': 'message', 'id': messageId, 'version': m['version']},
scope: _scopeOf(m['thread_id']! as String),
payload: {
'message_id': messageId,
'thread_id': m['thread_id'],
'thread_seq': m['thread_seq'],
'deleted_at': at,
'deleted_by': principalId,
},
actor: principalId,
);
}