Tusker/Tusker/Views/StatusContentTextView.swift

53 lines
1.6 KiB
Swift
Raw Normal View History

2018-08-26 18:49:22 +00:00
//
// StatusContentTextView.swift
2018-08-26 18:49:22 +00:00
// Tusker
//
// 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
class StatusContentTextView: ContentTextView {
private var statusID: String?
func setTextFrom(status: StatusMO) {
statusID = status.id
2021-11-07 18:11:49 +00:00
emojiIdentifier = status.id
setTextFromHtml(status.content)
setEmojis(status.emojis)
}
2018-08-28 01:27:34 +00:00
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!
}
} 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
2018-08-26 19:19:54 +00:00
}
return hashtag ?? super.getHashtag(for: url, text: text)
2018-08-26 18:49:22 +00:00
}
2018-08-26 18:49:22 +00:00
}