2014-10-29 21:58:58 +01:00
|
|
|
//
|
2017-02-02 23:22:36 +01:00
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
2014-10-29 21:58:58 +01:00
|
|
|
//
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
#import "HomeViewController.h"
|
2016-10-10 22:02:09 +02:00
|
|
|
#import "AppDelegate.h"
|
2017-07-31 22:45:06 +02:00
|
|
|
#import "AppSettingsViewController.h"
|
2017-09-06 20:13:18 +02:00
|
|
|
#import "ConversationViewController.h"
|
2016-10-10 22:02:09 +02:00
|
|
|
#import "InboxTableViewCell.h"
|
2017-09-06 19:55:01 +02:00
|
|
|
#import "NewContactThreadViewController.h"
|
2016-08-01 00:25:07 +02:00
|
|
|
#import "OWSContactsManager.h"
|
2017-08-17 18:37:21 +02:00
|
|
|
#import "OWSNavigationController.h"
|
2017-08-16 16:25:36 +02:00
|
|
|
#import "ProfileViewController.h"
|
2016-10-10 22:02:09 +02:00
|
|
|
#import "PushManager.h"
|
|
|
|
#import "Signal-Swift.h"
|
2015-01-14 22:30:01 +01:00
|
|
|
#import "TSAccountManager.h"
|
2014-11-21 14:38:37 +01:00
|
|
|
#import "TSDatabaseView.h"
|
2016-08-01 00:25:07 +02:00
|
|
|
#import "TSGroupThread.h"
|
2015-12-22 12:45:09 +01:00
|
|
|
#import "TSStorageManager.h"
|
2016-10-10 22:02:09 +02:00
|
|
|
#import "UIUtil.h"
|
2015-02-21 03:47:52 +01:00
|
|
|
#import "VersionMigrations.h"
|
2017-07-12 16:46:54 +02:00
|
|
|
#import "ViewControllerUtils.h"
|
2017-05-09 16:45:41 +02:00
|
|
|
#import <PromiseKit/AnyPromise.h>
|
2017-09-22 16:30:35 +02:00
|
|
|
#import <SignalServiceKit/NSDate+OWS.h>
|
2017-04-08 16:47:47 +02:00
|
|
|
#import <SignalServiceKit/OWSBlockingManager.h>
|
2016-10-14 22:59:58 +02:00
|
|
|
#import <SignalServiceKit/OWSMessageSender.h>
|
|
|
|
#import <SignalServiceKit/TSOutgoingMessage.h>
|
2017-08-03 19:16:45 +02:00
|
|
|
#import <SignalServiceKit/Threading.h>
|
2014-11-21 14:38:37 +01:00
|
|
|
#import <YapDatabase/YapDatabaseViewChange.h>
|
2016-10-14 22:59:58 +02:00
|
|
|
#import <YapDatabase/YapDatabaseViewConnection.h>
|
2014-11-21 14:38:37 +01:00
|
|
|
|
2017-07-14 20:06:19 +02:00
|
|
|
typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
@interface HomeViewController () <UITableViewDelegate, UITableViewDataSource, UIViewControllerPreviewingDelegate>
|
2017-07-10 22:04:03 +02:00
|
|
|
|
|
|
|
@property (nonatomic) UITableView *tableView;
|
|
|
|
@property (nonatomic) UILabel *emptyBoxLabel;
|
2015-01-29 03:57:53 +01:00
|
|
|
|
2017-04-08 16:47:47 +02:00
|
|
|
@property (nonatomic) YapDatabaseConnection *editingDbConnection;
|
|
|
|
@property (nonatomic) YapDatabaseConnection *uiDatabaseConnection;
|
|
|
|
@property (nonatomic) YapDatabaseViewMappings *threadMappings;
|
2015-01-14 22:30:01 +01:00
|
|
|
@property (nonatomic) CellState viewingThreadsIn;
|
|
|
|
@property (nonatomic) long inboxCount;
|
2017-04-08 16:47:47 +02:00
|
|
|
@property (nonatomic) UISegmentedControl *segmentedControl;
|
|
|
|
@property (nonatomic) id previewingContext;
|
2017-05-05 18:39:21 +02:00
|
|
|
@property (nonatomic) NSSet<NSString *> *blockedPhoneNumberSet;
|
2017-09-02 00:08:31 +02:00
|
|
|
@property (nonatomic) BOOL viewHasEverAppeared;
|
2017-02-27 17:04:14 +01:00
|
|
|
|
2017-05-31 23:49:21 +02:00
|
|
|
@property (nonatomic) BOOL isViewVisible;
|
|
|
|
@property (nonatomic) BOOL isAppInBackground;
|
|
|
|
@property (nonatomic) BOOL shouldObserveDBModifications;
|
2017-08-16 16:25:36 +02:00
|
|
|
@property (nonatomic) BOOL hasBeenPresented;
|
2017-05-31 23:49:21 +02:00
|
|
|
|
2017-02-27 17:04:14 +01:00
|
|
|
// Dependencies
|
|
|
|
|
2017-04-08 16:47:47 +02:00
|
|
|
@property (nonatomic, readonly) AccountManager *accountManager;
|
2016-09-21 14:37:51 +02:00
|
|
|
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
|
2017-02-27 17:04:14 +01:00
|
|
|
@property (nonatomic, readonly) ExperienceUpgradeFinder *experienceUpgradeFinder;
|
2017-09-14 17:00:30 +02:00
|
|
|
@property (nonatomic, readonly) OWSMessageManager *messagesManager;
|
2017-04-08 16:47:47 +02:00
|
|
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
|
|
|
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
|
|
|
|
|
2017-05-05 18:39:21 +02:00
|
|
|
// Views
|
|
|
|
|
2017-07-10 22:38:18 +02:00
|
|
|
@property (nonatomic) NSLayoutConstraint *hideArchiveReminderViewConstraint;
|
|
|
|
@property (nonatomic) NSLayoutConstraint *hideMissingContactsPermissionViewConstraint;
|
2017-07-10 22:04:03 +02:00
|
|
|
|
|
|
|
@property (nonatomic) TSThread *lastThread;
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-05-31 22:37:08 +02:00
|
|
|
#pragma mark -
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
@implementation HomeViewController
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2017-05-05 18:39:21 +02:00
|
|
|
#pragma mark - Init
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-11-12 18:22:29 +01:00
|
|
|
[self commonInit];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)aDecoder
|
|
|
|
{
|
2017-07-10 22:04:03 +02:00
|
|
|
OWSFail(@"Do not load this from the storyboard.");
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
self = [super initWithCoder:aDecoder];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-11-12 18:22:29 +01:00
|
|
|
[self commonInit];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-11-12 18:22:29 +01:00
|
|
|
- (void)commonInit
|
|
|
|
{
|
|
|
|
_accountManager = [Environment getCurrent].accountManager;
|
|
|
|
_contactsManager = [Environment getCurrent].contactsManager;
|
2017-09-14 17:00:30 +02:00
|
|
|
_messagesManager = [OWSMessageManager sharedManager];
|
2016-11-12 18:22:29 +01:00
|
|
|
_messageSender = [Environment getCurrent].messageSender;
|
2017-04-08 16:47:47 +02:00
|
|
|
_blockingManager = [OWSBlockingManager sharedManager];
|
|
|
|
_blockedPhoneNumberSet = [NSSet setWithArray:[_blockingManager blockedPhoneNumbers]];
|
|
|
|
|
2017-02-27 17:04:14 +01:00
|
|
|
_experienceUpgradeFinder = [ExperienceUpgradeFinder new];
|
2017-04-08 16:47:47 +02:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(blockedPhoneNumbersDidChange:)
|
|
|
|
name:kNSNotificationName_BlockedPhoneNumbersDidChange
|
|
|
|
object:nil];
|
2017-05-01 20:10:53 +02:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(signalAccountsDidChange:)
|
|
|
|
name:OWSContactsManagerSignalAccountsDidChangeNotification
|
|
|
|
object:nil];
|
2017-05-31 23:49:21 +02:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(applicationWillEnterForeground:)
|
|
|
|
name:UIApplicationWillEnterForegroundNotification
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(applicationDidEnterBackground:)
|
|
|
|
name:UIApplicationDidEnterBackgroundNotification
|
|
|
|
object:nil];
|
2017-07-14 19:43:36 +02:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(yapDatabaseModified:)
|
|
|
|
name:YapDatabaseModifiedNotification
|
|
|
|
object:nil];
|
2017-04-08 16:47:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
|
2017-05-05 18:39:21 +02:00
|
|
|
#pragma mark - Notifications
|
|
|
|
|
2017-04-08 16:47:47 +02:00
|
|
|
- (void)blockedPhoneNumbersDidChange:(id)notification
|
|
|
|
{
|
2017-06-09 22:21:59 +02:00
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
_blockedPhoneNumberSet = [NSSet setWithArray:[_blockingManager blockedPhoneNumbers]];
|
|
|
|
|
|
|
|
[self.tableView reloadData];
|
2016-11-12 18:22:29 +01:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:10:53 +02:00
|
|
|
- (void)signalAccountsDidChange:(id)notification
|
|
|
|
{
|
2017-06-09 22:21:59 +02:00
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
[self.tableView reloadData];
|
2017-05-01 20:10:53 +02:00
|
|
|
}
|
|
|
|
|
2017-05-05 18:39:21 +02:00
|
|
|
#pragma mark - View Life Cycle
|
|
|
|
|
2017-07-10 22:04:03 +02:00
|
|
|
- (void)loadView
|
2016-09-21 14:37:51 +02:00
|
|
|
{
|
2017-07-10 22:04:03 +02:00
|
|
|
[super loadView];
|
|
|
|
|
|
|
|
self.view.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
|
|
|
// TODO: Remove this.
|
2017-09-06 19:59:39 +02:00
|
|
|
[[Environment getCurrent] setHomeViewController:self];
|
2017-07-10 22:04:03 +02:00
|
|
|
|
|
|
|
self.navigationItem.rightBarButtonItem =
|
|
|
|
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
|
|
|
|
target:self
|
2017-09-11 18:49:14 +02:00
|
|
|
action:@selector(showNewConversationView)];
|
2017-07-10 22:04:03 +02:00
|
|
|
|
2017-07-10 22:38:18 +02:00
|
|
|
ReminderView *archiveReminderView = [ReminderView new];
|
|
|
|
archiveReminderView.text = NSLocalizedString(
|
|
|
|
@"INBOX_VIEW_ARCHIVE_MODE_REMINDER", @"Label reminding the user that they are in archive mode.");
|
2017-09-06 19:59:39 +02:00
|
|
|
__weak HomeViewController *weakSelf = self;
|
2017-07-10 22:38:18 +02:00
|
|
|
archiveReminderView.tapAction = ^{
|
2017-07-14 20:06:19 +02:00
|
|
|
[weakSelf showInboxGrouping];
|
2017-07-10 22:38:18 +02:00
|
|
|
};
|
|
|
|
[self.view addSubview:archiveReminderView];
|
|
|
|
[archiveReminderView autoPinWidthToSuperview];
|
|
|
|
[archiveReminderView autoPinToTopLayoutGuideOfViewController:self withInset:0];
|
|
|
|
self.hideArchiveReminderViewConstraint = [archiveReminderView autoSetDimension:ALDimensionHeight toSize:0];
|
|
|
|
self.hideArchiveReminderViewConstraint.priority = UILayoutPriorityRequired;
|
|
|
|
|
2017-07-10 22:04:03 +02:00
|
|
|
ReminderView *missingContactsPermissionView = [ReminderView new];
|
2017-07-10 22:38:18 +02:00
|
|
|
missingContactsPermissionView.text = NSLocalizedString(@"INBOX_VIEW_MISSING_CONTACTS_PERMISSION",
|
|
|
|
@"Multiline label explaining how to show names instead of phone numbers in your inbox");
|
|
|
|
missingContactsPermissionView.tapAction = ^{
|
|
|
|
[[UIApplication sharedApplication] openSystemSettings];
|
|
|
|
};
|
2017-07-10 22:04:03 +02:00
|
|
|
[self.view addSubview:missingContactsPermissionView];
|
|
|
|
[missingContactsPermissionView autoPinWidthToSuperview];
|
2017-07-10 22:38:18 +02:00
|
|
|
[missingContactsPermissionView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:archiveReminderView];
|
2017-07-10 22:04:03 +02:00
|
|
|
self.hideMissingContactsPermissionViewConstraint =
|
|
|
|
[missingContactsPermissionView autoSetDimension:ALDimensionHeight toSize:0];
|
2017-07-10 22:38:18 +02:00
|
|
|
self.hideMissingContactsPermissionViewConstraint.priority = UILayoutPriorityRequired;
|
2017-07-10 22:04:03 +02:00
|
|
|
|
|
|
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
|
|
self.tableView.delegate = self;
|
|
|
|
self.tableView.dataSource = self;
|
2017-07-11 23:56:22 +02:00
|
|
|
[self.tableView registerClass:[InboxTableViewCell class]
|
|
|
|
forCellReuseIdentifier:InboxTableViewCell.cellReuseIdentifier];
|
2017-07-10 22:04:03 +02:00
|
|
|
[self.view addSubview:self.tableView];
|
|
|
|
[self.tableView autoPinWidthToSuperview];
|
|
|
|
[self.tableView autoPinToBottomLayoutGuideOfViewController:self withInset:0];
|
|
|
|
[self.tableView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:missingContactsPermissionView];
|
|
|
|
|
|
|
|
UILabel *emptyBoxLabel = [UILabel new];
|
|
|
|
self.emptyBoxLabel = emptyBoxLabel;
|
|
|
|
[self.view addSubview:emptyBoxLabel];
|
|
|
|
[emptyBoxLabel autoPinWidthToSuperview];
|
|
|
|
[emptyBoxLabel autoPinToTopLayoutGuideOfViewController:self withInset:0];
|
|
|
|
[emptyBoxLabel autoPinToBottomLayoutGuideOfViewController:self withInset:0];
|
|
|
|
|
2017-07-10 22:38:18 +02:00
|
|
|
[self updateReminderViews];
|
2017-07-10 22:04:03 +02:00
|
|
|
}
|
|
|
|
|
2017-07-10 22:38:18 +02:00
|
|
|
- (void)updateReminderViews
|
2017-07-10 22:04:03 +02:00
|
|
|
{
|
2017-07-10 22:38:18 +02:00
|
|
|
BOOL shouldHideArchiveReminderView = self.viewingThreadsIn != kArchiveState;
|
|
|
|
BOOL shouldHideMissingContactsPermissionView = !self.shouldShowMissingContactsPermissionView;
|
|
|
|
if (self.hideArchiveReminderViewConstraint.active == shouldHideArchiveReminderView
|
|
|
|
&& self.hideMissingContactsPermissionViewConstraint.active == shouldHideMissingContactsPermissionView) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.hideArchiveReminderViewConstraint.active = shouldHideArchiveReminderView;
|
|
|
|
self.hideMissingContactsPermissionViewConstraint.active = shouldHideMissingContactsPermissionView;
|
|
|
|
[self.view setNeedsLayout];
|
|
|
|
[self.view layoutSubviews];
|
2014-11-26 20:29:45 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
2014-10-29 21:58:58 +01:00
|
|
|
[super viewDidLoad];
|
2015-01-14 22:30:01 +01:00
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2014-12-05 23:38:13 +01:00
|
|
|
self.editingDbConnection = TSStorageManager.sharedManager.newDatabaseConnection;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-05-31 23:49:21 +02:00
|
|
|
// Create the database connection.
|
|
|
|
[self uiDatabaseConnection];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-07-14 20:06:19 +02:00
|
|
|
[self showInboxGrouping];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-07-18 21:18:52 +02:00
|
|
|
// because this uses the table data source, `tableViewSetup` must happen
|
|
|
|
// after mappings have been set up in `showInboxGrouping`
|
|
|
|
[self tableViewSetUp];
|
|
|
|
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
self.segmentedControl = [[UISegmentedControl alloc] initWithItems:@[
|
|
|
|
NSLocalizedString(@"WHISPER_NAV_BAR_TITLE", nil),
|
|
|
|
NSLocalizedString(@"ARCHIVE_NAV_BAR_TITLE", nil)
|
|
|
|
]];
|
|
|
|
|
|
|
|
[self.segmentedControl addTarget:self
|
|
|
|
action:@selector(swappedSegmentedControl)
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
2017-01-31 04:59:39 +01:00
|
|
|
UINavigationItem *navigationItem = self.navigationItem;
|
|
|
|
navigationItem.titleView = self.segmentedControl;
|
2015-05-23 15:54:50 +02:00
|
|
|
[self.segmentedControl setSelectedSegmentIndex:0];
|
2017-09-06 19:59:39 +02:00
|
|
|
navigationItem.leftBarButtonItem.accessibilityLabel
|
|
|
|
= NSLocalizedString(@"SETTINGS_BUTTON_ACCESSIBILITY", @"Accessibility hint for the settings button");
|
2015-12-26 17:27:27 +01:00
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)]
|
|
|
|
&& (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) {
|
2015-12-26 17:27:27 +01:00
|
|
|
[self registerForPreviewingWithDelegate:self sourceView:self.tableView];
|
2015-10-31 16:53:32 +01:00
|
|
|
}
|
2017-06-20 22:13:16 +02:00
|
|
|
|
2017-02-17 18:00:10 +01:00
|
|
|
[self updateBarButtonItems];
|
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)updateBarButtonItems
|
|
|
|
{
|
2017-02-17 18:00:10 +01:00
|
|
|
const CGFloat kBarButtonSize = 44;
|
2017-07-11 23:56:22 +02: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 *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
UIImage *image = [UIImage imageNamed:@"button_settings_white"];
|
|
|
|
[button setImage:image forState:UIControlStateNormal];
|
|
|
|
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
|
|
|
|
// leading inset tighten up the layout.
|
|
|
|
CGFloat hInset = round((kBarButtonSize - image.size.width) * 0.5f);
|
|
|
|
if (self.view.isRTL) {
|
|
|
|
imageEdgeInsets.right = hInset;
|
|
|
|
imageEdgeInsets.left = round((kBarButtonSize - (image.size.width + hInset)) * 0.5f);
|
|
|
|
} else {
|
|
|
|
imageEdgeInsets.left = hInset;
|
|
|
|
imageEdgeInsets.right = round((kBarButtonSize - (image.size.width + hInset)) * 0.5f);
|
2017-02-17 18:00:10 +01:00
|
|
|
}
|
2017-07-11 23:56:22 +02:00
|
|
|
imageEdgeInsets.top = round((kBarButtonSize - image.size.height) * 0.5f);
|
|
|
|
imageEdgeInsets.bottom = round(kBarButtonSize - (image.size.height + imageEdgeInsets.top));
|
|
|
|
button.imageEdgeInsets = imageEdgeInsets;
|
|
|
|
button.accessibilityLabel
|
|
|
|
= NSLocalizedString(@"OPEN_SETTINGS_BUTTON", "Label for button which opens the settings UI");
|
|
|
|
[button addTarget:self action:@selector(settingsButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
button.frame = CGRectMake(0,
|
|
|
|
0,
|
|
|
|
round(image.size.width + imageEdgeInsets.left + imageEdgeInsets.right),
|
|
|
|
round(image.size.height + imageEdgeInsets.top + imageEdgeInsets.bottom));
|
|
|
|
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
|
2017-02-17 18:00:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)settingsButtonPressed:(id)sender {
|
2017-09-07 17:03:54 +02:00
|
|
|
OWSNavigationController *navigationController = [AppSettingsViewController inModalNavigationController];
|
2017-05-23 16:25:47 +02:00
|
|
|
[self presentViewController:navigationController animated:YES completion:nil];
|
2015-10-31 16:53:32 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
|
2017-09-06 19:59:39 +02:00
|
|
|
viewControllerForLocation:(CGPoint)location
|
|
|
|
{
|
2015-12-22 12:45:09 +01:00
|
|
|
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
|
|
|
|
|
2015-12-26 17:27:27 +01:00
|
|
|
if (indexPath) {
|
|
|
|
[previewingContext setSourceRect:[self.tableView rectForRowAtIndexPath:indexPath]];
|
|
|
|
|
2017-09-06 20:13:18 +02:00
|
|
|
ConversationViewController *vc = [ConversationViewController new];
|
2017-09-06 19:59:39 +02:00
|
|
|
TSThread *thread = [self threadForIndexPath:indexPath];
|
2017-07-10 22:04:03 +02:00
|
|
|
self.lastThread = thread;
|
2017-04-18 22:08:01 +02:00
|
|
|
[vc configureForThread:thread keyboardOnViewAppearing:NO callOnViewAppearing:NO];
|
2015-12-26 17:27:27 +01:00
|
|
|
[vc peekSetup];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-12-26 17:27:27 +01:00
|
|
|
return vc;
|
|
|
|
} else {
|
|
|
|
return nil;
|
|
|
|
}
|
2015-10-31 16:53:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
|
2017-09-06 19:59:39 +02:00
|
|
|
commitViewController:(UIViewController *)viewControllerToCommit
|
|
|
|
{
|
2017-09-06 20:13:18 +02:00
|
|
|
ConversationViewController *vc = (ConversationViewController *)viewControllerToCommit;
|
2015-10-31 16:53:32 +01:00
|
|
|
[vc popped];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
[self.navigationController pushViewController:vc animated:NO];
|
2015-10-31 16:53:32 +01:00
|
|
|
}
|
|
|
|
|
2017-09-11 18:49:14 +02:00
|
|
|
- (void)showNewConversationView
|
2017-05-02 00:06:53 +02:00
|
|
|
{
|
2017-09-06 19:55:01 +02:00
|
|
|
NewContactThreadViewController *viewController = [NewContactThreadViewController new];
|
2017-05-08 22:28:01 +02:00
|
|
|
|
|
|
|
[self.contactsManager requestSystemContactsOnceWithCompletion:^(NSError *_Nullable error) {
|
2017-05-11 22:09:39 +02:00
|
|
|
if (error) {
|
|
|
|
DDLogError(@"%@ Error when requesting contacts: %@", self.tag, error);
|
|
|
|
}
|
|
|
|
// Even if there is an error fetching contacts we proceed to the next screen.
|
2017-05-08 22:28:01 +02:00
|
|
|
// As the compose view will present the proper thing depending on contact access.
|
|
|
|
//
|
|
|
|
// We just want to make sure contact access is *complete* before showing the compose
|
|
|
|
// screen to avoid flicker.
|
2017-08-17 18:37:21 +02:00
|
|
|
OWSNavigationController *navigationController =
|
|
|
|
[[OWSNavigationController alloc] initWithRootViewController:viewController];
|
2017-05-08 22:28:01 +02:00
|
|
|
[self presentTopLevelModalViewController:navigationController animateDismissal:YES animatePresentation:YES];
|
|
|
|
}];
|
2015-10-31 23:13:28 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)swappedSegmentedControl
|
|
|
|
{
|
2015-05-23 15:54:50 +02:00
|
|
|
if (self.segmentedControl.selectedSegmentIndex == 0) {
|
2017-07-14 20:06:19 +02:00
|
|
|
[self showInboxGrouping];
|
2015-05-23 15:54:50 +02:00
|
|
|
} else {
|
2017-07-14 20:06:19 +02:00
|
|
|
[self showArchiveGrouping];
|
2015-05-23 15:54:50 +02:00
|
|
|
}
|
2014-11-24 21:51:43 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
2014-11-24 21:51:43 +01:00
|
|
|
[super viewWillAppear:animated];
|
2017-05-01 20:28:37 +02:00
|
|
|
if ([TSThread numberOfKeysInCollection] > 0) {
|
2017-06-30 06:26:37 +02:00
|
|
|
[self.contactsManager requestSystemContactsOnceWithCompletion:^(NSError *_Nullable error) {
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2017-07-10 22:38:18 +02:00
|
|
|
[self updateReminderViews];
|
2017-06-30 06:26:37 +02:00
|
|
|
});
|
|
|
|
}];
|
2017-05-01 20:28:37 +02:00
|
|
|
}
|
2017-06-30 06:26:37 +02:00
|
|
|
|
2016-04-01 17:34:47 +02:00
|
|
|
[self updateInboxCountLabel];
|
2017-05-31 23:49:21 +02:00
|
|
|
|
|
|
|
self.isViewVisible = YES;
|
2017-07-10 22:04:03 +02:00
|
|
|
|
2017-07-10 22:42:51 +02:00
|
|
|
// When returning to home view, try to ensure that the "last" thread is still
|
|
|
|
// visible. The threads often change ordering while in conversation view due
|
|
|
|
// to incoming & outgoing messages.
|
2017-07-10 22:04:03 +02:00
|
|
|
if (self.lastThread) {
|
2017-07-11 22:11:56 +02:00
|
|
|
__block NSIndexPath *indexPathOfLastThread = nil;
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
indexPathOfLastThread =
|
|
|
|
[[transaction extension:TSThreadDatabaseViewExtensionName] indexPathForKey:self.lastThread.uniqueId
|
|
|
|
inCollection:[TSThread collection]
|
|
|
|
withMappings:self.threadMappings];
|
|
|
|
}];
|
2017-07-10 22:04:03 +02:00
|
|
|
|
|
|
|
if (indexPathOfLastThread) {
|
|
|
|
[self.tableView scrollToRowAtIndexPath:indexPathOfLastThread
|
|
|
|
atScrollPosition:UITableViewScrollPositionNone
|
|
|
|
animated:NO];
|
|
|
|
}
|
|
|
|
}
|
2017-07-14 19:20:00 +02:00
|
|
|
|
|
|
|
[self checkIfEmptyView];
|
2017-05-31 23:49:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
|
|
|
self.isViewVisible = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setIsViewVisible:(BOOL)isViewVisible
|
|
|
|
{
|
|
|
|
_isViewVisible = isViewVisible;
|
|
|
|
|
|
|
|
[self updateShouldObserveDBModifications];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setIsAppInBackground:(BOOL)isAppInBackground
|
|
|
|
{
|
|
|
|
_isAppInBackground = isAppInBackground;
|
|
|
|
|
|
|
|
[self updateShouldObserveDBModifications];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateShouldObserveDBModifications
|
|
|
|
{
|
|
|
|
self.shouldObserveDBModifications = self.isViewVisible && !self.isAppInBackground;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setShouldObserveDBModifications:(BOOL)shouldObserveDBModifications
|
|
|
|
{
|
2017-07-14 19:43:36 +02:00
|
|
|
if (_shouldObserveDBModifications == shouldObserveDBModifications) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-14 19:34:24 +02:00
|
|
|
|
2017-07-14 19:43:36 +02:00
|
|
|
_shouldObserveDBModifications = shouldObserveDBModifications;
|
2017-05-31 23:49:21 +02:00
|
|
|
|
2017-07-26 18:39:43 +02:00
|
|
|
if (self.shouldObserveDBModifications) {
|
|
|
|
[self resetMappings];
|
2017-05-31 23:49:21 +02:00
|
|
|
}
|
2017-07-26 18:39:43 +02:00
|
|
|
}
|
2017-05-31 23:49:21 +02:00
|
|
|
|
2017-07-26 18:39:43 +02:00
|
|
|
- (void)resetMappings
|
|
|
|
{
|
2017-07-14 19:43:36 +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.threadMappings != 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];
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
[self.threadMappings updateWithTransaction:transaction];
|
|
|
|
}];
|
2017-05-31 23:49:21 +02:00
|
|
|
}
|
2017-07-14 19:20:00 +02:00
|
|
|
|
2017-07-14 19:43:36 +02:00
|
|
|
[[self tableView] reloadData];
|
2017-07-14 19:20:00 +02:00
|
|
|
[self checkIfEmptyView];
|
2017-07-14 19:43:36 +02:00
|
|
|
[self updateInboxCountLabel];
|
2017-07-26 18:39:43 +02:00
|
|
|
|
|
|
|
// If the user hasn't already granted contact access
|
|
|
|
// we don't want to request until they receive a message.
|
|
|
|
if ([TSThread numberOfKeysInCollection] > 0) {
|
|
|
|
[self.contactsManager requestSystemContactsOnce];
|
|
|
|
}
|
2017-05-31 23:49:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
self.isAppInBackground = NO;
|
2017-07-14 19:43:36 +02:00
|
|
|
[self checkIfEmptyView];
|
2017-05-31 23:49:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
self.isAppInBackground = YES;
|
2016-04-01 17:34:47 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
{
|
2016-04-01 17:34:47 +02:00
|
|
|
[super viewDidAppear:animated];
|
2017-07-10 22:04:03 +02:00
|
|
|
|
Rework push registration
== Account Registration ==
Not complete until push tokens are uploaded
== Remote Notifications Registration ==
Extracted from PushManager
- wait for notification-settings registration to complete before
requesting push tokens, otherwise it's possible token requests will
be ignored.
- Less state required for push notification callbacks, specifically, we
no longer need to ensure we've created a promise before the
registration delegate methods get called.
- no more TOCFuture in Signal-iOS (still in SSK for now). It's not in
cases of inexplicable behavior - one a recently, push notification
premature free, in redphone, and more popular use, and I've seen two
futures inexplicably being nil. Instead, let's consolidate around
PromiseKit for popularly used, maintained, strongly-typed futures.
- separate logic for registering for vanilla push/voip notifications
(few dependencies) from responding to UILocalNotifications (lots of
dependencies). Ultimately I'd like to consolidate the remaining
UILocalNotifications logic with the existing NotificationsManager
== Misc ==
more debug logging
more uniform logging
remove stale logic around newly registered user
// FREEBIE
2017-09-20 23:47:12 +02:00
|
|
|
if (!self.viewHasEverAppeared) {
|
|
|
|
self.viewHasEverAppeared = YES;
|
2017-02-27 17:04:14 +01:00
|
|
|
[self displayAnyUnseenUpgradeExperience];
|
2016-10-10 22:02:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-27 17:04:14 +01:00
|
|
|
#pragma mark - startup
|
|
|
|
|
2017-05-26 00:00:41 +02:00
|
|
|
- (NSArray<ExperienceUpgrade *> *)unseenUpgradeExperiences
|
2017-02-27 17:04:14 +01:00
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
__block NSArray<ExperienceUpgrade *> *unseenUpgrades;
|
|
|
|
[self.editingDbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
unseenUpgrades = [self.experienceUpgradeFinder allUnseenWithTransaction:transaction];
|
|
|
|
}];
|
2017-05-26 00:00:41 +02:00
|
|
|
return unseenUpgrades;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markAllUpgradeExperiencesAsSeen
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
[self.experienceUpgradeFinder markAllAsSeenWithTransaction:transaction];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)displayAnyUnseenUpgradeExperience
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
NSArray<ExperienceUpgrade *> *unseenUpgrades = [self unseenUpgradeExperiences];
|
2017-02-27 17:04:14 +01:00
|
|
|
|
|
|
|
if (unseenUpgrades.count > 0) {
|
2017-09-06 19:59:39 +02:00
|
|
|
ExperienceUpgradesPageViewController *experienceUpgradeViewController =
|
|
|
|
[[ExperienceUpgradesPageViewController alloc] initWithExperienceUpgrades:unseenUpgrades];
|
2017-05-26 00:00:41 +02:00
|
|
|
[self presentViewController:experienceUpgradeViewController
|
|
|
|
animated:YES
|
|
|
|
completion:^{
|
|
|
|
[self markAllUpgradeExperiencesAsSeen];
|
|
|
|
}];
|
2017-08-16 16:25:36 +02:00
|
|
|
} else if (!self.hasBeenPresented && [ProfileViewController shouldDisplayProfileViewOnLaunch]) {
|
|
|
|
[ProfileViewController presentForUpgradeOrNag:self];
|
2017-02-27 17:04:14 +01:00
|
|
|
}
|
2017-08-16 16:25:36 +02:00
|
|
|
|
|
|
|
self.hasBeenPresented = YES;
|
2017-02-27 17:04:14 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)tableViewSetUp
|
|
|
|
{
|
2014-11-21 14:38:37 +01:00
|
|
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-05-05 18:39:21 +02:00
|
|
|
- (BOOL)shouldShowMissingContactsPermissionView
|
|
|
|
{
|
|
|
|
if ([TSContactThread numberOfKeysInCollection] == 0) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !self.contactsManager.isSystemContactsAuthorized;
|
|
|
|
}
|
|
|
|
|
2015-01-24 04:26:04 +01:00
|
|
|
#pragma mark - Table View Data Source
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2017-05-31 23:49:21 +02:00
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
|
{
|
2014-11-21 14:38:37 +01:00
|
|
|
return (NSInteger)[self.threadMappings numberOfSections];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
|
{
|
2014-11-21 14:38:37 +01:00
|
|
|
return (NSInteger)[self.threadMappings numberOfItemsInSection:(NSUInteger)section];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-05-05 18:39:21 +02:00
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-12-22 12:45:09 +01:00
|
|
|
InboxTableViewCell *cell =
|
2017-07-11 23:56:22 +02:00
|
|
|
[self.tableView dequeueReusableCellWithIdentifier:InboxTableViewCell.cellReuseIdentifier];
|
|
|
|
OWSAssert(cell);
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-07-11 23:56:22 +02:00
|
|
|
TSThread *thread = [self threadForIndexPath:indexPath];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-04-08 16:47:47 +02:00
|
|
|
[cell configureWithThread:thread contactsManager:self.contactsManager blockedPhoneNumberSet:_blockedPhoneNumberSet];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
if ((unsigned long)indexPath.row == [self.threadMappings numberOfItemsInSection:0] - 1) {
|
2015-03-20 14:32:57 +01:00
|
|
|
cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f);
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
return cell;
|
2014-11-21 14:38:37 +01:00
|
|
|
}
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (TSThread *)threadForIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2014-11-21 14:38:37 +01:00
|
|
|
__block TSThread *thread = nil;
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
2017-09-06 19:59:39 +02:00
|
|
|
thread = [[transaction extension:TSThreadDatabaseViewExtensionName] objectAtIndexPath:indexPath
|
|
|
|
withMappings:self.threadMappings];
|
2014-11-21 14:38:37 +01:00
|
|
|
}];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
return thread;
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2017-07-21 16:36:45 +02:00
|
|
|
return InboxTableViewCell.rowHeight;
|
2014-11-21 14:38:37 +01:00
|
|
|
}
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
#pragma mark Table Swipe to Delete
|
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
- (void)tableView:(UITableView *)tableView
|
|
|
|
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
|
2017-09-06 19:59:39 +02:00
|
|
|
forRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-01-14 22:30:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:17:49 +01:00
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-12-22 12:45:09 +01:00
|
|
|
UITableViewRowAction *deleteAction =
|
|
|
|
[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
|
2015-12-26 17:27:27 +01:00
|
|
|
title:NSLocalizedString(@"TXT_DELETE_TITLE", nil)
|
2015-12-22 12:45:09 +01:00
|
|
|
handler:^(UITableViewRowAction *action, NSIndexPath *swipedIndexPath) {
|
2017-09-06 19:59:39 +02:00
|
|
|
[self tableViewCellTappedDelete:swipedIndexPath];
|
2015-12-22 12:45:09 +01:00
|
|
|
}];
|
|
|
|
|
2015-12-26 17:27:27 +01:00
|
|
|
UITableViewRowAction *archiveAction;
|
|
|
|
if (self.viewingThreadsIn == kInboxState) {
|
|
|
|
archiveAction = [UITableViewRowAction
|
|
|
|
rowActionWithStyle:UITableViewRowActionStyleNormal
|
2017-09-06 19:59:39 +02:00
|
|
|
title:NSLocalizedString(@"ARCHIVE_ACTION",
|
|
|
|
@"Pressing this button moves a thread from the inbox to the archive")
|
2015-12-26 17:27:27 +01:00
|
|
|
handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull tappedIndexPath) {
|
2017-09-06 19:59:39 +02:00
|
|
|
[self archiveIndexPath:tappedIndexPath];
|
|
|
|
[Environment.preferences setHasArchivedAMessage:YES];
|
2015-12-26 17:27:27 +01:00
|
|
|
}];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-12-26 17:27:27 +01:00
|
|
|
} else {
|
|
|
|
archiveAction = [UITableViewRowAction
|
|
|
|
rowActionWithStyle:UITableViewRowActionStyleNormal
|
2017-09-06 19:59:39 +02:00
|
|
|
title:NSLocalizedString(@"UNARCHIVE_ACTION",
|
|
|
|
@"Pressing this button moves an archived thread from the archive back to the inbox")
|
2015-12-26 17:27:27 +01:00
|
|
|
handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull tappedIndexPath) {
|
2017-09-06 19:59:39 +02:00
|
|
|
[self archiveIndexPath:tappedIndexPath];
|
2015-12-26 17:27:27 +01:00
|
|
|
}];
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
|
2015-12-26 17:27:27 +01:00
|
|
|
return @[ deleteAction, archiveAction ];
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-01-14 22:30:01 +01:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
#pragma mark - HomeFeedTableViewCellDelegate
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)tableViewCellTappedDelete:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-12-22 12:45:09 +01:00
|
|
|
TSThread *thread = [self threadForIndexPath:indexPath];
|
|
|
|
if ([thread isKindOfClass:[TSGroupThread class]]) {
|
2016-11-15 11:15:51 +01:00
|
|
|
|
|
|
|
TSGroupThread *gThread = (TSGroupThread *)thread;
|
|
|
|
if ([gThread.groupModel.groupMemberIds containsObject:[TSAccountManager localNumber]]) {
|
|
|
|
UIAlertController *removingFromGroup = [UIAlertController
|
2017-09-06 19:59:39 +02:00
|
|
|
alertControllerWithTitle:[NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"GROUP_REMOVING", nil), [thread name]]
|
|
|
|
message:nil
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
2016-11-15 11:15:51 +01:00
|
|
|
[self presentViewController:removingFromGroup animated:YES completion:nil];
|
|
|
|
|
|
|
|
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
inThread:thread
|
2017-04-12 17:03:16 +02:00
|
|
|
groupMetaMessage:TSGroupMessageQuit];
|
2016-11-15 11:15:51 +01:00
|
|
|
[self.messageSender sendMessage:message
|
2017-05-09 16:04:48 +02:00
|
|
|
success:^{
|
|
|
|
[self dismissViewControllerAnimated:YES
|
|
|
|
completion:^{
|
|
|
|
[self deleteThread:thread];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
failure:^(NSError *error) {
|
|
|
|
[self dismissViewControllerAnimated:YES
|
|
|
|
completion:^{
|
|
|
|
[OWSAlerts
|
|
|
|
showAlertWithTitle:
|
|
|
|
NSLocalizedString(@"GROUP_REMOVING_FAILED",
|
|
|
|
@"Title of alert indicating that group deletion failed.")
|
|
|
|
message:error.localizedRecoverySuggestion];
|
|
|
|
}];
|
|
|
|
}];
|
2016-11-15 11:15:51 +01:00
|
|
|
} else {
|
|
|
|
[self deleteThread:thread];
|
|
|
|
}
|
2015-12-26 17:27:27 +01:00
|
|
|
} else {
|
|
|
|
[self deleteThread:thread];
|
2014-12-24 02:25:10 +01:00
|
|
|
}
|
2015-12-26 17:27:27 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)deleteThread:(TSThread *)thread
|
|
|
|
{
|
2014-12-05 23:38:13 +01:00
|
|
|
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-09-06 19:59:39 +02:00
|
|
|
[thread removeWithTransaction:transaction];
|
2014-12-05 23:38:13 +01:00
|
|
|
}];
|
2015-12-26 17:27:27 +01:00
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
_inboxCount -= (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
|
2015-01-27 02:20:11 +01:00
|
|
|
[self checkIfEmptyView];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)archiveIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-12-26 17:27:27 +01:00
|
|
|
TSThread *thread = [self threadForIndexPath:indexPath];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-07-10 15:00:14 +02:00
|
|
|
BOOL viewingThreadsIn = self.viewingThreadsIn;
|
2014-12-05 23:38:13 +01:00
|
|
|
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2017-09-06 19:59:39 +02:00
|
|
|
viewingThreadsIn == kInboxState ? [thread archiveThreadWithTransaction:transaction]
|
|
|
|
: [thread unarchiveThreadWithTransaction:transaction];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2014-12-05 23:38:13 +01:00
|
|
|
}];
|
2015-01-27 02:20:11 +01:00
|
|
|
[self checkIfEmptyView];
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-12 16:46:54 +02:00
|
|
|
- (void)updateInboxCountLabel
|
|
|
|
{
|
2016-10-14 22:59:58 +02:00
|
|
|
NSUInteger numberOfItems = [self.messagesManager unreadMessagesCount];
|
2017-09-06 19:59:39 +02:00
|
|
|
NSString *unreadString = NSLocalizedString(@"WHISPER_NAV_BAR_TITLE", nil);
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-07-12 16:46:54 +02:00
|
|
|
if (numberOfItems > 0) {
|
|
|
|
unreadString =
|
|
|
|
[unreadString stringByAppendingFormat:@" (%@)", [ViewControllerUtils formatInt:(int)numberOfItems]];
|
2015-02-10 12:02:58 +01:00
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2015-05-23 15:54:50 +02:00
|
|
|
[_segmentedControl setTitle:unreadString forSegmentAtIndex:0];
|
2017-02-07 22:29:23 +01:00
|
|
|
[_segmentedControl.superview setNeedsLayout];
|
2015-09-01 19:22:08 +02:00
|
|
|
[_segmentedControl reloadInputViews];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
2015-12-26 17:27:27 +01:00
|
|
|
TSThread *thread = [self threadForIndexPath:indexPath];
|
2017-04-18 22:08:01 +02:00
|
|
|
[self presentThread:thread keyboardOnViewAppearing:NO callOnViewAppearing:NO];
|
2015-12-26 17:27:27 +01:00
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
|
}
|
|
|
|
|
2017-04-18 22:08:01 +02:00
|
|
|
- (void)presentThread:(TSThread *)thread
|
|
|
|
keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
|
|
|
|
callOnViewAppearing:(BOOL)callOnViewAppearing
|
|
|
|
{
|
2017-09-18 22:12:51 +02:00
|
|
|
// At most one.
|
|
|
|
OWSAssert(!keyboardOnViewAppearing || !callOnViewAppearing);
|
|
|
|
|
2017-08-31 18:31:13 +02:00
|
|
|
if (thread == nil) {
|
|
|
|
OWSFail(@"Thread unexpectedly nil");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-03 19:16:45 +02:00
|
|
|
// We do this synchronously if we're already on the main thread.
|
|
|
|
DispatchMainThreadSafe(^{
|
2017-09-06 20:13:18 +02:00
|
|
|
ConversationViewController *mvc =
|
|
|
|
[[ConversationViewController alloc] initWithNibName:@"ConversationViewController" bundle:nil];
|
2017-05-02 00:06:53 +02:00
|
|
|
[mvc configureForThread:thread
|
|
|
|
keyboardOnViewAppearing:keyboardOnViewAppearing
|
|
|
|
callOnViewAppearing:callOnViewAppearing];
|
2017-07-10 22:04:03 +02:00
|
|
|
self.lastThread = thread;
|
2015-12-26 17:27:27 +01:00
|
|
|
|
2017-08-03 16:40:45 +02:00
|
|
|
[self pushTopLevelViewController:mvc animateDismissal:YES animatePresentation:YES];
|
2015-12-26 17:27:27 +01:00
|
|
|
});
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2017-04-25 18:56:37 +02:00
|
|
|
- (void)presentTopLevelModalViewController:(UIViewController *)viewController
|
|
|
|
animateDismissal:(BOOL)animateDismissal
|
|
|
|
animatePresentation:(BOOL)animatePresentation
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert(viewController);
|
|
|
|
|
|
|
|
[self presentViewControllerWithBlock:^{
|
|
|
|
[self presentViewController:viewController animated:animatePresentation completion:nil];
|
|
|
|
}
|
|
|
|
animateDismissal:animateDismissal];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)pushTopLevelViewController:(UIViewController *)viewController
|
|
|
|
animateDismissal:(BOOL)animateDismissal
|
|
|
|
animatePresentation:(BOOL)animatePresentation
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert(viewController);
|
|
|
|
|
|
|
|
[self presentViewControllerWithBlock:^{
|
|
|
|
[self.navigationController pushViewController:viewController animated:animatePresentation];
|
|
|
|
}
|
|
|
|
animateDismissal:animateDismissal];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)presentViewControllerWithBlock:(void (^)())presentationBlock animateDismissal:(BOOL)animateDismissal
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
OWSAssert(presentationBlock);
|
|
|
|
|
|
|
|
// Presenting a "top level" view controller has three steps:
|
|
|
|
//
|
|
|
|
// First, dismiss any presented modal.
|
|
|
|
// Second, pop to the root view controller if necessary.
|
|
|
|
// Third present the new view controller using presentationBlock.
|
|
|
|
|
|
|
|
// Define a block to perform the second step.
|
|
|
|
void (^dismissNavigationBlock)() = ^{
|
|
|
|
if (self.navigationController.viewControllers.lastObject != self) {
|
|
|
|
[CATransaction begin];
|
|
|
|
[CATransaction setCompletionBlock:^{
|
|
|
|
presentationBlock();
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.navigationController popToViewController:self animated:animateDismissal];
|
|
|
|
|
|
|
|
[CATransaction commit];
|
|
|
|
} else {
|
|
|
|
presentationBlock();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Perform the first step.
|
|
|
|
if (self.presentedViewController) {
|
2017-08-03 16:40:45 +02:00
|
|
|
if ([self.presentedViewController isKindOfClass:[CallViewController class]]) {
|
2017-08-03 16:41:16 +02:00
|
|
|
OWSProdInfo([OWSAnalyticsEvents errorCouldNotPresentViewDueToCall]);
|
2017-08-03 16:40:45 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-04-25 18:56:37 +02:00
|
|
|
[self.presentedViewController dismissViewControllerAnimated:animateDismissal completion:dismissNavigationBlock];
|
|
|
|
} else {
|
|
|
|
dismissNavigationBlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 22:04:03 +02:00
|
|
|
#pragma mark - Groupings
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2017-07-18 21:18:52 +02:00
|
|
|
- (YapDatabaseViewMappings *)threadMappings
|
|
|
|
{
|
|
|
|
OWSAssert(_threadMappings != nil);
|
|
|
|
return _threadMappings;
|
|
|
|
}
|
|
|
|
|
2017-07-14 20:06:19 +02:00
|
|
|
- (void)showInboxGrouping
|
2017-07-10 22:04:03 +02:00
|
|
|
{
|
2015-01-14 22:30:01 +01:00
|
|
|
self.viewingThreadsIn = kInboxState;
|
|
|
|
}
|
|
|
|
|
2017-07-14 20:06:19 +02:00
|
|
|
- (void)showArchiveGrouping
|
2017-07-10 22:04:03 +02:00
|
|
|
{
|
2015-01-14 22:30:01 +01:00
|
|
|
self.viewingThreadsIn = kArchiveState;
|
2017-07-14 20:06:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setViewingThreadsIn:(CellState)viewingThreadsIn
|
|
|
|
{
|
|
|
|
BOOL didChange = _viewingThreadsIn != viewingThreadsIn;
|
|
|
|
_viewingThreadsIn = viewingThreadsIn;
|
|
|
|
self.segmentedControl.selectedSegmentIndex = (viewingThreadsIn == kInboxState ? 0 : 1);
|
|
|
|
if (didChange || !self.threadMappings) {
|
2017-07-25 18:52:30 +02:00
|
|
|
[self updateMappings];
|
2017-07-14 20:06:19 +02:00
|
|
|
} else {
|
|
|
|
[self checkIfEmptyView];
|
|
|
|
[self updateReminderViews];
|
|
|
|
}
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-25 18:52:30 +02:00
|
|
|
- (NSString *)currentGrouping
|
|
|
|
{
|
|
|
|
return self.viewingThreadsIn == kInboxState ? TSInboxGroup : TSArchiveGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateMappings
|
|
|
|
{
|
2017-05-31 23:49:21 +02:00
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
2017-07-25 18:52:30 +02:00
|
|
|
self.threadMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[ self.currentGrouping ]
|
|
|
|
view:TSThreadDatabaseViewExtensionName];
|
|
|
|
[self.threadMappings setIsReversed:YES forGroup:self.currentGrouping];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-07-26 18:39:43 +02:00
|
|
|
[self resetMappings];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-07-19 15:30:36 +02:00
|
|
|
[[self tableView] reloadData];
|
2017-05-31 23:49:21 +02:00
|
|
|
[self checkIfEmptyView];
|
2017-07-10 22:38:18 +02:00
|
|
|
[self updateReminderViews];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
2014-11-21 14:38:37 +01:00
|
|
|
|
|
|
|
#pragma mark Database delegates
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (YapDatabaseConnection *)uiDatabaseConnection
|
|
|
|
{
|
2014-11-21 14:38:37 +01:00
|
|
|
NSAssert([NSThread isMainThread], @"Must access uiDatabaseConnection on main thread!");
|
|
|
|
if (!_uiDatabaseConnection) {
|
|
|
|
YapDatabase *database = TSStorageManager.sharedManager.database;
|
|
|
|
_uiDatabaseConnection = [database newConnection];
|
|
|
|
[_uiDatabaseConnection beginLongLivedReadTransaction];
|
|
|
|
}
|
|
|
|
return _uiDatabaseConnection;
|
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)yapDatabaseModified:(NSNotification *)notification
|
|
|
|
{
|
2017-07-25 18:52:30 +02:00
|
|
|
if (!self.shouldObserveDBModifications) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
NSArray *notifications = [self.uiDatabaseConnection beginLongLivedReadTransaction];
|
2017-07-25 18:52:30 +02:00
|
|
|
|
|
|
|
if (![[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] hasChangesForGroup:self.currentGrouping
|
|
|
|
inNotifications:notifications]) {
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
[self.self.threadMappings updateWithTransaction:transaction];
|
|
|
|
}];
|
|
|
|
return;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-05-01 20:28:37 +02:00
|
|
|
// If the user hasn't already granted contact access
|
|
|
|
// we don't want to request until they receive a message.
|
|
|
|
if ([TSThread numberOfKeysInCollection] > 0) {
|
|
|
|
[self.contactsManager requestSystemContactsOnce];
|
|
|
|
}
|
|
|
|
|
2017-07-25 18:52:30 +02:00
|
|
|
NSArray *sectionChanges = nil;
|
|
|
|
NSArray *rowChanges = nil;
|
2014-11-21 14:38:37 +01:00
|
|
|
[[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] getSectionChanges:§ionChanges
|
|
|
|
rowChanges:&rowChanges
|
|
|
|
forNotifications:notifications
|
|
|
|
withMappings:self.threadMappings];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2016-09-01 17:14:58 +02:00
|
|
|
// We want this regardless of if we're currently viewing the archive.
|
|
|
|
// So we run it before the early return
|
|
|
|
[self updateInboxCountLabel];
|
2017-07-14 20:14:41 +02:00
|
|
|
[self checkIfEmptyView];
|
2016-09-01 17:14:58 +02:00
|
|
|
|
2015-12-22 12:45:09 +01:00
|
|
|
if ([sectionChanges count] == 0 && [rowChanges count] == 0) {
|
2014-11-21 14:38:37 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView beginUpdates];
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
for (YapDatabaseViewSectionChange *sectionChange in sectionChanges) {
|
|
|
|
switch (sectionChange.type) {
|
|
|
|
case YapDatabaseViewChangeDelete: {
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionChange.index]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
break;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
case YapDatabaseViewChangeInsert: {
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionChange.index]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case YapDatabaseViewChangeUpdate:
|
|
|
|
case YapDatabaseViewChangeMove:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
|
|
|
for (YapDatabaseViewRowChange *rowChange in rowChanges) {
|
|
|
|
switch (rowChange.type) {
|
|
|
|
case YapDatabaseViewChangeDelete: {
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView deleteRowsAtIndexPaths:@[ rowChange.indexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
2015-01-14 22:30:01 +01:00
|
|
|
_inboxCount += (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
|
2014-11-21 14:38:37 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
case YapDatabaseViewChangeInsert: {
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView insertRowsAtIndexPaths:@[ rowChange.newIndexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
2015-01-14 22:30:01 +01:00
|
|
|
_inboxCount -= (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
|
2014-11-21 14:38:37 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
case YapDatabaseViewChangeMove: {
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView deleteRowsAtIndexPaths:@[ rowChange.indexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
[self.tableView insertRowsAtIndexPaths:@[ rowChange.newIndexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
break;
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
case YapDatabaseViewChangeUpdate: {
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView reloadRowsAtIndexPaths:@[ rowChange.indexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView endUpdates];
|
|
|
|
}
|
2014-11-25 19:06:09 +01:00
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)checkIfEmptyView
|
|
|
|
{
|
2015-01-27 02:20:11 +01:00
|
|
|
[_tableView setHidden:NO];
|
2016-11-14 19:31:24 +01:00
|
|
|
[_emptyBoxLabel setHidden:NO];
|
2015-12-22 12:45:09 +01:00
|
|
|
if (self.viewingThreadsIn == kInboxState && [self.threadMappings numberOfItemsInGroup:TSInboxGroup] == 0) {
|
2015-01-27 21:17:49 +01:00
|
|
|
[self setEmptyBoxText];
|
2015-01-27 02:20:11 +01:00
|
|
|
[_tableView setHidden:YES];
|
2015-12-22 12:45:09 +01:00
|
|
|
} else if (self.viewingThreadsIn == kArchiveState &&
|
2017-09-06 19:59:39 +02:00
|
|
|
[self.threadMappings numberOfItemsInGroup:TSArchiveGroup] == 0) {
|
2015-01-27 21:17:49 +01:00
|
|
|
[self setEmptyBoxText];
|
2015-01-27 02:20:11 +01:00
|
|
|
[_tableView setHidden:YES];
|
2016-11-14 19:31:24 +01:00
|
|
|
} else {
|
|
|
|
[_emptyBoxLabel setHidden:YES];
|
2014-11-25 19:06:09 +01:00
|
|
|
}
|
2015-01-27 21:17:49 +01:00
|
|
|
}
|
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
- (void)setEmptyBoxText
|
|
|
|
{
|
|
|
|
_emptyBoxLabel.textColor = [UIColor grayColor];
|
|
|
|
_emptyBoxLabel.font = [UIFont ows_regularFontWithSize:18.f];
|
2015-01-27 21:17:49 +01:00
|
|
|
_emptyBoxLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
_emptyBoxLabel.numberOfLines = 4;
|
2015-12-22 12:45:09 +01:00
|
|
|
|
2017-09-06 19:59:39 +02:00
|
|
|
NSString *firstLine = @"";
|
2015-12-22 12:45:09 +01:00
|
|
|
NSString *secondLine = @"";
|
|
|
|
|
|
|
|
if (self.viewingThreadsIn == kInboxState) {
|
|
|
|
if ([Environment.preferences getHasSentAMessage]) {
|
2017-09-06 19:59:39 +02:00
|
|
|
firstLine = NSLocalizedString(@"EMPTY_INBOX_FIRST_TITLE", @"");
|
2015-02-18 23:21:03 +01:00
|
|
|
secondLine = NSLocalizedString(@"EMPTY_INBOX_FIRST_TEXT", @"");
|
2015-12-22 12:45:09 +01:00
|
|
|
} else {
|
2016-08-10 15:58:34 +02:00
|
|
|
// FIXME This looks wrong. Shouldn't we be showing inbox_title/text here?
|
2017-09-06 19:59:39 +02:00
|
|
|
firstLine = NSLocalizedString(@"EMPTY_ARCHIVE_FIRST_TITLE", @"");
|
2015-02-18 23:21:03 +01:00
|
|
|
secondLine = NSLocalizedString(@"EMPTY_ARCHIVE_FIRST_TEXT", @"");
|
2015-02-09 17:31:22 +01:00
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
} else {
|
|
|
|
if ([Environment.preferences getHasArchivedAMessage]) {
|
2016-08-10 15:58:34 +02:00
|
|
|
// FIXME This looks wrong. Shouldn't we be showing first_archive_title/text here?
|
2017-09-06 19:59:39 +02:00
|
|
|
firstLine = NSLocalizedString(@"EMPTY_INBOX_TITLE", @"");
|
2015-12-22 12:45:09 +01:00
|
|
|
secondLine = NSLocalizedString(@"EMPTY_INBOX_TEXT", @"");
|
|
|
|
} else {
|
2017-09-06 19:59:39 +02:00
|
|
|
firstLine = NSLocalizedString(@"EMPTY_ARCHIVE_TITLE", @"");
|
2015-12-22 12:45:09 +01:00
|
|
|
secondLine = NSLocalizedString(@"EMPTY_ARCHIVE_TEXT", @"");
|
2015-02-09 17:31:22 +01:00
|
|
|
}
|
2015-01-27 21:17:49 +01:00
|
|
|
}
|
2015-12-22 12:45:09 +01:00
|
|
|
NSMutableAttributedString *fullLabelString =
|
|
|
|
[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@", firstLine, secondLine]];
|
|
|
|
|
|
|
|
[fullLabelString addAttribute:NSFontAttributeName
|
|
|
|
value:[UIFont ows_boldFontWithSize:15.f]
|
|
|
|
range:NSMakeRange(0, firstLine.length)];
|
|
|
|
[fullLabelString addAttribute:NSFontAttributeName
|
|
|
|
value:[UIFont ows_regularFontWithSize:14.f]
|
|
|
|
range:NSMakeRange(firstLine.length + 1, secondLine.length)];
|
|
|
|
[fullLabelString addAttribute:NSForegroundColorAttributeName
|
|
|
|
value:[UIColor blackColor]
|
|
|
|
range:NSMakeRange(0, firstLine.length)];
|
|
|
|
[fullLabelString addAttribute:NSForegroundColorAttributeName
|
|
|
|
value:[UIColor ows_darkGrayColor]
|
|
|
|
range:NSMakeRange(firstLine.length + 1, secondLine.length)];
|
2015-01-27 21:17:49 +01:00
|
|
|
_emptyBoxLabel.attributedText = fullLabelString;
|
2014-11-25 19:06:09 +01:00
|
|
|
}
|
|
|
|
|
2016-10-10 22:02:09 +02:00
|
|
|
#pragma mark - Logging
|
|
|
|
|
|
|
|
+ (NSString *)tag
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tag
|
|
|
|
{
|
|
|
|
return self.class.tag;
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
@end
|