Merge branch 'charlesmchen/quotedRepliesVariations'

pull/1/head
Matthew Chen 8 years ago
commit 363a1ae332

@ -2274,14 +2274,6 @@ typedef enum : NSUInteger {
- (void)scrollDownButtonTapped
{
#ifdef DEBUG
CGPoint contentOffset = self.collectionView.contentOffset;
contentOffset.y += self.collectionView.height
- (self.collectionView.contentInset.top + self.collectionView.contentInset.bottom);
[self.collectionView setContentOffset:contentOffset animated:NO];
return;
#endif
NSIndexPath *indexPathOfUnreadMessagesIndicator = [self indexPathOfUnreadMessagesIndicator];
if (indexPathOfUnreadMessagesIndicator != nil) {
NSInteger unreadRow = indexPathOfUnreadMessagesIndicator.row;

@ -1876,23 +1876,33 @@ NS_ASSUME_NONNULL_BEGIN
quotedMessageAssetLoader:(nullable DebugUIMessagesAssetLoader *)quotedMessageAssetLoader
// Only applies if quotedMessageAssetLoader is non-nil.
isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
// Only applies if !isQuotedMessageIncoming.
quotedMessageMessageState:(TSOutgoingMessageState)quotedMessageMessageState
replyLabel:(NSString *)replyLabel
isReplyIncoming:(BOOL)isReplyIncoming
replyMessageBody:(NSString *)replyMessageBody
// Only applies if !isReplyIncoming.
replyMessageState:(TSOutgoingMessageState)replyMessageState
// Only applies if !isReplyIncoming.
replyIsDelivered:(BOOL)replyIsDelivered
// Only applies if !isReplyIncoming.
replyIsRead:(BOOL)replyIsRead
{
OWSAssert(thread);
// Only applies if !isQuotedMessageIncoming.
// Used fixed values for properties that shouldn't matter much.
BOOL quotedMessageIsDelivered = NO;
BOOL quotedMessageIsRead = NO;
TSOutgoingMessageState quotedMessageMessageState = TSOutgoingMessageStateSentToService;
BOOL replyIsDelivered = NO;
BOOL replyIsRead = NO;
// Seamlessly convert oversize text messages to oversize text attachments.
if ([quotedMessageBody lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) {
OWSAssert(!quotedMessageAssetLoader);
quotedMessageAssetLoader = [DebugUIMessagesAssetLoader oversizeTextInstanceWithText:quotedMessageBody];
quotedMessageBody = nil;
}
DebugUIMessagesAssetLoader *_Nullable replyAssetLoader = nil;
if ([replyMessageBody lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) {
OWSAssert(!replyAssetLoader);
replyAssetLoader = [DebugUIMessagesAssetLoader oversizeTextInstanceWithText:replyMessageBody];
replyMessageBody = nil;
}
NSMutableString *label = [NSMutableString new];
[label appendString:@"Quoted Reply ("];
@ -1907,11 +1917,11 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
[label appendString:@") to ("];
[label appendString:quotedMessageLabel];
if (quotedMessageAssetLoader) {
[label appendString:@" 📎"];
[label appendFormat:@" %@", quotedMessageAssetLoader.labelEmoji];
}
if (isQuotedMessageIncoming) {
if (quotedMessageAssetLoader && isQuotedMessageAttachmentDownloaded) {
[label appendString:@" Downloaded"];
if (quotedMessageAssetLoader && !isQuotedMessageAttachmentDownloaded) {
[label appendString:@" !Downloaded"];
}
} else {
[label appendString:[self actionLabelForHasCaption:quotedMessageBody.length > 0
@ -1951,14 +1961,14 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
if (isReplyIncoming) {
[self createFakeIncomingMessage:thread
messageBody:replyMessageBody
fakeAssetLoader:nil
fakeAssetLoader:replyAssetLoader
isAttachmentDownloaded:NO
quotedMessage:quotedMessage
transaction:transaction];
} else {
[self createFakeOutgoingMessage:thread
messageBody:replyMessageBody
fakeAssetLoader:nil
fakeAssetLoader:replyAssetLoader
messageState:replyMessageState
isDelivered:replyIsDelivered
isRead:replyIsRead
@ -1967,6 +1977,18 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
}
}
prepareBlock:^(ActionSuccessBlock success, ActionFailureBlock failure) {
if (replyAssetLoader.prepareBlock) {
__block BOOL didSucceed = NO;
replyAssetLoader.prepareBlock(
^{
didSucceed = YES;
},
^{
OWSFail(@"%@ could not prepare oversize text reply asset.", self.logTag);
});
OWSAssert(didSucceed);
}
if (quotedMessageAssetLoader.prepareBlock) {
quotedMessageAssetLoader.prepareBlock(success, failure);
} else {
@ -1996,70 +2018,55 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Short Text"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Medium Text"
isReplyIncoming:NO
replyMessageBody:mediumText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Medium Text"
isQuotedMessageIncoming:NO
quotedMessageBody:mediumText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Medium Text"
isQuotedMessageIncoming:NO
quotedMessageBody:mediumText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Medium Text"
isReplyIncoming:NO
replyMessageBody:mediumText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Long Text"
isQuotedMessageIncoming:NO
quotedMessageBody:longText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Long Text"
isReplyIncoming:NO
replyMessageBody:longText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
]];
if (includeLabels) {
@ -2072,112 +2079,132 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
isQuotedMessageIncoming:NO
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader jpegInstance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Jpg"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader jpegInstance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Mp3"
isQuotedMessageIncoming:NO
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader mp3Instance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Mp3"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader mp3Instance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Mp4"
isQuotedMessageIncoming:NO
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader mp4Instance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Mp4"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader mp4Instance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Gif"
isQuotedMessageIncoming:NO
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader gifInstance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Gif"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader gifInstance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Pdf"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tinyPdfInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Missing Pdf"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader missingPdfInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Tiny Png"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tinyPngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Missing Png"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader missingPngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
]];
if (includeLabels) {
@ -2186,32 +2213,92 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
}
[actions addObjectsFromArray:@[
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Jpg"
quotedMessageLabel:@"Tall Portrait Png"
isQuotedMessageIncoming:NO
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader jpegInstance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tallPortraitPngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Jpg"
quotedMessageLabel:@"Tall Portrait Png"
isQuotedMessageIncoming:NO
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tallPortraitPngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Medium Text"
isReplyIncoming:NO
replyMessageBody:mediumText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Tall Portrait Png"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader jpegInstance]
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tallPortraitPngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Wide Landscape Png"
isQuotedMessageIncoming:NO
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader wideLandscapePngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Wide Landscape Png"
isQuotedMessageIncoming:NO
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader wideLandscapePngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Medium Text"
isReplyIncoming:NO
replyMessageBody:mediumText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Wide Landscape Png"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader wideLandscapePngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Medium Text"
isReplyIncoming:NO
replyMessageBody:mediumText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Tiny Png"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tinyPngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Tiny Png"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tinyPngInstance]
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Medium Text"
isReplyIncoming:NO
replyMessageBody:mediumText
replyMessageState:TSOutgoingMessageStateSentToService],
]];
void (^directionActions)(BOOL, BOOL) = ^(BOOL isQuotedMessageIncoming, BOOL isReplyIncoming) {
@ -2221,14 +2308,11 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
isQuotedMessageIncoming:isQuotedMessageIncoming
quotedMessageBody:shortText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:NO
quotedMessageMessageState:TSOutgoingMessageStateUnsent
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:isReplyIncoming
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent
replyIsDelivered:NO
replyIsRead:NO],
replyMessageState:TSOutgoingMessageStateSentToService],
]];
};
@ -2241,6 +2325,133 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
directionActions(NO, YES);
directionActions(YES, YES);
if (includeLabels) {
[actions addObject:[self fakeIncomingTextMessageAction:thread
text:@"⚠️ Quoted Replies (Message States) ⚠️"]];
}
[actions addObjectsFromArray:@[
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Jpg"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader jpegInstance]
isQuotedMessageAttachmentDownloaded:NO
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Mp3"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader mp3Instance]
isQuotedMessageAttachmentDownloaded:NO
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Mp4"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader mp4Instance]
isQuotedMessageAttachmentDownloaded:NO
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Gif"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader gifInstance]
isQuotedMessageAttachmentDownloaded:NO
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Pdf"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tinyPdfInstance]
isQuotedMessageAttachmentDownloaded:NO
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Missing Pdf"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader missingPdfInstance]
isQuotedMessageAttachmentDownloaded:NO
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Tiny Png"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader tinyPngInstance]
isQuotedMessageAttachmentDownloaded:NO
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Missing Png"
isQuotedMessageIncoming:YES
quotedMessageBody:nil
quotedMessageAssetLoader:[DebugUIMessagesAssetLoader missingPngInstance]
isQuotedMessageAttachmentDownloaded:NO
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Short Text"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateAttemptingOut],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Short Text"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateSentToService],
[self fakeQuotedReplyAction:thread
quotedMessageLabel:@"Short Text"
isQuotedMessageIncoming:NO
quotedMessageBody:shortText
quotedMessageAssetLoader:nil
isQuotedMessageAttachmentDownloaded:YES
replyLabel:@"Short Text"
isReplyIncoming:NO
replyMessageBody:shortText
replyMessageState:TSOutgoingMessageStateUnsent],
]];
return actions;
}
@ -2448,7 +2659,7 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
+ (NSString *)randomOversizeText
{
NSMutableString *message = [NSMutableString new];
for (NSUInteger i = 0; i < 32; i++) {
while (message.length < kOversizeTextMessageSizeThreshold) {
[message appendString:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rutrum, nulla "
@"vitae pretium hendrerit, tellus turpis pharetra libero, vitae sodales tortor ante vel "
@"sem. Fusce sed nisl a lorem gravida tincidunt. Suspendisse efficitur non quam ac "
@ -3509,6 +3720,13 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
{
OWSAssert(thread);
// Seamlessly convert oversize text messages to oversize text attachments.
if ([messageBody lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) {
OWSAssert(!fakeAssetLoader);
fakeAssetLoader = [DebugUIMessagesAssetLoader oversizeTextInstanceWithText:messageBody];
messageBody = nil;
}
TSAttachment *_Nullable attachment = nil;
if (fakeAssetLoader) {
attachment = [self createFakeAttachment:fakeAssetLoader isAttachmentDownloaded:YES transaction:transaction];
@ -3587,6 +3805,13 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
{
OWSAssert(thread);
// Seamlessly convert oversize text messages to oversize text attachments.
if ([messageBody lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) {
OWSAssert(!fakeAssetLoader);
fakeAssetLoader = [DebugUIMessagesAssetLoader oversizeTextInstanceWithText:messageBody];
messageBody = nil;
}
TSAttachment *_Nullable attachment = nil;
if (fakeAssetLoader) {
attachment = [self createFakeAttachment:fakeAssetLoader

@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) NSString *filePath;
- (NSString *)labelEmoji;
#pragma mark -
+ (instancetype)jpegInstance;
@ -37,6 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)missingPngInstance;
+ (instancetype)missingPdfInstance;
+ (instancetype)oversizeTextInstance;
+ (instancetype)oversizeTextInstanceWithText:(NSString *)text;
@end

@ -8,11 +8,17 @@
#import <Curve25519Kit/Randomness.h>
#import <SignalServiceKit/MIMETypeUtil.h>
#import <SignalServiceKit/OWSFileSystem.h>
#import <SignalServiceKit/TSAttachment.h>
NS_ASSUME_NONNULL_BEGIN
@implementation DebugUIMessagesAssetLoader
- (NSString *)labelEmoji
{
return [TSAttachment emojiForMimeType:self.mimeType];
}
+ (DebugUIMessagesAssetLoader *)fakeAssetLoaderWithUrl:(NSString *)fileUrl mimeType:(NSString *)mimeType
{
OWSAssert(fileUrl.length > 0);
@ -318,6 +324,46 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark -
+ (DebugUIMessagesAssetLoader *)fakeOversizeTextAssetLoaderWithText:(NSString *)text
{
DebugUIMessagesAssetLoader *instance = [DebugUIMessagesAssetLoader new];
instance.mimeType = OWSMimeTypeOversizeTextMessage;
instance.filename = @"attachment.txt";
__weak DebugUIMessagesAssetLoader *weakSelf = instance;
instance.prepareBlock = ^(ActionSuccessBlock success, ActionFailureBlock failure) {
[weakSelf ensureOversizeTextAssetLoadedWithText:text success:success failure:failure];
};
return instance;
}
- (void)ensureOversizeTextAssetLoadedWithText:(NSString *)text
success:(ActionSuccessBlock)success
failure:(ActionFailureBlock)failure
{
OWSAssert(success);
OWSAssert(failure);
OWSAssert(self.filename.length > 0);
OWSAssert(self.mimeType.length > 0);
if (self.filePath) {
success();
return;
}
NSString *fileExtension = @"txt";
NSString *filePath = [OWSFileSystem temporaryFilePathWithFileExtension:fileExtension];
NSData *data = [text dataUsingEncoding:NSUTF8StringEncoding];
OWSAssert(data);
BOOL didWrite = [data writeToFile:filePath atomically:YES];
OWSAssert(didWrite);
self.filePath = filePath;
OWSAssert([NSFileManager.defaultManager fileExistsAtPath:filePath]);
success();
}
#pragma mark -
+ (instancetype)jpegInstance
{
static DebugUIMessagesAssetLoader *instance = nil;
@ -518,6 +564,16 @@ NS_ASSUME_NONNULL_BEGIN
return instance;
}
+ (instancetype)oversizeTextInstanceWithText:(NSString *)text
{
static DebugUIMessagesAssetLoader *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [DebugUIMessagesAssetLoader fakeOversizeTextAssetLoaderWithText:text];
});
return instance;
}
@end
NS_ASSUME_NONNULL_END

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSYapDatabaseObject.h"
@ -61,6 +61,8 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) {
- (BOOL)isVoiceMessage;
+ (NSString *)emojiForMimeType:(NSString *)contentType;
@end
NS_ASSUME_NONNULL_END

@ -163,28 +163,32 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
- (NSString *)description {
NSString *attachmentString = NSLocalizedString(@"ATTACHMENT", nil);
if ([MIMETypeUtil isImage:self.contentType]) {
return [NSString stringWithFormat:@"📷 %@", attachmentString];
} else if ([MIMETypeUtil isVideo:self.contentType]) {
return [NSString stringWithFormat:@"📽 %@", attachmentString];
} else if ([MIMETypeUtil isAudio:self.contentType]) {
if ([MIMETypeUtil isAudio:self.contentType]) {
// a missing filename is the legacy way to determine if an audio attachment is
// a voice note vs. other arbitrary audio attachments.
if (self.isVoiceMessage || !self.sourceFilename || self.sourceFilename.length == 0) {
attachmentString = NSLocalizedString(@"ATTACHMENT_TYPE_VOICE_MESSAGE",
@"Short text label for a voice message attachment, used for thread preview and on the lock screen");
return [NSString stringWithFormat:@"🎤 %@", attachmentString];
} else {
return [NSString stringWithFormat:@"📻 %@", attachmentString];
}
} else if ([MIMETypeUtil isAnimated:self.contentType]) {
return [NSString stringWithFormat:@"🎡 %@", attachmentString];
} else {
return [NSString stringWithFormat:@"📎 %@", attachmentString];
}
return attachmentString;
return [NSString stringWithFormat:@"%@ %@", [TSAttachment emojiForMimeType:self.contentType], attachmentString];
}
+ (NSString *)emojiForMimeType:(NSString *)contentType
{
if ([MIMETypeUtil isImage:contentType]) {
return @"📷";
} else if ([MIMETypeUtil isVideo:contentType]) {
return @"📽";
} else if ([MIMETypeUtil isAudio:contentType]) {
return @"📻";
} else if ([MIMETypeUtil isAnimated:contentType]) {
return @"🎡";
} else {
return @"📎";
}
}
- (BOOL)isVoiceMessage

Loading…
Cancel
Save