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.
|
||||
///
|
||||
/// [maxBytes] is the screen's outbound byte limit and [encodeOutbound] turns
|
||||
/// draft text into what the radio would actually send, so the limit is
|
||||
/// checked against the encoded form.
|
||||
/// draft text into exactly what the send path measures (including any reply
|
||||
/// 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({
|
||||
required BuildContext context,
|
||||
required TextEditingController controller,
|
||||
@@ -33,6 +35,25 @@ Future<void> attachIpfsLinkToDraft({
|
||||
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) {
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
@@ -73,50 +94,31 @@ Future<void> attachIpfsLinkToDraft({
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
|
||||
final messageText = composeIpfsLinkDraft(
|
||||
messageUrl: messageUrl,
|
||||
existingText: controller.text.trim(),
|
||||
maxBytes: maxBytes,
|
||||
encodeOutbound: encodeOutbound,
|
||||
);
|
||||
if (messageText == null) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.chat_messageTooLong(maxBytes)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final messageText = draftWithLink(messageUrl);
|
||||
controller.value = TextEditingValue(
|
||||
text: messageText,
|
||||
selection: TextSelection.collapsed(offset: messageText.length),
|
||||
);
|
||||
focusNode.requestFocus();
|
||||
if (!fits(messageText)) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.chat_ipfsLinkOverLimit),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the draft with [messageUrl] in front of [existingText], trimming
|
||||
/// [existingText] from the end until the encoded result fits [maxBytes].
|
||||
/// Returns null when even the link alone does not fit.
|
||||
/// Puts [messageUrl] in front of [existingText], leaving the text intact.
|
||||
@visibleForTesting
|
||||
String? composeIpfsLinkDraft({
|
||||
String composeIpfsLinkDraft({
|
||||
required String messageUrl,
|
||||
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 String Function(String text) encodeOutbound,
|
||||
}) {
|
||||
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;
|
||||
}
|
||||
}) => utf8.encode(encodeOutbound(draft.trim())).length <= maxBytes;
|
||||
@@ -22,6 +22,19 @@ class IpfsUploadHelper {
|
||||
|
||||
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) {
|
||||
switch (fileName.toLowerCase().split('.').last) {
|
||||
case 'jpg':
|
||||
@@ -149,8 +162,7 @@ class IpfsUploadHelper {
|
||||
);
|
||||
}
|
||||
|
||||
final gateway = normalizeIpfsGateway(uploadGateway);
|
||||
return gateway.isEmpty ? 'ipfs://$cid' : '$gateway$cid';
|
||||
return linkForCid(uploadGateway: uploadGateway, cid: cid);
|
||||
}
|
||||
|
||||
static Future<void> _copyKuboFileToMfs({
|
||||
|
||||
@@ -953,6 +953,14 @@
|
||||
}
|
||||
},
|
||||
"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": {
|
||||
"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.'**
|
||||
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
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
|
||||
@@ -1850,6 +1850,14 @@ class AppLocalizationsBg extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Не мог да откривам та изображин';
|
||||
|
||||
|
||||
@@ -1849,6 +1849,14 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Konnte dieses Bild nicht öffnen.';
|
||||
|
||||
|
||||
@@ -1818,6 +1818,14 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Couldn\'t open that image';
|
||||
|
||||
|
||||
@@ -1845,6 +1845,14 @@ class AppLocalizationsEs extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'No pude abrir esa imagen';
|
||||
|
||||
|
||||
@@ -1849,6 +1849,14 @@ class AppLocalizationsFr extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Je n\'ai pas pu ouvrir cette image';
|
||||
|
||||
|
||||
@@ -1839,6 +1839,14 @@ class AppLocalizationsHu extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Nem tudtam ezt a fenti fényre kapni';
|
||||
|
||||
|
||||
@@ -1849,6 +1849,14 @@ class AppLocalizationsIt extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed =>
|
||||
'Non sono riuscito ad aprire quell\'immagine';
|
||||
|
||||
@@ -1762,6 +1762,14 @@ class AppLocalizationsJa extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'その画像を開けませんでした';
|
||||
|
||||
|
||||
@@ -1767,6 +1767,14 @@ class AppLocalizationsKo extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => '그 이미지를 열 수 없었어요.';
|
||||
|
||||
|
||||
@@ -1835,6 +1835,14 @@ class AppLocalizationsNl extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Kon die afbeelding niet openen';
|
||||
|
||||
|
||||
@@ -1864,6 +1864,14 @@ class AppLocalizationsPl extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Nie mogłem otworzyć tego obrazu';
|
||||
|
||||
|
||||
@@ -1845,6 +1845,14 @@ class AppLocalizationsPt extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Não consegui abrir essa imagem';
|
||||
|
||||
|
||||
@@ -1849,6 +1849,14 @@ class AppLocalizationsRu extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Не удалось открыть это изображение';
|
||||
|
||||
|
||||
@@ -1837,6 +1837,14 @@ class AppLocalizationsSk extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Nesmiela jsem otvoriť tento obrázok';
|
||||
|
||||
|
||||
@@ -1836,6 +1836,14 @@ class AppLocalizationsSl extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Nispeval sem tega ta slik';
|
||||
|
||||
|
||||
@@ -1824,6 +1824,14 @@ class AppLocalizationsSv extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Kunde inte öppna bilden';
|
||||
|
||||
|
||||
@@ -1839,6 +1839,14 @@ class AppLocalizationsUk extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => 'Неможливо відкрити це изображення';
|
||||
|
||||
|
||||
@@ -1742,6 +1742,14 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
String get chat_ipfsUploadNotConfigured =>
|
||||
'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
|
||||
String get chat_imagePickFailed => '无法打开该图片';
|
||||
|
||||
|
||||
@@ -1319,8 +1319,13 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
controller: _textController,
|
||||
focusNode: _textFieldFocusNode,
|
||||
maxBytes: maxChannelMessageBytes(connector.selfName),
|
||||
encodeOutbound: (text) =>
|
||||
connector.prepareChannelOutboundText(widget.channel.index, text),
|
||||
encodeOutbound: (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:meshcore_open/helpers/ipfs_link_attach_flow.dart';
|
||||
import 'package:meshcore_open/helpers/ipfs_upload_helper.dart';
|
||||
|
||||
void main() {
|
||||
const url = 'ipfs://cid';
|
||||
String identity(String text) => text;
|
||||
|
||||
test('puts the link before an empty draft with a trailing space', () {
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: '',
|
||||
maxBytes: 100,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
'$url ',
|
||||
);
|
||||
group('composeIpfsLinkDraft', () {
|
||||
test('puts the link before an empty draft with a trailing space', () {
|
||||
expect(composeIpfsLinkDraft(messageUrl: url, existingText: ''), '$url ');
|
||||
});
|
||||
|
||||
test('keeps the whole draft after the link', () {
|
||||
final draft = 'x' * 500;
|
||||
expect(
|
||||
composeIpfsLinkDraft(messageUrl: url, existingText: draft),
|
||||
'$url\n$draft',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('keeps a draft that fits after the link', () {
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: 'hello',
|
||||
maxBytes: 100,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
'$url\nhello',
|
||||
);
|
||||
group('ipfsLinkDraftFits', () {
|
||||
test('accepts a draft at the limit and rejects one byte over', () {
|
||||
expect(
|
||||
ipfsLinkDraftFits('$url\nhi', maxBytes: 13, encodeOutbound: identity),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
ipfsLinkDraftFits('$url\nhi', maxBytes: 12, encodeOutbound: identity),
|
||||
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', () {
|
||||
expect(
|
||||
composeIpfsLinkDraft(
|
||||
messageUrl: url,
|
||||
existingText: 'hello',
|
||||
maxBytes: url.length + 3,
|
||||
encodeOutbound: identity,
|
||||
),
|
||||
'$url\nhe',
|
||||
);
|
||||
});
|
||||
group('IpfsUploadHelper.linkForCid', () {
|
||||
test('uses ipfs:// without a gateway', () {
|
||||
expect(
|
||||
IpfsUploadHelper.linkForCid(uploadGateway: '', cid: 'abc'),
|
||||
'ipfs://abc',
|
||||
);
|
||||
});
|
||||
|
||||
test('measures the encoded form', () {
|
||||
expect(
|
||||
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,
|
||||
);
|
||||
test('sample CID is CIDv1 base32 length', () {
|
||||
expect(IpfsUploadHelper.sampleCid.length, 59);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -21,6 +21,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -64,6 +66,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -107,6 +111,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -150,6 +156,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -193,6 +201,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -236,6 +246,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -279,6 +291,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -322,6 +336,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -365,6 +381,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -408,6 +426,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -451,6 +471,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -494,6 +516,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -537,6 +561,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -580,6 +606,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -623,6 +651,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -666,6 +696,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
@@ -709,6 +741,8 @@
|
||||
"chat_sendImageIpfs",
|
||||
"chat_ipfsUploadFailed",
|
||||
"chat_ipfsUploadNotConfigured",
|
||||
"chat_ipfsLinkNoRoom",
|
||||
"chat_ipfsLinkOverLimit",
|
||||
"map_pathTraceAddMoreHint",
|
||||
"map_pathTraceModeRoundTrip",
|
||||
"map_pathTraceModeRoundTripHint",
|
||||
|
||||
Reference in new issue
Block a user