Fix interaction initializers and tests.

pull/1/head
Matthew Chen 7 years ago
parent a6dbe5bf7a
commit 9085609087

@ -3568,15 +3568,7 @@ typedef enum : NSUInteger {
groupThread.groupModel = newGroupModel; groupThread.groupModel = newGroupModel;
[groupThread saveWithTransaction:transaction]; [groupThread saveWithTransaction:transaction];
message = [[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] message = [TSOutgoingMessage outgoingMessageInThread:groupThread groupMetaMessage:TSGroupMessageUpdate];
inThread:groupThread
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:0
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageUpdate
quotedMessage:nil];
[message updateWithCustomMessage:updateGroupInfo transaction:transaction]; [message updateWithCustomMessage:updateGroupInfo transaction:transaction];
}]; }];

@ -800,7 +800,7 @@ NS_ASSUME_NONNULL_BEGIN
TSOutgoingMessage *message = [self createFakeOutgoingMessage:thread TSOutgoingMessage *message = [self createFakeOutgoingMessage:thread
messageBody:messageBody messageBody:messageBody
fakeAssetLoader:fakeAssetLoader fakeAssetLoader:fakeAssetLoader
messageState:(TSOutgoingMessageState)messageState messageState:messageState
isDelivered:YES isDelivered:YES
isRead:NO isRead:NO
quotedMessage:nil quotedMessage:nil
@ -3115,6 +3115,7 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
messageState:TSOutgoingMessageStateUnsent messageState:TSOutgoingMessageStateUnsent
isDelivered:NO isDelivered:NO
isRead:NO isRead:NO
isVoiceMessage:NO
quotedMessage:nil quotedMessage:nil
transaction:transaction]; transaction:transaction];
break; break;
@ -3147,16 +3148,7 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
}]; }];
OWSAssert(thread); OWSAssert(thread);
TSOutgoingMessage *message = TSOutgoingMessage *message = [TSOutgoingMessage outgoingMessageInThread:thread groupMetaMessage:TSGroupMessageNew];
[[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:0
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageNew
quotedMessage:nil];
[message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)]; [message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)];
OWSMessageSender *messageSender = [Environment current].messageSender; OWSMessageSender *messageSender = [Environment current].messageSender;
@ -3407,16 +3399,11 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
NSString *text = [self randomText]; NSString *text = [self randomText];
OWSDisappearingMessagesConfiguration *configuration = OWSDisappearingMessagesConfiguration *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId transaction:transaction]; [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId transaction:transaction];
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] TSOutgoingMessage *message =
initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] [TSOutgoingMessage outgoingMessageInThread:thread
inThread:thread messageBody:text
messageBody:text attachmentId:nil
attachmentIds:[NSMutableArray new] expiresInSeconds:(configuration.isEnabled ? configuration.durationSeconds : 0)];
expiresInSeconds:(configuration.isEnabled ? configuration.durationSeconds
: 0)expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageNone
quotedMessage:nil];
DDLogError(@"%@ insertAndDeleteNewOutgoingMessages timestamp: %llu.", self.logTag, message.timestamp); DDLogError(@"%@ insertAndDeleteNewOutgoingMessages timestamp: %llu.", self.logTag, message.timestamp);
[messages addObject:message]; [messages addObject:message];
} }
@ -3441,16 +3428,11 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
OWSDisappearingMessagesConfiguration *configuration = OWSDisappearingMessagesConfiguration *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId
transaction:initialTransaction]; transaction:initialTransaction];
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] TSOutgoingMessage *message =
initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] [TSOutgoingMessage outgoingMessageInThread:thread
inThread:thread messageBody:text
messageBody:text attachmentId:nil
attachmentIds:[NSMutableArray new] expiresInSeconds:(configuration.isEnabled ? configuration.durationSeconds : 0)];
expiresInSeconds:(configuration.isEnabled ? configuration.durationSeconds
: 0)expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageNone
quotedMessage:nil];
DDLogError(@"%@ resurrectNewOutgoingMessages1 timestamp: %llu.", self.logTag, message.timestamp); DDLogError(@"%@ resurrectNewOutgoingMessages1 timestamp: %llu.", self.logTag, message.timestamp);
[messages addObject:message]; [messages addObject:message];
} }
@ -3774,6 +3756,7 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
messageState:messageState messageState:messageState
isDelivered:isDelivered isDelivered:isDelivered
isRead:isRead isRead:isRead
isVoiceMessage:attachment.isVoiceMessage
quotedMessage:quotedMessage quotedMessage:quotedMessage
transaction:transaction]; transaction:transaction];
} }
@ -3785,6 +3768,7 @@ isQuotedMessageAttachmentDownloaded:(BOOL)isQuotedMessageAttachmentDownloaded
messageState:(TSOutgoingMessageState)messageState messageState:(TSOutgoingMessageState)messageState
isDelivered:(BOOL)isDelivered isDelivered:(BOOL)isDelivered
isRead:(BOOL)isRead isRead:(BOOL)isRead
isVoiceMessage:(BOOL)isVoiceMessage
quotedMessage:(nullable TSQuotedMessage *)quotedMessage quotedMessage:(nullable TSQuotedMessage *)quotedMessage
transaction:(YapDatabaseReadWriteTransaction *)transaction transaction:(YapDatabaseReadWriteTransaction *)transaction
{ {

@ -684,15 +684,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
[self presentViewController:removingFromGroup animated:YES completion:nil]; [self presentViewController:removingFromGroup animated:YES completion:nil];
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] [TSOutgoingMessage outgoingMessageInThread:thread groupMetaMessage:TSGroupMessageQuit];
inThread:thread
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:0
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageQuit
quotedMessage:nil];
[self.messageSender enqueueMessage:message [self.messageSender enqueueMessage:message
success:^{ success:^{
[self dismissViewControllerAnimated:YES [self dismissViewControllerAnimated:YES

@ -490,15 +490,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
canCancel:NO canCancel:NO
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] [TSOutgoingMessage outgoingMessageInThread:thread groupMetaMessage:TSGroupMessageNew];
inThread:thread
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:0
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageNew
quotedMessage:nil];
[message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)]; [message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)];

@ -937,15 +937,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
TSGroupThread *gThread = (TSGroupThread *)self.thread; TSGroupThread *gThread = (TSGroupThread *)self.thread;
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] [TSOutgoingMessage outgoingMessageInThread:gThread groupMetaMessage:TSGroupMessageQuit];
inThread:gThread
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:0
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageQuit
quotedMessage:nil];
[self.messageSender enqueueMessage:message [self.messageSender enqueueMessage:message
success:^{ success:^{
DDLogInfo(@"%@ Successfully left group.", self.logTag); DDLogInfo(@"%@ Successfully left group.", self.logTag);

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
import XCTest import XCTest
@ -23,7 +23,7 @@ class MesssagesBubblesSizeCalculatorTest: XCTestCase {
let contactsManager = OWSContactsManager() let contactsManager = OWSContactsManager()
func viewItemForText(_ text: String?) -> ConversationViewItem { func viewItemForText(_ text: String?) -> ConversationViewItem {
let interaction = TSOutgoingMessage(timestamp: 0, in: thread, messageBody: text) let interaction = TSOutgoingMessage(in: thread, messageBody: text, attachmentId: nil)
interaction.save() interaction.save()
var viewItem: ConversationViewItem! var viewItem: ConversationViewItem!
@ -41,7 +41,7 @@ class MesssagesBubblesSizeCalculatorTest: XCTestCase {
// These are the expected values on iPhone SE. // These are the expected values on iPhone SE.
let viewWidth = 320 let viewWidth = 320
let contentWidth = 300 let contentWidth = 300
return viewItem.cellSize(forViewWidth: Int32(viewWidth), contentWidth:Int32(contentWidth)) return viewItem.cellSize(forViewWidth: Int32(viewWidth), contentWidth: Int32(contentWidth))
} }
func testHeightForEmptyMessage() { func testHeightForEmptyMessage() {

@ -37,7 +37,7 @@
- (ConversationViewItem *)textViewItem - (ConversationViewItem *)textViewItem
{ {
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initWithTimestamp:1 inThread:nil messageBody:self.fakeTextMessageText]; [TSOutgoingMessage outgoingMessageInThread:nil messageBody:self.fakeTextMessageText attachmentId:nil];
[message save]; [message save];
__block ConversationViewItem *viewItem = nil; __block ConversationViewItem *viewItem = nil;
[TSYapDatabaseObject.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [TSYapDatabaseObject.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
@ -62,11 +62,8 @@
BOOL success = [attachment writeDataSource:dataSource]; BOOL success = [attachment writeDataSource:dataSource];
OWSAssert(success); OWSAssert(success);
[attachment save]; [attachment save];
NSMutableArray<NSString *> *attachmentIds = [@[
attachment.uniqueId,
] mutableCopy];
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initWithTimestamp:1 inThread:nil messageBody:nil attachmentIds:attachmentIds]; [TSOutgoingMessage outgoingMessageInThread:nil messageBody:nil attachmentId:attachment.uniqueId];
[message save]; [message save];
__block ConversationViewItem *viewItem = nil; __block ConversationViewItem *viewItem = nil;

@ -64,7 +64,7 @@ class DisplayableTextTest: XCTestCase {
XCTAssertEqual("Příliš žluťoučký kůň úpěl ďábelské ódy.".glyphCount, 39) XCTAssertEqual("Příliš žluťoučký kůň úpěl ďábelské ódy.".glyphCount, 39)
// Excessive diacritics // Excessive diacritics
XCTAssertEqual("H҉̸̧͘͠A͢͞V̛̛I̴̸N͏̕͏G҉̵͜͏͢ ̧̧́T̶̛͘͡R̸̵̨̢̀O̷̡U͡҉B̶̛͢͞L̸̸͘͢͟É̸ ̸̛͘͏R͟È͠͞A̸͝Ḑ̕͘͜I̵͘҉͜͞N̷̡̢͠G̴͘͠ ͟͞T͏̢́͡È̀X̕҉̢̀T̢͠?̕͏̢͘͢".glyphCount, 109) XCTAssertEqual("H҉̸̧͘͠A͢͞V̛̛I̴̸N͏̕͏G҉̵͜͏͢ ̧̧́T̶̛͘͡R̸̵̨̢̀O̷̡U͡҉B̶̛͢͞L̸̸͘͢͟É̸ ̸̛͘͏R͟È͠͞A̸͝Ḑ̕͘͜I̵͘҉͜͞N̷̡̢͠G̴͘͠ ͟͞T͏̢́͡È̀X̕҉̢̀T̢͠?̕͏̢͘͢".glyphCount, 115)
XCTAssertEqual("L̷̳͔̲͝Ģ̵̮̯̤̩̙͍̬̟͉̹̘̹͍͈̮̦̰̣͟͝O̶̴̮̻̮̗͘͡!̴̷̟͓͓".glyphCount, 43) XCTAssertEqual("L̷̳͔̲͝Ģ̵̮̯̤̩̙͍̬̟͉̹̘̹͍͈̮̦̰̣͟͝O̶̴̮̻̮̗͘͡!̴̷̟͓͓".glyphCount, 43)
} }

@ -85,18 +85,12 @@ NS_ASSUME_NONNULL_BEGIN
OWSDisappearingMessagesConfiguration *configuration = OWSDisappearingMessagesConfiguration *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId]; [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
uint32_t expiresInSeconds = (configuration.isEnabled ? configuration.durationSeconds : 0); uint32_t expiresInSeconds = (configuration.isEnabled ? configuration.durationSeconds : 0);
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] [TSOutgoingMessage outgoingMessageInThread:thread
inThread:thread messageBody:text
messageBody:text attachmentId:nil
attachmentIds:[NSMutableArray new] expiresInSeconds:expiresInSeconds];
expiresInSeconds:expiresInSeconds
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageNone
quotedMessage:quotedMessage];
[messageSender enqueueMessage:message success:successHandler failure:failureHandler]; [messageSender enqueueMessage:message success:successHandler failure:failureHandler];

@ -57,6 +57,18 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
+ (instancetype)outgoingMessageInThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentId:(nullable NSString *)attachmentId;
+ (instancetype)outgoingMessageInThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentId:(nullable NSString *)attachmentId
expiresInSeconds:(uint32_t)expiresInSeconds;
+ (instancetype)outgoingMessageInThread:(nullable TSThread *)thread
groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage;
@property (atomic, readonly) TSOutgoingMessageState messageState; @property (atomic, readonly) TSOutgoingMessageState messageState;
// The message has been sent to the service and received by at least one recipient client. // The message has been sent to the service and received by at least one recipient client.

@ -75,6 +75,47 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
return self; return self;
} }
+ (instancetype)outgoingMessageInThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentId:(nullable NSString *)attachmentId
{
return [self outgoingMessageInThread:thread messageBody:body attachmentId:attachmentId expiresInSeconds:0];
}
+ (instancetype)outgoingMessageInThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentId:(nullable NSString *)attachmentId
expiresInSeconds:(uint32_t)expiresInSeconds
{
NSMutableArray<NSString *> *attachmentIds = [NSMutableArray new];
if (attachmentId) {
[attachmentIds addObject:attachmentId];
}
return [[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread
messageBody:body
attachmentIds:attachmentIds
expiresInSeconds:expiresInSeconds
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageNone
quotedMessage:nil];
}
+ (instancetype)outgoingMessageInThread:(nullable TSThread *)thread
groupMetaMessage:(TSGroupMetaMessage)groupMetaMessage
{
return [[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:0
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:groupMetaMessage
quotedMessage:nil];
}
- (instancetype)initOutgoingMessageWithTimestamp:(uint64_t)timestamp - (instancetype)initOutgoingMessageWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body messageBody:(nullable NSString *)body

@ -890,15 +890,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *updateGroupInfo = NSString *updateGroupInfo =
[gThread.groupModel getInfoStringAboutUpdateTo:gThread.groupModel contactsManager:self.contactsManager]; [gThread.groupModel getInfoStringAboutUpdateTo:gThread.groupModel contactsManager:self.contactsManager];
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] [TSOutgoingMessage outgoingMessageInThread:gThread groupMetaMessage:TSGroupMessageUpdate];
inThread:gThread
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:0
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMessageUpdate
quotedMessage:nil];
[message updateWithCustomMessage:updateGroupInfo transaction:transaction]; [message updateWithCustomMessage:updateGroupInfo transaction:transaction];
// Only send this group update to the requester. // Only send this group update to the requester.
[message updateWithSingleGroupRecipient:envelope.source transaction:transaction]; [message updateWithSingleGroupRecipient:envelope.source transaction:transaction];

Loading…
Cancel
Save