mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Clarify message.attachments -> attachmentIds
What we *previously* refered to as attachments are actually just the attachment's id (NSString). This has tripped me up a few too many times. Also, use generics with attachment id's array. // FREEBIE
This commit is contained in:
parent
0f9a3334c1
commit
e61c818738
15 changed files with 188 additions and 150 deletions
|
@ -38,13 +38,13 @@
|
|||
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:10000
|
||||
inThread:thread
|
||||
messageBody:@"incoming message body"
|
||||
attachments:nil];
|
||||
attachmentIds:nil];
|
||||
[incomingMessage save];
|
||||
|
||||
TSOutgoingMessage *outgoingMessage = [[TSOutgoingMessage alloc] initWithTimestamp:20000
|
||||
inThread:thread
|
||||
messageBody:@"outgoing message body"
|
||||
attachments:nil];
|
||||
attachmentIds:nil];
|
||||
[outgoingMessage save];
|
||||
|
||||
XCTAssertEqual(2, [thread numberOfInteractions]);
|
||||
|
@ -75,7 +75,7 @@
|
|||
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:10000
|
||||
inThread:thread
|
||||
messageBody:@"incoming message body"
|
||||
attachments:@[ attachment.uniqueId ]];
|
||||
attachmentIds:@[ attachment.uniqueId ]];
|
||||
[incomingMessage save];
|
||||
|
||||
// Sanity check
|
||||
|
|
|
@ -16,13 +16,16 @@
|
|||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSThread *)thread
|
||||
failedMessageType:(TSErrorMessageType)errorMessageType {
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:nil attachments:nil];
|
||||
failedMessageType:(TSErrorMessageType)errorMessageType
|
||||
{
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:nil attachmentIds:nil];
|
||||
|
||||
if (self) {
|
||||
_errorType = errorMessageType;
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_errorType = errorMessageType;
|
||||
|
||||
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForErrorMessage:self inThread:thread];
|
||||
|
||||
return self;
|
||||
|
|
|
@ -16,10 +16,14 @@
|
|||
/**
|
||||
* Initiates an incoming message
|
||||
*
|
||||
* @param timestamp timestamp of the message in milliseconds since epoch
|
||||
* @param thread thread to which the message belongs
|
||||
* @param body body of the message
|
||||
* @param attachments attachments of the message
|
||||
* @param timestamp
|
||||
* Timestamp of the message in milliseconds since epoch
|
||||
* @param thread
|
||||
* Thread to which the message belongs
|
||||
* @param body
|
||||
* Body of the message
|
||||
* @param attachmentIds
|
||||
* The uniqueIds for the message's attachments
|
||||
*
|
||||
* @return initiated incoming message
|
||||
*/
|
||||
|
@ -27,16 +31,21 @@
|
|||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSContactThread *)thread
|
||||
messageBody:(NSString *)body
|
||||
attachments:(NSArray *)attachments;
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds;
|
||||
|
||||
/**
|
||||
* Initiates an incoming group message
|
||||
*
|
||||
* @param timestamp timestamp of the message in milliseconds since epoch
|
||||
* @param thread thread to which the message belongs
|
||||
* @param authorId author identifier of the user in the group that sent the message
|
||||
* @param body body of the message
|
||||
* @param attachments attachments of the message
|
||||
* @param timestamp
|
||||
* Timestamp of the message in milliseconds since epoch
|
||||
* @param thread
|
||||
* Thread to which the message belongs
|
||||
* @param authorId
|
||||
* Author identifier of the user in the group that sent the message
|
||||
* @param body
|
||||
* Body of the message
|
||||
* @param attachmentIds
|
||||
* The uniqueIds for the message's attachments
|
||||
*
|
||||
* @return initiated incoming group message
|
||||
*/
|
||||
|
@ -45,7 +54,7 @@
|
|||
inThread:(TSGroupThread *)thread
|
||||
authorId:(NSString *)authorId
|
||||
messageBody:(NSString *)body
|
||||
attachments:(NSArray *)attachments;
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds;
|
||||
|
||||
@property (nonatomic, readonly) NSString *authorId;
|
||||
@property (nonatomic, getter=wasRead) BOOL read;
|
||||
|
|
|
@ -16,30 +16,36 @@
|
|||
inThread:(TSGroupThread *)thread
|
||||
authorId:(NSString *)authorId
|
||||
messageBody:(NSString *)body
|
||||
attachments:(NSArray *)attachments {
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachments:attachments];
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
{
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachmentIds:attachmentIds];
|
||||
|
||||
if (self) {
|
||||
_authorId = authorId;
|
||||
_read = NO;
|
||||
_receivedAt = [NSDate date];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_authorId = authorId;
|
||||
_read = NO;
|
||||
_receivedAt = [NSDate date];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSContactThread *)thread
|
||||
messageBody:(NSString *)body
|
||||
attachments:(NSArray *)attachments {
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachments:attachments];
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
{
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachmentIds:attachmentIds];
|
||||
|
||||
if (self) {
|
||||
_authorId = nil;
|
||||
_read = NO;
|
||||
_receivedAt = [NSDate date];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_authorId = nil;
|
||||
_read = NO;
|
||||
_receivedAt = [NSDate date];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,13 +13,16 @@
|
|||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSThread *)thread
|
||||
messageType:(TSInfoMessageType)infoMessage {
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:nil attachments:nil];
|
||||
messageType:(TSInfoMessageType)infoMessage
|
||||
{
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:nil attachmentIds:nil];
|
||||
|
||||
if (self) {
|
||||
_messageType = infoMessage;
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_messageType = infoMessage;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,17 +16,15 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
|
|||
};
|
||||
@interface TSMessage : TSInteraction
|
||||
|
||||
@property (nonatomic, readonly) NSMutableArray<NSString *> *attachments;
|
||||
@property (nonatomic, readonly) NSMutableArray<NSString *> *attachmentIds;
|
||||
@property (nonatomic) NSString *body;
|
||||
@property (nonatomic) TSGroupMetaMessage groupMetaMessage;
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSThread *)thread
|
||||
messageBody:(NSString *)body
|
||||
attachments:(NSArray<NSString *> *)attachments;
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds;
|
||||
|
||||
- (void)addattachments:(NSArray<NSString *> *)attachments;
|
||||
- (void)addattachment:(NSString *)attachment;
|
||||
- (BOOL)hasAttachments;
|
||||
|
||||
@end
|
||||
|
|
|
@ -7,42 +7,32 @@
|
|||
|
||||
@implementation TSMessage
|
||||
|
||||
- (void)addattachments:(NSArray *)attachments {
|
||||
for (NSString *identifier in attachments) {
|
||||
[self addattachment:identifier];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)addattachment:(NSString *)attachment {
|
||||
if (!_attachments) {
|
||||
_attachments = [NSMutableArray array];
|
||||
}
|
||||
|
||||
[self.attachments addObject:attachment];
|
||||
}
|
||||
|
||||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSThread *)thread
|
||||
messageBody:(NSString *)body
|
||||
attachments:(NSArray *)attachments {
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
{
|
||||
self = [super initWithTimestamp:timestamp inThread:thread];
|
||||
|
||||
if (self) {
|
||||
_body = body;
|
||||
_attachments = [attachments mutableCopy];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_body = body;
|
||||
_attachmentIds = [attachmentIds mutableCopy];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)hasAttachments
|
||||
{
|
||||
return self.attachments ? (self.attachments.count > 0) : false;
|
||||
return self.attachmentIds ? (self.attachmentIds.count > 0) : false;
|
||||
}
|
||||
|
||||
- (NSString *)debugDescription
|
||||
{
|
||||
if ([self hasAttachments]) {
|
||||
NSString *attachmentId = self.attachments[0];
|
||||
NSString *attachmentId = self.attachmentIds[0];
|
||||
return [NSString stringWithFormat:@"Media Message with attachmentId:%@", attachmentId];
|
||||
} else {
|
||||
return [NSString stringWithFormat:@"Message with body:%@", self.body];
|
||||
|
@ -52,7 +42,7 @@
|
|||
- (NSString *)description
|
||||
{
|
||||
if ([self hasAttachments]) {
|
||||
NSString *attachmentId = self.attachments[0];
|
||||
NSString *attachmentId = self.attachmentIds[0];
|
||||
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId];
|
||||
if (attachment) {
|
||||
return attachment.description;
|
||||
|
@ -67,11 +57,10 @@
|
|||
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
[super removeWithTransaction:transaction];
|
||||
[self.attachments
|
||||
enumerateObjectsUsingBlock:^(NSString *_Nonnull attachmentId, NSUInteger idx, BOOL *_Nonnull stop) {
|
||||
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
|
||||
[attachment removeWithTransaction:transaction];
|
||||
}];
|
||||
for (NSString *attachmentId in self.attachmentIds) {
|
||||
TSAttachment *attachment = [TSAttachment fetchObjectWithUniqueID:attachmentId transaction:transaction];
|
||||
[attachment removeWithTransaction:transaction];
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -9,16 +9,19 @@
|
|||
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
||||
inThread:(TSThread *)thread
|
||||
messageBody:(NSString *)body
|
||||
attachments:(NSMutableArray *)attachments {
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachments:attachments];
|
||||
attachmentIds:(NSMutableArray<NSString *> *)attachmentIds
|
||||
{
|
||||
self = [super initWithTimestamp:timestamp inThread:thread messageBody:body attachmentIds:attachmentIds];
|
||||
|
||||
if (self) {
|
||||
_messageState = TSOutgoingMessageStateAttemptingOut;
|
||||
if ([thread isKindOfClass:[TSGroupThread class]]) {
|
||||
self.groupMetaMessage = TSGroupMessageDeliver;
|
||||
} else {
|
||||
self.groupMetaMessage = TSGroupMessageNone;
|
||||
}
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_messageState = TSOutgoingMessageStateAttemptingOut;
|
||||
if ([thread isKindOfClass:[TSGroupThread class]]) {
|
||||
self.groupMetaMessage = TSGroupMessageDeliver;
|
||||
} else {
|
||||
self.groupMetaMessage = TSGroupMessageNone;
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
|
@ -71,10 +71,11 @@ dispatch_queue_t attachmentsQueue() {
|
|||
}];
|
||||
|
||||
if (shouldProcessMessage) {
|
||||
[self handleReceivedMessage:message
|
||||
withContent:content
|
||||
attachments:retrievedAttachments
|
||||
completionBlock:^(NSString *messageIdentifier) {
|
||||
[self
|
||||
handleReceivedMessage:message
|
||||
withContent:content
|
||||
attachmentIds:retrievedAttachments
|
||||
completionBlock:^(NSString *messageIdentifier) {
|
||||
for (NSString *pointerId in retrievedAttachments) {
|
||||
dispatch_async(attachmentsQueue(), ^{
|
||||
__block TSAttachmentPointer *pointer;
|
||||
|
@ -86,7 +87,7 @@ dispatch_queue_t attachmentsQueue() {
|
|||
[self retrieveAttachment:pointer messageId:messageIdentifier];
|
||||
});
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,17 +103,17 @@ dispatch_queue_t attachmentsQueue() {
|
|||
dispatch_async(attachmentsQueue(), ^{
|
||||
if ([responseObject isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *responseDict = (NSDictionary *)responseObject;
|
||||
NSString *attachementId = [(NSNumber *)[responseDict objectForKey:@"id"] stringValue];
|
||||
NSString *attachmentId = [(NSNumber *)[responseDict objectForKey:@"id"] stringValue];
|
||||
NSString *location = [responseDict objectForKey:@"location"];
|
||||
|
||||
TSAttachmentEncryptionResult *result =
|
||||
[Cryptography encryptAttachment:attachmentData contentType:contentType identifier:attachementId];
|
||||
[Cryptography encryptAttachment:attachmentData contentType:contentType identifier:attachmentId];
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
result.pointer.isDownloaded = NO;
|
||||
[result.pointer saveWithTransaction:transaction];
|
||||
}];
|
||||
outgoingMessage.body = nil;
|
||||
[outgoingMessage.attachments addObject:attachementId];
|
||||
[outgoingMessage.attachmentIds addObject:attachmentId];
|
||||
if (outgoingMessage.groupMetaMessage != TSGroupMessageNew &&
|
||||
outgoingMessage.groupMetaMessage != TSGroupMessageUpdate) {
|
||||
[outgoingMessage setMessageState:TSOutgoingMessageStateAttemptingOut];
|
||||
|
@ -120,7 +121,7 @@ dispatch_queue_t attachmentsQueue() {
|
|||
[outgoingMessage saveWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
BOOL success = [self uploadDataWithProgress:result.body location:location attachmentID:attachementId];
|
||||
BOOL success = [self uploadDataWithProgress:result.body location:location attachmentID:attachmentId];
|
||||
if (success) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
result.pointer.isDownloaded = YES;
|
||||
|
@ -164,11 +165,12 @@ dispatch_queue_t attachmentsQueue() {
|
|||
contentType:(NSString *)contentType
|
||||
thread:(TSThread *)thread
|
||||
success:(successSendingCompletionBlock)successCompletionBlock
|
||||
failure:(failedSendingCompletionBlock)failedCompletionBlock {
|
||||
failure:(failedSendingCompletionBlock)failedCompletionBlock
|
||||
{
|
||||
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
||||
inThread:thread
|
||||
messageBody:nil
|
||||
attachments:[[NSMutableArray alloc] init]];
|
||||
attachmentIds:[NSMutableArray new]];
|
||||
[self sendAttachment:attachmentData
|
||||
contentType:contentType
|
||||
inMessage:message
|
||||
|
|
|
@ -524,8 +524,8 @@ dispatch_queue_t sendingQueue() {
|
|||
break;
|
||||
case TSGroupMessageUpdate:
|
||||
case TSGroupMessageNew: {
|
||||
if (gThread.groupModel.groupImage != nil && [message.attachments count] == 1) {
|
||||
id dbObject = [TSAttachmentStream fetchObjectWithUniqueID:[message.attachments firstObject]];
|
||||
if (gThread.groupModel.groupImage != nil && [message.attachmentIds count] == 1) {
|
||||
id dbObject = [TSAttachmentStream fetchObjectWithUniqueID:message.attachmentIds[0]];
|
||||
if ([dbObject isKindOfClass:[TSAttachmentStream class]]) {
|
||||
TSAttachmentStream *attachment = (TSAttachmentStream *)dbObject;
|
||||
PushMessageContentAttachmentPointerBuilder *attachmentbuilder =
|
||||
|
@ -550,8 +550,8 @@ dispatch_queue_t sendingQueue() {
|
|||
[builder setGroup:groupBuilder.build];
|
||||
}
|
||||
if (processAttachments) {
|
||||
NSMutableArray *attachmentsArray = [NSMutableArray array];
|
||||
for (NSString *attachmentId in message.attachments) {
|
||||
NSMutableArray *attachments = [NSMutableArray new];
|
||||
for (NSString *attachmentId in message.attachmentIds) {
|
||||
id dbObject = [TSAttachmentStream fetchObjectWithUniqueID:attachmentId];
|
||||
|
||||
if ([dbObject isKindOfClass:[TSAttachmentStream class]]) {
|
||||
|
@ -563,10 +563,10 @@ dispatch_queue_t sendingQueue() {
|
|||
[attachmentbuilder setContentType:attachment.contentType];
|
||||
[attachmentbuilder setKey:attachment.encryptionKey];
|
||||
|
||||
[attachmentsArray addObject:[attachmentbuilder build]];
|
||||
[attachments addObject:[attachmentbuilder build]];
|
||||
}
|
||||
}
|
||||
[builder setAttachmentsArray:attachmentsArray];
|
||||
[builder setAttachmentsArray:attachments];
|
||||
}
|
||||
return [builder.build data];
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
inThread:(TSThread *)thread;
|
||||
- (void)handleReceivedMessage:(IncomingPushMessageSignal *)message
|
||||
withContent:(PushMessageContent *)content
|
||||
attachments:(NSArray *)attachments;
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds;
|
||||
- (void)handleReceivedMessage:(IncomingPushMessageSignal *)message
|
||||
withContent:(PushMessageContent *)content
|
||||
attachments:(NSArray *)attachments
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
completionBlock:(void (^)(NSString *messageIdentifier))completionBlock;
|
||||
|
||||
- (void)handleSendToMyself:(TSOutgoingMessage *)outgoingMessage;
|
||||
|
|
|
@ -211,11 +211,13 @@
|
|||
[[TSStorageManager sharedManager] deleteAllSessionsForContact:message.source];
|
||||
}
|
||||
|
||||
- (void)handleReceivedTextMessage:(IncomingPushMessageSignal *)message withContent:(PushMessageContent *)content {
|
||||
[self handleReceivedMessage:message withContent:content attachments:content.attachments];
|
||||
- (void)handleReceivedTextMessage:(IncomingPushMessageSignal *)message withContent:(PushMessageContent *)content
|
||||
{
|
||||
[self handleReceivedMessage:message withContent:content attachmentIds:content.attachments];
|
||||
}
|
||||
|
||||
- (void)handleSendToMyself:(TSOutgoingMessage *)outgoingMessage {
|
||||
- (void)handleSendToMyself:(TSOutgoingMessage *)outgoingMessage
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSContactThread *cThread =
|
||||
[TSContactThread getOrCreateThreadWithContactId:[TSAccountManager localNumber] transaction:transaction];
|
||||
|
@ -223,21 +225,23 @@
|
|||
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:(outgoingMessage.timestamp + 1)
|
||||
inThread:cThread
|
||||
messageBody:outgoingMessage.body
|
||||
attachments:outgoingMessage.attachments];
|
||||
attachmentIds:outgoingMessage.attachmentIds];
|
||||
[incomingMessage saveWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)handleReceivedMessage:(IncomingPushMessageSignal *)message
|
||||
withContent:(PushMessageContent *)content
|
||||
attachments:(NSArray *)attachments {
|
||||
[self handleReceivedMessage:message withContent:content attachments:attachments completionBlock:nil];
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
{
|
||||
[self handleReceivedMessage:message withContent:content attachmentIds:attachmentIds completionBlock:nil];
|
||||
}
|
||||
|
||||
- (void)handleReceivedMessage:(IncomingPushMessageSignal *)message
|
||||
withContent:(PushMessageContent *)content
|
||||
attachments:(NSArray *)attachments
|
||||
completionBlock:(void (^)(NSString *messageIdentifier))completionBlock {
|
||||
attachmentIds:(NSArray<NSString *> *)attachmentIds
|
||||
completionBlock:(void (^)(NSString *messageIdentifier))completionBlock
|
||||
{
|
||||
uint64_t timeStamp = message.timestamp;
|
||||
NSString *body = content.body;
|
||||
NSData *groupId = content.hasGroup ? content.group.id : nil;
|
||||
|
@ -256,8 +260,8 @@
|
|||
[gThread saveWithTransaction:transaction];
|
||||
|
||||
if (content.group.type == PushMessageContentGroupContextTypeUpdate) {
|
||||
if ([attachments count] == 1) {
|
||||
NSString *avatarId = [attachments firstObject];
|
||||
if ([attachmentIds count] == 1) {
|
||||
NSString *avatarId = attachmentIds[0];
|
||||
TSAttachment *avatar = [TSAttachment fetchObjectWithUniqueID:avatarId];
|
||||
if ([avatar isKindOfClass:[TSAttachmentStream class]]) {
|
||||
TSAttachmentStream *stream = (TSAttachmentStream *)avatar;
|
||||
|
@ -299,7 +303,7 @@
|
|||
inThread:gThread
|
||||
authorId:message.source
|
||||
messageBody:body
|
||||
attachments:attachments];
|
||||
attachmentIds:attachmentIds];
|
||||
[incomingMessage saveWithTransaction:transaction];
|
||||
}
|
||||
|
||||
|
@ -312,30 +316,30 @@
|
|||
incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:timeStamp
|
||||
inThread:cThread
|
||||
messageBody:body
|
||||
attachments:attachments];
|
||||
attachmentIds:attachmentIds];
|
||||
thread = cThread;
|
||||
}
|
||||
|
||||
if (thread && incomingMessage) {
|
||||
if ([attachments count] > 0 && body != nil &&
|
||||
![body isEqualToString:@""]) { // Android allows attachments to be
|
||||
// sent with body.
|
||||
uint64_t textMessageTimestamp = timeStamp + 1000; // We want the text to be displayed under the attachment
|
||||
// Android allows attachments to be sent with body.
|
||||
// We want the text to be displayed under the attachment
|
||||
if ([attachmentIds count] > 0 && body != nil && ![body isEqualToString:@""]) {
|
||||
uint64_t textMessageTimestamp = timeStamp + 1000;
|
||||
|
||||
if ([thread isGroupThread]) {
|
||||
TSGroupThread *gThread = (TSGroupThread *)thread;
|
||||
TSGroupThread *gThread = (TSGroupThread *)thread;
|
||||
TSIncomingMessage *textMessage = [[TSIncomingMessage alloc] initWithTimestamp:textMessageTimestamp
|
||||
inThread:gThread
|
||||
authorId:message.source
|
||||
messageBody:body
|
||||
attachments:nil];
|
||||
attachmentIds:nil];
|
||||
[textMessage saveWithTransaction:transaction];
|
||||
} else {
|
||||
TSContactThread *cThread = (TSContactThread *)thread;
|
||||
TSContactThread *cThread = (TSContactThread *)thread;
|
||||
TSIncomingMessage *textMessage = [[TSIncomingMessage alloc] initWithTimestamp:textMessageTimestamp
|
||||
inThread:cThread
|
||||
messageBody:body
|
||||
attachments:nil];
|
||||
attachmentIds:nil];
|
||||
[textMessage saveWithTransaction:transaction];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,20 +24,25 @@
|
|||
|
||||
- (void)testDescription {
|
||||
TSThread *thread = [[TSThread alloc] init];
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachments:nil];
|
||||
TSMessage *message =
|
||||
[[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachmentIds:nil];
|
||||
XCTAssertEqualObjects(@"My message body", [message description]);
|
||||
}
|
||||
|
||||
- (void)testDescriptionWithBogusAttachmentId {
|
||||
TSThread *thread = [[TSThread alloc] init];
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachments:@[@"fake-attachment-id"]];
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||||
inThread:thread
|
||||
messageBody:@"My message body"
|
||||
attachmentIds:@[ @"fake-attachment-id" ]];
|
||||
NSString *actualDescription = [message description];
|
||||
XCTAssertEqualObjects(@"UNKNOWN_ATTACHMENT_LABEL", actualDescription);
|
||||
}
|
||||
|
||||
- (void)testDescriptionWithEmptyAttachments {
|
||||
TSThread *thread = [[TSThread alloc] init];
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachments:@[]];
|
||||
TSMessage *message =
|
||||
[[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachmentIds:@[]];
|
||||
NSString *actualDescription = [message description];
|
||||
XCTAssertEqualObjects(@"My message body", actualDescription);
|
||||
}
|
||||
|
@ -49,7 +54,10 @@
|
|||
contentType:@"image/jpeg"];
|
||||
[attachment save];
|
||||
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachments:@[@"fake-photo-attachment-id"]];
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||||
inThread:thread
|
||||
messageBody:@"My message body"
|
||||
attachmentIds:@[ @"fake-photo-attachment-id" ]];
|
||||
NSString *actualDescription = [message description];
|
||||
XCTAssertEqualObjects(@"📷 ATTACHMENT", actualDescription);
|
||||
}
|
||||
|
@ -62,7 +70,10 @@
|
|||
contentType:@"video/mp4"];
|
||||
[attachment save];
|
||||
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachments:@[@"fake-video-attachment-id"]];
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||||
inThread:thread
|
||||
messageBody:@"My message body"
|
||||
attachmentIds:@[ @"fake-video-attachment-id" ]];
|
||||
NSString *actualDescription = [message description];
|
||||
XCTAssertEqualObjects(@"📽 ATTACHMENT", actualDescription);
|
||||
}
|
||||
|
@ -75,7 +86,10 @@
|
|||
contentType:@"audio/mp3"];
|
||||
[attachment save];
|
||||
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachments:@[@"fake-audio-attachment-id"]];
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||||
inThread:thread
|
||||
messageBody:@"My message body"
|
||||
attachmentIds:@[ @"fake-audio-attachment-id" ]];
|
||||
NSString *actualDescription = [message description];
|
||||
XCTAssertEqualObjects(@"📻 ATTACHMENT", actualDescription);
|
||||
}
|
||||
|
@ -87,7 +101,10 @@
|
|||
contentType:@"non/sense"];
|
||||
[attachment save];
|
||||
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 inThread:thread messageBody:@"My message body" attachments:@[@"fake-nonsense-attachment-id"]];
|
||||
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
|
||||
inThread:thread
|
||||
messageBody:@"My message body"
|
||||
attachmentIds:@[ @"fake-nonsense-attachment-id" ]];
|
||||
NSString *actualDescription = [message description];
|
||||
XCTAssertEqualObjects(@"ATTACHMENT", actualDescription);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
TSContactThread *unsavedThread = [[TSContactThread alloc] initWithUniqueId:@"this-thread-does-not-exist"];
|
||||
|
||||
TSIncomingMessage *incomingMessage =
|
||||
[[TSIncomingMessage alloc] initWithTimestamp:1 inThread:unsavedThread messageBody:@"footch" attachments:nil];
|
||||
[[TSIncomingMessage alloc] initWithTimestamp:1 inThread:unsavedThread messageBody:@"footch" attachmentIds:nil];
|
||||
[incomingMessage save];
|
||||
XCTAssertEqual(1, [TSIncomingMessage numberOfKeysInCollection]);
|
||||
|
||||
|
@ -57,7 +57,7 @@
|
|||
[savedThread save];
|
||||
|
||||
TSIncomingMessage *incomingMessage =
|
||||
[[TSIncomingMessage alloc] initWithTimestamp:1 inThread:savedThread messageBody:@"footch" attachments:nil];
|
||||
[[TSIncomingMessage alloc] initWithTimestamp:1 inThread:savedThread messageBody:@"footch" attachmentIds:nil];
|
||||
[incomingMessage save];
|
||||
XCTAssertEqual(1, [TSIncomingMessage numberOfKeysInCollection]);
|
||||
|
||||
|
@ -98,7 +98,7 @@
|
|||
TSIncomingMessage *incomingMessage = [[TSIncomingMessage alloc] initWithTimestamp:1
|
||||
inThread:savedThread
|
||||
messageBody:@"footch"
|
||||
attachments:@[ attachmentStream.uniqueId ]];
|
||||
attachmentIds:@[ attachmentStream.uniqueId ]];
|
||||
[incomingMessage save];
|
||||
|
||||
NSString *attachmentFilePath = [attachmentStream filePath];
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
|
||||
@implementation TSMessageStorageTests
|
||||
|
||||
- (void)setUp {
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
|
||||
[[TSStorageManager sharedManager].dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
|
@ -40,12 +41,14 @@
|
|||
[manager purgeCollection:[TSMessage collection]];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
- (void)tearDown
|
||||
{
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testIncrementalMessageNumbers{
|
||||
- (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) {
|
||||
|
@ -53,13 +56,11 @@
|
|||
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;
|
||||
TSIncomingMessage *newMessage =
|
||||
[[TSIncomingMessage alloc] initWithTimestamp:i inThread:self.thread messageBody:body attachmentIds:nil];
|
||||
[newMessage saveWithTransaction:transaction];
|
||||
if (i == 0) {
|
||||
messageId = newMessage.uniqueId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +81,7 @@
|
|||
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:uniqueNewTimestamp
|
||||
inThread:self.thread
|
||||
messageBody:body
|
||||
attachments:nil];
|
||||
attachmentIds:nil];
|
||||
[newMessage saveWithTransaction:transaction];
|
||||
|
||||
TSIncomingMessage *retrieved = [TSIncomingMessage fetchObjectWithUniqueID:[@(messageInt+50) stringValue] transaction:transaction];
|
||||
|
@ -88,16 +89,15 @@
|
|||
}];
|
||||
}
|
||||
|
||||
- (void)testStoreIncomingMessage {
|
||||
- (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.";
|
||||
|
||||
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:timestamp
|
||||
inThread:self.thread
|
||||
messageBody:body
|
||||
attachments:nil];
|
||||
|
||||
TSIncomingMessage *newMessage =
|
||||
[[TSIncomingMessage alloc] initWithTimestamp:timestamp inThread:self.thread messageBody:body attachmentIds:nil];
|
||||
[[TSStorageManager sharedManager].newDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[newMessage saveWithTransaction:transaction];
|
||||
messageId = newMessage.uniqueId;
|
||||
|
@ -106,21 +106,20 @@
|
|||
TSIncomingMessage *fetchedMessage = [TSIncomingMessage fetchObjectWithUniqueID:messageId];
|
||||
|
||||
NSAssert([fetchedMessage.body isEqualToString:body], @"Body of incoming message recovered");
|
||||
NSAssert(fetchedMessage.attachments == nil, @"attachments are nil");
|
||||
NSAssert(fetchedMessage.attachmentIds == nil, @"attachments are nil");
|
||||
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!");
|
||||
}
|
||||
|
||||
- (void)testMessagesDeletedOnThreadDeletion {
|
||||
- (void)testMessagesDeletedOnThreadDeletion
|
||||
{
|
||||
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.";
|
||||
|
||||
for (uint64_t i = timestamp; i<100; i++) {
|
||||
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:i
|
||||
inThread:self.thread
|
||||
messageBody:body
|
||||
attachments:nil];
|
||||
TSIncomingMessage *newMessage =
|
||||
[[TSIncomingMessage alloc] initWithTimestamp:i inThread:self.thread messageBody:body attachmentIds:nil];
|
||||
[newMessage save];
|
||||
}
|
||||
|
||||
|
@ -131,7 +130,7 @@
|
|||
TSIncomingMessage *fetchedMessage = [TSIncomingMessage fetchObjectWithUniqueID:[TSInteraction stringFromTimeStamp:timestamp] transaction:transaction];
|
||||
|
||||
NSAssert([fetchedMessage.body isEqualToString:body], @"Body of incoming message recovered");
|
||||
NSAssert(fetchedMessage.attachments == nil, @"attachments are nil");
|
||||
NSAssert(fetchedMessage.attachmentIds == nil, @"attachments are nil");
|
||||
NSAssert([fetchedMessage.uniqueId isEqualToString:[TSInteraction stringFromTimeStamp: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!");
|
||||
|
@ -150,7 +149,8 @@
|
|||
}
|
||||
|
||||
|
||||
- (void)testGroupMessagesDeletedOnThreadDeletion {
|
||||
- (void)testGroupMessagesDeletedOnThreadDeletion
|
||||
{
|
||||
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.";
|
||||
|
||||
|
@ -170,8 +170,12 @@
|
|||
[manager purgeCollection:[TSMessage collection]];
|
||||
|
||||
for (uint64_t i = timestamp; i<100; i++) {
|
||||
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:i inThread:thread authorId:@"Ed" messageBody:body attachments:nil];
|
||||
|
||||
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:i
|
||||
inThread:thread
|
||||
authorId:@"Ed"
|
||||
messageBody:body
|
||||
attachmentIds:nil];
|
||||
|
||||
[newMessage save];
|
||||
}
|
||||
|
||||
|
@ -185,7 +189,7 @@
|
|||
|
||||
|
||||
NSAssert([fetchedMessage.body isEqualToString:body], @"Body of incoming message recovered");
|
||||
NSAssert(fetchedMessage.attachments == nil, @"attachments are nil");
|
||||
NSAssert(fetchedMessage.attachmentIds == nil, @"attachments are nil");
|
||||
NSAssert([fetchedMessage.uniqueId isEqualToString:[TSInteraction stringFromTimeStamp: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!");
|
||||
|
|
Loading…
Reference in a new issue