From 9a25d20e026bb11ad94053ef6348e5e37f39ddd0 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Tue, 2 Jan 2024 23:10:17 +0100 Subject: [PATCH] Replace another user with an account (IOS-192) --- .../ComposeContentViewModel.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift index 70f762ffa..a70b35a42 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift @@ -7,7 +7,6 @@ import UIKit import Combine -import CoreDataStack import Meta import MetaTextKit import MastodonMeta @@ -310,11 +309,19 @@ extension ComposeContentViewModel { // bind author $authContext .sink { [weak self] authContext in - guard let self = self else { return } - guard let user = authContext.mastodonAuthenticationBox.authentication.user(in: self.context.managedObjectContext) else { return } - self.avatarURL = user.avatarImageURL() - self.name = user.nameMetaContent ?? PlaintextMetaContent(string: user.displayNameWithFallback) - self.username = user.acctWithDomain + guard let self, let account = authContext.mastodonAuthenticationBox.authentication.account() else { return } + + self.avatarURL = account.avatarImageURL() + + do { + let content = MastodonContent(content: account.displayNameWithFallback, emojis: (account.emojis ?? []).asDictionary) + let metaContent = try MastodonMetaContent.convert(document: content) + self.name = metaContent + } catch { + self.name = PlaintextMetaContent(string: account.displayNameWithFallback) + } + + self.username = account.acctWithDomain } .store(in: &disposeBag)