From 3eb2df004edf7668a7d3a54d467e1fc580084603 Mon Sep 17 00:00:00 2001 From: Taksh Date: Fri, 13 Nov 2026 15:50:11 +0530 Subject: [PATCH] Explain oversized private-message failures --- bitchat/Localizable.xcstrings | 186 ++++++++++++++++++ bitchat/Services/CommandProcessor.swift | 2 +- .../ChatPrivateConversationCoordinator.swift | 2 +- ...eConversationCoordinatorContextTests.swift | 17 +- bitchatTests/CommandProcessorTests.swift | 8 +- 5 files changed, 206 insertions(+), 9 deletions(-) diff --git a/bitchat/Localizable.xcstrings b/bitchat/Localizable.xcstrings index 601d5b6a..80728504 100644 --- a/bitchat/Localizable.xcstrings +++ b/bitchat/Localizable.xcstrings @@ -52221,6 +52221,192 @@ } } }, + "content.delivery.reason.too_long" : { + "comment" : "Failure reason when a private message exceeds the wire size limit", + "extractionState" : "manual", + "localizations" : { + "ar" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "الرسالة طويلة جدًا" + } + }, + "bn" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "বার্তাটি খুব দীর্ঘ" + } + }, + "de" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "nachricht zu lang" + } + }, + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "message too long" + } + }, + "es" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "mensaje demasiado largo" + } + }, + "fa" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "پیام بیش از حد طولانی است" + } + }, + "fil" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "masyadong mahaba ang mensahe" + } + }, + "fr" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "message trop long" + } + }, + "he" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "ההודעה ארוכה מדי" + } + }, + "hi" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "संदेश बहुत लंबा है" + } + }, + "id" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "pesan terlalu panjang" + } + }, + "it" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "messaggio troppo lungo" + } + }, + "ja" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "メッセージが長すぎます" + } + }, + "ko" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "메시지가 너무 깁니다" + } + }, + "ms" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "mesej terlalu panjang" + } + }, + "ne" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "सन्देश धेरै लामो छ" + } + }, + "nl" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "bericht te lang" + } + }, + "pl" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "wiadomość jest za długa" + } + }, + "pt" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "mensagem demasiado longa" + } + }, + "pt-BR" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "mensagem muito longa" + } + }, + "ru" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "сообщение слишком длинное" + } + }, + "sv" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "meddelandet är för långt" + } + }, + "ta" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "செய்தி மிகவும் நீளமாக உள்ளது" + } + }, + "th" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "ข้อความยาวเกินไป" + } + }, + "tr" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "mesaj çok uzun" + } + }, + "uk" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "повідомлення надто довге" + } + }, + "ur" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "پیغام بہت لمبا ہے" + } + }, + "vi" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "tin nhắn quá dài" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "消息过长" + } + }, + "zh-Hant" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "訊息過長" + } + } + } + }, "content.delivery.reason.unknown_recipient" : { "extractionState" : "manual", "localizations" : { diff --git a/bitchat/Services/CommandProcessor.swift b/bitchat/Services/CommandProcessor.swift index 11aa5e4e..8af2deb7 100644 --- a/bitchat/Services/CommandProcessor.swift +++ b/bitchat/Services/CommandProcessor.swift @@ -531,7 +531,7 @@ final class CommandProcessor { if let peerID = contextProvider?.selectedPrivateChatPeer { guard PrivateMessagePacket.contentFitsOnWire(token) else { - return .error(message: String(localized: "content.delivery.reason.send_error", defaultValue: "send error", comment: "Failure reason for a generic send error")) + return .error(message: String(localized: "content.delivery.reason.too_long", defaultValue: "message too long", comment: "Failure reason when a private message exceeds the wire size limit")) } contextProvider?.sendPrivateMessage(token, to: peerID) return .success(message: String(format: String(localized: "command.pay.sent_private", defaultValue: "sent %@ — cashu is a bearer token; whoever redeems it first gets the funds", comment: "Confirmation after sending a cashu token in a private chat; placeholder is the amount summary"), locale: .current, summary)) diff --git a/bitchat/ViewModels/ChatPrivateConversationCoordinator.swift b/bitchat/ViewModels/ChatPrivateConversationCoordinator.swift index 529021dd..d42f6e10 100644 --- a/bitchat/ViewModels/ChatPrivateConversationCoordinator.swift +++ b/bitchat/ViewModels/ChatPrivateConversationCoordinator.swift @@ -397,7 +397,7 @@ final class ChatPrivateConversationCoordinator { private func initialDeliveryStatus(for content: String) -> DeliveryStatus { guard PrivateMessagePacket.contentFitsOnWire(content) else { - return .failed(reason: String(localized: "content.delivery.reason.send_error", comment: "Failure reason for a generic send error")) + return .failed(reason: String(localized: "content.delivery.reason.too_long", defaultValue: "message too long", comment: "Failure reason when a private message exceeds the wire size limit")) } return .sending } diff --git a/bitchatTests/ChatPrivateConversationCoordinatorContextTests.swift b/bitchatTests/ChatPrivateConversationCoordinatorContextTests.swift index b31a06d1..80f613bc 100644 --- a/bitchatTests/ChatPrivateConversationCoordinatorContextTests.swift +++ b/bitchatTests/ChatPrivateConversationCoordinatorContextTests.swift @@ -1253,11 +1253,20 @@ struct ChatPrivateConversationCoordinatorContextTests { coordinator.sendPrivateMessage(content, to: peerID) #expect(context.privateChats[peerID]?.map(\.content) == [content]) - guard case .failed? = context.privateChats[peerID]?.first?.deliveryStatus else { - Issue.record("Expected oversized content to fail delivery") - return - } + #expect(context.privateChats[peerID]?.first?.deliveryStatus == .failed( + reason: String(localized: "content.delivery.reason.too_long", defaultValue: "message too long") + )) #expect(context.routedPrivateMessages.isEmpty) #expect(context.geoPrivateMessages.isEmpty) + + // The multibyte UTF-8 boundary still sends: 127 × 2 + 1 = 255 bytes. + let boundaryContent = String(repeating: "é", count: 127) + "a" + #expect(boundaryContent.utf8.count == PrivateMessagePacket.maxContentUTF8Bytes) + coordinator.sendPrivateMessage(boundaryContent, to: peerID) + + #expect(context.privateChats[peerID]?.map(\.content) == [content, boundaryContent]) + #expect(context.privateChats[peerID]?.last?.deliveryStatus == (isGeohash ? .sent : .sending)) + #expect(context.routedPrivateMessages.map(\.content) == (isGeohash ? [] : [boundaryContent])) + #expect(context.geoPrivateMessages.map(\.content) == (isGeohash ? [boundaryContent] : [])) } } diff --git a/bitchatTests/CommandProcessorTests.swift b/bitchatTests/CommandProcessorTests.swift index 97ce6da0..6f20ccb6 100644 --- a/bitchatTests/CommandProcessorTests.swift +++ b/bitchatTests/CommandProcessorTests.swift @@ -489,16 +489,18 @@ struct CommandProcessorTests { } @MainActor - @Test func payRefusesAPrivateTokenThatDoesNotFitTheWire() { + @Test(arguments: [false, true]) func payRefusesAPrivateTokenThatDoesNotFitTheWire(isGeohash: Bool) { let context = MockCommandContextProvider() - context.selectedPrivateChatPeer = PeerID(str: "abcd1234abcd1234") + context.selectedPrivateChatPeer = isGeohash + ? PeerID(nostr_: String(repeating: "a", count: 64)) + : PeerID(str: "abcd1234abcd1234") let processor = makePayProcessor(context: context) let token = Self.cashuV3Token(mint: "https://mint.example.com/" + String(repeating: "a", count: 240)) #expect(token.utf8.count > PrivateMessagePacket.maxContentUTF8Bytes) switch processor.process("/pay \(token)") { case .error(let message): - #expect(message == "send error") + #expect(message == String(localized: "content.delivery.reason.too_long", defaultValue: "message too long")) default: Issue.record("Expected the oversized token to be refused") }