add send-links capability with translation

This commit is contained in:
Salvatore Giordano
2022-01-17 12:13:03 +01:00
parent cd50ee50d2
commit b2e20b8a08
10 changed files with 88 additions and 4 deletions
@@ -144,6 +144,12 @@ abstract class Translations {
/// The label for "OK"
String get okLabel;
/// The label for a link disabled error
String get linkDisabledError;
/// The additional info on a link disabled error
String get linkDisabledDetails;
/// The label for "add more files"
String get addMoreFilesLabel;
@@ -692,4 +698,11 @@ class DefaultTranslations implements Translations {
@override
String attachmentLimitExceedError(int limit) => """
Attachment limit exceeded: it's not possible to add more than $limit attachments""";
@override
String get linkDisabledDetails =>
'Sending links is not allowed in this conversation.';
@override
String get linkDisabledError => 'Links are disabled';
}
@@ -928,7 +928,9 @@ class MessageInputState extends State<MessageInput>
_actionsShrunk = value.isNotEmpty && actionsLength > 1;
});
_checkContainsUrl(value, context);
if (channel.ownCapabilities.contains(PermissionType.sendLinks)) {
_checkContainsUrl(value, context);
}
_checkCommands(value, context);
_checkMentions(value, context);
_checkEmoji(value, context);
@@ -1646,9 +1648,25 @@ class MessageInputState extends State<MessageInput>
/// Sends the current message
Future<void> sendMessage() async {
final skipEnrichUrl = _effectiveController.ogAttachment == null;
final streamChannel = StreamChannel.of(context);
var message = _effectiveController.value;
if (!streamChannel.channel.ownCapabilities
.contains(PermissionType.sendLinks) &&
_urlRegex.hasMatch(message.text ?? '')) {
showInfoDialog(
context,
icon: StreamSvgIcon.error(
color: StreamChatTheme.of(context).colorTheme.accentError,
size: 24,
),
title: 'Links are disabled',
details: 'Sending links is not allowed in this conversation.',
okText: context.translations.okLabel,
);
return;
}
final skipEnrichUrl = _effectiveController.ogAttachment == null;
var shouldKeepFocus = widget.shouldKeepFocusAfterMessage;
@@ -1660,7 +1678,6 @@ class MessageInputState extends State<MessageInput>
message = await widget.preMessageSending!(message);
}
final streamChannel = StreamChannel.of(context);
final channel = streamChannel.channel;
if (!channel.state!.isUpToDate) {
await streamChannel.reloadChannel();
@@ -396,6 +396,13 @@ class NnStreamChatLocalizations extends GlobalStreamChatLocalizations {
@override
String get slowModeOnLabel => 'Slow mode ON';
@override
String get linkDisabledDetails =>
'Sending links is not allowed in this conversation.';
@override
String get linkDisabledError => 'Links are disabled';
}
void main() async {
@@ -372,4 +372,11 @@ class StreamChatLocalizationsEn extends GlobalStreamChatLocalizations {
@override
String get slowModeOnLabel => 'Slow mode ON';
@override
String get linkDisabledDetails =>
'Sending links is not allowed in this conversation.';
@override
String get linkDisabledError => 'Links are disabled';
}
@@ -378,4 +378,11 @@ No es posible añadir más de $limit archivos adjuntos
@override
String get slowModeOnLabel => 'Modo lento activado';
@override
String get linkDisabledDetails =>
'No se permite enviar enlaces en esta conversación.';
@override
String get linkDisabledError => 'Los enlaces están deshabilitados';
}
@@ -377,4 +377,11 @@ Limite de pièces jointes dépassée : il n'est pas possible d'ajouter plus de $
@override
String get slowModeOnLabel => 'Mode lent activé';
@override
String get linkDisabledDetails =>
'L\'envoi de liens n\'est pas autorisé dans cette conversation.';
@override
String get linkDisabledError => 'Les liens sont désactivés';
}
@@ -371,4 +371,11 @@ class StreamChatLocalizationsHi extends GlobalStreamChatLocalizations {
@override
String get slowModeOnLabel => 'स्लो मोड चालू';
@override
String get linkDisabledDetails =>
'इस बातचीत में लिंक भेजने की अनुमति नहीं है.';
@override
String get linkDisabledError => 'लिंक भेजना प्रतिबंधित';
}
@@ -374,4 +374,11 @@ Attenzione: il limite massimo di $limit file è stato superato.
@override
String get slowModeOnLabel => 'Slowmode attiva';
@override
String get linkDisabledDetails =>
'Non è permesso condividere link in questa convesazione.';
@override
String get linkDisabledError => 'I links sono disattivati';
}
@@ -357,4 +357,10 @@ class StreamChatLocalizationsJa extends GlobalStreamChatLocalizations {
String attachmentLimitExceedError(int limit) => '''
添付ファイルの制限を超えました:$limit個のファイル以上を添付することはできません
''';
@override
String get linkDisabledDetails => 'この会話では、リンクの送信は許可されていません。';
@override
String get linkDisabledError => 'リンクが無効になっています';
}
@@ -357,4 +357,10 @@ class StreamChatLocalizationsKo extends GlobalStreamChatLocalizations {
@override
String attachmentLimitExceedError(int limit) =>
'첨부 파일 제한 초과: $limit 이상의 첨부 파일을 추가할 수 없습니다';
@override
String get linkDisabledDetails => '이 대화에서는 링크를 보낼 수 없습니다.';
@override
String get linkDisabledError => '링크가 비활성화되었습니다.';
}