Group avatar relationship for deletion.

This commit is contained in:
Christine Corbett 2015-01-31 01:37:36 -10:00 committed by Frederic Jacobs
parent 585079de21
commit 8a5c5efd73
6 changed files with 49 additions and 18 deletions

View File

@ -107,6 +107,7 @@ dispatch_queue_t attachmentsQueue() {
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
result.pointer.isDownloaded = YES;
[result.pointer saveWithTransaction:transaction];
NSLog(@"finished uploading");
}];
[self sendMessage:outgoingMessage inThread:thread];
@ -158,13 +159,13 @@ dispatch_queue_t attachmentsQueue() {
contentType:attachment.contentType];
[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]; // 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 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 getOrCreateThreadWithGroupModel:emptyModelToFillOutId transaction:transaction];
gThread.groupModel.groupImage=[stream image];
[gThread saveWithTransaction:transaction];
} else {
}
else {
// Causing message to be reloaded in view.
TSMessage *message = [TSMessage fetchObjectWithUniqueID:messageId transaction:transaction];
[message saveWithTransaction:transaction];

View File

@ -190,7 +190,7 @@
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]; // 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: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;
@ -255,7 +255,7 @@
TSIncomingMessage *incomingMessage;
TSThread *thread;
if (groupId) {
TSGroupModel *model = [[TSGroupModel alloc] initWithTitle:content.group.name memberIds:[[NSMutableArray alloc ] initWithArray:content.group.members] image:nil groupId:content.group.id];
TSGroupModel *model = [[TSGroupModel alloc] initWithTitle:content.group.name memberIds:[[NSMutableArray alloc ] initWithArray:content.group.members] image:nil groupId:content.group.id associatedAttachmentId:nil];
TSGroupThread *gThread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction];
[gThread saveWithTransaction:transaction];
if(content.group.type==PushMessageContentGroupContextTypeUpdate) {
@ -265,6 +265,7 @@
if ([avatar isKindOfClass:[TSAttachmentStream class]]) {
TSAttachmentStream *stream = (TSAttachmentStream*)avatar;
if ([stream isImage]) {
model.associatedAttachmentId = stream.uniqueId;
model.groupImage = [stream image];
}
}

View File

@ -126,7 +126,7 @@ static NSString* const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
[mut addObjectsFromArray:[[contacts objectAtIndex:(NSUInteger)idx.row] textSecureIdentifiers]];
}
[mut addObjectsFromArray:_thread.groupModel.groupMemberIds];
_groupModel = [[TSGroupModel alloc] initWithTitle:_nameGroupTextField.text memberIds:[NSMutableArray arrayWithArray:[[NSSet setWithArray:mut] allObjects]] image:_thread.groupModel.groupImage groupId:_thread.groupModel.groupId];
_groupModel = [[TSGroupModel alloc] initWithTitle:_nameGroupTextField.text memberIds:[NSMutableArray arrayWithArray:[[NSSet setWithArray:mut] allObjects]] image:_thread.groupModel.groupImage groupId:_thread.groupModel.groupId associatedAttachmentId:nil];
[self performSegueWithIdentifier:kUnwindToMessagesViewSegue sender:self];
}
@ -142,7 +142,7 @@ static NSString* const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
[mut addObject:[SignalKeyingStorage.localNumber toE164]];
NSData* groupId = [SecurityUtils generateRandomBytes:16];
return [[TSGroupModel alloc] initWithTitle:title memberIds:mut image:_groupImage groupId:groupId];
return [[TSGroupModel alloc] initWithTitle:title memberIds:mut image:_groupImage groupId:groupId associatedAttachmentId:nil];
}
-(IBAction)addGroupPhoto:(id)sender

View File

@ -9,17 +9,18 @@
#import <Foundation/Foundation.h>
#import "TSYapDatabaseObject.h"
#import "TSAttachmentAdapter.h"
@interface TSGroupModel : TSYapDatabaseObject
@interface TSGroupModel : TSYapDatabaseObject <YapDatabaseRelationshipNode>
@property (nonatomic, strong) NSMutableArray *groupMemberIds;
@property (nonatomic, strong) UIImage *groupImage;
@property (nonatomic, strong) NSString *associatedAttachmentId;
@property (nonatomic, strong) NSString *groupName;
@property (nonatomic, strong) NSData* groupId;
- (instancetype)initWithTitle:(NSString*)title memberIds:(NSMutableArray*)members image:(UIImage*)image groupId:(NSData*)groupId;
-(instancetype)initWithTitle:(NSString*)title memberIds:(NSMutableArray*)memberIds image:(UIImage*)image groupId:(NSData *)groupId associatedAttachmentId:(NSString*)attachmentId;
- (BOOL)isEqual:(id)other;
- (BOOL)isEqualToGroupModel:(TSGroupModel *)model;
- (NSString*) getInfoStringAboutUpdateTo:(TSGroupModel*)model;

