Invite Flow when "no contact"

TODO: we should probably just prevent people from getting to the invite
flow when their contacts aren't shared, but still it seems good to fix
these crashes.

// FREEBIE
This commit is contained in:
Michael Kirk 2017-05-05 17:34:37 -04:00
parent 40dead89e5
commit bf5b6d1e63
3 changed files with 32 additions and 18 deletions

View File

@ -145,20 +145,27 @@ open class ContactsPicker: UIViewController, UITableViewDelegate, UITableViewDat
func getContacts(onError errorHandler: @escaping (_ error: Error) -> Void) {
switch CNContactStore.authorizationStatus(for: CNEntityType.contacts) {
case CNAuthorizationStatus.denied, CNAuthorizationStatus.restricted:
let title = NSLocalizedString("INVITE_FLOW_REQUIRES_CONTACT_ACCESS_TITLE", comment: "Alert title when contacts disabled while trying to invite contacts to signal")
let body = NSLocalizedString("INVITE_FLOW_REQUIRES_CONTACT_ACCESS_BODY", comment: "Alert body when contacts disabled while trying to invite contacts to signal")
let title = NSLocalizedString("AB_PERMISSION_MISSING_TITLE", comment: "Alert title when contacts disabled")
let body = NSLocalizedString("ADDRESSBOOK_RESTRICTED_ALERT_BODY", comment: "Alert body when contacts disabled")
let alert = UIAlertController(title: title, message: body, preferredStyle: UIAlertControllerStyle.alert)
let dismissText = NSLocalizedString("DISMISS_BUTTON_TEXT", comment:"")
let dismissText = NSLocalizedString("TXT_CANCEL_TITLE", comment:"")
let okAction = UIAlertAction(title: dismissText, style: UIAlertActionStyle.default, handler: { _ in
let cancelAction = UIAlertAction(title: dismissText, style: .cancel, handler: { _ in
let error = NSError(domain: "contactsPickerErrorDomain", code: 1, userInfo: [NSLocalizedDescriptionKey: "No Contacts Access"])
self.contactsPickerDelegate?.contactsPicker(self, didContactFetchFailed: error)
errorHandler(error)
self.dismiss(animated: true, completion: nil)
})
alert.addAction(okAction)
alert.addAction(cancelAction)
let settingsText = NSLocalizedString("OPEN_SETTINGS_BUTTON", comment:"Button text which opens the settings app")
let openSettingsAction = UIAlertAction(title: settingsText, style: .default, handler: { (_) in
UIApplication.shared.openSystemSettings()
})
alert.addAction(openSettingsAction)
self.present(alert, animated: true, completion: nil)
case CNAuthorizationStatus.notDetermined:
@ -208,6 +215,10 @@ open class ContactsPicker: UIViewController, UITableViewDelegate, UITableViewDat
open func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let dataSource = filteredSections
guard section < dataSource.count else {
return 0
}
return dataSource[section].count
}
@ -274,15 +285,15 @@ open class ContactsPicker: UIViewController, UITableViewDelegate, UITableViewDat
open func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let dataSource = filteredSections
guard dataSource.count >= section else {
guard section < dataSource.count else {
return nil
}
if dataSource[section].count > 0 {
guard collation.sectionTitles.count >= section else {
guard section < collation.sectionTitles.count else {
return nil
}
return collation.sectionTitles[section]
} else {
return nil

View File

@ -151,7 +151,7 @@ NS_ASSUME_NONNULL_BEGIN
UIButton *inviteContactsButton = [UIButton buttonWithType:UIButtonTypeCustom];
[inviteContactsButton setTitle:NSLocalizedString(@"INVITE_FRIENDS_CONTACT_TABLE_BUTTON",
"Text for button at the top of the contact picker")
"Label for the cell that presents the 'invite contacts' workflow.")
forState:UIControlStateNormal];
[inviteContactsButton setTitleColor:[UIColor ows_materialBlueColor] forState:UIControlStateNormal];
[inviteContactsButton.titleLabel setFont:[UIFont ows_regularFontWithSize:17.f]];
@ -420,6 +420,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)showNoContactsModeIfNecessary
{
if (!self.contactsViewHelper.contactsManager.isSystemContactsAuthorized) {
return;
}
BOOL hasNoContacts = self.contactsViewHelper.signalAccounts.count < 1;
self.isNoContactsModeActive = (hasNoContacts && ![[Environment preferences] hasDeclinedNoContactsView]);
}

View File

@ -1,9 +1,6 @@
/* Button text to dismiss missing contacts permission alert */
"AB_PERMISSION_MISSING_ACTION_NOT_NOW" = "Not Now";
/* Alert title when contacts disabled */
"AB_PERMISSION_MISSING_TITLE" = "Sorry!";
/* Action sheet item */
"ACCEPT_NEW_IDENTITY_ACTION" = "Accept new safety number";
@ -22,9 +19,6 @@
/* Title for the 'add group member' view. */
"ADD_GROUP_MEMBER_VIEW_TITLE" = "Add Member";
/* Alert body when contacts disabled */
"ADDRESSBOOK_RESTRICTED_ALERT_BODY" = "Signal requires access to your contacts. Access to contacts is restricted. Signal will close. You can disable the restriction temporarily to let Signal access your contacts by going the Settings app >> General >> Restrictions >> Contacts >> Allow Changes.";
/* The label for the 'discard' button in alerts and action sheets. */
"ALERT_DISCARD_BUTTON" = "Discard";
@ -580,8 +574,13 @@
/* No comment provided by engineer. */
"INCOMING_INCOMPLETE_CALL" = "Incomplete incoming call from";
/* Label for the cell that presents the 'invite contacts' workflow.
Text for button at the top of the contact picker */
/* Alert body when contacts disabled while trying to invite contacts to signal */
"INVITE_FLOW_REQUIRES_CONTACT_ACCESS_BODY" = "To invite your contacts, you need to allow Signal access to your contacts in the Settings app.";
/* Alert title when contacts disabled while trying to invite contacts to signal */
"INVITE_FLOW_REQUIRES_CONTACT_ACCESS_TITLE" = "Enable Contact Access";
/* Label for the cell that presents the 'invite contacts' workflow. */
"INVITE_FRIENDS_CONTACT_TABLE_BUTTON" = "Invite Friends to Signal";
/* Search */