Add information about number of users and posts.

This commit is contained in:
Marcin Czachursk 2023-02-19 12:11:25 +01:00
parent e507ed3916
commit ca4236e118
3 changed files with 47 additions and 0 deletions

View File

@ -47,6 +47,9 @@ public struct Instance: Codable {
/// Main contact email.
public let email: String?
/// Statistics about the instance.
public let stats: Stats?
enum CodingKeys: String, CodingKey {
case uri
case title
@ -61,6 +64,7 @@ public struct Instance: Codable {
case email
case registrations
case approvalRequired = "approval_required"
case stats
}
public init(from decoder: Decoder) throws {
@ -79,5 +83,6 @@ public struct Instance: Codable {
self.email = try? container.decodeIfPresent(String.self, forKey: .email)
self.registrations = (try? container.decodeIfPresent(Bool.self, forKey: .registrations)) ?? false
self.approvalRequired = (try? container.decodeIfPresent(Bool.self, forKey: .approvalRequired)) ?? false
self.stats = try? container.decodeIfPresent(Stats.self, forKey: .stats)
}
}

View File

@ -0,0 +1,27 @@
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
import Foundation
/// Instance stats.
public struct Stats: Codable {
/// Number of user in the instance.
public let userCount: Int
/// Number of statuses in the instance.
public let statusCount: Int
/// Number of domains?
public let domainCount: Int
private enum CodingKeys: String, CodingKey {
case userCount = "user_count"
case statusCount = "status_count"
case domainCount = "domain_count"
}
}

View File

@ -55,6 +55,21 @@ struct InstanceRow: View {
Text(instance.description ?? "")
.font(.caption)
if let stats = instance.stats {
HStack {
Image(systemName: "person.2.fill")
Text("\(stats.userCount) users")
Image(systemName: "photo.stack.fill")
Text("\(stats.statusCount) posts")
Spacer()
}
.padding(.top, 4)
.foregroundColor(.lightGrayColor)
.font(.caption)
}
}
}