Mention everyone in reply

This commit is contained in:
Thomas Ricouard 2022-12-30 22:49:09 +01:00
parent 2bb68c915d
commit 639227be89
2 changed files with 11 additions and 2 deletions

View file

@ -48,6 +48,7 @@ public struct StatusEditorView: View {
} }
.onAppear { .onAppear {
viewModel.client = client viewModel.client = client
viewModel.currentAccount = currentAccount.account
viewModel.prepareStatusText() viewModel.prepareStatusText()
if !client.isAuth { if !client.isAuth {
dismiss() dismiss()

View file

@ -17,6 +17,7 @@ public class StatusEditorViewModel: ObservableObject {
let generator = UINotificationFeedbackGenerator() let generator = UINotificationFeedbackGenerator()
var client: Client? var client: Client?
var currentAccount: Account?
@Published var statusText = NSMutableAttributedString(string: "") { @Published var statusText = NSMutableAttributedString(string: "") {
didSet { didSet {
@ -40,6 +41,7 @@ public class StatusEditorViewModel: ObservableObject {
} }
} }
@Published var mediasImages: [ImageContainer] = [] @Published var mediasImages: [ImageContainer] = []
@Published var replyToStatus: Status?
@Published var embededStatus: Status? @Published var embededStatus: Status?
@Published var visibility: Models.Visibility = .pub @Published var visibility: Models.Visibility = .pub
@ -93,8 +95,14 @@ public class StatusEditorViewModel: ObservableObject {
func prepareStatusText() { func prepareStatusText() {
switch mode { switch mode {
case let .replyTo(status): case let .replyTo(status):
statusText = .init(string: "@\(status.reblog?.account.acct ?? status.account.acct) ") var mentionString = "@\(status.reblog?.account.acct ?? status.account.acct)"
selectedRange = .init(location: statusText.string.utf16.count, length: 0) for mention in status.mentions where mention.acct != currentAccount?.acct {
mentionString += " @\(mention.acct)"
}
mentionString += " "
replyToStatus = status
statusText = .init(string: mentionString)
selectedRange = .init(location: mentionString.utf16.count, length: 0)
case let .edit(status): case let .edit(status):
statusText = .init(status.content.asSafeAttributedString) statusText = .init(status.content.asSafeAttributedString)
selectedRange = .init(location: statusText.string.utf16.count, length: 0) selectedRange = .init(location: statusText.string.utf16.count, length: 0)