Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gtalha07 committed Aug 20, 2024
1 parent 04f0563 commit f863e7b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/lib/features/chat/widgets/custom_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ class __ChatInputState extends ConsumerState<_ChatInput> {
Future<void> loadDraft() async {
final draft =
await ref.read(chatComposerDraftProvider(widget.roomId).future);
final inputNotifier = ref.read(chatInputProvider.notifier);
inputNotifier.unsetSelectedMessage();
if (draft != null) {
if (draft.eventId() != null) {
final eventId = draft.eventId()!;
final draftType = draft.draftType();
final inputNotifier = ref.read(chatInputProvider.notifier);

final m = ref
.read(chatMessagesProvider(widget.roomId))
.firstWhere((x) => x.id == eventId);
Expand Down Expand Up @@ -601,6 +603,8 @@ class __ChatInputState extends ConsumerState<_ChatInput> {
const Spacer(),
GestureDetector(
onTap: () async {
final convo = await ref.read(chatProvider(widget.roomId).future);
await convo?.saveMsgDraft(textController.text, null, 'new', null);
inputNotifier.unsetSelectedMessage();
// frame delay to keep focus connected with keyboard.
WidgetsBinding.instance.addPostFrameCallback((_) {
Expand Down Expand Up @@ -696,6 +700,9 @@ class __ChatInputState extends ConsumerState<_ChatInput> {
ref.read(chatInputProvider.notifier).messageSent();

textController.clear();
// also clear composed state
final convo = await ref.read(chatProvider(widget.roomId).future);
await convo?.saveMsgDraft(textController.text, null, 'new', null);
} catch (e, s) {
_log.severe('Sending chat message failed', e, s);
EasyLoading.showError(
Expand All @@ -704,6 +711,7 @@ class __ChatInputState extends ConsumerState<_ChatInput> {
);
ref.read(chatInputProvider.notifier).sendingFailed();
}

if (!chatFocus.hasFocus) {
chatFocus.requestFocus();
}
Expand Down

0 comments on commit f863e7b

Please sign in to comment.