Skip to content

Commit

Permalink
add send-links capability with translation
Browse files Browse the repository at this point in the history
  • Loading branch information
imtoori committed Jan 17, 2022
1 parent cd50ee5 commit b2e20b8
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,11 @@ class StreamChatLocalizationsHi extends GlobalStreamChatLocalizations {

@override
String get slowModeOnLabel => 'स्लो मोड चालू';

@override
String get linkDisabledDetails =>
'इस बातचीत में लिंक भेजने की अनुमति नहीं है.';

@override
String get linkDisabledError => 'लिंक भेजना प्रतिबंधित';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,10 @@ class StreamChatLocalizationsJa extends GlobalStreamChatLocalizations {
String attachmentLimitExceedError(int limit) => '''
添付ファイルの制限を超えました:$limit個のファイル以上を添付することはできません
''';

@override
String get linkDisabledDetails => 'この会話では、リンクの送信は許可されていません。';

@override
String get linkDisabledError => 'リンクが無効になっています';
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,10 @@ class StreamChatLocalizationsKo extends GlobalStreamChatLocalizations {
@override
String attachmentLimitExceedError(int limit) =>
'첨부 파일 제한 초과: $limit 이상의 첨부 파일을 추가할 수 없습니다';

@override
String get linkDisabledDetails => '이 대화에서는 링크를 보낼 수 없습니다.';

@override
String get linkDisabledError => '링크가 비활성화되었습니다.';
}

0 comments on commit b2e20b8

Please sign in to comment.