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

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

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

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

Loading…
Cancel
Save