Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added replies_count to Status. #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/MastodonSwift/Entities/Status.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Status: Codable {
public let mentions: [Mention]
public let tags: [Tag]
public let application: Application?
public let repliesCount: Int

private enum CodingKeys: String, CodingKey {
case id
Expand All @@ -60,6 +61,7 @@ public class Status: Codable {
case mentions
case tags
case application
case repliesCount = "replies_count"
}

public required init(from decoder: Decoder) throws {
Expand Down Expand Up @@ -89,6 +91,7 @@ public class Status: Codable {
self.mentions = (try? container.decode([Mention].self, forKey: .mentions)) ?? []
self.tags = (try? container.decode([Tag].self, forKey: .tags)) ?? []
self.application = try? container.decode(Application.self, forKey: .application)
self.repliesCount = try container.decode(Int.self, forKey: .repliesCount)
}

public func encode(to encoder: Encoder) throws {
Expand Down Expand Up @@ -134,5 +137,6 @@ public class Status: Codable {
if let application {
try container.encode(application, forKey: .application)
}
try container.encode(repliesCount, forKey: .repliesCount)
}
}
2 changes: 2 additions & 0 deletions Tests/MastodonSwiftTests/MastodonClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class MastodonSwiftTests: XCTestCase {
let result = try await client.getHomeTimeline()

XCTAssertEqual(result.first?.content, "<p>TEST</p>")
XCTAssertEqual(result.first?.repliesCount, 1)
XCTAssertEqual(result.last?.repliesCount, 0)
}

func testGetHomeTimeline_withoutConvenienceMethod() async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let getHomeTimelineMockResponseData = """
"language": "de",
"uri": "https://bearologics.social/users/Beartest/statuses/109264839555846597",
"url": "https://bearologics.social/@Beartest/109264839555846597",
"replies_count": 0,
"replies_count": 1,
"reblogs_count": 0,
"favourites_count": 0,
"edited_at": null,
Expand Down