diff --git a/Session/Signal/ConversationView/ConversationViewController.m b/Session/Signal/ConversationView/ConversationViewController.m index 44e502a37..2536714be 100644 --- a/Session/Signal/ConversationView/ConversationViewController.m +++ b/Session/Signal/ConversationView/ConversationViewController.m @@ -370,12 +370,12 @@ typedef enum : NSUInteger { name:NSNotification.groupThreadUpdated object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(handleCalculatingPoWNotification:) - name:NSNotification.calculatingMessagePoW + selector:@selector(handleEncryptingMessageNotification:) + name:NSNotification.encryptingMessage object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(handleRoutingNotification:) - name:NSNotification.encryptingMessage + selector:@selector(handleCalculatingMessagePoWNotification:) + name:NSNotification.calculatingMessagePoW object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMessageSendingNotification:) @@ -386,7 +386,7 @@ typedef enum : NSUInteger { name:NSNotification.messageSent object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(handleMessageFailedNotification:) + selector:@selector(handleMessageSendingFailedNotification:) name:NSNotification.messageSendingFailed object:nil]; } @@ -3816,47 +3816,30 @@ typedef enum : NSUInteger { text = [text ows_stripped]; - if (text.length < 1) { - return; - } - - // Limit outgoing text messages to 16kb. - // - // We convert large text messages to attachments - // which are presented as normal text messages. + if (text.length < 1) { return; } SNVisibleMessage *message = [SNVisibleMessage new]; + [message setSentTimestamp:[NSDate millisecondTimestamp]]; message.text = text; message.quote = [SNQuote from:self.inputToolbar.quotedReply]; [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [SNMessageSender send:message inThread:self.thread usingTransaction:transaction]; }]; - + TSOutgoingMessage *tsMessage = [TSOutgoingMessage from:message associatedWith:self.thread]; - [self.conversationViewModel appendUnsavedOutgoingTextMessage:tsMessage]; + [tsMessage save]; + [self.conversationViewModel appendUnsavedOutgoingTextMessage:tsMessage]; + [self messageWasSent:tsMessage]; - // Clearing the text message is a key part of the send animation. - // It takes 10-15ms, but we do it inline rather than dispatch async - // since the send can't feel "complete" without it. - [BenchManager benchWithTitle:@"clearTextMessageAnimated" - block:^{ - [self.inputToolbar clearTextMessageAnimated:YES]; - [self resetMentions]; - }]; - [BenchManager completeEventWithEventId:@"fromSendUntil_clearTextMessageAnimated"]; + [self.inputToolbar clearTextMessageAnimated:YES]; + + [self resetMentions]; dispatch_async(dispatch_get_main_queue(), ^{ - // After sending we want to return from the numeric keyboard to the - // alphabetical one. Because this is so slow (40-50ms), we prefer it - // happens async, after any more essential send UI work is done. - [BenchManager benchWithTitle:@"toggleDefaultKeyboard" - block:^{ - [self.inputToolbar toggleDefaultKeyboard]; - }]; - [BenchManager completeEventWithEventId:@"fromSendUntil_toggleDefaultKeyboard"]; + [self.inputToolbar toggleDefaultKeyboard]; }); [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { @@ -4554,13 +4537,13 @@ typedef enum : NSUInteger { [self updateScrollDownButtonLayout]; } -- (void)handleCalculatingPoWNotification:(NSNotification *)notification +- (void)handleEncryptingMessageNotification:(NSNotification *)notification { NSNumber *timestamp = (NSNumber *)notification.object; [self setProgressIfNeededTo:0.25f forMessageWithTimestamp:timestamp]; } -- (void)handleRoutingNotification:(NSNotification *)notification +- (void)handleCalculatingMessagePoWNotification:(NSNotification *)notification { NSNumber *timestamp = (NSNumber *)notification.object; [self setProgressIfNeededTo:0.50f forMessageWithTimestamp:timestamp]; @@ -4582,7 +4565,7 @@ typedef enum : NSUInteger { }); } -- (void)handleMessageFailedNotification:(NSNotification *)notification +- (void)handleMessageSendingFailedNotification:(NSNotification *)notification { NSNumber *timestamp = (NSNumber *)notification.object; [self hideProgressIndicatorViewForMessageWithTimestamp:timestamp]; @@ -4590,11 +4573,7 @@ typedef enum : NSUInteger { - (void)setProgressIfNeededTo:(float)progress forMessageWithTimestamp:(NSNumber *)timestamp { - if ([self.handledMessageTimestamps contains:^BOOL(NSNumber *t) { - return [t isEqual:timestamp]; - }]) { - return; - } + if ([self.handledMessageTimestamps containsObject:timestamp]) { return; } dispatch_async(dispatch_get_main_queue(), ^{ __block TSInteraction *targetInteraction; [LKStorage readWithBlock:^(YapDatabaseReadTransaction *transaction) { diff --git a/SessionMessagingKit/Messages/Message.swift b/SessionMessagingKit/Messages/Message.swift index 59a8acd17..abfd2887a 100644 --- a/SessionMessagingKit/Messages/Message.swift +++ b/SessionMessagingKit/Messages/Message.swift @@ -47,4 +47,9 @@ public class Message : NSObject, NSCoding { // NSObject/NSCoding conformance is public func toProto() -> SNProtoContent? { preconditionFailure("toProto() is abstract and must be overridden.") } + + // MARK: General + @objc public func setSentTimestamp(_ sentTimestamp: UInt64) { + self.sentTimestamp = sentTimestamp + } } diff --git a/SessionMessagingKit/Sending & Receiving/MessageSender.swift b/SessionMessagingKit/Sending & Receiving/MessageSender.swift index d3263c174..dcb9858dc 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageSender.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageSender.swift @@ -31,7 +31,9 @@ public final class MessageSender : NSObject { } internal static func sendToSnodeDestination(_ destination: Message.Destination, message: Message, using transaction: Any) -> Promise { - message.sentTimestamp = NSDate.millisecondTimestamp() + if message.sentTimestamp == nil { // Visible messages will already have the sent timestamp set + message.sentTimestamp = NSDate.millisecondTimestamp() + } message.sender = Configuration.shared.storage.getUserPublicKey() switch destination { case .contact(let publicKey): message.recipient = publicKey diff --git a/SignalUtilitiesKit/Messaging/TSOutgoingMessage+Conversion.swift b/SignalUtilitiesKit/Messaging/TSOutgoingMessage+Conversion.swift index eba40aaf3..3a9d87941 100644 --- a/SignalUtilitiesKit/Messaging/TSOutgoingMessage+Conversion.swift +++ b/SignalUtilitiesKit/Messaging/TSOutgoingMessage+Conversion.swift @@ -8,10 +8,14 @@ expiration = disappearingMessagesConfiguration.isEnabled ? disappearingMessagesConfiguration.durationSeconds : 0 } return TSOutgoingMessage( + outgoingMessageWithTimestamp: visibleMessage.sentTimestamp!, in: thread, messageBody: visibleMessage.text, - attachmentId: nil, + attachmentIds: NSMutableArray(), expiresInSeconds: expiration, + expireStartedAt: 0, + isVoiceMessage: false, + groupMetaMessage: .unspecified, quotedMessage: nil, linkPreview: nil )