From 65b95e1510435830e2656da763b8bfb554066ec9 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sat, 6 Feb 2021 13:26:42 -0800 Subject: [PATCH] Fix composition mention population --- .../ViewModels/View Models/NewStatusViewModel.swift | 12 +++++++++++- .../ViewModels/View Models/StatusViewModel.swift | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ViewModels/Sources/ViewModels/View Models/NewStatusViewModel.swift b/ViewModels/Sources/ViewModels/View Models/NewStatusViewModel.swift index 536fbb5..1940fba 100644 --- a/ViewModels/Sources/ViewModels/View Models/NewStatusViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/NewStatusViewModel.swift @@ -65,7 +65,17 @@ public final class NewStatusViewModel: ObservableObject { } if let inReplyTo = inReplyTo, redraft == nil { - compositionViewModel.text = inReplyTo.accountName.appending(" ") + var mentions = Set() + + if !inReplyTo.isMine { + mentions.insert(inReplyTo.accountName) + } + + mentions.formUnion(inReplyTo.mentions.map(\.acct) + .filter { $0 != identityContext.identity.account?.username } + .map("@".appending)) + + compositionViewModel.text = mentions.joined(separator: " ").appending(" ") } compositionViewModels = [compositionViewModel] diff --git a/ViewModels/Sources/ViewModels/View Models/StatusViewModel.swift b/ViewModels/Sources/ViewModels/View Models/StatusViewModel.swift index 3d071b7..ff93030 100644 --- a/ViewModels/Sources/ViewModels/View Models/StatusViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/StatusViewModel.swift @@ -108,6 +108,8 @@ public extension StatusViewModel { return URL(string: website) } + var mentions: [Mention] { statusService.status.displayStatus.mentions } + var visibility: Status.Visibility { statusService.status.displayStatus.visibility } var repliesCount: Int { statusService.status.displayStatus.repliesCount }