diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift index 1096af93a..92d53e020 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterEntities.swift @@ -14,18 +14,19 @@ protocol TwitterEntity { } extension TwitterEntity { - var startIndex: Int? { - if indices?.count ?? 0 > 0 { - return indices?[0] + + var startIndex: Int { + if let indices = indices, indices.count > 0 { + return indices[0] } - return nil + return 0 } - var endIndex: Int? { - if indices?.count ?? 0 > 1 { - return indices?[1] + var endIndex: Int { + if let indices = indices, indices.count > 1 { + return indices[1] } - return nil + return 0 } } @@ -58,7 +59,7 @@ struct TwitterEntities: Codable { if let symbols = symbols { entities.append(contentsOf: symbols) } - return entities + return entities.sorted(by: { $0.startIndex < $1.startIndex }) } } diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterHashtag.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterHashtag.swift index 1877347ef..a2a614e61 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterHashtag.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterHashtag.swift @@ -18,6 +18,13 @@ struct TwitterHashtag: Codable, TwitterEntity { case indices = "indices" } + var startIndex: Int { + if let indices = indices, indices.count > 0 { + return indices[0] - 1 + } + return 0 + } + func renderAsHTML() -> String { return "" } diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterSymbol.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterSymbol.swift index 2071c0b47..7c90d9300 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterSymbol.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterSymbol.swift @@ -18,6 +18,13 @@ struct TwitterSymbol: Codable, TwitterEntity { case indices = "indices" } + var startIndex: Int { + if let indices = indices, indices.count > 0 { + return indices[0] - 1 + } + return 0 + } + func renderAsHTML() -> String { return "" }