Improve asserts and logging in attachment adapters.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-05-22 18:12:01 -04:00
parent b1f7cf0d62
commit 964e6f1adf
4 changed files with 44 additions and 6 deletions

View file

@ -266,6 +266,11 @@ NS_ASSUME_NONNULL_BEGIN
NSString *utiType = [MIMETypeUtil utiTypeForMIMEType:self.attachment.contentType];
OWSAssert(utiType.length > 0);
NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL];
if (!data) {
OWSAssert(data);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return;
}
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
} else {
// Shouldn't get here, as only supported actions should be exposed via canPerformEditingAction
@ -290,6 +295,18 @@ NS_ASSUME_NONNULL_BEGIN
}
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

View file

@ -57,8 +57,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) uint64_t expiresAtSeconds;
@property (nonatomic) uint32_t expiresInSeconds;
@property (nonatomic, copy) NSDate *messageDate;
@property (nonatomic, retain) NSString *messageBody;
@property (nonatomic) NSDate *messageDate;
@property (nonatomic) NSString *messageBody;
@property (nonatomic) NSString *interactionUniqueId;

View file

@ -400,6 +400,11 @@ NS_ASSUME_NONNULL_BEGIN
utiType = (NSString *)kUTTypeVideo;
}
NSData *data = [NSData dataWithContentsOfURL:self.fileURL];
if (!data) {
OWSAssert(data);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return;
}
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
return;
} else if (action == NSSelectorFromString(@"save:")) {
@ -418,7 +423,11 @@ NS_ASSUME_NONNULL_BEGIN
}
NSData *data = [NSData dataWithContentsOfURL:self.fileURL];
OWSAssert(data);
if (!data) {
OWSAssert(data);
DDLogError(@"%@ Could not load data: %@", [self tag], [self.attachment mediaURL]);
return;
}
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
}
} else {
@ -446,6 +455,18 @@ NS_ASSUME_NONNULL_BEGIN
}
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

View file

@ -758,11 +758,11 @@ typedef enum : NSUInteger {
[[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ] view:TSMessageDatabaseViewExtensionName];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.messageMappings updateWithTransaction:transaction];
self.page = 0;
[self updateRangeOptionsForPage:self.page];
[self.collectionView reloadData];
}];
self.page = 0;
[self updateRangeOptionsForPage:self.page];
[self updateLoadEarlierVisible];
[self.collectionView reloadData];
}
- (BOOL)userLeftGroup