Fix/Simplify outgoing attachment proto building

// FREEBIE
This commit is contained in:
Michael Kirk 2018-05-07 17:22:07 -04:00
parent 73102a9963
commit d3cda951ef
7 changed files with 14 additions and 49 deletions

View File

@ -82,11 +82,9 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Protobuf
+ (nullable OWSSignalServiceProtosAttachmentPointer *)buildProtoForAttachmentId:(nullable NSString *)filename
isVoiceMessage:(BOOL)isVoiceMessage;
+ (nullable OWSSignalServiceProtosAttachmentPointer *)buildProtoForAttachmentId:(nullable NSString *)attachmentId;
- (OWSSignalServiceProtosAttachmentPointer *)buildProtoWithFilename:(nullable NSString *)filename
isVoiceMessage:(BOOL)isVoiceMessage;
- (OWSSignalServiceProtosAttachmentPointer *)buildProto;
@end

View File

@ -706,7 +706,6 @@ NS_ASSUME_NONNULL_BEGIN
// MARK: Protobuf serialization
+ (nullable OWSSignalServiceProtosAttachmentPointer *)buildProtoForAttachmentId:(nullable NSString *)attachmentId
isVoiceMessage:(BOOL)isVoiceMessage
{
OWSAssert(attachmentId.length > 0);
@ -720,28 +719,11 @@ NS_ASSUME_NONNULL_BEGIN
}
TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment;
return [attachmentStream buildProtoWithFilename:attachmentStream.sourceFilename isVoiceMessage:isVoiceMessage];
return [attachmentStream buildProto];
}
// MJK can we get rid of the filename / isVoiceMessage pararms?
// They seem to live (redundantly) on attachmentStream...
+ (nullable OWSSignalServiceProtosAttachmentPointer *)buildProtoForAttachmentId:(NSString *)attachmentId
filename:(nullable NSString *)filename
isVoiceMessage:(BOOL)isVoiceMessage
{
OWSAssert(attachmentId.length > 0);
TSAttachment *attachment = [TSAttachmentStream fetchObjectWithUniqueID:attachmentId];
if (![attachment isKindOfClass:[TSAttachmentStream class]]) {
DDLogError(@"Unexpected type for attachment builder: %@", attachment);
return nil;
}
TSAttachmentStream *attachmentStream = (TSAttachmentStream *)attachment;
return [attachmentStream buildProtoWithFilename:filename isVoiceMessage:isVoiceMessage];
}
- (OWSSignalServiceProtosAttachmentPointer *)buildProtoWithFilename:(nullable NSString *)filename
isVoiceMessage:(BOOL)isVoiceMessage
- (OWSSignalServiceProtosAttachmentPointer *)buildProto
{
OWSSignalServiceProtosAttachmentPointerBuilder *builder = [OWSSignalServiceProtosAttachmentPointerBuilder new];
@ -750,13 +732,13 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(self.contentType.length > 0);
builder.contentType = self.contentType;
DDLogVerbose(@"%@ Sending attachment with filename: '%@'", self.logTag, filename);
builder.fileName = filename;
DDLogVerbose(@"%@ Sending attachment with filename: '%@'", self.logTag, self.sourceFilename);
builder.fileName = self.sourceFilename;
builder.size = self.byteCount;
builder.key = self.encryptionKey;
builder.digest = self.digest;
builder.flags = isVoiceMessage ? OWSSignalServiceProtosAttachmentPointerFlagsVoiceMessage : 0;
builder.flags = self.isVoiceMessage ? OWSSignalServiceProtosAttachmentPointerFlagsVoiceMessage : 0;
if (self.shouldHaveImageSize) {
CGSize imageSize = self.imageSize;

View File

@ -59,7 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
}
OWSSignalServiceProtosAttachmentPointer *attachmentProto =
[self buildProtoForAttachmentId:self.attachmentIds[0] filename:nil];
[TSAttachmentStream buildProtoForAttachmentId:self.attachmentIds.firstObject];
OWSSignalServiceProtosSyncMessageContactsBuilder *contactsBuilder =
[OWSSignalServiceProtosSyncMessageContactsBuilder new];

View File

@ -7,6 +7,7 @@
#import "OWSGroupsOutputStream.h"
#import "OWSSignalServiceProtos.pb.h"
#import "TSAttachment.h"
#import "TSAttachmentStream.h"
#import "TSGroupModel.h"
#import "TSGroupThread.h"
@ -35,8 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
DDLogError(@"expected sync groups message to have exactly one attachment, but found %lu",
(unsigned long)self.attachmentIds.count);
}
OWSSignalServiceProtosAttachmentPointer *attachmentProto =
[self buildProtoForAttachmentId:self.attachmentIds[0] filename:nil];
OWSSignalServiceProtosAttachmentPointer *attachmentProto = [TSAttachmentStream buildProtoForAttachmentId:self.attachmentIds.firstObject];
OWSSignalServiceProtosSyncMessageGroupsBuilder *groupsBuilder =
[OWSSignalServiceProtosSyncMessageGroupsBuilder new];

