From c45252b294a3293f5f7d7814a149638113fd638d Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Mon, 20 Nov 2023 12:27:10 +0100 Subject: [PATCH] Set properties based on Entity.Account (IOS-194) --- .../ProfileCardView+Configuration.swift | 86 ++++--------------- 1 file changed, 17 insertions(+), 69 deletions(-) diff --git a/Mastodon/Scene/Discovery/ForYou/ProfileCardView+Configuration.swift b/Mastodon/Scene/Discovery/ForYou/ProfileCardView+Configuration.swift index 3db4698f7..1e7a0f5ed 100644 --- a/Mastodon/Scene/Discovery/ForYou/ProfileCardView+Configuration.swift +++ b/Mastodon/Scene/Discovery/ForYou/ProfileCardView+Configuration.swift @@ -16,11 +16,16 @@ import MastodonSDK extension ProfileCardView { public func configure(account: Mastodon.Entity.Account) { - //TODO: Implement viewModel.authorBannerImageURL = URL(string: account.header) - + viewModel.statusesCount = account.statusesCount + viewModel.followingCount = account.followingCount + viewModel.followersCount = account.followersCount + viewModel.authorAvatarImageURL = account.avatarImageURL() + + let emojis = account.emojis?.asDictionary ?? [:] + do { - let content = MastodonContent(content: account.displayNameWithFallback, emojis: account.emojis?.asDictionary ?? [:]) + let content = MastodonContent(content: account.displayNameWithFallback, emojis: emojis) let metaContent = try MastodonMetaContent.convert(document: content) viewModel.authorName = metaContent } catch { @@ -29,73 +34,16 @@ extension ProfileCardView { viewModel.authorName = metaContent } - } + viewModel.authorUsername = account.acct - public func configure(user: MastodonUser) { - // author avatar - Publishers.CombineLatest3( - user.publisher(for: \.avatar), - user.publisher(for: \.avatarStatic), - UserDefaults.shared.publisher(for: \.preferredStaticAvatar) - ) - .map { _ in user.avatarImageURL() } - .assign(to: \.authorAvatarImageURL, on: viewModel) - .store(in: &disposeBag) - // name - Publishers.CombineLatest( - user.publisher(for: \.displayName), - user.publisher(for: \.emojis) - ) - .map { _, emojis in - do { - let content = MastodonContent(content: user.displayNameWithFallback, emojis: emojis.asDictionary) - let metaContent = try MastodonMetaContent.convert(document: content) - return metaContent - } catch { - assertionFailure(error.localizedDescription) - return PlaintextMetaContent(string: user.displayNameWithFallback) - } + do { + let content = MastodonContent(content: account.note, emojis: emojis) + let metaContent = try MastodonMetaContent.convert(document: content) + viewModel.bioContent = metaContent + } catch { + assertionFailure(error.localizedDescription) + let metaContent = PlaintextMetaContent(string: account.note) + viewModel.bioContent = metaContent } - .assign(to: \.authorName, on: viewModel) - .store(in: &disposeBag) - // username - user.publisher(for: \.acct) - .map { $0 as String? } - .assign(to: \.authorUsername, on: viewModel) - .store(in: &disposeBag) - // bio - Publishers.CombineLatest( - user.publisher(for: \.note), - user.publisher(for: \.emojis) - ) - .map { note, emojis in - guard let note = note else { return nil } - do { - let content = MastodonContent(content: note, emojis: emojis.asDictionary) - let metaContent = try MastodonMetaContent.convert(document: content) - return metaContent - } catch { - assertionFailure(error.localizedDescription) - return nil - } - } - .assign(to: \.bioContent, on: viewModel) - .store(in: &disposeBag) - // relationship - viewModel.relationshipViewModel.user = user - // dashboard - user.publisher(for: \.statusesCount) - .map { Int($0) } - .assign(to: \.statusesCount, on: viewModel) - .store(in: &disposeBag) - user.publisher(for: \.followingCount) - .map { Int($0) } - .assign(to: \.followingCount, on: viewModel) - .store(in: &disposeBag) - user.publisher(for: \.followersCount) - .map { Int($0) } - .assign(to: \.followersCount, on: viewModel) - .store(in: &disposeBag) } - }