mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Unify link preview image size
This commit is contained in:
parent
96279df59b
commit
686f3c4a75
@ -22,6 +22,31 @@ import ChatControllerInteraction
|
|||||||
|
|
||||||
private let titleFont: UIFont = Font.semibold(15.0)
|
private let titleFont: UIFont = Font.semibold(15.0)
|
||||||
|
|
||||||
|
public func defaultWebpageImageSizeIsSmall(webpage: TelegramMediaWebpageLoadedContent) -> Bool {
|
||||||
|
let type = websiteType(of: webpage.websiteName)
|
||||||
|
|
||||||
|
let mainMedia: Media?
|
||||||
|
switch type {
|
||||||
|
case .instagram, .twitter:
|
||||||
|
mainMedia = webpage.story ?? webpage.image ?? webpage.file
|
||||||
|
default:
|
||||||
|
mainMedia = webpage.story ?? webpage.file ?? webpage.image
|
||||||
|
}
|
||||||
|
|
||||||
|
if let image = mainMedia as? TelegramMediaImage {
|
||||||
|
if let type = webpage.type, (["photo", "video", "embed", "gif", "document", "telegram_album"] as [String]).contains(type) {
|
||||||
|
} else if let type = webpage.type, (["article"] as [String]).contains(type) {
|
||||||
|
return true
|
||||||
|
} else if let _ = largestImageRepresentation(image.representations)?.dimensions {
|
||||||
|
if webpage.instantPage == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
public final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContentNode {
|
public final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContentNode {
|
||||||
private var webPage: TelegramMediaWebpage?
|
private var webPage: TelegramMediaWebpage?
|
||||||
|
|
||||||
@ -309,10 +334,7 @@ public final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContent
|
|||||||
}
|
}
|
||||||
mediaAndFlags = (image, flags)
|
mediaAndFlags = (image, flags)
|
||||||
} else if let _ = largestImageRepresentation(image.representations)?.dimensions {
|
} else if let _ = largestImageRepresentation(image.representations)?.dimensions {
|
||||||
var flags = ChatMessageAttachedContentNodeMediaFlags()
|
let flags = ChatMessageAttachedContentNodeMediaFlags()
|
||||||
if webpage.instantPage == nil {
|
|
||||||
flags.insert(.preferMediaInline)
|
|
||||||
}
|
|
||||||
mediaAndFlags = (image, flags)
|
mediaAndFlags = (image, flags)
|
||||||
}
|
}
|
||||||
} else if let story = mainMedia as? TelegramMediaStory {
|
} else if let story = mainMedia as? TelegramMediaStory {
|
||||||
@ -441,6 +463,10 @@ public final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if defaultWebpageImageSizeIsSmall(webpage: webpage) {
|
||||||
|
mediaAndFlags?.1.insert(.preferMediaInline)
|
||||||
|
}
|
||||||
|
|
||||||
if let webPageContent, let isMediaLargeByDefault = webPageContent.isMediaLargeByDefault, !isMediaLargeByDefault {
|
if let webPageContent, let isMediaLargeByDefault = webPageContent.isMediaLargeByDefault, !isMediaLargeByDefault {
|
||||||
mediaAndFlags?.1.insert(.preferMediaInline)
|
mediaAndFlags?.1.insert(.preferMediaInline)
|
||||||
} else if let attribute = item.message.attributes.first(where: { $0 is WebpagePreviewMessageAttribute }) as? WebpagePreviewMessageAttribute {
|
} else if let attribute = item.message.attributes.first(where: { $0 is WebpagePreviewMessageAttribute }) as? WebpagePreviewMessageAttribute {
|
||||||
|
@ -16,6 +16,7 @@ import TextFormat
|
|||||||
import ChatMessageItemView
|
import ChatMessageItemView
|
||||||
import ChatMessageBubbleItemNode
|
import ChatMessageBubbleItemNode
|
||||||
import TelegramNotices
|
import TelegramNotices
|
||||||
|
import ChatMessageWebpageBubbleContentNode
|
||||||
|
|
||||||
private enum OptionsId: Hashable {
|
private enum OptionsId: Hashable {
|
||||||
case reply
|
case reply
|
||||||
@ -710,7 +711,13 @@ private func chatLinkOptions(selfController: ChatControllerImpl, sourceNode: ASD
|
|||||||
|
|
||||||
var largeMedia = false
|
var largeMedia = false
|
||||||
if webpageHasLargeMedia {
|
if webpageHasLargeMedia {
|
||||||
largeMedia = urlPreview.largeMedia ?? true
|
if let value = urlPreview.largeMedia {
|
||||||
|
largeMedia = value
|
||||||
|
} else if case let .Loaded(content) = urlPreview.webPage.content {
|
||||||
|
largeMedia = !defaultWebpageImageSizeIsSmall(webpage: content)
|
||||||
|
} else {
|
||||||
|
largeMedia = true
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
largeMedia = false
|
largeMedia = false
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user