Add support for album captions to models.

pull/1/head
Matthew Chen 7 years ago
parent 3816cb4bf4
commit 57de089118

@ -88,6 +88,7 @@ class ConversationConfigurationSyncOperation: OWSOperation {
dataSource: attachmentDataSource,
contentType: OWSMimeTypeApplicationOctetStream,
sourceFilename: nil,
caption: nil,
isTemporaryAttachment: true)
self.reportSuccess()
}

@ -48,6 +48,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
// This property will be non-zero if the attachment is valid.
@property (nonatomic, readonly) CGSize mediaSize;
@property (nonatomic, readonly, nullable) NSString *caption;
@end
#pragma mark -

@ -3759,6 +3759,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
byteCount:filesize
contentType:@"audio/mp3"
sourceFilename:@"test.mp3"
caption:nil
attachmentType:TSAttachmentTypeDefault];
pointer.state = TSAttachmentPointerStateFailed;
[pointer saveWithTransaction:transaction];
@ -3785,7 +3786,8 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3"
byteCount:filesize
sourceFilename:filename];
sourceFilename:filename
caption:nil];
NSError *error;
BOOL success = [attachmentStream writeData:[self createRandomNSDataOfSize:filesize] error:&error];
@ -4616,7 +4618,8 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
UInt32 nominalDataLength = (UInt32)MAX((NSUInteger)1, dataSource.dataLength);
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:fakeAssetLoader.mimeType
byteCount:nominalDataLength
sourceFilename:filename];
sourceFilename:filename
caption:nil];
NSError *error;
BOOL success = [attachmentStream writeData:dataSource.data error:&error];
OWSAssertDebug(success && !error);
@ -4631,6 +4634,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
byteCount:filesize
contentType:fakeAssetLoader.mimeType
sourceFilename:fakeAssetLoader.filename
caption:nil
attachmentType:TSAttachmentTypeDefault];
attachmentPointer.state = TSAttachmentPointerStateFailed;
[attachmentPointer saveWithTransaction:transaction];

@ -118,6 +118,7 @@ NS_ASSUME_NONNULL_BEGIN
dataSource:dataSource
contentType:OWSMimeTypeApplicationOctetStream
sourceFilename:nil
caption:nil
isTemporaryAttachment:YES];
}

@ -241,7 +241,7 @@ public class SignalAttachment: NSObject {
@objc
public var outgoingAttachmentInfo: OutgoingAttachmentInfo {
return OutgoingAttachmentInfo(dataSource: dataSource, contentType: mimeType, sourceFilename: filenameOrDefault)
return OutgoingAttachmentInfo(dataSource: dataSource, contentType: mimeType, sourceFilename: filenameOrDefault, caption: captionText)
}
@objc

@ -37,19 +37,24 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) {
// not the filename on disk.
@property (nonatomic, readonly, nullable) NSString *sourceFilename;
// Currently only applies to albums.
@property (nonatomic, readonly, nullable) NSString *caption;
// This constructor is used for new instances of TSAttachmentPointer,
// i.e. undownloaded incoming attachments.
- (instancetype)initWithServerId:(UInt64)serverId
encryptionKey:(NSData *)encryptionKey
byteCount:(UInt32)byteCount
contentType:(NSString *)contentType
sourceFilename:(nullable NSString *)sourceFilename;
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption;
// 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;
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption;
// This constructor is used for new instances of TSAttachmentStream
// that represent downloaded incoming attachments.

@ -19,6 +19,8 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
@property (nonatomic) NSString *contentType;
@property (nonatomic, nullable) NSString *caption;
@end
@implementation TSAttachment
@ -30,6 +32,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
byteCount:(UInt32)byteCount
contentType:(NSString *)contentType
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption
{
OWSAssertDebug(serverId > 0);
OWSAssertDebug(encryptionKey.length > 0);
@ -54,6 +57,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
_byteCount = byteCount;
_contentType = contentType;
_sourceFilename = sourceFilename;
_caption = caption;
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
@ -65,6 +69,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
- (instancetype)initWithContentType:(NSString *)contentType
byteCount:(UInt32)byteCount
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption
{
if (contentType.length < 1) {
OWSLogWarn(@"outgoing attachment has invalid content type");
@ -82,6 +87,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
_contentType = contentType;
_byteCount = byteCount;
_sourceFilename = sourceFilename;
_caption = caption;
_attachmentSchemaVersion = TSAttachmentSchemaVersion;
@ -117,6 +123,7 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
contentType = OWSMimeTypeApplicationOctetStream;
}
_contentType = contentType;
_caption = pointer.caption;
_attachmentSchemaVersion = TSAttachmentSchemaVersion;

@ -27,6 +27,7 @@ typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) {
byteCount:(UInt32)byteCount
contentType:(NSString *)contentType
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption
attachmentType:(TSAttachmentType)attachmentType NS_DESIGNATED_INITIALIZER;
+ (nullable TSAttachmentPointer *)attachmentPointerFromProto:(SSKProtoAttachmentPointer *)attachmentProto;

@ -32,13 +32,15 @@ NS_ASSUME_NONNULL_BEGIN
byteCount:(UInt32)byteCount
contentType:(NSString *)contentType
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption
attachmentType:(TSAttachmentType)attachmentType
{
self = [super initWithServerId:serverId
encryptionKey:key
byteCount:byteCount
contentType:contentType
sourceFilename:sourceFilename];
sourceFilename:sourceFilename
caption:caption];
if (!self) {
return self;
}
@ -76,13 +78,17 @@ NS_ASSUME_NONNULL_BEGIN
attachmentType = TSAttachmentTypeVoiceMessage;
}
}
NSString *_Nullable caption;
if (attachmentProto.hasCaption) {
caption = attachmentProto.caption;
}
TSAttachmentPointer *pointer = [[TSAttachmentPointer alloc] initWithServerId:attachmentProto.id
key:attachmentProto.key
digest:digest
byteCount:attachmentProto.size
contentType:attachmentProto.contentType
sourceFilename:attachmentProto.fileName
caption:caption
attachmentType:attachmentType];
return pointer;
}

