diff --git a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift index 2d054c83b..a54610b37 100644 --- a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift +++ b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift @@ -35,7 +35,7 @@ extension Status.Property { deletedAt: nil, attachments: entity.mastodonAttachments, emojis: entity.mastodonEmojis, - mentions: entity.mastodonMentions + mentions: [] ) } } diff --git a/MastodonSDK/Sources/MastodonCore/Persistence/Protocol/MastodonMentionContainer.swift b/MastodonSDK/Sources/MastodonCore/Persistence/Protocol/MastodonMentionContainer.swift deleted file mode 100644 index 75cae7573..000000000 --- a/MastodonSDK/Sources/MastodonCore/Persistence/Protocol/MastodonMentionContainer.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// MastodonMentionContainer.swift -// Mastodon -// -// Created by MainasuK on 2022-1-17. -// - -import Foundation -import CoreDataStack -import MastodonSDK - -public protocol MastodonMentionContainer { - var mentions: [Mastodon.Entity.Mention]? { get } -} - -extension MastodonMentionContainer { - public var mastodonMentions: [MastodonMention] { - return mentions.flatMap { mentions in - mentions.map { MastodonMention(mention: $0) } - } ?? [] - } -} - -extension Mastodon.Entity.Status: MastodonMentionContainer { } diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Status.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Status.swift index 5262bfef0..cf401e960 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Status.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Status.swift @@ -36,7 +36,7 @@ extension Mastodon.Entity { public let application: Application? // Rendering - public let mentions: [Mention]? + public let mentions: [Mention] public let tags: [Tag] public let emojis: [Emoji] diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift index a01cfa0cf..325cbc955 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/ComposeContentViewModel.swift @@ -193,34 +193,31 @@ public final class ComposeContentViewModel: NSObject, ObservableObject { let initialContentWithSpace = initialContent.isEmpty ? "" : initialContent + " " switch destination { case .reply(let record): - context.managedObjectContext.performAndWait { - let status = record.entity - let author = authContext.mastodonAuthenticationBox.authentication.account() - - var mentionAccts: [String] = [] - if author?.id != status.account.id { - mentionAccts.append("@" + status.account.acct) - } - let mentions = status.mentions ?? [] - .filter { author?.id != $0.id } - for mention in mentions { - let acct = "@" + mention.acct - guard !mentionAccts.contains(acct) else { continue } - mentionAccts.append(acct) - } - for acct in mentionAccts { - UITextChecker.learnWord(acct) - } - if let spoilerText = status.spoilerText, !spoilerText.isEmpty { - self.isContentWarningActive = true - self.contentWarning = spoilerText - } - - let initialComposeContent = mentionAccts.joined(separator: " ") - let preInsertedContent = initialComposeContent.isEmpty ? "" : initialComposeContent + " " - self.initialContent = preInsertedContent + initialContentWithSpace - self.content = preInsertedContent + initialContentWithSpace + let status = record.entity + let author = authContext.mastodonAuthenticationBox.authentication.account() + + var mentionAccts: [String] = [] + if author?.id != status.account.id { + mentionAccts.append("@" + status.account.acct) } + let mentions = status.mentions.filter { author?.id != $0.id } + for mention in mentions { + let acct = "@" + mention.acct + guard !mentionAccts.contains(acct) else { continue } + mentionAccts.append(acct) + } + for acct in mentionAccts { + UITextChecker.learnWord(acct) + } + if let spoilerText = status.spoilerText, !spoilerText.isEmpty { + self.isContentWarningActive = true + self.contentWarning = spoilerText + } + + let initialComposeContent = mentionAccts.joined(separator: " ") + let preInsertedContent = initialComposeContent.isEmpty ? "" : initialComposeContent + " " + self.initialContent = preInsertedContent + initialContentWithSpace + self.content = preInsertedContent + initialContentWithSpace case .topLevel: self.initialContent = initialContentWithSpace self.content = initialContentWithSpace