From f0582739cc307fc6b19d8d1730e11770f52b69d2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 31 Aug 2020 21:39:36 -0400 Subject: [PATCH] Re-add Compose button to Profile screen Add menu with Direct Message option --- .../Profile/ProfileViewController.swift | 26 +++++++++++++++++++ Tusker/TuskerNavigationDelegate.swift | 8 ++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Tusker/Screens/Profile/ProfileViewController.swift b/Tusker/Screens/Profile/ProfileViewController.swift index 512863b2..ea867438 100644 --- a/Tusker/Screens/Profile/ProfileViewController.swift +++ b/Tusker/Screens/Profile/ProfileViewController.swift @@ -58,6 +58,16 @@ class ProfileViewController: UIPageViewController { view.backgroundColor = .systemBackground + let composeButton = UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(composeMentioning)) + if #available(iOS 14.0, *) { + composeButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: [ + UIAction(title: "Direct Message", image: UIImage(systemName: Status.Visibility.direct.unfilledImageName), identifier: nil, discoverabilityTitle: nil, attributes: [], state: .off, handler: { (_) in + self.composeDirectMentioning() + }) + ]) + } + navigationItem.rightBarButtonItem = composeButton + headerView = ProfileHeaderView.create() headerView.delegate = self @@ -161,6 +171,22 @@ class ProfileViewController: UIPageViewController { } } } + + // MARK: Interaction + + @objc private func composeMentioning() { + if let account = mastodonController.persistentContainer.account(for: accountID) { + compose(mentioningAcct: account.acct) + } + } + + private func composeDirectMentioning() { + if let account = mastodonController.persistentContainer.account(for: accountID) { + let draft = mastodonController.createDraft(mentioningAcct: account.acct) + draft.visibility = .direct + compose(editing: draft) + } + } } diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index 53ddd455..bb9f4583 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -79,8 +79,7 @@ extension TuskerNavigationDelegate { show(ConversationTableViewController(for: statusID, state: state, mastodonController: apiController), sender: self) } - func compose(inReplyToID: String? = nil, mentioningAcct: String? = nil) { - let draft = apiController.createDraft(inReplyToID: inReplyToID, mentioningAcct: mentioningAcct) + func compose(editing draft: Draft) { let compose = ComposeHostingController(draft: draft, mastodonController: apiController) let vc = UINavigationController(rootViewController: compose) @@ -88,6 +87,11 @@ extension TuskerNavigationDelegate { present(vc, animated: true) } + func compose(inReplyToID: String? = nil, mentioningAcct: String? = nil) { + let draft = apiController.createDraft(inReplyToID: inReplyToID, mentioningAcct: mentioningAcct) + compose(editing: draft) + } + func loadingLargeImage(url: URL, cache: ImageCache, description: String?, animatingFrom sourceView: UIImageView) -> LoadingLargeImageViewController { let vc = LoadingLargeImageViewController(url: url, cache: cache, imageDescription: description) vc.animationSourceView = sourceView