diff --git a/Mlem.xcodeproj/project.pbxproj b/Mlem.xcodeproj/project.pbxproj index cce2b8530..b10d68493 100644 --- a/Mlem.xcodeproj/project.pbxproj +++ b/Mlem.xcodeproj/project.pbxproj @@ -125,6 +125,7 @@ 0369B3562BFA6824001EFEDF /* InboxView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0369B3552BFA6824001EFEDF /* InboxView.swift */; }; 0369B35D2BFB86E3001EFEDF /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0369B35A2BFB86E3001EFEDF /* Account.swift */; }; 036CC3AF2B8145C30098B6A1 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036CC3AE2B8145C30098B6A1 /* AppState.swift */; }; + 036ED6832D0C483B0018E5EA /* Profile2Providing+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036ED6822D0C483B0018E5EA /* Profile2Providing+Extensions.swift */; }; 037331A42C9CB12D00C826E1 /* EnvironmentValues+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 037331A32C9CB12D00C826E1 /* EnvironmentValues+Extensions.swift */; }; 037386472BDAFE81007492B5 /* LemmyMarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = 037386462BDAFE81007492B5 /* LemmyMarkdownUI */; }; 037658DF2BE7D9EF00F4DD4D /* Community1Providing+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 037658DE2BE7D9EF00F4DD4D /* Community1Providing+Extensions.swift */; }; @@ -549,6 +550,7 @@ 0369B3552BFA6824001EFEDF /* InboxView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxView.swift; sourceTree = ""; }; 0369B35A2BFB86E3001EFEDF /* Account.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = ""; }; 036CC3AE2B8145C30098B6A1 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = ""; }; + 036ED6822D0C483B0018E5EA /* Profile2Providing+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Profile2Providing+Extensions.swift"; sourceTree = ""; }; 037331A32C9CB12D00C826E1 /* EnvironmentValues+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EnvironmentValues+Extensions.swift"; sourceTree = ""; }; 037658DE2BE7D9EF00F4DD4D /* Community1Providing+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Community1Providing+Extensions.swift"; sourceTree = ""; }; 037DE0742CE023E3007F7B92 /* BlockListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockListView.swift; sourceTree = ""; }; @@ -1772,6 +1774,7 @@ CD7743882C20EDEE0085BB43 /* VotesModel+Extensions.swift */, 035EDF042C2ED35500F51144 /* Person1Providing+Extensions.swift */, CD8DCAF82C5E92E8003E4DD7 /* Profile1Providing+Extensions.swift */, + 036ED6822D0C483B0018E5EA /* Profile2Providing+Extensions.swift */, 0320B6532C8B65EB00D38548 /* Captcha+Extensions.swift */, ); path = "Content Models"; @@ -2450,6 +2453,7 @@ 038028F62CB096960091A8A2 /* SearchView+FilterModels.swift in Sources */, 033FCB292C5E3933007B7CD1 /* IconSettingsView.swift in Sources */, 035394932CA1AE2C00795AA5 /* UptimeData.swift in Sources */, + 036ED6832D0C483B0018E5EA /* Profile2Providing+Extensions.swift in Sources */, 033FCB2A2C5E3933007B7CD1 /* AlternateIconCell.swift in Sources */, 0389DDC72C389F840005B808 /* UnreadCount+Extensions.swift in Sources */, 03500C242BF55D0E00CAA076 /* Toast.swift in Sources */, diff --git a/Mlem/App/Utility/Extensions/Content Models/Person1Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Person1Providing+Extensions.swift index 6caef4759..f77845490 100644 --- a/Mlem/App/Utility/Extensions/Content Models/Person1Providing+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Content Models/Person1Providing+Extensions.swift @@ -27,16 +27,10 @@ extension Person1Providing { output.insert(.bannedFromInstance) } - let intervalSinceCreation = Date.now.timeIntervalSince(created) - if intervalSinceCreation < 30 * 24 * 60 * 60 { - output.insert(.new(intervalSinceCreation)) - } else { - let calendar = Calendar.current - let createdComponents = calendar.dateComponents([.month, .day], from: created) - let currentComponents = calendar.dateComponents([.month, .day], from: .now) - if createdComponents.month == currentComponents.month, createdComponents.day == currentComponents.day { - output.insert(.cakeDay) - } + if createdRecently { + output.insert(.new(Date.now.timeIntervalSince(created))) + } else if isCakeDay { + output.insert(.cakeDay) } if let interactable { diff --git a/Mlem/App/Utility/Extensions/Content Models/Profile2Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Profile2Providing+Extensions.swift new file mode 100644 index 000000000..5cd608506 --- /dev/null +++ b/Mlem/App/Utility/Extensions/Content Models/Profile2Providing+Extensions.swift @@ -0,0 +1,18 @@ +// +// Profile2Providing+Extensions.swift +// Mlem +// +// Created by Sjmarf on 2024-12-13. +// + +import Foundation +import MlemMiddleware + +extension Profile2Providing { + var isCakeDay: Bool { created.isAnniversaryToday } + + var createdRecently: Bool { + let intervalSinceCreation = Date.now.timeIntervalSince(created) + return intervalSinceCreation < 30 * 24 * 60 * 60 + } +} diff --git a/Mlem/App/Utility/Extensions/Date+Extensions.swift b/Mlem/App/Utility/Extensions/Date+Extensions.swift index 758e63703..19775cf82 100644 --- a/Mlem/App/Utility/Extensions/Date+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Date+Extensions.swift @@ -37,4 +37,11 @@ extension Date { let value = formatter.string(from: interval) return value ?? String(localized: "Unknown") } + + var isAnniversaryToday: Bool { + let calendar = Calendar.current + let date = calendar.dateComponents([.month, .day, .year], from: self) + let current = calendar.dateComponents([.month, .day, .year], from: .now) + return date.month == current.month && date.day == current.day && date.year != current.year + } } diff --git a/Mlem/App/Views/Shared/ProfileDateView.swift b/Mlem/App/Views/Shared/ProfileDateView.swift index 29ad067b0..67a9df71a 100644 --- a/Mlem/App/Views/Shared/ProfileDateView.swift +++ b/Mlem/App/Views/Shared/ProfileDateView.swift @@ -14,13 +14,36 @@ struct ProfileDateView: View { var profilable: any Profile2Providing var body: some View { - Label(format(profilable.created), systemImage: Icons.cakeDay) - .foregroundStyle(palette.secondary) + Label(format(profilable.created), systemImage: systemImage) + .foregroundStyle(color) .font(.footnote) } + var color: Color { + if profilable.createdRecently { + palette.colorfulAccent(3) + } else if profilable.isCakeDay { + palette.colorfulAccent(1) + } else { + palette.secondary + } + } + + var systemImage: String { + if profilable.createdRecently { + Icons.newAccountFlair + } else if profilable.isCakeDay { + Icons.cakeDayFill + } else { + Icons.cakeDay + } + } + func format(_ date: Date) -> String { - let relTime = date.getRelativeTime(date: Date.now, unitsStyle: .abbreviated) + var relTime = date.getRelativeTime(date: Date.now, unitsStyle: .abbreviated) + if profilable.isCakeDay { + relTime = String(localized: "\(relTime) today!") + } return "\(date.dateString), \(relTime)" } } diff --git a/Mlem/Localizable.xcstrings b/Mlem/Localizable.xcstrings index 8a561e14c..0e94e522b 100644 --- a/Mlem/Localizable.xcstrings +++ b/Mlem/Localizable.xcstrings @@ -55,6 +55,9 @@ }, "%@ rules..." : { + }, + "%@ today!" : { + }, "%lld Crossposts..." : { "localizations" : {