2018-08-26 18:49:22 +00:00
|
|
|
//
|
2020-01-18 21:00:38 +00:00
|
|
|
// StatusContentTextView.swift
|
2018-08-26 18:49:22 +00:00
|
|
|
// Tusker
|
|
|
|
//
|
2020-01-18 21:00:38 +00:00
|
|
|
// Created by Shadowfacts on 1/18/20.
|
|
|
|
// Copyright © 2020 Shadowfacts. All rights reserved.
|
2018-08-26 18:49:22 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2018-09-11 14:52:21 +00:00
|
|
|
import Pachyderm
|
2022-07-09 15:45:27 +00:00
|
|
|
import WebURLFoundationExtras
|
2018-08-26 18:49:22 +00:00
|
|
|
|
2020-01-18 21:00:38 +00:00
|
|
|
class StatusContentTextView: ContentTextView {
|
|
|
|
|
2020-06-16 03:22:34 +00:00
|
|
|
private var statusID: String?
|
|
|
|
|
2022-12-04 17:08:22 +00:00
|
|
|
func setTextFrom(status: StatusMO, precomputed attributedText: NSAttributedString? = nil) {
|
2020-06-16 03:22:34 +00:00
|
|
|
statusID = status.id
|
2022-12-04 17:08:22 +00:00
|
|
|
if let attributedText {
|
|
|
|
self.attributedText = attributedText
|
|
|
|
} else {
|
|
|
|
setTextFromHtml(status.content)
|
|
|
|
}
|
2022-09-12 02:19:54 +00:00
|
|
|
setEmojis(status.emojis, identifier: status.id)
|
2018-08-27 16:40:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
override func getMention(for url: URL, text: String) -> Mention? {
|
2018-10-01 19:14:09 +00:00
|
|
|
let mention: Mention?
|
|
|
|
if let statusID = statusID,
|
2020-01-06 00:54:28 +00:00
|
|
|
let mastodonController = mastodonController,
|
2020-05-02 23:52:35 +00:00
|
|
|
let status = mastodonController.persistentContainer.status(for: statusID) {
|
2018-10-01 19:14:09 +00:00
|
|
|
mention = status.mentions.first { (mention) in
|
2022-10-10 18:31:26 +00:00
|
|
|
url.host == mention.url.host!.serialized && (
|
|
|
|
text.dropFirst() == mention.username // Mastodon and Pleroma include @ in the text
|
|
|
|
|| text.dropFirst() == mention.acct // Misskey includes @ and uses the whole acct
|
|
|
|
|| text == mention.username // GNU Social does not include the @ in the text, so we don't need to drop it
|
|
|
|
)
|
2018-10-01 19:14:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mention = nil
|
|
|
|
}
|
|
|
|
return mention ?? super.getMention(for: url, text: text)
|
2018-08-27 16:40:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-01 19:14:09 +00:00
|
|
|
override func getHashtag(for url: URL, text: String) -> Hashtag? {
|
|
|
|
let hashtag: Hashtag?
|
|
|
|
if let statusID = statusID,
|
2020-01-06 00:54:28 +00:00
|
|
|
let mastodonController = mastodonController,
|
2020-05-02 23:52:35 +00:00
|
|
|
let status = mastodonController.persistentContainer.status(for: statusID) {
|
2018-10-01 19:14:09 +00:00
|
|
|
hashtag = status.hashtags.first { (hashtag) in
|
2022-07-09 15:45:27 +00:00
|
|
|
URL(hashtag.url) == url
|
2018-10-01 19:14:09 +00:00
|
|
|
}
|
2018-08-27 16:40:22 +00:00
|
|
|
} else {
|
2018-10-01 19:14:09 +00:00
|
|
|
hashtag = nil
|
2018-08-26 19:19:54 +00:00
|
|
|
}
|
2018-10-01 19:14:09 +00:00
|
|
|
return hashtag ?? super.getHashtag(for: url, text: text)
|
2018-08-26 18:49:22 +00:00
|
|
|
}
|
2020-01-18 21:00:38 +00:00
|
|
|
|
2018-08-26 18:49:22 +00:00
|
|
|
}
|