Delete lingering group avatar attachments

The images for group avatars are stored directly in the datbase, which
is fine since they are small. But then there's no reason to have them
lingering on the filesystem.

Also removed the unused group associatedAttachmentId property.

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent e61c818738
commit 28281ccfdd

@ -1,13 +1,11 @@
// Created by Frederic Jacobs. // Created by Frederic Jacobs.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved. // Copyright (c) 2014 Open Whisper Systems. All rights reserved.
#import <Foundation/Foundation.h>
#import "TSYapDatabaseObject.h" #import "TSYapDatabaseObject.h"
@interface TSGroupModel : TSYapDatabaseObject @interface TSGroupModel : TSYapDatabaseObject
@property (nonatomic, strong) NSMutableArray *groupMemberIds; @property (nonatomic, strong) NSMutableArray *groupMemberIds;
@property (nonatomic, strong) NSString *associatedAttachmentId;
@property (nonatomic, strong) NSString *groupName; @property (nonatomic, strong) NSString *groupName;
@property (nonatomic, strong) NSData *groupId; @property (nonatomic, strong) NSData *groupId;
@ -17,8 +15,7 @@
- (instancetype)initWithTitle:(NSString *)title - (instancetype)initWithTitle:(NSString *)title
memberIds:(NSMutableArray *)memberIds memberIds:(NSMutableArray *)memberIds
image:(UIImage *)image image:(UIImage *)image
groupId:(NSData *)groupId groupId:(NSData *)groupId;
associatedAttachmentId:(NSString *)attachmentId;
- (BOOL)isEqual:(id)other; - (BOOL)isEqual:(id)other;
- (BOOL)isEqualToGroupModel:(TSGroupModel *)model; - (BOOL)isEqualToGroupModel:(TSGroupModel *)model;

@ -3,8 +3,6 @@
#import "TSGroupModel.h" #import "TSGroupModel.h"
NSString *const TSAttachementGroupAvatarFileRelationshipEdge = @"TSAttachementGroupAvatarFileEdge";
@implementation TSGroupModel @implementation TSGroupModel
#if TARGET_OS_IOS #if TARGET_OS_IOS
@ -12,11 +10,10 @@ NSString *const TSAttachementGroupAvatarFileRelationshipEdge = @"TSAttachementGr
memberIds:(NSMutableArray *)memberIds memberIds:(NSMutableArray *)memberIds
image:(UIImage *)image image:(UIImage *)image
groupId:(NSData *)groupId groupId:(NSData *)groupId
associatedAttachmentId:(NSString *)attachmentId { {
_groupName = title; _groupName = title;
_groupMemberIds = [memberIds copy]; _groupMemberIds = [memberIds copy];
_groupImage = image; _groupImage = image; // image is stored in DB
_associatedAttachmentId = attachmentId;
_groupId = groupId; _groupId = groupId;
return self; return self;

@ -228,7 +228,8 @@ dispatch_queue_t attachmentsQueue() {
- (void)decryptedAndSaveAttachment:(TSAttachmentPointer *)attachment - (void)decryptedAndSaveAttachment:(TSAttachmentPointer *)attachment
data:(NSData *)cipherText data:(NSData *)cipherText
messageId:(NSString *)messageId { messageId:(NSString *)messageId
{
NSData *plaintext = [Cryptography decryptAttachment:cipherText withKey:attachment.encryptionKey]; NSData *plaintext = [Cryptography decryptAttachment:cipherText withKey:attachment.encryptionKey];
if (!plaintext) { if (!plaintext) {
@ -242,17 +243,15 @@ dispatch_queue_t attachmentsQueue() {
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[stream saveWithTransaction:transaction]; [stream saveWithTransaction:transaction];
if ([attachment.avatarOfGroupId length] != 0) { if ([attachment.avatarOfGroupId length] != 0) {
TSGroupModel *emptyModelToFillOutId = [[TSGroupModel alloc] TSGroupModel *emptyModelToFillOutId =
initWithTitle:nil [[TSGroupModel alloc] initWithTitle:nil memberIds:nil image:nil groupId:attachment.avatarOfGroupId];
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
TSGroupThread *gThread = TSGroupThread *gThread =
[TSGroupThread getOrCreateThreadWithGroupModel:emptyModelToFillOutId transaction:transaction]; [TSGroupThread getOrCreateThreadWithGroupModel:emptyModelToFillOutId transaction:transaction];
gThread.groupModel.groupImage = [stream image]; gThread.groupModel.groupImage = [stream image];
// No need to keep the attachment around after assigning the image.
[stream removeWithTransaction:transaction];
[gThread saveWithTransaction:transaction]; [gThread saveWithTransaction:transaction];
} else { } else {
// Causing message to be reloaded in view. // Causing message to be reloaded in view.

@ -158,23 +158,17 @@
} }
} }
- (void)handleIncomingMessage:(IncomingPushMessageSignal *)incomingMessage - (void)handleIncomingMessage:(IncomingPushMessageSignal *)incomingMessage withPushContent:(PushMessageContent *)content
withPushContent:(PushMessageContent *)content { {
if (content.hasGroup) { if (content.hasGroup) {
__block BOOL ignoreMessage = NO; __block BOOL ignoreMessage = NO;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
TSGroupModel *emptyModelToFillOutId = TSGroupModel *emptyModelToFillOutId =
[[TSGroupModel alloc] initWithTitle:nil [[TSGroupModel alloc] initWithTitle:nil memberIds:nil image:nil groupId:content.group.id];
memberIds:nil TSGroupThread *gThread = [TSGroupThread threadWithGroupModel:emptyModelToFillOutId transaction:transaction];
image:nil if (gThread == nil && content.group.type != PushMessageContentGroupContextTypeUpdate) {
groupId:content.group.id ignoreMessage = YES;
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;
}
}]; }];
if (ignoreMessage) { if (ignoreMessage) {
DDLogDebug(@"Received message from group that I left or don't know " DDLogDebug(@"Received message from group that I left or don't know "
@ -254,8 +248,7 @@
[[TSGroupModel alloc] initWithTitle:content.group.name [[TSGroupModel alloc] initWithTitle:content.group.name
memberIds:[[[NSSet setWithArray:content.group.members] allObjects] mutableCopy] memberIds:[[[NSSet setWithArray:content.group.members] allObjects] mutableCopy]
image:nil image:nil
groupId:content.group.id groupId:content.group.id];
associatedAttachmentId:nil];
TSGroupThread *gThread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction]; TSGroupThread *gThread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction];
[gThread saveWithTransaction:transaction]; [gThread saveWithTransaction:transaction];
@ -266,8 +259,9 @@
if ([avatar isKindOfClass:[TSAttachmentStream class]]) { if ([avatar isKindOfClass:[TSAttachmentStream class]]) {
TSAttachmentStream *stream = (TSAttachmentStream *)avatar; TSAttachmentStream *stream = (TSAttachmentStream *)avatar;
if ([stream isImage]) { 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];
} }
} }
} }

@ -159,7 +159,11 @@
__block TSGroupThread *thread; __block TSGroupThread *thread;
[[TSStorageManager sharedManager].dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [[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]; [thread saveWithTransaction:transaction];
[pointer saveWithTransaction:transaction]; [pointer saveWithTransaction:transaction];

Loading…
Cancel
Save