Improve support for arbitrary attachments.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-03-29 17:54:11 -04:00
parent 306895ea6d
commit d85dfb8a4e
6 changed files with 45 additions and 37 deletions

View file

@ -85,11 +85,6 @@ NS_ASSUME_NONNULL_BEGIN
return [UIFont ows_regularFontWithSize:11.f];
}
- (UIFont *)fileTypeLabelFont
{
return [UIFont ows_mediumFontWithSize:16.f];
}
- (UIView *)mediaView
{
if (_cachedMediaView == nil) {
@ -132,10 +127,11 @@ NS_ASSUME_NONNULL_BEGIN
fileTypeLabel.text = fileExtension.uppercaseString;
fileTypeLabel.textColor = textColor;
fileTypeLabel.lineBreakMode = NSLineBreakByTruncatingTail;
fileTypeLabel.font = [self fileTypeLabelFont];
fileTypeLabel.font = [UIFont ows_mediumFontWithSize:20.f];
fileTypeLabel.adjustsFontSizeToFitWidth = YES;
CGRect fileTypeLabelFrame = CGRectZero;
fileTypeLabelFrame.size = [fileTypeLabel sizeThatFits:CGSizeZero];
fileTypeLabelFrame.size.width = floor(MIN(self.iconSize * 0.5f, fileTypeLabelFrame.size.width));
fileTypeLabelFrame.size.width = ceil(MIN(self.iconSize * 0.45f, fileTypeLabelFrame.size.width));
// Center on icon.
fileTypeLabelFrame.origin.x
= round(iconFrame.origin.x + (iconFrame.size.width - fileTypeLabelFrame.size.width) * 0.5f);

View file

@ -10,4 +10,6 @@
+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream;
+ (void)showShareUIForURL:(NSURL *)url;
@end

View file

@ -10,29 +10,18 @@
+ (void)showShareUIForAttachment:(TSAttachmentStream *)stream {
OWSAssert(stream);
NSString *filePath = stream.filePath;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSError *error;
NSData *data = [NSData dataWithContentsOfFile:filePath options:0 error:&error];
if (!data || error) {
DDLogError(@"%@ %s could not read data from attachment: %@.",
self.tag,
__PRETTY_FUNCTION__,
error);
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
[AttachmentSharing showShareUIForData:data];
});
dispatch_async(dispatch_get_main_queue(), ^{
[AttachmentSharing showShareUIForURL:stream.mediaURL];
});
}
+ (void)showShareUIForData:(NSData *)data {
+ (void)showShareUIForURL:(NSURL *)url {
AssertIsOnMainThread();
OWSAssert(data);
OWSAssert(url);
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[data, ]
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[
url,
]
applicationActivities:@[
]];

View file

@ -247,9 +247,15 @@ NSString * const kDebugUITableCellIdentifier = @"kDebugUITableCellIdentifier";
actionBlock:^{
[DebugUITableViewController sendOversizeTextMessage:thread];
}],
[OWSTableItem actionWithTitle:@"Send unknown/mimetype"
[OWSTableItem actionWithTitle:@"Send unknown mimetype"
actionBlock:^{
[DebugUITableViewController sendUnknownMimetypeAttachment:thread];
[DebugUITableViewController sendRandomAttachment:thread
uti:SignalAttachment.kUnknownTestAttachmentUTI];
}],
[OWSTableItem actionWithTitle:@"Send pdf"
actionBlock:^{
[DebugUITableViewController sendRandomAttachment:thread
uti:(NSString *) kUTTypePDF];
}],
]]];
@ -275,7 +281,11 @@ NSString * const kDebugUITableCellIdentifier = @"kDebugUITableCellIdentifier";
+ (void)sendOversizeTextMessage:(TSThread *)thread {
OWSMessageSender *messageSender = [Environment getCurrent].messageSender;
NSString *message = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse consequat, ligula et tincidunt mattis, nisl risus ultricies justo, vitae dictum augue risus vel ante. Suspendisse convallis bibendum lectus. Etiam molestie nisi ac orci sodales sollicitudin vitae eu quam. Morbi lacinia scelerisque risus. Quisque sagittis mauris enim, ac vestibulum dui commodo quis. Nullam at commodo nisl, ut pulvinar dui. Nunc tempus volutpat sagittis. Vestibulum eget maximus sem, sit amet tristique ex posuere.";
NSMutableString *message = [NSMutableString new];
for (int i=0; i < 32; i++) {
[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 sodales. Aenean ut velit maximus, posuere sem a, accumsan nunc. Donec ullamcorper turpis lorem. Quisque dignissim purus eu placerat ultricies. Proin at urna eget mi semper congue. Aenean non elementum ex. Praesent pharetra quam at sem vestibulum, vestibulum ornare dolor elementum. Vestibulum massa tortor, scelerisque sit amet pulvinar a, rhoncus vitae nisl. Sed mi nunc, tempus at varius in, malesuada vitae dui. Vivamus efficitur pulvinar erat vitae congue. Proin vehicula turpis non felis congue facilisis. Nullam aliquet dapibus ligula ac mollis. Etiam sit amet posuere lorem, in rhoncus nisi."];
}
SignalAttachment *attachment = [SignalAttachment oversizeTextAttachmentWithText:message];
[ThreadUtil sendMessageWithAttachment:attachment
inThread:thread
@ -295,10 +305,11 @@ NSString * const kDebugUITableCellIdentifier = @"kDebugUITableCellIdentifier";
return data;
}
+ (void)sendUnknownMimetypeAttachment:(TSThread *)thread {
+ (void)sendRandomAttachment:(TSThread *)thread
uti:(NSString *)uti {
OWSMessageSender *messageSender = [Environment getCurrent].messageSender;
SignalAttachment *attachment = [SignalAttachment genericAttachmentWithData:[self createRandomNSDataOfSize:256]
dataUTI:SignalAttachment.kUnknownTestAttachmentUTI];
dataUTI:uti];
[ThreadUtil sendMessageWithAttachment:attachment
inThread:thread
messageSender:messageSender];

View file

@ -3,7 +3,7 @@
//
#import "AppDelegate.h"
#import "AttachmentSharing.h"
#import "Environment.h"
#import "FingerprintViewController.h"
#import "FullImageViewController.h"
@ -29,6 +29,7 @@
#import "TSContentAdapters.h"
#import "TSDatabaseView.h"
#import "TSErrorMessage.h"
#import "TSGenericAttachmentAdapter.h"
#import "TSGroupThread.h"
#import "TSIncomingMessage.h"
#import "TSInfoMessage.h"
@ -1554,6 +1555,21 @@ typedef enum : NSUInteger {
DDLogDebug(@"Unhandled bubble touch for interaction: %@.", interaction);
break;
}
if (messageItem.messageType == TSOutgoingMessageAdapter ||
messageItem.messageType == TSIncomingMessageAdapter) {
TSMessage *message = (TSMessage *)interaction;
if ([message hasAttachments]) {
NSString *attachmentID = message.attachmentIds[0];
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentID];
if ([attachment isKindOfClass:[TSAttachmentStream class]]) {
TSAttachmentStream *stream = (TSAttachmentStream *)attachment;
if ([[messageItem media] isKindOfClass:[TSGenericAttachmentAdapter class]]) {
[AttachmentSharing showShareUIForAttachment:stream];
}
}
}
}
}
- (void)handleWarningTap:(TSInteraction *)interaction

View file

@ -97,12 +97,6 @@
/* No comment provided by engineer. */
"ATTACHMENT_QUEUED" = "New attachment queued for retrieval.";
/* A message indicating that an attachment of unknown type was received. */
"ATTACHMENT_UNKNOWN_TYPE" = "Unknown attachment received";
/* No comment provided by engineer. */
"AUDIO_PERMISSION_MESSAGE" = "Signal requires access to your microphone to work properly. You can grant this permission in the Settings app >> Privacy >> Microphone >> Signal";
/* Accessibilty label for placing call button */
"CALL_LABEL" = "Call";