sendAsDm changes

This commit is contained in:
Deven Joshi
2021-10-19 16:08:25 +05:30
parent 011fb1b2d9
commit 4459253f49
2 changed files with 37 additions and 15 deletions
@@ -348,7 +348,6 @@ class MessageInputState extends State<MessageInput> {
Command? _chosenCommand; Command? _chosenCommand;
bool _actionsShrunk = false; bool _actionsShrunk = false;
bool _sendAsDm = false;
bool _openFilePickerSection = false; bool _openFilePickerSection = false;
int _filePickerIndex = 0; int _filePickerIndex = 0;
@@ -535,7 +534,7 @@ class MessageInputState extends State<MessageInput> {
height: 16, height: 16,
width: 16, width: 16,
foregroundDecoration: BoxDecoration( foregroundDecoration: BoxDecoration(
border: _sendAsDm border: messageInputController.showInChannel
? null ? null
: Border.all( : Border.all(
color: _streamChatTheme.colorTheme.textHighEmphasis color: _streamChatTheme.colorTheme.textHighEmphasis
@@ -547,19 +546,20 @@ class MessageInputState extends State<MessageInput> {
child: Center( child: Center(
child: Material( child: Material(
borderRadius: BorderRadius.circular(3), borderRadius: BorderRadius.circular(3),
color: _sendAsDm color: messageInputController.showInChannel
? _streamChatTheme.colorTheme.accentPrimary ? _streamChatTheme.colorTheme.accentPrimary
: _streamChatTheme.colorTheme.barsBg, : _streamChatTheme.colorTheme.barsBg,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
setState(() { setState(() {
_sendAsDm = !_sendAsDm; messageInputController.showInChannel =
!messageInputController.showInChannel;
}); });
}, },
child: AnimatedCrossFade( child: AnimatedCrossFade(
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
reverseDuration: const Duration(milliseconds: 300), reverseDuration: const Duration(milliseconds: 300),
crossFadeState: _sendAsDm crossFadeState: messageInputController.showInChannel
? CrossFadeState.showFirst ? CrossFadeState.showFirst
: CrossFadeState.showSecond, : CrossFadeState.showSecond,
firstChild: StreamSvgIcon.check( firstChild: StreamSvgIcon.check(
@@ -1216,7 +1216,7 @@ class MessageInputState extends State<MessageInput> {
size: Size(renderObject.size.width - 16, 400), size: Size(renderObject.size.width - 16, 400),
mentionsTileBuilder: tileBuilder, mentionsTileBuilder: tileBuilder,
onMentionUserTap: (user) { onMentionUserTap: (user) {
messageInputController.mentionedUsers.add(user); messageInputController.addMentionedUser(user);
splits[splits.length - 1] = user.name; splits[splits.length - 1] = user.name;
final rejoin = splits.join('@'); final rejoin = splits.join('@');
@@ -1794,8 +1794,8 @@ class MessageInputState extends State<MessageInput> {
text = '${'/${_chosenCommand!.name} '}$text'; text = '${'/${_chosenCommand!.name} '}$text';
} }
messageInputController.clear(); messageInputController.text = '';
messageInputController.attachments.clear(); messageInputController.clearAttachments();
widget.onQuotedMessageCleared?.call(); widget.onQuotedMessageCleared?.call();
setState(() { setState(() {
@@ -1819,7 +1819,9 @@ class MessageInputState extends State<MessageInput> {
mentionedUsers: messageInputController.mentionedUsers mentionedUsers: messageInputController.mentionedUsers
.where((u) => text.contains('@${u.name}')) .where((u) => text.contains('@${u.name}'))
.toList(), .toList(),
showInChannel: widget.parentMessage != null ? _sendAsDm : null, showInChannel: widget.parentMessage != null
? messageInputController.showInChannel
: null,
); );
} }
@@ -1839,7 +1841,7 @@ class MessageInputState extends State<MessageInput> {
await streamChannel.reloadChannel(); await streamChannel.reloadChannel();
} }
messageInputController.mentionedUsers.clear(); messageInputController.clearMentionedUsers();
try { try {
Future sendingFuture; Future sendingFuture;
@@ -44,11 +44,26 @@ class MessageInputController extends ValueNotifier<Message> {
_textEditingController.text = newText ?? ''; _textEditingController.text = newText ?? '';
} }
///
set textEditingValue(TextEditingValue newValue) { set textEditingValue(TextEditingValue newValue) {
_textEditingController.value = newValue; _textEditingController.value = newValue;
value = value.copyWith(text: _textEditingController.text); 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<Attachment> get attachments => value.attachments; List<Attachment> get attachments => value.attachments;
@@ -56,11 +71,6 @@ class MessageInputController extends ValueNotifier<Message> {
value = value.copyWith(attachments: attachments); value = value.copyWith(attachments: attachments);
} }
///
get baseOffset {
return textEditingController.selection.baseOffset;
}
/// ///
void addAttachment(Attachment attachment) { void addAttachment(Attachment attachment) {
attachments = [...attachments, attachment]; attachments = [...attachments, attachment];
@@ -86,6 +96,11 @@ class MessageInputController extends ValueNotifier<Message> {
attachments = [...attachments]..removeAt(index); attachments = [...attachments]..removeAt(index);
} }
///
void clearAttachments() {
attachments = [];
}
/// ///
List<User> get mentionedUsers => value.mentionedUsers; List<User> get mentionedUsers => value.mentionedUsers;
@@ -108,6 +123,11 @@ class MessageInputController extends ValueNotifier<Message> {
mentionedUsers = [...mentionedUsers]..removeWhere((it) => it.id == userId); mentionedUsers = [...mentionedUsers]..removeWhere((it) => it.id == userId);
} }
///
void clearMentionedUsers() {
mentionedUsers = [];
}
/// Set the [value] to empty. /// Set the [value] to empty.
/// ///
/// After calling this function, [text], [attachments] and [mentionedUsers] /// After calling this function, [text], [attachments] and [mentionedUsers]