Remove `contactShare` state from ContactShareViewHelper

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 0265787dd6
commit 77bbbad70c

@ -17,14 +17,12 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
weak var delegate: ContactShareViewHelperDelegate?
let contactShare: ContactShareViewModel
let contactsManager: OWSContactsManager
weak var fromViewController: UIViewController?
public required init(contactShare: ContactShareViewModel, contactsManager: OWSContactsManager, fromViewController: UIViewController, delegate: ContactShareViewHelperDelegate) {
public required init(contactsManager: OWSContactsManager, fromViewController: UIViewController, delegate: ContactShareViewHelperDelegate) {
SwiftAssertIsOnMainThread(#function)
self.contactShare = contactShare
self.contactsManager = contactsManager
self.fromViewController = fromViewController
self.delegate = delegate
@ -35,27 +33,27 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
// MARK: Actions
@objc
public func sendMessageToContact() {
public func sendMessage(contactShare: ContactShareViewModel) {
Logger.info("\(logTag) \(#function)")
presentThreadAndPeform(action: .compose)
presentThreadAndPeform(action: .compose, contactShare: contactShare)
}
@objc
public func audioCallToContact() {
public func audioCall(contactShare: ContactShareViewModel) {
Logger.info("\(logTag) \(#function)")
presentThreadAndPeform(action: .audioCall)
presentThreadAndPeform(action: .audioCall, contactShare: contactShare)
}
@objc
public func videoCallToContact() {
public func videoCall(contactShare: ContactShareViewModel) {
Logger.info("\(logTag) \(#function)")
presentThreadAndPeform(action: .videoCall)
presentThreadAndPeform(action: .videoCall, contactShare: contactShare)
}
private func presentThreadAndPeform(action: ConversationViewAction) {
private func presentThreadAndPeform(action: ConversationViewAction, contactShare: ContactShareViewModel) {
// TODO: We're taking the first Signal account id. We might
// want to let the user select if there's more than one.
let phoneNumbers = contactShare.systemContactsWithSignalAccountPhoneNumbers(contactsManager)
@ -75,7 +73,7 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
}
@objc
public func inviteContact() {
public func inviteContact(contactShare: ContactShareViewModel) {
Logger.info("\(logTag) \(#function)")
guard let fromViewController = fromViewController else {
@ -99,7 +97,7 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
inviteFlow.sendSMSTo(phoneNumbers: phoneNumbers)
}
func addToContacts() {
func addToContacts(contactShare: ContactShareViewModel) {
Logger.info("\(logTag) \(#function)")
guard let fromViewController = fromViewController else {
@ -112,12 +110,12 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
actionSheet.addAction(UIAlertAction(title: NSLocalizedString("CONVERSATION_SETTINGS_NEW_CONTACT",
comment: "Label for 'new contact' button in conversation settings view."),
style: .default) { _ in
self.didPressCreateNewContact()
self.didPressCreateNewContact(contactShare: contactShare)
})
actionSheet.addAction(UIAlertAction(title: NSLocalizedString("CONVERSATION_SETTINGS_ADD_TO_EXISTING_CONTACT",
comment: "Label for 'new contact' button in conversation settings view."),
style: .default) { _ in
self.didPressAddToExistingContact()
self.didPressAddToExistingContact(contactShare: contactShare)
})
actionSheet.addAction(OWSAlerts.cancelAction)
@ -144,21 +142,21 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
fromViewController.present(actionSheet, animated: true)
}
func didPressCreateNewContact() {
func didPressCreateNewContact(contactShare: ContactShareViewModel) {
Logger.info("\(logTag) \(#function)")
presentNewContactView()
presentNewContactView(contactShare: contactShare)
}
func didPressAddToExistingContact() {
func didPressAddToExistingContact(contactShare: ContactShareViewModel) {
Logger.info("\(logTag) \(#function)")
presentSelectAddToExistingContactView()
presentSelectAddToExistingContactView(contactShare: contactShare)
}
// MARK: -
private func presentNewContactView() {
private func presentNewContactView(contactShare: ContactShareViewModel) {
guard let fromViewController = fromViewController else {
owsFail("\(logTag) missing fromViewController")
@ -203,7 +201,7 @@ public class ContactShareViewHelper: NSObject, CNContactViewControllerDelegate {
UIUtil.applyDefaultSystemAppearence()
}
private func presentSelectAddToExistingContactView() {
private func presentSelectAddToExistingContactView(contactShare: ContactShareViewModel) {
guard let fromViewController = fromViewController else {
owsFail("\(logTag) missing fromViewController")

@ -52,7 +52,7 @@ class ContactViewController: OWSViewController, ContactShareViewHelperDelegate {
super.init(nibName: nil, bundle: nil)
self.helper = ContactShareViewHelper(contactShare: contactShare, contactsManager: contactsManager, fromViewController: self, delegate: self)
self.helper = ContactShareViewHelper(contactsManager: contactsManager, fromViewController: self, delegate: self)
updateMode()
@ -478,31 +478,31 @@ class ContactViewController: OWSViewController, ContactShareViewHelperDelegate {
func didPressSendMessage() {
Logger.info("\(logTag) \(#function)")
self.helper.sendMessageToContact()
self.helper.sendMessage(contactShare: self.contactShare)
}
func didPressAudioCall() {
Logger.info("\(logTag) \(#function)")
self.helper.audioCallToContact()
self.helper.audioCall(contactShare: self.contactShare)
}
func didPressVideoCall() {
Logger.info("\(logTag) \(#function)")
self.helper.videoCallToContact()
self.helper.videoCall(contactShare: self.contactShare)
}
func didPressInvite() {
Logger.info("\(logTag) \(#function)")
self.helper.inviteContact()
self.helper.inviteContact(contactShare: self.contactShare)
}
func didPressAddToContacts() {
Logger.info("\(logTag) \(#function)")
self.helper.addToContacts()
self.helper.addToContacts(contactShare: self.contactShare)
}
func didPressDismiss() {

@ -276,6 +276,10 @@ typedef enum : NSUInteger {
_networkManager = [TSNetworkManager sharedManager];
_blockingManager = [OWSBlockingManager sharedManager];
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
_contactShareViewHelper = [[ContactShareViewHelper alloc] initWithContactsManager:self.contactsManager
fromViewController:self
delegate:self];
NSString *audioActivityDescription = [NSString stringWithFormat:@"%@ voice note", self.logTag];
_voiceNoteAudioActivity = [[AudioActivity alloc] initWithAudioDescription:audioActivityDescription];
}
@ -2113,11 +2117,7 @@ typedef enum : NSUInteger {
OWSAssertIsOnMainThread();
OWSAssert(contactShare);
self.contactShareViewHelper = [[ContactShareViewHelper alloc] initWithContactShare:contactShare
contactsManager:self.contactsManager
fromViewController:self
delegate:self];
[self.contactShareViewHelper sendMessageToContact];
[self.contactShareViewHelper sendMessageWithContactShare:contactShare];
}
- (void)didTapSendInviteToContactShare:(ContactShareViewModel *)contactShare
@ -2125,11 +2125,7 @@ typedef enum : NSUInteger {
OWSAssertIsOnMainThread();
OWSAssert(contactShare);
self.contactShareViewHelper = [[ContactShareViewHelper alloc] initWithContactShare:contactShare
contactsManager:self.contactsManager
fromViewController:self
delegate:self];
[self.contactShareViewHelper inviteContact];
[self.contactShareViewHelper inviteContactWithContactShare:contactShare];
}
- (void)didTapShowAddToContactUIForContactShare:(ContactShareViewModel *)contactShare
@ -2137,11 +2133,7 @@ typedef enum : NSUInteger {
OWSAssertIsOnMainThread();
OWSAssert(contactShare);
self.contactShareViewHelper = [[ContactShareViewHelper alloc] initWithContactShare:contactShare
contactsManager:self.contactsManager
fromViewController:self
delegate:self];
[self.contactShareViewHelper addToContacts];
[self.contactShareViewHelper addToContactsWithContactShare:contactShare];
}
- (void)didTapFailedIncomingAttachment:(ConversationViewItem *)viewItem

@ -624,27 +624,25 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
}
func didTapSendMessage(toContactShare contactShare: ContactShareViewModel) {
contactShareViewHelper = ContactShareViewHelper(contactShare: contactShare,
contactsManager: contactsManager,
contactShareViewHelper = ContactShareViewHelper(contactsManager: contactsManager,
fromViewController: self,
delegate: self)
contactShareViewHelper?.sendMessageToContact()
contactShareViewHelper?.sendMessage(contactShare: contactShare)
}
func didTapSendInvite(toContactShare contactShare: ContactShareViewModel) {
contactShareViewHelper = ContactShareViewHelper(contactShare: contactShare,
contactsManager: contactsManager,
contactShareViewHelper = ContactShareViewHelper(contactsManager: contactsManager,
fromViewController: self,
delegate: self)
contactShareViewHelper?.inviteContact()
contactShareViewHelper?.inviteContact(contactShare: contactShare)
}
func didTapShowAddToContactUI(forContactShare contactShare: ContactShareViewModel) {
contactShareViewHelper = ContactShareViewHelper(contactShare: contactShare,
contactsManager: contactsManager,
contactShareViewHelper = ContactShareViewHelper(contactsManager: contactsManager,
fromViewController: self,
delegate: self)
contactShareViewHelper?.addToContacts()
contactShareViewHelper?.addToContacts(contactShare: contactShare)
}
var audioAttachmentPlayer: OWSAudioPlayer?

Loading…
Cancel
Save