Never silently truncate the draft when attaching an IPFS link
Check before uploading that the link (from the gateway and a CIDv1-sized placeholder) fits with the draft and the reply prefix, and tell the user when it doesn't instead of cutting their text. The channel limit now counts the @[name] reply prefix like the send path.
This commit is contained in:
1 parent
084a8fb98b
commit
34db64d7af
25 files changed
+315
-103
No files matched your search
@@ -14,8 +14,10 @@ import 'snack_bar_builder.dart';
|
|||||||
/// puts the resulting link at the start of the composer draft.
|
/// puts the resulting link at the start of the composer draft.
|
||||||
///
|
///
|
||||||
/// [maxBytes] is the screen's outbound byte limit and [encodeOutbound] turns
|
/// [maxBytes] is the screen's outbound byte limit and [encodeOutbound] turns
|
||||||
/// draft text into what the radio would actually send, so the limit is
|
/// draft text into exactly what the send path measures (including any reply
|
||||||
/// checked against the encoded form.
|
/// prefix), so the limit is checked against that form. The draft is never
|
||||||
|
/// shortened: if the link won't fit, nothing is uploaded and the user is told
|
||||||
|
/// to shorten the message.
|
||||||
Future<void> attachIpfsLinkToDraft({
|
Future<void> attachIpfsLinkToDraft({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required TextEditingController controller,
|
required TextEditingController controller,
|
||||||
@@ -33,6 +35,25 @@ Future<void> attachIpfsLinkToDraft({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String draftWithLink(String messageUrl) => composeIpfsLinkDraft(
|
||||||
|
messageUrl: messageUrl,
|
||||||
|
existingText: controller.text.trim(),
|
||||||
|
);
|
||||||
|
bool fits(String draft) => ipfsLinkDraftFits(
|
||||||
|
draft,
|
||||||
|
maxBytes: maxBytes,
|
||||||
|
encodeOutbound: encodeOutbound,
|
||||||
|
);
|
||||||
|
|
||||||
|
final sampleLink = IpfsUploadHelper.linkForCid(
|
||||||
|
uploadGateway: settings.uploadIpfsGateway,
|
||||||
|
cid: IpfsUploadHelper.sampleCid,
|
||||||
|
);
|
||||||
|
if (!fits(draftWithLink(sampleLink))) {
|
||||||
|
showDismissibleSnackBar(context, content: Text(l10n.chat_ipfsLinkNoRoom));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void showFailure(Object error) {
|
void showFailure(Object error) {
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
showDismissibleSnackBar(
|
showDismissibleSnackBar(
|
||||||
@@ -73,50 +94,31 @@ Future<void> attachIpfsLinkToDraft({
|
|||||||
}
|
}
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
final messageText = composeIpfsLinkDraft(
|
final messageText = draftWithLink(messageUrl);
|
||||||
messageUrl: messageUrl,
|
|
||||||
existingText: controller.text.trim(),
|
|
||||||
maxBytes: maxBytes,
|
|
||||||
encodeOutbound: encodeOutbound,
|
|
||||||
);
|
|
||||||
if (messageText == null) {
|
|
||||||
showDismissibleSnackBar(
|
|
||||||
context,
|
|
||||||
content: Text(l10n.chat_messageTooLong(maxBytes)),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
controller.value = TextEditingValue(
|
controller.value = TextEditingValue(
|
||||||
text: messageText,
|
text: messageText,
|
||||||
selection: TextSelection.collapsed(offset: messageText.length),
|
selection: TextSelection.collapsed(offset: messageText.length),
|
||||||
);
|
);
|
||||||
focusNode.requestFocus();
|
focusNode.requestFocus();
|
||||||
|
if (!fits(messageText)) {
|
||||||
|
showDismissibleSnackBar(
|
||||||
|
context,
|
||||||
|
content: Text(l10n.chat_ipfsLinkOverLimit),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builds the draft with [messageUrl] in front of [existingText], trimming
|
/// Puts [messageUrl] in front of [existingText], leaving the text intact.
|
||||||
/// [existingText] from the end until the encoded result fits [maxBytes].
|
|
||||||
/// Returns null when even the link alone does not fit.
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
String? composeIpfsLinkDraft({
|
String composeIpfsLinkDraft({
|
||||||
required String messageUrl,
|
required String messageUrl,
|
||||||
required String existingText,
|
required String existingText,
|
||||||
|
}) => existingText.isEmpty ? '$messageUrl ' : '$messageUrl\n$existingText';
|
||||||
|
|
||||||
|
/// Whether [draft], encoded the way the send path encodes it, fits [maxBytes].
|
||||||
|
@visibleForTesting
|
||||||
|
bool ipfsLinkDraftFits(
|
||||||
|
String draft, {
|
||||||
required int maxBytes,
|
required int maxBytes,
|
||||||
required String Function(String text) encodeOutbound,
|
required String Function(String text) encodeOutbound,
|
||||||
}) {
|
}) => utf8.encode(encodeOutbound(draft.trim())).length <= maxBytes;
|
||||||
bool fits(String text) =>
|
|
||||||
utf8.encode(encodeOutbound(text)).length <= maxBytes;
|
|
||||||
|
|
||||||
final messageText = existingText.isEmpty
|
|
||||||
? '$messageUrl '
|
|
||||||
: '$messageUrl\n$existingText';
|
|
||||||
if (fits(messageText)) return messageText;
|
|
||||||
if (existingText.isEmpty) return null;
|
|
||||||
|
|
||||||
final originalCharacters = existingText.characters.toList();
|
|
||||||
for (var count = originalCharacters.length - 1; count >= 0; count--) {
|
|
||||||
final candidate = '$messageUrl\n${originalCharacters.take(count).join()}';
|
|
||||||
if (fits(candidate)) return candidate;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
@@ -22,6 +22,19 @@ class IpfsUploadHelper {
|
|||||||
|
|
||||||
static final _kuboAddPath = RegExp(r'/api/v0/add/?$');
|
static final _kuboAddPath = RegExp(r'/api/v0/add/?$');
|
||||||
|
|
||||||
|
/// A CIDv1 (base32, sha2-256) as long as the CID of every upload, used to
|
||||||
|
/// size the link before uploading.
|
||||||
|
static const sampleCid =
|
||||||
|
'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku';
|
||||||
|
|
||||||
|
static String linkForCid({
|
||||||
|
required String uploadGateway,
|
||||||
|
required String cid,
|
||||||
|
}) {
|
||||||
|
final gateway = normalizeIpfsGateway(uploadGateway);
|
||||||
|
return gateway.isEmpty ? 'ipfs://$cid' : '$gateway$cid';
|
||||||
|
}
|
||||||
|
|
||||||
static String mimeTypeForFileName(String fileName) {
|
static String mimeTypeForFileName(String fileName) {
|
||||||
switch (fileName.toLowerCase().split('.').last) {
|
switch (fileName.toLowerCase().split('.').last) {
|
||||||
case 'jpg':
|
case 'jpg':
|
||||||
@@ -149,8 +162,7 @@ class IpfsUploadHelper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final gateway = normalizeIpfsGateway(uploadGateway);
|
return linkForCid(uploadGateway: uploadGateway, cid: cid);
|
||||||
return gateway.isEmpty ? 'ipfs://$cid' : '$gateway$cid';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> _copyKuboFileToMfs({
|
static Future<void> _copyKuboFileToMfs({
|
||||||
|
|||||||
@@ -953,6 +953,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"chat_ipfsUploadNotConfigured": "Configure an IPFS upload provider in App Settings first.",
|
"chat_ipfsUploadNotConfigured": "Configure an IPFS upload provider in App Settings first.",
|
||||||
|
"chat_ipfsLinkNoRoom": "Not enough room for the image link. Shorten your message, then try again.",
|
||||||
|
"@chat_ipfsLinkNoRoom": {
|
||||||
|
"description": "Shown before an IPFS upload when the link would push the draft over the message size limit"
|
||||||
|
},
|
||||||
|
"chat_ipfsLinkOverLimit": "Image link added, but the message is now too long. Shorten it before sending.",
|
||||||
|
"@chat_ipfsLinkOverLimit": {
|
||||||
|
"description": "Shown after an IPFS upload when the link plus the draft no longer fits the message size limit"
|
||||||
|
},
|
||||||
"chat_imagePickFailed": "Couldn't open that image",
|
"chat_imagePickFailed": "Couldn't open that image",
|
||||||
"@chat_imagePickFailed": {
|
"@chat_imagePickFailed": {
|
||||||
"description": "Shown when picking or reading a photo to send fails"
|
"description": "Shown when picking or reading a photo to send fails"
|
||||||
|
|||||||
@@ -3286,6 +3286,18 @@ abstract class AppLocalizations {
|
|||||||
/// **'Configure an IPFS upload provider in App Settings first.'**
|
/// **'Configure an IPFS upload provider in App Settings first.'**
|
||||||
String get chat_ipfsUploadNotConfigured;
|
String get chat_ipfsUploadNotConfigured;
|
||||||
|
|
||||||
|
/// Shown before an IPFS upload when the link would push the draft over the message size limit
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Not enough room for the image link. Shorten your message, then try again.'**
|
||||||
|
String get chat_ipfsLinkNoRoom;
|
||||||
|
|
||||||
|
/// Shown after an IPFS upload when the link plus the draft no longer fits the message size limit
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Image link added, but the message is now too long. Shorten it before sending.'**
|
||||||
|
String get chat_ipfsLinkOverLimit;
|
||||||
|
|
||||||
/// Shown when picking or reading a photo to send fails
|
/// Shown when picking or reading a photo to send fails
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
|
|||||||
@@ -1850,6 +1850,14 @@ class AppLocalizationsBg extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Не мог да откривам та изображин';
|
String get chat_imagePickFailed => 'Не мог да откривам та изображин';
|
||||||
|
|
||||||
|
|||||||
@@ -1849,6 +1849,14 @@ class AppLocalizationsDe extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Konnte dieses Bild nicht öffnen.';
|
String get chat_imagePickFailed => 'Konnte dieses Bild nicht öffnen.';
|
||||||
|
|
||||||
|
|||||||
@@ -1818,6 +1818,14 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Couldn\'t open that image';
|
String get chat_imagePickFailed => 'Couldn\'t open that image';
|
||||||
|
|
||||||
|
|||||||
@@ -1845,6 +1845,14 @@ class AppLocalizationsEs extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'No pude abrir esa imagen';
|
String get chat_imagePickFailed => 'No pude abrir esa imagen';
|
||||||
|
|
||||||
|
|||||||
@@ -1849,6 +1849,14 @@ class AppLocalizationsFr extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Je n\'ai pas pu ouvrir cette image';
|
String get chat_imagePickFailed => 'Je n\'ai pas pu ouvrir cette image';
|
||||||
|
|
||||||
|
|||||||
@@ -1839,6 +1839,14 @@ class AppLocalizationsHu extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Nem tudtam ezt a fenti fényre kapni';
|
String get chat_imagePickFailed => 'Nem tudtam ezt a fenti fényre kapni';
|
||||||
|
|
||||||
|
|||||||
@@ -1849,6 +1849,14 @@ class AppLocalizationsIt extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed =>
|
String get chat_imagePickFailed =>
|
||||||
'Non sono riuscito ad aprire quell\'immagine';
|
'Non sono riuscito ad aprire quell\'immagine';
|
||||||
|
|||||||
@@ -1762,6 +1762,14 @@ class AppLocalizationsJa extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'その画像を開けませんでした';
|
String get chat_imagePickFailed => 'その画像を開けませんでした';
|
||||||
|
|
||||||
|
|||||||
@@ -1767,6 +1767,14 @@ class AppLocalizationsKo extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => '그 이미지를 열 수 없었어요.';
|
String get chat_imagePickFailed => '그 이미지를 열 수 없었어요.';
|
||||||
|
|
||||||
|
|||||||
@@ -1835,6 +1835,14 @@ class AppLocalizationsNl extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Kon die afbeelding niet openen';
|
String get chat_imagePickFailed => 'Kon die afbeelding niet openen';
|
||||||
|
|
||||||
|
|||||||
@@ -1864,6 +1864,14 @@ class AppLocalizationsPl extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Nie mogłem otworzyć tego obrazu';
|
String get chat_imagePickFailed => 'Nie mogłem otworzyć tego obrazu';
|
||||||
|
|
||||||
|
|||||||
@@ -1845,6 +1845,14 @@ class AppLocalizationsPt extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Não consegui abrir essa imagem';
|
String get chat_imagePickFailed => 'Não consegui abrir essa imagem';
|
||||||
|
|
||||||
|
|||||||
@@ -1849,6 +1849,14 @@ class AppLocalizationsRu extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Не удалось открыть это изображение';
|
String get chat_imagePickFailed => 'Не удалось открыть это изображение';
|
||||||
|
|
||||||
|
|||||||
@@ -1837,6 +1837,14 @@ class AppLocalizationsSk extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Nesmiela jsem otvoriť tento obrázok';
|
String get chat_imagePickFailed => 'Nesmiela jsem otvoriť tento obrázok';
|
||||||
|
|
||||||
|
|||||||
@@ -1836,6 +1836,14 @@ class AppLocalizationsSl extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Nispeval sem tega ta slik';
|
String get chat_imagePickFailed => 'Nispeval sem tega ta slik';
|
||||||
|
|
||||||
|
|||||||
@@ -1824,6 +1824,14 @@ class AppLocalizationsSv extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Kunde inte öppna bilden';
|
String get chat_imagePickFailed => 'Kunde inte öppna bilden';
|
||||||
|
|
||||||
|
|||||||
@@ -1839,6 +1839,14 @@ class AppLocalizationsUk extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => 'Неможливо відкрити це изображення';
|
String get chat_imagePickFailed => 'Неможливо відкрити це изображення';
|
||||||
|
|
||||||
|
|||||||
@@ -1742,6 +1742,14 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
String get chat_ipfsUploadNotConfigured =>
|
String get chat_ipfsUploadNotConfigured =>
|
||||||
'Configure an IPFS upload provider in App Settings first.';
|
'Configure an IPFS upload provider in App Settings first.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkNoRoom =>
|
||||||
|
'Not enough room for the image link. Shorten your message, then try again.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get chat_ipfsLinkOverLimit =>
|
||||||
|
'Image link added, but the message is now too long. Shorten it before sending.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get chat_imagePickFailed => '无法打开该图片';
|
String get chat_imagePickFailed => '无法打开该图片';
|
||||||
|
|
||||||
|
|||||||
@@ -1319,8 +1319,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
controller: _textController,
|
controller: _textController,
|
||||||
focusNode: _textFieldFocusNode,
|
focusNode: _textFieldFocusNode,
|
||||||
maxBytes: maxChannelMessageBytes(connector.selfName),
|
maxBytes: maxChannelMessageBytes(connector.selfName),
|
||||||
encodeOutbound: (text) =>
|
encodeOutbound: (text) {
|
||||||
connector.prepareChannelOutboundText(widget.channel.index, text),
|
final replyTo = _replyingToMessage;
|
||||||
|
return connector.prepareChannelOutboundText(
|
||||||
|
widget.channel.index,
|
||||||
|
replyTo == null ? text : '${_replyPrefix(replyTo)}$text',
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,76 +1,71 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:meshcore_open/helpers/ipfs_link_attach_flow.dart';
|
import 'package:meshcore_open/helpers/ipfs_link_attach_flow.dart';
|
||||||
|
import 'package:meshcore_open/helpers/ipfs_upload_helper.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const url = 'ipfs://cid';
|
const url = 'ipfs://cid';
|
||||||
String identity(String text) => text;
|
String identity(String text) => text;
|
||||||
|
|
||||||
test('puts the link before an empty draft with a trailing space', () {
|
group('composeIpfsLinkDraft', () {
|
||||||
expect(
|
test('puts the link before an empty draft with a trailing space', () {
|
||||||
composeIpfsLinkDraft(
|
expect(composeIpfsLinkDraft(messageUrl: url, existingText: ''), '$url ');
|
||||||
messageUrl: url,
|
});
|
||||||
existingText: '',
|
|
||||||
maxBytes: 100,
|
test('keeps the whole draft after the link', () {
|
||||||
encodeOutbound: identity,
|
final draft = 'x' * 500;
|
||||||
),
|
expect(
|
||||||
'$url ',
|
composeIpfsLinkDraft(messageUrl: url, existingText: draft),
|
||||||
);
|
'$url\n$draft',
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('keeps a draft that fits after the link', () {
|
group('ipfsLinkDraftFits', () {
|
||||||
expect(
|
test('accepts a draft at the limit and rejects one byte over', () {
|
||||||
composeIpfsLinkDraft(
|
expect(
|
||||||
messageUrl: url,
|
ipfsLinkDraftFits('$url\nhi', maxBytes: 13, encodeOutbound: identity),
|
||||||
existingText: 'hello',
|
isTrue,
|
||||||
maxBytes: 100,
|
);
|
||||||
encodeOutbound: identity,
|
expect(
|
||||||
),
|
ipfsLinkDraftFits('$url\nhi', maxBytes: 12, encodeOutbound: identity),
|
||||||
'$url\nhello',
|
isFalse,
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('measures the encoded form, including a reply prefix', () {
|
||||||
|
String withReply(String text) => '@[Alice] $text';
|
||||||
|
expect(
|
||||||
|
ipfsLinkDraftFits('$url\nhi', maxBytes: 13, encodeOutbound: withReply),
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ipfsLinkDraftFits('$url\nhi', maxBytes: 22, encodeOutbound: withReply),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('ignores the trailing space the send path trims', () {
|
||||||
|
expect(
|
||||||
|
ipfsLinkDraftFits(
|
||||||
|
'$url ',
|
||||||
|
maxBytes: url.length,
|
||||||
|
encodeOutbound: identity,
|
||||||
|
),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('trims the draft until the encoded text fits', () {
|
group('IpfsUploadHelper.linkForCid', () {
|
||||||
expect(
|
test('uses ipfs:// without a gateway', () {
|
||||||
composeIpfsLinkDraft(
|
expect(
|
||||||
messageUrl: url,
|
IpfsUploadHelper.linkForCid(uploadGateway: '', cid: 'abc'),
|
||||||
existingText: 'hello',
|
'ipfs://abc',
|
||||||
maxBytes: url.length + 3,
|
);
|
||||||
encodeOutbound: identity,
|
});
|
||||||
),
|
|
||||||
'$url\nhe',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('measures the encoded form', () {
|
test('sample CID is CIDv1 base32 length', () {
|
||||||
expect(
|
expect(IpfsUploadHelper.sampleCid.length, 59);
|
||||||
composeIpfsLinkDraft(
|
});
|
||||||
messageUrl: url,
|
|
||||||
existingText: 'hello',
|
|
||||||
maxBytes: url.length + 3,
|
|
||||||
encodeOutbound: (text) => 'x$text',
|
|
||||||
),
|
|
||||||
'$url\nh',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('returns null when the link alone does not fit', () {
|
|
||||||
expect(
|
|
||||||
composeIpfsLinkDraft(
|
|
||||||
messageUrl: url,
|
|
||||||
existingText: 'hello',
|
|
||||||
maxBytes: 4,
|
|
||||||
encodeOutbound: identity,
|
|
||||||
),
|
|
||||||
isNull,
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
composeIpfsLinkDraft(
|
|
||||||
messageUrl: url,
|
|
||||||
existingText: '',
|
|
||||||
maxBytes: 4,
|
|
||||||
encodeOutbound: identity,
|
|
||||||
),
|
|
||||||
isNull,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -64,6 +66,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -107,6 +111,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -150,6 +156,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -193,6 +201,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -236,6 +246,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -279,6 +291,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -322,6 +336,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -365,6 +381,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -408,6 +426,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -451,6 +471,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -494,6 +516,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -537,6 +561,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -580,6 +606,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -623,6 +651,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -666,6 +696,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
@@ -709,6 +741,8 @@
|
|||||||
"chat_sendImageIpfs",
|
"chat_sendImageIpfs",
|
||||||
"chat_ipfsUploadFailed",
|
"chat_ipfsUploadFailed",
|
||||||
"chat_ipfsUploadNotConfigured",
|
"chat_ipfsUploadNotConfigured",
|
||||||
|
"chat_ipfsLinkNoRoom",
|
||||||
|
"chat_ipfsLinkOverLimit",
|
||||||
"map_pathTraceAddMoreHint",
|
"map_pathTraceAddMoreHint",
|
||||||
"map_pathTraceModeRoundTrip",
|
"map_pathTraceModeRoundTrip",
|
||||||
"map_pathTraceModeRoundTripHint",
|
"map_pathTraceModeRoundTripHint",
|
||||||
|
|||||||
Reference in new issue
Block a user