From 6cc069ec5bf899da43f9ed6882d640a3661f4713 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Thu, 14 Dec 2023 14:07:58 +0100 Subject: [PATCH] Try to fix domain (IOS-192) --- Mastodon/Scene/Profile/ProfileViewController.swift | 10 +++++----- .../MastodonSDK/Entity/Mastodon+Entity+Account.swift | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Mastodon/Scene/Profile/ProfileViewController.swift b/Mastodon/Scene/Profile/ProfileViewController.swift index b43694483..f2fc6885a 100644 --- a/Mastodon/Scene/Profile/ProfileViewController.swift +++ b/Mastodon/Scene/Profile/ProfileViewController.swift @@ -298,9 +298,9 @@ extension ProfileViewController { // header #warning("TODO: Implement") let headerViewModel = profileHeaderViewController.viewModel! -// viewModel.$account -// .assign(to: \.account, on: headerViewModel) -// .store(in: &disposeBag) + viewModel.$account + .assign(to: \.account, on: headerViewModel) + .store(in: &disposeBag) viewModel.$isEditing .assign(to: \.isEditing, on: headerViewModel) .store(in: &disposeBag) @@ -378,11 +378,11 @@ extension ProfileViewController { profileHeaderViewController.profileHeaderView.viewModel.viewDidAppear ) .sink { [weak self] (user, _) in - guard let self else { return } + guard let self, let domain = user.domainFromAcct else { return } Task { _ = try await self.context.apiService.fetchUser( username: user.username, - domain: "user.domainFromAcct", + domain: domain, authenticationBox: self.authContext.mastodonAuthenticationBox ) } diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift index a358bcace..4de477896 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift @@ -178,4 +178,15 @@ extension Mastodon.Entity.Account { return !displayName.isEmpty ? displayName : username } + + public var domainFromAcct: String? { + if acct.contains("@") { + return domain + } else if let domain = acct.split(separator: "@").last { + return String(domain) + } else { + return nil + } + } + }