|
|
|
@ -56,12 +56,12 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
@property (nonatomic) BOOL hasViewState;
|
|
|
|
|
@property (nonatomic) OWSMessageCellType messageCellType;
|
|
|
|
|
// TODO: Rename to displayableBodyText.
|
|
|
|
|
@property (nonatomic, nullable) DisplayableText *displayableText;
|
|
|
|
|
@property (nonatomic, nullable) DisplayableText *displayableBodyText;
|
|
|
|
|
@property (nonatomic, nullable) TSAttachmentStream *attachmentStream;
|
|
|
|
|
@property (nonatomic, nullable) TSAttachmentPointer *attachmentPointer;
|
|
|
|
|
@property (nonatomic) CGSize mediaSize;
|
|
|
|
|
// TODO: Remove in favor of displayableBodyText nil test.
|
|
|
|
|
//@property (nonatomic) BOOL hasText;
|
|
|
|
|
//@property (nonatomic) BOOL hasBodyText;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
@ -97,7 +97,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
|
|
|
|
|
self.hasViewState = NO;
|
|
|
|
|
self.messageCellType = OWSMessageCellType_Unknown;
|
|
|
|
|
self.displayableText = nil;
|
|
|
|
|
self.displayableBodyText = nil;
|
|
|
|
|
self.attachmentStream = nil;
|
|
|
|
|
self.attachmentPointer = nil;
|
|
|
|
|
self.mediaSize = CGSizeZero;
|
|
|
|
@ -107,9 +107,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
[self ensureViewState:transaction];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)hasText
|
|
|
|
|
- (BOOL)hasBodyText
|
|
|
|
|
{
|
|
|
|
|
return _displayableText != nil;
|
|
|
|
|
return _displayableBodyText != nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setShouldShowDate:(BOOL)shouldShowDate
|
|
|
|
@ -271,7 +271,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
|
|
|
|
|
// TODO: Now that we're caching the displayable text on the view items,
|
|
|
|
|
// I don't think we need this cache any more.
|
|
|
|
|
- (NSCache *)displayableTextCache
|
|
|
|
|
- (NSCache *)displayableBodyTextCache
|
|
|
|
|
{
|
|
|
|
|
static NSCache *cache = nil;
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
@ -283,44 +283,45 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
return cache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (DisplayableText *)displayableTextForText:(NSString *)text interactionId:(NSString *)interactionId
|
|
|
|
|
- (DisplayableText *)displayableBodyTextForText:(NSString *)text interactionId:(NSString *)interactionId
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(text);
|
|
|
|
|
OWSAssert(interactionId.length > 0);
|
|
|
|
|
|
|
|
|
|
return [self displayableTextForInteractionId:interactionId
|
|
|
|
|
textBlock:^{
|
|
|
|
|
return text;
|
|
|
|
|
}];
|
|
|
|
|
return [self displayableBodyTextForInteractionId:interactionId
|
|
|
|
|
textBlock:^{
|
|
|
|
|
return text;
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (DisplayableText *)displayableTextForOversizeTextAttachment:(TSAttachmentStream *)attachmentStream
|
|
|
|
|
interactionId:(NSString *)interactionId
|
|
|
|
|
- (DisplayableText *)displayableBodyTextForOversizeTextAttachment:(TSAttachmentStream *)attachmentStream
|
|
|
|
|
interactionId:(NSString *)interactionId
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(attachmentStream);
|
|
|
|
|
OWSAssert(interactionId.length > 0);
|
|
|
|
|
|
|
|
|
|
return [self displayableTextForInteractionId:interactionId
|
|
|
|
|
textBlock:^{
|
|
|
|
|
NSData *textData = [NSData dataWithContentsOfURL:attachmentStream.mediaURL];
|
|
|
|
|
NSString *text =
|
|
|
|
|
[[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding];
|
|
|
|
|
return text;
|
|
|
|
|
}];
|
|
|
|
|
return
|
|
|
|
|
[self displayableBodyTextForInteractionId:interactionId
|
|
|
|
|
textBlock:^{
|
|
|
|
|
NSData *textData = [NSData dataWithContentsOfURL:attachmentStream.mediaURL];
|
|
|
|
|
NSString *text =
|
|
|
|
|
[[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding];
|
|
|
|
|
return text;
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (DisplayableText *)displayableTextForInteractionId:(NSString *)interactionId
|
|
|
|
|
textBlock:(NSString * (^_Nonnull)(void))textBlock
|
|
|
|
|
- (DisplayableText *)displayableBodyTextForInteractionId:(NSString *)interactionId
|
|
|
|
|
textBlock:(NSString * (^_Nonnull)(void))textBlock
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(interactionId.length > 0);
|
|
|
|
|
|
|
|
|
|
DisplayableText *_Nullable displayableText = [[self displayableTextCache] objectForKey:interactionId];
|
|
|
|
|
if (!displayableText) {
|
|
|
|
|
DisplayableText *_Nullable displayableBodyText = [[self displayableBodyTextCache] objectForKey:interactionId];
|
|
|
|
|
if (!displayableBodyText) {
|
|
|
|
|
NSString *text = textBlock();
|
|
|
|
|
displayableText = [DisplayableText displayableText:text];
|
|
|
|
|
[[self displayableTextCache] setObject:displayableText forKey:interactionId];
|
|
|
|
|
displayableBodyText = [DisplayableText displayableText:text];
|
|
|
|
|
[[self displayableBodyTextCache] setObject:displayableBodyText forKey:interactionId];
|
|
|
|
|
}
|
|
|
|
|
return displayableText;
|
|
|
|
|
return displayableBodyText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable TSAttachment *)firstAttachmentIfAnyOfMessage:(TSMessage *)message
|
|
|
|
@ -360,9 +361,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
|
|
|
|
|
if ([attachment.contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) {
|
|
|
|
|
self.messageCellType = OWSMessageCellType_OversizeTextMessage;
|
|
|
|
|
self.displayableText = [self displayableTextForOversizeTextAttachment:self.attachmentStream
|
|
|
|
|
interactionId:message.uniqueId];
|
|
|
|
|
// self.hasText = YES;
|
|
|
|
|
self.displayableBodyText = [self displayableBodyTextForOversizeTextAttachment:self.attachmentStream
|
|
|
|
|
interactionId:message.uniqueId];
|
|
|
|
|
// self.hasBodyText = YES;
|
|
|
|
|
} else if ([self.attachmentStream isAnimated] || [self.attachmentStream isImage] ||
|
|
|
|
|
[self.attachmentStream isVideo]) {
|
|
|
|
|
if ([self.attachmentStream isAnimated]) {
|
|
|
|
@ -407,19 +408,19 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
|
|
|
|
|
// Ignore message body for oversize text attachments.
|
|
|
|
|
if (message.body.length > 0) {
|
|
|
|
|
if (self.hasText) {
|
|
|
|
|
if (self.hasBodyText) {
|
|
|
|
|
OWSFail(@"%@ oversize text message has unexpected caption.", self.logTag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// self.hasText = YES;
|
|
|
|
|
// self.hasBodyText = YES;
|
|
|
|
|
// If we haven't already assigned an attachment type at this point, message.body isn't a caption,
|
|
|
|
|
// it's a stand-alone text message.
|
|
|
|
|
if (self.messageCellType == OWSMessageCellType_Unknown) {
|
|
|
|
|
OWSAssert(message.attachmentIds.count == 0);
|
|
|
|
|
self.messageCellType = OWSMessageCellType_TextMessage;
|
|
|
|
|
}
|
|
|
|
|
self.displayableText = [self displayableTextForText:message.body interactionId:message.uniqueId];
|
|
|
|
|
OWSAssert(self.displayableText);
|
|
|
|
|
self.displayableBodyText = [self displayableBodyTextForText:message.body interactionId:message.uniqueId];
|
|
|
|
|
OWSAssert(self.displayableBodyText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self.messageCellType == OWSMessageCellType_Unknown) {
|
|
|
|
@ -427,8 +428,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
// are rendered like empty text messages, but without any interactivity.
|
|
|
|
|
DDLogWarn(@"%@ Treating unknown message as empty text message: %@", self.logTag, message.description);
|
|
|
|
|
self.messageCellType = OWSMessageCellType_TextMessage;
|
|
|
|
|
// self.hasText = YES;
|
|
|
|
|
self.displayableText = [[DisplayableText alloc] initWithFullText:@"" displayText:@"" isTextTruncated:NO];
|
|
|
|
|
// self.hasBodyText = YES;
|
|
|
|
|
self.displayableBodyText = [[DisplayableText alloc] initWithFullText:@"" displayText:@"" isTextTruncated:NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -439,16 +440,16 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
return _messageCellType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable DisplayableText *)displayableText
|
|
|
|
|
- (nullable DisplayableText *)displayableBodyText
|
|
|
|
|
{
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
OWSAssert(self.hasViewState);
|
|
|
|
|
|
|
|
|
|
OWSAssert(_displayableText);
|
|
|
|
|
OWSAssert(_displayableText.displayText);
|
|
|
|
|
OWSAssert(_displayableText.fullText);
|
|
|
|
|
OWSAssert(_displayableBodyText);
|
|
|
|
|
OWSAssert(_displayableBodyText.displayText);
|
|
|
|
|
OWSAssert(_displayableBodyText.fullText);
|
|
|
|
|
|
|
|
|
|
return _displayableText;
|
|
|
|
|
return _displayableBodyText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable TSAttachmentStream *)attachmentStream
|
|
|
|
@ -551,13 +552,13 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
- (BOOL)canPerformAction:(SEL)action
|
|
|
|
|
{
|
|
|
|
|
if (action == self.copyTextActionSelector) {
|
|
|
|
|
return [self hasTextActionContent];
|
|
|
|
|
return [self hasBodyTextActionContent];
|
|
|
|
|
} else if (action == self.copyMediaActionSelector) {
|
|
|
|
|
return [self hasMediaActionContent];
|
|
|
|
|
} else if (action == self.saveMediaActionSelector) {
|
|
|
|
|
return [self canSaveMedia];
|
|
|
|
|
} else if (action == self.shareTextActionSelector) {
|
|
|
|
|
return [self hasTextActionContent];
|
|
|
|
|
return [self hasBodyTextActionContent];
|
|
|
|
|
} else if (action == self.shareMediaActionSelector) {
|
|
|
|
|
return [self hasMediaActionContent];
|
|
|
|
|
} else if (action == self.deleteActionSelector) {
|
|
|
|
@ -579,8 +580,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
case OWSMessageCellType_Audio:
|
|
|
|
|
case OWSMessageCellType_Video:
|
|
|
|
|
case OWSMessageCellType_GenericAttachment: {
|
|
|
|
|
OWSAssert(self.displayableText);
|
|
|
|
|
[UIPasteboard.generalPasteboard setString:self.displayableText.fullText];
|
|
|
|
|
OWSAssert(self.displayableBodyText);
|
|
|
|
|
[UIPasteboard.generalPasteboard setString:self.displayableBodyText.fullText];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case OWSMessageCellType_DownloadingAttachment: {
|
|
|
|
@ -638,8 +639,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
case OWSMessageCellType_Audio:
|
|
|
|
|
case OWSMessageCellType_Video:
|
|
|
|
|
case OWSMessageCellType_GenericAttachment: {
|
|
|
|
|
OWSAssert(self.displayableText);
|
|
|
|
|
[AttachmentSharing showShareUIForText:self.displayableText.fullText];
|
|
|
|
|
OWSAssert(self.displayableBodyText);
|
|
|
|
|
[AttachmentSharing showShareUIForText:self.displayableBodyText.fullText];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case OWSMessageCellType_DownloadingAttachment: {
|
|
|
|
@ -746,9 +747,9 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|
|
|
|
[self.interaction remove];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)hasTextActionContent
|
|
|
|
|
- (BOOL)hasBodyTextActionContent
|
|
|
|
|
{
|
|
|
|
|
return self.hasText && self.displayableText.fullText.length > 0;
|
|
|
|
|
return self.hasBodyText && self.displayableBodyText.fullText.length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)hasMediaActionContent
|
|
|
|
|