From 05cc3fd6d97af9c0348578ee876fde257dfeb1bf Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 4 Jan 2020 19:31:35 -0500 Subject: [PATCH] Add pinning/unpinning statuses Closes #69 --- Tusker.xcodeproj/project.pbxproj | 8 ++++ .../Status Activities/PinStatusActivity.swift | 39 +++++++++++++++++++ .../UnpinStatusActivity.swift | 39 +++++++++++++++++++ Tusker/Activities/UIActivity+Types.swift | 4 +- Tusker/TuskerNavigationDelegate.swift | 5 +++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 Tusker/Activities/Status Activities/PinStatusActivity.swift create mode 100644 Tusker/Activities/Status Activities/UnpinStatusActivity.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 2a4fb9bd..beec2813 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -114,6 +114,8 @@ D646C958213B367000269FB5 /* LargeImageShrinkAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C957213B367000269FB5 /* LargeImageShrinkAnimationController.swift */; }; D646C95A213B5D0500269FB5 /* LargeImageInteractionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C959213B5D0500269FB5 /* LargeImageInteractionController.swift */; }; D64BC18623C1253A000D0238 /* AssetPreviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64BC18523C1253A000D0238 /* AssetPreviewViewController.swift */; }; + D64BC18823C1640A000D0238 /* PinStatusActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64BC18723C1640A000D0238 /* PinStatusActivity.swift */; }; + D64BC18A23C16487000D0238 /* UnpinStatusActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64BC18923C16487000D0238 /* UnpinStatusActivity.swift */; }; D64D0AAD2128D88B005A6F37 /* LocalData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64D0AAC2128D88B005A6F37 /* LocalData.swift */; }; D64D0AB12128D9AE005A6F37 /* OnboardingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64D0AB02128D9AE005A6F37 /* OnboardingViewController.swift */; }; D64F80E2215875CC00BEF393 /* XCBActionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64F80E1215875CC00BEF393 /* XCBActionType.swift */; }; @@ -380,6 +382,8 @@ D646C957213B367000269FB5 /* LargeImageShrinkAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageShrinkAnimationController.swift; sourceTree = ""; }; D646C959213B5D0500269FB5 /* LargeImageInteractionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageInteractionController.swift; sourceTree = ""; }; D64BC18523C1253A000D0238 /* AssetPreviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetPreviewViewController.swift; sourceTree = ""; }; + D64BC18723C1640A000D0238 /* PinStatusActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinStatusActivity.swift; sourceTree = ""; }; + D64BC18923C16487000D0238 /* UnpinStatusActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnpinStatusActivity.swift; sourceTree = ""; }; D64D0AAC2128D88B005A6F37 /* LocalData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalData.swift; sourceTree = ""; }; D64D0AB02128D9AE005A6F37 /* OnboardingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewController.swift; sourceTree = ""; }; D64F80E1215875CC00BEF393 /* XCBActionType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCBActionType.swift; sourceTree = ""; }; @@ -703,6 +707,8 @@ D627943423A5525100D38C68 /* StatusActivity.swift */, D627943623A552C200D38C68 /* BookmarkStatusActivity.swift */, D627943823A553B600D38C68 /* UnbookmarkStatusActivity.swift */, + D64BC18723C1640A000D0238 /* PinStatusActivity.swift */, + D64BC18923C16487000D0238 /* UnpinStatusActivity.swift */, ); path = "Status Activities"; sourceTree = ""; @@ -1633,6 +1639,7 @@ D62D2424217ABF3F005076CC /* NSUserActivity+Extensions.swift in Sources */, D646C958213B367000269FB5 /* LargeImageShrinkAnimationController.swift in Sources */, D6A3BC852321F6C100FD64D5 /* AccountListTableViewController.swift in Sources */, + D64BC18823C1640A000D0238 /* PinStatusActivity.swift in Sources */, D6674AEA23341F7600E8DF94 /* AppShortcutItems.swift in Sources */, D646C956213B365700269FB5 /* LargeImageExpandAnimationController.swift in Sources */, 0454DDB122B467AA00B8BB8E /* GalleryShrinkAnimationController.swift in Sources */, @@ -1702,6 +1709,7 @@ D667E5EB21349EF80057A976 /* ProfileHeaderTableViewCell.swift in Sources */, 04D14BB022B34A2800642648 /* GalleryViewController.swift in Sources */, D641C773213CAA25004B4513 /* NotificationsTableViewController.swift in Sources */, + D64BC18A23C16487000D0238 /* UnpinStatusActivity.swift in Sources */, D6757A7C2157E01900721E32 /* XCBManager.swift in Sources */, D6F1F84D2193B56E00F5FE67 /* Cache.swift in Sources */, 0427037C22B316B9000D31B6 /* SilentActionPrefs.swift in Sources */, diff --git a/Tusker/Activities/Status Activities/PinStatusActivity.swift b/Tusker/Activities/Status Activities/PinStatusActivity.swift new file mode 100644 index 00000000..66c56c10 --- /dev/null +++ b/Tusker/Activities/Status Activities/PinStatusActivity.swift @@ -0,0 +1,39 @@ +// +// PinStatusActivity.swift +// Tusker +// +// Created by Shadowfacts on 1/4/20. +// Copyright © 2020 Shadowfacts. All rights reserved. +// + +import UIKit +import Pachyderm + +class PinStatusActivity: StatusActivity { + override var activityType: UIActivity.ActivityType? { + return .pinStatus + } + + override var activityTitle: String? { + return NSLocalizedString("Pin", comment: "pin status activity title") + } + + override var activityImage: UIImage? { + return UIImage(systemName: "pin") + } + + override func perform() { + guard let status = status else { return } + + let request = Status.pin(status) + MastodonController.client.run(request) { (response) in + if case let .success(status, _) = response { + MastodonCache.add(status: status) + } else { + // todo: display error message + UINotificationFeedbackGenerator().notificationOccurred(.error) + fatalError() + } + } + } +} diff --git a/Tusker/Activities/Status Activities/UnpinStatusActivity.swift b/Tusker/Activities/Status Activities/UnpinStatusActivity.swift new file mode 100644 index 00000000..2fc2fa85 --- /dev/null +++ b/Tusker/Activities/Status Activities/UnpinStatusActivity.swift @@ -0,0 +1,39 @@ +// +// UnpinStatusActivity.swift +// Tusker +// +// Created by Shadowfacts on 1/4/20. +// Copyright © 2020 Shadowfacts. All rights reserved. +// + +import UIKit +import Pachyderm + +class UnpinStatusActivity: StatusActivity { + override var activityType: UIActivity.ActivityType? { + return .unpinStatus + } + + override var activityTitle: String? { + return NSLocalizedString("Unpin", comment: "unpin status activity title") + } + + override var activityImage: UIImage? { + return UIImage(systemName: "pin.slash") + } + + override func perform() { + guard let status = status else { return } + + let request = Status.unpin(status) + MastodonController.client.run(request) { (response) in + if case let .success(status, _) = response { + MastodonCache.add(status: status) + } else { + // todo: display error message + UINotificationFeedbackGenerator().notificationOccurred(.error) + fatalError() + } + } + } +} diff --git a/Tusker/Activities/UIActivity+Types.swift b/Tusker/Activities/UIActivity+Types.swift index 86b12d23..16a76940 100644 --- a/Tusker/Activities/UIActivity+Types.swift +++ b/Tusker/Activities/UIActivity+Types.swift @@ -20,5 +20,7 @@ extension UIActivity.ActivityType { // Status static let bookmarkStatus = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).bookmark_status") static let unbookmarkStatus = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unbookmark_status") - + static let pinStatus = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).pin_status") + static let unpinStatus = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unpin_status") + } diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index d8aacef1..a62072b2 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -200,6 +200,11 @@ extension TuskerNavigationDelegate where Self: UIViewController { customActivites.insert(bookmarked ? UnbookmarkStatusActivity() : BookmarkStatusActivity(), at: 0) } + if status.account == MastodonController.account, + let pinned = status.pinned { + customActivites.insert(pinned ? UnpinStatusActivity() : PinStatusActivity(), at: 1) + } + let activityController = UIActivityViewController(activityItems: [url, status], applicationActivities: customActivites) activityController.completionWithItemsHandler = OpenInSafariActivity.completionHandler(viewController: self, url: url) return activityController