2014-10-29 21:58:58 +01:00
|
|
|
|
//
|
2018-01-10 16:54:17 +01:00
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2014-10-29 21:58:58 +01:00
|
|
|
|
//
|
|
|
|
|
|
2017-09-22 06:31:13 +02:00
|
|
|
|
#import "ConversationViewController.h"
|
2014-10-29 21:58:58 +01:00
|
|
|
|
#import "AppDelegate.h"
|
2017-04-04 18:35:52 +02:00
|
|
|
|
#import "BlockListUIUtils.h"
|
2017-04-04 21:38:00 +02:00
|
|
|
|
#import "BlockListViewController.h"
|
2017-05-19 19:23:46 +02:00
|
|
|
|
#import "ContactsViewHelper.h"
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#import "ConversationCollectionView.h"
|
|
|
|
|
#import "ConversationHeaderView.h"
|
|
|
|
|
#import "ConversationInputTextView.h"
|
|
|
|
|
#import "ConversationInputToolbar.h"
|
2017-11-21 22:23:42 +01:00
|
|
|
|
#import "ConversationScrollButton.h"
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#import "ConversationViewCell.h"
|
|
|
|
|
#import "ConversationViewItem.h"
|
|
|
|
|
#import "ConversationViewLayout.h"
|
2017-09-27 21:19:50 +02:00
|
|
|
|
#import "DateUtil.h"
|
2017-04-10 03:39:04 +02:00
|
|
|
|
#import "DebugUITableViewController.h"
|
2014-12-04 00:23:36 +01:00
|
|
|
|
#import "FingerprintViewController.h"
|
2017-09-15 21:28:44 +02:00
|
|
|
|
#import "NSAttributedString+OWS.h"
|
2017-09-22 06:31:13 +02:00
|
|
|
|
#import "NewGroupViewController.h"
|
2018-02-23 21:44:46 +01:00
|
|
|
|
#import "OWSAudioPlayer.h"
|
2017-08-18 16:48:48 +02:00
|
|
|
|
#import "OWSContactOffersCell.h"
|
2017-08-01 22:16:33 +02:00
|
|
|
|
#import "OWSConversationSettingsViewController.h"
|
2017-04-28 18:18:42 +02:00
|
|
|
|
#import "OWSConversationSettingsViewDelegate.h"
|
2016-09-21 14:37:51 +02:00
|
|
|
|
#import "OWSDisappearingMessagesJob.h"
|
2017-10-25 00:27:07 +02:00
|
|
|
|
#import "OWSMath.h"
|
2017-10-17 06:05:29 +02:00
|
|
|
|
#import "OWSMessageCell.h"
|
2017-06-02 21:49:34 +02:00
|
|
|
|
#import "OWSSystemMessageCell.h"
|
2017-05-16 17:26:01 +02:00
|
|
|
|
#import "OWSUnreadIndicatorCell.h"
|
2016-11-01 20:02:15 +01:00
|
|
|
|
#import "Signal-Swift.h"
|
2014-12-24 02:25:10 +01:00
|
|
|
|
#import "SignalKeyingStorage.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
|
#import "TSAttachmentPointer.h"
|
2016-09-02 16:22:06 +02:00
|
|
|
|
#import "TSCall.h"
|
2016-09-11 22:53:12 +02:00
|
|
|
|
#import "TSContactThread.h"
|
2014-11-25 16:38:33 +01:00
|
|
|
|
#import "TSDatabaseView.h"
|
2014-12-11 00:05:41 +01:00
|
|
|
|
#import "TSErrorMessage.h"
|
2016-09-21 14:37:51 +02:00
|
|
|
|
#import "TSGroupThread.h"
|
2014-12-06 17:45:42 +01:00
|
|
|
|
#import "TSIncomingMessage.h"
|
2016-09-02 16:22:06 +02:00
|
|
|
|
#import "TSInfoMessage.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
|
#import "TSInvalidIdentityKeyErrorMessage.h"
|
2015-12-26 17:27:27 +01:00
|
|
|
|
#import "UIFont+OWS.h"
|
2017-11-07 16:32:28 +01:00
|
|
|
|
#import "UIViewController+Permissions.h"
|
2017-04-13 19:43:09 +02:00
|
|
|
|
#import "ViewControllerUtils.h"
|
2017-09-22 06:31:13 +02:00
|
|
|
|
#import <AVFoundation/AVFoundation.h>
|
2016-09-02 16:22:06 +02:00
|
|
|
|
#import <AddressBookUI/AddressBookUI.h>
|
2017-04-13 18:55:21 +02:00
|
|
|
|
#import <AssetsLibrary/AssetsLibrary.h>
|
2016-09-02 16:22:06 +02:00
|
|
|
|
#import <ContactsUI/CNContactViewController.h>
|
|
|
|
|
#import <JSQMessagesViewController/JSQMessagesBubbleImage.h>
|
|
|
|
|
#import <JSQMessagesViewController/JSQMessagesBubbleImageFactory.h>
|
|
|
|
|
#import <JSQMessagesViewController/JSQMessagesCollectionViewFlowLayoutInvalidationContext.h>
|
2017-06-01 03:12:27 +02:00
|
|
|
|
#import <JSQMessagesViewController/JSQMessagesCollectionViewLayoutAttributes.h>
|
2016-09-02 16:22:06 +02:00
|
|
|
|
#import <JSQMessagesViewController/JSQMessagesTimestampFormatter.h>
|
|
|
|
|
#import <JSQMessagesViewController/JSQSystemSoundPlayer+JSQMessages.h>
|
|
|
|
|
#import <JSQMessagesViewController/UIColor+JSQMessages.h>
|
2017-11-28 00:17:46 +01:00
|
|
|
|
#import <JSQSystemSoundPlayer/JSQSystemSoundPlayer.h>
|
2016-09-02 16:22:06 +02:00
|
|
|
|
#import <MobileCoreServices/UTCoreTypes.h>
|
2017-12-12 02:16:08 +01:00
|
|
|
|
#import <PromiseKit/AnyPromise.h>
|
2017-12-19 03:50:51 +01:00
|
|
|
|
#import <SignalMessaging/Environment.h>
|
|
|
|
|
#import <SignalMessaging/NSString+OWS.h>
|
2017-12-08 17:50:35 +01:00
|
|
|
|
#import <SignalMessaging/OWSContactOffersInteraction.h>
|
2017-12-19 03:50:51 +01:00
|
|
|
|
#import <SignalMessaging/OWSContactsManager.h>
|
2017-12-01 23:10:14 +01:00
|
|
|
|
#import <SignalMessaging/OWSFormat.h>
|
2017-12-08 19:45:24 +01:00
|
|
|
|
#import <SignalMessaging/OWSUserProfile.h>
|
2017-12-08 17:50:35 +01:00
|
|
|
|
#import <SignalMessaging/TSUnreadIndicatorInteraction.h>
|
|
|
|
|
#import <SignalMessaging/ThreadUtil.h>
|
|
|
|
|
#import <SignalMessaging/UIUtil.h>
|
2018-03-01 20:42:54 +01:00
|
|
|
|
#import <SignalMessaging/UIViewController+OWS.h>
|
2017-01-26 19:39:13 +01:00
|
|
|
|
#import <SignalServiceKit/ContactsUpdater.h>
|
2016-09-02 16:22:06 +02:00
|
|
|
|
#import <SignalServiceKit/MimeTypeUtil.h>
|
2017-07-21 17:49:38 +02:00
|
|
|
|
#import <SignalServiceKit/NSDate+OWS.h>
|
2017-05-09 20:39:15 +02:00
|
|
|
|
#import <SignalServiceKit/NSTimer+OWS.h>
|
2017-05-19 19:23:46 +02:00
|
|
|
|
#import <SignalServiceKit/OWSAddToContactsOfferMessage.h>
|
2017-08-03 23:43:21 +02:00
|
|
|
|
#import <SignalServiceKit/OWSAddToProfileWhitelistOfferMessage.h>
|
2016-10-14 22:59:58 +02:00
|
|
|
|
#import <SignalServiceKit/OWSAttachmentsProcessor.h>
|
2017-04-04 18:35:52 +02:00
|
|
|
|
#import <SignalServiceKit/OWSBlockingManager.h>
|
2016-09-21 14:37:51 +02:00
|
|
|
|
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
|
2017-06-09 19:12:33 +02:00
|
|
|
|
#import <SignalServiceKit/OWSIdentityManager.h>
|
2017-09-14 17:00:30 +02:00
|
|
|
|
#import <SignalServiceKit/OWSMessageManager.h>
|
2016-10-14 22:59:58 +02:00
|
|
|
|
#import <SignalServiceKit/OWSMessageSender.h>
|
2018-01-30 21:49:36 +01:00
|
|
|
|
#import <SignalServiceKit/OWSMessageUtils.h>
|
2017-09-15 21:28:44 +02:00
|
|
|
|
#import <SignalServiceKit/OWSReadReceiptManager.h>
|
2017-06-07 22:51:22 +02:00
|
|
|
|
#import <SignalServiceKit/OWSVerificationStateChangeMessage.h>
|
2016-09-02 16:22:06 +02:00
|
|
|
|
#import <SignalServiceKit/SignalRecipient.h>
|
|
|
|
|
#import <SignalServiceKit/TSAccountManager.h>
|
2017-05-30 19:04:43 +02:00
|
|
|
|
#import <SignalServiceKit/TSGroupModel.h>
|
2017-06-08 05:30:51 +02:00
|
|
|
|
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
|
2016-10-14 22:59:58 +02:00
|
|
|
|
#import <SignalServiceKit/TSNetworkManager.h>
|
2018-04-04 03:22:02 +02:00
|
|
|
|
#import <SignalServiceKit/TSQuotedMessage.h>
|
2017-09-22 06:31:13 +02:00
|
|
|
|
#import <SignalServiceKit/Threading.h>
|
2017-12-20 17:28:07 +01:00
|
|
|
|
#import <YapDatabase/YapDatabase.h>
|
2017-12-15 17:16:07 +01:00
|
|
|
|
#import <YapDatabase/YapDatabaseViewChange.h>
|
|
|
|
|
#import <YapDatabase/YapDatabaseViewConnection.h>
|
2014-12-31 13:22:40 +01:00
|
|
|
|
|
2016-07-22 02:15:34 +02:00
|
|
|
|
@import Photos;
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
2017-05-26 18:59:31 +02:00
|
|
|
|
// Always load up to 50 messages when user arrives.
|
2017-05-26 00:00:41 +02:00
|
|
|
|
static const int kYapDatabasePageSize = 50;
|
2017-08-16 21:56:10 +02:00
|
|
|
|
// Never show more than 50*500 = 25k messages in conversation view at a time.
|
|
|
|
|
static const int kYapDatabaseMaxPageCount = 500;
|
2017-05-26 00:00:41 +02:00
|
|
|
|
// Never show more than 6*50 = 300 messages in conversation view when user
|
|
|
|
|
// arrives.
|
2017-11-17 21:10:08 +01:00
|
|
|
|
static const int kYapDatabaseMaxInitialPageCount = 6;
|
2017-09-02 00:16:46 +02:00
|
|
|
|
static const int kConversationInitialMaxRangeSize = kYapDatabasePageSize * kYapDatabaseMaxInitialPageCount;
|
2017-05-26 00:00:41 +02:00
|
|
|
|
static const int kYapDatabaseRangeMaxLength = kYapDatabasePageSize * kYapDatabaseMaxPageCount;
|
|
|
|
|
static const int kYapDatabaseRangeMinLength = 0;
|
2016-11-12 18:22:29 +01:00
|
|
|
|
|
2017-10-16 02:46:48 +02:00
|
|
|
|
static const CGFloat kLoadMoreHeaderHeight = 60.f;
|
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
|
typedef enum : NSUInteger {
|
|
|
|
|
kMediaTypePicture,
|
|
|
|
|
kMediaTypeVideo,
|
|
|
|
|
} kMediaTypes;
|
|
|
|
|
|
2017-05-23 17:28:59 +02:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
2018-01-16 23:55:53 +01:00
|
|
|
|
@interface ConversationViewController () <AttachmentApprovalViewControllerDelegate,
|
|
|
|
|
AVAudioPlayerDelegate,
|
2017-05-31 20:22:32 +02:00
|
|
|
|
ContactsViewHelperDelegate,
|
|
|
|
|
ContactEditingDelegate,
|
|
|
|
|
CNContactViewControllerDelegate,
|
2018-01-20 17:27:32 +01:00
|
|
|
|
DisappearingTimerConfigurationViewDelegate,
|
2017-05-31 20:22:32 +02:00
|
|
|
|
OWSConversationSettingsViewDelegate,
|
2017-10-10 22:13:54 +02:00
|
|
|
|
ConversationViewLayoutDelegate,
|
|
|
|
|
ConversationViewCellDelegate,
|
|
|
|
|
ConversationInputTextViewDelegate,
|
|
|
|
|
UICollectionViewDelegate,
|
|
|
|
|
UICollectionViewDataSource,
|
2017-04-20 23:51:45 +02:00
|
|
|
|
UIDocumentMenuDelegate,
|
2017-05-19 19:23:46 +02:00
|
|
|
|
UIDocumentPickerDelegate,
|
2017-05-31 20:22:32 +02:00
|
|
|
|
UIImagePickerControllerDelegate,
|
|
|
|
|
UINavigationControllerDelegate,
|
2017-08-30 22:18:42 +02:00
|
|
|
|
UITextViewDelegate,
|
2017-10-10 22:13:54 +02:00
|
|
|
|
ConversationCollectionViewDelegate,
|
|
|
|
|
ConversationInputToolbarDelegate,
|
2017-10-01 03:04:36 +02:00
|
|
|
|
GifPickerViewControllerDelegate>
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
2017-10-24 19:25:17 +02:00
|
|
|
|
// Show message info animation
|
|
|
|
|
@property (nullable, nonatomic) UIPercentDrivenInteractiveTransition *showMessageDetailsTransition;
|
|
|
|
|
@property (nullable, nonatomic) UIPanGestureRecognizer *currentShowMessageDetailsPanGesture;
|
|
|
|
|
|
2017-03-15 14:23:21 +01:00
|
|
|
|
@property (nonatomic) TSThread *thread;
|
|
|
|
|
@property (nonatomic) YapDatabaseConnection *editingDatabaseConnection;
|
2018-02-16 21:32:29 +01:00
|
|
|
|
@property (nonatomic, readonly) AudioActivity *voiceNoteAudioActivity;
|
2017-08-16 17:40:43 +02:00
|
|
|
|
|
|
|
|
|
// These two properties must be updated in lockstep.
|
|
|
|
|
//
|
2017-08-16 21:32:56 +02:00
|
|
|
|
// * The first (required) step is to update uiDatabaseConnection using beginLongLivedReadTransaction.
|
|
|
|
|
// * The second (required) step is to update messageMappings.
|
|
|
|
|
// * The third (optional) step is to update the messageMappings range using
|
|
|
|
|
// updateMessageMappingRangeOptions.
|
2017-10-19 15:53:35 +02:00
|
|
|
|
// * The fourth (optional) step is to update the view items using reloadViewItems.
|
2017-08-16 21:32:56 +02:00
|
|
|
|
// * The steps must be done in strict order.
|
|
|
|
|
// * If we do any of the steps, we must do all of the required steps.
|
2017-10-19 15:53:35 +02:00
|
|
|
|
// * We can't use messageMappings or viewItems after the first step until we've
|
|
|
|
|
// done the last step; i.e.. we can't do any layout, since that uses the view
|
|
|
|
|
// items which haven't been updated yet.
|
|
|
|
|
// * If the first and/or second steps changes the set of messages
|
|
|
|
|
// their ordering and/or their state, we must do the third and fourth steps.
|
2017-08-16 21:32:56 +02:00
|
|
|
|
// * If we do the third step, we must call resetContentAndLayout afterward.
|
2017-03-15 14:23:21 +01:00
|
|
|
|
@property (nonatomic) YapDatabaseConnection *uiDatabaseConnection;
|
|
|
|
|
@property (nonatomic) YapDatabaseViewMappings *messageMappings;
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
@property (nonatomic, readonly) ConversationInputToolbar *inputToolbar;
|
|
|
|
|
@property (nonatomic, readonly) ConversationCollectionView *collectionView;
|
2017-10-11 20:45:02 +02:00
|
|
|
|
@property (nonatomic, readonly) ConversationViewLayout *layout;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
@property (nonatomic) NSArray<ConversationViewItem *> *viewItems;
|
2017-11-22 19:06:54 +01:00
|
|
|
|
@property (nonatomic) NSMutableDictionary<NSString *, ConversationViewItem *> *viewItemCache;
|
2017-09-28 21:27:17 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
@property (nonatomic, nullable) AVAudioRecorder *audioRecorder;
|
2018-02-23 21:44:46 +01:00
|
|
|
|
@property (nonatomic, nullable) OWSAudioPlayer *audioAttachmentPlayer;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
@property (nonatomic, nullable) NSUUID *voiceMessageUUID;
|
2017-03-15 14:23:21 +01:00
|
|
|
|
|
2017-10-16 17:01:13 +02:00
|
|
|
|
@property (nonatomic, nullable) NSTimer *readTimer;
|
2017-10-18 21:11:19 +02:00
|
|
|
|
@property (nonatomic) NSCache *cellMediaCache;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
@property (nonatomic) ConversationHeaderView *navigationBarTitleView;
|
2017-03-15 14:23:21 +01:00
|
|
|
|
@property (nonatomic) UILabel *navigationBarTitleLabel;
|
|
|
|
|
@property (nonatomic) UILabel *navigationBarSubtitleLabel;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
@property (nonatomic, nullable) UIView *bannerView;
|
2017-10-25 04:02:27 +02:00
|
|
|
|
@property (nonatomic, nullable) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
|
2014-12-06 23:21:15 +01:00
|
|
|
|
|
2017-04-09 21:31:31 +02:00
|
|
|
|
// Back Button Unread Count
|
|
|
|
|
@property (nonatomic, readonly) UIView *backButtonUnreadCountView;
|
|
|
|
|
@property (nonatomic, readonly) UILabel *backButtonUnreadCountLabel;
|
|
|
|
|
@property (nonatomic, readonly) NSUInteger backButtonUnreadCount;
|
|
|
|
|
|
2018-02-22 00:37:19 +01:00
|
|
|
|
@property (nonatomic) NSUInteger lastRangeLength;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
@property (nonatomic) BOOL composeOnOpen;
|
2017-04-18 22:08:01 +02:00
|
|
|
|
@property (nonatomic) BOOL callOnOpen;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
@property (nonatomic) BOOL peek;
|
2015-01-31 12:00:58 +01:00
|
|
|
|
|
2016-09-11 22:53:12 +02:00
|
|
|
|
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
|
2016-10-14 22:59:58 +02:00
|
|
|
|
@property (nonatomic, readonly) ContactsUpdater *contactsUpdater;
|
2016-11-01 20:02:15 +01:00
|
|
|
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
2018-03-05 15:30:58 +01:00
|
|
|
|
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
|
2016-10-14 22:59:58 +02:00
|
|
|
|
@property (nonatomic, readonly) TSNetworkManager *networkManager;
|
2017-02-02 00:26:47 +01:00
|
|
|
|
@property (nonatomic, readonly) OutboundCallInitiator *outboundCallInitiator;
|
2017-04-04 18:35:52 +02:00
|
|
|
|
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
|
2016-04-13 19:05:09 +02:00
|
|
|
|
|
2017-04-05 00:08:51 +02:00
|
|
|
|
@property (nonatomic) BOOL userHasScrolled;
|
2017-10-12 22:19:07 +02:00
|
|
|
|
@property (nonatomic, nullable) NSDate *lastMessageSentDate;
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
@property (nonatomic, nullable) ThreadDynamicInteractions *dynamicInteractions;
|
2017-05-19 21:19:51 +02:00
|
|
|
|
@property (nonatomic) BOOL hasClearedUnreadMessagesIndicator;
|
2017-10-16 02:46:48 +02:00
|
|
|
|
@property (nonatomic) BOOL showLoadMoreHeader;
|
2017-11-16 22:43:41 +01:00
|
|
|
|
@property (nonatomic) UILabel *loadMoreHeader;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
@property (nonatomic) uint64_t lastVisibleTimestamp;
|
2017-05-19 21:19:51 +02:00
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
@property (nonatomic, readonly) BOOL isGroupConversation;
|
|
|
|
|
@property (nonatomic) BOOL isUserScrolling;
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
@property (nonatomic) NSLayoutConstraint *scrollDownButtonButtomConstraint;
|
|
|
|
|
|
2017-11-21 22:23:42 +01:00
|
|
|
|
@property (nonatomic) ConversationScrollButton *scrollDownButton;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#ifdef DEBUG
|
2017-11-21 22:23:42 +01:00
|
|
|
|
@property (nonatomic) ConversationScrollButton *scrollUpButton;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#endif
|
2017-05-19 19:23:46 +02:00
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
@property (nonatomic) BOOL isViewCompletelyAppeared;
|
2017-07-25 18:52:30 +02:00
|
|
|
|
@property (nonatomic) BOOL isViewVisible;
|
|
|
|
|
@property (nonatomic) BOOL isAppInBackground;
|
|
|
|
|
@property (nonatomic) BOOL shouldObserveDBModifications;
|
2017-08-29 17:12:20 +02:00
|
|
|
|
@property (nonatomic) BOOL viewHasEverAppeared;
|
2017-11-21 22:23:42 +01:00
|
|
|
|
@property (nonatomic) BOOL hasUnreadMessages;
|
2018-01-29 22:35:31 +01:00
|
|
|
|
@property (nonatomic) BOOL isPickingMediaAsDocument;
|
2018-02-22 00:37:19 +01:00
|
|
|
|
@property (nonatomic, nullable) NSNumber *previousLastTimestamp;
|
2018-02-22 17:03:53 +01:00
|
|
|
|
@property (nonatomic, nullable) NSNumber *viewHorizonTimestamp;
|
2017-07-25 18:52:30 +02:00
|
|
|
|
|
2015-05-23 15:54:50 +02:00
|
|
|
|
@end
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
2017-09-06 20:13:18 +02:00
|
|
|
|
@implementation ConversationViewController
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder
|
2016-09-11 22:53:12 +02:00
|
|
|
|
{
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSFail(@"Do not instantiate this view from coder");
|
2016-09-11 22:53:12 +02:00
|
|
|
|
|
|
|
|
|
self = [super initWithCoder:aDecoder];
|
|
|
|
|
if (!self) {
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 20:02:15 +01:00
|
|
|
|
[self commonInit];
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-03-10 14:56:12 +01:00
|
|
|
|
return self;
|
|
|
|
|
}
|
2016-11-01 20:02:15 +01:00
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil
|
|
|
|
|
{
|
2017-03-10 14:56:12 +01:00
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
|
if (!self) {
|
|
|
|
|
return self;
|
|
|
|
|
}
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-03-10 14:56:12 +01:00
|
|
|
|
[self commonInit];
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2016-11-01 20:02:15 +01:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)commonInit
|
|
|
|
|
{
|
2017-12-04 16:35:47 +01:00
|
|
|
|
_contactsManager = [Environment current].contactsManager;
|
|
|
|
|
_contactsUpdater = [Environment current].contactsUpdater;
|
|
|
|
|
_messageSender = [Environment current].messageSender;
|
|
|
|
|
_outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator;
|
2018-03-05 15:30:58 +01:00
|
|
|
|
_primaryStorage = [OWSPrimaryStorage sharedManager];
|
2016-10-14 22:59:58 +02:00
|
|
|
|
_networkManager = [TSNetworkManager sharedManager];
|
2017-04-04 18:35:52 +02:00
|
|
|
|
_blockingManager = [OWSBlockingManager sharedManager];
|
2017-05-19 19:23:46 +02:00
|
|
|
|
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
|
2018-02-16 21:32:29 +01:00
|
|
|
|
NSString *audioActivityDescription = [NSString stringWithFormat:@"%@ voice note", self.logTag];
|
|
|
|
|
_voiceNoteAudioActivity = [[AudioActivity alloc] initWithAudioDescription:audioActivityDescription];
|
2017-04-04 18:35:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)addNotificationListeners
|
|
|
|
|
{
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(blockedPhoneNumbersDidChange:)
|
|
|
|
|
name:kNSNotificationName_BlockedPhoneNumbersDidChange
|
|
|
|
|
object:nil];
|
2017-06-09 19:12:33 +02:00
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(identityStateDidChange:)
|
|
|
|
|
name:kNSNotificationName_IdentityStateDidChange
|
|
|
|
|
object:nil];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(didChangePreferredContentSize:)
|
|
|
|
|
name:UIContentSizeCategoryDidChangeNotification
|
|
|
|
|
object:nil];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(yapDatabaseModified:)
|
|
|
|
|
name:YapDatabaseModifiedNotification
|
2018-03-05 15:30:58 +01:00
|
|
|
|
object:OWSPrimaryStorage.sharedManager.dbNotificationObject];
|
2017-11-29 17:37:49 +01:00
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
2017-12-12 22:31:03 +01:00
|
|
|
|
selector:@selector(yapDatabaseModifiedExternally:)
|
2017-11-29 17:37:49 +01:00
|
|
|
|
name:YapDatabaseModifiedExternallyNotification
|
2018-01-11 16:04:03 +01:00
|
|
|
|
object:nil];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(applicationWillEnterForeground:)
|
2018-01-10 16:54:17 +01:00
|
|
|
|
name:OWSApplicationWillEnterForegroundNotification
|
2017-07-25 18:52:30 +02:00
|
|
|
|
object:nil];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(applicationDidEnterBackground:)
|
2018-01-10 16:54:17 +01:00
|
|
|
|
name:OWSApplicationDidEnterBackgroundNotification
|
2017-07-25 18:52:30 +02:00
|
|
|
|
object:nil];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(applicationWillResignActive:)
|
2018-01-10 16:54:17 +01:00
|
|
|
|
name:OWSApplicationWillResignActiveNotification
|
2017-07-25 18:52:30 +02:00
|
|
|
|
object:nil];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(cancelReadTimer)
|
2018-01-10 16:54:17 +01:00
|
|
|
|
name:OWSApplicationDidEnterBackgroundNotification
|
2017-07-25 18:52:30 +02:00
|
|
|
|
object:nil];
|
2017-08-17 00:09:47 +02:00
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(otherUsersProfileDidChange:)
|
|
|
|
|
name:kNSNotificationName_OtherUsersProfileDidChange
|
|
|
|
|
object:nil];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(profileWhitelistDidChange:)
|
|
|
|
|
name:kNSNotificationName_ProfileWhitelistDidChange
|
|
|
|
|
object:nil];
|
2017-09-29 22:38:57 +02:00
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(signalAccountsDidChange:)
|
|
|
|
|
name:OWSContactsManagerSignalAccountsDidChangeNotification
|
|
|
|
|
object:nil];
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(keyboardWillChangeFrame:)
|
|
|
|
|
name:UIKeyboardWillChangeFrameNotification
|
|
|
|
|
object:nil];
|
2017-08-17 00:09:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-29 22:38:57 +02:00
|
|
|
|
- (void)signalAccountsDidChange:(NSNotification *)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-09-29 22:38:57 +02:00
|
|
|
|
|
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-17 00:09:47 +02:00
|
|
|
|
- (void)otherUsersProfileDidChange:(NSNotification *)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-08-17 00:09:47 +02:00
|
|
|
|
|
2017-08-21 23:27:30 +02:00
|
|
|
|
NSString *recipientId = notification.userInfo[kNSNotificationKey_ProfileRecipientId];
|
2017-08-17 00:09:47 +02:00
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
if (recipientId.length > 0 && [self.thread.recipientIdentifiers containsObject:recipientId]) {
|
2017-08-23 22:41:31 +02:00
|
|
|
|
if ([self.thread isKindOfClass:[TSContactThread class]]) {
|
|
|
|
|
// update title with profile name
|
|
|
|
|
[self setNavigationTitle];
|
|
|
|
|
}
|
2017-09-06 20:13:18 +02:00
|
|
|
|
|
2017-10-16 18:29:22 +02:00
|
|
|
|
if (self.isGroupConversation) {
|
|
|
|
|
// Reload all cells if this is a group conversation,
|
|
|
|
|
// since we may need to update the sender names on the messages.
|
|
|
|
|
[self resetContentAndLayout];
|
|
|
|
|
}
|
2017-08-17 00:09:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)profileWhitelistDidChange:(NSNotification *)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-08-17 00:09:47 +02:00
|
|
|
|
|
|
|
|
|
// If profile whitelist just changed, we may want to hide a profile whitelist offer.
|
2017-08-21 23:27:30 +02:00
|
|
|
|
NSString *_Nullable recipientId = notification.userInfo[kNSNotificationKey_ProfileRecipientId];
|
|
|
|
|
NSData *_Nullable groupId = notification.userInfo[kNSNotificationKey_ProfileGroupId];
|
2017-08-17 00:09:47 +02:00
|
|
|
|
if (recipientId.length > 0 && [self.thread.recipientIdentifiers containsObject:recipientId]) {
|
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
} else if (groupId.length > 0 && self.thread.isGroupThread) {
|
|
|
|
|
TSGroupThread *groupThread = (TSGroupThread *)self.thread;
|
|
|
|
|
if ([groupThread.groupModel.groupId isEqualToData:groupId]) {
|
|
|
|
|
[self ensureDynamicInteractions];
|
2017-08-23 22:34:30 +02:00
|
|
|
|
[self ensureBannerState];
|
2017-08-17 00:09:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-04 18:35:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)blockedPhoneNumbersDidChange:(id)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-06-09 22:21:59 +02:00
|
|
|
|
|
|
|
|
|
[self ensureBannerState];
|
2016-09-11 22:53:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 19:12:33 +02:00
|
|
|
|
- (void)identityStateDidChange:(NSNotification *)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-06-09 19:12:33 +02:00
|
|
|
|
|
|
|
|
|
[self updateNavigationBarSubtitleLabel];
|
2017-06-09 22:21:59 +02:00
|
|
|
|
[self ensureBannerState];
|
2017-06-09 19:12:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)peekSetup
|
|
|
|
|
{
|
2015-10-31 16:53:32 +01:00
|
|
|
|
_peek = YES;
|
|
|
|
|
[self setComposeOnOpen:NO];
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)popped
|
|
|
|
|
{
|
2015-10-31 16:53:32 +01:00
|
|
|
|
_peek = NO;
|
|
|
|
|
[self hideInputIfNeeded];
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 22:08:01 +02:00
|
|
|
|
- (void)configureForThread:(TSThread *)thread
|
|
|
|
|
keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
|
|
|
|
|
callOnViewAppearing:(BOOL)callOnViewAppearing
|
|
|
|
|
{
|
2017-09-18 22:12:51 +02:00
|
|
|
|
// At most one.
|
|
|
|
|
OWSAssert(!keyboardOnViewAppearing || !callOnViewAppearing);
|
|
|
|
|
|
2017-04-18 22:08:01 +02:00
|
|
|
|
if (callOnViewAppearing) {
|
|
|
|
|
keyboardOnViewAppearing = NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_thread = thread;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
_isGroupConversation = [self.thread isKindOfClass:[TSGroupThread class]];
|
2017-04-18 22:08:01 +02:00
|
|
|
|
_composeOnOpen = keyboardOnViewAppearing;
|
|
|
|
|
_callOnOpen = callOnViewAppearing;
|
2017-10-18 21:11:19 +02:00
|
|
|
|
_cellMediaCache = [NSCache new];
|
|
|
|
|
// Cache the cell media for ~24 cells.
|
|
|
|
|
self.cellMediaCache.countLimit = 24;
|
2014-11-26 16:00:10 +01:00
|
|
|
|
|
2015-12-26 17:27:27 +01:00
|
|
|
|
[self.uiDatabaseConnection beginLongLivedReadTransaction];
|
2017-08-31 18:31:13 +02:00
|
|
|
|
|
2017-09-02 00:19:51 +02:00
|
|
|
|
// We need to update the "unread indicator" _before_ we determine the initial range
|
|
|
|
|
// size, since it depends on where the unread indicator is placed.
|
2018-02-22 00:37:19 +01:00
|
|
|
|
self.lastRangeLength = 0;
|
2017-09-02 00:16:46 +02:00
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
|
2017-08-31 18:31:13 +02:00
|
|
|
|
if (thread.uniqueId.length > 0) {
|
|
|
|
|
self.messageMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ]
|
|
|
|
|
view:TSMessageDatabaseViewExtensionName];
|
|
|
|
|
} else {
|
|
|
|
|
OWSFail(@"uniqueId unexpectedly empty for thread: %@", thread);
|
|
|
|
|
self.messageMappings =
|
|
|
|
|
[[YapDatabaseViewMappings alloc] initWithGroups:@[] view:TSMessageDatabaseViewExtensionName];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-26 18:39:43 +02:00
|
|
|
|
// We need to impose the range restrictions on the mappings immediately to avoid
|
|
|
|
|
// doing a great deal of unnecessary work and causing a perf hotspot.
|
2015-12-26 17:27:27 +01:00
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[self.messageMappings updateWithTransaction:transaction];
|
2015-12-26 17:27:27 +01:00
|
|
|
|
}];
|
2018-02-22 00:37:19 +01:00
|
|
|
|
[self updateMessageMappingRangeOptions];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
[self updateShouldObserveDBModifications];
|
2015-05-23 15:54:50 +02:00
|
|
|
|
}
|
2015-01-14 22:30:01 +01:00
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
|
- (BOOL)userLeftGroup
|
|
|
|
|
{
|
|
|
|
|
if (![_thread isKindOfClass:[TSGroupThread class]]) {
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSGroupThread *groupThread = (TSGroupThread *)self.thread;
|
|
|
|
|
return ![groupThread.groupModel.groupMemberIds containsObject:[TSAccountManager localNumber]];
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)hideInputIfNeeded
|
|
|
|
|
{
|
2015-10-31 16:53:32 +01:00
|
|
|
|
if (_peek) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
self.inputToolbar.hidden = YES;
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2015-10-31 16:53:32 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
|
if (self.userLeftGroup) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
self.inputToolbar.hidden = YES; // user has requested they leave the group. further sends disallowed
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2015-03-01 00:04:39 +01:00
|
|
|
|
} else {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
self.inputToolbar.hidden = NO;
|
2015-01-27 02:20:11 +01:00
|
|
|
|
}
|
2015-01-14 22:30:01 +01:00
|
|
|
|
}
|
2015-01-31 12:00:58 +01:00
|
|
|
|
|
2016-07-13 21:17:09 +02:00
|
|
|
|
- (void)viewDidLoad
|
|
|
|
|
{
|
2015-01-22 05:08:12 +01:00
|
|
|
|
[super viewDidLoad];
|
2016-07-22 09:05:24 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self createContents];
|
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self registerCellClasses];
|
|
|
|
|
|
2017-11-21 22:23:42 +01:00
|
|
|
|
[self createConversationScrollButtons];
|
2017-07-27 17:43:31 +02:00
|
|
|
|
[self createHeaderViews];
|
2017-10-25 00:47:19 +02:00
|
|
|
|
[self createBackButton];
|
2017-09-13 23:16:32 +02:00
|
|
|
|
[self addNotificationListeners];
|
2017-11-01 17:01:42 +01:00
|
|
|
|
[self loadDraftInCompose];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 00:36:57 +01:00
|
|
|
|
- (void)loadView
|
|
|
|
|
{
|
|
|
|
|
[super loadView];
|
|
|
|
|
|
2018-01-17 21:38:36 +01:00
|
|
|
|
self.view.backgroundColor = [UIColor ows_toolbarBackgroundColor];
|
2017-11-08 00:36:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)createContents
|
|
|
|
|
{
|
2017-10-11 20:45:02 +02:00
|
|
|
|
_layout = [ConversationViewLayout new];
|
|
|
|
|
self.layout.delegate = self;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
// We use the root view bounds as the initial frame for the collection
|
|
|
|
|
// view so that its contents can be laid out immediately.
|
2017-10-11 20:45:02 +02:00
|
|
|
|
_collectionView =
|
|
|
|
|
[[ConversationCollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:self.layout];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
self.collectionView.layoutDelegate = self;
|
|
|
|
|
self.collectionView.delegate = self;
|
|
|
|
|
self.collectionView.dataSource = self;
|
2017-10-18 01:53:55 +02:00
|
|
|
|
self.collectionView.showsVerticalScrollIndicator = YES;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
self.collectionView.showsHorizontalScrollIndicator = NO;
|
2018-01-02 22:55:40 +01:00
|
|
|
|
self.collectionView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
self.collectionView.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
[self.view addSubview:self.collectionView];
|
|
|
|
|
[self.collectionView autoPinWidthToSuperview];
|
|
|
|
|
[self.collectionView autoPinToTopLayoutGuideOfViewController:self withInset:0];
|
|
|
|
|
|
2017-11-20 22:01:59 +01:00
|
|
|
|
// Fix a bug that only affects iOS 11.0.x and 11.1.x.
|
|
|
|
|
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0) && !SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 2)) {
|
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
|
#pragma clang diagnostic ignored "-Wpartial-availability"
|
|
|
|
|
self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
_inputToolbar = [ConversationInputToolbar new];
|
|
|
|
|
self.inputToolbar.inputToolbarDelegate = self;
|
|
|
|
|
self.inputToolbar.inputTextViewDelegate = self;
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self.collectionView autoPinToBottomLayoutGuideOfViewController:self withInset:0];
|
2017-10-16 02:46:48 +02:00
|
|
|
|
|
2017-11-16 22:43:41 +01:00
|
|
|
|
self.loadMoreHeader = [UILabel new];
|
|
|
|
|
self.loadMoreHeader.text = NSLocalizedString(@"CONVERSATION_VIEW_LOADING_MORE_MESSAGES",
|
|
|
|
|
@"Indicates that the app is loading more messages in this conversation.");
|
|
|
|
|
self.loadMoreHeader.textColor = [UIColor ows_materialBlueColor];
|
2017-11-21 18:15:10 +01:00
|
|
|
|
self.loadMoreHeader.textAlignment = NSTextAlignmentCenter;
|
2017-11-16 22:43:41 +01:00
|
|
|
|
self.loadMoreHeader.font = [UIFont ows_mediumFontWithSize:16.f];
|
2017-10-16 02:46:48 +02:00
|
|
|
|
[self.collectionView addSubview:self.loadMoreHeader];
|
|
|
|
|
[self.loadMoreHeader autoPinWidthToWidthOfView:self.view];
|
|
|
|
|
[self.loadMoreHeader autoPinEdgeToSuperviewEdge:ALEdgeTop];
|
|
|
|
|
[self.loadMoreHeader autoSetDimension:ALDimensionHeight toSize:kLoadMoreHeaderHeight];
|
2016-07-09 00:25:28 +02:00
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2018-02-22 14:57:58 +01:00
|
|
|
|
- (BOOL)becomeFirstResponder
|
|
|
|
|
{
|
|
|
|
|
DDLogDebug(@"%@ in %s", self.logTag, __PRETTY_FUNCTION__);
|
|
|
|
|
return [super becomeFirstResponder];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)resignFirstResponder
|
|
|
|
|
{
|
|
|
|
|
DDLogDebug(@"%@ in %s", self.logTag, __PRETTY_FUNCTION__);
|
|
|
|
|
return [super resignFirstResponder];
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
- (BOOL)canBecomeFirstResponder
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable UIView *)inputAccessoryView
|
|
|
|
|
{
|
|
|
|
|
return self.inputToolbar;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)registerCellClasses
|
2016-07-09 00:25:28 +02:00
|
|
|
|
{
|
2017-06-02 21:49:34 +02:00
|
|
|
|
[self.collectionView registerClass:[OWSSystemMessageCell class]
|
|
|
|
|
forCellWithReuseIdentifier:[OWSSystemMessageCell cellReuseIdentifier]];
|
2017-05-16 17:26:01 +02:00
|
|
|
|
[self.collectionView registerClass:[OWSUnreadIndicatorCell class]
|
|
|
|
|
forCellWithReuseIdentifier:[OWSUnreadIndicatorCell cellReuseIdentifier]];
|
2017-08-18 17:49:54 +02:00
|
|
|
|
[self.collectionView registerClass:[OWSContactOffersCell class]
|
|
|
|
|
forCellWithReuseIdentifier:[OWSContactOffersCell cellReuseIdentifier]];
|
2017-10-17 06:05:29 +02:00
|
|
|
|
[self.collectionView registerClass:[OWSMessageCell class]
|
|
|
|
|
forCellWithReuseIdentifier:[OWSMessageCell cellReuseIdentifier]];
|
2016-06-17 19:45:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:59:31 +02:00
|
|
|
|
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
|
|
|
|
{
|
|
|
|
|
[self startReadTimer];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
self.isAppInBackground = NO;
|
2017-05-26 18:59:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 18:19:17 +02:00
|
|
|
|
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
|
|
|
|
{
|
2017-07-25 18:52:30 +02:00
|
|
|
|
self.isAppInBackground = YES;
|
2017-05-30 18:19:17 +02:00
|
|
|
|
if (self.hasClearedUnreadMessagesIndicator) {
|
|
|
|
|
self.hasClearedUnreadMessagesIndicator = NO;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[self.dynamicInteractions clearUnreadIndicatorState];
|
2017-05-30 18:19:17 +02:00
|
|
|
|
}
|
2017-10-18 21:11:19 +02:00
|
|
|
|
[self.cellMediaCache removeAllObjects];
|
2017-05-30 18:19:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 04:10:37 +02:00
|
|
|
|
- (void)applicationWillResignActive:(NSNotification *)notification
|
|
|
|
|
{
|
|
|
|
|
[self cancelVoiceMemo];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
self.isUserScrolling = NO;
|
2017-10-20 05:43:55 +02:00
|
|
|
|
[self saveDraft];
|
|
|
|
|
[self markVisibleMessagesAsRead];
|
|
|
|
|
[self.cellMediaCache removeAllObjects];
|
|
|
|
|
[self cancelReadTimer];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 09:05:24 +02:00
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ viewWillAppear", self.logTag);
|
2017-06-19 23:10:34 +02:00
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
[self ensureBannerState];
|
2017-05-26 00:00:41 +02:00
|
|
|
|
|
2014-12-24 11:50:07 +01:00
|
|
|
|
[super viewWillAppear:animated];
|
2016-06-17 19:45:48 +02:00
|
|
|
|
|
2017-09-26 03:51:41 +02:00
|
|
|
|
// In case we're dismissing a CNContactViewController, or DocumentPicker which requires default system appearance
|
2017-05-19 19:23:46 +02:00
|
|
|
|
[UIUtil applySignalAppearence];
|
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
|
// We need to recheck on every appearance, since the user may have left the group in the settings VC,
|
|
|
|
|
// or on another device.
|
|
|
|
|
[self hideInputIfNeeded];
|
|
|
|
|
|
2017-07-25 18:52:30 +02:00
|
|
|
|
self.isViewVisible = YES;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-05-01 20:28:37 +02:00
|
|
|
|
// We should have already requested contact access at this point, so this should be a no-op
|
2017-09-06 19:59:39 +02:00
|
|
|
|
// unless it ever becomes possible to load this VC without going via the HomeViewController.
|
2017-05-01 20:28:37 +02:00
|
|
|
|
[self.contactsManager requestSystemContactsOnce];
|
|
|
|
|
|
2017-11-16 18:25:43 +01:00
|
|
|
|
[self updateDisappearingMessagesConfiguration];
|
2017-10-25 04:02:27 +02:00
|
|
|
|
|
|
|
|
|
[self updateBarButtonItems];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
[self setNavigationTitle];
|
|
|
|
|
|
2017-08-29 17:18:17 +02:00
|
|
|
|
// We want to set the initial scroll state the first time we enter the view.
|
2017-08-29 17:12:20 +02:00
|
|
|
|
if (!self.viewHasEverAppeared) {
|
|
|
|
|
[self scrollToDefaultPosition];
|
|
|
|
|
}
|
2017-11-21 22:23:42 +01:00
|
|
|
|
|
|
|
|
|
[self updateLastVisibleTimestamp];
|
2017-05-16 21:52:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 19:46:57 +02:00
|
|
|
|
- (NSIndexPath *_Nullable)indexPathOfUnreadMessagesIndicator
|
|
|
|
|
{
|
2017-10-10 22:13:54 +02:00
|
|
|
|
NSInteger row = 0;
|
|
|
|
|
for (ConversationViewItem *viewItem in self.viewItems) {
|
|
|
|
|
OWSInteractionType interactionType
|
|
|
|
|
= (viewItem ? viewItem.interaction.interactionType : OWSInteractionType_Unknown);
|
|
|
|
|
if (interactionType == OWSInteractionType_UnreadIndicator) {
|
|
|
|
|
return [NSIndexPath indexPathForRow:row inSection:0];
|
2017-05-16 19:46:57 +02:00
|
|
|
|
}
|
2017-10-10 22:13:54 +02:00
|
|
|
|
row++;
|
2017-05-16 19:46:57 +02:00
|
|
|
|
}
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)scrollToDefaultPosition
|
|
|
|
|
{
|
2017-05-31 20:22:32 +02:00
|
|
|
|
if (self.isUserScrolling) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 19:46:57 +02:00
|
|
|
|
NSIndexPath *_Nullable indexPath = [self indexPathOfUnreadMessagesIndicator];
|
|
|
|
|
if (indexPath) {
|
2017-05-26 00:00:41 +02:00
|
|
|
|
if (indexPath.section == 0 && indexPath.row == 0) {
|
|
|
|
|
[self.collectionView setContentOffset:CGPointZero animated:NO];
|
|
|
|
|
} else {
|
|
|
|
|
[self.collectionView scrollToItemAtIndexPath:indexPath
|
|
|
|
|
atScrollPosition:UICollectionViewScrollPositionTop
|
|
|
|
|
animated:NO];
|
|
|
|
|
}
|
2017-05-16 19:46:57 +02:00
|
|
|
|
} else {
|
|
|
|
|
[self scrollToBottomAnimated:NO];
|
|
|
|
|
}
|
2017-04-10 18:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 00:00:41 +02:00
|
|
|
|
- (void)scrollToUnreadIndicatorAnimated
|
|
|
|
|
{
|
2017-05-31 20:22:32 +02:00
|
|
|
|
if (self.isUserScrolling) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 00:00:41 +02:00
|
|
|
|
NSIndexPath *_Nullable indexPath = [self indexPathOfUnreadMessagesIndicator];
|
|
|
|
|
if (indexPath) {
|
|
|
|
|
if (indexPath.section == 0 && indexPath.row == 0) {
|
|
|
|
|
[self.collectionView setContentOffset:CGPointZero animated:YES];
|
|
|
|
|
} else {
|
|
|
|
|
[self.collectionView scrollToItemAtIndexPath:indexPath
|
|
|
|
|
atScrollPosition:UICollectionViewScrollPositionTop
|
|
|
|
|
animated:YES];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 18:48:29 +02:00
|
|
|
|
- (void)resetContentAndLayout
|
|
|
|
|
{
|
2017-04-10 18:44:03 +02:00
|
|
|
|
// Avoid layout corrupt issues and out-of-date message subtitles.
|
2017-10-16 18:29:22 +02:00
|
|
|
|
[self.collectionView.collectionViewLayout invalidateLayout];
|
2017-04-04 16:51:32 +02:00
|
|
|
|
[self.collectionView reloadData];
|
2017-04-04 18:35:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)setUserHasScrolled:(BOOL)userHasScrolled
|
|
|
|
|
{
|
2017-04-05 00:08:51 +02:00
|
|
|
|
_userHasScrolled = userHasScrolled;
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
[self ensureBannerState];
|
2017-04-05 00:08:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 21:50:54 +02:00
|
|
|
|
// Returns a collection of the group members who are "no longer verified".
|
|
|
|
|
- (NSArray<NSString *> *)noLongerVerifiedRecipientIds
|
|
|
|
|
{
|
|
|
|
|
NSMutableArray<NSString *> *result = [NSMutableArray new];
|
|
|
|
|
for (NSString *recipientId in self.thread.recipientIdentifiers) {
|
2018-01-30 22:41:25 +01:00
|
|
|
|
if ([[OWSIdentityManager sharedManager] verificationStateForRecipientId:recipientId]
|
2017-06-12 21:50:54 +02:00
|
|
|
|
== OWSVerificationStateNoLongerVerified) {
|
|
|
|
|
[result addObject:recipientId];
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-15 21:19:33 +02:00
|
|
|
|
return [result copy];
|
2017-06-12 21:50:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
- (void)ensureBannerState
|
2017-04-04 18:35:52 +02:00
|
|
|
|
{
|
2017-04-04 21:38:00 +02:00
|
|
|
|
// This method should be called rarely, so it's simplest to discard and
|
|
|
|
|
// rebuild the indicator view every time.
|
2017-06-09 22:21:59 +02:00
|
|
|
|
[self.bannerView removeFromSuperview];
|
|
|
|
|
self.bannerView = nil;
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-04-05 00:08:51 +02:00
|
|
|
|
if (self.userHasScrolled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 21:50:54 +02:00
|
|
|
|
NSArray<NSString *> *noLongerVerifiedRecipientIds = [self noLongerVerifiedRecipientIds];
|
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
if (noLongerVerifiedRecipientIds.count > 0) {
|
|
|
|
|
NSString *message;
|
|
|
|
|
if (noLongerVerifiedRecipientIds.count > 1) {
|
|
|
|
|
message = NSLocalizedString(@"MESSAGES_VIEW_N_MEMBERS_NO_LONGER_VERIFIED",
|
|
|
|
|
@"Indicates that more than one member of this group conversation is no longer verified.");
|
|
|
|
|
} else {
|
|
|
|
|
NSString *recipientId = [noLongerVerifiedRecipientIds firstObject];
|
|
|
|
|
NSString *displayName = [self.contactsManager displayNameForPhoneIdentifier:recipientId];
|
|
|
|
|
NSString *format
|
|
|
|
|
= (self.isGroupConversation ? NSLocalizedString(@"MESSAGES_VIEW_1_MEMBER_NO_LONGER_VERIFIED_FORMAT",
|
|
|
|
|
@"Indicates that one member of this group conversation is no longer "
|
|
|
|
|
@"verified. Embeds {{user's name or phone number}}.")
|
|
|
|
|
: NSLocalizedString(@"MESSAGES_VIEW_CONTACT_NO_LONGER_VERIFIED_FORMAT",
|
|
|
|
|
@"Indicates that this 1:1 conversation is no longer verified. Embeds "
|
|
|
|
|
@"{{user's name or phone number}}."));
|
|
|
|
|
message = [NSString stringWithFormat:format, displayName];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self createBannerWithTitle:message
|
|
|
|
|
bannerColor:[UIColor ows_destructiveRedColor]
|
|
|
|
|
tapSelector:@selector(noLongerVerifiedBannerViewWasTapped:)];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 21:38:00 +02:00
|
|
|
|
NSString *blockStateMessage = nil;
|
|
|
|
|
if ([self isBlockedContactConversation]) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
blockStateMessage = NSLocalizedString(
|
|
|
|
|
@"MESSAGES_VIEW_CONTACT_BLOCKED", @"Indicates that this 1:1 conversation has been blocked.");
|
|
|
|
|
} else if (self.isGroupConversation) {
|
2017-04-04 21:38:00 +02:00
|
|
|
|
int blockedGroupMemberCount = [self blockedGroupMemberCount];
|
|
|
|
|
if (blockedGroupMemberCount == 1) {
|
2017-04-05 18:16:54 +02:00
|
|
|
|
blockStateMessage = NSLocalizedString(@"MESSAGES_VIEW_GROUP_1_MEMBER_BLOCKED",
|
2017-05-30 19:04:43 +02:00
|
|
|
|
@"Indicates that a single member of this group has been blocked.");
|
2017-04-04 21:38:00 +02:00
|
|
|
|
} else if (blockedGroupMemberCount > 1) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
blockStateMessage =
|
|
|
|
|
[NSString stringWithFormat:NSLocalizedString(@"MESSAGES_VIEW_GROUP_N_MEMBERS_BLOCKED_FORMAT",
|
|
|
|
|
@"Indicates that some members of this group has been blocked. Embeds "
|
|
|
|
|
@"{{the number of blocked users in this group}}."),
|
2017-12-01 23:10:14 +01:00
|
|
|
|
[OWSFormat formatInt:blockedGroupMemberCount]];
|
2017-04-04 21:38:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-04-04 21:38:00 +02:00
|
|
|
|
if (blockStateMessage) {
|
2017-06-09 22:21:59 +02:00
|
|
|
|
[self createBannerWithTitle:blockStateMessage
|
|
|
|
|
bannerColor:[UIColor ows_destructiveRedColor]
|
|
|
|
|
tapSelector:@selector(blockBannerViewWasTapped:)];
|
2017-08-21 22:58:26 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([ThreadUtil shouldShowGroupProfileBannerInThread:self.thread blockingManager:self.blockingManager]) {
|
|
|
|
|
[self createBannerWithTitle:
|
|
|
|
|
NSLocalizedString(@"MESSAGES_VIEW_GROUP_PROFILE_WHITELIST_BANNER",
|
|
|
|
|
@"Text for banner in group conversation view that offers to share your profile with this group.")
|
2017-08-21 23:05:02 +02:00
|
|
|
|
bannerColor:[UIColor ows_reminderDarkYellowColor]
|
2017-08-21 22:58:26 +02:00
|
|
|
|
tapSelector:@selector(groupProfileWhitelistBannerWasTapped:)];
|
2017-08-23 22:34:30 +02:00
|
|
|
|
return;
|
2017-06-09 22:21:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
- (void)createBannerWithTitle:(NSString *)title bannerColor:(UIColor *)bannerColor tapSelector:(SEL)tapSelector
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(title.length > 0);
|
|
|
|
|
OWSAssert(bannerColor);
|
|
|
|
|
|
2017-07-11 19:24:47 +02:00
|
|
|
|
UIView *bannerView = [UIView containerView];
|
2017-06-09 22:21:59 +02:00
|
|
|
|
bannerView.backgroundColor = bannerColor;
|
|
|
|
|
bannerView.layer.cornerRadius = 2.5f;
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
// Use a shadow to "pop" the indicator above the other views.
|
|
|
|
|
bannerView.layer.shadowColor = [UIColor blackColor].CGColor;
|
|
|
|
|
bannerView.layer.shadowOffset = CGSizeMake(2, 3);
|
|
|
|
|
bannerView.layer.shadowRadius = 2.f;
|
|
|
|
|
bannerView.layer.shadowOpacity = 0.35f;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
2017-06-12 21:50:54 +02:00
|
|
|
|
UILabel *label = [UILabel new];
|
|
|
|
|
label.font = [UIFont ows_mediumFontWithSize:14.f];
|
|
|
|
|
label.text = title;
|
|
|
|
|
label.textColor = [UIColor whiteColor];
|
|
|
|
|
label.numberOfLines = 0;
|
|
|
|
|
label.lineBreakMode = NSLineBreakByWordWrapping;
|
|
|
|
|
label.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
|
|
|
|
|
UIImage *closeIcon = [UIImage imageNamed:@"banner_close"];
|
|
|
|
|
UIImageView *closeButton = [[UIImageView alloc] initWithImage:closeIcon];
|
|
|
|
|
[bannerView addSubview:closeButton];
|
|
|
|
|
const CGFloat kBannerCloseButtonPadding = 8.f;
|
|
|
|
|
[closeButton autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kBannerCloseButtonPadding];
|
2018-04-02 21:31:32 +02:00
|
|
|
|
[closeButton autoPinTrailingToSuperviewMarginWithInset:kBannerCloseButtonPadding];
|
2017-06-12 21:50:54 +02:00
|
|
|
|
[closeButton autoSetDimension:ALDimensionWidth toSize:closeIcon.size.width];
|
|
|
|
|
[closeButton autoSetDimension:ALDimensionHeight toSize:closeIcon.size.height];
|
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
[bannerView addSubview:label];
|
|
|
|
|
[label autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:5];
|
|
|
|
|
[label autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:5];
|
|
|
|
|
const CGFloat kBannerHPadding = 15.f;
|
2018-04-02 21:31:32 +02:00
|
|
|
|
[label autoPinLeadingToSuperviewMarginWithInset:kBannerHPadding];
|
2017-06-12 21:50:54 +02:00
|
|
|
|
const CGFloat kBannerHSpacing = 10.f;
|
2018-04-02 21:31:32 +02:00
|
|
|
|
[closeButton autoPinLeadingToTrailingEdgeOfView:label offset:kBannerHSpacing];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
[bannerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:tapSelector]];
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
[self.view addSubview:bannerView];
|
|
|
|
|
[bannerView autoPinToTopLayoutGuideOfViewController:self withInset:10];
|
|
|
|
|
[bannerView autoHCenterInSuperview];
|
|
|
|
|
|
|
|
|
|
CGFloat labelDesiredWidth = [label sizeThatFits:CGSizeZero].width;
|
2017-06-12 21:50:54 +02:00
|
|
|
|
CGFloat bannerDesiredWidth
|
|
|
|
|
= (labelDesiredWidth + kBannerHPadding + kBannerHSpacing + closeIcon.size.width + kBannerCloseButtonPadding);
|
2017-06-09 22:21:59 +02:00
|
|
|
|
const CGFloat kMinBannerHMargin = 20.f;
|
|
|
|
|
if (bannerDesiredWidth + kMinBannerHMargin * 2.f >= self.view.width) {
|
|
|
|
|
[bannerView autoPinWidthToSuperviewWithMargin:kMinBannerHMargin];
|
2017-04-04 21:38:00 +02:00
|
|
|
|
}
|
2017-06-09 22:21:59 +02:00
|
|
|
|
|
|
|
|
|
[self.view layoutSubviews];
|
|
|
|
|
|
|
|
|
|
self.bannerView = bannerView;
|
2017-04-04 18:35:52 +02:00
|
|
|
|
}
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
- (void)blockBannerViewWasTapped:(UIGestureRecognizer *)sender
|
2017-05-31 20:22:32 +02:00
|
|
|
|
{
|
2017-04-04 21:38:00 +02:00
|
|
|
|
if (sender.state != UIGestureRecognizerStateRecognized) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-04 18:35:52 +02:00
|
|
|
|
|
2017-04-04 21:38:00 +02:00
|
|
|
|
if ([self isBlockedContactConversation]) {
|
|
|
|
|
// If this a blocked 1:1 conversation, offer to unblock the user.
|
2017-04-04 21:54:11 +02:00
|
|
|
|
[self showUnblockContactUI:nil];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
} else if (self.isGroupConversation) {
|
2017-04-04 21:38:00 +02:00
|
|
|
|
// If this a group conversation with at least one blocked member,
|
|
|
|
|
// Show the block list view.
|
|
|
|
|
int blockedGroupMemberCount = [self blockedGroupMemberCount];
|
|
|
|
|
if (blockedGroupMemberCount > 0) {
|
|
|
|
|
BlockListViewController *vc = [[BlockListViewController alloc] init];
|
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-04 18:35:52 +02:00
|
|
|
|
|
2017-08-21 22:58:26 +02:00
|
|
|
|
- (void)groupProfileWhitelistBannerWasTapped:(UIGestureRecognizer *)sender
|
|
|
|
|
{
|
|
|
|
|
if (sender.state != UIGestureRecognizerStateRecognized) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-28 22:45:24 +02:00
|
|
|
|
[self presentAddThreadToProfileWhitelistWithSuccess:^{
|
|
|
|
|
[self ensureBannerState];
|
|
|
|
|
}];
|
2017-08-21 22:58:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
|
- (void)noLongerVerifiedBannerViewWasTapped:(UIGestureRecognizer *)sender
|
|
|
|
|
{
|
|
|
|
|
if (sender.state == UIGestureRecognizerStateRecognized) {
|
2017-06-20 16:24:29 +02:00
|
|
|
|
NSArray<NSString *> *noLongerVerifiedRecipientIds = [self noLongerVerifiedRecipientIds];
|
|
|
|
|
if (noLongerVerifiedRecipientIds.count < 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
BOOL hasMultiple = noLongerVerifiedRecipientIds.count > 1;
|
|
|
|
|
|
2017-06-12 21:50:54 +02:00
|
|
|
|
UIAlertController *actionSheetController =
|
|
|
|
|
[UIAlertController alertControllerWithTitle:nil
|
|
|
|
|
message:nil
|
|
|
|
|
preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
|
2017-09-06 20:13:18 +02:00
|
|
|
|
__weak ConversationViewController *weakSelf = self;
|
2017-06-15 21:19:33 +02:00
|
|
|
|
UIAlertAction *verifyAction = [UIAlertAction
|
2017-06-20 16:24:29 +02:00
|
|
|
|
actionWithTitle:(hasMultiple ? NSLocalizedString(@"VERIFY_PRIVACY_MULTIPLE",
|
|
|
|
|
@"Label for button or row which allows users to verify the safety "
|
|
|
|
|
@"numbers of multiple users.")
|
|
|
|
|
: NSLocalizedString(@"VERIFY_PRIVACY",
|
|
|
|
|
@"Label for button or row which allows users to verify the safety "
|
|
|
|
|
@"number of another user."))style:UIAlertActionStyleDefault
|
2017-06-12 21:50:54 +02:00
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
2017-06-20 16:24:29 +02:00
|
|
|
|
[weakSelf showNoLongerVerifiedUI];
|
2017-06-12 21:50:54 +02:00
|
|
|
|
}];
|
2017-06-15 21:19:33 +02:00
|
|
|
|
[actionSheetController addAction:verifyAction];
|
2017-06-12 21:50:54 +02:00
|
|
|
|
|
2017-07-13 20:53:24 +02:00
|
|
|
|
UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:CommonStrings.dismissButton
|
|
|
|
|
style:UIAlertActionStyleCancel
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
|
[weakSelf resetVerificationStateToDefault];
|
|
|
|
|
}];
|
2017-06-12 21:50:54 +02:00
|
|
|
|
[actionSheetController addAction:dismissAction];
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2017-06-12 21:50:54 +02:00
|
|
|
|
[self presentViewController:actionSheetController animated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)resetVerificationStateToDefault
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-06-12 21:50:54 +02:00
|
|
|
|
|
|
|
|
|
NSArray<NSString *> *noLongerVerifiedRecipientIds = [self noLongerVerifiedRecipientIds];
|
|
|
|
|
for (NSString *recipientId in noLongerVerifiedRecipientIds) {
|
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
|
|
OWSRecipientIdentity *_Nullable recipientIdentity =
|
|
|
|
|
[[OWSIdentityManager sharedManager] recipientIdentityForRecipientId:recipientId];
|
|
|
|
|
OWSAssert(recipientIdentity);
|
|
|
|
|
|
|
|
|
|
NSData *identityKey = recipientIdentity.identityKey;
|
|
|
|
|
OWSAssert(identityKey.length > 0);
|
|
|
|
|
if (identityKey.length < 1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-02 20:07:13 +01:00
|
|
|
|
[OWSIdentityManager.sharedManager setVerificationState:OWSVerificationStateDefault
|
|
|
|
|
identityKey:identityKey
|
|
|
|
|
recipientId:recipientId
|
|
|
|
|
isUserInitiatedChange:YES];
|
2017-06-09 22:21:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 22:19:07 +02:00
|
|
|
|
- (void)showUnblockContactUI:(nullable BlockActionCompletionBlock)completionBlock
|
2017-04-04 21:54:11 +02:00
|
|
|
|
{
|
|
|
|
|
OWSAssert([self.thread isKindOfClass:[TSContactThread class]]);
|
|
|
|
|
|
2017-04-05 18:16:54 +02:00
|
|
|
|
self.userHasScrolled = NO;
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-04-05 18:16:54 +02:00
|
|
|
|
// To avoid "noisy" animations (hiding the keyboard before showing
|
|
|
|
|
// the action sheet, re-showing it after), hide the keyboard before
|
|
|
|
|
// showing the "unblock" action sheet.
|
|
|
|
|
//
|
|
|
|
|
// Unblocking is a rare interaction, so it's okay to leave the keyboard
|
|
|
|
|
// hidden.
|
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
|
2017-04-04 21:54:11 +02:00
|
|
|
|
NSString *contactIdentifier = ((TSContactThread *)self.thread).contactIdentifier;
|
|
|
|
|
[BlockListUIUtils showUnblockPhoneNumberActionSheet:contactIdentifier
|
|
|
|
|
fromViewController:self
|
|
|
|
|
blockingManager:_blockingManager
|
|
|
|
|
contactsManager:_contactsManager
|
|
|
|
|
completionBlock:completionBlock];
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 18:35:52 +02:00
|
|
|
|
- (BOOL)isBlockedContactConversation
|
|
|
|
|
{
|
|
|
|
|
if (![self.thread isKindOfClass:[TSContactThread class]]) {
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
NSString *contactIdentifier = ((TSContactThread *)self.thread).contactIdentifier;
|
|
|
|
|
return [[_blockingManager blockedPhoneNumbers] containsObject:contactIdentifier];
|
2014-12-24 11:50:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-04 21:38:00 +02:00
|
|
|
|
- (int)blockedGroupMemberCount
|
|
|
|
|
{
|
2017-05-31 20:22:32 +02:00
|
|
|
|
OWSAssert(self.isGroupConversation);
|
2017-04-05 18:16:54 +02:00
|
|
|
|
OWSAssert([self.thread isKindOfClass:[TSGroupThread class]]);
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-04-04 21:38:00 +02:00
|
|
|
|
TSGroupThread *groupThread = (TSGroupThread *)self.thread;
|
|
|
|
|
int blockedMemberCount = 0;
|
|
|
|
|
NSArray<NSString *> *blockedPhoneNumbers = [_blockingManager blockedPhoneNumbers];
|
|
|
|
|
for (NSString *contactIdentifier in groupThread.groupModel.groupMemberIds) {
|
|
|
|
|
if ([blockedPhoneNumbers containsObject:contactIdentifier]) {
|
|
|
|
|
blockedMemberCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return blockedMemberCount;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)startReadTimer
|
|
|
|
|
{
|
2017-05-30 18:19:17 +02:00
|
|
|
|
[self.readTimer invalidate];
|
2017-05-31 20:27:46 +02:00
|
|
|
|
self.readTimer = [NSTimer weakScheduledTimerWithTimeInterval:3.f
|
2017-05-30 18:19:17 +02:00
|
|
|
|
target:self
|
|
|
|
|
selector:@selector(readTimerDidFire)
|
|
|
|
|
userInfo:nil
|
|
|
|
|
repeats:YES];
|
2014-12-09 20:11:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 17:28:12 +02:00
|
|
|
|
- (void)readTimerDidFire
|
|
|
|
|
{
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[self markVisibleMessagesAsRead];
|
2017-05-23 17:28:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)cancelReadTimer
|
|
|
|
|
{
|
2014-12-09 20:11:14 +01:00
|
|
|
|
[self.readTimer invalidate];
|
2017-10-16 17:01:13 +02:00
|
|
|
|
self.readTimer = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
|
{
|
2014-12-09 20:11:14 +01:00
|
|
|
|
[super viewDidAppear:animated];
|
2015-12-26 17:27:27 +01:00
|
|
|
|
|
2017-10-25 00:47:19 +02:00
|
|
|
|
[ProfileFetcherJob runWithThread:self.thread networkManager:self.networkManager];
|
|
|
|
|
[self markVisibleMessagesAsRead];
|
|
|
|
|
[self startReadTimer];
|
|
|
|
|
[self updateNavigationBarSubtitleLabel];
|
2017-04-09 21:31:31 +02:00
|
|
|
|
[self updateBackButtonUnreadCount];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-10-25 20:37:04 +02:00
|
|
|
|
if (_composeOnOpen && !self.inputToolbar.hidden) {
|
|
|
|
|
[self popKeyBoard];
|
|
|
|
|
_composeOnOpen = NO;
|
|
|
|
|
}
|
|
|
|
|
if (_callOnOpen) {
|
|
|
|
|
[self callAction];
|
|
|
|
|
_callOnOpen = NO;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
self.isViewCompletelyAppeared = YES;
|
2017-08-29 17:12:20 +02:00
|
|
|
|
self.viewHasEverAppeared = YES;
|
2018-01-19 21:00:41 +01:00
|
|
|
|
|
|
|
|
|
// HACK: Because the inputToolbar is the inputAccessoryView, we make some special considertations WRT it's firstResponder status.
|
|
|
|
|
//
|
|
|
|
|
// When a view controller is presented, it is first responder. However if we resign first responder
|
|
|
|
|
// and the view re-appears, without being presented, the inputToolbar can become invisible.
|
|
|
|
|
// e.g. specifically works around the scenario:
|
|
|
|
|
// - Present this VC
|
|
|
|
|
// - Longpress on a message to show edit menu, which entails making the pressed view the first responder.
|
|
|
|
|
// - Begin presenting another view, e.g. swipe-left for details or swipe-right to go back, but quit part way, so that you remain on the conversation view
|
|
|
|
|
// - toolbar will be not be visible unless we reaquire first responder.
|
|
|
|
|
if (!self.isFirstResponder) {
|
|
|
|
|
|
|
|
|
|
// We don't have to worry about the input toolbar being visible if the inputToolbar.textView is first responder
|
|
|
|
|
// In fact doing so would unnecessarily dismiss the keyboard which is probably not desirable and at least
|
|
|
|
|
// a distracting animation.
|
|
|
|
|
if (!self.inputToolbar.isInputTextViewFirstResponder) {
|
|
|
|
|
DDLogDebug(@"%@ reclaiming first responder to ensure toolbar is shown.", self.logTag);
|
|
|
|
|
[self becomeFirstResponder];
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-09 20:11:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 00:21:46 +02:00
|
|
|
|
// `viewWillDisappear` is called whenever the view *starts* to disappear,
|
|
|
|
|
// but, as is the case with the "pan left for message details view" gesture,
|
|
|
|
|
// this can be canceled. As such, we shouldn't tear down anything expensive
|
|
|
|
|
// until `viewDidDisappear`.
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ viewWillDisappear", self.logTag);
|
2017-06-19 23:10:34 +02:00
|
|
|
|
|
2015-12-26 17:27:27 +01:00
|
|
|
|
[super viewWillDisappear:animated];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
self.isViewCompletelyAppeared = NO;
|
2017-10-24 19:25:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)viewDidDisappear:(BOOL)animated
|
|
|
|
|
{
|
|
|
|
|
[super viewDidDisappear:animated];
|
|
|
|
|
self.userHasScrolled = NO;
|
|
|
|
|
self.isViewVisible = NO;
|
2017-10-16 17:55:19 +02:00
|
|
|
|
|
2017-04-20 15:44:25 +02:00
|
|
|
|
[self.audioAttachmentPlayer stop];
|
2017-04-20 19:43:33 +02:00
|
|
|
|
self.audioAttachmentPlayer = nil;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2014-12-09 20:11:14 +01:00
|
|
|
|
[self cancelReadTimer];
|
2015-03-01 00:04:39 +01:00
|
|
|
|
[self saveDraft];
|
2017-05-31 20:27:46 +02:00
|
|
|
|
[self markVisibleMessagesAsRead];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
[self cancelVoiceMemo];
|
2017-10-18 21:11:19 +02:00
|
|
|
|
[self.cellMediaCache removeAllObjects];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
|
|
|
|
self.isUserScrolling = NO;
|
2014-10-29 21:58:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-29 19:54:33 +01:00
|
|
|
|
#pragma mark - Initiliazers
|
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
|
- (void)setNavigationTitle
|
|
|
|
|
{
|
2017-08-23 18:03:36 +02:00
|
|
|
|
NSAttributedString *name;
|
|
|
|
|
if (self.thread.isGroupThread) {
|
|
|
|
|
if (self.thread.name.length == 0) {
|
2017-10-14 19:20:46 +02:00
|
|
|
|
name = [[NSAttributedString alloc] initWithString:[MessageStrings newGroupDefaultTitle]];
|
2017-08-23 18:03:36 +02:00
|
|
|
|
} else {
|
|
|
|
|
name = [[NSAttributedString alloc] initWithString:self.thread.name];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2017-09-12 16:14:17 +02:00
|
|
|
|
OWSAssert(self.thread.contactIdentifier);
|
2017-08-23 21:41:56 +02:00
|
|
|
|
name = [self.contactsManager
|
|
|
|
|
attributedStringForConversationTitleWithPhoneIdentifier:self.thread.contactIdentifier
|
2017-09-12 16:14:17 +02:00
|
|
|
|
primaryFont:[self navigationBarTitleLabelFont]
|
2017-08-23 21:41:56 +02:00
|
|
|
|
secondaryFont:[UIFont ows_footnoteFont]];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
}
|
2017-02-15 22:09:57 +01:00
|
|
|
|
self.title = nil;
|
|
|
|
|
|
2017-08-23 18:03:36 +02:00
|
|
|
|
if ([name isEqual:self.navigationBarTitleLabel.attributedText]) {
|
2017-02-15 22:09:57 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-08-23 18:03:36 +02:00
|
|
|
|
self.navigationBarTitleLabel.attributedText = name;
|
2017-02-15 22:09:57 +01:00
|
|
|
|
|
|
|
|
|
// Changing the title requires relayout of the nav bar contents.
|
2017-10-25 04:02:27 +02:00
|
|
|
|
[self updateBarButtonItems];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
}
|
2015-01-14 22:30:01 +01:00
|
|
|
|
|
2017-07-27 17:43:31 +02:00
|
|
|
|
- (void)createHeaderViews
|
|
|
|
|
{
|
|
|
|
|
_backButtonUnreadCountView = [UIView new];
|
|
|
|
|
_backButtonUnreadCountView.layer.cornerRadius = self.unreadCountViewDiameter / 2;
|
|
|
|
|
_backButtonUnreadCountView.backgroundColor = [UIColor redColor];
|
|
|
|
|
_backButtonUnreadCountView.hidden = YES;
|
|
|
|
|
_backButtonUnreadCountView.userInteractionEnabled = NO;
|
|
|
|
|
|
|
|
|
|
_backButtonUnreadCountLabel = [UILabel new];
|
|
|
|
|
_backButtonUnreadCountLabel.backgroundColor = [UIColor clearColor];
|
|
|
|
|
_backButtonUnreadCountLabel.textColor = [UIColor whiteColor];
|
|
|
|
|
_backButtonUnreadCountLabel.font = [UIFont systemFontOfSize:11];
|
|
|
|
|
_backButtonUnreadCountLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
self.navigationBarTitleView = [ConversationHeaderView new];
|
2017-09-07 16:35:11 +02:00
|
|
|
|
self.navigationBarTitleView.userInteractionEnabled = YES;
|
2017-07-27 17:43:31 +02:00
|
|
|
|
[self.navigationBarTitleView
|
|
|
|
|
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
|
|
|
|
|
action:@selector(navigationTitleTapped:)]];
|
2017-09-01 20:30:39 +02:00
|
|
|
|
#ifdef USE_DEBUG_UI
|
2017-07-27 17:43:31 +02:00
|
|
|
|
[self.navigationBarTitleView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
|
|
|
|
|
initWithTarget:self
|
|
|
|
|
action:@selector(navigationTitleLongPressed:)]];
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
self.navigationBarTitleLabel = [UILabel new];
|
2017-09-07 16:35:11 +02:00
|
|
|
|
self.navigationBarTitleView.titleLabel = self.navigationBarTitleLabel;
|
2017-07-27 17:43:31 +02:00
|
|
|
|
self.navigationBarTitleLabel.textColor = [UIColor whiteColor];
|
2017-09-12 16:14:17 +02:00
|
|
|
|
self.navigationBarTitleLabel.font = [self navigationBarTitleLabelFont];
|
2017-07-27 17:43:31 +02:00
|
|
|
|
self.navigationBarTitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
|
[self.navigationBarTitleView addSubview:self.navigationBarTitleLabel];
|
|
|
|
|
|
|
|
|
|
self.navigationBarSubtitleLabel = [UILabel new];
|
2017-09-07 16:35:11 +02:00
|
|
|
|
self.navigationBarTitleView.subtitleLabel = self.navigationBarSubtitleLabel;
|
2017-07-27 17:43:31 +02:00
|
|
|
|
[self updateNavigationBarSubtitleLabel];
|
|
|
|
|
[self.navigationBarTitleView addSubview:self.navigationBarSubtitleLabel];
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-12 16:14:17 +02:00
|
|
|
|
- (UIFont *)navigationBarTitleLabelFont
|
|
|
|
|
{
|
|
|
|
|
return [UIFont ows_boldFontWithSize:20.f];
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-27 17:43:31 +02:00
|
|
|
|
- (CGFloat)unreadCountViewDiameter
|
|
|
|
|
{
|
|
|
|
|
return 16;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 00:47:19 +02:00
|
|
|
|
- (void)createBackButton
|
2016-09-21 14:37:51 +02:00
|
|
|
|
{
|
2017-02-17 23:30:49 +01:00
|
|
|
|
UIBarButtonItem *backItem = [self createOWSBackButton];
|
2017-10-13 18:57:44 +02:00
|
|
|
|
if (backItem.customView) {
|
|
|
|
|
// This method gets called multiple times, so it's important we re-layout the unread badge
|
|
|
|
|
// with respect to the new backItem.
|
|
|
|
|
[backItem.customView addSubview:_backButtonUnreadCountView];
|
|
|
|
|
// TODO: The back button assets are assymetrical. There are strong reasons
|
|
|
|
|
// to use spacing in the assets to manipulate the size and positioning of
|
|
|
|
|
// bar button items, but it means we'll probably need separate RTL and LTR
|
|
|
|
|
// flavors of these assets.
|
|
|
|
|
[_backButtonUnreadCountView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:-6];
|
2018-04-02 21:31:32 +02:00
|
|
|
|
[_backButtonUnreadCountView autoPinLeadingToSuperviewMarginWithInset:1];
|
2017-10-13 18:57:44 +02:00
|
|
|
|
[_backButtonUnreadCountView autoSetDimension:ALDimensionHeight toSize:self.unreadCountViewDiameter];
|
|
|
|
|
// We set a min width, but we will also pin to our subview label, so we can grow to accommodate multiple digits.
|
|
|
|
|
[_backButtonUnreadCountView autoSetDimension:ALDimensionWidth
|
|
|
|
|
toSize:self.unreadCountViewDiameter
|
|
|
|
|
relation:NSLayoutRelationGreaterThanOrEqual];
|
|
|
|
|
|
|
|
|
|
[_backButtonUnreadCountView addSubview:_backButtonUnreadCountLabel];
|
|
|
|
|
[_backButtonUnreadCountLabel autoPinWidthToSuperviewWithMargin:4];
|
|
|
|
|
[_backButtonUnreadCountLabel autoPinHeightToSuperview];
|
|
|
|
|
|
|
|
|
|
// Initialize newly created unread count badge to accurately reflect the current unread count.
|
|
|
|
|
[self updateBackButtonUnreadCount];
|
|
|
|
|
}
|
2017-04-09 21:31:31 +02:00
|
|
|
|
|
2017-09-07 16:35:11 +02:00
|
|
|
|
self.navigationItem.leftBarButtonItem = backItem;
|
2017-10-25 00:47:19 +02:00
|
|
|
|
}
|
2017-09-07 16:35:11 +02:00
|
|
|
|
|
2017-10-25 04:02:27 +02:00
|
|
|
|
- (void)updateBarButtonItems
|
2017-10-25 00:47:19 +02:00
|
|
|
|
{
|
2017-02-17 23:30:49 +01:00
|
|
|
|
// We want to leave space for the "back" button, the "timer" button, and the "call"
|
|
|
|
|
// button, and all of the whitespace around these views. There
|
2017-02-15 22:09:57 +01:00
|
|
|
|
// isn't a convenient way to calculate these in a navigation bar, so we just leave
|
|
|
|
|
// a constant amount of space which will be safe unless Apple makes radical changes
|
|
|
|
|
// to the appearance of the navigation bar.
|
2017-02-17 17:45:26 +01:00
|
|
|
|
int rightBarButtonItemCount = 0;
|
|
|
|
|
if ([self canCall]) {
|
|
|
|
|
rightBarButtonItemCount++;
|
|
|
|
|
}
|
2017-10-25 04:02:27 +02:00
|
|
|
|
if (self.disappearingMessagesConfiguration.isEnabled) {
|
2017-02-17 17:45:26 +01:00
|
|
|
|
rightBarButtonItemCount++;
|
|
|
|
|
}
|
2017-03-06 01:33:43 +01:00
|
|
|
|
CGFloat barButtonSize = 0;
|
2017-02-17 17:45:26 +01:00
|
|
|
|
switch (rightBarButtonItemCount) {
|
|
|
|
|
case 0:
|
2017-03-06 01:33:43 +01:00
|
|
|
|
barButtonSize = 70;
|
2017-02-17 17:45:26 +01:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2017-03-06 01:33:43 +01:00
|
|
|
|
barButtonSize = 105;
|
2017-02-17 17:45:26 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Unexpected number of right navbar items.", self.logTag);
|
2017-05-30 19:04:43 +02:00
|
|
|
|
// In production, fall through to the largest defined case.
|
2017-02-17 17:45:26 +01:00
|
|
|
|
case 2:
|
2017-03-06 01:33:43 +01:00
|
|
|
|
barButtonSize = 150;
|
2017-02-17 17:45:26 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-09-07 16:35:11 +02:00
|
|
|
|
CGSize screenSize = [UIScreen mainScreen].bounds.size;
|
|
|
|
|
CGFloat screenWidth = MIN(screenSize.width, screenSize.height);
|
2017-09-07 16:47:35 +02:00
|
|
|
|
if (self.navigationItem.titleView != self.navigationBarTitleView) {
|
|
|
|
|
// Request "full width" title; the navigation bar will truncate this
|
|
|
|
|
// to fit between the left and right buttons.
|
|
|
|
|
self.navigationBarTitleView.frame = CGRectMake(0, 0, screenWidth, 44);
|
|
|
|
|
self.navigationItem.titleView = self.navigationBarTitleView;
|
|
|
|
|
} else {
|
|
|
|
|
// Don't reset the frame of the navigationBarTitleView every time
|
|
|
|
|
// this method is called or we'll gave bad frames where it will appear
|
|
|
|
|
// in the wrong position.
|
|
|
|
|
[self.navigationBarTitleView layoutSubviews];
|
|
|
|
|
}
|
2017-04-04 18:35:52 +02:00
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
|
if (self.userLeftGroup) {
|
|
|
|
|
self.navigationItem.rightBarButtonItems = @[];
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-02-17 17:45:26 +01:00
|
|
|
|
const CGFloat kBarButtonSize = 44;
|
2016-09-21 14:37:51 +02:00
|
|
|
|
NSMutableArray<UIBarButtonItem *> *barButtons = [NSMutableArray new];
|
|
|
|
|
if ([self canCall]) {
|
2017-02-15 22:09:57 +01:00
|
|
|
|
// We use UIButtons with [UIBarButtonItem initWithCustomView:...] instead of
|
|
|
|
|
// UIBarButtonItem in order to ensure that these buttons are spaced tightly.
|
|
|
|
|
// The contents of the navigation bar are cramped in this view.
|
|
|
|
|
UIButton *callButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
2017-02-17 17:45:26 +01:00
|
|
|
|
UIImage *image = [UIImage imageNamed:@"button_phone_white"];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[callButton setImage:image forState:UIControlStateNormal];
|
2017-02-17 17:45:26 +01:00
|
|
|
|
UIEdgeInsets imageEdgeInsets = UIEdgeInsetsZero;
|
|
|
|
|
// We normally would want to use left and right insets that ensure the button
|
|
|
|
|
// is square and the icon is centered. However UINavigationBar doesn't offer us
|
|
|
|
|
// control over the margins and spacing of its content, and the buttons end up
|
|
|
|
|
// too far apart and too far from the edge of the screen. So we use a smaller
|
|
|
|
|
// right inset tighten up the layout.
|
|
|
|
|
imageEdgeInsets.left = round((kBarButtonSize - image.size.width) * 0.5f);
|
2017-02-17 23:30:49 +01:00
|
|
|
|
imageEdgeInsets.right = round((kBarButtonSize - (image.size.width + imageEdgeInsets.left)) * 0.5f);
|
2017-02-17 17:45:26 +01:00
|
|
|
|
imageEdgeInsets.top = round((kBarButtonSize - image.size.height) * 0.5f);
|
|
|
|
|
imageEdgeInsets.bottom = round(kBarButtonSize - (image.size.height + imageEdgeInsets.top));
|
|
|
|
|
callButton.imageEdgeInsets = imageEdgeInsets;
|
2018-03-26 15:37:43 +02:00
|
|
|
|
callButton.accessibilityLabel = NSLocalizedString(@"CALL_LABEL", "Accessibility label for placing call button");
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[callButton addTarget:self action:@selector(callAction) forControlEvents:UIControlEventTouchUpInside];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
callButton.frame = CGRectMake(0,
|
|
|
|
|
0,
|
|
|
|
|
round(image.size.width + imageEdgeInsets.left + imageEdgeInsets.right),
|
|
|
|
|
round(image.size.height + imageEdgeInsets.top + imageEdgeInsets.bottom));
|
2017-02-15 22:09:57 +01:00
|
|
|
|
[barButtons addObject:[[UIBarButtonItem alloc] initWithCustomView:callButton]];
|
2015-01-14 22:30:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 04:02:27 +02:00
|
|
|
|
if (self.disappearingMessagesConfiguration.isEnabled) {
|
2018-01-20 17:27:32 +01:00
|
|
|
|
DisappearingTimerConfigurationView *timerView = [[DisappearingTimerConfigurationView alloc]
|
|
|
|
|
initWithDurationSeconds:self.disappearingMessagesConfiguration.durationSeconds];
|
|
|
|
|
timerView.delegate = self;
|
|
|
|
|
timerView.tintColor = UIColor.whiteColor;
|
|
|
|
|
|
|
|
|
|
// As of iOS11, we can size barButton item custom views with autoLayout.
|
|
|
|
|
// Before that, though we can still use autoLayout *within* the customView,
|
|
|
|
|
// setting the view's size with constraints causes the customView to be temporarily
|
|
|
|
|
// laid out with a misplaced origin.
|
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
|
[timerView autoSetDimensionsToSize:CGSizeMake(36, 44)];
|
|
|
|
|
} else {
|
|
|
|
|
timerView.frame = CGRectMake(0, 0, 36, 44);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[barButtons addObject:[[UIBarButtonItem alloc] initWithCustomView:timerView]];
|
2015-01-27 02:20:11 +01:00
|
|
|
|
}
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
|
self.navigationItem.rightBarButtonItems = [barButtons copy];
|
2015-01-14 22:30:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-17 21:50:43 +02:00
|
|
|
|
- (void)updateNavigationBarSubtitleLabel
|
|
|
|
|
{
|
|
|
|
|
NSMutableAttributedString *subtitleText = [NSMutableAttributedString new];
|
2017-06-09 19:12:33 +02:00
|
|
|
|
|
2017-04-17 21:50:43 +02:00
|
|
|
|
if (self.thread.isMuted) {
|
2017-04-17 22:06:39 +02:00
|
|
|
|
// Show a "mute" icon before the navigation bar subtitle if this thread is muted.
|
2017-04-17 21:50:43 +02:00
|
|
|
|
[subtitleText
|
|
|
|
|
appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
|
initWithString:@"\ue067 "
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : [UIFont ows_elegantIconsFont:7.f],
|
|
|
|
|
NSForegroundColorAttributeName : [UIColor colorWithWhite:0.9f alpha:1.f],
|
|
|
|
|
}]];
|
|
|
|
|
}
|
2017-06-09 19:12:33 +02:00
|
|
|
|
|
|
|
|
|
BOOL isVerified = YES;
|
|
|
|
|
for (NSString *recipientId in self.thread.recipientIdentifiers) {
|
2018-01-30 22:41:25 +01:00
|
|
|
|
if ([[OWSIdentityManager sharedManager] verificationStateForRecipientId:recipientId]
|
2017-06-09 19:12:33 +02:00
|
|
|
|
!= OWSVerificationStateVerified) {
|
|
|
|
|
isVerified = NO;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isVerified) {
|
|
|
|
|
// Show a "checkmark" icon before the navigation bar subtitle if this thread is verified.
|
|
|
|
|
[subtitleText
|
|
|
|
|
appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
|
initWithString:@"\uf00c "
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : [UIFont ows_fontAwesomeFont:10.f],
|
|
|
|
|
NSForegroundColorAttributeName : [UIColor colorWithWhite:0.9f alpha:1.f],
|
|
|
|
|
}]];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-03 19:41:48 +02:00
|
|
|
|
if (self.userLeftGroup) {
|
|
|
|
|
[subtitleText
|
|
|
|
|
appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
|
initWithString:NSLocalizedString(@"GROUP_YOU_LEFT", @"")
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : [UIFont ows_regularFontWithSize:9.f],
|
|
|
|
|
NSForegroundColorAttributeName : [UIColor colorWithWhite:0.9f alpha:1.f],
|
|
|
|
|
}]];
|
|
|
|
|
} else {
|
|
|
|
|
[subtitleText appendAttributedString:
|
|
|
|
|
[[NSAttributedString alloc]
|
|
|
|
|
initWithString:NSLocalizedString(@"MESSAGES_VIEW_TITLE_SUBTITLE",
|
|
|
|
|
@"The subtitle for the messages view title indicates that the "
|
|
|
|
|
@"title can be tapped to access settings for this conversation.")
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : [UIFont ows_regularFontWithSize:9.f],
|
|
|
|
|
NSForegroundColorAttributeName : [UIColor colorWithWhite:0.9f alpha:1.f],
|
|
|
|
|
}]];
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-17 21:50:43 +02:00
|
|
|
|
self.navigationBarSubtitleLabel.attributedText = subtitleText;
|
2017-04-24 17:58:07 +02:00
|
|
|
|
[self.navigationBarSubtitleLabel sizeToFit];
|
2017-04-17 21:50:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-29 19:54:33 +01:00
|
|
|
|
|
2017-05-25 19:45:42 +02:00
|
|
|
|
#pragma mark - Identity
|
|
|
|
|
|
|
|
|
|
/**
|
2017-05-27 03:19:46 +02:00
|
|
|
|
* Shows confirmation dialog if at least one of the recipient id's is not confirmed.
|
|
|
|
|
*
|
|
|
|
|
* returns YES if an alert was shown
|
|
|
|
|
* NO if there were no unconfirmed identities
|
2017-05-25 19:45:42 +02:00
|
|
|
|
*/
|
2017-05-27 03:19:46 +02:00
|
|
|
|
- (BOOL)showSafetyNumberConfirmationIfNecessaryWithConfirmationText:(NSString *)confirmationText
|
2017-06-07 20:27:24 +02:00
|
|
|
|
completion:(void (^)(BOOL didConfirmIdentity))completionHandler
|
2017-05-27 03:19:46 +02:00
|
|
|
|
{
|
2017-06-01 03:12:18 +02:00
|
|
|
|
return [SafetyNumberConfirmationAlert presentAlertIfNecessaryWithRecipientIds:self.thread.recipientIdentifiers
|
2018-02-21 01:52:49 +01:00
|
|
|
|
confirmationText:confirmationText
|
|
|
|
|
contactsManager:self.contactsManager
|
|
|
|
|
completion:^(BOOL didShowAlert) {
|
|
|
|
|
// Pre iOS-11, the keyboard and inputAccessoryView will obscure the alert if the keyboard is up when the
|
|
|
|
|
// alert is presented, so after hiding it, we regain first responder here.
|
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
|
// do nothing
|
|
|
|
|
} else {
|
|
|
|
|
[self becomeFirstResponder];
|
|
|
|
|
}
|
|
|
|
|
completionHandler(didShowAlert);
|
|
|
|
|
}
|
|
|
|
|
beforePresentationHandler:^(void) {
|
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
|
// do nothing
|
|
|
|
|
} else {
|
|
|
|
|
// Pre iOS-11, the keyboard and inputAccessoryView will obscure the alert if the keyboard is up when the
|
|
|
|
|
// alert is presented.
|
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
[self resignFirstResponder];
|
|
|
|
|
}
|
|
|
|
|
}];
|
2017-05-25 19:45:42 +02:00
|
|
|
|
}
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
2017-06-07 22:51:22 +02:00
|
|
|
|
- (void)showFingerprintWithRecipientId:(NSString *)recipientId
|
2016-09-11 22:53:12 +02:00
|
|
|
|
{
|
2017-04-07 03:41:35 +02:00
|
|
|
|
// Ensure keyboard isn't hiding the "safety numbers changed" interaction when we
|
|
|
|
|
// return from FingerprintViewController.
|
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
|
2017-06-15 22:20:33 +02:00
|
|
|
|
[FingerprintViewController presentFromViewController:self recipientId:recipientId];
|
2014-12-24 02:25:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-29 19:54:33 +01:00
|
|
|
|
#pragma mark - Calls
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)callAction
|
2017-05-31 20:22:32 +02:00
|
|
|
|
{
|
2017-01-25 17:41:30 +01:00
|
|
|
|
OWSAssert([self.thread isKindOfClass:[TSContactThread class]]);
|
|
|
|
|
|
2017-01-26 19:39:13 +01:00
|
|
|
|
if (![self canCall]) {
|
2016-06-28 04:51:57 +02:00
|
|
|
|
DDLogWarn(@"Tried to initiate a call but thread is not callable.");
|
2017-01-26 19:39:13 +01:00
|
|
|
|
return;
|
2014-11-29 19:54:33 +01:00
|
|
|
|
}
|
2017-01-26 19:39:13 +01:00
|
|
|
|
|
2017-09-06 20:13:18 +02:00
|
|
|
|
__weak ConversationViewController *weakSelf = self;
|
2017-04-04 18:35:52 +02:00
|
|
|
|
if ([self isBlockedContactConversation]) {
|
2017-04-04 21:54:11 +02:00
|
|
|
|
[self showUnblockContactUI:^(BOOL isBlocked) {
|
|
|
|
|
if (!isBlocked) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[weakSelf callAction];
|
2017-04-04 21:54:11 +02:00
|
|
|
|
}
|
|
|
|
|
}];
|
2017-04-04 18:35:52 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-01 03:12:18 +02:00
|
|
|
|
BOOL didShowSNAlert =
|
|
|
|
|
[self showSafetyNumberConfirmationIfNecessaryWithConfirmationText:[CallStrings confirmAndCallButtonTitle]
|
|
|
|
|
completion:^(BOOL didConfirmIdentity) {
|
|
|
|
|
if (didConfirmIdentity) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[weakSelf callAction];
|
2017-06-01 03:12:18 +02:00
|
|
|
|
}
|
|
|
|
|
}];
|
2017-05-27 03:19:46 +02:00
|
|
|
|
if (didShowSNAlert) {
|
2017-05-27 01:32:04 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-02 00:26:47 +01:00
|
|
|
|
[self.outboundCallInitiator initiateCallWithRecipientId:self.thread.contactIdentifier];
|
2014-11-29 19:54:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (BOOL)canCall
|
|
|
|
|
{
|
|
|
|
|
return !(self.isGroupConversation ||
|
|
|
|
|
[((TSContactThread *)self.thread).contactIdentifier isEqualToString:[TSAccountManager localNumber]]);
|
2015-01-27 21:17:49 +01:00
|
|
|
|
}
|
2015-02-17 00:14:50 +01:00
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
|
#pragma mark - JSQMessagesViewController method overrides
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - Dynamic Text
|
2017-04-04 18:35:52 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
/**
|
|
|
|
|
Called whenever the user manually changes the dynamic type options inside Settings.
|
2017-06-07 21:31:54 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
@param notification NSNotification with the dynamic type change information.
|
|
|
|
|
*/
|
|
|
|
|
- (void)didChangePreferredContentSize:(NSNotification *)notification
|
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ didChangePreferredContentSize", self.logTag);
|
2017-10-16 18:29:22 +02:00
|
|
|
|
|
|
|
|
|
// Evacuate cached cell sizes.
|
|
|
|
|
for (ConversationViewItem *viewItem in self.viewItems) {
|
|
|
|
|
[viewItem clearCachedLayoutState];
|
|
|
|
|
}
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self resetContentAndLayout];
|
2017-10-16 18:29:22 +02:00
|
|
|
|
[self.inputToolbar updateFontSizes];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
2017-03-14 16:17:54 +01:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - Actions
|
2017-05-19 21:19:51 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)showNoLongerVerifiedUI
|
|
|
|
|
{
|
|
|
|
|
NSArray<NSString *> *noLongerVerifiedRecipientIds = [self noLongerVerifiedRecipientIds];
|
|
|
|
|
if (noLongerVerifiedRecipientIds.count > 1) {
|
|
|
|
|
[self showConversationSettingsAndShowVerification:YES];
|
|
|
|
|
} else if (noLongerVerifiedRecipientIds.count == 1) {
|
|
|
|
|
// Pick one in an arbitrary but deterministic manner.
|
|
|
|
|
NSString *recipientId = noLongerVerifiedRecipientIds.lastObject;
|
|
|
|
|
[self showFingerprintWithRecipientId:recipientId];
|
2017-10-01 03:04:36 +02:00
|
|
|
|
}
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
2017-05-16 21:52:19 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)showConversationSettings
|
|
|
|
|
{
|
|
|
|
|
[self showConversationSettingsAndShowVerification:NO];
|
2014-10-29 21:58:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)showConversationSettingsAndShowVerification:(BOOL)showVerification
|
2016-11-14 21:33:24 +01:00
|
|
|
|
{
|
2017-10-10 22:13:54 +02:00
|
|
|
|
if (self.userLeftGroup) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ Ignoring request to show conversation settings, since user left group", self.logTag);
|
2016-11-21 20:26:42 +01:00
|
|
|
|
return;
|
2016-11-14 21:33:24 +01:00
|
|
|
|
}
|
2017-06-20 19:43:05 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSConversationSettingsViewController *settingsVC = [OWSConversationSettingsViewController new];
|
|
|
|
|
settingsVC.conversationSettingsViewDelegate = self;
|
2018-03-19 17:22:39 +01:00
|
|
|
|
[settingsVC configureWithThread:self.thread uiDatabaseConnection:self.uiDatabaseConnection];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
settingsVC.showVerificationOnAppear = showVerification;
|
|
|
|
|
[self.navigationController pushViewController:settingsVC animated:YES];
|
2016-11-14 21:33:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 17:27:32 +01:00
|
|
|
|
#pragma mark - DisappearingTimerConfigurationViewDelegate
|
|
|
|
|
|
|
|
|
|
- (void)disappearingTimerConfigurationViewWasTapped:(DisappearingTimerConfigurationView *)disappearingTimerView
|
2017-10-10 22:13:54 +02:00
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ Tapped timer in navbar", self.logTag);
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self showConversationSettings];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 07:06:19 +02:00
|
|
|
|
#pragma mark - Load More
|
|
|
|
|
|
|
|
|
|
- (void)autoLoadMoreIfNecessary
|
|
|
|
|
{
|
|
|
|
|
if (self.isUserScrolling || !self.isViewVisible || self.isAppInBackground) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!self.showLoadMoreHeader) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
static const CGFloat kThreshold = 50.f;
|
|
|
|
|
if (self.collectionView.contentOffset.y < kThreshold) {
|
|
|
|
|
[self loadMoreMessages];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)loadMoreMessages
|
|
|
|
|
{
|
2017-10-16 02:46:48 +02:00
|
|
|
|
BOOL hasEarlierUnseenMessages = self.dynamicInteractions.hasMoreUnseenMessages;
|
|
|
|
|
|
|
|
|
|
// We want to restore the current scroll state after we update the range, update
|
|
|
|
|
// the dynamic interactions and re-layout. Here we take a "before" snapshot.
|
|
|
|
|
CGFloat scrollDistanceToBottom = self.safeContentHeight - self.collectionView.contentOffset.y;
|
|
|
|
|
|
2018-02-22 00:37:19 +01:00
|
|
|
|
self.lastRangeLength = MIN(self.lastRangeLength + kYapDatabasePageSize, (NSUInteger) kYapDatabaseRangeMaxLength);
|
2017-10-16 02:46:48 +02:00
|
|
|
|
|
|
|
|
|
[self resetMappings];
|
|
|
|
|
|
|
|
|
|
[self.layout prepareLayout];
|
|
|
|
|
|
|
|
|
|
self.collectionView.contentOffset = CGPointMake(0, self.safeContentHeight - scrollDistanceToBottom);
|
|
|
|
|
|
|
|
|
|
// Don’t auto-scroll after “loading more messages” unless we have “more unseen messages”.
|
|
|
|
|
//
|
|
|
|
|
// Otherwise, tapping on "load more messages" autoscrolls you downward which is completely wrong.
|
|
|
|
|
if (hasEarlierUnseenMessages) {
|
|
|
|
|
[self scrollToUnreadIndicatorAnimated];
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-15 22:41:40 +02:00
|
|
|
|
|
2017-10-19 07:06:19 +02:00
|
|
|
|
- (void)updateShowLoadMoreHeader
|
2016-03-11 19:34:39 +01:00
|
|
|
|
{
|
2018-02-22 00:37:19 +01:00
|
|
|
|
if (self.lastRangeLength == kYapDatabaseRangeMaxLength) {
|
2017-10-19 07:06:19 +02:00
|
|
|
|
self.showLoadMoreHeader = NO;
|
|
|
|
|
return;
|
2016-03-11 19:34:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 07:06:19 +02:00
|
|
|
|
NSUInteger loadWindowSize = [self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
|
|
|
|
__block NSUInteger totalMessageCount;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
2017-10-19 07:06:19 +02:00
|
|
|
|
totalMessageCount =
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInGroup:self.thread.uniqueId];
|
2014-12-31 13:22:40 +01:00
|
|
|
|
}];
|
2017-10-19 07:06:19 +02:00
|
|
|
|
self.showLoadMoreHeader = loadWindowSize < totalMessageCount;
|
2017-10-16 02:46:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setShowLoadMoreHeader:(BOOL)showLoadMoreHeader
|
2017-05-31 20:22:32 +02:00
|
|
|
|
{
|
2017-10-16 02:46:48 +02:00
|
|
|
|
BOOL valueChanged = _showLoadMoreHeader != showLoadMoreHeader;
|
|
|
|
|
|
|
|
|
|
_showLoadMoreHeader = showLoadMoreHeader;
|
|
|
|
|
|
|
|
|
|
self.loadMoreHeader.hidden = !showLoadMoreHeader;
|
|
|
|
|
self.loadMoreHeader.userInteractionEnabled = showLoadMoreHeader;
|
|
|
|
|
|
|
|
|
|
if (valueChanged) {
|
|
|
|
|
[self.collectionView.collectionViewLayout invalidateLayout];
|
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
|
}
|
2014-12-31 13:22:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-16 18:25:43 +01:00
|
|
|
|
- (void)updateDisappearingMessagesConfiguration
|
|
|
|
|
{
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
|
|
|
|
|
self.disappearingMessagesConfiguration =
|
|
|
|
|
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId transaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 04:02:27 +02:00
|
|
|
|
- (void)setDisappearingMessagesConfiguration:
|
|
|
|
|
(nullable OWSDisappearingMessagesConfiguration *)disappearingMessagesConfiguration
|
|
|
|
|
{
|
|
|
|
|
if (_disappearingMessagesConfiguration.isEnabled == disappearingMessagesConfiguration.isEnabled
|
|
|
|
|
&& _disappearingMessagesConfiguration.durationSeconds == disappearingMessagesConfiguration.durationSeconds) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_disappearingMessagesConfiguration = disappearingMessagesConfiguration;
|
|
|
|
|
[self updateBarButtonItems];
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 00:37:19 +01:00
|
|
|
|
- (void)updateMessageMappingRangeOptions
|
2017-05-26 00:00:41 +02:00
|
|
|
|
{
|
2018-02-22 00:37:19 +01:00
|
|
|
|
NSUInteger rangeLength = 0;
|
|
|
|
|
|
|
|
|
|
if (self.lastRangeLength == 0) {
|
|
|
|
|
// If this is the first time we're configuring the range length,
|
|
|
|
|
// try to take into account the position of the unread indicator.
|
2017-09-02 00:16:46 +02:00
|
|
|
|
OWSAssert(self.dynamicInteractions);
|
|
|
|
|
|
|
|
|
|
if (self.dynamicInteractions.unreadIndicatorPosition) {
|
|
|
|
|
NSUInteger unreadIndicatorPosition
|
|
|
|
|
= (NSUInteger)[self.dynamicInteractions.unreadIndicatorPosition longValue];
|
2018-02-22 00:37:19 +01:00
|
|
|
|
|
2017-09-02 00:16:46 +02:00
|
|
|
|
// If there is an unread indicator, increase the initial load window
|
|
|
|
|
// to include it.
|
|
|
|
|
OWSAssert(unreadIndicatorPosition > 0);
|
|
|
|
|
OWSAssert(unreadIndicatorPosition <= kYapDatabaseRangeMaxLength);
|
|
|
|
|
|
|
|
|
|
// We'd like to include at least N seen messages,
|
|
|
|
|
// to give the user the context of where they left off the conversation.
|
|
|
|
|
const NSUInteger kPreferredSeenMessageCount = 1;
|
2018-02-22 00:37:19 +01:00
|
|
|
|
rangeLength = unreadIndicatorPosition + kPreferredSeenMessageCount;
|
2017-09-02 00:16:46 +02:00
|
|
|
|
}
|
2017-08-23 19:10:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 00:37:19 +01:00
|
|
|
|
// Always try to load at least a single page of messages.
|
|
|
|
|
rangeLength = MAX(rangeLength, kYapDatabasePageSize);
|
|
|
|
|
|
|
|
|
|
// Range size should monotonically increase.
|
|
|
|
|
rangeLength = MAX(rangeLength, self.lastRangeLength);
|
|
|
|
|
|
|
|
|
|
// Enforce max range size.
|
|
|
|
|
rangeLength = MIN(rangeLength, kYapDatabaseRangeMaxLength);
|
|
|
|
|
|
|
|
|
|
self.lastRangeLength = rangeLength;
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
|
YapDatabaseViewRangeOptions *rangeOptions =
|
2017-08-16 21:32:56 +02:00
|
|
|
|
[YapDatabaseViewRangeOptions flexibleRangeWithLength:rangeLength offset:0 from:YapDatabaseViewEnd];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-08-16 21:32:56 +02:00
|
|
|
|
rangeOptions.maxLength = MAX(rangeLength, kYapDatabaseRangeMaxLength);
|
2014-12-31 13:22:40 +01:00
|
|
|
|
rangeOptions.minLength = kYapDatabaseRangeMinLength;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2014-12-31 13:22:40 +01:00
|
|
|
|
[self.messageMappings setRangeOptions:rangeOptions forGroup:self.thread.uniqueId];
|
2017-10-19 07:06:19 +02:00
|
|
|
|
[self updateShowLoadMoreHeader];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self reloadViewItems];
|
2014-12-31 13:22:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-11 00:05:41 +01:00
|
|
|
|
#pragma mark Bubble User Actions
|
|
|
|
|
|
2017-04-20 00:50:27 +02:00
|
|
|
|
- (void)handleFailedDownloadTapForMessage:(TSMessage *)message
|
|
|
|
|
attachmentPointer:(TSAttachmentPointer *)attachmentPointer
|
|
|
|
|
{
|
|
|
|
|
UIAlertController *actionSheetController = [UIAlertController
|
|
|
|
|
alertControllerWithTitle:NSLocalizedString(@"MESSAGES_VIEW_FAILED_DOWNLOAD_ACTIONSHEET_TITLE", comment
|
|
|
|
|
: "Action sheet title after tapping on failed download.")
|
|
|
|
|
message:nil
|
|
|
|
|
preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
|
2017-08-21 22:58:26 +02:00
|
|
|
|
[actionSheetController addAction:[OWSAlerts cancelAction]];
|
2017-04-20 00:50:27 +02:00
|
|
|
|
|
|
|
|
|
UIAlertAction *deleteMessageAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_DELETE_TITLE", @"")
|
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
|
[message remove];
|
|
|
|
|
}];
|
|
|
|
|
[actionSheetController addAction:deleteMessageAction];
|
|
|
|
|
|
|
|
|
|
UIAlertAction *resendMessageAction = [UIAlertAction
|
|
|
|
|
actionWithTitle:NSLocalizedString(@"MESSAGES_VIEW_FAILED_DOWNLOAD_RETRY_ACTION", @"Action sheet button text")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
|
OWSAttachmentsProcessor *processor =
|
|
|
|
|
[[OWSAttachmentsProcessor alloc] initWithAttachmentPointer:attachmentPointer
|
2017-09-13 22:48:38 +02:00
|
|
|
|
networkManager:self.networkManager
|
2018-03-05 15:30:58 +01:00
|
|
|
|
primaryStorage:self.primaryStorage];
|
2017-04-20 00:50:27 +02:00
|
|
|
|
[processor fetchAttachmentsForMessage:message
|
2018-03-05 15:30:58 +01:00
|
|
|
|
primaryStorage:self.primaryStorage
|
2017-04-20 00:50:27 +02:00
|
|
|
|
success:^(TSAttachmentStream *_Nonnull attachmentStream) {
|
|
|
|
|
DDLogInfo(
|
2017-11-08 20:04:51 +01:00
|
|
|
|
@"%@ Successfully redownloaded attachment in thread: %@", self.logTag, message.thread);
|
2017-04-20 00:50:27 +02:00
|
|
|
|
}
|
|
|
|
|
failure:^(NSError *_Nonnull error) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogWarn(@"%@ Failed to redownload message with error: %@", self.logTag, error);
|
2017-04-20 00:50:27 +02:00
|
|
|
|
}];
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
[actionSheetController addAction:resendMessageAction];
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2017-04-20 00:50:27 +02:00
|
|
|
|
[self presentViewController:actionSheetController animated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)handleUnsentMessageTap:(TSOutgoingMessage *)message
|
|
|
|
|
{
|
|
|
|
|
UIAlertController *actionSheetController =
|
|
|
|
|
[UIAlertController alertControllerWithTitle:message.mostRecentFailureText
|
|
|
|
|
message:nil
|
|
|
|
|
preferredStyle:UIAlertControllerStyleActionSheet];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
|
2017-08-21 22:58:26 +02:00
|
|
|
|
[actionSheetController addAction:[OWSAlerts cancelAction]];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
|
|
|
|
|
UIAlertAction *deleteMessageAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_DELETE_TITLE", @"")
|
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
|
[message remove];
|
|
|
|
|
}];
|
|
|
|
|
[actionSheetController addAction:deleteMessageAction];
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
UIAlertAction *resendMessageAction =
|
|
|
|
|
[UIAlertAction actionWithTitle:NSLocalizedString(@"SEND_AGAIN_BUTTON", @"")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
2017-11-15 19:21:31 +01:00
|
|
|
|
[self.messageSender enqueueMessage:message
|
2017-05-31 20:22:32 +02:00
|
|
|
|
success:^{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ Successfully resent failed message.", self.logTag);
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}
|
|
|
|
|
failure:^(NSError *_Nonnull error) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogWarn(@"%@ Failed to send message with error: %@", self.logTag, error);
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}];
|
|
|
|
|
}];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
|
|
|
|
|
[actionSheetController addAction:resendMessageAction];
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[self presentViewController:actionSheetController animated:YES completion:nil];
|
2014-12-11 00:05:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-11 22:53:12 +02:00
|
|
|
|
- (void)handleErrorMessageTap:(TSErrorMessage *)message
|
|
|
|
|
{
|
2017-06-06 15:46:00 +02:00
|
|
|
|
OWSAssert(message);
|
|
|
|
|
|
|
|
|
|
switch (message.errorType) {
|
|
|
|
|
case TSErrorMessageInvalidKeyException:
|
|
|
|
|
break;
|
|
|
|
|
case TSErrorMessageNonBlockingIdentityChange:
|
|
|
|
|
[self tappedNonBlockingIdentityChangeForRecipientId:message.recipientId];
|
|
|
|
|
return;
|
|
|
|
|
case TSErrorMessageWrongTrustedIdentityKey:
|
|
|
|
|
OWSAssert([message isKindOfClass:[TSInvalidIdentityKeyErrorMessage class]]);
|
|
|
|
|
[self tappedInvalidIdentityKeyErrorMessage:(TSInvalidIdentityKeyErrorMessage *)message];
|
|
|
|
|
return;
|
|
|
|
|
case TSErrorMessageMissingKeyId:
|
|
|
|
|
// Unused.
|
|
|
|
|
break;
|
|
|
|
|
case TSErrorMessageNoSession:
|
|
|
|
|
break;
|
|
|
|
|
case TSErrorMessageInvalidMessage:
|
|
|
|
|
[self tappedCorruptedMessage:message];
|
|
|
|
|
return;
|
|
|
|
|
case TSErrorMessageDuplicateMessage:
|
|
|
|
|
// Unused.
|
|
|
|
|
break;
|
|
|
|
|
case TSErrorMessageInvalidVersion:
|
|
|
|
|
break;
|
|
|
|
|
case TSErrorMessageUnknownContactBlockOffer:
|
2017-08-18 17:49:54 +02:00
|
|
|
|
// Unused.
|
|
|
|
|
OWSFail(@"TSErrorMessageUnknownContactBlockOffer");
|
2017-06-06 15:46:00 +02:00
|
|
|
|
return;
|
2017-06-13 21:09:47 +02:00
|
|
|
|
case TSErrorMessageGroupCreationFailed:
|
|
|
|
|
[self resendGroupUpdateForErrorMessage:message];
|
|
|
|
|
return;
|
2016-09-11 22:53:12 +02:00
|
|
|
|
}
|
2017-06-06 15:46:00 +02:00
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogWarn(@"%@ Unhandled tap for error message:%@", self.logTag, message);
|
2016-09-11 22:53:12 +02:00
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-06-16 17:59:59 +02:00
|
|
|
|
- (void)tappedNonBlockingIdentityChangeForRecipientId:(nullable NSString *)signalId
|
2017-05-23 17:28:12 +02:00
|
|
|
|
{
|
2017-06-16 17:59:59 +02:00
|
|
|
|
if (signalId == nil) {
|
2017-06-16 18:33:50 +02:00
|
|
|
|
if (self.thread.isGroupThread) {
|
|
|
|
|
// Before 2.13 we didn't track the recipient id in the identity change error.
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogWarn(@"%@ Ignoring tap on legacy nonblocking identity change since it has no signal id", self.logTag);
|
2017-06-16 18:33:50 +02:00
|
|
|
|
} else {
|
|
|
|
|
DDLogInfo(
|
|
|
|
|
@"%@ Assuming tap on legacy nonblocking identity change corresponds to current contact thread: %@",
|
2017-11-08 20:04:51 +01:00
|
|
|
|
self.logTag,
|
2017-06-16 18:33:50 +02:00
|
|
|
|
self.thread.contactIdentifier);
|
|
|
|
|
signalId = self.thread.contactIdentifier;
|
|
|
|
|
}
|
2017-06-16 17:59:59 +02:00
|
|
|
|
}
|
2017-05-23 17:28:12 +02:00
|
|
|
|
|
2017-06-07 22:51:22 +02:00
|
|
|
|
[self showFingerprintWithRecipientId:signalId];
|
2017-05-23 17:28:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 19:23:46 +02:00
|
|
|
|
- (void)handleInfoMessageTap:(TSInfoMessage *)message
|
|
|
|
|
{
|
2017-06-06 15:46:00 +02:00
|
|
|
|
OWSAssert(message);
|
|
|
|
|
|
|
|
|
|
switch (message.messageType) {
|
|
|
|
|
case TSInfoMessageUserNotRegistered:
|
|
|
|
|
break;
|
|
|
|
|
case TSInfoMessageTypeSessionDidEnd:
|
|
|
|
|
break;
|
|
|
|
|
case TSInfoMessageTypeUnsupportedMessage:
|
|
|
|
|
// Unused.
|
|
|
|
|
break;
|
|
|
|
|
case TSInfoMessageAddToContactsOffer:
|
2017-08-18 17:49:54 +02:00
|
|
|
|
// Unused.
|
|
|
|
|
OWSFail(@"TSInfoMessageAddToContactsOffer");
|
2017-06-06 15:46:00 +02:00
|
|
|
|
return;
|
2017-08-03 23:43:21 +02:00
|
|
|
|
case TSInfoMessageAddUserToProfileWhitelistOffer:
|
2017-08-18 17:49:54 +02:00
|
|
|
|
// Unused.
|
|
|
|
|
OWSFail(@"TSInfoMessageAddUserToProfileWhitelistOffer");
|
|
|
|
|
return;
|
2017-08-03 23:43:21 +02:00
|
|
|
|
case TSInfoMessageAddGroupToProfileWhitelistOffer:
|
2017-08-18 17:49:54 +02:00
|
|
|
|
// Unused.
|
|
|
|
|
OWSFail(@"TSInfoMessageAddGroupToProfileWhitelistOffer");
|
2017-08-03 23:43:21 +02:00
|
|
|
|
return;
|
2017-06-06 15:46:00 +02:00
|
|
|
|
case TSInfoMessageTypeGroupUpdate:
|
|
|
|
|
[self showConversationSettings];
|
|
|
|
|
return;
|
|
|
|
|
case TSInfoMessageTypeGroupQuit:
|
|
|
|
|
break;
|
|
|
|
|
case TSInfoMessageTypeDisappearingMessagesUpdate:
|
|
|
|
|
[self showConversationSettings];
|
|
|
|
|
return;
|
2017-06-07 22:51:22 +02:00
|
|
|
|
case TSInfoMessageVerificationStateChange:
|
|
|
|
|
[self showFingerprintWithRecipientId:((OWSVerificationStateChangeMessage *)message).recipientId];
|
|
|
|
|
break;
|
2017-05-19 19:23:46 +02:00
|
|
|
|
}
|
2017-06-06 15:46:00 +02:00
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ Unhandled tap for info message:%@", self.logTag, message);
|
2017-05-19 19:23:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 20:02:15 +01:00
|
|
|
|
- (void)tappedCorruptedMessage:(TSErrorMessage *)message
|
|
|
|
|
{
|
2016-11-26 00:12:00 +01:00
|
|
|
|
NSString *alertMessage = [NSString
|
2016-11-01 20:02:15 +01:00
|
|
|
|
stringWithFormat:NSLocalizedString(@"CORRUPTED_SESSION_DESCRIPTION", @"ActionSheet title"), self.thread.name];
|
|
|
|
|
|
2016-11-26 00:12:00 +01:00
|
|
|
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
|
|
|
|
|
message:alertMessage
|
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-08-21 22:58:26 +02:00
|
|
|
|
[alertController addAction:[OWSAlerts cancelAction]];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
|
|
|
|
UIAlertAction *resetSessionAction = [UIAlertAction
|
|
|
|
|
actionWithTitle:NSLocalizedString(@"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON", @"")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
|
if (![self.thread isKindOfClass:[TSContactThread class]]) {
|
|
|
|
|
// Corrupt Message errors only appear in contact threads.
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ Unexpected request to reset session in group thread. Refusing", self.logTag);
|
2017-05-31 20:22:32 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
|
[OWSSessionResetJob runWithContactThread:contactThread
|
|
|
|
|
messageSender:self.messageSender
|
2018-03-05 15:30:58 +01:00
|
|
|
|
primaryStorage:self.primaryStorage];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[alertController addAction:resetSessionAction];
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[self presentViewController:alertController animated:YES completion:nil];
|
2016-11-01 20:02:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-11 22:53:12 +02:00
|
|
|
|
- (void)tappedInvalidIdentityKeyErrorMessage:(TSInvalidIdentityKeyErrorMessage *)errorMessage
|
|
|
|
|
{
|
2016-12-01 22:17:57 +01:00
|
|
|
|
NSString *keyOwner = [self.contactsManager displayNameForPhoneIdentifier:errorMessage.theirSignalId];
|
2016-09-11 22:53:12 +02:00
|
|
|
|
NSString *titleFormat = NSLocalizedString(@"SAFETY_NUMBERS_ACTIONSHEET_TITLE", @"Action sheet heading");
|
|
|
|
|
NSString *titleText = [NSString stringWithFormat:titleFormat, keyOwner];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
|
2017-04-10 03:39:04 +02:00
|
|
|
|
UIAlertController *actionSheetController =
|
|
|
|
|
[UIAlertController alertControllerWithTitle:titleText
|
|
|
|
|
message:nil
|
|
|
|
|
preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
|
2017-08-21 22:58:26 +02:00
|
|
|
|
[actionSheetController addAction:[OWSAlerts cancelAction]];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
|
2017-04-10 03:39:04 +02:00
|
|
|
|
UIAlertAction *showSafteyNumberAction =
|
|
|
|
|
[UIAlertAction actionWithTitle:NSLocalizedString(@"SHOW_SAFETY_NUMBER_ACTION", @"Action sheet item")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ Remote Key Changed actions: Show fingerprint display", self.logTag);
|
2017-06-07 22:51:22 +02:00
|
|
|
|
[self showFingerprintWithRecipientId:errorMessage.theirSignalId];
|
2017-04-10 03:39:04 +02:00
|
|
|
|
}];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[actionSheetController addAction:showSafteyNumberAction];
|
2017-04-10 03:39:04 +02:00
|
|
|
|
|
2017-09-06 20:13:18 +02:00
|
|
|
|
UIAlertAction *acceptSafetyNumberAction =
|
|
|
|
|
[UIAlertAction actionWithTitle:NSLocalizedString(@"ACCEPT_NEW_IDENTITY_ACTION", @"Action sheet item")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ Remote Key Changed actions: Accepted new identity key", self.logTag);
|
2017-09-06 20:13:18 +02:00
|
|
|
|
|
|
|
|
|
// DEPRECATED: we're no longer creating these incoming SN error's per message,
|
|
|
|
|
// but there will be some legacy ones in the wild, behind which await
|
|
|
|
|
// as-of-yet-undecrypted messages
|
|
|
|
|
if ([errorMessage isKindOfClass:[TSInvalidIdentityKeyReceivingErrorMessage class]]) {
|
|
|
|
|
[errorMessage acceptNewIdentityKey];
|
|
|
|
|
}
|
|
|
|
|
}];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[actionSheetController addAction:acceptSafetyNumberAction];
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[self presentViewController:actionSheetController animated:YES completion:nil];
|
2014-10-29 21:58:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-18 17:49:54 +02:00
|
|
|
|
- (void)handleCallTap:(TSCall *)call
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(call);
|
|
|
|
|
|
|
|
|
|
if (![self.thread isKindOfClass:[TSContactThread class]]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ unexpected thread: %@ in %s", self.logTag, self.thread, __PRETTY_FUNCTION__);
|
2017-08-18 17:49:54 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
|
NSString *displayName = [self.contactsManager displayNameForPhoneIdentifier:contactThread.contactIdentifier];
|
|
|
|
|
|
|
|
|
|
UIAlertController *alertController = [UIAlertController
|
|
|
|
|
alertControllerWithTitle:[CallStrings callBackAlertTitle]
|
|
|
|
|
message:[NSString stringWithFormat:[CallStrings callBackAlertMessageFormat], displayName]
|
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
2017-09-06 20:13:18 +02:00
|
|
|
|
__weak ConversationViewController *weakSelf = self;
|
2017-08-18 17:49:54 +02:00
|
|
|
|
UIAlertAction *callAction = [UIAlertAction actionWithTitle:[CallStrings callBackAlertCallButton]
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[weakSelf callAction];
|
2017-08-18 17:49:54 +02:00
|
|
|
|
}];
|
|
|
|
|
[alertController addAction:callAction];
|
2017-08-21 22:58:26 +02:00
|
|
|
|
[alertController addAction:[OWSAlerts cancelAction]];
|
2017-08-18 17:49:54 +02:00
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
[self presentViewController:alertController animated:YES completion:nil];
|
2017-08-18 17:49:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - ConversationViewCellDelegate
|
2017-08-18 17:49:54 +02:00
|
|
|
|
|
2017-10-12 05:03:28 +02:00
|
|
|
|
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-12 05:03:28 +02:00
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
|
|
return [self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:recipientId];
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-18 17:49:54 +02:00
|
|
|
|
- (void)tappedUnknownContactBlockOfferMessage:(OWSContactOffersInteraction *)interaction
|
2017-04-10 03:39:04 +02:00
|
|
|
|
{
|
2017-08-18 17:49:54 +02:00
|
|
|
|
if (![self.thread isKindOfClass:[TSContactThread class]]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ unexpected thread: %@ in %s", self.logTag, self.thread, __PRETTY_FUNCTION__);
|
2017-08-18 17:49:54 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
|
|
2017-08-21 23:13:36 +02:00
|
|
|
|
NSString *displayName = [self.contactsManager displayNameForPhoneIdentifier:interaction.recipientId];
|
2017-04-10 03:39:04 +02:00
|
|
|
|
NSString *title =
|
|
|
|
|
[NSString stringWithFormat:NSLocalizedString(@"BLOCK_OFFER_ACTIONSHEET_TITLE_FORMAT",
|
|
|
|
|
@"Title format for action sheet that offers to block an unknown user."
|
|
|
|
|
@"Embeds {{the unknown user's name or phone number}}."),
|
|
|
|
|
[BlockListUIUtils formatDisplayNameForAlertTitle:displayName]];
|
|
|
|
|
|
|
|
|
|
UIAlertController *actionSheetController =
|
|
|
|
|
[UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
|
2017-08-21 22:58:26 +02:00
|
|
|
|
[actionSheetController addAction:[OWSAlerts cancelAction]];
|
2017-04-10 03:39:04 +02:00
|
|
|
|
|
2017-09-06 20:13:18 +02:00
|
|
|
|
UIAlertAction *blockAction = [UIAlertAction
|
|
|
|
|
actionWithTitle:NSLocalizedString(
|
|
|
|
|
@"BLOCK_OFFER_ACTIONSHEET_BLOCK_ACTION", @"Action sheet that will block an unknown user.")
|
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ Blocking an unknown user.", self.logTag);
|
2017-09-06 20:13:18 +02:00
|
|
|
|
[self.blockingManager addBlockedPhoneNumber:interaction.recipientId];
|
|
|
|
|
// Delete the offers.
|
|
|
|
|
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
contactThread.hasDismissedOffers = YES;
|
|
|
|
|
[contactThread saveWithTransaction:transaction];
|
|
|
|
|
[interaction removeWithTransaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
}];
|
2017-04-10 03:39:04 +02:00
|
|
|
|
[actionSheetController addAction:blockAction];
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2017-04-10 03:39:04 +02:00
|
|
|
|
[self presentViewController:actionSheetController animated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-18 17:49:54 +02:00
|
|
|
|
- (void)tappedAddToContactsOfferMessage:(OWSContactOffersInteraction *)interaction
|
2017-05-19 19:23:46 +02:00
|
|
|
|
{
|
|
|
|
|
if (!self.contactsManager.supportsContactEditing) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Contact editing not supported", self.logTag);
|
2017-05-19 19:23:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (![self.thread isKindOfClass:[TSContactThread class]]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ unexpected thread: %@ in %s", self.logTag, self.thread, __PRETTY_FUNCTION__);
|
2017-05-19 19:23:46 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
|
[self.contactsViewHelper presentContactViewControllerForRecipientId:contactThread.contactIdentifier
|
|
|
|
|
fromViewController:self
|
|
|
|
|
editImmediately:YES];
|
2017-08-18 17:49:54 +02:00
|
|
|
|
|
|
|
|
|
// Delete the offers.
|
|
|
|
|
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
contactThread.hasDismissedOffers = YES;
|
|
|
|
|
[contactThread saveWithTransaction:transaction];
|
|
|
|
|
[interaction removeWithTransaction:transaction];
|
|
|
|
|
}];
|
2017-05-19 19:23:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-18 17:49:54 +02:00
|
|
|
|
- (void)tappedAddToProfileWhitelistOfferMessage:(OWSContactOffersInteraction *)interaction
|
2017-08-03 23:43:21 +02:00
|
|
|
|
{
|
2017-08-28 22:45:24 +02:00
|
|
|
|
// This is accessed via the contact offer. Group whitelisting happens via a different interaction.
|
2017-08-18 17:49:54 +02:00
|
|
|
|
if (![self.thread isKindOfClass:[TSContactThread class]]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ unexpected thread: %@ in %s", self.logTag, self.thread, __PRETTY_FUNCTION__);
|
2017-08-18 17:49:54 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
|
|
2017-08-28 22:45:24 +02:00
|
|
|
|
[self presentAddThreadToProfileWhitelistWithSuccess:^() {
|
|
|
|
|
// Delete the offers.
|
|
|
|
|
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
contactThread.hasDismissedOffers = YES;
|
|
|
|
|
[contactThread saveWithTransaction:transaction];
|
|
|
|
|
[interaction removeWithTransaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
}];
|
|
|
|
|
}
|
2017-08-03 23:43:21 +02:00
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
|
- (void)presentAddThreadToProfileWhitelistWithSuccess:(void (^)(void))successHandler
|
2017-08-28 22:45:24 +02:00
|
|
|
|
{
|
|
|
|
|
[[OWSProfileManager sharedManager] presentAddThreadToProfileWhitelist:self.thread
|
|
|
|
|
fromViewController:self
|
|
|
|
|
success:successHandler];
|
2017-08-03 23:43:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - Message Events
|
|
|
|
|
|
|
|
|
|
- (void)didTapImageViewItem:(ConversationViewItem *)viewItem
|
|
|
|
|
attachmentStream:(TSAttachmentStream *)attachmentStream
|
|
|
|
|
imageView:(UIView *)imageView
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSAssert(viewItem);
|
|
|
|
|
OWSAssert(attachmentStream);
|
|
|
|
|
OWSAssert(imageView);
|
|
|
|
|
|
2018-01-05 16:10:13 +01:00
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
|
2018-03-12 23:04:16 +01:00
|
|
|
|
if (![viewItem.interaction isKindOfClass:[TSMessage class]]) {
|
|
|
|
|
OWSFail(@"Unexpected viewItem.interaction");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TSMessage *mediaMessage = (TSMessage *)viewItem.interaction;
|
|
|
|
|
|
2018-03-20 14:56:39 +01:00
|
|
|
|
MediaGalleryViewController *vc = [[MediaGalleryViewController alloc]
|
|
|
|
|
initWithThread:self.thread
|
|
|
|
|
uiDatabaseConnection:self.uiDatabaseConnection
|
|
|
|
|
options:MediaGalleryOptionSliderEnabled | MediaGalleryOptionShowAllMediaButton];
|
2018-03-12 23:04:16 +01:00
|
|
|
|
|
2018-03-19 17:22:39 +01:00
|
|
|
|
[vc presentDetailViewFromViewController:self mediaMessage:mediaMessage replacingView:imageView];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-05 16:10:13 +01:00
|
|
|
|
- (void)didTapVideoViewItem:(ConversationViewItem *)viewItem
|
|
|
|
|
attachmentStream:(TSAttachmentStream *)attachmentStream
|
|
|
|
|
imageView:(UIImageView *)imageView
|
2017-10-10 22:13:54 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSAssert(viewItem);
|
|
|
|
|
OWSAssert(attachmentStream);
|
|
|
|
|
|
|
|
|
|
[self dismissKeyBoard];
|
2018-03-12 23:04:16 +01:00
|
|
|
|
|
|
|
|
|
if (![viewItem.interaction isKindOfClass:[TSMessage class]]) {
|
|
|
|
|
OWSFail(@"Unexpected viewItem.interaction");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TSMessage *mediaMessage = (TSMessage *)viewItem.interaction;
|
|
|
|
|
|
2018-03-20 14:56:39 +01:00
|
|
|
|
MediaGalleryViewController *vc = [[MediaGalleryViewController alloc]
|
|
|
|
|
initWithThread:self.thread
|
|
|
|
|
uiDatabaseConnection:self.uiDatabaseConnection
|
|
|
|
|
options:MediaGalleryOptionSliderEnabled | MediaGalleryOptionShowAllMediaButton];
|
2018-03-15 18:46:29 +01:00
|
|
|
|
|
2018-03-19 17:22:39 +01:00
|
|
|
|
[vc presentDetailViewFromViewController:self mediaMessage:mediaMessage replacingView:imageView];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)didTapAudioViewItem:(ConversationViewItem *)viewItem attachmentStream:(TSAttachmentStream *)attachmentStream
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSAssert(viewItem);
|
|
|
|
|
OWSAssert(attachmentStream);
|
|
|
|
|
|
|
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
|
if (![fileManager fileExistsAtPath:[attachmentStream.mediaURL path]]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Missing video file: %@", self.logTag, attachmentStream.mediaURL);
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
|
|
|
|
|
if (self.audioAttachmentPlayer) {
|
|
|
|
|
// Is this player associated with this media adapter?
|
|
|
|
|
if (self.audioAttachmentPlayer.owner == viewItem) {
|
|
|
|
|
// Tap to pause & unpause.
|
|
|
|
|
[self.audioAttachmentPlayer togglePlayState];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[self.audioAttachmentPlayer stop];
|
|
|
|
|
self.audioAttachmentPlayer = nil;
|
|
|
|
|
}
|
2018-02-23 21:44:46 +01:00
|
|
|
|
self.audioAttachmentPlayer = [[OWSAudioPlayer alloc] initWithMediaUrl:attachmentStream.mediaURL delegate:viewItem];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
// Associate the player with this media adapter.
|
|
|
|
|
self.audioAttachmentPlayer.owner = viewItem;
|
2018-03-03 17:33:31 +01:00
|
|
|
|
[self.audioAttachmentPlayer playWithPlaybackAudioCategory];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 20:53:54 +02:00
|
|
|
|
- (void)didTapTruncatedTextMessage:(ConversationViewItem *)conversationItem
|
2017-10-10 22:13:54 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-25 20:53:54 +02:00
|
|
|
|
OWSAssert(conversationItem);
|
2017-10-26 18:09:36 +02:00
|
|
|
|
OWSAssert([conversationItem.interaction isKindOfClass:[TSMessage class]]);
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
2018-04-05 21:55:59 +02:00
|
|
|
|
LongTextViewController *view = [[LongTextViewController alloc] initWithViewItem:conversationItem];
|
2017-10-25 20:53:54 +02:00
|
|
|
|
[self.navigationController pushViewController:view animated:YES];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)didTapFailedIncomingAttachment:(ConversationViewItem *)viewItem
|
|
|
|
|
attachmentPointer:(TSAttachmentPointer *)attachmentPointer
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSAssert(viewItem);
|
|
|
|
|
OWSAssert(attachmentPointer);
|
|
|
|
|
|
|
|
|
|
// Restart failed downloads
|
|
|
|
|
TSMessage *message = (TSMessage *)viewItem.interaction;
|
|
|
|
|
[self handleFailedDownloadTapForMessage:message attachmentPointer:attachmentPointer];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)didTapFailedOutgoingMessage:(TSOutgoingMessage *)message
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSAssert(message);
|
|
|
|
|
|
|
|
|
|
[self handleUnsentMessageTap:message];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-25 20:53:54 +02:00
|
|
|
|
- (void)showMetadataViewForViewItem:(ConversationViewItem *)conversationItem
|
2017-10-10 22:13:54 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-25 20:53:54 +02:00
|
|
|
|
OWSAssert(conversationItem);
|
2017-10-26 18:09:36 +02:00
|
|
|
|
OWSAssert([conversationItem.interaction isKindOfClass:[TSMessage class]]);
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
2017-10-25 20:53:54 +02:00
|
|
|
|
TSMessage *message = (TSMessage *)conversationItem.interaction;
|
2017-10-26 18:09:36 +02:00
|
|
|
|
MessageDetailViewController *view =
|
|
|
|
|
[[MessageDetailViewController alloc] initWithViewItem:conversationItem
|
|
|
|
|
message:message
|
|
|
|
|
mode:MessageMetadataViewModeFocusOnMetadata];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self.navigationController pushViewController:view animated:YES];
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 04:31:13 +02:00
|
|
|
|
- (void)conversationCell:(ConversationViewCell *)cell didTapReplyForViewItem:(ConversationViewItem *)conversationItem
|
|
|
|
|
{
|
|
|
|
|
DDLogDebug(@"%@ user did tap reply", self.logTag);
|
|
|
|
|
|
|
|
|
|
TSMessage *message = (TSMessage *)conversationItem.interaction;
|
|
|
|
|
if (![message isKindOfClass:[TSMessage class]]) {
|
|
|
|
|
OWSFail(@"%@ unexpected reply message: %@", self.logTag, message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__block TSQuotedMessage *quotedMessage;
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
|
|
|
|
|
quotedMessage = [OWSMessageUtils quotedMessageForMessage:message transaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
if (![quotedMessage isKindOfClass:[TSQuotedMessage class]]) {
|
|
|
|
|
OWSFail(@"%@ unexpected quotedMessage: %@", self.logTag, quotedMessage);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self.inputToolbar setQuotedMessage:quotedMessage];
|
|
|
|
|
[self.inputToolbar beginEditingTextMessage];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - System Messages
|
2017-06-06 15:46:00 +02:00
|
|
|
|
|
|
|
|
|
- (void)didTapSystemMessageWithInteraction:(TSInteraction *)interaction
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-06-06 15:46:00 +02:00
|
|
|
|
OWSAssert(interaction);
|
|
|
|
|
|
|
|
|
|
if ([interaction isKindOfClass:[TSErrorMessage class]]) {
|
|
|
|
|
[self handleErrorMessageTap:(TSErrorMessage *)interaction];
|
|
|
|
|
} else if ([interaction isKindOfClass:[TSInfoMessage class]]) {
|
|
|
|
|
[self handleInfoMessageTap:(TSInfoMessage *)interaction];
|
|
|
|
|
} else if ([interaction isKindOfClass:[TSCall class]]) {
|
|
|
|
|
[self handleCallTap:(TSCall *)interaction];
|
|
|
|
|
} else {
|
|
|
|
|
OWSFail(@"Tap for system messages of unknown type: %@", [interaction class]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 19:23:46 +02:00
|
|
|
|
#pragma mark - ContactEditingDelegate
|
|
|
|
|
|
|
|
|
|
- (void)didFinishEditingContact
|
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
2017-05-19 19:23:46 +02:00
|
|
|
|
|
|
|
|
|
[self dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - CNContactViewControllerDelegate
|
|
|
|
|
|
|
|
|
|
- (void)contactViewController:(CNContactViewController *)viewController
|
|
|
|
|
didCompleteWithContact:(nullable CNContact *)contact
|
|
|
|
|
{
|
|
|
|
|
if (contact) {
|
|
|
|
|
// Saving normally returns you to the "Show Contact" view
|
|
|
|
|
// which we're not interested in, so we skip it here. There is
|
|
|
|
|
// an unfortunate blip of the "Show Contact" view on slower devices.
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ completed editing contact.", self.logTag);
|
2017-05-19 19:23:46 +02:00
|
|
|
|
[self dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
|
} else {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ canceled editing contact.", self.logTag);
|
2017-05-19 19:23:46 +02:00
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - ContactsViewHelperDelegate
|
|
|
|
|
|
|
|
|
|
- (void)contactsViewHelperDidUpdateContacts
|
|
|
|
|
{
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[self ensureDynamicInteractions];
|
2017-05-19 19:23:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)ensureDynamicInteractions
|
2017-05-19 19:23:46 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-19 19:23:46 +02:00
|
|
|
|
|
2018-02-22 00:37:19 +01:00
|
|
|
|
const int currentMaxRangeSize = (int)self.lastRangeLength;
|
2017-09-02 00:16:46 +02:00
|
|
|
|
const int maxRangeSize = MAX(kConversationInitialMaxRangeSize, currentMaxRangeSize);
|
2017-05-26 00:00:41 +02:00
|
|
|
|
|
2017-06-19 20:05:59 +02:00
|
|
|
|
// `ensureDynamicInteractionsForThread` should operate on the latest thread contents, so
|
|
|
|
|
// we should _read_ from uiDatabaseConnection and _write_ to `editingDatabaseConnection`.
|
2017-05-31 20:22:32 +02:00
|
|
|
|
self.dynamicInteractions =
|
|
|
|
|
[ThreadUtil ensureDynamicInteractionsForThread:self.thread
|
|
|
|
|
contactsManager:self.contactsManager
|
|
|
|
|
blockingManager:self.blockingManager
|
2017-06-19 23:10:34 +02:00
|
|
|
|
dbConnection:self.editingDatabaseConnection
|
2017-05-31 20:22:32 +02:00
|
|
|
|
hideUnreadMessagesIndicator:self.hasClearedUnreadMessagesIndicator
|
|
|
|
|
firstUnseenInteractionTimestamp:self.dynamicInteractions.firstUnseenInteractionTimestamp
|
|
|
|
|
maxRangeSize:maxRangeSize];
|
2017-05-19 21:19:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)clearUnreadMessagesIndicator
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-19 21:19:51 +02:00
|
|
|
|
|
|
|
|
|
if (self.hasClearedUnreadMessagesIndicator) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
// ensureDynamicInteractionsForThread is somewhat expensive
|
2017-05-19 21:36:43 +02:00
|
|
|
|
// so we don't want to call it unnecessarily.
|
2017-05-19 21:19:51 +02:00
|
|
|
|
return;
|
2017-05-19 19:23:46 +02:00
|
|
|
|
}
|
2017-05-19 21:19:51 +02:00
|
|
|
|
|
|
|
|
|
// Once we've cleared the unread messages indicator,
|
|
|
|
|
// make sure we don't show it again.
|
|
|
|
|
self.hasClearedUnreadMessagesIndicator = YES;
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
if (self.dynamicInteractions.unreadIndicatorPosition) {
|
2017-05-30 18:19:17 +02:00
|
|
|
|
// If we've just cleared the "unread messages" indicator,
|
|
|
|
|
// update the dynamic interactions.
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 22:23:42 +01:00
|
|
|
|
- (void)createConversationScrollButtons
|
2017-10-10 22:13:54 +02:00
|
|
|
|
{
|
2017-11-21 22:23:42 +01:00
|
|
|
|
self.scrollDownButton = [[ConversationScrollButton alloc] initWithIconText:@"\uf103"];
|
|
|
|
|
[self.scrollDownButton addTarget:self
|
|
|
|
|
action:@selector(scrollDownButtonTapped)
|
|
|
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
[self.view addSubview:self.scrollDownButton];
|
2017-11-22 15:39:11 +01:00
|
|
|
|
[self.scrollDownButton autoSetDimension:ALDimensionWidth toSize:ConversationScrollButton.buttonSize];
|
|
|
|
|
[self.scrollDownButton autoSetDimension:ALDimensionHeight toSize:ConversationScrollButton.buttonSize];
|
2018-01-02 22:55:40 +01:00
|
|
|
|
|
|
|
|
|
self.scrollDownButtonButtomConstraint =
|
|
|
|
|
[self.scrollDownButton autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.collectionView];
|
2017-11-21 22:23:42 +01:00
|
|
|
|
[self.scrollDownButton autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#ifdef DEBUG
|
2017-11-21 22:23:42 +01:00
|
|
|
|
self.scrollUpButton = [[ConversationScrollButton alloc] initWithIconText:@"\uf102"];
|
|
|
|
|
[self.scrollUpButton addTarget:self
|
|
|
|
|
action:@selector(scrollUpButtonTapped)
|
|
|
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
[self.view addSubview:self.scrollUpButton];
|
2017-11-22 15:39:11 +01:00
|
|
|
|
[self.scrollUpButton autoSetDimension:ALDimensionWidth toSize:ConversationScrollButton.buttonSize];
|
|
|
|
|
[self.scrollUpButton autoSetDimension:ALDimensionHeight toSize:ConversationScrollButton.buttonSize];
|
2017-11-21 22:23:42 +01:00
|
|
|
|
[self.scrollUpButton autoPinToTopLayoutGuideOfViewController:self withInset:0];
|
|
|
|
|
[self.scrollUpButton autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 22:23:42 +01:00
|
|
|
|
- (void)setHasUnreadMessages:(BOOL)hasUnreadMessages
|
2017-05-31 20:22:32 +02:00
|
|
|
|
{
|
2017-11-21 22:23:42 +01:00
|
|
|
|
if (_hasUnreadMessages == hasUnreadMessages) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
2017-11-21 22:23:42 +01:00
|
|
|
|
_hasUnreadMessages = hasUnreadMessages;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
2017-11-21 22:23:42 +01:00
|
|
|
|
self.scrollDownButton.hasUnreadMessages = hasUnreadMessages;
|
|
|
|
|
[self ensureDynamicInteractions];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)scrollDownButtonTapped
|
|
|
|
|
{
|
2018-04-05 21:01:02 +02:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
CGPoint contentOffset = self.collectionView.contentOffset;
|
|
|
|
|
contentOffset.y += self.collectionView.height
|
|
|
|
|
- (self.collectionView.contentInset.top + self.collectionView.contentInset.bottom);
|
|
|
|
|
[self.collectionView setContentOffset:contentOffset animated:NO];
|
|
|
|
|
return;
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-11-21 17:42:11 +01:00
|
|
|
|
NSIndexPath *indexPathOfUnreadMessagesIndicator = [self indexPathOfUnreadMessagesIndicator];
|
|
|
|
|
if (indexPathOfUnreadMessagesIndicator != nil) {
|
|
|
|
|
NSInteger unreadRow = indexPathOfUnreadMessagesIndicator.row;
|
|
|
|
|
|
|
|
|
|
BOOL isScrolledAboveUnreadIndicator = YES;
|
|
|
|
|
NSArray<NSIndexPath *> *visibleIndices = self.collectionView.indexPathsForVisibleItems;
|
|
|
|
|
for (NSIndexPath *indexPath in visibleIndices) {
|
|
|
|
|
if (indexPath.row > unreadRow) {
|
|
|
|
|
isScrolledAboveUnreadIndicator = NO;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isScrolledAboveUnreadIndicator) {
|
|
|
|
|
// Only scroll as far as the unread indicator if we're scrolled above the unread indicator.
|
|
|
|
|
[[self collectionView] scrollToItemAtIndexPath:indexPathOfUnreadMessagesIndicator
|
|
|
|
|
atScrollPosition:UICollectionViewScrollPositionTop
|
|
|
|
|
animated:YES];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[self scrollToBottomAnimated:YES];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
- (void)scrollUpButtonTapped
|
|
|
|
|
{
|
|
|
|
|
[self.collectionView setContentOffset:CGPointZero animated:YES];
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)ensureScrollDownButton
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
|
|
|
|
BOOL shouldShowScrollDownButton = NO;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
CGFloat scrollSpaceToBottom = (self.safeContentHeight + self.collectionView.contentInset.bottom
|
2017-06-22 16:55:26 +02:00
|
|
|
|
- (self.collectionView.contentOffset.y + self.collectionView.frame.size.height));
|
|
|
|
|
CGFloat pageHeight = (self.collectionView.frame.size.height
|
|
|
|
|
- (self.collectionView.contentInset.top + self.collectionView.contentInset.bottom));
|
|
|
|
|
// Show "scroll down" button if user is scrolled up at least
|
|
|
|
|
// one page.
|
|
|
|
|
BOOL isScrolledUp = scrollSpaceToBottom > pageHeight * 1.f;
|
|
|
|
|
|
2017-10-19 15:53:35 +02:00
|
|
|
|
if (self.viewItems.count > 0) {
|
|
|
|
|
ConversationViewItem *lastViewItem = [self.viewItems lastObject];
|
|
|
|
|
OWSAssert(lastViewItem);
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
2017-10-19 15:53:35 +02:00
|
|
|
|
if (lastViewItem.interaction.timestampForSorting > self.lastVisibleTimestamp) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
shouldShowScrollDownButton = YES;
|
2017-06-22 16:55:26 +02:00
|
|
|
|
} else if (isScrolledUp) {
|
|
|
|
|
shouldShowScrollDownButton = YES;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shouldShowScrollDownButton) {
|
|
|
|
|
self.scrollDownButton.hidden = NO;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
self.scrollDownButton.hidden = YES;
|
2017-05-30 18:19:17 +02:00
|
|
|
|
}
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
BOOL shouldShowScrollUpButton = self.collectionView.contentOffset.y > 0;
|
|
|
|
|
if (shouldShowScrollUpButton) {
|
|
|
|
|
self.scrollUpButton.hidden = NO;
|
|
|
|
|
} else {
|
|
|
|
|
self.scrollUpButton.hidden = YES;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2017-05-19 19:23:46 +02:00
|
|
|
|
}
|
2017-04-20 23:51:45 +02:00
|
|
|
|
|
|
|
|
|
#pragma mark - Attachment Picking: Documents
|
|
|
|
|
|
2017-09-26 03:51:41 +02:00
|
|
|
|
- (void)showAttachmentDocumentPickerMenu
|
2017-04-20 23:51:45 +02:00
|
|
|
|
{
|
2017-04-26 23:22:27 +02:00
|
|
|
|
NSString *allItems = (__bridge NSString *)kUTTypeItem;
|
2017-04-20 23:51:45 +02:00
|
|
|
|
NSArray<NSString *> *documentTypes = @[ allItems ];
|
|
|
|
|
// UIDocumentPickerModeImport copies to a temp file within our container.
|
2017-04-21 23:08:35 +02:00
|
|
|
|
// It uses more memory than "open" but lets us avoid working with security scoped URLs.
|
2017-04-20 23:51:45 +02:00
|
|
|
|
UIDocumentPickerMode pickerMode = UIDocumentPickerModeImport;
|
2018-01-29 22:35:31 +01:00
|
|
|
|
// TODO: UIDocumentMenuViewController is deprecated; we should use UIDocumentPickerViewController
|
|
|
|
|
// instead.
|
2017-04-20 23:51:45 +02:00
|
|
|
|
UIDocumentMenuViewController *menuController =
|
|
|
|
|
[[UIDocumentMenuViewController alloc] initWithDocumentTypes:documentTypes inMode:pickerMode];
|
|
|
|
|
menuController.delegate = self;
|
2017-09-26 03:51:41 +02:00
|
|
|
|
|
2018-01-29 22:35:31 +01:00
|
|
|
|
UIImage *takeMediaImage = [UIImage imageNamed:@"actionsheet_camera_black"];
|
|
|
|
|
OWSAssert(takeMediaImage);
|
|
|
|
|
[menuController addOptionWithTitle:NSLocalizedString(
|
|
|
|
|
@"MEDIA_FROM_LIBRARY_BUTTON", @"media picker option to choose from library")
|
|
|
|
|
image:takeMediaImage
|
|
|
|
|
order:UIDocumentMenuOrderFirst
|
|
|
|
|
handler:^{
|
|
|
|
|
[self chooseFromLibraryAsDocument];
|
|
|
|
|
}];
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2017-04-20 23:51:45 +02:00
|
|
|
|
[self presentViewController:menuController animated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-26 18:37:00 +02:00
|
|
|
|
#pragma mark - Attachment Picking: GIFs
|
|
|
|
|
|
|
|
|
|
- (void)showGifPicker
|
|
|
|
|
{
|
2017-09-29 17:23:07 +02:00
|
|
|
|
GifPickerViewController *view =
|
|
|
|
|
[[GifPickerViewController alloc] initWithThread:self.thread messageSender:self.messageSender];
|
2017-10-01 03:04:36 +02:00
|
|
|
|
view.delegate = self;
|
2017-09-26 18:37:00 +02:00
|
|
|
|
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:view];
|
2018-01-02 22:55:40 +01:00
|
|
|
|
|
|
|
|
|
[self dismissKeyBoard];
|
2017-09-26 18:37:00 +02:00
|
|
|
|
[self presentViewController:navigationController animated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-01 03:04:36 +02:00
|
|
|
|
#pragma mark GifPickerViewControllerDelegate
|
|
|
|
|
|
2017-10-23 17:56:09 +02:00
|
|
|
|
- (void)gifPickerDidSelectWithAttachment:(SignalAttachment *)attachment
|
2017-10-01 03:04:36 +02:00
|
|
|
|
{
|
2017-10-23 17:56:09 +02:00
|
|
|
|
OWSAssert(attachment);
|
2017-10-01 03:04:36 +02:00
|
|
|
|
|
2017-10-23 17:56:09 +02:00
|
|
|
|
[self tryToSendAttachmentIfApproved:attachment];
|
2017-10-01 03:04:36 +02:00
|
|
|
|
|
2017-10-23 17:56:09 +02:00
|
|
|
|
[ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:self.thread];
|
2017-10-01 03:04:36 +02:00
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)messageWasSent:(TSOutgoingMessage *)message
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-01 03:04:36 +02:00
|
|
|
|
OWSAssert(message);
|
|
|
|
|
|
|
|
|
|
[self updateLastVisibleTimestamp:message.timestampForSorting];
|
|
|
|
|
self.lastMessageSentDate = [NSDate new];
|
|
|
|
|
[self clearUnreadMessagesIndicator];
|
2018-04-04 04:56:45 +02:00
|
|
|
|
self.inputToolbar.quotedMessage = nil;
|
2017-10-01 03:04:36 +02:00
|
|
|
|
|
|
|
|
|
if ([Environment.preferences soundInForeground]) {
|
|
|
|
|
[JSQSystemSoundPlayer jsq_playMessageSentSound];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 23:51:45 +02:00
|
|
|
|
#pragma mark UIDocumentMenuDelegate
|
|
|
|
|
|
|
|
|
|
- (void)documentMenu:(UIDocumentMenuViewController *)documentMenu
|
|
|
|
|
didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
|
|
|
|
|
{
|
|
|
|
|
documentPicker.delegate = self;
|
2017-09-26 03:51:41 +02:00
|
|
|
|
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0)) {
|
|
|
|
|
// post iOS11, document picker has no blue header.
|
|
|
|
|
[UIUtil applyDefaultSystemAppearence];
|
|
|
|
|
}
|
2018-01-02 22:55:40 +01:00
|
|
|
|
|
|
|
|
|
[self dismissKeyBoard];
|
2017-04-20 23:51:45 +02:00
|
|
|
|
[self presentViewController:documentPicker animated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark UIDocumentPickerDelegate
|
2017-04-22 15:45:20 +02:00
|
|
|
|
|
2017-04-20 23:51:45 +02:00
|
|
|
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
|
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ Picked document at url: %@", self.logTag, url);
|
2017-04-20 23:51:45 +02:00
|
|
|
|
|
2017-09-26 03:51:41 +02:00
|
|
|
|
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0)) {
|
|
|
|
|
// post iOS11, document picker has no blue header.
|
|
|
|
|
[UIUtil applySignalAppearence];
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-26 03:51:41 +02:00
|
|
|
|
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0)) {
|
|
|
|
|
// post iOS11, document picker has no blue header.
|
|
|
|
|
[UIUtil applySignalAppearence];
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 23:51:45 +02:00
|
|
|
|
NSString *type;
|
2017-04-26 23:22:27 +02:00
|
|
|
|
NSError *typeError;
|
|
|
|
|
[url getResourceValue:&type forKey:NSURLTypeIdentifierKey error:&typeError];
|
|
|
|
|
if (typeError) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(
|
|
|
|
|
@"%@ Determining type of picked document at url: %@ failed with error: %@", self.logTag, url, typeError);
|
2017-04-20 23:51:45 +02:00
|
|
|
|
}
|
2017-04-27 15:46:51 +02:00
|
|
|
|
if (!type) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ falling back to default filetype for picked document at url: %@", self.logTag, url);
|
2017-04-27 15:46:51 +02:00
|
|
|
|
type = (__bridge NSString *)kUTTypeData;
|
|
|
|
|
}
|
2017-04-20 23:51:45 +02:00
|
|
|
|
|
2017-04-26 23:22:27 +02:00
|
|
|
|
NSNumber *isDirectory;
|
|
|
|
|
NSError *isDirectoryError;
|
|
|
|
|
[url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&isDirectoryError];
|
|
|
|
|
if (isDirectoryError) {
|
2017-08-18 17:49:54 +02:00
|
|
|
|
OWSFail(@"%@ Determining if picked document at url: %@ was a directory failed with error: %@",
|
2017-11-08 20:04:51 +01:00
|
|
|
|
self.logTag,
|
2017-04-26 23:22:27 +02:00
|
|
|
|
url,
|
|
|
|
|
isDirectoryError);
|
|
|
|
|
} else if ([isDirectory boolValue]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogInfo(@"%@ User picked directory at url: %@", self.logTag, url);
|
2017-04-26 23:22:27 +02:00
|
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2017-09-08 21:34:07 +02:00
|
|
|
|
[OWSAlerts
|
|
|
|
|
showAlertWithTitle:
|
|
|
|
|
NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_TITLE",
|
|
|
|
|
@"Alert title when picking a document fails because user picked a directory/bundle")
|
|
|
|
|
message:
|
|
|
|
|
NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_BODY",
|
|
|
|
|
@"Alert body when picking a document fails because user picked a directory/bundle")];
|
2017-04-26 23:22:27 +02:00
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 23:51:45 +02:00
|
|
|
|
NSString *filename = url.lastPathComponent;
|
|
|
|
|
if (!filename) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Unable to determine filename from url: %@", self.logTag, url);
|
2017-04-20 23:51:45 +02:00
|
|
|
|
filename = NSLocalizedString(
|
|
|
|
|
@"ATTACHMENT_DEFAULT_FILENAME", @"Generic filename for an attachment with no known name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OWSAssert(type);
|
|
|
|
|
OWSAssert(filename);
|
2017-09-18 21:02:34 +02:00
|
|
|
|
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithURL:url];
|
2017-09-08 21:34:07 +02:00
|
|
|
|
if (!dataSource) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ attachment data was unexpectedly empty for picked document url: %@", self.logTag, url);
|
2017-09-08 21:34:07 +02:00
|
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_FAILED_ALERT_TITLE",
|
|
|
|
|
@"Alert title when picking a document fails for an unknown reason")];
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-08 21:16:24 +02:00
|
|
|
|
[dataSource setSourceFilename:filename];
|
2017-12-12 02:30:34 +01:00
|
|
|
|
|
|
|
|
|
// Although we want to be able to send higher quality attachments throught the document picker
|
|
|
|
|
// it's more imporant that we ensure the sent format is one all clients can accept (e.g. *not* quicktime .mov)
|
|
|
|
|
if ([SignalAttachment isInvalidVideoWithDataSource:dataSource dataUTI:type]) {
|
|
|
|
|
[self sendQualityAdjustedAttachmentForVideo:url filename:filename skipApprovalDialog:NO];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-07 17:49:31 +01:00
|
|
|
|
// "Document picker" attachments _SHOULD NOT_ be resized, if possible.
|
2017-12-07 23:29:47 +01:00
|
|
|
|
SignalAttachment *attachment =
|
|
|
|
|
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:type imageQuality:TSImageQualityOriginal];
|
2017-04-21 23:08:35 +02:00
|
|
|
|
[self tryToSendAttachmentIfApproved:attachment];
|
2017-04-20 23:51:45 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
|
#pragma mark - UIImagePickerController
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Presenting UIImagePickerController
|
|
|
|
|
*/
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)takePictureOrVideo
|
|
|
|
|
{
|
2017-11-07 16:38:36 +01:00
|
|
|
|
[self ows_askForCameraPermissions:^(BOOL granted) {
|
|
|
|
|
if (!granted) {
|
2018-01-17 21:41:08 +01:00
|
|
|
|
DDLogWarn(@"%@ camera permission denied.", self.logTag);
|
2017-11-07 16:38:36 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-01-17 21:41:08 +01:00
|
|
|
|
|
|
|
|
|
UIImagePickerController *picker = [UIImagePickerController new];
|
2016-11-04 23:41:37 +01:00
|
|
|
|
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
|
|
|
|
|
picker.mediaTypes = @[ (__bridge NSString *)kUTTypeImage, (__bridge NSString *)kUTTypeMovie ];
|
|
|
|
|
picker.allowsEditing = NO;
|
|
|
|
|
picker.delegate = self;
|
2018-01-02 22:55:40 +01:00
|
|
|
|
|
2018-01-17 21:41:08 +01:00
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
[self presentViewController:picker animated:YES completion:[UIUtil modalCompletionBlock]];
|
2017-06-09 00:10:02 +02:00
|
|
|
|
}];
|
2016-07-07 18:54:30 +02:00
|
|
|
|
}
|
2017-09-08 21:16:24 +02:00
|
|
|
|
|
2018-01-29 22:35:31 +01:00
|
|
|
|
- (void)chooseFromLibraryAsDocument
|
|
|
|
|
{
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
|
2018-01-30 16:15:15 +01:00
|
|
|
|
[self chooseFromLibraryAsDocument:YES];
|
2018-01-29 22:35:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)chooseFromLibraryAsMedia
|
|
|
|
|
{
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
|
2018-01-30 16:15:15 +01:00
|
|
|
|
[self chooseFromLibraryAsDocument:NO];
|
2018-01-29 22:35:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 16:15:15 +01:00
|
|
|
|
- (void)chooseFromLibraryAsDocument:(BOOL)shouldTreatAsDocument
|
2017-05-31 20:22:32 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-09-08 21:16:24 +02:00
|
|
|
|
|
2018-01-29 22:35:31 +01:00
|
|
|
|
self.isPickingMediaAsDocument = shouldTreatAsDocument;
|
|
|
|
|
|
2018-01-17 21:41:08 +01:00
|
|
|
|
[self ows_askForMediaLibraryPermissions:^(BOOL granted) {
|
|
|
|
|
if (!granted) {
|
|
|
|
|
DDLogWarn(@"%@ Media Library permission denied.", self.logTag);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-07 18:54:30 +02:00
|
|
|
|
|
2018-01-17 21:41:08 +01:00
|
|
|
|
UIImagePickerController *picker = [UIImagePickerController new];
|
|
|
|
|
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
|
|
|
|
|
picker.delegate = self;
|
|
|
|
|
picker.mediaTypes = @[ (__bridge NSString *)kUTTypeImage, (__bridge NSString *)kUTTypeMovie ];
|
2017-09-08 21:16:24 +02:00
|
|
|
|
|
2018-01-17 21:41:08 +01:00
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
[self presentViewController:picker animated:YES completion:[UIUtil modalCompletionBlock]];
|
|
|
|
|
}];
|
2014-10-29 21:58:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Dismissing UIImagePickerController
|
|
|
|
|
*/
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
|
|
|
|
|
{
|
2015-01-31 09:38:52 +01:00
|
|
|
|
[UIUtil modalCompletionBlock]();
|
2014-10-29 21:58:58 +01:00
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)resetFrame
|
|
|
|
|
{
|
2015-01-31 09:38:52 +01:00
|
|
|
|
// fixes bug on frame being off after this selection
|
2017-05-31 20:22:32 +02:00
|
|
|
|
CGRect frame = [UIScreen mainScreen].applicationFrame;
|
2015-01-31 09:38:52 +01:00
|
|
|
|
self.view.frame = frame;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
|
/*
|
2014-11-29 19:54:33 +01:00
|
|
|
|
* Fetching data from UIImagePickerController
|
2014-10-29 21:58:58 +01:00
|
|
|
|
*/
|
2016-07-22 02:15:34 +02:00
|
|
|
|
- (void)imagePickerController:(UIImagePickerController *)picker
|
|
|
|
|
didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
|
|
|
|
|
{
|
2015-01-31 09:38:52 +01:00
|
|
|
|
[UIUtil modalCompletionBlock]();
|
|
|
|
|
[self resetFrame];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-04-13 18:55:21 +02:00
|
|
|
|
NSURL *referenceURL = [info valueForKey:UIImagePickerControllerReferenceURL];
|
|
|
|
|
if (!referenceURL) {
|
2017-04-13 22:06:23 +02:00
|
|
|
|
DDLogVerbose(@"Could not retrieve reference URL for picked asset");
|
|
|
|
|
[self imagePickerController:picker didFinishPickingMediaWithInfo:info filename:nil];
|
2017-04-13 18:55:21 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset) {
|
|
|
|
|
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
|
|
|
|
|
NSString *filename = [imageRep filename];
|
|
|
|
|
[self imagePickerController:picker didFinishPickingMediaWithInfo:info filename:filename];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init];
|
|
|
|
|
[assetslibrary assetForURL:referenceURL
|
|
|
|
|
resultBlock:resultblock
|
|
|
|
|
failureBlock:^(NSError *error) {
|
2017-09-08 21:34:07 +02:00
|
|
|
|
OWSFail(@"Error retrieving filename for asset: %@", error);
|
2017-04-13 18:55:21 +02:00
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)imagePickerController:(UIImagePickerController *)picker
|
|
|
|
|
didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info
|
2017-11-08 18:56:55 +01:00
|
|
|
|
filename:(NSString *_Nullable)filename
|
2017-04-13 18:55:21 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-04-13 18:55:21 +02:00
|
|
|
|
|
2016-07-22 02:15:34 +02:00
|
|
|
|
void (^failedToPickAttachment)(NSError *error) = ^void(NSError *error) {
|
|
|
|
|
DDLogError(@"failed to pick attachment with error: %@", error);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
NSString *mediaType = info[UIImagePickerControllerMediaType];
|
|
|
|
|
if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeMovie]) {
|
|
|
|
|
// Video picked from library or captured with camera
|
|
|
|
|
|
|
|
|
|
NSURL *videoURL = info[UIImagePickerControllerMediaURL];
|
2017-03-16 19:29:30 +01:00
|
|
|
|
[self dismissViewControllerAnimated:YES
|
|
|
|
|
completion:^{
|
2017-04-22 15:45:20 +02:00
|
|
|
|
[self sendQualityAdjustedAttachmentForVideo:videoURL
|
|
|
|
|
filename:filename
|
2018-01-16 23:55:53 +01:00
|
|
|
|
skipApprovalDialog:NO];
|
2017-03-16 19:29:30 +01:00
|
|
|
|
}];
|
2016-07-22 02:15:34 +02:00
|
|
|
|
} else if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
|
|
|
|
|
// Static Image captured from camera
|
|
|
|
|
|
|
|
|
|
UIImage *imageFromCamera = [info[UIImagePickerControllerOriginalImage] normalizedImage];
|
2017-04-13 18:55:21 +02:00
|
|
|
|
|
2017-03-16 19:29:30 +01:00
|
|
|
|
[self dismissViewControllerAnimated:YES
|
|
|
|
|
completion:^{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-03-16 19:29:30 +01:00
|
|
|
|
if (imageFromCamera) {
|
2017-12-07 17:49:31 +01:00
|
|
|
|
// "Camera" attachments _SHOULD_ be resized, if possible.
|
2017-04-13 18:55:21 +02:00
|
|
|
|
SignalAttachment *attachment =
|
|
|
|
|
[SignalAttachment imageAttachmentWithImage:imageFromCamera
|
|
|
|
|
dataUTI:(NSString *)kUTTypeJPEG
|
2017-12-07 17:49:31 +01:00
|
|
|
|
filename:filename
|
2017-12-07 23:29:47 +01:00
|
|
|
|
imageQuality:TSImageQualityCompact];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
if (!attachment || [attachment hasError]) {
|
2017-03-16 19:29:30 +01:00
|
|
|
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
2017-11-08 20:04:51 +01:00
|
|
|
|
self.logTag,
|
2017-05-30 19:04:43 +02:00
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
|
attachment ? [attachment errorName] : @"Missing data");
|
2017-03-24 03:32:42 +01:00
|
|
|
|
[self showErrorAlertForAttachment:attachment];
|
2017-03-16 19:29:30 +01:00
|
|
|
|
failedToPickAttachment(nil);
|
|
|
|
|
} else {
|
2018-01-16 23:55:53 +01:00
|
|
|
|
[self tryToSendAttachmentIfApproved:attachment skipApprovalDialog:NO];
|
2017-03-16 19:29:30 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
failedToPickAttachment(nil);
|
|
|
|
|
}
|
|
|
|
|
}];
|
2016-07-22 02:15:34 +02:00
|
|
|
|
} else {
|
|
|
|
|
// Non-Video image picked from library
|
|
|
|
|
|
2017-09-06 03:35:27 +02:00
|
|
|
|
// To avoid re-encoding GIF and PNG's as JPEG we have to get the raw data of
|
|
|
|
|
// the selected item vs. using the UIImagePickerControllerOriginalImage
|
2016-07-22 02:15:34 +02:00
|
|
|
|
NSURL *assetURL = info[UIImagePickerControllerReferenceURL];
|
|
|
|
|
PHAsset *asset = [[PHAsset fetchAssetsWithALAssetURLs:@[ assetURL ] options:nil] lastObject];
|
|
|
|
|
if (!asset) {
|
|
|
|
|
return failedToPickAttachment(nil);
|
2016-04-13 20:38:42 +02:00
|
|
|
|
}
|
2016-07-22 02:15:34 +02:00
|
|
|
|
|
2018-01-29 22:35:31 +01:00
|
|
|
|
// Images chosen from the "attach document" UI should be sent as originals;
|
|
|
|
|
// images chosen from the "attach media" UI should be resized to "medium" size;
|
|
|
|
|
TSImageQuality imageQuality = (self.isPickingMediaAsDocument ? TSImageQualityOriginal : TSImageQualityMedium);
|
|
|
|
|
|
2016-07-22 02:15:34 +02:00
|
|
|
|
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
|
|
|
|
|
options.synchronous = YES; // We're only fetching one asset.
|
|
|
|
|
options.networkAccessAllowed = YES; // iCloud OK
|
|
|
|
|
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; // Don't need quick/dirty version
|
|
|
|
|
[[PHImageManager defaultManager]
|
2017-05-30 19:04:43 +02:00
|
|
|
|
requestImageDataForAsset:asset
|
|
|
|
|
options:options
|
|
|
|
|
resultHandler:^(NSData *_Nullable imageData,
|
|
|
|
|
NSString *_Nullable dataUTI,
|
|
|
|
|
UIImageOrientation orientation,
|
|
|
|
|
NSDictionary *_Nullable assetInfo) {
|
|
|
|
|
|
|
|
|
|
NSError *assetFetchingError = assetInfo[PHImageErrorKey];
|
|
|
|
|
if (assetFetchingError || !imageData) {
|
|
|
|
|
return failedToPickAttachment(assetFetchingError);
|
|
|
|
|
}
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-09-18 21:02:34 +02:00
|
|
|
|
DataSource *_Nullable dataSource =
|
2017-09-08 18:04:16 +02:00
|
|
|
|
[DataSourceValue dataSourceWithData:imageData utiType:dataUTI];
|
2017-09-08 21:16:24 +02:00
|
|
|
|
[dataSource setSourceFilename:filename];
|
2018-01-29 22:35:31 +01:00
|
|
|
|
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource
|
|
|
|
|
dataUTI:dataUTI
|
|
|
|
|
imageQuality:imageQuality];
|
2017-05-30 19:04:43 +02:00
|
|
|
|
[self dismissViewControllerAnimated:YES
|
|
|
|
|
completion:^{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-30 19:04:43 +02:00
|
|
|
|
if (!attachment || [attachment hasError]) {
|
|
|
|
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
2017-11-08 20:04:51 +01:00
|
|
|
|
self.logTag,
|
2017-05-30 19:04:43 +02:00
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
|
attachment ? [attachment errorName] : @"Missing data");
|
|
|
|
|
[self showErrorAlertForAttachment:attachment];
|
|
|
|
|
failedToPickAttachment(nil);
|
|
|
|
|
} else {
|
|
|
|
|
[self tryToSendAttachmentIfApproved:attachment];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}];
|
2017-03-10 14:56:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)sendMessageAttachment:(SignalAttachment *)attachment
|
2016-08-01 00:25:07 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-03-10 14:56:12 +01:00
|
|
|
|
// TODO: Should we assume non-nil or should we check for non-nil?
|
|
|
|
|
OWSAssert(attachment != nil);
|
|
|
|
|
OWSAssert(![attachment hasError]);
|
|
|
|
|
OWSAssert([attachment mimeType].length > 0);
|
2017-04-07 04:04:10 +02:00
|
|
|
|
|
|
|
|
|
DDLogVerbose(@"Sending attachment. Size in bytes: %lu, contentType: %@",
|
2017-09-08 16:28:21 +02:00
|
|
|
|
(unsigned long)[attachment dataLength],
|
2017-04-07 04:04:10 +02:00
|
|
|
|
[attachment mimeType]);
|
2017-08-16 21:32:56 +02:00
|
|
|
|
BOOL didAddToProfileWhitelist = [ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:self.thread];
|
2017-12-20 17:10:37 +01:00
|
|
|
|
TSOutgoingMessage *message = [ThreadUtil sendMessageWithAttachment:attachment
|
|
|
|
|
inThread:self.thread
|
2018-04-04 04:56:45 +02:00
|
|
|
|
quotedMessage:self.inputToolbar.quotedMessage
|
2017-12-20 17:10:37 +01:00
|
|
|
|
messageSender:self.messageSender
|
|
|
|
|
completion:nil];
|
2017-10-01 03:04:36 +02:00
|
|
|
|
|
|
|
|
|
[self messageWasSent:message];
|
|
|
|
|
|
2017-08-16 21:32:56 +02:00
|
|
|
|
if (didAddToProfileWhitelist) {
|
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
}
|
2015-01-14 22:30:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (NSURL *)videoTempFolder
|
|
|
|
|
{
|
2017-09-08 16:28:21 +02:00
|
|
|
|
NSString *temporaryDirectory = NSTemporaryDirectory();
|
|
|
|
|
NSString *videoDirPath = [temporaryDirectory stringByAppendingPathComponent:@"videos"];
|
2017-12-01 18:20:09 +01:00
|
|
|
|
[OWSFileSystem ensureDirectoryExists:videoDirPath];
|
2017-09-08 16:28:21 +02:00
|
|
|
|
return [NSURL fileURLWithPath:videoDirPath];
|
2015-04-25 16:59:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 15:45:20 +02:00
|
|
|
|
- (void)sendQualityAdjustedAttachmentForVideo:(NSURL *)movieURL
|
|
|
|
|
filename:(NSString *)filename
|
|
|
|
|
skipApprovalDialog:(BOOL)skipApprovalDialog
|
2017-04-13 18:55:21 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-09-08 21:16:24 +02:00
|
|
|
|
|
2017-09-11 18:49:14 +02:00
|
|
|
|
[ModalActivityIndicatorViewController
|
|
|
|
|
presentFromViewController:self
|
|
|
|
|
canCancel:YES
|
2017-09-18 21:35:14 +02:00
|
|
|
|
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
2017-12-12 02:16:08 +01:00
|
|
|
|
DataSource *dataSource = [DataSourcePath dataSourceWithURL:movieURL];
|
|
|
|
|
dataSource.sourceFilename = filename;
|
|
|
|
|
VideoCompressionResult *compressionResult =
|
|
|
|
|
[SignalAttachment compressVideoAsMp4WithDataSource:dataSource
|
|
|
|
|
dataUTI:(NSString *)kUTTypeMPEG4];
|
|
|
|
|
[compressionResult.attachmentPromise retainUntilComplete];
|
|
|
|
|
|
|
|
|
|
compressionResult.attachmentPromise.then(^(SignalAttachment *attachment) {
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-12-12 02:16:08 +01:00
|
|
|
|
OWSAssert([attachment isKindOfClass:[SignalAttachment class]]);
|
|
|
|
|
|
|
|
|
|
if (modalActivityIndicator.wasCancelled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[modalActivityIndicator dismissWithCompletion:^{
|
|
|
|
|
if (!attachment || [attachment hasError]) {
|
|
|
|
|
DDLogError(@"%@ %s Invalid attachment: %@.",
|
|
|
|
|
self.logTag,
|
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
|
attachment ? [attachment errorName] : @"Missing data");
|
|
|
|
|
[self showErrorAlertForAttachment:attachment];
|
|
|
|
|
} else {
|
|
|
|
|
[self tryToSendAttachmentIfApproved:attachment skipApprovalDialog:skipApprovalDialog];
|
2017-09-18 21:35:14 +02:00
|
|
|
|
}
|
2017-12-12 02:16:08 +01:00
|
|
|
|
}];
|
|
|
|
|
});
|
2017-09-18 21:35:14 +02:00
|
|
|
|
}];
|
2014-11-25 16:38:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-26 21:17:43 +01:00
|
|
|
|
|
2014-11-25 16:38:33 +01:00
|
|
|
|
#pragma mark Storage access
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (YapDatabaseConnection *)uiDatabaseConnection
|
|
|
|
|
{
|
2014-11-25 16:38:33 +01:00
|
|
|
|
NSAssert([NSThread isMainThread], @"Must access uiDatabaseConnection on main thread!");
|
|
|
|
|
if (!_uiDatabaseConnection) {
|
2018-03-05 15:30:58 +01:00
|
|
|
|
_uiDatabaseConnection = [self.primaryStorage newDatabaseConnection];
|
2018-03-18 16:28:26 +01:00
|
|
|
|
// Increase object cache limit. Default is 250.
|
|
|
|
|
_uiDatabaseConnection.objectCacheLimit = 500;
|
2014-11-25 16:38:33 +01:00
|
|
|
|
[_uiDatabaseConnection beginLongLivedReadTransaction];
|
|
|
|
|
}
|
|
|
|
|
return _uiDatabaseConnection;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (YapDatabaseConnection *)editingDatabaseConnection
|
|
|
|
|
{
|
2014-12-06 17:45:42 +01:00
|
|
|
|
if (!_editingDatabaseConnection) {
|
2018-03-05 15:30:58 +01:00
|
|
|
|
_editingDatabaseConnection = [self.primaryStorage newDatabaseConnection];
|
2014-12-06 17:45:42 +01:00
|
|
|
|
}
|
|
|
|
|
return _editingDatabaseConnection;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-12 22:31:03 +01:00
|
|
|
|
- (void)yapDatabaseModifiedExternally:(NSNotification *)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-12-12 22:31:03 +01:00
|
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
|
|
|
|
|
2018-02-22 00:37:19 +01:00
|
|
|
|
if (self.shouldObserveDBModifications) {
|
|
|
|
|
// External database modifications can't be converted into incremental updates,
|
|
|
|
|
// so rebuild everything. This is expensive and usually isn't necessary, but
|
|
|
|
|
// there's no alternative.
|
|
|
|
|
//
|
2018-02-22 18:07:11 +01:00
|
|
|
|
// We don't need to do this if we're not observing db modifications since we'll
|
|
|
|
|
// do it when we resume.
|
2018-02-22 00:37:19 +01:00
|
|
|
|
[self resetMappings];
|
|
|
|
|
}
|
2017-12-12 22:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)yapDatabaseModified:(NSNotification *)notification
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-09-18 20:16:00 +02:00
|
|
|
|
|
2017-03-11 02:43:33 +01:00
|
|
|
|
// Currently, we update thread and message state every time
|
|
|
|
|
// the database is modified. That doesn't seem optimal, but
|
|
|
|
|
// in practice it's efficient enough.
|
|
|
|
|
|
2017-07-25 18:52:30 +02:00
|
|
|
|
if (!self.shouldObserveDBModifications) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-12 22:31:03 +01:00
|
|
|
|
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
|
|
|
|
|
2017-08-15 22:12:00 +02:00
|
|
|
|
// HACK to work around radar #28167779
|
|
|
|
|
// "UICollectionView performBatchUpdates can trigger a crash if the collection view is flagged for layout"
|
|
|
|
|
// more: https://github.com/PSPDFKit-labs/radar.apple.com/tree/master/28167779%20-%20CollectionViewBatchingIssue
|
|
|
|
|
// This was our #2 crash, and much exacerbated by the refactoring somewhere between 2.6.2.0-2.6.3.8
|
|
|
|
|
//
|
|
|
|
|
// NOTE: It's critical we do this before beginLongLivedReadTransaction.
|
2017-10-19 15:53:35 +02:00
|
|
|
|
// We want to relayout our contents using the old message mappings and
|
|
|
|
|
// view items before they are updated.
|
2017-08-15 22:12:00 +02:00
|
|
|
|
[self.collectionView layoutIfNeeded];
|
|
|
|
|
// ENDHACK to work around radar #28167779
|
|
|
|
|
|
2017-03-11 14:01:45 +01:00
|
|
|
|
// We need to `beginLongLivedReadTransaction` before we update our
|
|
|
|
|
// models in order to jump to the most recent commit.
|
|
|
|
|
NSArray *notifications = [self.uiDatabaseConnection beginLongLivedReadTransaction];
|
|
|
|
|
|
2017-04-09 21:31:31 +02:00
|
|
|
|
[self updateBackButtonUnreadCount];
|
2017-04-17 21:50:43 +02:00
|
|
|
|
[self updateNavigationBarSubtitleLabel];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
if (self.isGroupConversation) {
|
2014-12-24 02:25:10 +01:00
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
TSGroupThread *gThread = (TSGroupThread *)self.thread;
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
if (gThread.groupModel) {
|
2017-10-03 19:41:48 +02:00
|
|
|
|
TSGroupThread *_Nullable updatedThread =
|
|
|
|
|
[TSGroupThread threadWithGroupId:gThread.groupModel.groupId transaction:transaction];
|
|
|
|
|
if (updatedThread) {
|
|
|
|
|
self.thread = updatedThread;
|
|
|
|
|
} else {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Could not reload thread.", self.logTag);
|
2017-10-03 19:41:48 +02:00
|
|
|
|
}
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}
|
2014-12-24 02:25:10 +01:00
|
|
|
|
}];
|
2017-03-11 02:43:33 +01:00
|
|
|
|
[self setNavigationTitle];
|
2014-12-24 02:25:10 +01:00
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-11-16 18:25:43 +01:00
|
|
|
|
[self updateDisappearingMessagesConfiguration];
|
2017-10-25 04:02:27 +02:00
|
|
|
|
|
2017-06-19 19:56:23 +02:00
|
|
|
|
if (![[self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName] hasChangesForGroup:self.thread.uniqueId
|
|
|
|
|
inNotifications:notifications]) {
|
2015-12-22 12:45:09 +01:00
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[self.messageMappings updateWithTransaction:transaction];
|
2015-01-31 12:00:58 +01:00
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2017-11-01 18:58:20 +01:00
|
|
|
|
NSArray<YapDatabaseViewSectionChange *> *sectionChanges = nil;
|
|
|
|
|
NSArray<YapDatabaseViewRowChange *> *rowChanges = nil;
|
2017-09-06 20:13:18 +02:00
|
|
|
|
[[self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName] getSectionChanges:§ionChanges
|
2017-11-01 18:58:20 +01:00
|
|
|
|
rowChanges:&rowChanges
|
2017-09-06 20:13:18 +02:00
|
|
|
|
forNotifications:notifications
|
|
|
|
|
withMappings:self.messageMappings];
|
2017-06-19 19:56:23 +02:00
|
|
|
|
|
2017-11-01 18:58:20 +01:00
|
|
|
|
if ([sectionChanges count] == 0 && [rowChanges count] == 0) {
|
2017-07-25 18:58:30 +02:00
|
|
|
|
// YapDatabase will ignore insertions within the message mapping's
|
|
|
|
|
// range that are not within the current mapping's contents. We
|
|
|
|
|
// may need to extend the mapping's contents to reflect the current
|
|
|
|
|
// range.
|
2018-02-22 00:37:19 +01:00
|
|
|
|
[self updateMessageMappingRangeOptions];
|
2017-10-16 18:36:04 +02:00
|
|
|
|
// Calling resetContentAndLayout is a bit expensive.
|
|
|
|
|
// Since by definition this won't affect any cells in the previous
|
|
|
|
|
// range, it should be sufficient to call invalidateLayout.
|
|
|
|
|
//
|
|
|
|
|
// TODO: Investigate whether we can just call invalidateLayout.
|
2017-07-25 18:58:30 +02:00
|
|
|
|
[self resetContentAndLayout];
|
2014-12-08 23:12:22 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-16 20:04:44 +02:00
|
|
|
|
|
2017-10-12 22:46:20 +02:00
|
|
|
|
// We need to reload any modified interactions _before_ we call
|
|
|
|
|
// reloadViewItems.
|
2017-11-22 16:39:38 +01:00
|
|
|
|
BOOL hasDeletions = NO;
|
2018-01-29 17:05:33 +01:00
|
|
|
|
BOOL hasMalformedRowChange = NO;
|
2017-11-01 18:58:20 +01:00
|
|
|
|
for (YapDatabaseViewRowChange *rowChange in rowChanges) {
|
2017-10-12 22:46:20 +02:00
|
|
|
|
switch (rowChange.type) {
|
|
|
|
|
case YapDatabaseViewChangeUpdate: {
|
|
|
|
|
YapCollectionKey *collectionKey = rowChange.collectionKey;
|
|
|
|
|
if (collectionKey.key) {
|
2017-11-22 19:06:54 +01:00
|
|
|
|
ConversationViewItem *viewItem = self.viewItemCache[collectionKey.key];
|
2017-10-12 22:46:20 +02:00
|
|
|
|
[self reloadInteractionForViewItem:viewItem];
|
2018-01-29 17:05:33 +01:00
|
|
|
|
} else {
|
|
|
|
|
hasMalformedRowChange = YES;
|
2017-10-12 22:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-11-15 17:12:30 +01:00
|
|
|
|
case YapDatabaseViewChangeDelete: {
|
|
|
|
|
// Discard cached view items after deletes.
|
|
|
|
|
YapCollectionKey *collectionKey = rowChange.collectionKey;
|
|
|
|
|
if (collectionKey.key) {
|
2017-11-22 19:06:54 +01:00
|
|
|
|
[self.viewItemCache removeObjectForKey:collectionKey.key];
|
2018-01-29 17:05:33 +01:00
|
|
|
|
} else {
|
|
|
|
|
hasMalformedRowChange = YES;
|
2017-11-15 17:12:30 +01:00
|
|
|
|
}
|
2017-11-22 16:39:38 +01:00
|
|
|
|
hasDeletions = YES;
|
2017-11-15 17:12:30 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-10-12 22:46:20 +02:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-01-29 17:05:33 +01:00
|
|
|
|
if (hasMalformedRowChange) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasMalformedRowChange) {
|
|
|
|
|
// These errors seems to be very rare; they can only be reproduced
|
|
|
|
|
// using the more extreme actions in the debug UI.
|
|
|
|
|
DDLogError(@"%@ hasMalformedRowChange", self.logTag);
|
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
|
[self updateLastVisibleTimestamp];
|
|
|
|
|
[self cleanUpUnreadIndicatorIfNecessary];
|
|
|
|
|
return;
|
2017-10-12 22:46:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 15:21:07 +01:00
|
|
|
|
NSUInteger oldViewItemCount = self.viewItems.count;
|
2017-10-11 21:23:53 +02:00
|
|
|
|
NSMutableSet<NSNumber *> *rowsThatChangedSize = [[self reloadViewItems] mutableCopy];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
2017-09-06 16:22:25 +02:00
|
|
|
|
BOOL wasAtBottom = [self isScrolledToBottom];
|
|
|
|
|
// We want sending messages to feel snappy. So, if the only
|
|
|
|
|
// update is a new outgoing message AND we're already scrolled to
|
|
|
|
|
// the bottom of the conversation, skip the scroll animation.
|
|
|
|
|
__block BOOL shouldAnimateScrollToBottom = !wasAtBottom;
|
|
|
|
|
// We want to scroll to the bottom if the user:
|
|
|
|
|
//
|
|
|
|
|
// a) already was at the bottom of the conversation.
|
|
|
|
|
// b) is inserting new interactions.
|
|
|
|
|
__block BOOL scrollToBottom = wasAtBottom;
|
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
|
void (^batchUpdates)(void) = ^{
|
2017-11-01 18:58:20 +01:00
|
|
|
|
for (YapDatabaseViewRowChange *rowChange in rowChanges) {
|
2017-05-26 00:00:41 +02:00
|
|
|
|
switch (rowChange.type) {
|
|
|
|
|
case YapDatabaseViewChangeDelete: {
|
2017-11-17 16:49:34 +01:00
|
|
|
|
DDLogVerbose(@"YapDatabaseViewChangeDelete: %@, %@, %zd",
|
|
|
|
|
rowChange.collectionKey,
|
|
|
|
|
rowChange.indexPath,
|
|
|
|
|
rowChange.finalIndex);
|
2017-05-26 00:00:41 +02:00
|
|
|
|
[self.collectionView deleteItemsAtIndexPaths:@[ rowChange.indexPath ]];
|
|
|
|
|
YapCollectionKey *collectionKey = rowChange.collectionKey;
|
2017-06-20 19:00:38 +02:00
|
|
|
|
OWSAssert(collectionKey.key.length > 0);
|
2017-05-26 00:00:41 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case YapDatabaseViewChangeInsert: {
|
2017-11-17 16:49:34 +01:00
|
|
|
|
DDLogVerbose(@"YapDatabaseViewChangeInsert: %@, %@, %zd",
|
|
|
|
|
rowChange.collectionKey,
|
|
|
|
|
rowChange.newIndexPath,
|
|
|
|
|
rowChange.finalIndex);
|
2017-05-26 00:00:41 +02:00
|
|
|
|
[self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]];
|
2017-11-15 21:46:27 +01:00
|
|
|
|
// We don't want to reload a row that we just inserted.
|
2017-11-22 19:06:54 +01:00
|
|
|
|
[rowsThatChangedSize removeObject:@(rowChange.originalIndex)];
|
2017-09-06 16:22:25 +02:00
|
|
|
|
|
2017-11-17 16:49:34 +01:00
|
|
|
|
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex];
|
2017-10-19 15:53:35 +02:00
|
|
|
|
if ([viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]) {
|
|
|
|
|
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction;
|
2017-09-06 16:22:25 +02:00
|
|
|
|
if (!outgoingMessage.isFromLinkedDevice) {
|
|
|
|
|
scrollToBottom = YES;
|
|
|
|
|
shouldAnimateScrollToBottom = NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-26 00:00:41 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case YapDatabaseViewChangeMove: {
|
2017-11-17 16:49:34 +01:00
|
|
|
|
DDLogVerbose(@"YapDatabaseViewChangeMove: %@, %@, %@, %zd",
|
2017-10-11 21:23:53 +02:00
|
|
|
|
rowChange.collectionKey,
|
|
|
|
|
rowChange.indexPath,
|
2017-11-17 16:49:34 +01:00
|
|
|
|
rowChange.newIndexPath,
|
|
|
|
|
rowChange.finalIndex);
|
2017-11-17 17:56:48 +01:00
|
|
|
|
[self.collectionView moveItemAtIndexPath:rowChange.indexPath toIndexPath:rowChange.newIndexPath];
|
2017-11-15 21:46:27 +01:00
|
|
|
|
// We don't want to reload a row that we just moved.
|
2017-11-22 19:06:54 +01:00
|
|
|
|
[rowsThatChangedSize removeObject:@(rowChange.originalIndex)];
|
2017-05-26 00:00:41 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case YapDatabaseViewChangeUpdate: {
|
2017-11-17 16:49:34 +01:00
|
|
|
|
DDLogVerbose(@"YapDatabaseViewChangeUpdate: %@, %@, %zd",
|
|
|
|
|
rowChange.collectionKey,
|
|
|
|
|
rowChange.indexPath,
|
|
|
|
|
rowChange.finalIndex);
|
2017-05-26 00:00:41 +02:00
|
|
|
|
[self.collectionView reloadItemsAtIndexPaths:@[ rowChange.indexPath ]];
|
2017-11-15 21:46:27 +01:00
|
|
|
|
// We don't want to reload a row that we've already reloaded.
|
2017-11-22 19:06:54 +01:00
|
|
|
|
[rowsThatChangedSize removeObject:@(rowChange.originalIndex)];
|
2017-05-26 00:00:41 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-11 21:23:53 +02:00
|
|
|
|
|
|
|
|
|
// The changes performed above may affect the size of neighboring cells,
|
|
|
|
|
// as they may affect which cells show "date" headers or "status" footers.
|
|
|
|
|
NSMutableArray<NSIndexPath *> *rowsToReload = [NSMutableArray new];
|
|
|
|
|
for (NSNumber *row in rowsThatChangedSize) {
|
2017-11-17 17:56:48 +01:00
|
|
|
|
DDLogVerbose(@"rowsToReload: %@", row);
|
2017-10-11 21:23:53 +02:00
|
|
|
|
[rowsToReload addObject:[NSIndexPath indexPathForRow:row.integerValue inSection:0]];
|
|
|
|
|
}
|
2017-11-15 18:37:24 +01:00
|
|
|
|
if (rowsToReload.count > 0) {
|
|
|
|
|
[self.collectionView reloadItemsAtIndexPaths:rowsToReload];
|
|
|
|
|
}
|
2017-11-01 15:21:07 +01:00
|
|
|
|
};
|
2017-09-18 20:16:00 +02:00
|
|
|
|
|
2017-11-17 17:56:48 +01:00
|
|
|
|
DDLogVerbose(@"self.viewItems.count: %zd -> %zd", oldViewItemCount, self.viewItems.count);
|
2017-05-26 00:00:41 +02:00
|
|
|
|
|
2017-11-22 19:06:54 +01:00
|
|
|
|
BOOL shouldAnimateUpdates = [self shouldAnimateRowUpdates:rowChanges oldViewItemCount:oldViewItemCount];
|
|
|
|
|
void (^batchUpdatesCompletion)(BOOL) = ^(BOOL finished) {
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-11-01 15:21:07 +01:00
|
|
|
|
|
2017-11-17 17:56:48 +01:00
|
|
|
|
|
2017-11-22 19:06:54 +01:00
|
|
|
|
if (!finished) {
|
|
|
|
|
DDLogInfo(@"%@ performBatchUpdates did not finish", self.logTag);
|
2017-11-17 17:56:48 +01:00
|
|
|
|
}
|
2014-11-25 16:38:33 +01:00
|
|
|
|
|
2017-11-22 19:06:54 +01:00
|
|
|
|
[self updateLastVisibleTimestamp];
|
2017-11-17 17:56:48 +01:00
|
|
|
|
|
2017-11-22 19:06:54 +01:00
|
|
|
|
if (scrollToBottom) {
|
|
|
|
|
[self scrollToBottomAnimated:shouldAnimateScrollToBottom && shouldAnimateUpdates];
|
2017-11-17 17:56:48 +01:00
|
|
|
|
}
|
2017-11-22 19:06:54 +01:00
|
|
|
|
if (hasDeletions) {
|
|
|
|
|
[self cleanUpUnreadIndicatorIfNecessary];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if (shouldAnimateUpdates) {
|
|
|
|
|
[self.collectionView performBatchUpdates:batchUpdates completion:batchUpdatesCompletion];
|
|
|
|
|
} else {
|
|
|
|
|
[UIView performWithoutAnimation:^{
|
|
|
|
|
[self.collectionView performBatchUpdates:batchUpdates completion:batchUpdatesCompletion];
|
|
|
|
|
}];
|
2017-11-17 17:56:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 18:58:20 +01:00
|
|
|
|
- (BOOL)shouldAnimateRowUpdates:(NSArray<YapDatabaseViewRowChange *> *)rowChanges
|
|
|
|
|
oldViewItemCount:(NSUInteger)oldViewItemCount
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(rowChanges);
|
|
|
|
|
|
|
|
|
|
// If user sends a new outgoing message, don't animate the change.
|
|
|
|
|
BOOL isOnlyInsertingNewOutgoingMessages = YES;
|
|
|
|
|
BOOL isOnlyUpdatingLastOutgoingMessage = YES;
|
|
|
|
|
NSNumber *_Nullable lastUpdateRow = nil;
|
|
|
|
|
NSNumber *_Nullable lastNonUpdateRow = nil;
|
|
|
|
|
for (YapDatabaseViewRowChange *rowChange in rowChanges) {
|
|
|
|
|
switch (rowChange.type) {
|
|
|
|
|
case YapDatabaseViewChangeDelete:
|
|
|
|
|
isOnlyInsertingNewOutgoingMessages = NO;
|
|
|
|
|
isOnlyUpdatingLastOutgoingMessage = NO;
|
|
|
|
|
if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) {
|
|
|
|
|
lastNonUpdateRow = @(rowChange.indexPath.row);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case YapDatabaseViewChangeInsert: {
|
|
|
|
|
isOnlyUpdatingLastOutgoingMessage = NO;
|
2017-11-17 16:49:34 +01:00
|
|
|
|
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex];
|
2017-11-01 18:58:20 +01:00
|
|
|
|
if ([viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]
|
2017-11-17 16:49:34 +01:00
|
|
|
|
&& rowChange.finalIndex >= oldViewItemCount) {
|
2017-11-01 18:58:20 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-11-17 16:49:34 +01:00
|
|
|
|
if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) {
|
|
|
|
|
lastNonUpdateRow = @(rowChange.finalIndex);
|
2017-11-01 18:58:20 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case YapDatabaseViewChangeMove:
|
|
|
|
|
isOnlyInsertingNewOutgoingMessages = NO;
|
|
|
|
|
isOnlyUpdatingLastOutgoingMessage = NO;
|
|
|
|
|
if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) {
|
|
|
|
|
lastNonUpdateRow = @(rowChange.indexPath.row);
|
|
|
|
|
}
|
2017-11-17 16:49:34 +01:00
|
|
|
|
if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) {
|
|
|
|
|
lastNonUpdateRow = @(rowChange.finalIndex);
|
2017-11-01 18:58:20 +01:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case YapDatabaseViewChangeUpdate: {
|
|
|
|
|
isOnlyInsertingNewOutgoingMessages = NO;
|
2017-11-17 16:49:34 +01:00
|
|
|
|
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex];
|
2017-11-01 18:58:20 +01:00
|
|
|
|
if (![viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]
|
|
|
|
|
|| rowChange.indexPath.row != (NSInteger)(oldViewItemCount - 1)) {
|
|
|
|
|
isOnlyUpdatingLastOutgoingMessage = NO;
|
|
|
|
|
}
|
|
|
|
|
if (!lastUpdateRow || lastUpdateRow.integerValue < rowChange.indexPath.row) {
|
|
|
|
|
lastUpdateRow = @(rowChange.indexPath.row);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOL shouldAnimateRowUpdates = !(isOnlyInsertingNewOutgoingMessages || isOnlyUpdatingLastOutgoingMessage);
|
|
|
|
|
return shouldAnimateRowUpdates;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-16 19:46:57 +02:00
|
|
|
|
- (BOOL)isScrolledToBottom
|
|
|
|
|
{
|
2017-10-10 22:13:54 +02:00
|
|
|
|
CGFloat contentHeight = self.safeContentHeight;
|
2017-08-29 17:12:20 +02:00
|
|
|
|
|
2017-08-30 18:38:47 +02:00
|
|
|
|
// This is a bit subtle.
|
|
|
|
|
//
|
|
|
|
|
// The _wrong_ way to determine if we're scrolled to the bottom is to
|
|
|
|
|
// measure whether the collection view's content is "near" the bottom edge
|
|
|
|
|
// of the collection view. This is wrong because the collection view
|
|
|
|
|
// might not have enough content to fill the collection view's bounds
|
|
|
|
|
// _under certain conditions_ (e.g. with the keyboard dismissed).
|
|
|
|
|
//
|
|
|
|
|
// What we're really interested in is something a bit more subtle:
|
|
|
|
|
// "Is the scroll view scrolled down as far as it can, "at rest".
|
|
|
|
|
//
|
|
|
|
|
// To determine that, we find the appropriate "content offset y" if
|
|
|
|
|
// the scroll view were scrolled down as far as possible. IFF the
|
|
|
|
|
// actual "content offset y" is "near" that value, we return YES.
|
2017-05-16 19:46:57 +02:00
|
|
|
|
const CGFloat kIsAtBottomTolerancePts = 5;
|
2017-08-30 18:38:47 +02:00
|
|
|
|
// Note the usage of MAX() to handle the case where there isn't enough
|
|
|
|
|
// content to fill the collection view at its current size.
|
2018-01-02 22:55:40 +01:00
|
|
|
|
CGFloat contentOffsetYBottom
|
|
|
|
|
= MAX(0.f, contentHeight + self.collectionView.contentInset.bottom - self.collectionView.bounds.size.height);
|
2018-01-16 21:27:53 +01:00
|
|
|
|
|
2018-01-11 18:26:15 +01:00
|
|
|
|
CGFloat distanceFromBottom = contentOffsetYBottom - self.collectionView.contentOffset.y;
|
|
|
|
|
BOOL isScrolledToBottom = distanceFromBottom <= kIsAtBottomTolerancePts;
|
2016-04-13 19:05:09 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
return isScrolledToBottom;
|
2014-11-25 16:38:33 +01:00
|
|
|
|
}
|
2014-12-31 13:22:40 +01:00
|
|
|
|
|
2015-01-22 05:08:12 +01:00
|
|
|
|
#pragma mark - Audio
|
|
|
|
|
|
2017-05-15 22:51:12 +02:00
|
|
|
|
- (void)requestRecordingVoiceMemo
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-15 23:03:46 +02:00
|
|
|
|
|
2017-05-17 23:17:37 +02:00
|
|
|
|
NSUUID *voiceMessageUUID = [NSUUID UUID];
|
|
|
|
|
self.voiceMessageUUID = voiceMessageUUID;
|
|
|
|
|
|
2017-05-15 23:03:46 +02:00
|
|
|
|
__weak typeof(self) weakSelf = self;
|
2017-11-07 16:32:28 +01:00
|
|
|
|
[self ows_askForMicrophonePermissions:^(BOOL granted) {
|
|
|
|
|
__strong typeof(self) strongSelf = weakSelf;
|
|
|
|
|
if (!strongSelf) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-11-07 16:32:28 +01:00
|
|
|
|
if (strongSelf.voiceMessageUUID != voiceMessageUUID) {
|
|
|
|
|
// This voice message recording has been cancelled
|
|
|
|
|
// before recording could begin.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-30 19:04:43 +02:00
|
|
|
|
|
2017-11-07 16:32:28 +01:00
|
|
|
|
if (granted) {
|
|
|
|
|
[strongSelf startRecordingVoiceMemo];
|
|
|
|
|
} else {
|
2017-11-07 16:38:36 +01:00
|
|
|
|
DDLogInfo(@"%@ we do not have recording permission.", self.logTag);
|
2017-11-07 16:32:28 +01:00
|
|
|
|
[strongSelf cancelVoiceMemo];
|
|
|
|
|
[OWSAlerts showNoMicrophonePermissionAlert];
|
|
|
|
|
}
|
2017-05-15 22:51:12 +02:00
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 04:10:37 +02:00
|
|
|
|
- (void)startRecordingVoiceMemo
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-05 04:10:37 +02:00
|
|
|
|
|
|
|
|
|
DDLogInfo(@"startRecordingVoiceMemo");
|
|
|
|
|
|
2017-05-12 15:22:56 +02:00
|
|
|
|
// Cancel any ongoing audio playback.
|
|
|
|
|
[self.audioAttachmentPlayer stop];
|
|
|
|
|
self.audioAttachmentPlayer = nil;
|
|
|
|
|
|
2017-05-05 04:10:37 +02:00
|
|
|
|
NSString *temporaryDirectory = NSTemporaryDirectory();
|
|
|
|
|
NSString *filename = [NSString stringWithFormat:@"%lld.m4a", [NSDate ows_millisecondTimeStamp]];
|
|
|
|
|
NSString *filepath = [temporaryDirectory stringByAppendingPathComponent:filename];
|
|
|
|
|
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-01-22 05:08:12 +01:00
|
|
|
|
// Setup audio session
|
2018-03-05 23:59:09 +01:00
|
|
|
|
BOOL configuredAudio = [OWSAudioSession.shared startRecordingAudioActivity:self.voiceNoteAudioActivity];
|
2018-02-03 00:35:32 +01:00
|
|
|
|
if (!configuredAudio) {
|
|
|
|
|
OWSFail(@"%@ Couldn't configure audio session", self.logTag);
|
2017-05-08 17:13:51 +02:00
|
|
|
|
[self cancelVoiceMemo];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2018-02-03 00:35:32 +01:00
|
|
|
|
NSError *error;
|
2015-01-22 05:08:12 +01:00
|
|
|
|
// Initiate and prepare the recorder
|
2017-05-05 04:10:37 +02:00
|
|
|
|
self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:fileURL
|
|
|
|
|
settings:@{
|
|
|
|
|
AVFormatIDKey : @(kAudioFormatMPEG4AAC),
|
|
|
|
|
AVSampleRateKey : @(44100),
|
|
|
|
|
AVNumberOfChannelsKey : @(2),
|
2017-05-31 20:22:32 +02:00
|
|
|
|
AVEncoderBitRateKey : @(128 * 1024),
|
2017-05-05 04:10:37 +02:00
|
|
|
|
}
|
|
|
|
|
error:&error];
|
|
|
|
|
if (error) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Couldn't create audioRecorder: %@", self.logTag, error);
|
2017-05-08 17:13:51 +02:00
|
|
|
|
[self cancelVoiceMemo];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.audioRecorder.meteringEnabled = YES;
|
|
|
|
|
|
|
|
|
|
if (![self.audioRecorder prepareToRecord]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ audioRecorder couldn't prepareToRecord.", self.logTag);
|
2017-05-08 17:13:51 +02:00
|
|
|
|
[self cancelVoiceMemo];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (![self.audioRecorder record]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ audioRecorder couldn't record.", self.logTag);
|
2017-05-08 17:13:51 +02:00
|
|
|
|
[self cancelVoiceMemo];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)endRecordingVoiceMemo
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-05 04:10:37 +02:00
|
|
|
|
|
|
|
|
|
DDLogInfo(@"endRecordingVoiceMemo");
|
|
|
|
|
|
2017-05-17 23:17:37 +02:00
|
|
|
|
self.voiceMessageUUID = nil;
|
|
|
|
|
|
2017-05-05 04:10:37 +02:00
|
|
|
|
if (!self.audioRecorder) {
|
2017-05-17 23:17:37 +02:00
|
|
|
|
// No voice message recording is in progress.
|
|
|
|
|
// We may be cancelling before the recording could begin.
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ Missing audioRecorder", self.logTag);
|
2017-05-05 04:10:37 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 16:36:58 +01:00
|
|
|
|
NSTimeInterval durationSeconds = self.audioRecorder.currentTime;
|
2017-05-05 04:35:02 +02:00
|
|
|
|
|
2018-02-03 00:35:32 +01:00
|
|
|
|
[self stopRecording];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
|
2017-05-05 04:35:02 +02:00
|
|
|
|
const NSTimeInterval kMinimumRecordingTimeSeconds = 1.f;
|
2017-11-01 16:36:58 +01:00
|
|
|
|
if (durationSeconds < kMinimumRecordingTimeSeconds) {
|
2017-05-08 19:29:10 +02:00
|
|
|
|
DDLogInfo(@"Discarding voice message; too short.");
|
2017-05-05 04:35:02 +02:00
|
|
|
|
self.audioRecorder = nil;
|
2017-05-08 19:29:10 +02:00
|
|
|
|
|
2017-05-17 22:30:30 +02:00
|
|
|
|
[self dismissKeyBoard];
|
|
|
|
|
|
2017-05-08 19:29:10 +02:00
|
|
|
|
[OWSAlerts
|
|
|
|
|
showAlertWithTitle:
|
|
|
|
|
NSLocalizedString(@"VOICE_MESSAGE_TOO_SHORT_ALERT_TITLE",
|
|
|
|
|
@"Title for the alert indicating the 'voice message' needs to be held to be held down to record.")
|
|
|
|
|
message:NSLocalizedString(@"VOICE_MESSAGE_TOO_SHORT_ALERT_MESSAGE",
|
|
|
|
|
@"Message for the alert indicating the 'voice message' needs to be held to be held "
|
|
|
|
|
@"down to record.")];
|
2017-05-05 04:35:02 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-18 21:02:34 +02:00
|
|
|
|
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithURL:self.audioRecorder.url];
|
2017-05-05 16:29:27 +02:00
|
|
|
|
self.audioRecorder = nil;
|
|
|
|
|
|
2017-09-08 21:34:07 +02:00
|
|
|
|
if (!dataSource) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Couldn't load audioRecorder data", self.logTag);
|
2017-09-08 21:34:07 +02:00
|
|
|
|
self.audioRecorder = nil;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-08 19:29:10 +02:00
|
|
|
|
NSString *filename = [NSLocalizedString(@"VOICE_MESSAGE_FILE_NAME", @"Filename for voice messages.")
|
2017-05-11 16:04:42 +02:00
|
|
|
|
stringByAppendingPathExtension:@"m4a"];
|
2017-09-08 21:16:24 +02:00
|
|
|
|
[dataSource setSourceFilename:filename];
|
2017-09-18 20:16:00 +02:00
|
|
|
|
// Remove temporary file when complete.
|
|
|
|
|
[dataSource setShouldDeleteOnDeallocation];
|
2017-09-08 21:16:24 +02:00
|
|
|
|
SignalAttachment *attachment =
|
|
|
|
|
[SignalAttachment voiceMessageAttachmentWithDataSource:dataSource dataUTI:(NSString *)kUTTypeMPEG4Audio];
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogVerbose(@"%@ voice memo duration: %f, file size: %zd", self.logTag, durationSeconds, [dataSource dataLength]);
|
2017-05-05 04:10:37 +02:00
|
|
|
|
if (!attachment || [attachment hasError]) {
|
|
|
|
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
2017-11-08 20:04:51 +01:00
|
|
|
|
self.logTag,
|
2017-05-05 04:10:37 +02:00
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
|
attachment ? [attachment errorName] : @"Missing data");
|
|
|
|
|
[self showErrorAlertForAttachment:attachment];
|
|
|
|
|
} else {
|
|
|
|
|
[self tryToSendAttachmentIfApproved:attachment skipApprovalDialog:YES];
|
2015-01-22 05:08:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 00:35:32 +01:00
|
|
|
|
- (void)stopRecording
|
2017-05-05 04:10:37 +02:00
|
|
|
|
{
|
2018-02-03 00:35:32 +01:00
|
|
|
|
[self.audioRecorder stop];
|
2018-02-16 21:32:29 +01:00
|
|
|
|
[OWSAudioSession.shared endAudioActivity:self.voiceNoteAudioActivity];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-03 00:35:32 +01:00
|
|
|
|
- (void)cancelRecordingVoiceMemo
|
2017-05-05 04:10:37 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2018-02-03 00:35:32 +01:00
|
|
|
|
DDLogDebug(@"cancelRecordingVoiceMemo");
|
2017-05-05 04:10:37 +02:00
|
|
|
|
|
2018-02-03 00:35:32 +01:00
|
|
|
|
[self stopRecording];
|
2017-05-05 04:10:37 +02:00
|
|
|
|
self.audioRecorder = nil;
|
2017-05-17 23:17:37 +02:00
|
|
|
|
self.voiceMessageUUID = nil;
|
2017-05-05 04:10:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 22:19:07 +02:00
|
|
|
|
- (void)setAudioRecorder:(nullable AVAudioRecorder *)audioRecorder
|
2017-07-05 16:49:27 +02:00
|
|
|
|
{
|
|
|
|
|
// Prevent device from sleeping while recording a voice message.
|
|
|
|
|
if (audioRecorder) {
|
|
|
|
|
[DeviceSleepManager.sharedInstance addBlockWithBlockObject:audioRecorder];
|
|
|
|
|
} else if (_audioRecorder) {
|
|
|
|
|
[DeviceSleepManager.sharedInstance removeBlockWithBlockObject:_audioRecorder];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_audioRecorder = audioRecorder;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-25 16:38:33 +01:00
|
|
|
|
#pragma mark Accessory View
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)attachmentButtonPressed
|
2017-05-31 20:22:32 +02:00
|
|
|
|
{
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2017-04-04 18:35:52 +02:00
|
|
|
|
|
2017-09-06 20:13:18 +02:00
|
|
|
|
__weak ConversationViewController *weakSelf = self;
|
2017-04-04 18:35:52 +02:00
|
|
|
|
if ([self isBlockedContactConversation]) {
|
2017-04-04 21:54:11 +02:00
|
|
|
|
[self showUnblockContactUI:^(BOOL isBlocked) {
|
|
|
|
|
if (!isBlocked) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[weakSelf attachmentButtonPressed];
|
2017-04-04 21:54:11 +02:00
|
|
|
|
}
|
|
|
|
|
}];
|
2017-04-04 18:35:52 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 03:19:46 +02:00
|
|
|
|
BOOL didShowSNAlert =
|
|
|
|
|
[self showSafetyNumberConfirmationIfNecessaryWithConfirmationText:
|
|
|
|
|
NSLocalizedString(@"CONFIRMATION_TITLE", @"Generic button text to proceed with an action")
|
|
|
|
|
completion:^(BOOL didConfirmIdentity) {
|
|
|
|
|
if (didConfirmIdentity) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[weakSelf attachmentButtonPressed];
|
2017-05-27 03:19:46 +02:00
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
if (didShowSNAlert) {
|
2017-05-27 01:56:24 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 03:19:46 +02:00
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
UIAlertController *actionSheetController =
|
|
|
|
|
[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
|
2017-08-21 22:58:26 +02:00
|
|
|
|
[actionSheetController addAction:[OWSAlerts cancelAction]];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
|
|
|
|
UIAlertAction *takeMediaAction = [UIAlertAction
|
|
|
|
|
actionWithTitle:NSLocalizedString(@"MEDIA_FROM_CAMERA_BUTTON", @"media picker option to take photo or video")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
|
[self takePictureOrVideo];
|
|
|
|
|
}];
|
2017-04-21 22:58:41 +02:00
|
|
|
|
UIImage *takeMediaImage = [UIImage imageNamed:@"actionsheet_camera_black"];
|
|
|
|
|
OWSAssert(takeMediaImage);
|
|
|
|
|
[takeMediaAction setValue:takeMediaImage forKey:@"image"];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[actionSheetController addAction:takeMediaAction];
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
UIAlertAction *chooseMediaAction = [UIAlertAction
|
|
|
|
|
actionWithTitle:NSLocalizedString(@"MEDIA_FROM_LIBRARY_BUTTON", @"media picker option to choose from library")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
2018-01-29 22:35:31 +01:00
|
|
|
|
[self chooseFromLibraryAsMedia];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}];
|
2017-04-21 22:58:41 +02:00
|
|
|
|
UIImage *chooseMediaImage = [UIImage imageNamed:@"actionsheet_camera_roll_black"];
|
|
|
|
|
OWSAssert(chooseMediaImage);
|
|
|
|
|
[chooseMediaAction setValue:chooseMediaImage forKey:@"image"];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[actionSheetController addAction:chooseMediaAction];
|
2017-04-20 23:51:45 +02:00
|
|
|
|
|
|
|
|
|
UIAlertAction *chooseDocumentAction =
|
|
|
|
|
[UIAlertAction actionWithTitle:NSLocalizedString(@"MEDIA_FROM_DOCUMENT_PICKER_BUTTON",
|
|
|
|
|
@"action sheet button title when choosing attachment type")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
2017-09-26 03:51:41 +02:00
|
|
|
|
[self showAttachmentDocumentPickerMenu];
|
2017-04-20 23:51:45 +02:00
|
|
|
|
}];
|
2017-04-21 22:58:41 +02:00
|
|
|
|
UIImage *chooseDocumentImage = [UIImage imageNamed:@"actionsheet_document_black"];
|
|
|
|
|
OWSAssert(chooseDocumentImage);
|
|
|
|
|
[chooseDocumentAction setValue:chooseDocumentImage forKey:@"image"];
|
2017-04-20 23:51:45 +02:00
|
|
|
|
[actionSheetController addAction:chooseDocumentAction];
|
|
|
|
|
|
2018-03-26 15:37:43 +02:00
|
|
|
|
UIAlertAction *gifAction = [UIAlertAction
|
|
|
|
|
actionWithTitle:NSLocalizedString(@"SELECT_GIF_BUTTON", @"Label for 'select GIF to attach' action sheet button")
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
|
[self showGifPicker];
|
|
|
|
|
}];
|
2017-09-26 18:37:00 +02:00
|
|
|
|
UIImage *gifImage = [UIImage imageNamed:@"actionsheet_gif_black"];
|
|
|
|
|
OWSAssert(gifImage);
|
|
|
|
|
[gifAction setValue:gifImage forKey:@"image"];
|
|
|
|
|
[actionSheetController addAction:gifAction];
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
[self dismissKeyBoard];
|
2016-11-26 00:12:00 +01:00
|
|
|
|
[self presentViewController:actionSheetController animated:true completion:nil];
|
2014-11-25 16:38:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-17 17:56:48 +01:00
|
|
|
|
- (nullable NSIndexPath *)lastVisibleIndexPath
|
2017-10-20 15:53:33 +02:00
|
|
|
|
{
|
2017-11-17 17:56:48 +01:00
|
|
|
|
NSIndexPath *_Nullable lastVisibleIndexPath = nil;
|
2017-10-20 15:53:33 +02:00
|
|
|
|
for (NSIndexPath *indexPath in [self.collectionView indexPathsForVisibleItems]) {
|
|
|
|
|
if (!lastVisibleIndexPath || indexPath.row > lastVisibleIndexPath.row) {
|
|
|
|
|
lastVisibleIndexPath = indexPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-17 17:56:48 +01:00
|
|
|
|
if (lastVisibleIndexPath && lastVisibleIndexPath.row >= self.viewItems.count) {
|
|
|
|
|
return (self.viewItems.count > 0 ? [NSIndexPath indexPathForRow:self.viewItems.count - 1 inSection:0] : nil);
|
|
|
|
|
}
|
2017-10-20 15:53:33 +02:00
|
|
|
|
return lastVisibleIndexPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable ConversationViewItem *)lastVisibleViewItem
|
|
|
|
|
{
|
2017-11-17 17:56:48 +01:00
|
|
|
|
NSIndexPath *_Nullable lastVisibleIndexPath = [self lastVisibleIndexPath];
|
2017-10-20 15:53:33 +02:00
|
|
|
|
if (!lastVisibleIndexPath) {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
return [self viewItemForIndex:lastVisibleIndexPath.row];
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 22:23:42 +01:00
|
|
|
|
// In the case where we explicitly scroll to bottom, we want to synchronously
|
|
|
|
|
// update the UI to reflect that, since the "mark as read" logic is asynchronous
|
|
|
|
|
// and won't update the UI state immediately.
|
|
|
|
|
- (void)didScrollToBottom
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ConversationViewItem *_Nullable lastVisibleViewItem = [self.viewItems lastObject];
|
|
|
|
|
if (lastVisibleViewItem) {
|
|
|
|
|
uint64_t lastVisibleTimestamp = lastVisibleViewItem.interaction.timestampForSorting;
|
|
|
|
|
self.lastVisibleTimestamp = MAX(self.lastVisibleTimestamp, lastVisibleTimestamp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.scrollDownButton.hidden = YES;
|
|
|
|
|
|
|
|
|
|
self.hasUnreadMessages = NO;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)updateLastVisibleTimestamp
|
|
|
|
|
{
|
2017-10-20 15:53:33 +02:00
|
|
|
|
ConversationViewItem *_Nullable lastVisibleViewItem = [self lastVisibleViewItem];
|
|
|
|
|
if (lastVisibleViewItem) {
|
|
|
|
|
uint64_t lastVisibleTimestamp = lastVisibleViewItem.interaction.timestampForSorting;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
self.lastVisibleTimestamp = MAX(self.lastVisibleTimestamp, lastVisibleTimestamp);
|
|
|
|
|
}
|
2017-05-09 20:39:15 +02:00
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[self ensureScrollDownButton];
|
2017-11-21 22:23:42 +01:00
|
|
|
|
|
|
|
|
|
__block NSUInteger numberOfUnreadMessages;
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
numberOfUnreadMessages =
|
|
|
|
|
[[transaction ext:TSUnreadDatabaseViewExtensionName] numberOfItemsInGroup:self.thread.uniqueId];
|
|
|
|
|
}];
|
|
|
|
|
self.hasUnreadMessages = numberOfUnreadMessages > 0;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 16:39:38 +01:00
|
|
|
|
- (void)cleanUpUnreadIndicatorIfNecessary
|
|
|
|
|
{
|
|
|
|
|
BOOL hasUnreadIndicator = self.dynamicInteractions.unreadIndicatorPosition != nil;
|
|
|
|
|
if (!hasUnreadIndicator) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
__block BOOL hasUnseenInteractions = NO;
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
hasUnseenInteractions =
|
|
|
|
|
[[transaction ext:TSUnreadDatabaseViewExtensionName] numberOfItemsInGroup:self.thread.uniqueId] > 0;
|
|
|
|
|
}];
|
|
|
|
|
if (hasUnseenInteractions) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// If the last unread message was deleted (manually or due to disappearing messages)
|
|
|
|
|
// we may need to clean up an obsolete unread indicator.
|
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)updateLastVisibleTimestamp:(uint64_t)timestamp
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(timestamp > 0);
|
|
|
|
|
|
|
|
|
|
self.lastVisibleTimestamp = MAX(self.lastVisibleTimestamp, timestamp);
|
|
|
|
|
|
|
|
|
|
[self ensureScrollDownButton];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)markVisibleMessagesAsRead
|
|
|
|
|
{
|
|
|
|
|
[self updateLastVisibleTimestamp];
|
|
|
|
|
|
|
|
|
|
uint64_t lastVisibleTimestamp = self.lastVisibleTimestamp;
|
2017-08-31 17:49:21 +02:00
|
|
|
|
|
2017-09-28 15:31:17 +02:00
|
|
|
|
if (lastVisibleTimestamp == 0) {
|
|
|
|
|
// No visible messages yet. New Thread.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-09-15 21:28:44 +02:00
|
|
|
|
[OWSReadReceiptManager.sharedManager markAsReadLocallyBeforeTimestamp:lastVisibleTimestamp thread:self.thread];
|
2014-12-06 17:45:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
|
- (void)updateGroupModelTo:(TSGroupModel *)newGroupModel successCompletion:(void (^_Nullable)(void))successCompletion
|
2016-08-01 00:25:07 +02:00
|
|
|
|
{
|
2015-12-22 12:45:09 +01:00
|
|
|
|
__block TSGroupThread *groupThread;
|
2015-02-17 00:14:50 +01:00
|
|
|
|
__block TSOutgoingMessage *message;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2014-12-24 02:25:10 +01:00
|
|
|
|
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
groupThread = [TSGroupThread getOrCreateThreadWithGroupModel:newGroupModel transaction:transaction];
|
|
|
|
|
|
|
|
|
|
NSString *updateGroupInfo =
|
|
|
|
|
[groupThread.groupModel getInfoStringAboutUpdateTo:newGroupModel contactsManager:self.contactsManager];
|
2016-10-17 03:07:25 +02:00
|
|
|
|
|
|
|
|
|
groupThread.groupModel = newGroupModel;
|
|
|
|
|
[groupThread saveWithTransaction:transaction];
|
2018-04-03 21:40:02 +02:00
|
|
|
|
message = [TSOutgoingMessage outgoingMessageInThread:groupThread groupMetaMessage:TSGroupMessageUpdate];
|
2017-04-12 17:03:16 +02:00
|
|
|
|
[message updateWithCustomMessage:updateGroupInfo transaction:transaction];
|
2014-12-24 02:25:10 +01:00
|
|
|
|
}];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2016-10-14 22:59:58 +02:00
|
|
|
|
if (newGroupModel.groupImage) {
|
2017-09-08 18:51:25 +02:00
|
|
|
|
NSData *data = UIImagePNGRepresentation(newGroupModel.groupImage);
|
2017-09-18 21:02:34 +02:00
|
|
|
|
DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:data fileExtension:@"png"];
|
2017-11-15 19:21:31 +01:00
|
|
|
|
[self.messageSender enqueueAttachment:dataSource
|
2016-10-14 22:59:58 +02:00
|
|
|
|
contentType:OWSMimeTypeImagePng
|
2017-05-15 16:47:27 +02:00
|
|
|
|
sourceFilename:nil
|
2016-10-14 22:59:58 +02:00
|
|
|
|
inMessage:message
|
|
|
|
|
success:^{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ Successfully sent group update with avatar", self.logTag);
|
2017-06-13 21:09:47 +02:00
|
|
|
|
if (successCompletion) {
|
|
|
|
|
successCompletion();
|
|
|
|
|
}
|
2016-10-14 22:59:58 +02:00
|
|
|
|
}
|
|
|
|
|
failure:^(NSError *_Nonnull error) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ Failed to send group avatar update with error: %@", self.logTag, error);
|
2016-10-14 22:59:58 +02:00
|
|
|
|
}];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
} else {
|
2017-11-15 19:21:31 +01:00
|
|
|
|
[self.messageSender enqueueMessage:message
|
2016-10-14 22:59:58 +02:00
|
|
|
|
success:^{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogDebug(@"%@ Successfully sent group update", self.logTag);
|
2017-06-13 21:09:47 +02:00
|
|
|
|
if (successCompletion) {
|
|
|
|
|
successCompletion();
|
|
|
|
|
}
|
2016-10-14 22:59:58 +02:00
|
|
|
|
}
|
|
|
|
|
failure:^(NSError *_Nonnull error) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ Failed to send group update with error: %@", self.logTag, error);
|
2016-10-14 22:59:58 +02:00
|
|
|
|
}];
|
2015-02-17 00:14:50 +01:00
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-02-17 00:14:50 +01:00
|
|
|
|
self.thread = groupThread;
|
2014-12-24 02:25:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)popKeyBoard
|
|
|
|
|
{
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self.inputToolbar beginEditingTextMessage];
|
2015-04-14 21:49:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)dismissKeyBoard
|
|
|
|
|
{
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self.inputToolbar endEditingTextMessage];
|
2015-01-30 23:28:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-01 00:04:39 +01:00
|
|
|
|
#pragma mark Drafts
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)loadDraftInCompose
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-12 22:19:07 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
__block NSString *draft;
|
2017-10-12 22:19:07 +02:00
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
draft = [_thread currentDraftWithTransaction:transaction];
|
2017-10-12 22:19:07 +02:00
|
|
|
|
}];
|
|
|
|
|
[self.inputToolbar setMessageText:draft];
|
2015-03-01 00:04:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)saveDraft
|
|
|
|
|
{
|
2015-03-01 00:04:39 +01:00
|
|
|
|
if (self.inputToolbar.hidden == NO) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
__block TSThread *thread = _thread;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
__block NSString *currentDraft = [self.inputToolbar messageText];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
2015-03-21 19:15:43 +01:00
|
|
|
|
[self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-05-09 16:33:35 +02:00
|
|
|
|
[thread setDraft:currentDraft transaction:transaction];
|
2015-03-01 00:04:39 +01:00
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-09 16:33:35 +02:00
|
|
|
|
|
|
|
|
|
- (void)clearDraft
|
|
|
|
|
{
|
|
|
|
|
__block TSThread *thread = _thread;
|
|
|
|
|
[self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
[thread setDraft:@"" transaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
}
|
2015-03-01 00:04:39 +01:00
|
|
|
|
|
2015-05-23 15:54:50 +02:00
|
|
|
|
#pragma mark Unread Badge
|
|
|
|
|
|
2017-04-09 21:31:31 +02:00
|
|
|
|
- (void)updateBackButtonUnreadCount
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2018-01-30 21:49:36 +01:00
|
|
|
|
self.backButtonUnreadCount = [OWSMessageUtils.sharedManager unreadMessagesCountExcept:self.thread];
|
2017-04-09 21:31:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setBackButtonUnreadCount:(NSUInteger)unreadCount
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-04-09 21:31:31 +02:00
|
|
|
|
if (_backButtonUnreadCount == unreadCount) {
|
|
|
|
|
// No need to re-render same count.
|
|
|
|
|
return;
|
2015-05-23 15:54:50 +02:00
|
|
|
|
}
|
2017-04-09 21:31:31 +02:00
|
|
|
|
_backButtonUnreadCount = unreadCount;
|
|
|
|
|
|
|
|
|
|
OWSAssert(_backButtonUnreadCountView != nil);
|
|
|
|
|
_backButtonUnreadCountView.hidden = unreadCount <= 0;
|
|
|
|
|
|
|
|
|
|
OWSAssert(_backButtonUnreadCountLabel != nil);
|
2017-06-20 19:12:51 +02:00
|
|
|
|
|
|
|
|
|
// Max out the unread count at 99+.
|
|
|
|
|
const NSUInteger kMaxUnreadCount = 99;
|
2017-12-01 23:10:14 +01:00
|
|
|
|
_backButtonUnreadCountLabel.text = [OWSFormat formatInt:(int)MIN(kMaxUnreadCount, unreadCount)];
|
2015-05-23 15:54:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-26 17:27:27 +01:00
|
|
|
|
#pragma mark 3D Touch Preview Actions
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems
|
|
|
|
|
{
|
2015-12-26 17:27:27 +01:00
|
|
|
|
return @[];
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 22:09:57 +01:00
|
|
|
|
#pragma mark - Event Handling
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)navigationTitleTapped:(UIGestureRecognizer *)gestureRecognizer
|
|
|
|
|
{
|
2017-02-15 22:09:57 +01:00
|
|
|
|
if (gestureRecognizer.state == UIGestureRecognizerStateRecognized) {
|
|
|
|
|
[self showConversationSettings];
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-10 14:56:12 +01:00
|
|
|
|
|
2017-09-01 20:30:39 +02:00
|
|
|
|
#ifdef USE_DEBUG_UI
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)navigationTitleLongPressed:(UIGestureRecognizer *)gestureRecognizer
|
|
|
|
|
{
|
2017-03-27 23:03:36 +02:00
|
|
|
|
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
|
2017-05-31 20:22:32 +02:00
|
|
|
|
[DebugUITableViewController presentDebugUIForThread:self.thread fromViewController:self];
|
2017-03-27 23:03:36 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - ConversationInputTextViewDelegate
|
2017-03-10 14:56:12 +01:00
|
|
|
|
|
2017-11-01 16:28:58 +01:00
|
|
|
|
- (void)inputTextViewSendMessagePressed
|
|
|
|
|
{
|
|
|
|
|
[self sendButtonPressed];
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)didPasteAttachment:(SignalAttachment *_Nullable)attachment
|
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
2017-04-04 18:35:52 +02:00
|
|
|
|
|
2017-04-07 04:04:10 +02:00
|
|
|
|
[self tryToSendAttachmentIfApproved:attachment];
|
|
|
|
|
}
|
2017-04-04 18:35:52 +02:00
|
|
|
|
|
2017-04-07 04:04:10 +02:00
|
|
|
|
- (void)tryToSendAttachmentIfApproved:(SignalAttachment *_Nullable)attachment
|
2017-04-22 15:45:20 +02:00
|
|
|
|
{
|
|
|
|
|
[self tryToSendAttachmentIfApproved:attachment skipApprovalDialog:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)tryToSendAttachmentIfApproved:(SignalAttachment *_Nullable)attachment
|
|
|
|
|
skipApprovalDialog:(BOOL)skipApprovalDialog
|
2017-04-07 04:04:10 +02:00
|
|
|
|
{
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
2017-04-07 04:04:10 +02:00
|
|
|
|
|
|
|
|
|
DispatchMainThreadSafe(^{
|
2017-09-06 20:13:18 +02:00
|
|
|
|
__weak ConversationViewController *weakSelf = self;
|
2017-04-07 04:04:10 +02:00
|
|
|
|
if ([self isBlockedContactConversation]) {
|
|
|
|
|
[self showUnblockContactUI:^(BOOL isBlocked) {
|
|
|
|
|
if (!isBlocked) {
|
2017-04-12 00:18:50 +02:00
|
|
|
|
[weakSelf tryToSendAttachmentIfApproved:attachment];
|
2017-04-07 04:04:10 +02:00
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 21:31:54 +02:00
|
|
|
|
BOOL didShowSNAlert = [self
|
|
|
|
|
showSafetyNumberConfirmationIfNecessaryWithConfirmationText:[SafetyNumberStrings confirmSendButton]
|
|
|
|
|
completion:^(BOOL didConfirmIdentity) {
|
|
|
|
|
if (didConfirmIdentity) {
|
|
|
|
|
[weakSelf
|
|
|
|
|
tryToSendAttachmentIfApproved:attachment];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
if (didShowSNAlert) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-07 04:04:10 +02:00
|
|
|
|
if (attachment == nil || [attachment hasError]) {
|
|
|
|
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
2017-11-08 20:04:51 +01:00
|
|
|
|
self.logTag,
|
2017-04-07 04:04:10 +02:00
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
|
attachment ? [attachment errorName] : @"Missing data");
|
|
|
|
|
[self showErrorAlertForAttachment:attachment];
|
2017-04-22 15:45:20 +02:00
|
|
|
|
} else if (skipApprovalDialog) {
|
|
|
|
|
[self sendMessageAttachment:attachment];
|
2017-04-07 04:04:10 +02:00
|
|
|
|
} else {
|
2018-01-16 23:55:53 +01:00
|
|
|
|
AttachmentApprovalViewController *approvalVC = [[AttachmentApprovalViewController alloc] initWithAttachment:attachment delegate:self];
|
|
|
|
|
[self presentViewController:approvalVC animated:YES completion:nil];
|
2017-04-07 04:04:10 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
2017-03-10 14:56:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
- (void)keyboardWillChangeFrame:(NSNotification *)notification
|
|
|
|
|
{
|
|
|
|
|
// `willChange` is the correct keyboard notifiation to observe when adjusting contentInset
|
|
|
|
|
// in lockstep with the keyboard presentation animation. `didChange` results in the contentInset
|
|
|
|
|
// not adjusting until after the keyboard is fully up.
|
|
|
|
|
DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
|
|
|
|
[self handleKeyboardNotification:notification];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)handleKeyboardNotification:(NSNotification *)notification
|
|
|
|
|
{
|
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
|
|
NSDictionary *userInfo = [notification userInfo];
|
|
|
|
|
|
|
|
|
|
NSValue *_Nullable keyboardBeginFrameValue = userInfo[UIKeyboardFrameBeginUserInfoKey];
|
|
|
|
|
if (!keyboardBeginFrameValue) {
|
|
|
|
|
OWSFail(@"%@ Missing keyboard begin frame", self.logTag);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSValue *_Nullable keyboardEndFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
|
|
|
|
|
if (!keyboardEndFrameValue) {
|
|
|
|
|
OWSFail(@"%@ Missing keyboard end frame", self.logTag);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CGRect keyboardEndFrame = [keyboardEndFrameValue CGRectValue];
|
|
|
|
|
|
|
|
|
|
UIEdgeInsets oldInsets = self.collectionView.contentInset;
|
|
|
|
|
UIEdgeInsets newInsets = oldInsets;
|
|
|
|
|
|
|
|
|
|
// bottomLayoutGuide accounts for extra offset needed on iPhoneX
|
|
|
|
|
newInsets.bottom = keyboardEndFrame.size.height - self.bottomLayoutGuide.length;
|
|
|
|
|
|
|
|
|
|
BOOL wasScrolledToBottom = [self isScrolledToBottom];
|
|
|
|
|
|
|
|
|
|
void (^adjustInsets)(void) = ^(void) {
|
|
|
|
|
self.collectionView.contentInset = newInsets;
|
|
|
|
|
self.collectionView.scrollIndicatorInsets = newInsets;
|
|
|
|
|
|
|
|
|
|
// Note there is a bug in iOS11.2 which where switching to the emoji keyboard
|
|
|
|
|
// does not fire a UIKeyboardFrameWillChange notification. In that case, the scroll
|
|
|
|
|
// down button gets mostly obscured by the keyboard.
|
|
|
|
|
// RADAR: #36297652
|
|
|
|
|
self.scrollDownButtonButtomConstraint.constant = -1 * newInsets.bottom;
|
|
|
|
|
[self.scrollDownButton setNeedsLayout];
|
|
|
|
|
[self.scrollDownButton layoutIfNeeded];
|
|
|
|
|
// HACK: I've made the assumption that we are already in the context of an animation, in which case the
|
|
|
|
|
// above should be sufficient to smoothly move the scrollDown button in step with the keyboard presentation
|
|
|
|
|
// animation. Yet, setting the constraint doesn't animate the movement of the button - it "jumps" to it's final
|
|
|
|
|
// position. So here we manually lay out the scroll down button frame (seemingly redundantly), which allows it
|
|
|
|
|
// to be smoothly animated.
|
|
|
|
|
CGRect newButtonFrame = self.scrollDownButton.frame;
|
|
|
|
|
newButtonFrame.origin.y
|
|
|
|
|
= self.scrollDownButton.superview.height - (newInsets.bottom + self.scrollDownButton.height);
|
|
|
|
|
self.scrollDownButton.frame = newButtonFrame;
|
|
|
|
|
|
|
|
|
|
// Adjust content offset to prevent the presented keyboard from obscuring content.
|
|
|
|
|
if (wasScrolledToBottom) {
|
|
|
|
|
// If we were scrolled to the bottom, don't do any fancy math. Just stay at the bottom.
|
|
|
|
|
[self scrollToBottomAnimated:NO];
|
|
|
|
|
} else {
|
|
|
|
|
// If we were scrolled away from the bottom, shift the content in lockstep with the
|
|
|
|
|
// keyboard, up to the limits of the content bounds.
|
|
|
|
|
CGFloat insetChange = newInsets.bottom - oldInsets.bottom;
|
|
|
|
|
CGFloat oldYOffset = self.collectionView.contentOffset.y;
|
|
|
|
|
CGFloat newYOffset = Clamp(oldYOffset + insetChange, 0, self.safeContentHeight);
|
|
|
|
|
CGPoint newOffset = CGPointMake(0, newYOffset);
|
|
|
|
|
|
|
|
|
|
// If the user is dismissing the keyboard via interactive scrolling, any additional conset offset feels
|
2018-01-11 18:26:15 +01:00
|
|
|
|
// redundant, so we only adjust content offset when *presenting* the keyboard (i.e. when insetChange > 0).
|
2018-01-02 22:55:40 +01:00
|
|
|
|
if (insetChange > 0 && newYOffset > keyboardEndFrame.origin.y) {
|
|
|
|
|
[self.collectionView setContentOffset:newOffset animated:NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (self.isViewCompletelyAppeared) {
|
|
|
|
|
adjustInsets();
|
|
|
|
|
} else {
|
|
|
|
|
// Even though we are scrolling without explicitly animating, the notification seems to occur within the context
|
|
|
|
|
// of a system animation, which is desirable when the view is visible, because the user sees the content rise
|
|
|
|
|
// in sync with the keyboard. However, when the view hasn't yet been presented, the animation conflicts and the
|
|
|
|
|
// result is that initial load causes the collection cells to visably "animate" to their final position once the
|
|
|
|
|
// view appears.
|
|
|
|
|
[UIView performWithoutAnimation:adjustInsets];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 23:55:53 +01:00
|
|
|
|
- (void)attachmentApproval:(AttachmentApprovalViewController *)attachmentApproval didApproveAttachment:(SignalAttachment * _Nonnull)attachment
|
2017-10-16 17:55:19 +02:00
|
|
|
|
{
|
|
|
|
|
[self sendMessageAttachment:attachment];
|
2018-01-16 23:55:53 +01:00
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
2018-02-16 20:06:46 +01:00
|
|
|
|
// We always want to scroll to the bottom of the conversation after the local user
|
|
|
|
|
// sends a message. Normally, this is taken care of in yapDatabaseModified:, but
|
|
|
|
|
// we don't listen to db modifications when this view isn't visible, i.e. when the
|
|
|
|
|
// attachment approval view is presented.
|
|
|
|
|
[self scrollToBottomAnimated:YES];
|
2018-01-16 23:55:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)attachmentApproval:(AttachmentApprovalViewController *)attachmentApproval didCancelAttachment:(SignalAttachment * _Nonnull)attachment
|
|
|
|
|
{
|
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
2017-10-16 17:55:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)showErrorAlertForAttachment:(SignalAttachment *_Nullable)attachment
|
|
|
|
|
{
|
2017-03-24 03:32:42 +01:00
|
|
|
|
OWSAssert(attachment == nil || [attachment hasError]);
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
|
|
|
|
NSString *errorMessage
|
|
|
|
|
= (attachment ? [attachment localizedErrorDescription] : [SignalAttachment missingDataErrorMessage]);
|
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogError(@"%@ %s: %@", self.logTag, __PRETTY_FUNCTION__, errorMessage);
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
2017-09-08 16:28:21 +02:00
|
|
|
|
[OWSAlerts showAlertWithTitle:NSLocalizedString(
|
|
|
|
|
@"ATTACHMENT_ERROR_ALERT_TITLE", @"The title of the 'attachment error' alert.")
|
|
|
|
|
message:errorMessage];
|
2017-03-24 03:32:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (CGFloat)safeContentHeight
|
|
|
|
|
{
|
|
|
|
|
// Don't use self.collectionView.contentSize.height as the collection view's
|
|
|
|
|
// content size might not be set yet.
|
|
|
|
|
//
|
|
|
|
|
// We can safely call prepareLayout to ensure the layout state is up-to-date
|
|
|
|
|
// since our layout uses a dirty flag internally to debounce redundant work.
|
2017-10-16 02:46:48 +02:00
|
|
|
|
[self.layout prepareLayout];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
return [self.collectionView.collectionViewLayout collectionViewContentSize].height;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)scrollToBottomAnimated:(BOOL)animated
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-05-16 20:04:44 +02:00
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
if (self.isUserScrolling) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-01-16 21:27:53 +01:00
|
|
|
|
|
2018-01-11 18:26:15 +01:00
|
|
|
|
// Ensure the view is fully layed out before we try to scroll to the bottom, since
|
|
|
|
|
// we use the collectionView bounds to determine where the "bottom" is.
|
|
|
|
|
[self.view layoutIfNeeded];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
CGFloat contentHeight = self.safeContentHeight;
|
2017-11-21 22:23:42 +01:00
|
|
|
|
|
2018-01-02 22:55:40 +01:00
|
|
|
|
CGFloat dstY
|
|
|
|
|
= MAX(0, contentHeight + self.collectionView.contentInset.bottom - self.collectionView.bounds.size.height);
|
|
|
|
|
|
|
|
|
|
[self.collectionView setContentOffset:CGPointMake(0, dstY) animated:NO];
|
2017-11-21 22:23:42 +01:00
|
|
|
|
[self didScrollToBottom];
|
2017-05-05 16:10:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 00:08:51 +02:00
|
|
|
|
#pragma mark - UIScrollViewDelegate
|
|
|
|
|
|
2017-05-31 20:22:32 +02:00
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
|
|
|
|
{
|
|
|
|
|
[self updateLastVisibleTimestamp];
|
2017-10-19 07:06:19 +02:00
|
|
|
|
[self autoLoadMoreIfNecessary];
|
2017-05-31 20:22:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 00:08:51 +02:00
|
|
|
|
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
|
|
|
|
{
|
|
|
|
|
self.userHasScrolled = YES;
|
2017-05-31 20:22:32 +02:00
|
|
|
|
self.isUserScrolling = YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
|
|
|
|
|
{
|
|
|
|
|
self.isUserScrolling = NO;
|
2017-04-05 00:08:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-28 18:18:42 +02:00
|
|
|
|
#pragma mark - OWSConversationSettingsViewDelegate
|
|
|
|
|
|
2017-06-13 21:09:47 +02:00
|
|
|
|
- (void)resendGroupUpdateForErrorMessage:(TSErrorMessage *)message
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-06-13 21:09:47 +02:00
|
|
|
|
OWSAssert([_thread isKindOfClass:[TSGroupThread class]]);
|
|
|
|
|
OWSAssert(message);
|
|
|
|
|
|
|
|
|
|
TSGroupThread *groupThread = (TSGroupThread *)self.thread;
|
|
|
|
|
TSGroupModel *groupModel = groupThread.groupModel;
|
|
|
|
|
[self updateGroupModelTo:groupModel
|
|
|
|
|
successCompletion:^{
|
|
|
|
|
DDLogInfo(@"Group updated, removing group creation error.");
|
|
|
|
|
|
|
|
|
|
[message remove];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-28 18:18:42 +02:00
|
|
|
|
- (void)groupWasUpdated:(TSGroupModel *)groupModel
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(groupModel);
|
|
|
|
|
|
|
|
|
|
NSMutableSet *groupMemberIds = [NSMutableSet setWithArray:groupModel.groupMemberIds];
|
|
|
|
|
[groupMemberIds addObject:[TSAccountManager localNumber]];
|
|
|
|
|
groupModel.groupMemberIds = [NSMutableArray arrayWithArray:[groupMemberIds allObjects]];
|
2017-06-13 21:09:47 +02:00
|
|
|
|
[self updateGroupModelTo:groupModel successCompletion:nil];
|
2017-04-28 18:18:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)popAllConversationSettingsViews
|
|
|
|
|
{
|
2017-05-02 18:30:53 +02:00
|
|
|
|
if (self.presentedViewController) {
|
|
|
|
|
[self.presentedViewController
|
|
|
|
|
dismissViewControllerAnimated:YES
|
|
|
|
|
completion:^{
|
|
|
|
|
[self.navigationController popToViewController:self animated:YES];
|
|
|
|
|
}];
|
|
|
|
|
} else {
|
|
|
|
|
[self.navigationController popToViewController:self animated:YES];
|
|
|
|
|
}
|
2017-04-28 18:18:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - ConversationViewLayoutDelegate
|
|
|
|
|
|
|
|
|
|
- (NSArray<id<ConversationViewLayoutItem>> *)layoutItems
|
|
|
|
|
{
|
|
|
|
|
return self.viewItems;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-16 02:46:48 +02:00
|
|
|
|
- (CGFloat)layoutHeaderHeight
|
|
|
|
|
{
|
|
|
|
|
return (self.showLoadMoreHeader ? kLoadMoreHeaderHeight : 0.f);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - ConversationInputToolbarDelegate
|
|
|
|
|
|
|
|
|
|
- (void)sendButtonPressed
|
|
|
|
|
{
|
|
|
|
|
[self tryToSendTextMessage:self.inputToolbar.messageText updateKeyboardState:YES];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)tryToSendTextMessage:(NSString *)text updateKeyboardState:(BOOL)updateKeyboardState
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
__weak ConversationViewController *weakSelf = self;
|
|
|
|
|
if ([self isBlockedContactConversation]) {
|
|
|
|
|
[self showUnblockContactUI:^(BOOL isBlocked) {
|
|
|
|
|
if (!isBlocked) {
|
|
|
|
|
[weakSelf tryToSendTextMessage:text updateKeyboardState:NO];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL didShowSNAlert =
|
|
|
|
|
[self showSafetyNumberConfirmationIfNecessaryWithConfirmationText:[SafetyNumberStrings confirmSendButton]
|
|
|
|
|
completion:^(BOOL didConfirmIdentity) {
|
|
|
|
|
if (didConfirmIdentity) {
|
|
|
|
|
[weakSelf tryToSendTextMessage:text
|
|
|
|
|
updateKeyboardState:NO];
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
if (didShowSNAlert) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-18 20:53:31 +02:00
|
|
|
|
text = [text ows_stripped];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
BOOL didAddToProfileWhitelist = [ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:self.thread];
|
|
|
|
|
TSOutgoingMessage *message;
|
|
|
|
|
if ([text lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) {
|
|
|
|
|
DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithOversizeText:text];
|
2017-12-07 23:45:28 +01:00
|
|
|
|
SignalAttachment *attachment =
|
|
|
|
|
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:kOversizeTextAttachmentUTI];
|
2017-12-20 17:10:37 +01:00
|
|
|
|
message = [ThreadUtil sendMessageWithAttachment:attachment
|
|
|
|
|
inThread:self.thread
|
2018-04-04 04:56:45 +02:00
|
|
|
|
quotedMessage:self.inputToolbar.quotedMessage
|
2017-12-20 17:10:37 +01:00
|
|
|
|
messageSender:self.messageSender
|
|
|
|
|
completion:nil];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
} else {
|
2018-04-04 04:56:45 +02:00
|
|
|
|
message = [ThreadUtil sendMessageWithText:text
|
|
|
|
|
inThread:self.thread
|
|
|
|
|
quotedMessage:self.inputToolbar.quotedMessage
|
|
|
|
|
messageSender:self.messageSender];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self messageWasSent:message];
|
|
|
|
|
|
|
|
|
|
if (updateKeyboardState) {
|
2018-01-08 23:48:26 +01:00
|
|
|
|
[self.inputToolbar toggleDefaultKeyboard];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
2017-10-16 18:29:22 +02:00
|
|
|
|
[self.inputToolbar clearTextMessage];
|
2018-01-08 23:48:26 +01:00
|
|
|
|
[self clearDraft];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
if (didAddToProfileWhitelist) {
|
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)voiceMemoGestureDidStart
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
DDLogInfo(@"voiceMemoGestureDidStart");
|
|
|
|
|
|
|
|
|
|
const CGFloat kIgnoreMessageSendDoubleTapDurationSeconds = 2.f;
|
|
|
|
|
if (self.lastMessageSentDate &&
|
|
|
|
|
[[NSDate new] timeIntervalSinceDate:self.lastMessageSentDate] < kIgnoreMessageSendDoubleTapDurationSeconds) {
|
|
|
|
|
// If users double-taps the message send button, the second tap can look like a
|
|
|
|
|
// very short voice message gesture. We want to ignore such gestures.
|
|
|
|
|
[self.inputToolbar cancelVoiceMemoIfNecessary];
|
|
|
|
|
[self.inputToolbar hideVoiceMemoUI:NO];
|
|
|
|
|
[self cancelRecordingVoiceMemo];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self.inputToolbar showVoiceMemoUI];
|
|
|
|
|
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
|
|
|
|
[self requestRecordingVoiceMemo];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)voiceMemoGestureDidEnd
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
DDLogInfo(@"voiceMemoGestureDidEnd");
|
|
|
|
|
|
|
|
|
|
[self.inputToolbar hideVoiceMemoUI:YES];
|
|
|
|
|
[self endRecordingVoiceMemo];
|
|
|
|
|
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)voiceMemoGestureDidCancel
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
DDLogInfo(@"voiceMemoGestureDidCancel");
|
|
|
|
|
|
|
|
|
|
[self.inputToolbar hideVoiceMemoUI:NO];
|
|
|
|
|
[self cancelRecordingVoiceMemo];
|
|
|
|
|
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)voiceMemoGestureDidChange:(CGFloat)cancelAlpha
|
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
[self.inputToolbar setVoiceMemoUICancelAlpha:cancelAlpha];
|
|
|
|
|
}
|
2017-06-01 03:12:27 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)cancelVoiceMemo
|
2017-06-01 03:12:27 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
[self.inputToolbar cancelVoiceMemoIfNecessary];
|
|
|
|
|
[self.inputToolbar hideVoiceMemoUI:NO];
|
|
|
|
|
[self cancelRecordingVoiceMemo];
|
|
|
|
|
}
|
2017-08-18 16:48:48 +02:00
|
|
|
|
|
2017-07-25 18:52:30 +02:00
|
|
|
|
#pragma mark - Database Observation
|
|
|
|
|
|
2017-10-19 07:06:19 +02:00
|
|
|
|
- (void)setIsUserScrolling:(BOOL)isUserScrolling
|
|
|
|
|
{
|
|
|
|
|
_isUserScrolling = isUserScrolling;
|
|
|
|
|
|
|
|
|
|
[self autoLoadMoreIfNecessary];
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-25 18:52:30 +02:00
|
|
|
|
- (void)setIsViewVisible:(BOOL)isViewVisible
|
|
|
|
|
{
|
|
|
|
|
_isViewVisible = isViewVisible;
|
|
|
|
|
|
|
|
|
|
[self updateShouldObserveDBModifications];
|
2017-10-12 05:03:28 +02:00
|
|
|
|
[self updateCellsVisible];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setIsAppInBackground:(BOOL)isAppInBackground
|
|
|
|
|
{
|
|
|
|
|
_isAppInBackground = isAppInBackground;
|
|
|
|
|
|
|
|
|
|
[self updateShouldObserveDBModifications];
|
2017-10-12 05:03:28 +02:00
|
|
|
|
[self updateCellsVisible];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateCellsVisible
|
|
|
|
|
{
|
|
|
|
|
BOOL isCellVisible = self.isViewVisible && !self.isAppInBackground;
|
|
|
|
|
for (ConversationViewCell *cell in self.collectionView.visibleCells) {
|
|
|
|
|
cell.isCellVisible = isCellVisible;
|
|
|
|
|
}
|
2017-07-25 18:52:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateShouldObserveDBModifications
|
|
|
|
|
{
|
|
|
|
|
self.shouldObserveDBModifications = self.isViewVisible && !self.isAppInBackground;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications
|
|
|
|
|
{
|
|
|
|
|
if (_shouldObserveDBModifications == shouldObserveDBModifications) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_shouldObserveDBModifications = shouldObserveDBModifications;
|
|
|
|
|
|
2017-07-26 18:39:43 +02:00
|
|
|
|
if (self.shouldObserveDBModifications) {
|
2018-02-22 16:53:13 +01:00
|
|
|
|
DDLogVerbose(@"%@ resume observation of database modifications.", self.logTag);
|
2017-08-31 21:13:00 +02:00
|
|
|
|
// We need to call resetMappings when we _resume_ observing DB modifications,
|
|
|
|
|
// since we've been ignore DB modifications so the mappings can be wrong.
|
|
|
|
|
//
|
|
|
|
|
// resetMappings can however have the side effect of increasing the mapping's
|
|
|
|
|
// "window" size. If that happens, we need to restore the scroll state.
|
|
|
|
|
|
|
|
|
|
// Snapshot the scroll state by measuring the "distance from top of view to
|
|
|
|
|
// bottom of content"; if the mapping's "window" size grows, it will grow
|
|
|
|
|
// _upward_.
|
2017-10-10 22:13:54 +02:00
|
|
|
|
CGFloat viewTopToContentBottom = self.safeContentHeight - self.collectionView.contentOffset.y;
|
2017-08-31 21:13:00 +02:00
|
|
|
|
|
|
|
|
|
NSUInteger oldCellCount = [self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
2017-11-20 22:54:14 +01:00
|
|
|
|
|
2017-11-20 23:08:10 +01:00
|
|
|
|
// ViewItems modified while we were not observing may be stale.
|
|
|
|
|
//
|
|
|
|
|
// TODO: have a more fine-grained cache expiration based on rows modified.
|
2017-11-22 19:06:54 +01:00
|
|
|
|
[self.viewItemCache removeAllObjects];
|
2018-02-22 00:37:19 +01:00
|
|
|
|
|
|
|
|
|
// Snapshot the "previousLastTimestamp" value; it will be cleared by resetMappings.
|
|
|
|
|
NSNumber *_Nullable previousLastTimestamp = self.previousLastTimestamp;
|
2017-11-20 22:54:14 +01:00
|
|
|
|
|
2017-11-20 23:08:10 +01:00
|
|
|
|
[self resetMappings];
|
|
|
|
|
|
2017-08-31 21:13:00 +02:00
|
|
|
|
NSUInteger newCellCount = [self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
|
|
|
|
|
|
|
|
|
// Detect changes in the mapping's "window" size.
|
|
|
|
|
if (oldCellCount != newCellCount) {
|
2017-10-10 22:13:54 +02:00
|
|
|
|
CGFloat newContentHeight = self.safeContentHeight;
|
|
|
|
|
CGPoint newContentOffset = CGPointMake(0, MAX(0, newContentHeight - viewTopToContentBottom));
|
2017-08-31 21:13:00 +02:00
|
|
|
|
[self.collectionView setContentOffset:newContentOffset animated:NO];
|
|
|
|
|
}
|
2018-02-22 17:03:53 +01:00
|
|
|
|
|
2018-02-22 00:37:19 +01:00
|
|
|
|
// When we resume observing database changes, we want to scroll to show the user
|
|
|
|
|
// any new items inserted while we were not observing. We therefore find the
|
2018-02-22 17:03:53 +01:00
|
|
|
|
// first item at or after the "view horizon". See the comments below which explain
|
|
|
|
|
// the "view horizon".
|
2018-02-22 00:37:19 +01:00
|
|
|
|
ConversationViewItem *_Nullable lastViewItem = self.viewItems.lastObject;
|
|
|
|
|
BOOL hasAddedNewItems = (lastViewItem &&
|
|
|
|
|
previousLastTimestamp &&
|
|
|
|
|
lastViewItem.interaction.timestamp > previousLastTimestamp.unsignedLongLongValue);
|
|
|
|
|
|
|
|
|
|
DDLogInfo(@"%@ hasAddedNewItems: %d", self.logTag, hasAddedNewItems);
|
|
|
|
|
if (hasAddedNewItems) {
|
2018-02-22 17:03:53 +01:00
|
|
|
|
NSIndexPath *_Nullable indexPathToShow = [self firstIndexPathAtViewHorizonTimestamp];
|
2018-02-22 00:37:19 +01:00
|
|
|
|
if (indexPathToShow) {
|
2018-02-22 18:07:11 +01:00
|
|
|
|
// The goal is to show _both_ the last item before the "view horizon" and the
|
|
|
|
|
// first item after the "view horizon". We can't do "top on first item after"
|
|
|
|
|
// or "bottom on last item before" or we won't see the other. Unfortunately,
|
|
|
|
|
// this gets tricky if either is huge. The largest cells are oversize text,
|
|
|
|
|
// which should be rare. Other cells are considerably smaller than a screenful.
|
2018-02-22 16:53:13 +01:00
|
|
|
|
[self.collectionView scrollToItemAtIndexPath:indexPathToShow
|
|
|
|
|
atScrollPosition:UICollectionViewScrollPositionCenteredVertically
|
2018-02-22 18:07:11 +01:00
|
|
|
|
animated:NO];
|
2018-02-22 00:37:19 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-22 17:03:53 +01:00
|
|
|
|
self.viewHorizonTimestamp = nil;
|
2018-02-22 16:53:13 +01:00
|
|
|
|
DDLogVerbose(@"%@ resumed observation of database modifications.", self.logTag);
|
2018-02-22 00:37:19 +01:00
|
|
|
|
} else {
|
2018-02-22 16:53:13 +01:00
|
|
|
|
DDLogVerbose(@"%@ pausing observation of database modifications.", self.logTag);
|
2018-02-22 17:03:53 +01:00
|
|
|
|
// When stopping observation, try to record the timestamp of the "view horizon".
|
|
|
|
|
// The "view horizon" is where we'll want to focus the users when we resume
|
|
|
|
|
// observation if any changes have happened while we weren't observing.
|
|
|
|
|
// Ideally, we'll focus on those changes. But we can't skip over unread
|
|
|
|
|
// interactions, so we prioritize those, if any.
|
2018-02-22 00:37:19 +01:00
|
|
|
|
//
|
|
|
|
|
// We'll use this later to update the view to reflect any changes made while
|
|
|
|
|
// we were not observing the database. See extendRangeToIncludeUnobservedItems
|
|
|
|
|
// and the logic above.
|
|
|
|
|
ConversationViewItem *_Nullable lastViewItem = self.viewItems.lastObject;
|
|
|
|
|
if (lastViewItem) {
|
|
|
|
|
self.previousLastTimestamp = @(lastViewItem.interaction.timestamp);
|
|
|
|
|
} else {
|
|
|
|
|
self.previousLastTimestamp = nil;
|
|
|
|
|
}
|
|
|
|
|
__block TSInteraction *_Nullable firstUnseenInteraction = nil;
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
firstUnseenInteraction =
|
|
|
|
|
[[TSDatabaseView unseenDatabaseViewExtension:transaction] firstObjectInGroup:self.thread.uniqueId];
|
|
|
|
|
}];
|
|
|
|
|
if (firstUnseenInteraction) {
|
2018-02-22 17:03:53 +01:00
|
|
|
|
// If there are any unread interactions, focus on the first one.
|
|
|
|
|
self.viewHorizonTimestamp = @(firstUnseenInteraction.timestamp);
|
|
|
|
|
} else if (lastViewItem) {
|
|
|
|
|
// Otherwise, focus _just after_ the last interaction.
|
|
|
|
|
self.viewHorizonTimestamp = @(lastViewItem.interaction.timestamp + 1);
|
2018-02-22 00:37:19 +01:00
|
|
|
|
} else {
|
2018-02-22 17:03:53 +01:00
|
|
|
|
self.viewHorizonTimestamp = nil;
|
2018-02-22 00:37:19 +01:00
|
|
|
|
}
|
2018-02-22 16:53:13 +01:00
|
|
|
|
DDLogVerbose(@"%@ paused observation of database modifications.", self.logTag);
|
2017-07-25 18:52:30 +02:00
|
|
|
|
}
|
2017-07-26 18:39:43 +02:00
|
|
|
|
}
|
2017-07-25 18:52:30 +02:00
|
|
|
|
|
2018-02-22 17:03:53 +01:00
|
|
|
|
- (nullable NSIndexPath *)firstIndexPathAtViewHorizonTimestamp
|
2018-02-22 00:37:19 +01:00
|
|
|
|
{
|
|
|
|
|
OWSAssert(self.shouldObserveDBModifications);
|
|
|
|
|
|
2018-02-22 17:03:53 +01:00
|
|
|
|
if (!self.viewHorizonTimestamp) {
|
2018-02-22 00:37:19 +01:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
if (self.viewItems.count < 1) {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
2018-02-22 17:03:53 +01:00
|
|
|
|
uint64_t viewHorizonTimestamp = self.viewHorizonTimestamp.unsignedLongLongValue;
|
|
|
|
|
// Binary search for the first view item whose timestamp >= the "view horizon" timestamp.
|
2018-02-22 16:53:13 +01:00
|
|
|
|
// We want to move "left" rightward, discarding interactions before this cutoff.
|
|
|
|
|
// We want to move "right" leftward, discarding all-but-the-first interaction after this cutoff.
|
|
|
|
|
// In the end, if we converge on an item _after_ this cutoff, it's the one we want.
|
|
|
|
|
// If we converge on an item _before_ this cutoff, there was no interaction that fit our criteria.
|
2018-02-22 00:37:19 +01:00
|
|
|
|
NSUInteger left = 0, right = self.viewItems.count - 1;
|
|
|
|
|
while (left != right) {
|
|
|
|
|
OWSAssert(left < right);
|
|
|
|
|
NSUInteger mid = (left + right) / 2;
|
|
|
|
|
OWSAssert(left <= mid);
|
|
|
|
|
OWSAssert(mid < right);
|
|
|
|
|
ConversationViewItem *viewItem = self.viewItems[mid];
|
2018-02-22 17:03:53 +01:00
|
|
|
|
if (viewItem.interaction.timestamp >= viewHorizonTimestamp) {
|
2018-02-22 00:37:19 +01:00
|
|
|
|
right = mid;
|
|
|
|
|
} else {
|
|
|
|
|
// This is an optimization; it also ensures that we converge.
|
|
|
|
|
left = mid + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
OWSAssert(left == right);
|
|
|
|
|
ConversationViewItem *viewItem = self.viewItems[left];
|
2018-02-22 17:03:53 +01:00
|
|
|
|
if (viewItem.interaction.timestamp >= viewHorizonTimestamp) {
|
|
|
|
|
DDLogInfo(@"%@ firstIndexPathAtViewHorizonTimestamp: %zd / %zd", self.logTag, left, self.viewItems.count);
|
2018-02-22 00:37:19 +01:00
|
|
|
|
return [NSIndexPath indexPathForRow:(NSInteger) left inSection:0];
|
|
|
|
|
} else {
|
2018-02-22 17:03:53 +01:00
|
|
|
|
DDLogInfo(@"%@ firstIndexPathAtViewHorizonTimestamp: none / %zd", self.logTag, self.viewItems.count);
|
2018-02-22 00:37:19 +01:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We stop observing database modifications when the app or this view is not visible
|
|
|
|
|
// (see: shouldObserveDBModifications). When we resume observing db modifications,
|
|
|
|
|
// we want to extend the "range" of this view to include any items added to this
|
|
|
|
|
// thread while we were not observing.
|
|
|
|
|
- (void)extendRangeToIncludeUnobservedItems
|
|
|
|
|
{
|
|
|
|
|
if (!self.shouldObserveDBModifications) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!self.previousLastTimestamp) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t previousLastTimestamp = self.previousLastTimestamp.unsignedLongLongValue;
|
|
|
|
|
__block NSUInteger addedItemCount = 0;
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
[[transaction ext:TSMessageDatabaseViewExtensionName]
|
|
|
|
|
enumerateRowsInGroup:self.thread.uniqueId
|
|
|
|
|
withOptions:NSEnumerationReverse
|
|
|
|
|
usingBlock:^(NSString *collection,
|
|
|
|
|
NSString *key,
|
|
|
|
|
id object,
|
|
|
|
|
id metadata,
|
|
|
|
|
NSUInteger index,
|
|
|
|
|
BOOL *stop) {
|
|
|
|
|
|
|
|
|
|
if (![object isKindOfClass:[TSInteraction class]]) {
|
|
|
|
|
OWSFail(@"Expected a TSInteraction: %@", [object class]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSInteraction *interaction = (TSInteraction *)object;
|
|
|
|
|
if (interaction.timestamp <= previousLastTimestamp) {
|
|
|
|
|
*stop = YES;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addedItemCount++;
|
|
|
|
|
}];
|
|
|
|
|
}];
|
|
|
|
|
DDLogInfo(@"%@ extendRangeToIncludeUnobservedItems: %zd", self.logTag, addedItemCount);
|
|
|
|
|
self.lastRangeLength += addedItemCount;
|
|
|
|
|
// We only want to do this once, so clear the "previous last timestamp".
|
|
|
|
|
self.previousLastTimestamp = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-26 18:39:43 +02:00
|
|
|
|
- (void)resetMappings
|
|
|
|
|
{
|
2017-07-25 18:52:30 +02:00
|
|
|
|
// If we're entering "active" mode (e.g. view is visible and app is in foreground),
|
|
|
|
|
// reset all state updated by yapDatabaseModified:.
|
|
|
|
|
if (self.messageMappings != nil) {
|
|
|
|
|
// Before we begin observing database modifications, make sure
|
|
|
|
|
// our mapping and table state is up-to-date.
|
|
|
|
|
//
|
|
|
|
|
// We need to `beginLongLivedReadTransaction` before we update our
|
|
|
|
|
// mapping in order to jump to the most recent commit.
|
|
|
|
|
[self.uiDatabaseConnection beginLongLivedReadTransaction];
|
2018-02-22 00:37:19 +01:00
|
|
|
|
[self extendRangeToIncludeUnobservedItems];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
[self.messageMappings updateWithTransaction:transaction];
|
|
|
|
|
}];
|
2018-02-22 00:37:19 +01:00
|
|
|
|
[self updateMessageMappingRangeOptions];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
}
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[self reloadViewItems];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
|
|
|
|
|
[self resetContentAndLayout];
|
|
|
|
|
[self ensureDynamicInteractions];
|
|
|
|
|
[self updateBackButtonUnreadCount];
|
|
|
|
|
[self updateNavigationBarSubtitleLabel];
|
2018-02-22 16:44:05 +01:00
|
|
|
|
|
|
|
|
|
// There appears to be a bug in YapDatabase that sometimes delays modifications
|
|
|
|
|
// made in another process (e.g. the SAE) from showing up in other processes.
|
|
|
|
|
// There's a simple workaround: a trivial write to the database flushes changes
|
|
|
|
|
// made from other processes.
|
2018-02-22 18:07:11 +01:00
|
|
|
|
[self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
[transaction setObject:[NSUUID UUID].UUIDString forKey:@"conversation_view_noop_mod" inCollection:@"temp"];
|
|
|
|
|
}];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - ConversationCollectionViewDelegate
|
2017-08-30 22:18:42 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)collectionViewWillChangeLayout
|
2017-08-30 22:18:42 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-08-30 22:18:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)collectionViewDidChangeLayout
|
2017-08-30 22:18:42 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-08-30 22:18:42 +02:00
|
|
|
|
|
2017-10-19 15:53:35 +02:00
|
|
|
|
[self updateLastVisibleTimestamp];
|
2017-08-30 22:18:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - View Items
|
|
|
|
|
|
2017-10-11 15:44:10 +02:00
|
|
|
|
// This is a key method. It builds or rebuilds the list of
|
|
|
|
|
// cell view models.
|
2017-10-11 21:23:53 +02:00
|
|
|
|
//
|
|
|
|
|
// Returns a list of the rows which may have changed size and
|
|
|
|
|
// need to be reloaded if we're doing an incremental update
|
|
|
|
|
// of the view.
|
|
|
|
|
- (NSSet<NSNumber *> *)reloadViewItems
|
2017-10-10 22:13:54 +02:00
|
|
|
|
{
|
|
|
|
|
NSMutableArray<ConversationViewItem *> *viewItems = [NSMutableArray new];
|
2017-11-22 19:06:54 +01:00
|
|
|
|
NSMutableDictionary<NSString *, ConversationViewItem *> *viewItemCache = [NSMutableDictionary new];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
NSUInteger count = [self.messageMappings numberOfItemsInSection:0];
|
2017-10-12 05:03:28 +02:00
|
|
|
|
BOOL isGroupThread = self.isGroupConversation;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
YapDatabaseViewTransaction *viewTransaction = [transaction ext:TSMessageDatabaseViewExtensionName];
|
|
|
|
|
OWSAssert(viewTransaction);
|
|
|
|
|
for (NSUInteger row = 0; row < count; row++) {
|
|
|
|
|
TSInteraction *interaction =
|
|
|
|
|
[viewTransaction objectAtRow:row inSection:0 withMappings:self.messageMappings];
|
|
|
|
|
OWSAssert(interaction);
|
|
|
|
|
|
2017-11-22 19:06:54 +01:00
|
|
|
|
ConversationViewItem *_Nullable viewItem = self.viewItemCache[interaction.uniqueId];
|
2017-10-11 21:23:53 +02:00
|
|
|
|
if (viewItem) {
|
2017-10-17 06:05:29 +02:00
|
|
|
|
viewItem.previousRow = viewItem.row;
|
2017-10-11 21:23:53 +02:00
|
|
|
|
} else {
|
2017-11-16 17:22:16 +01:00
|
|
|
|
viewItem = [[ConversationViewItem alloc] initWithInteraction:interaction
|
|
|
|
|
isGroupThread:isGroupThread
|
|
|
|
|
transaction:transaction];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
2017-10-11 21:23:53 +02:00
|
|
|
|
viewItem.row = (NSInteger)row;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
[viewItems addObject:viewItem];
|
2017-11-22 19:06:54 +01:00
|
|
|
|
OWSAssert(!viewItemCache[interaction.uniqueId]);
|
|
|
|
|
viewItemCache[interaction.uniqueId] = viewItem;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
|
2017-10-11 21:23:53 +02:00
|
|
|
|
NSMutableSet<NSNumber *> *rowsThatChangedSize = [NSMutableSet new];
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
// Update the "shouldShowDate" property of the view items.
|
2017-10-11 21:23:53 +02:00
|
|
|
|
BOOL shouldShowDateOnNextViewItem = YES;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
uint64_t previousViewItemTimestamp = 0;
|
|
|
|
|
for (ConversationViewItem *viewItem in viewItems) {
|
2017-10-11 21:23:53 +02:00
|
|
|
|
BOOL canShowDate = NO;
|
|
|
|
|
switch (viewItem.interaction.interactionType) {
|
|
|
|
|
case OWSInteractionType_Unknown:
|
|
|
|
|
case OWSInteractionType_UnreadIndicator:
|
|
|
|
|
case OWSInteractionType_Offer:
|
|
|
|
|
canShowDate = NO;
|
|
|
|
|
break;
|
|
|
|
|
case OWSInteractionType_IncomingMessage:
|
|
|
|
|
case OWSInteractionType_OutgoingMessage:
|
|
|
|
|
case OWSInteractionType_Error:
|
|
|
|
|
case OWSInteractionType_Info:
|
|
|
|
|
case OWSInteractionType_Call:
|
|
|
|
|
canShowDate = YES;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL shouldShowDate = NO;
|
|
|
|
|
if (!canShowDate) {
|
|
|
|
|
shouldShowDate = NO;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
shouldShowDateOnNextViewItem = YES;
|
|
|
|
|
} else if (shouldShowDateOnNextViewItem) {
|
2017-10-11 21:23:53 +02:00
|
|
|
|
shouldShowDate = YES;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
shouldShowDateOnNextViewItem = NO;
|
|
|
|
|
} else {
|
|
|
|
|
uint64_t viewItemTimestamp = viewItem.interaction.timestampForSorting;
|
|
|
|
|
OWSAssert(viewItemTimestamp > 0);
|
|
|
|
|
OWSAssert(previousViewItemTimestamp > 0);
|
|
|
|
|
uint64_t timeDifferenceMs = viewItemTimestamp - previousViewItemTimestamp;
|
|
|
|
|
static const uint64_t kShowTimeIntervalMs = 5 * kMinuteInMs;
|
|
|
|
|
if (timeDifferenceMs > kShowTimeIntervalMs) {
|
2017-10-11 21:23:53 +02:00
|
|
|
|
shouldShowDate = YES;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
shouldShowDateOnNextViewItem = NO;
|
|
|
|
|
}
|
2017-10-12 06:16:23 +02:00
|
|
|
|
|
|
|
|
|
// If this is an existing view item and it has changed size,
|
|
|
|
|
// note that so that we can reload this cell while doing
|
|
|
|
|
// incremental updates.
|
2017-10-17 06:05:29 +02:00
|
|
|
|
if (viewItem.shouldShowDate != shouldShowDate && viewItem.previousRow != NSNotFound) {
|
|
|
|
|
[rowsThatChangedSize addObject:@(viewItem.previousRow)];
|
2017-10-11 21:23:53 +02:00
|
|
|
|
}
|
|
|
|
|
viewItem.shouldShowDate = shouldShowDate;
|
2017-10-12 06:16:23 +02:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
previousViewItemTimestamp = viewItem.interaction.timestampForSorting;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 05:03:28 +02:00
|
|
|
|
// Update the "shouldShowDate" property of the view items.
|
|
|
|
|
OWSInteractionType lastInteractionType = OWSInteractionType_Unknown;
|
2017-10-12 06:16:23 +02:00
|
|
|
|
MessageRecipientStatus lastRecipientStatus = MessageRecipientStatusUploading;
|
2018-03-29 17:49:02 +02:00
|
|
|
|
NSString *_Nullable lastIncomingSenderId = nil;
|
2017-10-12 06:16:23 +02:00
|
|
|
|
for (ConversationViewItem *viewItem in viewItems.reverseObjectEnumerator) {
|
|
|
|
|
BOOL shouldHideRecipientStatus = NO;
|
2018-03-29 17:49:02 +02:00
|
|
|
|
BOOL shouldHideBubbleTail = NO;
|
2017-10-12 05:03:28 +02:00
|
|
|
|
OWSInteractionType interactionType = viewItem.interaction.interactionType;
|
2017-10-12 06:16:23 +02:00
|
|
|
|
|
|
|
|
|
if (interactionType == OWSInteractionType_OutgoingMessage) {
|
|
|
|
|
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction;
|
|
|
|
|
MessageRecipientStatus recipientStatus =
|
|
|
|
|
[MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage];
|
2017-10-23 17:40:26 +02:00
|
|
|
|
|
|
|
|
|
if (outgoingMessage.messageState == TSOutgoingMessageStateUnsent) {
|
2018-03-29 17:49:02 +02:00
|
|
|
|
// always show "failed to send" status
|
2017-10-23 17:40:26 +02:00
|
|
|
|
shouldHideRecipientStatus = NO;
|
|
|
|
|
} else {
|
|
|
|
|
shouldHideRecipientStatus
|
|
|
|
|
= (interactionType == lastInteractionType && recipientStatus == lastRecipientStatus);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-29 17:49:02 +02:00
|
|
|
|
shouldHideBubbleTail = (interactionType == lastInteractionType && recipientStatus == lastRecipientStatus);
|
|
|
|
|
|
2017-10-12 06:16:23 +02:00
|
|
|
|
lastRecipientStatus = recipientStatus;
|
2018-03-29 17:49:02 +02:00
|
|
|
|
} else if (interactionType == OWSInteractionType_IncomingMessage) {
|
|
|
|
|
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)viewItem.interaction;
|
|
|
|
|
NSString *incomingSenderId = incomingMessage.authorId;
|
|
|
|
|
OWSAssert(incomingSenderId.length > 0);
|
|
|
|
|
shouldHideBubbleTail = (interactionType == lastInteractionType &&
|
|
|
|
|
[NSObject isNullableObject:lastIncomingSenderId equalTo:incomingSenderId]);
|
|
|
|
|
lastIncomingSenderId = incomingSenderId;
|
2017-10-12 06:16:23 +02:00
|
|
|
|
}
|
2017-10-12 05:03:28 +02:00
|
|
|
|
lastInteractionType = interactionType;
|
2017-10-12 06:16:23 +02:00
|
|
|
|
|
|
|
|
|
// If this is an existing view item and it has changed size,
|
|
|
|
|
// note that so that we can reload this cell while doing
|
|
|
|
|
// incremental updates.
|
2017-10-17 06:05:29 +02:00
|
|
|
|
if (viewItem.shouldHideRecipientStatus != shouldHideRecipientStatus && viewItem.previousRow != NSNotFound) {
|
|
|
|
|
[rowsThatChangedSize addObject:@(viewItem.previousRow)];
|
2017-10-12 06:16:23 +02:00
|
|
|
|
}
|
|
|
|
|
viewItem.shouldHideRecipientStatus = shouldHideRecipientStatus;
|
2018-03-29 17:49:02 +02:00
|
|
|
|
viewItem.shouldHideBubbleTail = shouldHideBubbleTail;
|
2017-10-12 05:03:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
self.viewItems = viewItems;
|
2017-11-22 19:06:54 +01:00
|
|
|
|
self.viewItemCache = viewItemCache;
|
2017-10-11 21:23:53 +02:00
|
|
|
|
|
|
|
|
|
return [rowsThatChangedSize copy];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-11 15:44:10 +02:00
|
|
|
|
// Whenever an interaction is modified, we need to reload it from the DB
|
|
|
|
|
// and update the corresponding view item.
|
2017-10-12 22:46:20 +02:00
|
|
|
|
- (void)reloadInteractionForViewItem:(ConversationViewItem *)viewItem
|
2017-10-10 22:13:54 +02:00
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
|
OWSAssertIsOnMainThread();
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSAssert(viewItem);
|
|
|
|
|
|
|
|
|
|
// This should never happen, but don't crash in production if we have a bug.
|
|
|
|
|
if (!viewItem) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
2017-10-12 22:19:07 +02:00
|
|
|
|
TSInteraction *_Nullable interaction =
|
|
|
|
|
[TSInteraction fetchObjectWithUniqueID:viewItem.interaction.uniqueId transaction:transaction];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
if (!interaction) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ could not reload interaction", self.logTag);
|
2017-10-10 22:13:54 +02:00
|
|
|
|
} else {
|
2017-11-16 17:22:16 +01:00
|
|
|
|
[viewItem replaceInteraction:interaction transaction:transaction];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-19 15:53:35 +02:00
|
|
|
|
- (nullable ConversationViewItem *)viewItemForIndex:(NSInteger)index
|
2017-10-10 22:13:54 +02:00
|
|
|
|
{
|
2017-10-19 15:53:35 +02:00
|
|
|
|
if (index < 0 || index >= (NSInteger)self.viewItems.count) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Invalid view item index: %zd", self.logTag, index);
|
2017-10-12 22:19:07 +02:00
|
|
|
|
return nil;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
2017-10-20 15:53:33 +02:00
|
|
|
|
return self.viewItems[(NSUInteger)index];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - UICollectionViewDataSource
|
|
|
|
|
|
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
|
|
|
|
{
|
|
|
|
|
return (NSInteger)self.viewItems.count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
|
|
|
|
|
cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
|
{
|
2017-10-19 15:53:35 +02:00
|
|
|
|
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:indexPath.row];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
ConversationViewCell *cell = [viewItem dequeueCellForCollectionView:self.collectionView indexPath:indexPath];
|
|
|
|
|
if (!cell) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Could not dequeue cell.", self.logTag);
|
2017-10-10 22:13:54 +02:00
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
cell.viewItem = viewItem;
|
|
|
|
|
cell.delegate = self;
|
2017-10-16 14:41:46 +02:00
|
|
|
|
cell.contentWidth = self.layout.contentWidth;
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
2017-10-16 14:41:46 +02:00
|
|
|
|
[cell loadForDisplay];
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-24 19:25:17 +02:00
|
|
|
|
#pragma mark - swipe to show message details
|
|
|
|
|
|
|
|
|
|
- (void)didPanWithGestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer
|
|
|
|
|
viewItem:(ConversationViewItem *)conversationItem
|
|
|
|
|
{
|
|
|
|
|
self.currentShowMessageDetailsPanGesture = gestureRecognizer;
|
|
|
|
|
|
2017-11-21 17:01:20 +01:00
|
|
|
|
const CGFloat swipeTranslation
|
|
|
|
|
= ([gestureRecognizer translationInView:self.view].x * (self.view.isRTL ? +1.f : -1.f));
|
|
|
|
|
const CGFloat ratioComplete = Clamp(swipeTranslation / self.view.frame.size.width, 0, 1);
|
2017-10-24 19:25:17 +02:00
|
|
|
|
|
|
|
|
|
switch (gestureRecognizer.state) {
|
|
|
|
|
case UIGestureRecognizerStateBegan: {
|
|
|
|
|
TSInteraction *interaction = conversationItem.interaction;
|
|
|
|
|
if ([interaction isKindOfClass:[TSIncomingMessage class]] ||
|
|
|
|
|
[interaction isKindOfClass:[TSOutgoingMessage class]]) {
|
|
|
|
|
|
|
|
|
|
// Canary check in case we later have another reason to set navigationController.delegate - we don't
|
|
|
|
|
// want to inadvertently clobber it here.
|
2017-11-15 18:50:56 +01:00
|
|
|
|
OWSAssert(self.navigationController.delegate == nil);
|
|
|
|
|
self.navigationController.delegate = self;
|
|
|
|
|
|
|
|
|
|
[self showMetadataViewForViewItem:conversationItem];
|
2017-10-24 19:25:17 +02:00
|
|
|
|
} else {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
OWSFail(@"%@ Can't show message metadata for message of type: %@", self.logTag, [interaction class]);
|
2017-10-24 19:25:17 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case UIGestureRecognizerStateChanged: {
|
|
|
|
|
UIPercentDrivenInteractiveTransition *transition = self.showMessageDetailsTransition;
|
|
|
|
|
if (!transition) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogVerbose(@"%@ transition not set up yet", self.logTag);
|
2017-10-24 19:25:17 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-10-25 00:27:07 +02:00
|
|
|
|
[transition updateInteractiveTransition:ratioComplete];
|
2017-10-24 19:25:17 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case UIGestureRecognizerStateEnded: {
|
|
|
|
|
const CGFloat velocity = [gestureRecognizer velocityInView:self.view].x;
|
|
|
|
|
|
|
|
|
|
UIPercentDrivenInteractiveTransition *transition = self.showMessageDetailsTransition;
|
|
|
|
|
if (!transition) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogVerbose(@"%@ transition not set up yet", self.logTag);
|
2017-10-24 19:25:17 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Complete the transition if moved sufficiently far or fast
|
|
|
|
|
// Note this is trickier for incoming, since you are already on the left, and have less space.
|
2017-10-25 00:27:07 +02:00
|
|
|
|
if (ratioComplete > 0.3 || velocity < -800) {
|
2017-10-24 19:25:17 +02:00
|
|
|
|
[transition finishInteractiveTransition];
|
|
|
|
|
} else {
|
|
|
|
|
[transition cancelInteractiveTransition];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case UIGestureRecognizerStateCancelled:
|
|
|
|
|
case UIGestureRecognizerStateFailed: {
|
|
|
|
|
UIPercentDrivenInteractiveTransition *transition = self.showMessageDetailsTransition;
|
|
|
|
|
if (!transition) {
|
2017-11-08 20:04:51 +01:00
|
|
|
|
DDLogVerbose(@"%@ transition not set up yet", self.logTag);
|
2017-10-24 19:25:17 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[transition cancelInteractiveTransition];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable id<UIViewControllerAnimatedTransitioning>)navigationController:
|
|
|
|
|
(UINavigationController *)navigationController
|
|
|
|
|
animationControllerForOperation:(UINavigationControllerOperation)operation
|
|
|
|
|
fromViewController:(UIViewController *)fromVC
|
|
|
|
|
toViewController:(UIViewController *)toVC
|
|
|
|
|
{
|
|
|
|
|
return [SlideOffAnimatedTransition new];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (nullable id<UIViewControllerInteractiveTransitioning>)
|
|
|
|
|
navigationController:(UINavigationController *)navigationController
|
|
|
|
|
interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController
|
|
|
|
|
{
|
|
|
|
|
// We needed to be the navigation controller delegate to specify the interactive "slide left for message details"
|
|
|
|
|
// animation But we may not want to be the navigation controller delegate permanently.
|
|
|
|
|
self.navigationController.delegate = nil;
|
|
|
|
|
|
|
|
|
|
UIPanGestureRecognizer *recognizer = self.currentShowMessageDetailsPanGesture;
|
|
|
|
|
if (recognizer == nil) {
|
2017-10-25 21:14:32 +02:00
|
|
|
|
// Not in the middle of the `currentShowMessageDetailsPanGesture`, abort.
|
2017-10-24 19:25:17 +02:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (recognizer.state == UIGestureRecognizerStateBegan) {
|
|
|
|
|
self.showMessageDetailsTransition = [UIPercentDrivenInteractiveTransition new];
|
|
|
|
|
self.showMessageDetailsTransition.completionCurve = UIViewAnimationCurveEaseOut;
|
|
|
|
|
} else {
|
|
|
|
|
self.showMessageDetailsTransition = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self.showMessageDetailsTransition;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
#pragma mark - UICollectionViewDelegate
|
2017-03-10 14:56:12 +01:00
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView
|
|
|
|
|
willDisplayCell:(UICollectionViewCell *)cell
|
|
|
|
|
forItemAtIndexPath:(NSIndexPath *)indexPath
|
2017-03-10 14:56:12 +01:00
|
|
|
|
{
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSAssert([cell isKindOfClass:[ConversationViewCell class]]);
|
|
|
|
|
|
|
|
|
|
ConversationViewCell *conversationViewCell = (ConversationViewCell *)cell;
|
|
|
|
|
conversationViewCell.isCellVisible = YES;
|
2017-03-10 14:56:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 22:13:54 +02:00
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView
|
|
|
|
|
didEndDisplayingCell:(nonnull UICollectionViewCell *)cell
|
|
|
|
|
forItemAtIndexPath:(nonnull NSIndexPath *)indexPath
|
2017-03-10 14:56:12 +01:00
|
|
|
|
{
|
2017-10-10 22:13:54 +02:00
|
|
|
|
OWSAssert([cell isKindOfClass:[ConversationViewCell class]]);
|
|
|
|
|
|
|
|
|
|
ConversationViewCell *conversationViewCell = (ConversationViewCell *)cell;
|
|
|
|
|
conversationViewCell.isCellVisible = NO;
|
2017-03-10 14:56:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
|
@end
|
2017-10-10 22:13:54 +02:00
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|