View File

@ -860,7 +860,7 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value)
OWSSignalServiceProtosDataMessageContactAvatarBuilder *avatarBuilder =
[OWSSignalServiceProtosDataMessageContactAvatarBuilder new];
avatarBuilder.avatar =
[TSAttachmentStream buildProtoForAttachmentId:contact.avatarAttachmentId isVoiceMessage:NO];
[TSAttachmentStream buildProtoForAttachmentId:contact.avatarAttachmentId];
contactBuilder.avatar = [avatarBuilder build];
}

View File

@ -143,19 +143,6 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
*/
- (BOOL)shouldSyncTranscript;
/**
* @param attachmentId
* id of an AttachmentStream containing the meta data used when populating the attachment proto
*
* @param filename
* optional filename of the attachment.
*
* @return
* An attachment pointer protobuf suitable for including in various container protobuf builders
*/
- (OWSSignalServiceProtosAttachmentPointer *)buildProtoForAttachmentId:(NSString *)attachmentId
filename:(nullable NSString *)filename;
- (BOOL)shouldBeSaved;
// All recipients of this message.

View File

@ -761,7 +761,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
case TSGroupMessageNew: {
if (gThread.groupModel.groupImage != nil && self.attachmentIds.count == 1) {
attachmentWasGroupAvatar = YES;
[groupBuilder setAvatar:[self buildProtoForAttachmentId:self.attachmentIds[0] filename:nil]];
[groupBuilder setAvatar:[TSAttachmentStream buildProtoForAttachmentId:self.attachmentIds.firstObject]];
}
[groupBuilder setMembersArray:gThread.groupModel.groupMemberIds];
@ -781,8 +781,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
if (!attachmentWasGroupAvatar) {
NSMutableArray *attachments = [NSMutableArray new];
for (NSString *attachmentId in self.attachmentIds) {
NSString *_Nullable sourceFilename = self.attachmentFilenameMap[attachmentId];
[attachments addObject:[self buildProtoForAttachmentId:attachmentId filename:sourceFilename]];
[attachments addObject:[TSAttachmentStream buildProtoForAttachmentId:attachmentId]];
}
[builder setAttachmentsArray:attachments];
}
@ -836,8 +835,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
quotedAttachmentBuilder.fileName = attachment.sourceFilename;
if (attachment.thumbnailAttachmentStreamId) {
quotedAttachmentBuilder.thumbnail =
[TSAttachmentStream buildProtoForAttachmentId:attachment.thumbnailAttachmentStreamId
isVoiceMessage:NO];
[TSAttachmentStream buildProtoForAttachmentId:attachment.thumbnailAttachmentStreamId];
}
[quoteBuilder addAttachments:[quotedAttachmentBuilder build]];