Add button to start a new conversation with non-contact based on phone number in search field.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 0a95dac616
commit 3ae85ce2d8

@ -1,9 +1,5 @@
// //
// MessageComposeTableViewController.m // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
//
// Created by Dylan Bourgeois on 02/11/14.
//
// //
#import "MessageComposeTableViewController.h" #import "MessageComposeTableViewController.h"
@ -24,24 +20,30 @@ NS_ASSUME_NONNULL_BEGIN
UISearchResultsUpdating, UISearchResultsUpdating,
MFMessageComposeViewControllerDelegate> MFMessageComposeViewControllerDelegate>
@property (nonatomic, strong) IBOutlet UITableViewCell *inviteCell; @property (nonatomic) IBOutlet UITableViewCell *inviteCell;
@property (nonatomic, strong) IBOutlet OWSNoSignalContactsView *noSignalContactsView; @property (nonatomic) UITableViewCell *conversationForNonContactCell;
@property (nonatomic) IBOutlet OWSNoSignalContactsView *noSignalContactsView;
@property (nonatomic) UIButton *sendTextButton; @property (nonatomic) UIButton *sendTextButton;
@property (nonatomic, strong) UISearchController *searchController; @property (nonatomic) UISearchController *searchController;
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicator; @property (nonatomic) UIActivityIndicatorView *activityIndicator;
@property (nonatomic, strong) UIBarButtonItem *addGroup; @property (nonatomic) UIBarButtonItem *addGroup;
@property (nonatomic, strong) UIView *loadingBackgroundView; @property (nonatomic) UIView *loadingBackgroundView;
@property (nonatomic) NSString *currentSearchTerm; @property (nonatomic) NSString *currentSearchTerm;
@property (copy) NSArray<Contact *> *contacts; @property (copy) NSArray<Contact *> *contacts;
@property (copy) NSArray<Contact *> *searchResults; @property (copy) NSArray<Contact *> *searchResults;
@property (nonatomic, readonly) OWSContactsManager *contactsManager; @property (nonatomic, readonly) OWSContactsManager *contactsManager;
@property (nonatomic) BOOL showNewConversationForNonContactButton;
// This property should be set IFF showNewConversationForNonContactButton is YES.
@property (nonatomic) NSString *nonContactPhoneNumber;
@end @end
NSInteger const MessageComposeTableViewControllerSectionInvite = 0; NSInteger const MessageComposeTableViewControllerSectionInvite = 0;
NSInteger const MessageComposeTableViewControllerSectionContacts = 1; NSInteger const MessageComposeTableViewControllerSectionContacts = 1;
NSInteger const MessageComposeTableViewControllerSectionNewConversationForNonContact = 2;
NSString *const MessageComposeTableViewControllerCellInvite = @"ContactTableInviteCell"; NSString *const MessageComposeTableViewControllerCellInvite = @"ContactTableInviteCell";
NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableViewCell"; NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableViewCell";
@ -88,6 +90,8 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
self.inviteCell.textLabel.text = NSLocalizedString( self.inviteCell.textLabel.text = NSLocalizedString(
@"INVITE_FRIENDS_CONTACT_TABLE_BUTTON", @"Text for button at the top of the contact picker"); @"INVITE_FRIENDS_CONTACT_TABLE_BUTTON", @"Text for button at the top of the contact picker");
self.conversationForNonContactCell = [UITableViewCell new];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
[self createLoadingAndBackgroundViews]; [self createLoadingAndBackgroundViews];
self.title = NSLocalizedString(@"MESSAGE_COMPOSEVIEW_TITLE", @""); self.title = NSLocalizedString(@"MESSAGE_COMPOSEVIEW_TITLE", @"");
@ -201,6 +205,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
self.inviteCell.hidden = YES; self.inviteCell.hidden = YES;
self.conversationForNonContactCell.hidden = YES;
self.searchController.searchBar.hidden = YES; self.searchController.searchBar.hidden = YES;
self.tableView.backgroundView = self.noSignalContactsView; self.tableView.backgroundView = self.noSignalContactsView;
self.tableView.backgroundView.opaque = YES; self.tableView.backgroundView.opaque = YES;
@ -212,6 +217,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
self.searchController.searchBar.hidden = NO; self.searchController.searchBar.hidden = NO;
self.tableView.backgroundView = nil; self.tableView.backgroundView = nil;
self.inviteCell.hidden = NO; self.inviteCell.hidden = NO;
self.conversationForNonContactCell.hidden = NO;
} }
} }
@ -296,11 +302,24 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
[self.sendTextButton setTitle:sendTextTo forState:UIControlStateNormal]; [self.sendTextButton setTitle:sendTextTo forState:UIControlStateNormal];
self.sendTextButton.hidden = NO; self.sendTextButton.hidden = NO;
self.currentSearchTerm = formattedNumber; self.currentSearchTerm = formattedNumber;
self.showNewConversationForNonContactButton = YES;
self.nonContactPhoneNumber = formattedNumber;
} else { } else {
self.sendTextButton.hidden = YES; self.sendTextButton.hidden = YES;
self.showNewConversationForNonContactButton = NO;
_nonContactPhoneNumber = nil;
} }
} }
- (void)setShowNewConversationForNonContactButton:(BOOL)showNewConversationForNonContactButton {
if (_showNewConversationForNonContactButton == showNewConversationForNonContactButton) {
return;
}
_showNewConversationForNonContactButton = showNewConversationForNonContactButton;
[self.tableView reloadData];
}
#pragma mark - Send Normal Text to Unknown Contact #pragma mark - Send Normal Text to Unknown Contact
@ -407,7 +426,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
#pragma mark - Table View Data Source #pragma mark - Table View Data Source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2; return 4;
} }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@ -417,6 +436,8 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
return 0; return 0;
} }
return 1; return 1;
} else if (section == MessageComposeTableViewControllerSectionNewConversationForNonContact) {
return _showNewConversationForNonContactButton ? 1 : 0;
} else { } else {
if (self.searchController.active) { if (self.searchController.active) {
return (NSInteger)[self.searchResults count]; return (NSInteger)[self.searchResults count];
@ -430,6 +451,13 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
{ {
if (indexPath.section == MessageComposeTableViewControllerSectionInvite) { if (indexPath.section == MessageComposeTableViewControllerSectionInvite) {
return self.inviteCell; return self.inviteCell;
} else if (indexPath.section == MessageComposeTableViewControllerSectionNewConversationForNonContact) {
OWSAssert(self.nonContactPhoneNumber.length > 0);
self.conversationForNonContactCell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"NEW_CONVERSATION_FOR_NON_CONTACT_FORMAT",
@"Text for button to start a new conversation with a non-contact"),
self.nonContactPhoneNumber];
return self.conversationForNonContactCell;
} else { } else {
ContactTableViewCell *cell = (ContactTableViewCell *)[tableView ContactTableViewCell *cell = (ContactTableViewCell *)[tableView
dequeueReusableCellWithIdentifier:MessageComposeTableViewControllerCellContact]; dequeueReusableCellWithIdentifier:MessageComposeTableViewControllerCellContact];
@ -461,6 +489,15 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
} else { } else {
showInvite(); showInvite();
} }
} else if (indexPath.section == MessageComposeTableViewControllerSectionNewConversationForNonContact) {
OWSAssert(self.nonContactPhoneNumber.length > 0);
if (self.nonContactPhoneNumber.length > 0) {
[self dismissViewControllerAnimated:YES
completion:^() {
[Environment messageIdentifier:self.nonContactPhoneNumber withCompose:YES];
}];
}
} else { } else {
NSString *identifier = [[[self contactForIndexPath:indexPath] textSecureIdentifiers] firstObject]; NSString *identifier = [[[self contactForIndexPath:indexPath] textSecureIdentifiers] firstObject];

@ -489,6 +489,9 @@
/* No comment provided by engineer. */ /* No comment provided by engineer. */
"NETWORK_STATUS_TEXT" = "You can check your network status by looking at the colored bar above your inbox."; "NETWORK_STATUS_TEXT" = "You can check your network status by looking at the colored bar above your inbox.";
/* Text for button to start a new conversation with a non-contact */
"NEW_CONVERSATION_FOR_NON_CONTACT_FORMAT" = "New conversation with %@";
/* Action Sheet title prompting the user for a group avatar */ /* Action Sheet title prompting the user for a group avatar */
"NEW_GROUP_ADD_PHOTO_ACTION" = "Set Group Photo"; "NEW_GROUP_ADD_PHOTO_ACTION" = "Set Group Photo";

Loading…
Cancel
Save