View File

@ -8,13 +8,16 @@
#import "TSGroupModel.h"
NSString * const TSAttachementGroupAvatarFileRelationshipEdge = @"TSAttachementGroupAvatarFileEdge";
@implementation TSGroupModel
-(instancetype)initWithTitle:(NSString*)title memberIds:(NSMutableArray*)memberIds image:(UIImage*)image groupId:(NSData *)groupId{
_groupName = title;
_groupMemberIds = [memberIds copy];
_groupImage = image;
_groupId = groupId;
-(instancetype)initWithTitle:(NSString*)title memberIds:(NSMutableArray*)memberIds image:(UIImage*)image groupId:(NSData *)groupId associatedAttachmentId:(NSString*)attachmentId {
_groupName = title;
_groupMemberIds = [memberIds copy];
_groupImage = image;
_associatedAttachmentId = attachmentId;
_groupId = groupId;
return self;
}
@ -84,4 +87,17 @@
return updatedGroupInfoString;
}
- (NSArray *)yapDatabaseRelationshipEdges {
if([_associatedAttachmentId length]>0){
YapDatabaseRelationshipEdge *fileEdge = [[YapDatabaseRelationshipEdge alloc] initWithName:TSAttachementGroupAvatarFileRelationshipEdge
destinationKey:_associatedAttachmentId
collection:[TSAttachment collection]
nodeDeleteRules:YDB_DeleteDestinationIfAllSourcesDeleted];
return @[fileEdge];
}
else {
return nil;
}
}
@end

View File

@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "Cryptography.h"
#import "TSThread.h"
#import "TSContactThread.h"
#import "TSGroupThread.h"
@ -146,22 +147,28 @@
[self.thread remove];
[[TSStorageManager sharedManager].dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (uint64_t i = timestamp; i<1000; i++) {
for (uint64_t i = timestamp; i<100; i++) {
TSIncomingMessage *fetchedMessage = [TSIncomingMessage fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:timestamp] transaction:transaction];
NSAssert(fetchedMessage == nil, @"Message should be deleted!");
}
}];
}
- (void)testGroupMessagesDeletedOnThreadDeletion {
uint64_t timestamp = 666;
NSString *body = @"A child born today will grow up with no conception of privacy at all. Theyll never know what it means to have a private moment to themselves an unrecorded, unanalyzed thought. And thats a problem because privacy matters; privacy is what allows us to determine who we are and who we want to be.";
TSAttachmentStream *pointer = [[TSAttachmentStream alloc] initWithIdentifier:@"helloid" data:[Cryptography generateRandomBytes:16] key:[Cryptography generateRandomBytes:16] contentType:@"data/random"];
__block TSGroupThread *thread;
[[TSStorageManager sharedManager].dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
thread = [TSGroupThread getOrCreateThreadWithGroupModel:[[TSGroupModel alloc] initWithTitle:@"fdsfsd" memberIds:[@[] mutableCopy] image:nil groupId:[NSData data]] transaction:transaction];
thread = [TSGroupThread getOrCreateThreadWithGroupModel:[[TSGroupModel alloc] initWithTitle:@"fdsfsd" memberIds:[@[] mutableCopy] image:nil groupId:[NSData data] associatedAttachmentId:pointer.uniqueId] transaction:transaction];
[thread saveWithTransaction:transaction];
[pointer saveWithTransaction:transaction];
}];
TSStorageManager *manager = [TSStorageManager sharedManager];
@ -178,6 +185,9 @@
[[TSStorageManager sharedManager].dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (uint64_t i = timestamp; i<100; i++) {
TSIncomingMessage *fetchedMessage = [TSIncomingMessage fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:timestamp] transaction:transaction];
TSAttachmentStream *fetchedPointer = [TSAttachmentStream fetchObjectWithUniqueID:pointer.uniqueId];
NSAssert([fetchedPointer.image isEqual:pointer.image], @"attachment pointers not equal");
NSAssert([fetchedMessage.body isEqualToString:body], @"Body of incoming message recovered");
NSAssert(fetchedMessage.attachments == nil, @"attachments are nil");
@ -191,8 +201,10 @@
[self.thread remove];
[[TSStorageManager sharedManager].dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (uint64_t i = timestamp; i<1000; i++) {
for (uint64_t i = timestamp; i<100; i++) {
TSIncomingMessage *fetchedMessage = [TSIncomingMessage fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:timestamp] transaction:transaction];
TSAttachmentStream *fetchedPointer = [TSAttachmentStream fetchObjectWithUniqueID:pointer.uniqueId];
NSAssert(fetchedPointer == nil, @"Attachment pointer should be deleted");
NSAssert(fetchedMessage == nil, @"Message should be deleted!");
}
}];