Tusker/Tusker/Views/StatusContentLabel.swift

37 lines
961 B
Swift
Raw Normal View History

2018-08-26 18:49:22 +00:00
//
// StatusContentLabel.swift
// Tusker
//
2018-08-28 01:27:34 +00:00
// Created by Shadowfacts on 8/27/18.
2018-08-26 18:49:22 +00:00
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
import MastodonKit
2018-08-26 18:49:22 +00:00
2018-08-28 01:27:34 +00:00
class StatusContentLabel: HTMLContentLabel {
2018-08-26 18:49:22 +00:00
var status: Status! {
didSet {
text = status.content
}
}
2018-08-28 01:27:34 +00:00
override func getMention(for url: URL, text: String) -> Mention? {
return status.mentions.first(where: { mention -> Bool in
(text.dropFirst() == mention.username || text == mention.username) && url.host == URL(string: mention.url)!.host
2018-08-28 01:27:34 +00:00
}) ?? super.getMention(for: url, text: text)
}
2018-08-28 01:27:34 +00:00
override func getTag(for url: URL, text: String) -> MastodonKit.Tag? {
if let tag = status.tags.first(where: { tag -> Bool in
tag.url == url.absoluteString
}) {
return tag
} else {
2018-08-28 01:27:34 +00:00
return super.getTag(for: url, text: text)
2018-08-26 19:19:54 +00:00
}
2018-08-26 18:49:22 +00:00
}
}