From ce464dfb9f5628baeb14d504bd0395c6056f4485 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 14 May 2020 22:00:58 -0400 Subject: [PATCH] Add mute/unmute conversation status activities Closes #70 --- Tusker.xcodeproj/project.pbxproj | 8 ++++ .../MuteConversationActivity.swift | 40 +++++++++++++++++++ .../UnmuteConversationActivity.swift | 40 +++++++++++++++++++ Tusker/Activities/UIActivity+Types.swift | 2 + Tusker/TuskerNavigationDelegate.swift | 10 +++-- 5 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 Tusker/Activities/Status Activities/MuteConversationActivity.swift create mode 100644 Tusker/Activities/Status Activities/UnmuteConversationActivity.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 2a4aaf9a..c1af2a33 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -168,6 +168,8 @@ D67C57B421E2910700C3118B /* ComposeStatusReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D67C57B321E2910700C3118B /* ComposeStatusReplyView.swift */; }; D68015402401A6BA00D6103B /* ComposingPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D680153F2401A6BA00D6103B /* ComposingPrefsView.swift */; }; D68015422401A74600D6103B /* MediaPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68015412401A74600D6103B /* MediaPrefsView.swift */; }; + D681E4D3246E2AFF0053414F /* MuteConversationActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D681E4D2246E2AFF0053414F /* MuteConversationActivity.swift */; }; + D681E4D5246E2BC30053414F /* UnmuteConversationActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D681E4D4246E2BC30053414F /* UnmuteConversationActivity.swift */; }; D68232F72464F4FD00325FB8 /* ComposeDrawingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68232F62464F4FD00325FB8 /* ComposeDrawingViewController.swift */; }; D68FEC4F232C5BC300C84F23 /* SegmentedPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68FEC4E232C5BC300C84F23 /* SegmentedPageViewController.swift */; }; D693DE5723FE1A6A0061E07D /* EnhancedNavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D693DE5623FE1A6A0061E07D /* EnhancedNavigationViewController.swift */; }; @@ -467,6 +469,8 @@ D67C57B321E2910700C3118B /* ComposeStatusReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeStatusReplyView.swift; sourceTree = ""; }; D680153F2401A6BA00D6103B /* ComposingPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposingPrefsView.swift; sourceTree = ""; }; D68015412401A74600D6103B /* MediaPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPrefsView.swift; sourceTree = ""; }; + D681E4D2246E2AFF0053414F /* MuteConversationActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MuteConversationActivity.swift; sourceTree = ""; }; + D681E4D4246E2BC30053414F /* UnmuteConversationActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnmuteConversationActivity.swift; sourceTree = ""; }; D68232F62464F4FD00325FB8 /* ComposeDrawingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeDrawingViewController.swift; sourceTree = ""; }; D68FEC4E232C5BC300C84F23 /* SegmentedPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedPageViewController.swift; sourceTree = ""; }; D693DE5623FE1A6A0061E07D /* EnhancedNavigationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnhancedNavigationViewController.swift; sourceTree = ""; }; @@ -773,6 +777,8 @@ D627943823A553B600D38C68 /* UnbookmarkStatusActivity.swift */, D64BC18723C1640A000D0238 /* PinStatusActivity.swift */, D64BC18923C16487000D0238 /* UnpinStatusActivity.swift */, + D681E4D2246E2AFF0053414F /* MuteConversationActivity.swift */, + D681E4D4246E2BC30053414F /* UnmuteConversationActivity.swift */, ); path = "Status Activities"; sourceTree = ""; @@ -1705,6 +1711,7 @@ D6674AEA23341F7600E8DF94 /* AppShortcutItems.swift in Sources */, D646C956213B365700269FB5 /* LargeImageExpandAnimationController.swift in Sources */, D667E5F82135C3040057A976 /* Mastodon+Equatable.swift in Sources */, + D681E4D5246E2BC30053414F /* UnmuteConversationActivity.swift in Sources */, D67C57B421E2910700C3118B /* ComposeStatusReplyView.swift in Sources */, D6B053A623BD2D0C00A066FA /* AssetCollectionViewController.swift in Sources */, 04DACE8E212CC7CC009840C4 /* ImageCache.swift in Sources */, @@ -1744,6 +1751,7 @@ D627943E23A564D400D38C68 /* ExploreViewController.swift in Sources */, D6B053AB23BD2F1400A066FA /* AssetCollectionViewCell.swift in Sources */, D6434EB3215B1856001A919A /* XCBRequest.swift in Sources */, + D681E4D3246E2AFF0053414F /* MuteConversationActivity.swift in Sources */, D6969EA0240C8384002843CE /* EmojiLabel.swift in Sources */, D64BC18623C1253A000D0238 /* AssetPreviewViewController.swift in Sources */, D663626221360B1900C9CBA2 /* Preferences.swift in Sources */, diff --git a/Tusker/Activities/Status Activities/MuteConversationActivity.swift b/Tusker/Activities/Status Activities/MuteConversationActivity.swift new file mode 100644 index 00000000..1c622eca --- /dev/null +++ b/Tusker/Activities/Status Activities/MuteConversationActivity.swift @@ -0,0 +1,40 @@ +// +// MuteConversationActivity.swift +// Tusker +// +// Created by Shadowfacts on 5/14/20. +// Copyright © 2020 Shadowfacts. All rights reserved. +// + +import UIKit +import Pachyderm + +class MuteConversationActivity: StatusActivity { + override var activityType: UIActivity.ActivityType? { + return .muteConversation + } + + override var activityTitle: String? { + return NSLocalizedString("Mute Conversation", comment: "mute conversation activity title") + } + + override var activityImage: UIImage? { + return UIImage(systemName: "speaker.slash") + } + + override func perform() { + guard let status = status else { return } + + let request = Status.muteConversation(status.id) + mastodonController.run(request) { (response) in + if case let .success(status, _) = response { + self.mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false) + } else { + // todo: display error message + UINotificationFeedbackGenerator().notificationOccurred(.error) + fatalError() + } + } + } + +} diff --git a/Tusker/Activities/Status Activities/UnmuteConversationActivity.swift b/Tusker/Activities/Status Activities/UnmuteConversationActivity.swift new file mode 100644 index 00000000..5a69664a --- /dev/null +++ b/Tusker/Activities/Status Activities/UnmuteConversationActivity.swift @@ -0,0 +1,40 @@ +// +// UnmuteConversationActivity.swift +// Tusker +// +// Created by Shadowfacts on 5/14/20. +// Copyright © 2020 Shadowfacts. All rights reserved. +// + +import UIKit +import Pachyderm + +class UnmuteConversationActivity: StatusActivity { + override var activityType: UIActivity.ActivityType? { + return .unmuteConversation + } + + override var activityTitle: String? { + return NSLocalizedString("Unmute Conversation", comment: "unmute conversation activity title") + } + + override var activityImage: UIImage? { + return UIImage(systemName: "speaker") + } + + override func perform() { + guard let status = status else { return } + + let request = Status.unmuteConversation(status.id) + mastodonController.run(request) { (response) in + if case let .success(status, _) = response { + self.mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false) + } else { + // todo: display error message + UINotificationFeedbackGenerator().notificationOccurred(.error) + fatalError() + } + } + } + +} diff --git a/Tusker/Activities/UIActivity+Types.swift b/Tusker/Activities/UIActivity+Types.swift index 16a76940..70d9e319 100644 --- a/Tusker/Activities/UIActivity+Types.swift +++ b/Tusker/Activities/UIActivity+Types.swift @@ -22,5 +22,7 @@ extension UIActivity.ActivityType { 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") + static let muteConversation = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).mute_conversation") + static let unmuteConversation = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unmute_conversation") } diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index ff8d2109..ab5fbc75 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -205,10 +205,12 @@ extension TuskerNavigationDelegate where Self: UIViewController { private func moreOptions(forStatus statusID: String) -> UIActivityViewController { guard let status = apiController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID)") } guard let url = status.url else { fatalError("Missing url for status \(statusID)") } - var customActivites: [UIActivity] = [OpenInSafariActivity()] - - let bookmarked = status.bookmarked ?? false - customActivites.insert(bookmarked ? UnbookmarkStatusActivity() : BookmarkStatusActivity(), at: 0) + + var customActivites: [UIActivity] = [ + OpenInSafariActivity(), + (status.bookmarked ?? false) ? UnbookmarkStatusActivity() : BookmarkStatusActivity(), + status.muted ? UnmuteConversationActivity() : MuteConversationActivity(), + ] if apiController.account != nil, status.account.id == apiController.account.id { let pinned = status.pinned ?? false