diff --git a/Pachyderm/Utilities/InstanceType.swift b/Pachyderm/Utilities/InstanceType.swift new file mode 100644 index 0000000000..9a8ad33f64 --- /dev/null +++ b/Pachyderm/Utilities/InstanceType.swift @@ -0,0 +1,24 @@ +// +// InstanceType.swift +// Pachyderm +// +// Created by Shadowfacts on 9/11/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import Foundation + +public enum InstanceType { + case mastodon, pleroma +} + +public extension Instance { + var instanceType: InstanceType { + let lowercased = version.lowercased() + if lowercased.contains("pleroma") { + return .pleroma + } else { + return .mastodon + } + } +} diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 4f5789845c..de797a6734 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -103,6 +103,7 @@ D663626C21361C6700C9CBA2 /* Account+Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663626B21361C6700C9CBA2 /* Account+Preferences.swift */; }; D66362712136338600C9CBA2 /* ComposeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66362702136338600C9CBA2 /* ComposeViewController.swift */; }; D66362752137068A00C9CBA2 /* Visibility+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66362742137068A00C9CBA2 /* Visibility+Helpers.swift */; }; + D667383C23299340000A2373 /* InstanceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667383B23299340000A2373 /* InstanceType.swift */; }; D667E5E12134937B0057A976 /* StatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E02134937B0057A976 /* StatusTableViewCell.xib */; }; D667E5E721349D4C0057A976 /* ProfileTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */; }; D667E5E921349EE50057A976 /* ProfileHeaderTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E821349EE50057A976 /* ProfileHeaderTableViewCell.xib */; }; @@ -348,6 +349,7 @@ D663626B21361C6700C9CBA2 /* Account+Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Account+Preferences.swift"; sourceTree = ""; }; D66362702136338600C9CBA2 /* ComposeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeViewController.swift; sourceTree = ""; }; D66362742137068A00C9CBA2 /* Visibility+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Visibility+Helpers.swift"; sourceTree = ""; }; + D667383B23299340000A2373 /* InstanceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceType.swift; sourceTree = ""; }; D667E5E02134937B0057A976 /* StatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusTableViewCell.xib; sourceTree = ""; }; D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTableViewController.swift; sourceTree = ""; }; D667E5E821349EE50057A976 /* ProfileHeaderTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ProfileHeaderTableViewCell.xib; sourceTree = ""; }; @@ -947,6 +949,7 @@ D6E6F26221603F8B006A8599 /* CharacterCounter.swift */, D6A3BC7323218C6E00FD64D5 /* TimelineSegment.swift */, D6A3BC7823218E9200FD64D5 /* NotificationGroup.swift */, + D667383B23299340000A2373 /* InstanceType.swift */, ); path = Utilities; sourceTree = ""; @@ -1428,6 +1431,7 @@ buildActionMask = 2147483647; files = ( D61099E5214561AB00432DC2 /* Application.swift in Sources */, + D667383C23299340000A2373 /* InstanceType.swift in Sources */, D61099FF21456A4C00432DC2 /* Status.swift in Sources */, D61099E32144C38900432DC2 /* Emoji.swift in Sources */, D6109A0D214599E100432DC2 /* RequestRange.swift in Sources */, diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 2801b357d4..6bdd9cfae5 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -283,7 +283,12 @@ class ComposeViewController: UIViewController { } func updateAddAttachmentButton() { - addAttachmentButton.isEnabled = selectedAssets.count < 5 // 4 attachments + 1 button + switch MastodonController.instance.instanceType { + case .pleroma: + addAttachmentButton.isEnabled = true + case .mastodon: + addAttachmentButton.isEnabled = selectedAssets.count <= 4 && selectedAssets.first(where: { $0.mediaType == .video }) == nil + } } func updateAttachmentViews() { @@ -311,7 +316,6 @@ class ComposeViewController: UIViewController { } func saveDraft() { - // TODO: save CW to draft var attachments = [DraftsManager.DraftAttachment]() for asset in selectedAssets { let index = attachments.count @@ -559,7 +563,15 @@ extension ComposeViewController: GMImagePickerControllerDelegate { } func assetsPickerController(_ picker: GMImagePickerController!, shouldSelect asset: PHAsset!) -> Bool { - return selectedAssets.count + picker.selectedAssets.count < 4 + switch MastodonController.instance.instanceType { + case .pleroma: + return true + case .mastodon: + if (asset.mediaType == .video && selectedAssets.count > 0) || selectedAssets.first(where: { $0.mediaType == .video }) != nil { + return false + } + return selectedAssets.count + picker.selectedAssets.count < 4 + } } }