mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Web app improvements
This commit is contained in:
parent
4a544882f2
commit
9ff797d9a4
@ -2283,9 +2283,20 @@ public func instantPageImageFile(account: Account, fileReference: FileMediaRefer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func svgIconImageFile(account: Account, fileReference: FileMediaReference, stickToTop: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
public func svgIconImageFile(account: Account, fileReference: FileMediaReference?, stickToTop: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
||||||
let data = account.postbox.mediaBox.cachedResourceRepresentation(fileReference.media.resource, representation: CachedPreparedSvgRepresentation(), complete: false, fetch: true)
|
let data: Signal<MediaResourceData, NoError>
|
||||||
|
if let fileReference = fileReference {
|
||||||
|
data = account.postbox.mediaBox.cachedResourceRepresentation(fileReference.media.resource, representation: CachedPreparedSvgRepresentation(), complete: false, fetch: true)
|
||||||
|
} else {
|
||||||
|
data = Signal { subscriber in
|
||||||
|
if let url = getAppBundle().url(forResource: "durgerking", withExtension: "placeholder"), let data = try? Data(contentsOf: url, options: .mappedRead) {
|
||||||
|
subscriber.putNext(MediaResourceData(path: url.path, offset: 0, size: data.count, complete: true))
|
||||||
|
subscriber.putCompletion()
|
||||||
|
}
|
||||||
|
return EmptyDisposable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|> map { value in
|
|> map { value in
|
||||||
let fullSizePath = value.path
|
let fullSizePath = value.path
|
||||||
@ -2301,8 +2312,6 @@ public func svgIconImageFile(account: Account, fileReference: FileMediaReference
|
|||||||
|
|
||||||
if fullSizeComplete, let data = try? Data(contentsOf: URL(fileURLWithPath: fullSizePath)) {
|
if fullSizeComplete, let data = try? Data(contentsOf: URL(fileURLWithPath: fullSizePath)) {
|
||||||
fullSizeImage = renderPreparedImage(data, CGSize.zero, .clear, UIScreenScale)
|
fullSizeImage = renderPreparedImage(data, CGSize.zero, .clear, UIScreenScale)
|
||||||
|
|
||||||
// fullSizeImage = drawSvgImage(data, stickToTop ? CGSize.zero : CGSize(width: 90.0, height: 90.0), .clear, .black, false)
|
|
||||||
if let image = fullSizeImage {
|
if let image = fullSizeImage {
|
||||||
fittedSize = image.size.aspectFitted(arguments.boundingSize)
|
fittedSize = image.size.aspectFitted(arguments.boundingSize)
|
||||||
}
|
}
|
||||||
|
BIN
submodules/TelegramUI/Resources/durgerking.placeholder
Normal file
BIN
submodules/TelegramUI/Resources/durgerking.placeholder
Normal file
Binary file not shown.
@ -18,6 +18,8 @@ import PhotoResources
|
|||||||
import LegacyComponents
|
import LegacyComponents
|
||||||
import UrlHandling
|
import UrlHandling
|
||||||
|
|
||||||
|
private let durgerKingBotIds: [Int64] = [5104055776, 2200339955]
|
||||||
|
|
||||||
public struct WebAppParameters {
|
public struct WebAppParameters {
|
||||||
let peerId: PeerId
|
let peerId: PeerId
|
||||||
let botId: PeerId
|
let botId: PeerId
|
||||||
@ -89,6 +91,7 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
private let present: (ViewController, Any?) -> Void
|
private let present: (ViewController, Any?) -> Void
|
||||||
private var queryId: Int64?
|
private var queryId: Int64?
|
||||||
|
|
||||||
|
private var placeholderDisposable: Disposable?
|
||||||
private var iconDisposable: Disposable?
|
private var iconDisposable: Disposable?
|
||||||
private var keepAliveDisposable: Disposable?
|
private var keepAliveDisposable: Disposable?
|
||||||
|
|
||||||
@ -121,45 +124,79 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
let placeholderNode = ShimmerEffectNode()
|
let placeholderNode = ShimmerEffectNode()
|
||||||
self.addSubnode(placeholderNode)
|
self.addSubnode(placeholderNode)
|
||||||
self.placeholderNode = placeholderNode
|
self.placeholderNode = placeholderNode
|
||||||
|
|
||||||
let _ = (self.context.engine.messages.getAttachMenuBot(botId: controller.botId, cached: true)
|
let placeholder: Signal<(FileMediaReference, Bool)?, NoError>
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] bot in
|
if durgerKingBotIds.contains(controller.botId.id._internalGetInt64Value()) {
|
||||||
|
placeholder = .single(nil)
|
||||||
|
|> delay(0.05, queue: Queue.mainQueue())
|
||||||
|
} else {
|
||||||
|
placeholder = self.context.engine.messages.getAttachMenuBot(botId: controller.botId, cached: true)
|
||||||
|
|> map(Optional.init)
|
||||||
|
|> `catch` { error -> Signal<AttachMenuBot?, NoError> in
|
||||||
|
return .complete()
|
||||||
|
}
|
||||||
|
|> mapToSignal { bot -> Signal<(FileMediaReference, Bool)?, NoError> in
|
||||||
|
if let bot = bot, let peerReference = PeerReference(bot.peer) {
|
||||||
|
var imageFile: TelegramMediaFile?
|
||||||
|
var isPlaceholder = false
|
||||||
|
if let file = bot.icons[.placeholder] {
|
||||||
|
imageFile = file
|
||||||
|
isPlaceholder = true
|
||||||
|
} else if let file = bot.icons[.iOSStatic] {
|
||||||
|
imageFile = file
|
||||||
|
} else if let file = bot.icons[.default] {
|
||||||
|
imageFile = file
|
||||||
|
}
|
||||||
|
if let imageFile = imageFile {
|
||||||
|
return .single((.attachBot(peer: peerReference, media: imageFile), isPlaceholder))
|
||||||
|
} else {
|
||||||
|
return .complete()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return .complete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.placeholderDisposable = (placeholder
|
||||||
|
|> deliverOnMainQueue).start(next: { [weak self] fileReferenceAndIsPlaceholder in
|
||||||
guard let strongSelf = self else {
|
guard let strongSelf = self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var imageFile: TelegramMediaFile?
|
let fileReference: FileMediaReference?
|
||||||
var isPlaceholder = false
|
let isPlaceholder: Bool
|
||||||
if let file = bot.icons[.placeholder] {
|
if let (maybeFileReference, maybeIsPlaceholder) = fileReferenceAndIsPlaceholder {
|
||||||
imageFile = file
|
fileReference = maybeFileReference
|
||||||
|
isPlaceholder = maybeIsPlaceholder
|
||||||
|
} else {
|
||||||
|
fileReference = nil
|
||||||
isPlaceholder = true
|
isPlaceholder = true
|
||||||
} else if let file = bot.icons[.iOSStatic] {
|
|
||||||
imageFile = file
|
|
||||||
} else if let file = bot.icons[.default] {
|
|
||||||
imageFile = file
|
|
||||||
}
|
}
|
||||||
if let imageFile = imageFile, let peer = PeerReference(bot.peer) {
|
|
||||||
let _ = freeMediaFileInteractiveFetched(account: strongSelf.context.account, fileReference: .attachBot(peer: peer, media: imageFile)).start()
|
if let fileReference = fileReference {
|
||||||
strongSelf.iconDisposable = (svgIconImageFile(account: strongSelf.context.account, fileReference: .attachBot(peer: peer, media: imageFile), stickToTop: isPlaceholder)
|
let _ = freeMediaFileInteractiveFetched(account: strongSelf.context.account, fileReference: fileReference).start()
|
||||||
|> deliverOnMainQueue).start(next: { [weak self] transform in
|
}
|
||||||
if let strongSelf = self {
|
strongSelf.iconDisposable = (svgIconImageFile(account: strongSelf.context.account, fileReference: fileReference, stickToTop: isPlaceholder)
|
||||||
let imageSize: CGSize
|
|> deliverOnMainQueue).start(next: { [weak self] transform in
|
||||||
if isPlaceholder, let (layout, _) = strongSelf.validLayout {
|
if let strongSelf = self {
|
||||||
let minSize = min(layout.size.width, layout.size.height)
|
let imageSize: CGSize
|
||||||
imageSize = CGSize(width: minSize, height: minSize * 3.0)
|
if isPlaceholder, let (layout, _) = strongSelf.validLayout {
|
||||||
} else {
|
let minSize = min(layout.size.width, layout.size.height)
|
||||||
imageSize = CGSize(width: 75.0, height: 75.0)
|
imageSize = CGSize(width: minSize, height: minSize * 2.0)
|
||||||
}
|
} else {
|
||||||
let arguments = TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets())
|
imageSize = CGSize(width: 75.0, height: 75.0)
|
||||||
let drawingContext = transform(arguments)
|
}
|
||||||
if let image = drawingContext?.generateImage()?.withRenderingMode(.alwaysTemplate) {
|
let arguments = TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets())
|
||||||
strongSelf.placeholderIcon = (image, isPlaceholder)
|
let drawingContext = transform(arguments)
|
||||||
if let (layout, navigationBarHeight) = strongSelf.validLayout {
|
if let image = drawingContext?.generateImage()?.withRenderingMode(.alwaysTemplate) {
|
||||||
strongSelf.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate)
|
strongSelf.placeholderIcon = (image, isPlaceholder)
|
||||||
}
|
if let (layout, navigationBarHeight) = strongSelf.validLayout {
|
||||||
|
strongSelf.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
strongSelf.placeholderNode?.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if let url = controller.url, !controller.fromMenu {
|
if let url = controller.url, !controller.fromMenu {
|
||||||
@ -207,6 +244,7 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
self.placeholderDisposable?.dispose()
|
||||||
self.iconDisposable?.dispose()
|
self.iconDisposable?.dispose()
|
||||||
self.keepAliveDisposable?.dispose()
|
self.keepAliveDisposable?.dispose()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user