From 201aeffafb6ec0a1b6980f223a1582ab148267e4 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 4f907f4d..c0b20ae1 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 65220e96..887efe0d 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 f3e41416..a25f75de 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 65a261d0..d2c997fd 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 42bfb0dd..ffeb548d 100644 --- a/Tusker/Screens/Compose/Compose.storyboard +++ b/Tusker/Screens/Compose/Compose.storyboard @@ -1,10 +1,10 @@ - + - + @@ -109,8 +109,14 @@ -