Fix attachment deleting for outgoing messages

Broken in the disappearing messages beta due to sloppy refactoring. =(

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 34868b9b0f
commit 0b4d81002f

@ -54,7 +54,7 @@
36DA6C703F99948D553F4E3F /* Pods-TSKitiOSTestAppTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TSKitiOSTestAppTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-TSKitiOSTestAppTests/Pods-TSKitiOSTestAppTests.debug.xcconfig"; sourceTree = "<group>"; };
45046FDF1D95A6130015EFF2 /* TSMessagesManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSMessagesManagerTest.m; path = ../../../tests/Messages/TSMessagesManagerTest.m; sourceTree = "<group>"; };
450E3C991D96DD2600BF4EB6 /* OWSDisappearingMessagesJobTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSDisappearingMessagesJobTest.m; path = ../../../tests/Messages/OWSDisappearingMessagesJobTest.m; sourceTree = "<group>"; };
452EE6CE1D4A754C00E934BA /* TSThreadTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSThreadTest.m; sourceTree = "<group>"; };
452EE6CE1D4A754C00E934BA /* TSThreadTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSThreadTest.m; path = ../../../tests/Contacts/TSThreadTest.m; sourceTree = "<group>"; };
452EE6D41D4AC43300E934BA /* OWSOrphanedDataCleanerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSOrphanedDataCleanerTest.m; sourceTree = "<group>"; };
454021EC1D960ABF00F2126D /* OWSDisappearingMessageFinderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSDisappearingMessageFinderTest.m; path = ../../../tests/Messages/OWSDisappearingMessageFinderTest.m; sourceTree = "<group>"; };
45458B6A1CC342B600A02153 /* SignedPreKeyDeletionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SignedPreKeyDeletionTests.m; sourceTree = "<group>"; };

@ -1,89 +0,0 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "TSAttachmentStream.h"
#import "TSContactThread.h"
#import "TSIncomingMessage.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import <XCTest/XCTest.h>
@interface TSThreadTest : XCTestCase
@end
@implementation TSThreadTest
- (void)setUp
{
[super setUp];
// Register views, etc.
[[TSStorageManager sharedManager] setupDatabase];
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testDeletingThreadDeletesInteractions
{
TSContactThread *thread = [[TSContactThread alloc] initWithUniqueId:@"fake-test-thread"];
[thread save];
[TSInteraction removeAllObjectsInCollection];
XCTAssertEqual(0, [thread numberOfInteractions]);
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:10000
inThread:thread
messageBody:@"incoming message body"];
[incomingMessage save];
TSOutgoingMessage *outgoingMessage = [[TSOutgoingMessage alloc] initWithTimestamp:20000
inThread:thread
messageBody:@"outgoing message body"];
[outgoingMessage save];
XCTAssertEqual(2, [thread numberOfInteractions]);
[thread remove];
XCTAssertEqual(0, [thread numberOfInteractions]);
XCTAssertEqual(0, [TSInteraction numberOfKeysInCollection]);
}
- (void)testDeletingThreadDeletesAttachmentFiles
{
TSContactThread *thread = [[TSContactThread alloc] initWithUniqueId:@"fake-test-thread"];
[thread save];
// Sanity check
[TSInteraction removeAllObjectsInCollection];
XCTAssertEqual(0, [thread numberOfInteractions]);
TSAttachmentStream *attachment = [[TSAttachmentStream alloc] initWithIdentifier:@"fake-photo-attachment-id"
data:[[NSData alloc] init]
key:[[NSData alloc] init]
contentType:@"image/jpeg"];
[attachment save];
BOOL fileWasCreated = [[NSFileManager defaultManager] fileExistsAtPath:[attachment filePath]];
XCTAssert(fileWasCreated);
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:10000
inThread:thread
messageBody:@"incoming message body"
attachmentIds:@[ attachment.uniqueId ]];
[incomingMessage save];
// Sanity check
XCTAssertEqual(1, [thread numberOfInteractions]);
[thread remove];
XCTAssertEqual(0, [thread numberOfInteractions]);
BOOL fileStillExists = [[NSFileManager defaultManager] fileExistsAtPath:[attachment filePath]];
XCTAssertFalse(fileStillExists);
}
@end

@ -41,13 +41,6 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
- (void)remove
{
[[self dbConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self removeWithTransaction:transaction];
}];
}
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
[super removeWithTransaction:transaction];

@ -42,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
return [self initWithTimestamp:timestamp
inThread:thread
messageBody:body
attachmentIds:[NSMutableArray new]
attachmentIds:attachmentIds
expiresInSeconds:0];
}

@ -0,0 +1,115 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "TSAttachmentStream.h"
#import "TSContactThread.h"
#import "TSIncomingMessage.h"
#import "TSOutgoingMessage.h"
#import "TSStorageManager.h"
#import <XCTest/XCTest.h>
@interface TSThreadTest : XCTestCase
@end
@implementation TSThreadTest
- (void)setUp
{
[super setUp];
// Register views, etc.
[[TSStorageManager sharedManager] setupDatabase];
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testDeletingThreadDeletesInteractions
{
TSContactThread *thread = [[TSContactThread alloc] initWithUniqueId:@"fake-test-thread"];
[thread save];
[TSInteraction removeAllObjectsInCollection];
XCTAssertEqual(0, [thread numberOfInteractions]);
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:10000
inThread:thread
authorId:@"fake-author-id"
messageBody:@"Incoming message body"];
[incomingMessage save];
TSOutgoingMessage *outgoingMessage =
[[TSOutgoingMessage alloc] initWithTimestamp:20000 inThread:thread messageBody:@"outgoing message body"];
[outgoingMessage save];
XCTAssertEqual(2, [thread numberOfInteractions]);
[thread remove];
XCTAssertEqual(0, [thread numberOfInteractions]);
XCTAssertEqual(0, [TSInteraction numberOfKeysInCollection]);
}
- (void)testDeletingThreadDeletesAttachmentFiles
{
TSContactThread *thread = [[TSContactThread alloc] initWithUniqueId:@"fake-test-thread"];
[thread save];
// Sanity check
[TSInteraction removeAllObjectsInCollection];
XCTAssertEqual(0, [thread numberOfInteractions]);
TSAttachmentStream *incomingAttachment =
[[TSAttachmentStream alloc] initWithIdentifier:@"fake-incoming-photo-attachment-id"
data:[[NSData alloc] init]
key:[[NSData alloc] init]
contentType:@"image/jpeg"];
[incomingAttachment save];
// Sanity check
BOOL incomingFileWasCreated = [[NSFileManager defaultManager] fileExistsAtPath:[incomingAttachment filePath]];
XCTAssert(incomingFileWasCreated);
TSIncomingMessage *incomingMessage =
[[TSIncomingMessage alloc] initWithTimestamp:10000
inThread:thread
authorId:@"fake-author-id"
messageBody:@"incoming message body"
attachmentIds:[NSMutableArray arrayWithObject:incomingAttachment.uniqueId]];
[incomingMessage save];
TSAttachmentStream *outgoingAttachment =
[[TSAttachmentStream alloc] initWithIdentifier:@"fake-outgoing-photo-attachment-id"
data:[[NSData alloc] init]
key:[[NSData alloc] init]
contentType:@"image/jpeg"];
[outgoingAttachment save];
// Sanity check
BOOL outgoingFileWasCreated = [[NSFileManager defaultManager] fileExistsAtPath:[outgoingAttachment filePath]];
XCTAssert(outgoingFileWasCreated);
TSOutgoingMessage *outgoingMessage =
[[TSOutgoingMessage alloc] initWithTimestamp:10000
inThread:thread
messageBody:@"outgoing message body"
attachmentIds:[NSMutableArray arrayWithObject:outgoingAttachment.uniqueId]];
[outgoingMessage save];
// Sanity check
XCTAssertEqual(2, [thread numberOfInteractions]);
// Actual Test Follows
[thread remove];
XCTAssertEqual(0, [thread numberOfInteractions]);
BOOL incomingFileStillExists = [[NSFileManager defaultManager] fileExistsAtPath:[incomingAttachment filePath]];
XCTAssertFalse(incomingFileStillExists);
BOOL outgoingFileStillExists = [[NSFileManager defaultManager] fileExistsAtPath:[outgoingAttachment filePath]];
XCTAssertFalse(outgoingFileStillExists);
}
@end

@ -42,8 +42,10 @@
// properly deleting it's interactions.
TSContactThread *unsavedThread = [[TSContactThread alloc] initWithUniqueId:@"this-thread-does-not-exist"];
TSIncomingMessage *incomingMessage =
[[TSIncomingMessage alloc] initWithTimestamp:1 inThread:unsavedThread messageBody:@"footch"];
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:1
inThread:unsavedThread
authorId:@"fake-author-id"
messageBody:@"footch"];
[incomingMessage save];
XCTAssertEqual(1, [TSIncomingMessage numberOfKeysInCollection]);
@ -56,8 +58,10 @@
TSContactThread *savedThread = [[TSContactThread alloc] initWithUniqueId:@"this-thread-exists"];
[savedThread save];
TSIncomingMessage *incomingMessage =
[[TSIncomingMessage alloc] initWithTimestamp:1 inThread:savedThread messageBody:@"footch"];
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:1
inThread:savedThread
authorId:@"fake-author-id"
messageBody:@"footch"];
[incomingMessage save];
XCTAssertEqual(1, [TSIncomingMessage numberOfKeysInCollection]);
@ -97,6 +101,7 @@
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:1
inThread:savedThread
authorId:@"fake-author-id"
messageBody:@"footch"
attachmentIds:@[ attachmentStream.uniqueId ]];
[incomingMessage save];

@ -15,8 +15,9 @@
#import "TSStorageManager.h"
#import "TSMessage.h"
#import "TSIncomingMessage.h"
#import "TSMessage.h"
#import "TSOutgoingMessage.h"
@interface TSMessageStorageTests : XCTestCase
@ -56,8 +57,8 @@
NSString* messageId;
for (uint64_t i = 0; i<50; i++) {
TSIncomingMessage *newMessage =
[[TSIncomingMessage alloc] initWithTimestamp:i inThread:self.thread messageBody:body];
TSOutgoingMessage *newMessage =
[[TSOutgoingMessage alloc] initWithTimestamp:i inThread:self.thread messageBody:body];
[newMessage saveWithTransaction:transaction];
if (i == 0) {
messageId = newMessage.uniqueId;
@ -67,25 +68,28 @@
messageInt = [messageId integerValue];
for (NSInteger i = messageInt; i < messageInt+50; i++) {
TSIncomingMessage *message = [TSIncomingMessage fetchObjectWithUniqueID:[@(i) stringValue] transaction:transaction];
TSOutgoingMessage *message =
[TSOutgoingMessage fetchObjectWithUniqueID:[@(i) stringValue] transaction:transaction];
XCTAssert(message != nil);
XCTAssert(message.body == body);
}
}];
[[TSStorageManager sharedManager].newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSIncomingMessage *deletedmessage = [TSIncomingMessage fetchObjectWithUniqueID:[@(messageInt+49) stringValue]];
[deletedmessage removeWithTransaction:transaction];
uint64_t uniqueNewTimestamp = 985439854983;
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:uniqueNewTimestamp
inThread:self.thread
messageBody:body];
[newMessage saveWithTransaction:transaction];
TSIncomingMessage *retrieved = [TSIncomingMessage fetchObjectWithUniqueID:[@(messageInt+50) stringValue] transaction:transaction];
XCTAssertEqual(uniqueNewTimestamp, retrieved.timestamp);
}];
[[TSStorageManager sharedManager].newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSOutgoingMessage *deletedmessage =
[TSOutgoingMessage fetchObjectWithUniqueID:[@(messageInt + 49) stringValue]];
[deletedmessage removeWithTransaction:transaction];
uint64_t uniqueNewTimestamp = 985439854983;
TSOutgoingMessage *newMessage =
[[TSOutgoingMessage alloc] initWithTimestamp:uniqueNewTimestamp inThread:self.thread messageBody:body];
[newMessage saveWithTransaction:transaction];
TSOutgoingMessage *retrieved =
[TSOutgoingMessage fetchObjectWithUniqueID:[@(messageInt + 50) stringValue] transaction:transaction];
XCTAssertEqual(uniqueNewTimestamp, retrieved.timestamp);
}];
}
- (void)testStoreIncomingMessage
@ -95,8 +99,10 @@
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.";
TSIncomingMessage *newMessage =
[[TSIncomingMessage alloc] initWithTimestamp:timestamp inThread:self.thread messageBody:body];
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:timestamp
inThread:self.thread
authorId:[self.thread contactIdentifier]
messageBody:body];
[[TSStorageManager sharedManager].newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[newMessage saveWithTransaction:transaction];
messageId = newMessage.uniqueId;
@ -117,8 +123,10 @@
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.";
for (uint64_t i = timestamp; i<100; i++) {
TSIncomingMessage *newMessage =
[[TSIncomingMessage alloc] initWithTimestamp:i inThread:self.thread messageBody:body];
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:i
inThread:self.thread
authorId:[self.thread contactIdentifier]
messageBody:body];
[newMessage save];
}

Loading…
Cancel
Save