mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 18:21:00 +00:00
Convert status to local URL when quoting
This commit is contained in:
parent
e93e05872a
commit
d61ce04dac
3 changed files with 15 additions and 6 deletions
|
@ -35,7 +35,7 @@ struct SettingsTabs: View {
|
|||
}
|
||||
|
||||
private var accountsSection: some View {
|
||||
Section("Account") {
|
||||
Section("Accounts") {
|
||||
ForEach(appAccountsManager.availableAccounts) { account in
|
||||
HStack {
|
||||
AppAccountView(viewModel: .init(appAccount: account))
|
||||
|
|
|
@ -31,7 +31,7 @@ extension HTMLString {
|
|||
var ids: [Int] = []
|
||||
for link in links {
|
||||
let href = try link.attr("href")
|
||||
if href.contains(instance),
|
||||
if href.contains(instance.lowercased()),
|
||||
let url = URL(string: href),
|
||||
let statusId = Int(url.lastPathComponent) {
|
||||
ids.append(statusId)
|
||||
|
@ -47,8 +47,7 @@ extension HTMLString {
|
|||
do {
|
||||
// Add space between hashtags and mentions that follow each other
|
||||
let markdown = asMarkdown
|
||||
.replacingOccurrences(of: ")[#", with: ") [#")
|
||||
.replacingOccurrences(of: ")[@", with: ") [@")
|
||||
.replacingOccurrences(of: ")[", with: ") [")
|
||||
let options = AttributedString.MarkdownParsingOptions(allowsExtendedAttributes: true,
|
||||
interpretedSyntax: .inlineOnlyPreservingWhitespace)
|
||||
return try AttributedString(markdown: markdown, options: options)
|
||||
|
|
|
@ -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() {
|
||||
switch mode {
|
||||
case let .replyTo(status):
|
||||
|
@ -99,7 +107,7 @@ public class StatusEditorViewModel: ObservableObject {
|
|||
mediasImages = status.mediaAttachments.map{ .init(image: nil, mediaAttachement: $0, error: nil )}
|
||||
case let .quote(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)")
|
||||
selectedRange = .init(location: 0, length: 0)
|
||||
}
|
||||
|
@ -148,7 +156,9 @@ public class StatusEditorViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
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.mode = .new
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue