putDraft method
Stores the draft of principalId in threadId from a DraftPut body; returns the
DraftPutResult (overwrote_newer when base_version was older, 04 14).
Implementation
JsonMap putDraft(
String principalId,
String threadId,
JsonMap body, {
String? deviceId,
}) {
final thread = visibleThread(principalId, threadId);
final key = '$principalId|$threadId';
final previous = drafts[key];
final base = body['base_version'] as int?;
final previousVersion = (previous?['version'] as int?) ?? 0;
final draft = <String, Object?>{
'id': previous?['id'] ?? nextId(),
'thread_id': threadId,
'channel_id': thread['channel_id'],
'content_md': body['content_md'],
'reply_to_message_id': ?body['reply_to_message_id'],
'file_ids': body['file_ids'] ?? <Object?>[],
'version': previousVersion + 1,
'updated_by_device_id': ?deviceId,
'updated_at': stamp(),
};
drafts[key] = draft;
append(
'draft.updated',
resource: {
'kind': 'draft',
'id': draft['id'],
'version': draft['version'],
},
scope: _scopeOf(threadId),
payload: {'draft': draft},
actor: principalId,
audience: principalId,
);
return {
'draft': draft,
'overwrote_newer':
base != null && previous != null && base < previousVersion,
};
}