From e6e4290fa931e3685a7bb74bf5708a3a3ff571c4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 14 Mar 2017 12:17:54 -0300 Subject: [PATCH] Limit size of outgoing text messages. // FREEBIE --- .../view controllers/MessagesViewController.m | 23 +++++++++++++++++++ .../translations/en.lproj/Localizable.strings | 9 +++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Signal/src/view controllers/MessagesViewController.m b/Signal/src/view controllers/MessagesViewController.m index 52f8ff5a8..e7b80026c 100644 --- a/Signal/src/view controllers/MessagesViewController.m +++ b/Signal/src/view controllers/MessagesViewController.m @@ -853,6 +853,29 @@ typedef enum : NSUInteger { senderDisplayName:(NSString *)senderDisplayName date:(NSDate *)date { + text = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + + // Limit outgoing text messages to 64kb. + // + // TODO: Convert large text messages to attachments + // which are presented as normal text messages. + const NSUInteger kMaxTextMessageSize = 64 * 1024; + if (text.length > kMaxTextMessageSize) { + UIAlertController *controller = + [UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONVERSATION_VIEW_TEXT_MESSAGE_TOO_LARGE_ALERT_TITLE", + @"The title of the 'text message too large' alert.") + message:NSLocalizedString(@"CONVERSATION_VIEW_TEXT_MESSAGE_TOO_LARGE_ALERT_MESSAGE", + @"The message of the 'text message too large' alert.") + preferredStyle:UIAlertControllerStyleAlert]; + [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) + style:UIAlertActionStyleDefault + handler:nil]]; + [self presentViewController:controller + animated:YES + completion:nil]; + return; + } + if (text.length > 0) { if ([Environment.preferences soundInForeground]) { [JSQSystemSoundPlayer jsq_playMessageSentSound]; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 93ef90493..4ad171d37 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -52,9 +52,6 @@ /* No comment provided by engineer. */ "ATTACHMENT" = "Attachment"; -/* Label for 'cancel' button in the 'attachment approval' dialog. */ -"ATTACHMENT_APPROVAL_CANCEL_BUTTON" = "Cancel"; - /* Title for the 'attachment approval' dialog. */ "ATTACHMENT_APPROVAL_DIALOG_TITLE" = "Attachment"; @@ -148,6 +145,12 @@ /* title for conversation settings screen */ "CONVERSATION_SETTINGS" = "Conversation Settings"; +/* The message of the 'text message too large' alert. */ +"CONVERSATION_VIEW_TEXT_MESSAGE_TOO_LARGE_ALERT_MESSAGE" = "This message is too long to send."; + +/* The title of the 'text message too large' alert. */ +"CONVERSATION_VIEW_TEXT_MESSAGE_TOO_LARGE_ALERT_TITLE" = "Error"; + /* ActionSheet title */ "CORRUPTED_SESSION_DESCRIPTION" = "Resetting your session will allow you to receive future messages from %@, but it will not recover any already corrupted messages.";