Don't add my own handle to a reply (#1254) (#1256)

* Don't add my own handle (#1254)

* Remove CoreData-stuff (#1254(

* Remove MastodonMentionContainer (#1254)

This is a left over from the status-refactoring. The Core Data-persistence-stuff for Status needed that, but as we don't use that any more say byebye
This commit is contained in:
Nathan Mattes 2024-03-19 10:28:16 +01:00 committed by GitHub
parent 484d72fbdd
commit 13cc2bdbec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 53 deletions

View File

@ -35,7 +35,7 @@ extension Status.Property {
deletedAt: nil,
attachments: entity.mastodonAttachments,
emojis: entity.mastodonEmojis,
mentions: entity.mastodonMentions
mentions: []
)
}
}

View File

@ -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 { }

View File

@ -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]

View File

@ -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