Closes #315
This commit is contained in:
parent
478110dc86
commit
5ccbc4131b
@ -356,6 +356,7 @@
|
||||
B63AF5D21A1F757900D01AAD /* TSNetworkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B63AF5C31A1F757900D01AAD /* TSNetworkManager.m */; };
|
||||
B63AF5D31A1F757900D01AAD /* TSSocketManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B63AF5C61A1F757900D01AAD /* TSSocketManager.m */; };
|
||||
B63AF5D81A1F889500D01AAD /* SubProtocol.pb.m in Sources */ = {isa = PBXBuildFile; fileRef = B63AF5D71A1F889500D01AAD /* SubProtocol.pb.m */; settings = {COMPILER_FLAGS = "-w"; }; };
|
||||
B63BAD6D1A74DA8F00269E74 /* TSStorageManager+messageIDs.m in Sources */ = {isa = PBXBuildFile; fileRef = B63BAD6C1A74DA8F00269E74 /* TSStorageManager+messageIDs.m */; };
|
||||
B640C4771A477B0F005C7C8A /* TSAttachementsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B640C4761A477B0F005C7C8A /* TSAttachementsTest.m */; };
|
||||
B6416FB8199A0478003C5699 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = B6416F57199A0478003C5699 /* Localizable.strings */; };
|
||||
B65EDA1219E1BE6400AAA7CB /* RPAPICall.m in Sources */ = {isa = PBXBuildFile; fileRef = B65EDA1119E1BE6400AAA7CB /* RPAPICall.m */; };
|
||||
@ -987,6 +988,8 @@
|
||||
B63AF5C61A1F757900D01AAD /* TSSocketManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSSocketManager.m; sourceTree = "<group>"; };
|
||||
B63AF5D61A1F889500D01AAD /* SubProtocol.pb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SubProtocol.pb.h; sourceTree = "<group>"; };
|
||||
B63AF5D71A1F889500D01AAD /* SubProtocol.pb.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SubProtocol.pb.m; sourceTree = "<group>"; };
|
||||
B63BAD6B1A74DA8F00269E74 /* TSStorageManager+messageIDs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "TSStorageManager+messageIDs.h"; sourceTree = "<group>"; };
|
||||
B63BAD6C1A74DA8F00269E74 /* TSStorageManager+messageIDs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TSStorageManager+messageIDs.m"; sourceTree = "<group>"; };
|
||||
B640C4761A477B0F005C7C8A /* TSAttachementsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSAttachementsTest.m; sourceTree = "<group>"; };
|
||||
B6416F58199A0478003C5699 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = Localizable.strings; sourceTree = "<group>"; };
|
||||
B657DDC91911A40500F45B0C /* Signal.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = Signal.entitlements; sourceTree = "<group>"; };
|
||||
@ -2427,6 +2430,8 @@
|
||||
B6B0964E1A1D25ED008BFAA6 /* TSStorageManager+keyingMaterial.m */,
|
||||
B6B0964F1A1D25ED008BFAA6 /* TSStorageManager.h */,
|
||||
B6B096501A1D25ED008BFAA6 /* TSStorageManager.m */,
|
||||
B63BAD6B1A74DA8F00269E74 /* TSStorageManager+messageIDs.h */,
|
||||
B63BAD6C1A74DA8F00269E74 /* TSStorageManager+messageIDs.m */,
|
||||
B6B096511A1D25ED008BFAA6 /* TSYapDatabaseObject.h */,
|
||||
B6B096521A1D25ED008BFAA6 /* TSYapDatabaseObject.m */,
|
||||
);
|
||||
@ -3158,6 +3163,7 @@
|
||||
76EB05D618170B33006006FC /* ZrtpResponder.m in Sources */,
|
||||
B62D53F71A23CCAD009AAF82 /* TSMessageAdapter.m in Sources */,
|
||||
B63AF5C91A1F757900D01AAD /* TSRecipientPrekeyRequest.m in Sources */,
|
||||
B63BAD6D1A74DA8F00269E74 /* TSStorageManager+messageIDs.m in Sources */,
|
||||
7095B7B018F46D35002C66E2 /* PhoneNumberUtil.m in Sources */,
|
||||
B63AF5D81A1F889500D01AAD /* SubProtocol.pb.m in Sources */,
|
||||
FCD274EB1A5AFDDB00202277 /* AboutTableViewController.m in Sources */,
|
||||
|
||||
@ -65,7 +65,6 @@ MacrosSingletonImplemention
|
||||
break;
|
||||
|
||||
case HTTP_DELETE:
|
||||
NSLog(@"endpoint %@, request serializer %@",apiCall.endPoint,apiCall.requestSerializer);
|
||||
[self.operationManager DELETE:apiCall.endPoint parameters:apiCall.parameters success:success failure:failure];
|
||||
break;
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ typedef NS_ENUM(NSInteger, TSLastActionType) {
|
||||
- (UIImage*)image;
|
||||
|
||||
@property (getter=isBlocked) BOOL blocked;
|
||||
@property (nonatomic) uint64_t lastMessageId;
|
||||
@property (nonatomic) NSString* latestMessageId;
|
||||
@property NSDate *archivalDate;
|
||||
|
||||
- (NSDate*)lastMessageDate;
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
if (self) {
|
||||
_blocked = NO;
|
||||
_lastMessageId = 0;
|
||||
_latestMessageId = nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
@ -40,21 +40,20 @@
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
- (uint64_t)lastMessageId{
|
||||
return _lastMessageId;
|
||||
}
|
||||
|
||||
- (NSDate*)lastMessageDate{
|
||||
__block NSDate *date;
|
||||
[[TSStorageManager sharedManager].dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
date = [TSInteraction fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:_lastMessageId] transaction:transaction].date;
|
||||
}];
|
||||
|
||||
if (date) {
|
||||
return date;
|
||||
} else{
|
||||
return [NSDate date];
|
||||
if (self.latestMessageId) {
|
||||
[[TSStorageManager sharedManager].dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
date = [TSInteraction fetchObjectWithUniqueID:self.latestMessageId transaction:transaction].date;
|
||||
}];
|
||||
|
||||
if (date) {
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
return [NSDate date];
|
||||
}
|
||||
|
||||
- (UIImage*)image{
|
||||
@ -64,7 +63,7 @@
|
||||
- (NSString*)lastMessageLabel{
|
||||
__block TSInteraction *interaction;
|
||||
[[TSStorageManager sharedManager].dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
interaction = [TSInteraction fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:_lastMessageId] transaction:transaction];
|
||||
interaction = [TSInteraction fetchObjectWithUniqueID:self.latestMessageId transaction:transaction];
|
||||
}];
|
||||
return interaction.description;
|
||||
}
|
||||
@ -73,7 +72,7 @@
|
||||
{
|
||||
__block TSInteraction *interaction;
|
||||
[[TSStorageManager sharedManager].dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
interaction = [TSInteraction fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:_lastMessageId] transaction:transaction];
|
||||
interaction = [TSInteraction fetchObjectWithUniqueID:self.latestMessageId transaction:transaction];
|
||||
}];
|
||||
|
||||
return [self lastActionForInteraction:interaction];
|
||||
@ -126,7 +125,7 @@
|
||||
__block TSInteraction * interaction;
|
||||
__block BOOL hasUnread = NO;
|
||||
[[TSStorageManager sharedManager].dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
interaction = [TSInteraction fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:_lastMessageId] transaction:transaction];
|
||||
interaction = [TSInteraction fetchObjectWithUniqueID:self.latestMessageId transaction:transaction];
|
||||
if ([interaction isKindOfClass:[TSIncomingMessage class]]){
|
||||
hasUnread = ![(TSIncomingMessage*)interaction wasRead];
|
||||
}
|
||||
|
||||
@ -27,9 +27,9 @@ extern const struct TSMessageEdges {
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(TSThread*)thread;
|
||||
|
||||
@property (nonatomic, readonly) NSString *uniqueThreadId;
|
||||
@property (nonatomic, readonly) uint64_t timestamp;
|
||||
|
||||
- (NSDate*)date;
|
||||
- (uint64_t)timeStamp;
|
||||
- (NSString*)description;
|
||||
|
||||
#pragma mark Utility Method
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "TSInteraction.h"
|
||||
#import "TSStorageManager+messageIDs.h"
|
||||
|
||||
const struct TSMessageRelationships TSMessageRelationships = {
|
||||
.threadUniqueId = @"threadUniqueId",
|
||||
@ -18,10 +19,11 @@ const struct TSMessageEdges TSMessageEdges = {
|
||||
|
||||
@implementation TSInteraction
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(TSThread*)thread{
|
||||
self = [super initWithUniqueId:[[self class] stringFromTimeStamp:timestamp]];
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(TSThread*)thread {
|
||||
self = [super initWithUniqueId:nil];
|
||||
|
||||
if (self) {
|
||||
_timestamp = timestamp;
|
||||
_uniqueThreadId = thread.uniqueId;
|
||||
}
|
||||
|
||||
@ -51,20 +53,15 @@ const struct TSMessageEdges TSMessageEdges = {
|
||||
|
||||
#pragma mark Date operations
|
||||
|
||||
- (uint64_t)identifierToTimestamp{
|
||||
return [[self class] timeStampFromString:self.uniqueId];
|
||||
- (uint64_t)millisecondsTimestamp{
|
||||
return self.timestamp;
|
||||
}
|
||||
|
||||
- (NSDate*)date{
|
||||
uint64_t milliseconds = [self identifierToTimestamp];
|
||||
uint64_t seconds = milliseconds/1000;
|
||||
uint64_t seconds = self.timestamp/1000;
|
||||
return [NSDate dateWithTimeIntervalSince1970:seconds];
|
||||
}
|
||||
|
||||
- (UInt64)timeStamp{
|
||||
return [self identifierToTimestamp];
|
||||
}
|
||||
|
||||
+ (NSString*)stringFromTimeStamp:(uint64_t)timestamp{
|
||||
return [[NSNumber numberWithUnsignedLongLong:timestamp] stringValue];
|
||||
}
|
||||
@ -81,15 +78,18 @@ const struct TSMessageEdges TSMessageEdges = {
|
||||
}
|
||||
|
||||
- (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction{
|
||||
[super saveWithTransaction:transaction];
|
||||
TSThread *fetchedThread = [TSThread fetchObjectWithUniqueID:self.uniqueThreadId transaction:transaction];
|
||||
uint64_t timeStamp = [TSInteraction timeStampFromString:self.uniqueId];
|
||||
if (!self.uniqueId) {
|
||||
self.uniqueId = [TSStorageManager getAndIncrementMessageIdWithTransaction:transaction];
|
||||
}
|
||||
|
||||
if (timeStamp > fetchedThread.lastMessageId) {
|
||||
fetchedThread.lastMessageId = timeStamp;
|
||||
[super saveWithTransaction:transaction];
|
||||
|
||||
TSThread *fetchedThread = [TSThread fetchObjectWithUniqueID:self.uniqueThreadId transaction:transaction];
|
||||
|
||||
if (!fetchedThread.latestMessageId || [self.date timeIntervalSinceDate:fetchedThread.lastMessageDate] > 0) {
|
||||
fetchedThread.latestMessageId = self.uniqueId;
|
||||
}
|
||||
[fetchedThread saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@ -12,6 +12,10 @@
|
||||
@interface TSMessagesManager (attachments)
|
||||
|
||||
- (void)handleReceivedMediaMessage:(IncomingPushMessageSignal*)message withContent:(PushMessageContent*)content;
|
||||
- (void)sendAttachment:(NSData*)attachmentData contentType:(NSString*)contentType inMessage:(TSOutgoingMessage*)outgoingMessage thread:(TSThread*)thread;
|
||||
|
||||
- (void)sendAttachment:(NSData*)attachmentData
|
||||
contentType:(NSString*)contentType
|
||||
inMessage:(TSOutgoingMessage*)outgoingMessage
|
||||
thread:(TSThread*)thread;
|
||||
|
||||
@end
|
||||
|
||||
@ -109,7 +109,7 @@ dispatch_queue_t sendingQueue() {
|
||||
remainingAttempts -= 1;
|
||||
|
||||
[self outgoingMessages:message toRecipient:recipient inThread:thread completion:^(NSArray *messages) {
|
||||
TSSubmitMessageRequest *request = [[TSSubmitMessageRequest alloc] initWithRecipient:recipient.uniqueId messages:messages relay:recipient.relay timeStamp:message.timeStamp];
|
||||
TSSubmitMessageRequest *request = [[TSSubmitMessageRequest alloc] initWithRecipient:recipient.uniqueId messages:messages relay:recipient.relay timeStamp:message.timestamp];
|
||||
|
||||
[[TSNetworkManager sharedManager] queueAuthenticatedRequest:request success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
@ -252,13 +252,13 @@ dispatch_queue_t sendingQueue() {
|
||||
else if(message.groupMetaMessage==TSGroupMessageQuit) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
|
||||
[[[TSInfoMessage alloc] initWithTimestamp:message.timeStamp inThread:thread messageType:TSInfoMessageTypeGroupQuit] saveWithTransaction:transaction];
|
||||
[[[TSInfoMessage alloc] initWithTimestamp:message.timestamp inThread:thread messageType:TSInfoMessageTypeGroupQuit] saveWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
else {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
|
||||
[[[TSInfoMessage alloc] initWithTimestamp:message.timeStamp inThread:thread messageType:TSInfoMessageTypeGroupUpdate] saveWithTransaction:transaction];
|
||||
[[[TSInfoMessage alloc] initWithTimestamp:message.timestamp inThread:thread messageType:TSInfoMessageTypeGroupUpdate] saveWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSContactThread *cThread = [TSContactThread getOrCreateThreadWithContactId:[SignalKeyingStorage.localNumber toE164] transaction:transaction];
|
||||
[cThread saveWithTransaction:transaction];
|
||||
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:(outgoingMessage.timeStamp + 1) inThread:cThread messageBody:outgoingMessage.body attachments:outgoingMessage.attachments];
|
||||
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:(outgoingMessage.timestamp + 1) inThread:cThread messageBody:outgoingMessage.body attachments:outgoingMessage.attachments];
|
||||
[incomingMessage saveWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
15
Signal/src/textsecure/Storage/TSStorageManager+messageIDs.h
Normal file
15
Signal/src/textsecure/Storage/TSStorageManager+messageIDs.h
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// TSStorageManager+messageIDs.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 24/01/15.
|
||||
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSStorageManager.h"
|
||||
|
||||
@interface TSStorageManager (messageIDs)
|
||||
|
||||
+ (NSString*)getAndIncrementMessageIdWithTransaction:(YapDatabaseReadWriteTransaction*)transaction;
|
||||
|
||||
@end
|
||||
36
Signal/src/textsecure/Storage/TSStorageManager+messageIDs.m
Normal file
36
Signal/src/textsecure/Storage/TSStorageManager+messageIDs.m
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// TSStorageManager+messageIDs.m
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 24/01/15.
|
||||
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TSStorageManager+messageIDs.h"
|
||||
|
||||
#define TSStorageParametersCollection @"TSStorageParametersCollection"
|
||||
#define TSMessagesLatestId @"TSMessagesLatestId"
|
||||
|
||||
@implementation TSStorageManager (messageIDs)
|
||||
|
||||
+ (NSString*)getAndIncrementMessageIdWithTransaction:(YapDatabaseReadWriteTransaction*)transaction {
|
||||
NSString *messageId = [transaction objectForKey:TSMessagesLatestId inCollection:TSStorageParametersCollection];
|
||||
if (!messageId) {
|
||||
messageId = @"0";
|
||||
}
|
||||
|
||||
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
|
||||
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
|
||||
NSNumber *myNumber = [numberFormatter numberFromString:messageId];
|
||||
|
||||
unsigned long long nextMessageId = [myNumber unsignedLongLongValue];
|
||||
nextMessageId ++;
|
||||
|
||||
NSString *nextMessageIdString = [[NSNumber numberWithUnsignedLongLong:nextMessageId] stringValue];
|
||||
|
||||
[transaction setObject:nextMessageIdString forKey:TSMessagesLatestId inCollection:TSStorageParametersCollection];
|
||||
|
||||
return messageId;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -64,7 +64,8 @@
|
||||
* The unique identifier of the stored object
|
||||
*/
|
||||
|
||||
@property (nonatomic, readonly) NSString *uniqueId;
|
||||
|
||||
@property (nonatomic) NSString *uniqueId;
|
||||
|
||||
|
||||
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction*)transaction;
|
||||
|
||||
@ -19,9 +19,9 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithUniqueId:(NSString *)uniqueId{
|
||||
- (instancetype)initWithUniqueId:(NSString *)aUniqueId{
|
||||
if (self = [super init]) {
|
||||
_uniqueId = uniqueId;
|
||||
_uniqueId = aUniqueId;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@
|
||||
switch (indexPath.section) {
|
||||
case 1:
|
||||
{
|
||||
[DJWActionSheet showInView:self.tabBarController.view
|
||||
[DJWActionSheet showInView:self.parentViewController.view
|
||||
withTitle:@"Are you sure you want to delete all your history (messages, attachments, call history ...) ? This action cannot be reverted."
|
||||
cancelButtonTitle:@"Cancel"
|
||||
destructiveButtonTitle:@"I'm sure."
|
||||
|
||||
@ -48,7 +48,6 @@
|
||||
|
||||
- (UIView *)mediaView
|
||||
{
|
||||
NSLog(@"attachment adapter");
|
||||
if (self.image == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@ -49,7 +49,51 @@
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testIncrementalMessageNumbers{
|
||||
__block NSInteger messageInt;
|
||||
NSString *body = @"I don't see myself as a hero because what I'm doing is self-interested: I don't want to live in a world where there's no privacy and therefore no room for intellectual exploration and creativity.";
|
||||
[[TSStorageManager sharedManager].newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
|
||||
NSString* messageId;
|
||||
|
||||
for (uint64_t i = 0; i<50; i++) {
|
||||
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:i
|
||||
inThread:self.thread
|
||||
messageBody:body
|
||||
attachments:nil];
|
||||
[newMessage saveWithTransaction:transaction];
|
||||
if (i == 0) {
|
||||
messageId = newMessage.uniqueId;
|
||||
}
|
||||
}
|
||||
|
||||
messageInt = [messageId integerValue];
|
||||
|
||||
for (NSInteger i = messageInt; i < messageInt+50; i++) {
|
||||
TSIncomingMessage *message = [TSIncomingMessage 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
|
||||
attachments:nil];
|
||||
[newMessage saveWithTransaction:transaction];
|
||||
|
||||
TSIncomingMessage *retreived = [TSIncomingMessage fetchObjectWithUniqueID:[@(messageInt+50) stringValue] transaction:transaction];
|
||||
XCTAssert(retreived.timestamp == uniqueNewTimestamp);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testStoreIncomingMessage {
|
||||
__block NSString *messageId;
|
||||
uint64_t timestamp = 666;
|
||||
|
||||
NSString *body = @"A child born today will grow up with no conception of privacy at all. They’ll never know what it means to have a private moment to themselves an unrecorded, unanalyzed thought. And that’s a problem because privacy matters; privacy is what allows us to determine who we are and who we want to be.";
|
||||
@ -57,16 +101,17 @@
|
||||
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:timestamp
|
||||
inThread:self.thread
|
||||
messageBody:body
|
||||
attachments:nil];
|
||||
attachments:nil];
|
||||
[[TSStorageManager sharedManager].newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[newMessage saveWithTransaction:transaction];
|
||||
messageId = newMessage.uniqueId;
|
||||
}];
|
||||
|
||||
TSIncomingMessage *fetchedMessage = [TSIncomingMessage fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:timestamp]];
|
||||
TSIncomingMessage *fetchedMessage = [TSIncomingMessage fetchObjectWithUniqueID:messageId];
|
||||
|
||||
NSAssert([fetchedMessage.body isEqualToString:body], @"Body of incoming message recovered");
|
||||
NSAssert(fetchedMessage.attachments == nil, @"attachments are nil");
|
||||
NSAssert([fetchedMessage.uniqueId isEqualToString:[TSInteraction stringFromTimeStamp:timestamp]], @"Unique identifier is accurate");
|
||||
NSAssert(fetchedMessage.timestamp == timestamp, @"Unique identifier is accurate");
|
||||
NSAssert(fetchedMessage.wasRead == false, @"Message should originally be unread");
|
||||
NSAssert([fetchedMessage.uniqueThreadId isEqualToString:self.thread.uniqueId], @"Isn't stored in the right thread!");
|
||||
}
|
||||
@ -79,7 +124,7 @@
|
||||
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:i
|
||||
inThread:self.thread
|
||||
messageBody:body
|
||||
attachments:nil];
|
||||
attachments:nil];
|
||||
[newMessage save];
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user