Convert status to local URL when quoting

This commit is contained in:
Thomas Ricouard 2022-12-30 10:11:05 +01:00
parent e93e05872a
commit d61ce04dac
3 changed files with 15 additions and 6 deletions

View file

@ -35,7 +35,7 @@ struct SettingsTabs: View {
} }
private var accountsSection: some View { private var accountsSection: some View {
Section("Account") { Section("Accounts") {
ForEach(appAccountsManager.availableAccounts) { account in ForEach(appAccountsManager.availableAccounts) { account in
HStack { HStack {
AppAccountView(viewModel: .init(appAccount: account)) AppAccountView(viewModel: .init(appAccount: account))

View file

@ -31,7 +31,7 @@ extension HTMLString {
var ids: [Int] = [] var ids: [Int] = []
for link in links { for link in links {
let href = try link.attr("href") let href = try link.attr("href")
if href.contains(instance), if href.contains(instance.lowercased()),
let url = URL(string: href), let url = URL(string: href),
let statusId = Int(url.lastPathComponent) { let statusId = Int(url.lastPathComponent) {
ids.append(statusId) ids.append(statusId)
@ -47,8 +47,7 @@ extension HTMLString {
do { do {
// Add space between hashtags and mentions that follow each other // Add space between hashtags and mentions that follow each other
let markdown = asMarkdown let markdown = asMarkdown
.replacingOccurrences(of: ")[#", with: ") [#") .replacingOccurrences(of: ")[", with: ") [")
.replacingOccurrences(of: ")[@", with: ") [@")
let options = AttributedString.MarkdownParsingOptions(allowsExtendedAttributes: true, let options = AttributedString.MarkdownParsingOptions(allowsExtendedAttributes: true,
interpretedSyntax: .inlineOnlyPreservingWhitespace) interpretedSyntax: .inlineOnlyPreservingWhitespace)
return try AttributedString(markdown: markdown, options: options) return try AttributedString(markdown: markdown, options: options)

View file

@ -86,6 +86,14 @@ public class StatusEditorViewModel: ObservableObject {
} }
} }
func localURLforStatus(status: Status) -> URL? {
guard let server = client?.server else { return nil }
if status.url?.host == server.lowercased() {
return status.url
}
return URL(string: "https://\(server.lowercased())/@\(status.account.acct)/\(status.id)")
}
func prepareStatusText() { func prepareStatusText() {
switch mode { switch mode {
case let .replyTo(status): case let .replyTo(status):
@ -99,7 +107,7 @@ public class StatusEditorViewModel: ObservableObject {
mediasImages = status.mediaAttachments.map{ .init(image: nil, mediaAttachement: $0, error: nil )} mediasImages = status.mediaAttachments.map{ .init(image: nil, mediaAttachement: $0, error: nil )}
case let .quote(status): case let .quote(status):
self.embededStatus = status self.embededStatus = status
if let url = status.reblog?.url ?? status.url { if let url = localURLforStatus(status: status) {
statusText = .init(string: "\n\nFrom: @\(status.reblog?.account.acct ?? status.account.acct)\n\(url)") statusText = .init(string: "\n\nFrom: @\(status.reblog?.account.acct ?? status.account.acct)\n\(url)")
selectedRange = .init(location: 0, length: 0) selectedRange = .init(location: 0, length: 0)
} }
@ -148,7 +156,9 @@ public class StatusEditorViewModel: ObservableObject {
} }
private func checkEmbed() { private func checkEmbed() {
if let embededStatus, !statusText.string.contains(embededStatus.reblog?.id ?? embededStatus.id) { if let embededStatus,
let url = localURLforStatus(status: embededStatus),
!statusText.string.contains(url.absoluteString) {
self.embededStatus = nil self.embededStatus = nil
self.mode = .new self.mode = .new
} }