saveDraft function
Implementation
Future<void> saveDraft(
String text,
String? htmlText,
String roomId,
WidgetRef ref,
) async {
// get the convo object to initiate draft
final chat = await ref.read(chatProvider(roomId).future);
final messageId = ref.read(chatInputProvider).selectedMessage?.id;
final mentions = ref.read(chatInputProvider).mentions;
final userMentions = [];
if (mentions.isNotEmpty) {
mentions.forEach((key, value) {
userMentions.add(value);
htmlText = htmlText?.replaceAll(
'@$key',
'[@$key](https://matrix.to/#/$value)',
);
});
}
if (chat != null) {
if (messageId != null) {
final selectedMessageState =
ref.read(chatInputProvider).selectedMessageState;
if (selectedMessageState == SelectedMessageState.edit) {
await chat.saveMsgDraft(text, htmlText, 'edit', messageId);
} else if (selectedMessageState == SelectedMessageState.replyTo) {
await chat.saveMsgDraft(text, htmlText, 'reply', messageId);
}
} else {
await chat.saveMsgDraft(text, htmlText, 'new', null);
}
}
}