From bb61b15265a2ba30cc1119ea886d898d7e5f612f Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 19 Apr 2020 19:19:39 -0500 Subject: [PATCH] Stub out support for Twitter entities --- .../Twitter/TwitterEntities.swift | 39 +++++++++++++++++++ .../FeedProvider/Twitter/TwitterHashtag.swift | 5 ++- .../FeedProvider/Twitter/TwitterMention.swift | 6 ++- .../FeedProvider/Twitter/TwitterSymbol.swift | 6 ++- .../FeedProvider/Twitter/TwitterURL.swift | 6 ++- 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift index 79d7703d7..1096af93a 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift @@ -8,6 +8,28 @@ import Foundation +protocol TwitterEntity { + var indices: [Int]? { get } + func renderAsHTML() -> String +} + +extension TwitterEntity { + var startIndex: Int? { + if indices?.count ?? 0 > 0 { + return indices?[0] + } + return nil + } + + var endIndex: Int? { + if indices?.count ?? 0 > 1 { + return indices?[1] + } + return nil + } + +} + struct TwitterEntities: Codable { let hashtags: [TwitterHashtag]? @@ -22,4 +44,21 @@ struct TwitterEntities: Codable { case symbols = "symbols" } + func combineAndSort() -> [TwitterEntity] { + var entities = [TwitterEntity]() + if let hashtags = hashtags { + entities.append(contentsOf: hashtags) + } + if let urls = urls { + entities.append(contentsOf: urls) + } + if let userMentions = userMentions { + entities.append(contentsOf: userMentions) + } + if let symbols = symbols { + entities.append(contentsOf: symbols) + } + return entities + } + } diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterHashtag.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterHashtag.swift index 92f6c4237..1877347ef 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterHashtag.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterHashtag.swift @@ -8,7 +8,7 @@ import Foundation -struct TwitterHashtag: Codable { +struct TwitterHashtag: Codable, TwitterEntity { let text: String? let indices: [Int]? @@ -18,4 +18,7 @@ struct TwitterHashtag: Codable { case indices = "indices" } + func renderAsHTML() -> String { + return "" + } } diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterMention.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterMention.swift index a923b4bdb..72310c8ae 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterMention.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterMention.swift @@ -8,7 +8,7 @@ import Foundation -struct TwitterMention: Codable { +struct TwitterMention: Codable, TwitterEntity { let name: String? let indices: [Int]? @@ -24,4 +24,8 @@ struct TwitterMention: Codable { case idStr = "idStr" } + func renderAsHTML() -> String { + return "" + } + } diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterSymbol.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterSymbol.swift index 881204cec..2071c0b47 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterSymbol.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterSymbol.swift @@ -8,7 +8,7 @@ import Foundation -struct TwitterSymbol: Codable { +struct TwitterSymbol: Codable, TwitterEntity { let name: String? let indices: [Int]? @@ -18,4 +18,8 @@ struct TwitterSymbol: Codable { case indices = "indices" } + func renderAsHTML() -> String { + return "" + } + } diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterURL.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterURL.swift index f0be16646..5c8c8d2da 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterURL.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterURL.swift @@ -8,7 +8,7 @@ import Foundation -struct TwitterURL: Codable { +struct TwitterURL: Codable, TwitterEntity { let url: String? let indices: [Int]? @@ -22,4 +22,8 @@ struct TwitterURL: Codable { case expandedURL = "expandedURL" } + func renderAsHTML() -> String { + return "" + } + }