mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix media fetch cancellation
This commit is contained in:
parent
620e96731b
commit
c59ca0a993
@ -46,8 +46,8 @@ public func messageMediaFileCancelInteractiveFetch(context: AccountContext, mess
|
|||||||
context.fetchManager.cancelInteractiveFetches(category: fetchCategoryForFile(file), location: .chat(messageId.peerId), locationKey: .messageId(messageId), resource: file.resource)
|
context.fetchManager.cancelInteractiveFetches(category: fetchCategoryForFile(file), location: .chat(messageId.peerId), locationKey: .messageId(messageId), resource: file.resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func messageMediaImageInteractiveFetched(context: AccountContext, message: Message, image: TelegramMediaImage, resource: MediaResource, range: Range<Int>? = nil, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal<Void, NoError> {
|
public func messageMediaImageInteractiveFetched(context: AccountContext, message: Message, image: TelegramMediaImage, resource: MediaResource, range: Range<Int>? = nil, userInitiated: Bool = true, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal<Void, NoError> {
|
||||||
return messageMediaImageInteractiveFetched(fetchManager: context.fetchManager, messageId: message.id, messageReference: MessageReference(message), image: image, resource: resource, range: range, userInitiated: true, priority: .userInitiated, storeToDownloadsPeerType: storeToDownloadsPeerType)
|
return messageMediaImageInteractiveFetched(fetchManager: context.fetchManager, messageId: message.id, messageReference: MessageReference(message), image: image, resource: resource, range: range, userInitiated: userInitiated, priority: .userInitiated, storeToDownloadsPeerType: storeToDownloadsPeerType)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func messageMediaImageInteractiveFetched(fetchManager: FetchManager, messageId: MessageId, messageReference: MessageReference, image: TelegramMediaImage, resource: MediaResource, range: Range<Int>? = nil, userInitiated: Bool, priority: FetchManagerPriority, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal<Void, NoError> {
|
public func messageMediaImageInteractiveFetched(fetchManager: FetchManager, messageId: MessageId, messageReference: MessageReference, image: TelegramMediaImage, resource: MediaResource, range: Range<Int>? = nil, userInitiated: Bool, priority: FetchManagerPriority, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal<Void, NoError> {
|
||||||
|
@ -1699,13 +1699,41 @@ public func standaloneChatMessagePhotoInteractiveFetched(account: Account, photo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func chatMessagePhotoInteractiveFetched(context: AccountContext, photoReference: ImageMediaReference, displayAtSize: Int?, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal<FetchResourceSourceType, FetchResourceError> {
|
public func chatMessagePhotoInteractiveFetched(context: AccountContext, photoReference: ImageMediaReference, displayAtSize: Int?, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal<Never, NoError> {
|
||||||
if let largestRepresentation = largestRepresentationForPhoto(photoReference.media) {
|
if let largestRepresentation = largestRepresentationForPhoto(photoReference.media) {
|
||||||
var fetchRange: (Range<Int>, MediaBoxFetchPriority)?
|
var fetchRange: (Range<Int>, MediaBoxFetchPriority)?
|
||||||
if let displayAtSize = displayAtSize, let range = representationFetchRangeForDisplayAtSize(representation: largestRepresentation, dimension: displayAtSize) {
|
if let displayAtSize = displayAtSize, let range = representationFetchRangeForDisplayAtSize(representation: largestRepresentation, dimension: displayAtSize) {
|
||||||
fetchRange = (range, .default)
|
fetchRange = (range, .default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*switch photoReference {
|
||||||
|
case let .message(message, _):
|
||||||
|
if let id = message.id {
|
||||||
|
let ranges: IndexSet
|
||||||
|
if let (range, _) = fetchRange {
|
||||||
|
ranges = IndexSet(integersIn: range)
|
||||||
|
} else {
|
||||||
|
ranges = IndexSet(integersIn: 0 ..< Int(Int32.max) as Range<Int>)
|
||||||
|
}
|
||||||
|
return context.fetchManager.interactivelyFetched(
|
||||||
|
category: .image,
|
||||||
|
location: .chat(id.peerId),
|
||||||
|
locationKey: .messageId(id),
|
||||||
|
mediaReference: photoReference.abstract,
|
||||||
|
resourceReference: photoReference.resourceReference(largestRepresentation.resource),
|
||||||
|
ranges: ranges,
|
||||||
|
statsCategory: .image,
|
||||||
|
elevatedPriority: false,
|
||||||
|
userInitiated: false,
|
||||||
|
priority: .userInitiated,
|
||||||
|
storeToDownloadsPeerType: nil
|
||||||
|
)
|
||||||
|
|> ignoreValues
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}*/
|
||||||
|
|
||||||
return fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, reference: photoReference.resourceReference(largestRepresentation.resource), range: fetchRange, statsCategory: .image, reportResultStatus: true)
|
return fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, reference: photoReference.resourceReference(largestRepresentation.resource), range: fetchRange, statsCategory: .image, reportResultStatus: true)
|
||||||
|> mapToSignal { type -> Signal<FetchResourceSourceType, FetchResourceError> in
|
|> mapToSignal { type -> Signal<FetchResourceSourceType, FetchResourceError> in
|
||||||
if case .remote = type, let peerType = storeToDownloadsPeerType {
|
if case .remote = type, let peerType = storeToDownloadsPeerType {
|
||||||
@ -1717,6 +1745,10 @@ public func chatMessagePhotoInteractiveFetched(context: AccountContext, photoRef
|
|||||||
}
|
}
|
||||||
return .single(type)
|
return .single(type)
|
||||||
}
|
}
|
||||||
|
|> ignoreValues
|
||||||
|
|> `catch` { _ -> Signal<Never, NoError> in
|
||||||
|
return .complete()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return .never()
|
return .never()
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,15 @@ public struct MessageReference: PostboxCoding, Hashable, Equatable {
|
|||||||
return peer
|
return peer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var id: MessageId? {
|
||||||
|
switch content {
|
||||||
|
case .none:
|
||||||
|
return nil
|
||||||
|
case let .message(_, id, _, _, _):
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public var timestamp: Int32? {
|
public var timestamp: Int32? {
|
||||||
switch content {
|
switch content {
|
||||||
|
@ -1104,19 +1104,20 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
|
|||||||
if isPreview {
|
if isPreview {
|
||||||
needShareButton = false
|
needShareButton = false
|
||||||
}
|
}
|
||||||
if item.content.firstMessage.adAttribute != nil {
|
let isAd = item.content.firstMessage.adAttribute != nil
|
||||||
|
if isAd {
|
||||||
needShareButton = false
|
needShareButton = false
|
||||||
}
|
}
|
||||||
|
|
||||||
var tmpWidth: CGFloat
|
var tmpWidth: CGFloat
|
||||||
if allowFullWidth {
|
if allowFullWidth {
|
||||||
tmpWidth = baseWidth
|
tmpWidth = baseWidth
|
||||||
if needShareButton {
|
if needShareButton || isAd {
|
||||||
tmpWidth -= 38.0
|
tmpWidth -= 38.0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmpWidth = layoutConstants.bubble.maximumWidthFill.widthFor(baseWidth)
|
tmpWidth = layoutConstants.bubble.maximumWidthFill.widthFor(baseWidth)
|
||||||
if needShareButton && tmpWidth + 32.0 > baseWidth {
|
if (needShareButton || isAd) && tmpWidth + 32.0 > baseWidth {
|
||||||
tmpWidth = baseWidth - 32.0
|
tmpWidth = baseWidth - 32.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2580,7 +2581,6 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
|
|||||||
strongSelf.insertSubnode(shareButtonNode, belowSubnode: strongSelf.messageAccessibilityArea)
|
strongSelf.insertSubnode(shareButtonNode, belowSubnode: strongSelf.messageAccessibilityArea)
|
||||||
shareButtonNode.addTarget(strongSelf, action: #selector(strongSelf.shareButtonPressed), forControlEvents: .touchUpInside)
|
shareButtonNode.addTarget(strongSelf, action: #selector(strongSelf.shareButtonPressed), forControlEvents: .touchUpInside)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if let shareButtonNode = strongSelf.shareButtonNode {
|
} else if let shareButtonNode = strongSelf.shareButtonNode {
|
||||||
strongSelf.shareButtonNode = nil
|
strongSelf.shareButtonNode = nil
|
||||||
shareButtonNode.removeFromSupernode()
|
shareButtonNode.removeFromSupernode()
|
||||||
|
@ -613,10 +613,8 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio
|
|||||||
|
|
||||||
updatedFetchControls = FetchControls(fetch: { manual in
|
updatedFetchControls = FetchControls(fetch: { manual in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
if !manual {
|
if let representation = largestRepresentationForPhoto(image) {
|
||||||
strongSelf.fetchDisposable.set(chatMessagePhotoInteractiveFetched(context: context, photoReference: .message(message: MessageReference(message), media: image), displayAtSize: isSecretMedia ? nil : 600, storeToDownloadsPeerType: storeToDownloadsPeerType).start())
|
strongSelf.fetchDisposable.set(messageMediaImageInteractiveFetched(context: context, message: message, image: image, resource: representation.resource, range: representationFetchRangeForDisplayAtSize(representation: representation, dimension: isSecretMedia ? nil : 600), userInitiated: manual, storeToDownloadsPeerType: storeToDownloadsPeerType).start())
|
||||||
} else if let representation = largestRepresentationForPhoto(image) {
|
|
||||||
strongSelf.fetchDisposable.set(messageMediaImageInteractiveFetched(context: context, message: message, image: image, resource: representation.resource, range: representationFetchRangeForDisplayAtSize(representation: representation, dimension: isSecretMedia ? nil : 600), storeToDownloadsPeerType: storeToDownloadsPeerType).start())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, cancel: {
|
}, cancel: {
|
||||||
@ -816,6 +814,7 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio
|
|||||||
let arguments = TransformImageArguments(corners: corners, imageSize: drawingSize, boundingSize: boundingSize, intrinsicInsets: UIEdgeInsets(), resizeMode: isInlinePlayableVideo ? .fill(.black) : .blurBackground, emptyColor: emptyColor, custom: patternArguments)
|
let arguments = TransformImageArguments(corners: corners, imageSize: drawingSize, boundingSize: boundingSize, intrinsicInsets: UIEdgeInsets(), resizeMode: isInlinePlayableVideo ? .fill(.black) : .blurBackground, emptyColor: emptyColor, custom: patternArguments)
|
||||||
|
|
||||||
let imageFrame = CGRect(origin: CGPoint(x: -arguments.insets.left, y: -arguments.insets.top), size: arguments.drawingSize).ensuredValid
|
let imageFrame = CGRect(origin: CGPoint(x: -arguments.insets.left, y: -arguments.insets.top), size: arguments.drawingSize).ensuredValid
|
||||||
|
let cleanImageFrame = CGRect(origin: imageFrame.origin, size: CGSize(width: imageFrame.width - arguments.corners.extendedEdges.right, height: imageFrame.height))
|
||||||
|
|
||||||
let imageApply = imageLayout(arguments)
|
let imageApply = imageLayout(arguments)
|
||||||
|
|
||||||
@ -860,7 +859,7 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio
|
|||||||
}
|
}
|
||||||
statusApply(hasAnimation)
|
statusApply(hasAnimation)
|
||||||
|
|
||||||
let dateAndStatusFrame = CGRect(origin: CGPoint(x: imageFrame.width - layoutConstants.image.statusInsets.right - statusSize.width, y: imageFrame.height - layoutConstants.image.statusInsets.bottom - statusSize.height), size: statusSize)
|
let dateAndStatusFrame = CGRect(origin: CGPoint(x: cleanImageFrame.width - layoutConstants.image.statusInsets.right - statusSize.width, y: cleanImageFrame.height - layoutConstants.image.statusInsets.bottom - statusSize.height), size: statusSize)
|
||||||
|
|
||||||
strongSelf.dateAndStatusNode.frame = dateAndStatusFrame
|
strongSelf.dateAndStatusNode.frame = dateAndStatusFrame
|
||||||
strongSelf.dateAndStatusNode.bounds = CGRect(origin: CGPoint(), size: dateAndStatusFrame.size)
|
strongSelf.dateAndStatusNode.bounds = CGRect(origin: CGPoint(), size: dateAndStatusFrame.size)
|
||||||
|
@ -99,8 +99,10 @@ private final class FetchManagerStatusContext {
|
|||||||
if let originalStatus = self.originalStatus {
|
if let originalStatus = self.originalStatus {
|
||||||
if originalStatus == .Remote && self.hasEntry {
|
if originalStatus == .Remote && self.hasEntry {
|
||||||
return .Fetching(isActive: false, progress: 0.0)
|
return .Fetching(isActive: false, progress: 0.0)
|
||||||
} else {
|
} else if self.hasEntry {
|
||||||
return originalStatus
|
return originalStatus
|
||||||
|
} else {
|
||||||
|
return .Remote
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
@ -238,7 +240,14 @@ private final class FetchManagerCategoryContext {
|
|||||||
|
|
||||||
if (previousPriorityKey != nil) != (updatedPriorityKey != nil) {
|
if (previousPriorityKey != nil) != (updatedPriorityKey != nil) {
|
||||||
if let statusContext = self.statusContexts[id] {
|
if let statusContext = self.statusContexts[id] {
|
||||||
var hasForegroundPriorityKey = false
|
let previousStatus = statusContext.combinedStatus
|
||||||
|
statusContext.hasEntry = self.entries[id] != nil
|
||||||
|
if let combinedStatus = statusContext.combinedStatus, combinedStatus != previousStatus {
|
||||||
|
for f in statusContext.subscribers.copyItems() {
|
||||||
|
f(combinedStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*var hasForegroundPriorityKey = false
|
||||||
if let updatedPriorityKey = updatedPriorityKey, let topReference = updatedPriorityKey.topReference {
|
if let updatedPriorityKey = updatedPriorityKey, let topReference = updatedPriorityKey.topReference {
|
||||||
switch topReference {
|
switch topReference {
|
||||||
case .userInitiated:
|
case .userInitiated:
|
||||||
@ -270,7 +279,7 @@ private final class FetchManagerCategoryContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user