@ -25,7 +25,8 @@ typedef void (^OWSThumbnailFailure)(void);
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithContentType:(NSString *)contentType
byteCount:(UInt32)byteCount
sourceFilename:(nullable NSString *)sourceFilename NS_DESIGNATED_INITIALIZER;
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithPointer:(TSAttachmentPointer *)pointer NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;

@ -54,8 +54,9 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
- (instancetype)initWithContentType:(NSString *)contentType
byteCount:(UInt32)byteCount
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption
{
self = [super initWithContentType:contentType byteCount:byteCount sourceFilename:sourceFilename];
self = [super initWithContentType:contentType byteCount:byteCount sourceFilename:sourceFilename caption:caption];
if (!self) {
return self;
}
@ -854,7 +855,8 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
TSAttachmentStream *thumbnailAttachment =
[[TSAttachmentStream alloc] initWithContentType:OWSMimeTypeImageJpeg
byteCount:(uint32_t)thumbnailData.length
sourceFilename:thumbnailName];
sourceFilename:thumbnailName
caption:nil];
NSError *error;
BOOL success = [thumbnailAttachment writeData:thumbnailData error:&error];
@ -894,7 +896,12 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
builder.contentType = self.contentType;
OWSLogVerbose(@"Sending attachment with filename: '%@'", self.sourceFilename);
builder.fileName = self.sourceFilename;
if (self.sourceFilename.length > 0) {
builder.fileName = self.sourceFilename;
}
if (self.caption.length > 0) {
builder.caption = self.caption;
}
builder.size = self.byteCount;
builder.key = self.encryptionKey;

@ -495,7 +495,8 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value)
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:OWSMimeTypeImageJpeg
byteCount:(UInt32)imageData.length
sourceFilename:nil];
sourceFilename:nil
caption:nil];
NSError *error;
BOOL success = [attachmentStream writeData:imageData error:&error];

@ -898,6 +898,7 @@ NS_ASSUME_NONNULL_BEGIN
dataSource:dataSource
contentType:OWSMimeTypeApplicationOctetStream
sourceFilename:nil
caption:nil
isTemporaryAttachment:YES];
} else if (syncMessage.request.type == SSKProtoSyncMessageRequestTypeBlocked) {
OWSLogInfo(@"Received request for block list");
@ -1119,6 +1120,7 @@ NS_ASSUME_NONNULL_BEGIN
dataSource:dataSource
contentType:OWSMimeTypeImagePng
sourceFilename:nil
caption:nil
isTemporaryAttachment:YES];
} else {

@ -39,12 +39,14 @@ NS_SWIFT_NAME(OutgoingAttachmentInfo)
@property (nonatomic, readonly) DataSource *dataSource;
@property (nonatomic, readonly) NSString *contentType;
@property (nonatomic, readonly, nullable) NSString *sourceFilename;
@property (nonatomic, readonly, nullable) NSString *caption;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithDataSource:(DataSource *)dataSource
contentType:(NSString *)contentType
sourceFilename:(nullable NSString *)sourceFilename NS_DESIGNATED_INITIALIZER;
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption NS_DESIGNATED_INITIALIZER;
@end

@ -86,6 +86,7 @@ void AssertIsOnSendingQueue()
- (instancetype)initWithDataSource:(DataSource *)dataSource
contentType:(NSString *)contentType
sourceFilename:(nullable NSString *)sourceFilename
caption:(nullable NSString *)caption
{
self = [super init];
if (!self) {
@ -95,6 +96,7 @@ void AssertIsOnSendingQueue()
_dataSource = dataSource;
_contentType = contentType;
_sourceFilename = sourceFilename;
_caption = caption;
return self;
}
@ -455,7 +457,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
OWSAssertDebug(dataSource);
OWSOutgoingAttachmentInfo *attachmentInfo = [[OWSOutgoingAttachmentInfo alloc] initWithDataSource:dataSource
contentType:contentType
sourceFilename:sourceFilename];
sourceFilename:sourceFilename
caption:nil];
[OutgoingMessagePreparer prepareAttachments:@[ attachmentInfo ]
inMessage:message
completionHandler:^(NSError *_Nullable error) {
@ -1804,7 +1807,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
TSAttachmentStream *attachmentStream =
[[TSAttachmentStream alloc] initWithContentType:attachmentInfo.contentType
byteCount:(UInt32)attachmentInfo.dataSource.dataLength
sourceFilename:attachmentInfo.sourceFilename];
sourceFilename:attachmentInfo.sourceFilename
caption:attachmentInfo.caption];
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:isTemporaryAttachment:)
public func add(mediaMessage: TSOutgoingMessage, dataSource: DataSource, contentType: String, sourceFilename: String?, isTemporaryAttachment: Bool) {
let attachmentInfo = OutgoingAttachmentInfo(dataSource: dataSource, contentType: contentType, sourceFilename: sourceFilename)
@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)
add(mediaMessage: mediaMessage, attachmentInfos: [attachmentInfo], isTemporaryAttachment: isTemporaryAttachment)
}

Loading…
Cancel
Save