Guard against invalid emoji URLs
This commit is contained in:
parent
9f350d1305
commit
014278f855
|
@ -89,7 +89,10 @@ extension CollectionItem {
|
|||
|
||||
private extension Account {
|
||||
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
|
||||
&& identityContext.appPreferences.animateAvatars == .everywhere {
|
||||
|
@ -106,6 +109,9 @@ private extension Status {
|
|||
func mediaPrefetchURLs(identityContext: IdentityContext) -> Set<URL> {
|
||||
displayStatus.account.mediaPrefetchURLs(identityContext: identityContext)
|
||||
.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) {
|
||||
let attachment = AnimatedTextAttachment()
|
||||
let imageURL: URL
|
||||
let imageURL: URL?
|
||||
|
||||
if !identityContext.appPreferences.shouldReduceMotion,
|
||||
identityContext.appPreferences.animateCustomEmojis {
|
||||
imageURL = emoji.url
|
||||
identityContext.appPreferences.animateCustomEmojis,
|
||||
let urlString = emoji.url {
|
||||
imageURL = URL(string: urlString)
|
||||
} else if let staticURLString = emoji.staticUrl {
|
||||
imageURL = URL(string: staticURLString)
|
||||
} else {
|
||||
imageURL = emoji.staticUrl
|
||||
imageURL = nil
|
||||
}
|
||||
|
||||
attachment.imageView.sd_setImage(with: imageURL) { image, _, _, _ in
|
||||
|
|
|
@ -4,8 +4,8 @@ import Foundation
|
|||
|
||||
public struct Emoji: Codable, Hashable {
|
||||
public let shortcode: String
|
||||
public let staticUrl: URL
|
||||
public let url: URL
|
||||
public let staticUrl: String?
|
||||
public let url: String?
|
||||
public let visibleInPicker: Bool
|
||||
public let category: String?
|
||||
}
|
||||
|
|
|
@ -21,10 +21,12 @@ public extension EmojiViewModel {
|
|||
var url: URL? {
|
||||
guard case let .custom(emoji, _) = emoji else { return nil }
|
||||
|
||||
if identityContext.appPreferences.animateCustomEmojis {
|
||||
return emoji.url
|
||||
} else {
|
||||
return emoji.staticUrl
|
||||
if identityContext.appPreferences.animateCustomEmojis, let urlString = emoji.url {
|
||||
return URL(string: urlString)
|
||||
} else if let staticURLString = emoji.staticUrl {
|
||||
return URL(string: staticURLString)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue