Rename UserProfileProxy to UserProfile. It's a pure struct and proxies nothing.

Also remove the redundant `userID` property given `id` already exists (for Identifiable conformance).
This commit is contained in:
Doug
2026-07-01 15:18:03 +01:00
committed by Doug
parent bdf53b64a8
commit 3ef66cdd05
55 changed files with 203 additions and 209 deletions
@@ -20,7 +20,7 @@ enum InviteUsersScreenViewModelAction {
}
enum InviteUsersScreenRoomType {
case draft(mandatoryInvitees: [UserProfileProxy])
case draft(mandatoryInvitees: [UserProfile])
case existingRoom(roomProxy: JoinedRoomProxyProtocol)
}
@@ -29,10 +29,10 @@ struct InviteUsersScreenViewState: BindableState {
var usersSection: UserDiscoverySection = .init(type: .suggestions, users: [])
var selectedUsers: [UserProfileProxy] = []
var mandatoryInvitees: [UserProfileProxy] = []
var selectedUsers: [UserProfile] = []
var mandatoryInvitees: [UserProfile] = []
var membershipState: [String: MembershipState] = .init()
var usersToConfirm: [UserProfileProxy] = []
var usersToConfirm: [UserProfile] = []
var isSearching = false
@@ -44,11 +44,11 @@ struct InviteUsersScreenViewState: BindableState {
selectedUsers.contains { !isInviteeMandatory($0) }
}
func isUserSelected(_ user: UserProfileProxy) -> Bool {
isUserDisabled(user) || selectedUsers.contains { $0.userID == user.userID }
func isUserSelected(_ user: UserProfile) -> Bool {
isUserDisabled(user) || selectedUsers.contains { $0.id == user.id }
}
func isUserDisabled(_ user: UserProfileProxy) -> Bool {
func isUserDisabled(_ user: UserProfile) -> Bool {
if isInviteeMandatory(user) {
return true
}
@@ -56,12 +56,12 @@ struct InviteUsersScreenViewState: BindableState {
return membershipState == .invite || membershipState == .join
}
func isInviteeMandatory(_ user: UserProfileProxy) -> Bool {
mandatoryInvitees.contains { $0.userID == user.userID }
func isInviteeMandatory(_ user: UserProfile) -> Bool {
mandatoryInvitees.contains { $0.id == user.id }
}
func membershipState(_ user: UserProfileProxy) -> MembershipState? {
membershipState[user.userID]
func membershipState(_ user: UserProfile) -> MembershipState? {
membershipState[user.id]
}
let isSkippable: Bool
@@ -83,5 +83,5 @@ enum InviteUsersScreenViewAction {
case proceed
case removeUnknownUsers
case confirmUnknownUsers
case toggleUser(UserProfileProxy)
case toggleUser(UserProfile)
}
@@ -19,7 +19,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
private let userIndicatorController: UserIndicatorControllerProtocol
private let appSettings: AppSettings
private var suggestedUsers = [UserProfileProxy]()
private var suggestedUsers = [UserProfile]()
private let actionsSubject: PassthroughSubject<InviteUsersScreenViewModelAction, Never> = .init()
var actions: AnyPublisher<InviteUsersScreenViewModelAction, Never> {
@@ -38,7 +38,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
self.userIndicatorController = userIndicatorController
self.appSettings = appSettings
let mandatoryInvitees: [UserProfileProxy] = if case .draft(let invitees) = roomType {
let mandatoryInvitees: [UserProfile] = if case .draft(let invitees) = roomType {
invitees
} else {
[]
@@ -70,12 +70,12 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
case .proceed:
switch roomType {
case .draft:
createDraftRoom(mandatoryUserIDs: state.selectedUsers.map(\.userID))
createDraftRoom(mandatoryUserIDs: state.selectedUsers.map(\.id))
case .existingRoom(let roomProxy):
guard roomProxy.details.historySharingState != RoomHistorySharingState.hidden,
!state.usersToConfirm.isEmpty,
!state.isSkippable else {
inviteUsers(state.selectedUsers.map(\.userID), roomProxy: roomProxy)
inviteUsers(state.selectedUsers.map(\.id), roomProxy: roomProxy)
return
}
state.bindings.presentConfirmationDialog = true
@@ -83,14 +83,14 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
case .removeUnknownUsers:
state.bindings.presentConfirmationDialog = false
state.selectedUsers.removeAll { user in
state.usersToConfirm.contains { $0.userID == user.userID }
state.usersToConfirm.contains { $0.id == user.id }
}
state.usersToConfirm = []
case .confirmUnknownUsers:
state.bindings.presentConfirmationDialog = false
state.usersToConfirm = []
if case .existingRoom(let roomProxy) = roomType {
inviteUsers(state.selectedUsers.map(\.userID), roomProxy: roomProxy)
inviteUsers(state.selectedUsers.map(\.id), roomProxy: roomProxy)
}
case .toggleUser(let user):
toggleUser(user)
@@ -99,16 +99,16 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
// MARK: - Private
private func toggleUser(_ user: UserProfileProxy) {
private func toggleUser(_ user: UserProfile) {
guard !state.isInviteeMandatory(user) else { return }
if state.selectedUsers.contains(user) {
state.selectedUsers.removeAll { $0.userID == user.userID }
state.selectedUsers.removeAll { $0.id == user.id }
} else {
state.selectedUsers.append(user)
withElementAnimation(.easeInOut) { state.bindings.selectedUsersPosition = user.userID }
withElementAnimation(.easeInOut) { state.bindings.selectedUsersPosition = user.id }
Task {
let identityUnknown = if case .success(let identity) = await self.clientProxy.userIdentity(for: user.userID, fallBackToServer: false) {
let identityUnknown = if case .success(let identity) = await self.clientProxy.userIdentity(for: user.id, fallBackToServer: false) {
identity == nil
} else {
true
@@ -12,7 +12,7 @@ struct InviteUsersConfirmationSheetView: View {
@ObservedObject var context: InviteUsersScreenViewModel.Context
/// The users whose identities we wish the user to confirm.
var users: [UserProfileProxy]
var users: [UserProfile]
var body: some View {
FullscreenDialog(topPadding: 24, horizontalPadding: 24) {
@@ -22,7 +22,7 @@ struct InviteUsersConfirmationSheetView: View {
icon: \.userAddSolid,
iconStyle: .defaultSolid)
VStack(spacing: 0) {
ForEach(users, id: \.userID) { user in
ForEach(users, id: \.id) { user in
UserProfileListRow(user: user,
membership: nil,
mediaProvider: context.mediaProvider,
@@ -83,7 +83,7 @@ struct InviteUsersScreen: View {
private var usersSection: some View {
if !context.viewState.usersSection.users.isEmpty {
Section {
ForEach(context.viewState.usersSection.users, id: \.userID) { user in
ForEach(context.viewState.usersSection.users, id: \.id) { user in
UserProfileListRow(user: user,
membership: context.viewState.membershipState(user),
mediaProvider: context.mediaProvider,
@@ -109,7 +109,7 @@ struct InviteUsersScreen: View {
private var selectedUsersSection: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 8) {
ForEach(context.viewState.selectedUsers, id: \.userID) { user in
ForEach(context.viewState.selectedUsers, id: \.id) { user in
InviteUsersScreenSelectedItem(user: user,
mediaProvider: context.mediaProvider,
isLocked: context.viewState.isInviteeMandatory(user)) {
@@ -150,7 +150,7 @@ struct InviteUsersScreen: View {
}
}
private func deselect(_ user: UserProfileProxy) {
private func deselect(_ user: UserProfile) {
context.send(viewAction: .toggleUser(user))
}
}
@@ -10,7 +10,7 @@ import Compound
import SwiftUI
struct InviteUsersScreenSelectedItem: View {
let user: UserProfileProxy
let user: UserProfile
let mediaProvider: MediaProviderProtocol?
var isLocked = false
let dismissAction: () -> Void
@@ -20,7 +20,7 @@ struct InviteUsersScreenSelectedItem: View {
avatar
.accessibilityHidden(true)
Text(user.displayName ?? user.userID)
Text(user.displayName ?? user.id)
.font(.compound.bodySM)
.foregroundColor(.compound.textSecondary)
.lineLimit(1)
@@ -39,7 +39,7 @@ struct InviteUsersScreenSelectedItem: View {
var avatar: some View {
let avatarImage = LoadableAvatarImage(url: user.avatarURL,
name: user.displayName,
contentID: user.userID,
contentID: user.id,
avatarSize: .user(on: .inviteUsers),
mediaProvider: mediaProvider)
if isLocked {
@@ -58,12 +58,12 @@ struct InviteUsersScreenSelectedItem: View {
}
struct InviteUsersScreenSelectedItem_Previews: PreviewProvider, TestablePreview {
static let people: [UserProfileProxy] = [.mockAlice, .mockVerbose]
static let people: [UserProfile] = [.mockAlice, .mockVerbose]
static var previews: some View {
ScrollView(.horizontal) {
HStack(spacing: 8) {
ForEach(people, id: \.userID) { user in
ForEach(people, id: \.id) { user in
InviteUsersScreenSelectedItem(user: user, mediaProvider: MediaProviderMock(.init())) { }
.frame(width: 80)
}