From a322a46fdf759f4ee394bf1d31d792a6330ec579 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Tue, 28 Nov 2023 09:13:24 +0100 Subject: [PATCH] Don't try to resolve self-relationship --- .../Content/StatusView+Configuration.swift | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+Configuration.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+Configuration.swift index 647c31ba2..245521d3d 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+Configuration.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+Configuration.swift @@ -184,31 +184,45 @@ extension StatusView { } public func configureAuthor(author: Mastodon.Entity.Account) { - // author avatar - viewModel.authorAvatarImageURL = author.avatarImageURL() - let emojis = author.emojis?.asDictionary ?? [:] - - // author name - viewModel.authorName = { - do { - let content = MastodonContent(content: author.displayNameWithFallback, emojis: emojis) - let metaContent = try MastodonMetaContent.convert(document: content) - return metaContent - } catch { - assertionFailure(error.localizedDescription) - return PlaintextMetaContent(string: author.displayNameWithFallback) - } - }() - - // author username - viewModel.authorUsername = author.acct - - // locked - viewModel.locked = author.locked - - // isMuting, isBlocking, Following Task { + + // author avatar + viewModel.authorAvatarImageURL = author.avatarImageURL() + let emojis = author.emojis?.asDictionary ?? [:] + + // author name + viewModel.authorName = { + do { + let content = MastodonContent(content: author.displayNameWithFallback, emojis: emojis) + let metaContent = try MastodonMetaContent.convert(document: content) + return metaContent + } catch { + assertionFailure(error.localizedDescription) + return PlaintextMetaContent(string: author.displayNameWithFallback) + } + }() + + // author username + viewModel.authorUsername = author.acct + + // locked + viewModel.locked = author.locked + + // isMyself + viewModel.isMyself = { + guard let authContext = viewModel.authContext else { return false } + return authContext.mastodonAuthenticationBox.domain == author.domain && authContext.mastodonAuthenticationBox.userID == author.id + }() + + // isMuting, isBlocking, Following guard let auth = viewModel.authContext?.mastodonAuthenticationBox else { return } + guard !viewModel.isMyself else { + viewModel.isMuting = false + viewModel.isBlocking = false + viewModel.isFollowed = false + return + } + if let relationship = try? await Mastodon.API.Account.relationships( session: .shared, domain: auth.domain, @@ -223,13 +237,6 @@ extension StatusView { } } } - - // isMyself - viewModel.isMyself = { - guard let authContext = viewModel.authContext else { return false } - return authContext.mastodonAuthenticationBox.domain == author.domain && authContext.mastodonAuthenticationBox.userID == author.id - }() - } private func configureTimestamp(timestamp: Date) {