diff --git a/submodules/AccountContext/Sources/FetchMediaUtils.swift b/submodules/AccountContext/Sources/FetchMediaUtils.swift index 3e7416c63f..96d91b784d 100644 --- a/submodules/AccountContext/Sources/FetchMediaUtils.swift +++ b/submodules/AccountContext/Sources/FetchMediaUtils.swift @@ -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) } -public func messageMediaImageInteractiveFetched(context: AccountContext, message: Message, image: TelegramMediaImage, resource: MediaResource, range: Range? = nil, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal { - return messageMediaImageInteractiveFetched(fetchManager: context.fetchManager, messageId: message.id, messageReference: MessageReference(message), image: image, resource: resource, range: range, userInitiated: true, priority: .userInitiated, storeToDownloadsPeerType: storeToDownloadsPeerType) +public func messageMediaImageInteractiveFetched(context: AccountContext, message: Message, image: TelegramMediaImage, resource: MediaResource, range: Range? = nil, userInitiated: Bool = true, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal { + 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? = nil, userInitiated: Bool, priority: FetchManagerPriority, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal { diff --git a/submodules/PhotoResources/Sources/PhotoResources.swift b/submodules/PhotoResources/Sources/PhotoResources.swift index 14c832524b..35af7162d1 100644 --- a/submodules/PhotoResources/Sources/PhotoResources.swift +++ b/submodules/PhotoResources/Sources/PhotoResources.swift @@ -1699,13 +1699,41 @@ public func standaloneChatMessagePhotoInteractiveFetched(account: Account, photo } } -public func chatMessagePhotoInteractiveFetched(context: AccountContext, photoReference: ImageMediaReference, displayAtSize: Int?, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal { +public func chatMessagePhotoInteractiveFetched(context: AccountContext, photoReference: ImageMediaReference, displayAtSize: Int?, storeToDownloadsPeerType: MediaAutoDownloadPeerType?) -> Signal { if let largestRepresentation = largestRepresentationForPhoto(photoReference.media) { var fetchRange: (Range, MediaBoxFetchPriority)? if let displayAtSize = displayAtSize, let range = representationFetchRangeForDisplayAtSize(representation: largestRepresentation, dimension: displayAtSize) { 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) + } + 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) |> mapToSignal { type -> Signal in if case .remote = type, let peerType = storeToDownloadsPeerType { @@ -1717,6 +1745,10 @@ public func chatMessagePhotoInteractiveFetched(context: AccountContext, photoRef } return .single(type) } + |> ignoreValues + |> `catch` { _ -> Signal in + return .complete() + } } else { return .never() } diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_MediaReference.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_MediaReference.swift index 29fa4cf791..b6b3672ac4 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_MediaReference.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_MediaReference.swift @@ -11,6 +11,15 @@ public struct MessageReference: PostboxCoding, Hashable, Equatable { return peer } } + + public var id: MessageId? { + switch content { + case .none: + return nil + case let .message(_, id, _, _, _): + return id + } + } public var timestamp: Int32? { switch content { diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift index f077acfc5f..3b3d34b0d0 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift @@ -1104,19 +1104,20 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode if isPreview { needShareButton = false } - if item.content.firstMessage.adAttribute != nil { + let isAd = item.content.firstMessage.adAttribute != nil + if isAd { needShareButton = false } var tmpWidth: CGFloat if allowFullWidth { tmpWidth = baseWidth - if needShareButton { + if needShareButton || isAd { tmpWidth -= 38.0 } } else { tmpWidth = layoutConstants.bubble.maximumWidthFill.widthFor(baseWidth) - if needShareButton && tmpWidth + 32.0 > baseWidth { + if (needShareButton || isAd) && tmpWidth + 32.0 > baseWidth { tmpWidth = baseWidth - 32.0 } } @@ -2580,7 +2581,6 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode strongSelf.insertSubnode(shareButtonNode, belowSubnode: strongSelf.messageAccessibilityArea) shareButtonNode.addTarget(strongSelf, action: #selector(strongSelf.shareButtonPressed), forControlEvents: .touchUpInside) } - } else if let shareButtonNode = strongSelf.shareButtonNode { strongSelf.shareButtonNode = nil shareButtonNode.removeFromSupernode() diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveMediaNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveMediaNode.swift index 323e38ba2e..8303684a1a 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveMediaNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveMediaNode.swift @@ -613,10 +613,8 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio updatedFetchControls = FetchControls(fetch: { manual in if let strongSelf = self { - if !manual { - strongSelf.fetchDisposable.set(chatMessagePhotoInteractiveFetched(context: context, photoReference: .message(message: MessageReference(message), media: image), displayAtSize: isSecretMedia ? nil : 600, 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()) + 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), userInitiated: manual, storeToDownloadsPeerType: storeToDownloadsPeerType).start()) } } }, 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 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) @@ -860,7 +859,7 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio } 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.bounds = CGRect(origin: CGPoint(), size: dateAndStatusFrame.size) diff --git a/submodules/TelegramUI/Sources/FetchManager.swift b/submodules/TelegramUI/Sources/FetchManager.swift index 26fef02594..cf546fc69c 100644 --- a/submodules/TelegramUI/Sources/FetchManager.swift +++ b/submodules/TelegramUI/Sources/FetchManager.swift @@ -99,8 +99,10 @@ private final class FetchManagerStatusContext { if let originalStatus = self.originalStatus { if originalStatus == .Remote && self.hasEntry { return .Fetching(isActive: false, progress: 0.0) - } else { + } else if self.hasEntry { return originalStatus + } else { + return .Remote } } else { return nil @@ -238,7 +240,14 @@ private final class FetchManagerCategoryContext { if (previousPriorityKey != nil) != (updatedPriorityKey != nil) { 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 { switch topReference { case .userInitiated: @@ -270,7 +279,7 @@ private final class FetchManagerCategoryContext { } } } - } + }*/ } }