From 59ad858234995a7f0e7043ecef32103a695a3662 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Sat, 12 Apr 2025 19:30:33 +0300 Subject: [PATCH] Displaying event authors --- AutoCat.xcodeproj/project.pbxproj | 4 ++-- AutoCat/Screens/EventsScreen/EventModel.swift | 3 +++ AutoCat/Screens/EventsScreen/EventsScreen.swift | 5 +++++ AutoCat/Screens/EventsScreen/EventsViewModel.swift | 8 +++++++- AutoCatCore/Models/User.swift | 11 +++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 60c2bb7..77ea4cc 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -1822,7 +1822,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 154; + CURRENT_PROJECT_VERSION = 155; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = AutoCat; @@ -1849,7 +1849,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 154; + CURRENT_PROJECT_VERSION = 155; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = AutoCat; diff --git a/AutoCat/Screens/EventsScreen/EventModel.swift b/AutoCat/Screens/EventsScreen/EventModel.swift index 4892e20..d0c750b 100644 --- a/AutoCat/Screens/EventsScreen/EventModel.swift +++ b/AutoCat/Screens/EventsScreen/EventModel.swift @@ -15,6 +15,7 @@ struct EventModel: Identifiable, Hashable { var coordinate: CLLocationCoordinate2D var address: String var isMe: Bool + var user: String? func hash(into hasher: inout Hasher) { @@ -24,6 +25,7 @@ struct EventModel: Identifiable, Hashable { hasher.combine(coordinate.longitude) hasher.combine(address) hasher.combine(isMe) + hasher.combine(user) } static func == (lhs: EventModel, rhs: EventModel) -> Bool { @@ -34,5 +36,6 @@ struct EventModel: Identifiable, Hashable { && lhs.coordinate.longitude == rhs.coordinate.longitude && lhs.address == rhs.address && lhs.isMe == rhs.isMe + && lhs.user == rhs.user } } diff --git a/AutoCat/Screens/EventsScreen/EventsScreen.swift b/AutoCat/Screens/EventsScreen/EventsScreen.swift index 2554dad..7e24114 100644 --- a/AutoCat/Screens/EventsScreen/EventsScreen.swift +++ b/AutoCat/Screens/EventsScreen/EventsScreen.swift @@ -110,6 +110,11 @@ struct EventsScreen: View { Text(event.address) Text(event.date) .foregroundStyle(.secondary) + if let user = event.user, !event.isMe, viewModel.shouldDisplayEventAuthors { + Text(user) + .font(.footnote) + .foregroundStyle(.teal) + } } Spacer() Image(systemName: event.isMe ? "person.fill" : "person") diff --git a/AutoCat/Screens/EventsScreen/EventsViewModel.swift b/AutoCat/Screens/EventsScreen/EventsViewModel.swift index a0c754f..722b602 100644 --- a/AutoCat/Screens/EventsScreen/EventsViewModel.swift +++ b/AutoCat/Screens/EventsScreen/EventsViewModel.swift @@ -45,6 +45,11 @@ class EventsViewModel: ACHudContainer { UIPasteboard.general.data(forPasteboardType: UTType.vehicleEvent.identifier) != nil } + var shouldDisplayEventAuthors: Bool { + + settingsService.user.hasPermission(.locationAuthor) + } + init(apiService: ApiServiceProtocol, storageService: StorageServiceProtocol, settingsService: SettingsServiceProtocol, @@ -73,7 +78,8 @@ class EventsViewModel: ACHudContainer { date: dateString, coordinate: coordinate, address: event.address ?? "Lat: \(event.latitude), Lon: \(event.longitude)", - isMe: event.addedBy == email + isMe: event.addedBy == email, + user: event.addedBy ) } } diff --git a/AutoCatCore/Models/User.swift b/AutoCatCore/Models/User.swift index f5f3cc0..dc146c4 100644 --- a/AutoCatCore/Models/User.swift +++ b/AutoCatCore/Models/User.swift @@ -1,14 +1,25 @@ import Foundation +public enum Permission: String, CaseIterable, Sendable { + + case locationAuthor +} + @MainActor public struct User: Codable, Sendable { public let email: String public var token: String public var firebaseIdToken: String? public var firebaseRefreshToken: String? + public var permissions: [String]? public init(email: String = "", token: String = "") { self.email = email self.token = token } + + public func hasPermission(_ permission: Permission) -> Bool { + + permissions?.contains(permission.rawValue) == true + } }