diff --git a/src/Messages/TSGroupModel.h b/src/Messages/TSGroupModel.h index b0723318a..fdbeb3d5a 100644 --- a/src/Messages/TSGroupModel.h +++ b/src/Messages/TSGroupModel.h @@ -1,13 +1,11 @@ // Created by Frederic Jacobs. // Copyright (c) 2014 Open Whisper Systems. All rights reserved. -#import #import "TSYapDatabaseObject.h" @interface TSGroupModel : TSYapDatabaseObject @property (nonatomic, strong) NSMutableArray *groupMemberIds; -@property (nonatomic, strong) NSString *associatedAttachmentId; @property (nonatomic, strong) NSString *groupName; @property (nonatomic, strong) NSData *groupId; @@ -17,8 +15,7 @@ - (instancetype)initWithTitle:(NSString *)title memberIds:(NSMutableArray *)memberIds image:(UIImage *)image - groupId:(NSData *)groupId - associatedAttachmentId:(NSString *)attachmentId; + groupId:(NSData *)groupId; - (BOOL)isEqual:(id)other; - (BOOL)isEqualToGroupModel:(TSGroupModel *)model; diff --git a/src/Messages/TSGroupModel.m b/src/Messages/TSGroupModel.m index 3a2f6f93b..fc6cbf76c 100644 --- a/src/Messages/TSGroupModel.m +++ b/src/Messages/TSGroupModel.m @@ -3,8 +3,6 @@ #import "TSGroupModel.h" -NSString *const TSAttachementGroupAvatarFileRelationshipEdge = @"TSAttachementGroupAvatarFileEdge"; - @implementation TSGroupModel #if TARGET_OS_IOS @@ -12,11 +10,10 @@ NSString *const TSAttachementGroupAvatarFileRelationshipEdge = @"TSAttachementGr memberIds:(NSMutableArray *)memberIds image:(UIImage *)image groupId:(NSData *)groupId - associatedAttachmentId:(NSString *)attachmentId { +{ _groupName = title; _groupMemberIds = [memberIds copy]; - _groupImage = image; - _associatedAttachmentId = attachmentId; + _groupImage = image; // image is stored in DB _groupId = groupId; return self; diff --git a/src/Messages/TSMessagesManager+attachments.m b/src/Messages/TSMessagesManager+attachments.m index 539b091a2..436afe416 100644 --- a/src/Messages/TSMessagesManager+attachments.m +++ b/src/Messages/TSMessagesManager+attachments.m @@ -228,7 +228,8 @@ dispatch_queue_t attachmentsQueue() { - (void)decryptedAndSaveAttachment:(TSAttachmentPointer *)attachment data:(NSData *)cipherText - messageId:(NSString *)messageId { + messageId:(NSString *)messageId +{ NSData *plaintext = [Cryptography decryptAttachment:cipherText withKey:attachment.encryptionKey]; if (!plaintext) { @@ -242,17 +243,15 @@ dispatch_queue_t attachmentsQueue() { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [stream saveWithTransaction:transaction]; if ([attachment.avatarOfGroupId length] != 0) { - TSGroupModel *emptyModelToFillOutId = [[TSGroupModel alloc] - initWithTitle:nil - memberIds:nil - image:nil - groupId:attachment.avatarOfGroupId - associatedAttachmentId:attachment.uniqueId]; // TODO refactor the TSGroupThread to just take in an ID - // (as it is all that it uses). Should not take in more - // than it uses + TSGroupModel *emptyModelToFillOutId = + [[TSGroupModel alloc] initWithTitle:nil memberIds:nil image:nil groupId:attachment.avatarOfGroupId]; TSGroupThread *gThread = [TSGroupThread getOrCreateThreadWithGroupModel:emptyModelToFillOutId transaction:transaction]; + gThread.groupModel.groupImage = [stream image]; + // No need to keep the attachment around after assigning the image. + [stream removeWithTransaction:transaction]; + [gThread saveWithTransaction:transaction]; } else { // Causing message to be reloaded in view. diff --git a/src/Messages/TSMessagesManager.m b/src/Messages/TSMessagesManager.m index 7a3718871..15c75dc81 100644 --- a/src/Messages/TSMessagesManager.m +++ b/src/Messages/TSMessagesManager.m @@ -158,23 +158,17 @@ } } -- (void)handleIncomingMessage:(IncomingPushMessageSignal *)incomingMessage - withPushContent:(PushMessageContent *)content { +- (void)handleIncomingMessage:(IncomingPushMessageSignal *)incomingMessage withPushContent:(PushMessageContent *)content +{ if (content.hasGroup) { __block BOOL ignoreMessage = NO; [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - TSGroupModel *emptyModelToFillOutId = - [[TSGroupModel alloc] initWithTitle:nil - memberIds:nil - image:nil - groupId:content.group.id - associatedAttachmentId:nil]; // TODO refactor the TSGroupThread to - // just take in an ID (as it - // is all that it uses). Should not take in more than it uses - TSGroupThread *gThread = [TSGroupThread threadWithGroupModel:emptyModelToFillOutId transaction:transaction]; - if (gThread == nil && content.group.type != PushMessageContentGroupContextTypeUpdate) { - ignoreMessage = YES; - } + TSGroupModel *emptyModelToFillOutId = + [[TSGroupModel alloc] initWithTitle:nil memberIds:nil image:nil groupId:content.group.id]; + TSGroupThread *gThread = [TSGroupThread threadWithGroupModel:emptyModelToFillOutId transaction:transaction]; + if (gThread == nil && content.group.type != PushMessageContentGroupContextTypeUpdate) { + ignoreMessage = YES; + } }]; if (ignoreMessage) { DDLogDebug(@"Received message from group that I left or don't know " @@ -254,8 +248,7 @@ [[TSGroupModel alloc] initWithTitle:content.group.name memberIds:[[[NSSet setWithArray:content.group.members] allObjects] mutableCopy] image:nil - groupId:content.group.id - associatedAttachmentId:nil]; + groupId:content.group.id]; TSGroupThread *gThread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction]; [gThread saveWithTransaction:transaction]; @@ -266,8 +259,9 @@ if ([avatar isKindOfClass:[TSAttachmentStream class]]) { TSAttachmentStream *stream = (TSAttachmentStream *)avatar; if ([stream isImage]) { - model.associatedAttachmentId = stream.uniqueId; - model.groupImage = [stream image]; + model.groupImage = [stream image]; + // No need to keep the attachment around after assigning the image. + [stream removeWithTransaction:transaction]; } } } diff --git a/tests/Storage/TSMessageStorageTests.m b/tests/Storage/TSMessageStorageTests.m index 3ea3358e0..0613b2b4b 100644 --- a/tests/Storage/TSMessageStorageTests.m +++ b/tests/Storage/TSMessageStorageTests.m @@ -159,13 +159,17 @@ __block TSGroupThread *thread; [[TSStorageManager sharedManager].dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - thread = [TSGroupThread getOrCreateThreadWithGroupModel:[[TSGroupModel alloc] initWithTitle:@"fdsfsd" memberIds:[@[] mutableCopy] image:nil groupId:[NSData data] associatedAttachmentId:pointer.uniqueId] transaction:transaction]; - + thread = [TSGroupThread getOrCreateThreadWithGroupModel:[[TSGroupModel alloc] initWithTitle:@"fdsfsd" + memberIds:[@[] mutableCopy] + image:nil + groupId:[NSData data]] + transaction:transaction]; + [thread saveWithTransaction:transaction]; [pointer saveWithTransaction:transaction]; }]; - + TSStorageManager *manager = [TSStorageManager sharedManager]; [manager purgeCollection:[TSMessage collection]];