Tusker/Tusker/Views/StatusContentTextView.swift

53 lines
1.6 KiB
Swift

//
// StatusContentTextView.swift
// Tusker
//
// Created by Shadowfacts on 1/18/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class StatusContentTextView: ContentTextView {
private var statusID: String?
func setTextFrom(status: StatusMO) {
statusID = status.id
emojiIdentifier = status.id
setTextFromHtml(status.content)
setEmojis(status.emojis)
}
override func getMention(for url: URL, text: String) -> Mention? {
let mention: Mention?
if let statusID = statusID,
let mastodonController = mastodonController,
let status = mastodonController.persistentContainer.status(for: statusID) {
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!.serialized
}
} else {
mention = nil
}
return mention ?? super.getMention(for: url, text: text)
}
override func getHashtag(for url: URL, text: String) -> Hashtag? {
let hashtag: Hashtag?
if let statusID = statusID,
let mastodonController = mastodonController,
let status = mastodonController.persistentContainer.status(for: statusID) {
hashtag = status.hashtags.first { (hashtag) in
hashtag.url == url
}
} else {
hashtag = nil
}
return hashtag ?? super.getHashtag(for: url, text: text)
}
}