From 4459253f49a2c514b1bc9143834ace881d468f8d Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Tue, 19 Oct 2021 16:08:25 +0530 Subject: [PATCH] sendAsDm changes --- .../lib/src/message_input.dart | 22 +++++++------- .../lib/src/message_input_controller.dart | 30 +++++++++++++++---- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/packages/stream_chat_flutter/lib/src/message_input.dart b/packages/stream_chat_flutter/lib/src/message_input.dart index 3f8e22d1..982d5cc5 100644 --- a/packages/stream_chat_flutter/lib/src/message_input.dart +++ b/packages/stream_chat_flutter/lib/src/message_input.dart @@ -348,7 +348,6 @@ class MessageInputState extends State { Command? _chosenCommand; bool _actionsShrunk = false; - bool _sendAsDm = false; bool _openFilePickerSection = false; int _filePickerIndex = 0; @@ -535,7 +534,7 @@ class MessageInputState extends State { height: 16, width: 16, foregroundDecoration: BoxDecoration( - border: _sendAsDm + border: messageInputController.showInChannel ? null : Border.all( color: _streamChatTheme.colorTheme.textHighEmphasis @@ -547,19 +546,20 @@ class MessageInputState extends State { child: Center( child: Material( borderRadius: BorderRadius.circular(3), - color: _sendAsDm + color: messageInputController.showInChannel ? _streamChatTheme.colorTheme.accentPrimary : _streamChatTheme.colorTheme.barsBg, child: InkWell( onTap: () { setState(() { - _sendAsDm = !_sendAsDm; + messageInputController.showInChannel = + !messageInputController.showInChannel; }); }, child: AnimatedCrossFade( duration: const Duration(milliseconds: 300), reverseDuration: const Duration(milliseconds: 300), - crossFadeState: _sendAsDm + crossFadeState: messageInputController.showInChannel ? CrossFadeState.showFirst : CrossFadeState.showSecond, firstChild: StreamSvgIcon.check( @@ -1216,7 +1216,7 @@ class MessageInputState extends State { size: Size(renderObject.size.width - 16, 400), mentionsTileBuilder: tileBuilder, onMentionUserTap: (user) { - messageInputController.mentionedUsers.add(user); + messageInputController.addMentionedUser(user); splits[splits.length - 1] = user.name; final rejoin = splits.join('@'); @@ -1794,8 +1794,8 @@ class MessageInputState extends State { text = '${'/${_chosenCommand!.name} '}$text'; } - messageInputController.clear(); - messageInputController.attachments.clear(); + messageInputController.text = ''; + messageInputController.clearAttachments(); widget.onQuotedMessageCleared?.call(); setState(() { @@ -1819,7 +1819,9 @@ class MessageInputState extends State { mentionedUsers: messageInputController.mentionedUsers .where((u) => text.contains('@${u.name}')) .toList(), - showInChannel: widget.parentMessage != null ? _sendAsDm : null, + showInChannel: widget.parentMessage != null + ? messageInputController.showInChannel + : null, ); } @@ -1839,7 +1841,7 @@ class MessageInputState extends State { await streamChannel.reloadChannel(); } - messageInputController.mentionedUsers.clear(); + messageInputController.clearMentionedUsers(); try { Future sendingFuture; diff --git a/packages/stream_chat_flutter_core/lib/src/message_input_controller.dart b/packages/stream_chat_flutter_core/lib/src/message_input_controller.dart index 365dc017..96026530 100644 --- a/packages/stream_chat_flutter_core/lib/src/message_input_controller.dart +++ b/packages/stream_chat_flutter_core/lib/src/message_input_controller.dart @@ -44,11 +44,26 @@ class MessageInputController extends ValueNotifier { _textEditingController.text = newText ?? ''; } + /// set textEditingValue(TextEditingValue newValue) { _textEditingController.value = newValue; value = value.copyWith(text: _textEditingController.text); } + /// + get baseOffset { + return textEditingController.selection.baseOffset; + } + + set showInChannel(bool newValue) { + value = value.copyWith(showInChannel: newValue); + } + + /// + bool get showInChannel { + return value.showInChannel ?? false; + } + /// List get attachments => value.attachments; @@ -56,11 +71,6 @@ class MessageInputController extends ValueNotifier { value = value.copyWith(attachments: attachments); } - /// - get baseOffset { - return textEditingController.selection.baseOffset; - } - /// void addAttachment(Attachment attachment) { attachments = [...attachments, attachment]; @@ -86,6 +96,11 @@ class MessageInputController extends ValueNotifier { attachments = [...attachments]..removeAt(index); } + /// + void clearAttachments() { + attachments = []; + } + /// List get mentionedUsers => value.mentionedUsers; @@ -108,6 +123,11 @@ class MessageInputController extends ValueNotifier { mentionedUsers = [...mentionedUsers]..removeWhere((it) => it.id == userId); } + /// + void clearMentionedUsers() { + mentionedUsers = []; + } + /// Set the [value] to empty. /// /// After calling this function, [text], [attachments] and [mentionedUsers]