mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Guard against invalid emoji URLs
This commit is contained in:
parent
9f350d1305
commit
014278f855
4 changed files with 23 additions and 12 deletions
|
@ -89,7 +89,10 @@ extension CollectionItem {
|
||||||
|
|
||||||
private extension Account {
|
private extension Account {
|
||||||
func mediaPrefetchURLs(identityContext: IdentityContext) -> Set<URL> {
|
func mediaPrefetchURLs(identityContext: IdentityContext) -> Set<URL> {
|
||||||
var urls = Set(emojis.map(\.url))
|
var urls = Set(emojis.compactMap {
|
||||||
|
identityContext.appPreferences.animateCustomEmojis ? $0.url : $0.staticUrl
|
||||||
|
}
|
||||||
|
.compactMap(URL.init(string:)))
|
||||||
|
|
||||||
if !identityContext.appPreferences.shouldReduceMotion
|
if !identityContext.appPreferences.shouldReduceMotion
|
||||||
&& identityContext.appPreferences.animateAvatars == .everywhere {
|
&& identityContext.appPreferences.animateAvatars == .everywhere {
|
||||||
|
@ -106,6 +109,9 @@ private extension Status {
|
||||||
func mediaPrefetchURLs(identityContext: IdentityContext) -> Set<URL> {
|
func mediaPrefetchURLs(identityContext: IdentityContext) -> Set<URL> {
|
||||||
displayStatus.account.mediaPrefetchURLs(identityContext: identityContext)
|
displayStatus.account.mediaPrefetchURLs(identityContext: identityContext)
|
||||||
.union(displayStatus.mediaAttachments.compactMap(\.previewUrl))
|
.union(displayStatus.mediaAttachments.compactMap(\.previewUrl))
|
||||||
.union(displayStatus.emojis.map(\.url))
|
.union(displayStatus.emojis.compactMap {
|
||||||
|
identityContext.appPreferences.animateCustomEmojis ? $0.url : $0.staticUrl
|
||||||
|
}
|
||||||
|
.compactMap(URL.init(string:)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,16 @@ extension NSMutableAttributedString {
|
||||||
|
|
||||||
while let tokenRange = string.range(of: token) {
|
while let tokenRange = string.range(of: token) {
|
||||||
let attachment = AnimatedTextAttachment()
|
let attachment = AnimatedTextAttachment()
|
||||||
let imageURL: URL
|
let imageURL: URL?
|
||||||
|
|
||||||
if !identityContext.appPreferences.shouldReduceMotion,
|
if !identityContext.appPreferences.shouldReduceMotion,
|
||||||
identityContext.appPreferences.animateCustomEmojis {
|
identityContext.appPreferences.animateCustomEmojis,
|
||||||
imageURL = emoji.url
|
let urlString = emoji.url {
|
||||||
|
imageURL = URL(string: urlString)
|
||||||
|
} else if let staticURLString = emoji.staticUrl {
|
||||||
|
imageURL = URL(string: staticURLString)
|
||||||
} else {
|
} else {
|
||||||
imageURL = emoji.staticUrl
|
imageURL = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
attachment.imageView.sd_setImage(with: imageURL) { image, _, _, _ in
|
attachment.imageView.sd_setImage(with: imageURL) { image, _, _, _ in
|
||||||
|
|
|
@ -4,8 +4,8 @@ import Foundation
|
||||||
|
|
||||||
public struct Emoji: Codable, Hashable {
|
public struct Emoji: Codable, Hashable {
|
||||||
public let shortcode: String
|
public let shortcode: String
|
||||||
public let staticUrl: URL
|
public let staticUrl: String?
|
||||||
public let url: URL
|
public let url: String?
|
||||||
public let visibleInPicker: Bool
|
public let visibleInPicker: Bool
|
||||||
public let category: String?
|
public let category: String?
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,12 @@ public extension EmojiViewModel {
|
||||||
var url: URL? {
|
var url: URL? {
|
||||||
guard case let .custom(emoji, _) = emoji else { return nil }
|
guard case let .custom(emoji, _) = emoji else { return nil }
|
||||||
|
|
||||||
if identityContext.appPreferences.animateCustomEmojis {
|
if identityContext.appPreferences.animateCustomEmojis, let urlString = emoji.url {
|
||||||
return emoji.url
|
return URL(string: urlString)
|
||||||
} else {
|
} else if let staticURLString = emoji.staticUrl {
|
||||||
return emoji.staticUrl
|
return URL(string: staticURLString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue