@@ -942,10 +942,15 @@ class MessageInputState extends State<MessageInput>
|
|||||||
if (_lastSearchedContainsUrlText == value) return;
|
if (_lastSearchedContainsUrlText == value) return;
|
||||||
_lastSearchedContainsUrlText = value;
|
_lastSearchedContainsUrlText = value;
|
||||||
|
|
||||||
final regex =
|
final matchedUrls =
|
||||||
RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+');
|
RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+')
|
||||||
final matchedUrls = regex.allMatches(value);
|
.allMatches(value);
|
||||||
if (matchedUrls.isEmpty) return;
|
|
||||||
|
// Reset the og attachment if the text doesn't contain any url
|
||||||
|
if (matchedUrls.isEmpty) {
|
||||||
|
setState(() => _ogAttachment = null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final firstMatchedUrl = matchedUrls.first.group(0)!;
|
final firstMatchedUrl = matchedUrls.first.group(0)!;
|
||||||
|
|
||||||
@@ -955,19 +960,20 @@ class MessageInputState extends State<MessageInput>
|
|||||||
final client = StreamChat.of(context).client;
|
final client = StreamChat.of(context).client;
|
||||||
|
|
||||||
_enrichUrlOperation = CancelableOperation.fromFuture(
|
_enrichUrlOperation = CancelableOperation.fromFuture(
|
||||||
client.enrichUrl(firstMatchedUrl).then((ogAttachment) {
|
client.enrichUrl(firstMatchedUrl),
|
||||||
|
).then(
|
||||||
|
(ogAttachment) {
|
||||||
final attachment = Attachment.fromOGAttachment(ogAttachment);
|
final attachment = Attachment.fromOGAttachment(ogAttachment);
|
||||||
setState(() => _ogAttachment = attachment);
|
setState(() => _ogAttachment = attachment);
|
||||||
}).onError((error, stackTrace) {
|
},
|
||||||
|
onError: (error, stackTrace) {
|
||||||
// Reset the ogAttachment if there was an error
|
// Reset the ogAttachment if there was an error
|
||||||
setState(() => _ogAttachment = null);
|
setState(() => _ogAttachment = null);
|
||||||
if (error != null) {
|
widget.onError?.call(error, stackTrace);
|
||||||
widget.onError?.call(error, stackTrace);
|
},
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
const Duration(seconds: 1),
|
const Duration(milliseconds: 650),
|
||||||
);
|
);
|
||||||
|
|
||||||
void _checkEmoji(String value, BuildContext context) {
|
void _checkEmoji(String value, BuildContext context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user