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
|
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?
|
|
|
|
|
|
|
|
func setTextFrom(status: StatusMO) {
|
|
|
|
statusID = status.id
|
|
|
|
setTextFromHtml(status.content)
|
|
|
|
setEmojis(status.emojis)
|
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
|
|
|
|
// Mastodon and Pleroma include the @ in the <a> text, GNU Social does not
|
|
|
|
(text.dropFirst() == mention.username || text == mention.username) && url.host == mention.url.host
|
|
|
|
}
|
|
|
|
} 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
|
|
|
|
hashtag.url == url
|
|
|
|
}
|
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
|
|
|
}
|