fix(ui): fix various message_list_view issues.

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2023-05-31 16:46:57 +05:30
committed by xsahil03x
parent c013fee5cf
commit a14731feea
4 changed files with 82 additions and 66 deletions
@@ -1372,10 +1372,10 @@ class StreamMessageInputState extends State<StreamMessageInput>
}
final streamChannel = StreamChannel.of(context);
final channel = streamChannel.channel;
var message = _effectiveController.value;
if (!streamChannel.channel.ownCapabilities
.contains(PermissionType.sendLinks) &&
if (!channel.ownCapabilities.contains(PermissionType.sendLinks) &&
_urlRegex.allMatches(message.text ?? '').any((element) =>
element.group(0)?.split('.').last.isValidTLD() == true)) {
showInfoBottomSheet(
@@ -1401,8 +1401,8 @@ class StreamMessageInputState extends State<StreamMessageInput>
final skipEnrichUrl = _effectiveController.ogAttachment == null;
var shouldKeepFocus = widget.shouldKeepFocusAfterMessage;
shouldKeepFocus ??= !_commandEnabled;
widget.onQuotedMessageCleared?.call();
_effectiveController.reset();
@@ -1411,12 +1411,35 @@ class StreamMessageInputState extends State<StreamMessageInput>
message = await widget.preMessageSending!(message);
}
final channel = streamChannel.channel;
message = message.replaceMentionsWithId();
// If the channel is not up to date, we should reload it before sending
// the message.
if (!channel.state!.isUpToDate) {
await streamChannel.reloadChannel();
// We need to wait for the frame to be rendered with the updated channel
// state before sending the message.
await WidgetsBinding.instance.endOfFrame;
}
message = message.replaceMentionsWithId();
await sendOrUpdateMessage(
message: message,
skipEnrichUrl: skipEnrichUrl,
);
if (shouldKeepFocus) {
FocusScope.of(context).requestFocus(_effectiveFocusNode);
} else {
FocusScope.of(context).unfocus();
}
}
Future<void> sendOrUpdateMessage({
required Message message,
bool skipEnrichUrl = false,
}) async {
final channel = StreamChannel.of(context).channel;
try {
Future sendingFuture;
@@ -1432,12 +1455,6 @@ class StreamMessageInputState extends State<StreamMessageInput>
);
}
if (shouldKeepFocus) {
FocusScope.of(context).requestFocus(_effectiveFocusNode);
} else {
FocusScope.of(context).unfocus();
}
final resp = await sendingFuture;
if (resp.message?.type == 'error') {
_effectiveController.message = message;