Update “new 1:1 conversation” view.
* Don’t hide blocked users. If selected, user needs to unblock to start conversation. * Add “you have no contacts” indicator. * Activate “block state indicator” in contact cell. // FREEBIE
This commit is contained in:
parent
8867b2882e
commit
b5562fa126
|
@ -3,9 +3,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#import "MessageComposeTableViewController.h"
|
#import "MessageComposeTableViewController.h"
|
||||||
|
#import "BlockListUIUtils.h"
|
||||||
#import <MessageUI/MessageUI.h>
|
|
||||||
|
|
||||||
#import "ContactTableViewCell.h"
|
#import "ContactTableViewCell.h"
|
||||||
#import "ContactsUpdater.h"
|
#import "ContactsUpdater.h"
|
||||||
#import "Environment.h"
|
#import "Environment.h"
|
||||||
|
@ -13,6 +11,7 @@
|
||||||
#import "Signal-Swift.h"
|
#import "Signal-Swift.h"
|
||||||
#import "UIColor+OWS.h"
|
#import "UIColor+OWS.h"
|
||||||
#import "UIUtil.h"
|
#import "UIUtil.h"
|
||||||
|
#import <MessageUI/MessageUI.h>
|
||||||
#import <SignalServiceKit/OWSBlockingManager.h>
|
#import <SignalServiceKit/OWSBlockingManager.h>
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
@ -536,6 +535,11 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
|
||||||
: MessageComposeTableViewControllerSection_Count);
|
: MessageComposeTableViewControllerSection_Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)hasNoContacts
|
||||||
|
{
|
||||||
|
return self.contacts.count == 0;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||||
// This logic will determine which one (if any) of the following special controls
|
// This logic will determine which one (if any) of the following special controls
|
||||||
// should be shown. No more than one should be shown at a time.
|
// should be shown. No more than one should be shown at a time.
|
||||||
|
@ -566,6 +570,9 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
|
||||||
if (self.searchController.active) {
|
if (self.searchController.active) {
|
||||||
return (NSInteger)[self.searchResults count];
|
return (NSInteger)[self.searchResults count];
|
||||||
} else {
|
} else {
|
||||||
|
if (self.hasNoContacts) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return (NSInteger)[self.contacts count];
|
return (NSInteger)[self.contacts count];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -599,11 +606,24 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
|
||||||
return self.inviteCell;
|
return self.inviteCell;
|
||||||
} else {
|
} else {
|
||||||
OWSAssert(indexPath.section == MessageComposeTableViewControllerSectionContacts)
|
OWSAssert(indexPath.section == MessageComposeTableViewControllerSectionContacts)
|
||||||
|
|
||||||
|
if (!self.searchController.active && self.hasNoContacts)
|
||||||
|
{
|
||||||
|
UITableViewCell *cell = [UITableViewCell new];
|
||||||
|
cell.textLabel.text = NSLocalizedString(
|
||||||
|
@"SETTINGS_BLOCK_LIST_NO_CONTACTS", @"A label that indicates the user has no Signal contacts.");
|
||||||
|
cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f];
|
||||||
|
cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
|
||||||
|
cell.textLabel.textAlignment = NSTextAlignmentCenter;
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
|
||||||
ContactTableViewCell *cell = (ContactTableViewCell *)[tableView
|
ContactTableViewCell *cell = (ContactTableViewCell *)[tableView
|
||||||
dequeueReusableCellWithIdentifier:MessageComposeTableViewControllerCellContact];
|
dequeueReusableCellWithIdentifier:MessageComposeTableViewControllerCellContact];
|
||||||
|
|
||||||
[cell configureWithContact:[self contactForIndexPath:indexPath] contactsManager:self.contactsManager];
|
Contact *contact = [self contactForIndexPath:indexPath];
|
||||||
|
cell.isBlocked = [self isContactBlocked:contact];
|
||||||
|
[cell configureWithContact:contact contactsManager:self.contactsManager];
|
||||||
|
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
@ -611,6 +631,17 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
|
||||||
|
|
||||||
#pragma mark - Table View delegate
|
#pragma mark - Table View delegate
|
||||||
|
|
||||||
|
- (nullable NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||||
|
{
|
||||||
|
if (indexPath.section == MessageComposeTableViewControllerSectionContacts && !self.searchController.active
|
||||||
|
&& self.hasNoContacts) {
|
||||||
|
// Don't let user select the "you have no contacts" cell.
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexPath;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
|
|
||||||
if (indexPath.section == MessageComposeTableViewControllerSectionInviteNonContactConversation) {
|
if (indexPath.section == MessageComposeTableViewControllerSectionInviteNonContactConversation) {
|
||||||
|
@ -654,12 +685,36 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
|
||||||
} else {
|
} else {
|
||||||
OWSAssert(indexPath.section == MessageComposeTableViewControllerSectionContacts)
|
OWSAssert(indexPath.section == MessageComposeTableViewControllerSectionContacts)
|
||||||
|
|
||||||
NSString *identifier = [[[self contactForIndexPath:indexPath] textSecureIdentifiers] firstObject];
|
if (!self.searchController.active && self.hasNoContacts)
|
||||||
|
{
|
||||||
|
// TODO: We could do something here, like show the "invite contacts" UI.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
[self dismissViewControllerAnimated:YES
|
Contact *contact = [self contactForIndexPath:indexPath];
|
||||||
completion:^() {
|
NSString *contactIdentifier = [[contact textSecureIdentifiers] firstObject];
|
||||||
[Environment messageIdentifier:identifier withCompose:YES];
|
|
||||||
}];
|
__weak MessageComposeTableViewController *weakSelf = self;
|
||||||
|
void (^newContactConversationBlock)() = ^{
|
||||||
|
[weakSelf dismissViewControllerAnimated:YES
|
||||||
|
completion:^() {
|
||||||
|
[Environment messageIdentifier:contactIdentifier withCompose:YES];
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
if ([self isContactBlocked:contact]) {
|
||||||
|
[BlockListUIUtils showUnblockPhoneNumberActionSheet:contactIdentifier
|
||||||
|
fromViewController:self
|
||||||
|
blockingManager:_blockingManager
|
||||||
|
contactsManager:_contactsManager
|
||||||
|
completionBlock:^(BOOL isBlocked) {
|
||||||
|
if (!isBlocked) {
|
||||||
|
newContactConversationBlock();
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
} else {
|
||||||
|
newContactConversationBlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,13 +738,23 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
|
||||||
[self.tableView reloadData];
|
[self.tableView reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isContactBlockedOrHidden:(Contact *)contact
|
- (BOOL)isContactHidden:(Contact *)contact
|
||||||
{
|
{
|
||||||
if (contact.parsedPhoneNumbers.count < 1) {
|
if (contact.parsedPhoneNumbers.count < 1) {
|
||||||
// Hide contacts without any valid phone numbers.
|
// Hide contacts without any valid phone numbers.
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isContactBlocked:(Contact *)contact
|
||||||
|
{
|
||||||
|
if (contact.parsedPhoneNumbers.count < 1) {
|
||||||
|
// Hide contacts without any valid phone numbers.
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
for (PhoneNumber *phoneNumber in contact.parsedPhoneNumbers) {
|
for (PhoneNumber *phoneNumber in contact.parsedPhoneNumbers) {
|
||||||
if ([_blockedPhoneNumbers containsObject:phoneNumber.toE164]) {
|
if ([_blockedPhoneNumbers containsObject:phoneNumber.toE164]) {
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -703,7 +768,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
|
||||||
{
|
{
|
||||||
NSMutableArray<Contact *> *result = [NSMutableArray new];
|
NSMutableArray<Contact *> *result = [NSMutableArray new];
|
||||||
for (Contact *contact in self.contactsManager.signalContacts) {
|
for (Contact *contact in self.contactsManager.signalContacts) {
|
||||||
if (![self isContactBlockedOrHidden:contact]) {
|
if (![self isContactHidden:contact]) {
|
||||||
[result addObject:contact];
|
[result addObject:contact];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,6 @@ typedef enum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue