diff --git a/Mlem/Views/Tabs/Settings/Components/Views/Account/MatrixLinkView.swift b/Mlem/Views/Tabs/Settings/Components/Views/Account/MatrixLinkView.swift index 51c4d9ab3..dec3f9ad4 100644 --- a/Mlem/Views/Tabs/Settings/Components/Views/Account/MatrixLinkView.swift +++ b/Mlem/Views/Tabs/Settings/Components/Views/Account/MatrixLinkView.swift @@ -13,12 +13,18 @@ struct MatrixLinkView: View { @Dependency(\.apiClient) var apiClient: APIClient @Dependency(\.errorHandler) var errorHandler: ErrorHandler - @State var matrixUserId: String = "" + @State var matrixUserId: String @State var hasEdited: UserSettingsEditState = .unedited let matrixIdRegex = /@.+\:.+\..+/ + init() { + @Dependency(\.siteInformation) var siteInformation: SiteInformationTracker + let user = siteInformation.myUserInfo?.localUserView + _matrixUserId = State(wrappedValue: user?.person.matrixUserId ?? "") + } + var matrixIdValid: Bool { if matrixUserId.isEmpty { return true @@ -51,7 +57,7 @@ struct MatrixLinkView: View { .autocorrectionDisabled() .textInputAutocapitalization(.never) .onChange(of: matrixUserId) { newValue in - if newValue != siteInformation.myUserInfo?.localUserView.person.matrixUserId { + if newValue != siteInformation.myUserInfo?.localUserView.person.matrixUserId ?? "" { hasEdited = .edited } } @@ -67,8 +73,7 @@ struct MatrixLinkView: View { } } } footer: { - // swiftlint:disable:next line_length - Text("Everyone will be able to see your matrix ID, and will be able to send you messages through Lemmy or another matrix client.") + Text("Everyone will be able to see your Matrix ID.") } Link("What is matrix?", destination: URL(string: "https://matrix.org/")!) } diff --git a/Mlem/Views/Tabs/Settings/Components/Views/Account/ProfileSettingsView.swift b/Mlem/Views/Tabs/Settings/Components/Views/Account/ProfileSettingsView.swift index 98d230e13..c1c62e890 100644 --- a/Mlem/Views/Tabs/Settings/Components/Views/Account/ProfileSettingsView.swift +++ b/Mlem/Views/Tabs/Settings/Components/Views/Account/ProfileSettingsView.swift @@ -17,8 +17,8 @@ struct ProfileSettingsView: View { @Dependency(\.apiClient) var apiClient: APIClient @Dependency(\.errorHandler) var errorHandler: ErrorHandler - @State var displayName: String = "" - @State var bio: String = "" + @State var displayName: String + @State var bio: String @StateObject var avatarAttachmentModel: LinkAttachmentModel @StateObject var bannerAttachmentModel: LinkAttachmentModel @@ -155,9 +155,19 @@ struct ProfileSettingsView: View { } } NavigationLink(.settings(.linkMatrixAccount)) { - Label("Link Matrix Account", image: "logo.matrix").labelStyle(SquircleLabelStyle(color: .black)) - .disabled(hasEdited != .unedited) + let user = siteInformation.myUserInfo?.localUserView + if let user, let matrixId = user.person.matrixUserId { + HStack { + Label("Matrix ID", image: "logo.matrix").labelStyle(SquircleLabelStyle(color: .black)) + Spacer() + Text(matrixId) + .foregroundStyle(.secondary) + } + } else { + Label("Link Matrix Account", image: "logo.matrix").labelStyle(SquircleLabelStyle(color: .black)) + } } + .disabled(hasEdited != .unedited) } .scrollDismissesKeyboard(.interactively) .navigationTitle("My Profile")