Displaying event authors

This commit is contained in:
Selim Mustafaev 2025-04-12 19:30:33 +03:00
parent a00cf9a597
commit 59ad858234
5 changed files with 28 additions and 3 deletions

View File

@ -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;

View File

@ -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
}
}

View File

@ -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")

View File

@ -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
)
}
}

View File

@ -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
}
}