Skip to content

Commit

Permalink
contact us
Browse files Browse the repository at this point in the history
  • Loading branch information
kenmueller committed Jul 10, 2019
1 parent da15da2 commit 33cdcdb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions memorize.ai/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ let CURRENT_DEVICE_HAS_ROUNDED_CORNERS = Device.allDevicesWithRoundedDisplayCorn
let MEMORIZE_AI_BASE_URL = "https://memorize.ai"
let MEMORIZE_AI_SUPPORT_EMAIL = "support@memorize.ai"
let PLACEHOLDER_FIELD_VALUE = "x"
let APP_VERSION = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
33 changes: 26 additions & 7 deletions memorize.ai/Home/EditProfileViewController.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import UIKit
import SafariServices
import MessageUI

class EditProfileViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate {
class EditProfileViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate, MFMailComposeViewControllerDelegate {
@IBOutlet weak var pictureView: UIView!
@IBOutlet weak var pictureImageView: UIImageView!
@IBOutlet weak var changeButton: UIButton!
Expand Down Expand Up @@ -31,7 +32,7 @@ class EditProfileViewController: UIViewController, UINavigationControllerDelegat
Option(image: #imageLiteral(resourceName: "Decks"), name: "Deck Ratings", action: showDeckRatings),
Option(image: #imageLiteral(resourceName: "Cards"), name: "Card Ratings", action: showCardRatings),
Option(image: #imageLiteral(resourceName: "Book"), name: "Tutorial", action: showTutorial)
]
] + (MFMailComposeViewController.canSendMail() ? [Option(image: #imageLiteral(resourceName: "Mail"), name: "Contact Us", action: showContactUsEmail)] : [])

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -151,11 +152,31 @@ class EditProfileViewController: UIViewController, UINavigationControllerDelegat
performSegue(withIdentifier: "tutorial", sender: self)
}

func showContactUsEmail() {
guard MFMailComposeViewController.canSendMail() else { return showNotification("You must add an email account to this device in settings before you can send mail", type: .error) }
guard let id = id, let name = name, let email = email else { return }
let profileLink = slug == nil ? nil : User.url(slug: slug ?? "...")?.absoluteString
let mailComposeVC = MFMailComposeViewController()
mailComposeVC.delegate = self
mailComposeVC.setToRecipients([MEMORIZE_AI_SUPPORT_EMAIL])
mailComposeVC.setMessageBody("""
=== User info ===
ID: \(id)
Name: \(name)
Email: \(email)\(profileLink == nil ? "" : "\nProfile link: \(profileLink ?? "unknown")")
iOS App version: \(APP_VERSION ?? "1.0")
iOS version: \(UIDevice.current.systemVersion)
""", isHTML: false)
present(mailComposeVC, animated: true, completion: nil)
}

@IBAction
func signOut() {
let alertController = UIAlertController(title: "Sign Out", message: "Are you sure?", preferredStyle: .alert)
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let signOut = UIAlertAction(title: "Sign Out", style: .destructive) { _ in
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alertController.addAction(UIAlertAction(title: "Sign Out", style: .destructive) { _ in
if (try? auth.signOut()) == nil { return self.showNotification("Unable to sign out. Please try again", type: .error) }
Listener.removeAll()
uploads.removeAll()
Expand All @@ -169,9 +190,7 @@ class EditProfileViewController: UIViewController, UINavigationControllerDelegat
allDecks.removeAll()
User.delete()
self.performSegue(withIdentifier: "signOut", sender: self)
}
alertController.addAction(cancel)
alertController.addAction(signOut)
})
present(alertController, animated: true, completion: nil)
}

Expand Down

0 comments on commit 33cdcdb

Please sign in to comment.