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 {
viewModel.client = client
viewModel.currentAccount = currentAccount.account
viewModel.prepareStatusText()
if !client.isAuth {
dismiss()

View file

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