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.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
#import <Foundation/Foundation.h>
#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;

@ -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;

@ -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.

@ -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];
}
}
}

@ -159,7 +159,11 @@
__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];

Loading…
Cancel
Save