Plumb through messageAlbumId so an Attachment knows what album (if any) it
belongs to.
This commit is contained in:
parent
6b796579dd
commit
27cb91e9c8
|
@ -89,6 +89,7 @@ class ConversationConfigurationSyncOperation: OWSOperation {
|
|||
contentType: OWSMimeTypeApplicationOctetStream,
|
||||
sourceFilename: nil,
|
||||
caption: nil,
|
||||
albumMessageId: nil,
|
||||
isTemporaryAttachment: true)
|
||||
self.reportSuccess()
|
||||
}
|
||||
|
|
|
@ -3760,6 +3760,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
|||
contentType:@"audio/mp3"
|
||||
sourceFilename:@"test.mp3"
|
||||
caption:nil
|
||||
albumMessageId:nil
|
||||
attachmentType:TSAttachmentTypeDefault];
|
||||
pointer.state = TSAttachmentPointerStateFailed;
|
||||
[pointer saveWithTransaction:transaction];
|
||||
|
@ -3787,7 +3788,8 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
|||
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3"
|
||||
byteCount:filesize
|
||||
sourceFilename:filename
|
||||
caption:nil];
|
||||
caption:nil
|
||||
albumMessageId:nil];
|
||||
|
||||
NSError *error;
|
||||
BOOL success = [attachmentStream writeData:[self createRandomNSDataOfSize:filesize] error:&error];
|
||||
|
@ -4619,7 +4621,8 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
|||
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:fakeAssetLoader.mimeType
|
||||
byteCount:nominalDataLength
|
||||
sourceFilename:filename
|
||||
caption:nil];
|
||||
caption:nil
|
||||
albumMessageId:nil];
|
||||
NSError *error;
|
||||
BOOL success = [attachmentStream writeData:dataSource.data error:&error];
|
||||
OWSAssertDebug(success && !error);
|
||||
|
@ -4635,6 +4638,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
|||
contentType:fakeAssetLoader.mimeType
|
||||
sourceFilename:fakeAssetLoader.filename
|
||||
caption:nil
|
||||
albumMessageId:nil
|
||||
attachmentType:TSAttachmentTypeDefault];
|
||||
attachmentPointer.state = TSAttachmentPointerStateFailed;
|
||||
[attachmentPointer saveWithTransaction:transaction];
|
||||
|
|
|
@ -119,6 +119,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
contentType:OWSMimeTypeApplicationOctetStream
|
||||
sourceFilename:nil
|
||||
caption:nil
|
||||
albumMessageId:nil
|
||||
isTemporaryAttachment:YES];
|
||||
}
|
||||
|
||||
|
|
|
@ -240,8 +240,13 @@ public class SignalAttachment: NSObject {
|
|||
}
|
||||
|
||||
@objc
|
||||
public var outgoingAttachmentInfo: OutgoingAttachmentInfo {
|
||||
return OutgoingAttachmentInfo(dataSource: dataSource, contentType: mimeType, sourceFilename: filenameOrDefault, caption: captionText)
|
||||
public func buildOutgoingAttachmentInfo(message: TSMessage) -> OutgoingAttachmentInfo {
|
||||
OWSAssertDebug(message.uniqueId)
|
||||
return OutgoingAttachmentInfo(dataSource: dataSource,
|
||||
contentType: mimeType,
|
||||
sourceFilename: filenameOrDefault,
|
||||
caption: captionText,
|
||||
albumMessageId: message.uniqueId)
|
||||
}
|
||||
|
||||
@objc
|
||||
|
|
|
@ -133,7 +133,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
NSMutableArray<OWSOutgoingAttachmentInfo *> *attachmentInfos = [NSMutableArray new];
|
||||
for (SignalAttachment *attachment in attachments) {
|
||||
[attachmentInfos addObject:attachment.outgoingAttachmentInfo];
|
||||
OWSOutgoingAttachmentInfo *attachmentInfo = [attachment buildOutgoingAttachmentInfoWithMessage:message];
|
||||
[attachmentInfos addObject:attachmentInfo];
|
||||
}
|
||||
[self.messageSenderJobQueue addMediaMessage:message attachmentInfos:attachmentInfos isTemporaryAttachment:NO];
|
||||
|
||||
|
|
|
@ -37,8 +37,12 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) {
|
|||
// not the filename on disk.
|
||||
@property (nonatomic, readonly, nullable) NSString *sourceFilename;
|
||||
|
||||
// Currently only applies to albums.
|
||||
#pragma mark - Media Album
|
||||
|
||||
@property (nonatomic, readonly, nullable) NSString *caption;
|
||||
@property (nonatomic, readonly, nullable) NSString *albumMessageId;
|
||||
|
||||
#pragma mark -
|
||||
|
||||
// This constructor is used for new instances of TSAttachmentPointer,
|
||||
// i.e. undownloaded incoming attachments.
|
||||
|
@ -47,14 +51,16 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) {
|
|||
byteCount:(UInt32)byteCount
|
||||
contentType:(NSString *)contentType
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption;
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId;
|
||||
|
||||
// This constructor is used for new instances of TSAttachmentStream
|
||||
// that represent new, un-uploaded outgoing attachments.
|
||||
- (instancetype)initWithContentType:(NSString *)contentType
|
||||
byteCount:(UInt32)byteCount
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption;
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId;
|
||||
|
||||
// This constructor is used for new instances of TSAttachmentStream
|
||||
// that represent downloaded incoming attachments.
|
||||
|
|
|
@ -19,8 +19,6 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
|
|||
|
||||
@property (nonatomic) NSString *contentType;
|
||||
|
||||
@property (nonatomic, nullable) NSString *caption;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TSAttachment
|
||||
|
@ -33,6 +31,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
|
|||
contentType:(NSString *)contentType
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId
|
||||
{
|
||||
OWSAssertDebug(serverId > 0);
|
||||
OWSAssertDebug(encryptionKey.length > 0);
|
||||
|
@ -70,6 +69,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
|
|||
byteCount:(UInt32)byteCount
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId
|
||||
{
|
||||
if (contentType.length < 1) {
|
||||
OWSLogWarn(@"outgoing attachment has invalid content type");
|
||||
|
@ -88,6 +88,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
|
|||
_byteCount = byteCount;
|
||||
_sourceFilename = sourceFilename;
|
||||
_caption = caption;
|
||||
_albumMessageId = albumMessageId;
|
||||
|
||||
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
|
||||
|
||||
|
@ -229,19 +230,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
|
|||
|
||||
- (BOOL)isVisualMedia
|
||||
{
|
||||
if (self.isImage) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (self.isVideo) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (self.isAnimated) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
return [MIMETypeUtil isVisualMedia:self.contentType];
|
||||
}
|
||||
|
||||
- (nullable NSString *)sourceFilename
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) {
|
|||
contentType:(NSString *)contentType
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId
|
||||
attachmentType:(TSAttachmentType)attachmentType NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
+ (nullable TSAttachmentPointer *)attachmentPointerFromProto:(SSKProtoAttachmentPointer *)attachmentProto;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
#import "TSAttachmentPointer.h"
|
||||
#import <SignalServiceKit/MimeTypeUtil.h>
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
@ -33,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
contentType:(NSString *)contentType
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId
|
||||
attachmentType:(TSAttachmentType)attachmentType
|
||||
{
|
||||
self = [super initWithServerId:serverId
|
||||
|
@ -40,7 +42,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
byteCount:byteCount
|
||||
contentType:contentType
|
||||
sourceFilename:sourceFilename
|
||||
caption:caption];
|
||||
caption:caption
|
||||
albumMessageId:albumMessageId];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
@ -54,6 +57,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
|
||||
+ (nullable TSAttachmentPointer *)attachmentPointerFromProto:(SSKProtoAttachmentPointer *)attachmentProto
|
||||
message:(TSMessage *)message
|
||||
{
|
||||
if (attachmentProto.id < 1) {
|
||||
OWSFailDebug(@"Invalid attachment id.");
|
||||
|
@ -82,6 +86,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
if (attachmentProto.hasCaption) {
|
||||
caption = attachmentProto.caption;
|
||||
}
|
||||
NSString *_Nullable albumMessageId;
|
||||
if ([MIMETypeUtil isVisualMedia:attachmentProto.contentType]) {
|
||||
OWSAssertDebug(message.uniqueId);
|
||||
albumMessageId = message.uniqueId;
|
||||
}
|
||||
|
||||
TSAttachmentPointer *pointer = [[TSAttachmentPointer alloc] initWithServerId:attachmentProto.id
|
||||
key:attachmentProto.key
|
||||
digest:digest
|
||||
|
@ -89,6 +99,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
contentType:attachmentProto.contentType
|
||||
sourceFilename:attachmentProto.fileName
|
||||
caption:caption
|
||||
albumMessageId:albumMessageId
|
||||
attachmentType:attachmentType];
|
||||
return pointer;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@ typedef void (^OWSThumbnailFailure)(void);
|
|||
- (instancetype)initWithContentType:(NSString *)contentType
|
||||
byteCount:(UInt32)byteCount
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption NS_DESIGNATED_INITIALIZER;
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (instancetype)initWithPointer:(TSAttachmentPointer *)pointer NS_DESIGNATED_INITIALIZER;
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
|
|
|
@ -55,8 +55,13 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
|
|||
byteCount:(UInt32)byteCount
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId
|
||||
{
|
||||
self = [super initWithContentType:contentType byteCount:byteCount sourceFilename:sourceFilename caption:caption];
|
||||
self = [super initWithContentType:contentType
|
||||
byteCount:byteCount
|
||||
sourceFilename:sourceFilename
|
||||
caption:caption
|
||||
albumMessageId:albumMessageId];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
@ -856,7 +861,8 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
|
|||
[[TSAttachmentStream alloc] initWithContentType:OWSMimeTypeImageJpeg
|
||||
byteCount:(uint32_t)thumbnailData.length
|
||||
sourceFilename:thumbnailName
|
||||
caption:nil];
|
||||
caption:nil
|
||||
albumMessageId:nil];
|
||||
|
||||
NSError *error;
|
||||
BOOL success = [thumbnailAttachment writeData:thumbnailData error:&error];
|
||||
|
|
|
@ -496,7 +496,8 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value)
|
|||
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:OWSMimeTypeImageJpeg
|
||||
byteCount:(UInt32)imageData.length
|
||||
sourceFilename:nil
|
||||
caption:nil];
|
||||
caption:nil
|
||||
albumMessageId:nil];
|
||||
|
||||
NSError *error;
|
||||
BOOL success = [attachmentStream writeData:imageData error:&error];
|
||||
|
|
|
@ -904,6 +904,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
contentType:OWSMimeTypeApplicationOctetStream
|
||||
sourceFilename:nil
|
||||
caption:nil
|
||||
albumMessageId:nil
|
||||
isTemporaryAttachment:YES];
|
||||
} else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeBlocked) {
|
||||
OWSLogInfo(@"Received request for block list");
|
||||
|
@ -1126,6 +1127,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
contentType:OWSMimeTypeImagePng
|
||||
sourceFilename:nil
|
||||
caption:nil
|
||||
albumMessageId:nil
|
||||
isTemporaryAttachment:YES];
|
||||
|
||||
} else {
|
||||
|
|
|
@ -40,13 +40,15 @@ NS_SWIFT_NAME(OutgoingAttachmentInfo)
|
|||
@property (nonatomic, readonly) NSString *contentType;
|
||||
@property (nonatomic, readonly, nullable) NSString *sourceFilename;
|
||||
@property (nonatomic, readonly, nullable) NSString *caption;
|
||||
@property (nonatomic, readonly, nullable) NSString *albumMessageId;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
- (instancetype)initWithDataSource:(DataSource *)dataSource
|
||||
contentType:(NSString *)contentType
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
caption:(nullable NSString *)caption NS_DESIGNATED_INITIALIZER;
|
||||
caption:(nullable NSString *)caption
|
||||
albumMessageId:(nullable NSString *)albumMessageId NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1808,7 +1808,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
[[TSAttachmentStream alloc] initWithContentType:attachmentInfo.contentType
|
||||
byteCount:(UInt32)attachmentInfo.dataSource.dataLength
|
||||
sourceFilename:attachmentInfo.sourceFilename
|
||||
caption:attachmentInfo.caption];
|
||||
caption:attachmentInfo.caption
|
||||
albumMessageId:attachmentInfo.albumMessageId];
|
||||
if (outgoingMessage.isVoiceMessage) {
|
||||
attachmentStream.attachmentType = TSAttachmentTypeVoiceMessage;
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
|
|||
self.add(message: message, removeMessageAfterSending: false, transaction: transaction)
|
||||
}
|
||||
|
||||
@objc(addMediaMessage:dataSource:contentType:sourceFilename:caption:isTemporaryAttachment:)
|
||||
public func add(mediaMessage: TSOutgoingMessage, dataSource: DataSource, contentType: String, sourceFilename: String?, caption: String?, isTemporaryAttachment: Bool) {
|
||||
let attachmentInfo = OutgoingAttachmentInfo(dataSource: dataSource, contentType: contentType, sourceFilename: sourceFilename, caption: caption)
|
||||
@objc(addMediaMessage:dataSource:contentType:sourceFilename:caption:albumMessageId:isTemporaryAttachment:)
|
||||
public func add(mediaMessage: TSOutgoingMessage, dataSource: DataSource, contentType: String, sourceFilename: String?, caption: String?, albumMessageId: String?, isTemporaryAttachment: Bool) {
|
||||
let attachmentInfo = OutgoingAttachmentInfo(dataSource: dataSource, contentType: contentType, sourceFilename: sourceFilename, caption: caption, albumMessageId: albumMessageId)
|
||||
add(mediaMessage: mediaMessage, attachmentInfos: [attachmentInfo], isTemporaryAttachment: isTemporaryAttachment)
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ extern NSString *const kSyncMessageFileExtension;
|
|||
+ (BOOL)isImage:(NSString *)contentType;
|
||||
+ (BOOL)isVideo:(NSString *)contentType;
|
||||
+ (BOOL)isAudio:(NSString *)contentType;
|
||||
+ (BOOL)isVisualMedia:(NSString *)contentType;
|
||||
|
||||
// filename is optional and should not be trusted.
|
||||
+ (nullable NSString *)filePathForAttachment:(NSString *)uniqueId
|
||||
|
|
|
@ -279,6 +279,23 @@ NSString *const kSyncMessageFileExtension = @"bin";
|
|||
return [MIMETypeUtil isSupportedAudioMIMEType:contentType];
|
||||
}
|
||||
|
||||
+ (BOOL)isVisualMedia:(NSString *)contentType
|
||||
{
|
||||
if ([self isImage:contentType]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([self isVideo:contentType]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([self isAnimated:contentType]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (nullable NSString *)filePathForAttachment:(NSString *)uniqueId
|
||||
ofMIMEType:(NSString *)contentType
|
||||
sourceFilename:(nullable NSString *)sourceFilename
|
||||
|
|
Loading…
Reference in New Issue