forked from shadowfacts/Tusker
51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
//
|
|
// StatusContentLabel.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 10/1/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Pachyderm
|
|
|
|
class StatusContentLabel: ContentLabel {
|
|
|
|
var statusID: String? {
|
|
didSet {
|
|
guard let statusID = statusID else { return }
|
|
guard let status = MastodonCache.status(for: statusID) else { fatalError("Can't set StatusContentLabel text without cached status \(statusID)") }
|
|
setTextFromHtml(status.content)
|
|
setEmojis(status.emojis)
|
|
}
|
|
}
|
|
|
|
override func getMention(for url: URL, text: String) -> Mention? {
|
|
let mention: Mention?
|
|
if let statusID = statusID,
|
|
let status = MastodonCache.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 status = MastodonCache.status(for: statusID) {
|
|
hashtag = status.hashtags.first { (hashtag) in
|
|
hashtag.url == url
|
|
}
|
|
} else {
|
|
hashtag = nil
|
|
}
|
|
return hashtag ?? super.getHashtag(for: url, text: text)
|
|
}
|
|
|
|
}
|