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

Instance Statistics #869

Merged
merged 44 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5cf1c2b
Update
Sjmarf Jan 14, 2024
fe8c799
Show instance version
Sjmarf Jan 14, 2024
84c9e38
Rewrite CommunityResultView and UserResultView
Sjmarf Jan 14, 2024
e298d1d
Remove extra divider
Sjmarf Jan 14, 2024
95a4671
Don't show instance in admin list
Sjmarf Jan 14, 2024
e7cb5bf
Merge branch 'dev' into sjmarf/instance-page
Sjmarf Jan 17, 2024
4a81fc3
Use existing `GetSiteRequest(instanceURL: URL)` system
Sjmarf Jan 17, 2024
672a9ba
Bug fix
Sjmarf Jan 19, 2024
85e7d44
Fix
Sjmarf Jan 19, 2024
9129886
KBin fix
Sjmarf Jan 20, 2024
cf282dd
Update InstanceView.swift
Sjmarf Jan 20, 2024
31acf9c
Update InstanceView.swift
Sjmarf Jan 20, 2024
fa2f0f9
Update InstanceView.swift
Sjmarf Jan 20, 2024
d416622
Faster loading for own instance page
Sjmarf Jan 20, 2024
a385c1d
Update
Sjmarf Jan 20, 2024
30186f7
Update project.pbxproj
Sjmarf Jan 20, 2024
c2f59e0
Fix again
Sjmarf Jan 20, 2024
401add5
Remove unnecessary code
Sjmarf Jan 20, 2024
0703e89
Merge branch 'sjmarf/instance-page' into sjmarf/instance-stats
Sjmarf Jan 21, 2024
0840ead
Update
Sjmarf Jan 21, 2024
563e340
Update
Sjmarf Jan 21, 2024
7f792fa
Update project.pbxproj
Sjmarf Jan 21, 2024
b97ea61
Rename "Statistics" tab to "Details"
Sjmarf Jan 21, 2024
597a24b
Bug fix
Sjmarf Jan 22, 2024
06837fd
Fix background on light mode
Sjmarf Jan 22, 2024
19f7e4c
Add pre-emptive support for `GetPersonDetailsResponse.site`
Sjmarf Jan 24, 2024
16de9ef
Merge branch 'sjmarf/instance-page' into sjmarf/instance-stats
Sjmarf Jan 24, 2024
51e7868
Design tweak
Sjmarf Jan 24, 2024
e8d6c1f
Merge branch 'dev' into sjmarf/instance-stats
Sjmarf Jan 25, 2024
0fc3e09
Merge branch 'dev' into sjmarf/instance-stats
Sjmarf Jan 27, 2024
a8d31b8
Update project.pbxproj
Sjmarf Jan 27, 2024
513f3a2
Bug fixes
Sjmarf Jan 27, 2024
51a1c8a
Tweak
Sjmarf Jan 27, 2024
cfee83e
Merge branch 'dev' into sjmarf/instance-stats
Sjmarf Jan 27, 2024
ebae6dd
Merge branch 'dev' into sjmarf/instance-stats
Sjmarf Jan 28, 2024
e85f37b
Show/hide slur filter with animation
Sjmarf Jan 28, 2024
37d06c2
Make some settings always show
Sjmarf Jan 28, 2024
f0a025e
Merge branch 'dev' into sjmarf/instance-stats
Sjmarf Jan 28, 2024
e73c7a1
Update InstanceModel.swift
Sjmarf Jan 28, 2024
eee8677
Merge branch 'dev' into sjmarf/instance-stats
Sjmarf Jan 30, 2024
64b6428
Update
Sjmarf Jan 30, 2024
cba9293
Merge branch 'dev' into sjmarf/instance-stats
Sjmarf Jan 30, 2024
6b5e2d7
Update InstanceDetailsView.swift
Sjmarf Jan 31, 2024
8d4cc6b
Merge branch 'dev' into sjmarf/instance-stats
Sjmarf Jan 31, 2024
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
13 changes: 9 additions & 4 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
031A93D62AC847DA0077030C /* UploadConfirmationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031A93D52AC847DA0077030C /* UploadConfirmationView.swift */; };
031BF9532AB24BAF00F4517F /* SiteVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031BF9522AB24BAF00F4517F /* SiteVersion.swift */; };
031BF9552AB25AFB00F4517F /* SiteVersionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031BF9542AB25AFB00F4517F /* SiteVersionTests.swift */; };
031F95572B5C7FF20069C244 /* InstanceDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031F95562B5C7FF20069C244 /* InstanceDetailsView.swift */; };
032109472AA7C3FC00912DFC /* CommunityLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032109462AA7C3FC00912DFC /* CommunityLabelView.swift */; };
032109492AA7C41800912DFC /* AvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032109482AA7C41800912DFC /* AvatarView.swift */; };
032C1E042B5D7DAC00FB4F23 /* QuickSwitcherSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 032C1E032B5D7DAC00FB4F23 /* QuickSwitcherSettingsView.swift */; };
Expand Down Expand Up @@ -271,7 +272,7 @@
63F0C7B92A0533C700A18C5D /* Add Account View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F0C7B82A0533C700A18C5D /* Add Account View.swift */; };
63F0C7BD2A058CD200A18C5D /* Check if Endpoint Exists.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F0C7BC2A058CD200A18C5D /* Check if Endpoint Exists.swift */; };
63F0C7BF2A058EDE00A18C5D /* Get Correct URL to Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63F0C7BE2A058EDE00A18C5D /* Get Correct URL to Endpoint.swift */; };
6D15D74C2A44DC240061B5CB /* Date+RelativeTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D15D74B2A44DC240061B5CB /* Date+RelativeTime.swift */; };
6D15D74C2A44DC240061B5CB /* Date+Formatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D15D74B2A44DC240061B5CB /* Date+Formatter.swift */; };
6D405AFF2A43E66600C65F9C /* UserLabelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D405AFE2A43E66600C65F9C /* UserLabelView.swift */; };
6D693A3E2A5113DF009E2D76 /* CreatePostReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D693A3D2A5113DF009E2D76 /* CreatePostReport.swift */; };
6D693A402A51147E009E2D76 /* APIPostReportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D693A3F2A51147E009E2D76 /* APIPostReportView.swift */; };
Expand Down Expand Up @@ -593,6 +594,7 @@
031A93D52AC847DA0077030C /* UploadConfirmationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadConfirmationView.swift; sourceTree = "<group>"; };
031BF9522AB24BAF00F4517F /* SiteVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteVersion.swift; sourceTree = "<group>"; };
031BF9542AB25AFB00F4517F /* SiteVersionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteVersionTests.swift; sourceTree = "<group>"; };
031F95562B5C7FF20069C244 /* InstanceDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceDetailsView.swift; sourceTree = "<group>"; };
032109462AA7C3FC00912DFC /* CommunityLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityLabelView.swift; sourceTree = "<group>"; };
032109482AA7C41800912DFC /* AvatarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarView.swift; sourceTree = "<group>"; };
032C1E032B5D7DAC00FB4F23 /* QuickSwitcherSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickSwitcherSettingsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -831,7 +833,7 @@
63F0C7B82A0533C700A18C5D /* Add Account View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Add Account View.swift"; sourceTree = "<group>"; };
63F0C7BC2A058CD200A18C5D /* Check if Endpoint Exists.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Check if Endpoint Exists.swift"; sourceTree = "<group>"; };
63F0C7BE2A058EDE00A18C5D /* Get Correct URL to Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Get Correct URL to Endpoint.swift"; sourceTree = "<group>"; };
6D15D74B2A44DC240061B5CB /* Date+RelativeTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+RelativeTime.swift"; sourceTree = "<group>"; };
6D15D74B2A44DC240061B5CB /* Date+Formatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Formatter.swift"; sourceTree = "<group>"; };
6D405AFE2A43E66600C65F9C /* UserLabelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserLabelView.swift; sourceTree = "<group>"; };
6D693A3D2A5113DF009E2D76 /* CreatePostReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePostReport.swift; sourceTree = "<group>"; };
6D693A3F2A51147E009E2D76 /* APIPostReportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIPostReportView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1366,6 +1368,7 @@
isa = PBXGroup;
children = (
03A54C312B5331F30064CCDE /* InstanceView.swift */,
031F95562B5C7FF20069C244 /* InstanceDetailsView.swift */,
);
path = Instance;
sourceTree = "<group>";
Expand Down Expand Up @@ -2291,7 +2294,7 @@
CD29ED2E2B2E8307006937CE /* Date */ = {
isa = PBXGroup;
children = (
6D15D74B2A44DC240061B5CB /* Date+RelativeTime.swift */,
6D15D74B2A44DC240061B5CB /* Date+Formatter.swift */,
);
path = Date;
sourceTree = "<group>";
Expand Down Expand Up @@ -3412,6 +3415,7 @@
CDC1C93C2A7AA76000072E3D /* InternetSpeed.swift in Sources */,
50EC39B22A346DDC00E014C2 /* URLHandler.swift in Sources */,
63F0C7BF2A058EDE00A18C5D /* Get Correct URL to Endpoint.swift in Sources */,
031F95572B5C7FF20069C244 /* InstanceDetailsView.swift in Sources */,
632E8EE827EE63DB007E8D75 /* DownvoteButtonView.swift in Sources */,
50D61E5B2AA32B9400A926EC /* APISession.swift in Sources */,
CDCBD72B2A8EC0A800387A2C /* Instance Summary.swift in Sources */,
Expand Down Expand Up @@ -3472,6 +3476,7 @@
03A54C322B5331F30064CCDE /* InstanceView.swift in Sources */,
6D8F08FF2A4029AE003EB4FD /* CommunityListSection.swift in Sources */,
6D8F08FF2A4029AE003EB4FD /* CommunityListSection.swift in Sources */,
6D8F08FF2A4029AE003EB4FD /* CommunityListSection.swift in Sources */,
035EB0CA2A8687C200227859 /* JumpButtonView.swift in Sources */,
5016A2B12A67EB8600B257E8 /* UIViewController+TopMostViewController.swift in Sources */,
6372184C2A3A2AAD008C4816 /* APIPostView.swift in Sources */,
Expand Down Expand Up @@ -3574,7 +3579,7 @@
E49E01F42ABD99D300E42BB3 /* Routable.swift in Sources */,
03F4DC9F2B1A8AD500556C67 /* SignInAndSecuritySettingsView.swift in Sources */,
03F76FA62B2F5F4700E2B54A /* LinkUploadOptionsView.swift in Sources */,
6D15D74C2A44DC240061B5CB /* Date+RelativeTime.swift in Sources */,
6D15D74C2A44DC240061B5CB /* Date+Formatter.swift in Sources */,
CDA217E62A63016A00BDA173 /* ReportMessage.swift in Sources */,
CD9DD8832A622A6C0044EA8E /* ReportCommentReply.swift in Sources */,
6FB4A4DE2B47860B00A7CD82 /* CollapsedCommentReplies.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Mlem/API/Models/Community/APICommunityAggregates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct APICommunityAggregates: Decodable {
let id: Int? // TODO: 0.18 Deprecation remove this field
let communityId: Int
let subscribers: Int
let subscribersLocal: Int?
let posts: Int
let comments: Int
let published: Date
Expand Down
70 changes: 51 additions & 19 deletions Mlem/API/Models/Site/APILocalSite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,72 @@
// Created by Jonathan de Jong on 12/06/2023.
//

import Foundation
import SwiftUI

enum APICaptchaDifficulty: String, Codable { case easy, medium, hard }

// lemmy_db_schema::source::local_site::LocalSite
struct APILocalSite: Decodable {
// let id: Int
// let siteId: Int
// let siteSetup: Bool
let enableDownvotes: Bool
// let enableNsfw: Bool
// let communityCreationAdminOnly: Bool
// let requireEmailVerification: Bool
let enableNsfw: Bool
let communityCreationAdminOnly: Bool
let requireEmailVerification: Bool
// let applicationQuestion: String?
// let privateInstance: Bool
let privateInstance: Bool
// let defaultTheme: String
// let defaultPostListingType: String
let defaultPostListingType: APIListingType
// let legalInformation: String?
// let hideModlogModNames: Bool
// let applicationEmailAdmins: Bool
let hideModlogModNames: Bool
let applicationEmailAdmins: Bool
let slurFilterRegex: String?
// let actorNameMaxLength: Int
// let federationEnabled: Bool
// let federationDebug: Bool
// let federationWorkerCount: Int
// let captchaEnabled: Bool
// let captchaDifficulty: String
// let registrationMode: APIRegistrationMode
// let reportsEmailAdmins: Bool
// let published: Date
let federationEnabled: Bool
let federationSignedFetch: Bool?
let captchaEnabled: Bool
let captchaDifficulty: APICaptchaDifficulty
let registrationMode: APIRegistrationMode
let reportsEmailAdmins: Bool
let published: Date
// let updated: Date?
}

// lemmy_db_schema::source::local_site::RegistrationMode
enum APIRegistrationMode: String, Codable {
case closed = "Closed"
case requireApplication = "RequireApplication"
case open = "Open"
case closed = "closed"
case requireApplication = "requireapplication"
case open = "open"

init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let stringValue = try? container.decode(String.self) {
if let item = APIRegistrationMode(rawValue: stringValue.lowercased()) {
self = item
return
}
}
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid APIRegistrationMode value")
}

var label: String {
switch self {
case .requireApplication:
return "Requires Application"
default:
return rawValue.capitalized
}
}

var color: Color {
switch self {
case .closed:
return .red
case .requireApplication:
return .orange
case .open:
return .green
}
}
}
25 changes: 25 additions & 0 deletions Mlem/Extensions/Date/Date+Formatter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Date+RelativeTime.swift
// Mlem
//
// Created by Jake Shirley on 6/22/23.
//

import SwiftUI

extension Date {
// Returns strings like "3 seconds ago" and "10 days ago"
func getRelativeTime(date: Date = .now, unitsStyle: RelativeDateTimeFormatter.UnitsStyle = .full) -> String {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = unitsStyle

return formatter.localizedString(for: self, relativeTo: date)
}

// Returns strings like "5/10/2023"
var dateString: String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = DateFormatter.dateFormat(fromTemplate: "ddMMYY", options: 0, locale: Locale.current)
return dateFormatter.string(from: self)
}
}
18 changes: 0 additions & 18 deletions Mlem/Extensions/Date/Date+RelativeTime.swift

This file was deleted.

2 changes: 2 additions & 0 deletions Mlem/Extensions/Mocks/APICommunityAggregates+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extension APICommunityAggregates {
id: Int = 0,
communityId: Int = 0,
subscribers: Int = 42349,
subscribersLocal: Int = 2043,
posts: Int = 300,
comments: Int = 5000,
published: Date = .mock,
Expand All @@ -25,6 +26,7 @@ extension APICommunityAggregates {
id: id,
communityId: communityId,
subscribers: subscribers,
subscribersLocal: subscribersLocal,
posts: posts,
comments: comments,
published: published,
Expand Down
5 changes: 5 additions & 0 deletions Mlem/Icons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ enum Icons {
static let bannedFlair: String = "multiply.circle"

// entities/general Lemmy concepts
static let federation: String = "point.3.filled.connected.trianglepath.dotted"
static let instance: String = "server.rack"
static let user: String = "person.crop.circle"
static let userFill: String = "person.crop.circle.fill"
Expand Down Expand Up @@ -143,6 +144,7 @@ enum Icons {
static let favoriteFill: String = "star.fill"
static let unfavorite: String = "star.slash"
static let unfavoriteFill: String = "star.slash.fill"
static let person: String = "person"
static let personFill: String = "person.fill"
static let close: String = "multiply"
static let cakeDay: String = "birthday.cake"
Expand Down Expand Up @@ -189,6 +191,9 @@ enum Icons {
static let collapseComments: String = "arrow.down.and.line.horizontal.and.arrow.up"

// misc
static let `private`: String = "lock"
static let email: String = "envelope"
static let photo: String = "photo"
static let switchUser: String = "person.crop.circle.badge.plus"
static let missing: String = "questionmark.square.dashed"
static let connection: String = "antenna.radiowaves.left.and.right"
Expand Down
17 changes: 9 additions & 8 deletions Mlem/Models/Content/Community/CommunityModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
import Dependencies
import SwiftUI

struct ActiveUserCount {
let sixMonths: Int
let month: Int
let week: Int
let day: Int
}

struct CommunityModel {
@Dependency(\.apiClient) private var apiClient
@Dependency(\.errorHandler) var errorHandler
Expand All @@ -20,13 +27,6 @@ struct CommunityModel {
case noData
}

struct ActiveUserCount {
let sixMonths: Int
let month: Int
let week: Int
let day: Int
}

@available(*, deprecated, message: "Use attributes of the CommunityModel directly instead.")
var community: APICommunity!

Expand Down Expand Up @@ -63,6 +63,7 @@ struct CommunityModel {
var blocked: Bool?
var subscribed: Bool?
var subscriberCount: Int?
var localSubscriberCount: Int?
var postCount: Int?
var commentCount: Int?
var activeUserCount: ActiveUserCount?
Expand Down Expand Up @@ -108,8 +109,8 @@ struct CommunityModel {
mutating func update(with communityView: APICommunityView) {
subscribed = communityView.subscribed.isSubscribed
blocked = communityView.blocked

subscriberCount = communityView.counts.subscribers
localSubscriberCount = communityView.counts.subscribersLocal
postCount = communityView.counts.posts
commentCount = communityView.counts.comments
activeUserCount = .init(
Expand Down
Loading
Loading