From e20f44024cc1dd14030357659a3488b71154cbdd Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 18 Dec 2017 10:08:52 -0600 Subject: [PATCH] WIP: Support sending attachment captions Looks fine on other clients, but locally we don't display the caption. // FREEBIE --- Signal/src/ViewControllers/DebugUI/DebugUIMessages.m | 2 ++ .../AttachmentApprovalViewController.swift | 11 ++++++----- SignalMessaging/attachments/SignalAttachment.swift | 5 ++++- SignalMessaging/utils/ThreadUtil.m | 2 ++ .../src/Messages/Interactions/TSOutgoingMessage.h | 1 + .../src/Messages/Interactions/TSOutgoingMessage.m | 3 ++- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index 1d27f52f9..66b300f2b 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -1007,6 +1007,7 @@ NS_ASSUME_NONNULL_BEGIN TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread + messageBody:nil isVoiceMessage:NO expiresInSeconds:0]; DDLogError(@"%@ sendFakeMessages outgoing attachment timestamp: %llu.", self.logTag, message.timestamp); @@ -1043,6 +1044,7 @@ NS_ASSUME_NONNULL_BEGIN [TSStorageManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread + messageBody:nil isVoiceMessage:NO expiresInSeconds:0]; DDLogError(@"%@ sendFakeMessages outgoing attachment timestamp: %llu.", self.logTag, message.timestamp); diff --git a/SignalMessaging/attachments/AttachmentApprovalViewController.swift b/SignalMessaging/attachments/AttachmentApprovalViewController.swift index 277654377..72d8ab587 100644 --- a/SignalMessaging/attachments/AttachmentApprovalViewController.swift +++ b/SignalMessaging/attachments/AttachmentApprovalViewController.swift @@ -211,15 +211,15 @@ public class AttachmentApprovalViewController: OWSViewController, MessagingToolb // MARK: MessagingToolbarDelegate - func messagingToolbarDidTapSend(_ messagingToolbar: MessagingToolbar) { - self.sendAttachment() + func messagingToolbarDidTapSend(_ messagingToolbar: MessagingToolbar, captionText: String?) { + self.sendAttachment(captionText: captionText) } func messagingToolbar(_ messagingToolbar: MessagingToolbar, didChangeHeight newHeight: CGFloat) { self.scrollView.contentInset.bottom = newHeight } - func sendAttachment() { + func sendAttachment(captionText: String?) { // disable controls after send was tapped. self.bottomToolbar.isUserInteractionEnabled = false @@ -231,6 +231,7 @@ public class AttachmentApprovalViewController: OWSViewController, MessagingToolb activityIndicatorView.autoCenterInSuperview() activityIndicatorView.startAnimating() + attachment.captionText = captionText self.delegate?.didApproveAttachment(attachment: attachment) } } @@ -325,7 +326,7 @@ private class GradientView: UIView { } protocol MessagingToolbarDelegate: class { - func messagingToolbarDidTapSend(_ messagingToolbar: MessagingToolbar) + func messagingToolbarDidTapSend(_ messagingToolbar: MessagingToolbar, captionText: String?) func messagingToolbar(_ messagingToolbar: MessagingToolbar, didChangeHeight newHeight: CGFloat) } @@ -397,7 +398,7 @@ class MessagingToolbar: UIView, UITextViewDelegate { } func didTapSend() { - self.messagingToolbarDelegate?.messagingToolbarDidTapSend(self) + self.messagingToolbarDelegate?.messagingToolbarDidTapSend(self, captionText: self.textView.text) } // MARK: - UITextViewDelegate diff --git a/SignalMessaging/attachments/SignalAttachment.swift b/SignalMessaging/attachments/SignalAttachment.swift index e410aaf87..cbc700046 100644 --- a/SignalMessaging/attachments/SignalAttachment.swift +++ b/SignalMessaging/attachments/SignalAttachment.swift @@ -108,7 +108,10 @@ public class SignalAttachment: NSObject { // MARK: Properties @objc - let dataSource: DataSource + public let dataSource: DataSource + + @objc + public var captionText: String? @objc public var data: Data { diff --git a/SignalMessaging/utils/ThreadUtil.m b/SignalMessaging/utils/ThreadUtil.m index 46b442664..acd384bc6 100644 --- a/SignalMessaging/utils/ThreadUtil.m +++ b/SignalMessaging/utils/ThreadUtil.m @@ -118,8 +118,10 @@ NS_ASSUME_NONNULL_BEGIN TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread + messageBody:attachment.captionText isVoiceMessage:[attachment isVoiceMessage] expiresInSeconds:(configuration.isEnabled ? configuration.durationSeconds : 0)]; + [messageSender enqueueAttachment:attachment.dataSource contentType:attachment.mimeType sourceFilename:attachment.filenameOrDefault diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h index f151e8a26..aec65fb49 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h @@ -62,6 +62,7 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) { - (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread + messageBody:(nullable NSString *)messageBody isVoiceMessage:(BOOL)isVoiceMessage expiresInSeconds:(uint32_t)expiresInSeconds; diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index 93f39f950..c659c65de 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -123,12 +123,13 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec - (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(nullable TSThread *)thread + messageBody:(nullable NSString *)messageBody isVoiceMessage:(BOOL)isVoiceMessage expiresInSeconds:(uint32_t)expiresInSeconds { self = [self initWithTimestamp:timestamp inThread:thread - messageBody:nil + messageBody:messageBody attachmentIds:[NSMutableArray new] expiresInSeconds:expiresInSeconds expireStartedAt:0];