From 3da1a7baddcccf20cab501b25e55b599ce86c7bd Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 29 Sep 2018 22:20:17 -0400 Subject: [PATCH] Add character counter --- Pachyderm/Model/Instance.swift | 6 +++-- PachydermTests/CharacterCounterTests.swift | 4 ++++ Tusker/AppDelegate.swift | 1 + Tusker/Controllers/MastodonController.swift | 9 ++++++++ Tusker/Screens/Compose/Compose.storyboard | 15 ++++++++---- .../Compose/ComposeViewController.swift | 23 +++++++++++++++++++ Tusker/XCallbackURL/XCBActions.swift | 6 +++++ 7 files changed, 58 insertions(+), 6 deletions(-) diff --git a/Pachyderm/Model/Instance.swift b/Pachyderm/Model/Instance.swift index 4f907f4d18..c0b20ae13c 100644 --- a/Pachyderm/Model/Instance.swift +++ b/Pachyderm/Model/Instance.swift @@ -15,8 +15,10 @@ public class Instance: Decodable { public let email: String public let version: String public let urls: [String: URL] - public let languages: [String] - public let contactAccount: Account + + // pleroma doesn't currently implement these + public let languages: [String]? + public let contactAccount: Account? // MARK: Unofficial additions to the Mastodon API. public let stats: Stats? diff --git a/PachydermTests/CharacterCounterTests.swift b/PachydermTests/CharacterCounterTests.swift index 65220e9623..887efe0dd7 100644 --- a/PachydermTests/CharacterCounterTests.swift +++ b/PachydermTests/CharacterCounterTests.swift @@ -17,6 +17,10 @@ class CharacterCounterTests: XCTestCase { override func tearDown() { } + func testCountEmpty() { + XCTAssertEqual(CharacterCounter.count(text: ""), 0) + } + func testCountPlainText() { XCTAssertEqual(CharacterCounter.count(text: "This is an example message"), 26) XCTAssertEqual(CharacterCounter.count(text: "This is an example message with an Emoji: 😄"), 43) diff --git a/Tusker/AppDelegate.swift b/Tusker/AppDelegate.swift index f3e414161f..a25f75def6 100644 --- a/Tusker/AppDelegate.swift +++ b/Tusker/AppDelegate.swift @@ -19,6 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { if LocalData.shared.onboardingComplete { MastodonController.shared.createClient() MastodonController.shared.getOwnAccount() + MastodonController.shared.getOwnInstance() } else { showOnboarding() } diff --git a/Tusker/Controllers/MastodonController.swift b/Tusker/Controllers/MastodonController.swift index 65a261d008..d2c997fdfb 100644 --- a/Tusker/Controllers/MastodonController.swift +++ b/Tusker/Controllers/MastodonController.swift @@ -16,6 +16,7 @@ class MastodonController { var client: Client! var account: Account! + var instance: Instance! private init() { } @@ -61,4 +62,12 @@ class MastodonController { } } + func getOwnInstance() { + let request = client.getInstance() + client.run(request) { (response) in + guard case let .success(instance, _) = response else { fatalError() } + self.instance = instance + } + } + } diff --git a/Tusker/Screens/Compose/Compose.storyboard b/Tusker/Screens/Compose/Compose.storyboard index 42bfb0ddbc..ffeb548d64 100644 --- a/Tusker/Screens/Compose/Compose.storyboard +++ b/Tusker/Screens/Compose/Compose.storyboard @@ -1,10 +1,10 @@ - + - + @@ -109,8 +109,14 @@ -