This commit is contained in:
Isaac 2024-08-14 23:32:42 +08:00
commit d5b171643f
5 changed files with 61 additions and 22 deletions

View file

@ -55,7 +55,8 @@ final class BrowserPdfContent: UIView, BrowserContent, UIScrollViewDelegate, PDF
self.file = file
self.pdfView = PDFView()
self.pdfView.clipsToBounds = false
var scrollView: UIScrollView?
for view in self.pdfView.subviews {
if let view = view as? UIScrollView {
@ -69,6 +70,7 @@ final class BrowserPdfContent: UIView, BrowserContent, UIScrollViewDelegate, PDF
}
}
self.scrollView = scrollView
scrollView?.clipsToBounds = false
self.pdfView.displayDirection = .vertical
self.pdfView.autoScales = true
@ -296,7 +298,14 @@ final class BrowserPdfContent: UIView, BrowserContent, UIScrollViewDelegate, PDF
self.previousScrollingOffset = ScrollingOffsetState(value: self.scrollView.contentOffset.y, isDraggingOrDecelerating: self.scrollView.isDragging || self.scrollView.isDecelerating)
let pdfViewFrame = CGRect(origin: CGPoint(x: insets.left, y: insets.top), size: CGSize(width: size.width - insets.left - insets.right, height: size.height - insets.top - insets.bottom))
let currentBounds = self.scrollView.bounds
let offsetToBottomEdge = max(0.0, self.scrollView.contentSize.height - currentBounds.maxY)
var bottomInset = insets.bottom
if offsetToBottomEdge < 128.0 {
bottomInset = fullInsets.bottom
}
let pdfViewFrame = CGRect(origin: CGPoint(x: insets.left, y: insets.top), size: CGSize(width: size.width - insets.left - insets.right, height: size.height - insets.top - bottomInset))
transition.setFrame(view: self.pdfView, frame: pdfViewFrame)
if isFirstTime {
@ -370,6 +379,10 @@ final class BrowserPdfContent: UIView, BrowserContent, UIScrollViewDelegate, PDF
}
if !decelerate {
self.snapScrollingOffsetToInsets()
if self.ignoreUpdatesUntilScrollingStopped {
self.ignoreUpdatesUntilScrollingStopped = false
}
}
}
@ -378,9 +391,16 @@ final class BrowserPdfContent: UIView, BrowserContent, UIScrollViewDelegate, PDF
scrollViewDelegate.scrollViewDidEndDecelerating?(scrollView)
}
self.snapScrollingOffsetToInsets()
if self.ignoreUpdatesUntilScrollingStopped {
self.ignoreUpdatesUntilScrollingStopped = false
}
}
private func updateScrollingOffset(isReset: Bool, transition: ComponentTransition) {
guard !self.ignoreUpdatesUntilScrollingStopped else {
return
}
guard let scrollView = self.scrollView else {
return
}
@ -412,8 +432,12 @@ final class BrowserPdfContent: UIView, BrowserContent, UIScrollViewDelegate, PDF
}
}
private var ignoreUpdatesUntilScrollingStopped = false
func resetScrolling() {
self.updateScrollingOffset(isReset: true, transition: .spring(duration: 0.4))
if self.scrollView.isDecelerating {
self.ignoreUpdatesUntilScrollingStopped = true
}
}
private func open(url: String, new: Bool) {

View file

@ -65,7 +65,7 @@ func resolveMissingStickerSets(network: Network, postbox: Postbox, stickerSets:
var missingSignals: [Signal<(Int, Api.StickerSetCovered)?, NoError>] = []
for i in 0 ..< stickerSets.count {
switch stickerSets[i] {
case let .stickerSetNoCovered(value):
case let .stickerSetNoCovered(value), let .stickerSetCovered(value, _):
switch value {
case let .stickerSet(_, _, id, accessHash, _, _, _, _, _, _, _, hash):
if ignorePacksWithHashes[id] == hash {
@ -143,7 +143,7 @@ func updatedFeaturedStickerPacks(network: Network, postbox: Postbox, category: F
case .featuredStickersNotModified:
return .single(.notModified)
case let .featuredStickers(flags, _, _, sets, unread):
return resolveMissingStickerSets(network: network, postbox: postbox, stickerSets: sets, ignorePacksWithHashes: initialPackMap.mapValues({ item in
return resolveMissingStickerSets(network: network, postbox: postbox, stickerSets: sets, ignorePacksWithHashes: initialPackMap.filter { $0.value.topItems.count > 1 }.mapValues({ item in
item.info.hash
}))
|> castError(MTRpcError.self)
@ -153,8 +153,10 @@ func updatedFeaturedStickerPacks(network: Network, postbox: Postbox, category: F
for set in sets {
var (info, items) = parsePreviewStickerSet(set, namespace: category.collectionIdNamespace)
if let previousPack = initialPackMap[info.id.id] {
if previousPack.info.hash == info.hash {
if previousPack.info.hash == info.hash, previousPack.topItems.count > 1 {
items = previousPack.topItems
} else {
items = Array(items.prefix(5))
}
}
updatedPacks.append(FeaturedStickerPackItem(info: info, topItems: items, unread: unreadIds.contains(info.id.id)))

View file

@ -532,21 +532,7 @@ private class AdMessagesHistoryContextImpl {
}
func markAction(opaqueId: Data) {
let account = self.account
let signal: Signal<Never, NoError> = account.postbox.transaction { transaction -> Api.InputChannel? in
return transaction.getPeer(self.peerId).flatMap(apiInputChannel)
}
|> mapToSignal { inputChannel -> Signal<Never, NoError> in
guard let inputChannel = inputChannel else {
return .complete()
}
return account.network.request(Api.functions.channels.clickSponsoredMessage(channel: inputChannel, randomId: Buffer(data: opaqueId)))
|> `catch` { _ -> Signal<Api.Bool, NoError> in
return .single(.boolFalse)
}
|> ignoreValues
}
let _ = signal.start()
_internal_markAdAction(account: self.account, peerId: self.peerId, opaqueId: opaqueId)
}
func remove(opaqueId: Data) {
@ -619,3 +605,21 @@ public class AdMessagesHistoryContext {
}
}
}
func _internal_markAdAction(account: Account, peerId: EnginePeer.Id, opaqueId: Data) {
let signal: Signal<Never, NoError> = account.postbox.transaction { transaction -> Api.InputChannel? in
return transaction.getPeer(peerId).flatMap(apiInputChannel)
}
|> mapToSignal { inputChannel -> Signal<Never, NoError> in
guard let inputChannel = inputChannel else {
return .complete()
}
return account.network.request(Api.functions.channels.clickSponsoredMessage(channel: inputChannel, randomId: Buffer(data: opaqueId)))
|> `catch` { _ -> Signal<Api.Bool, NoError> in
return .single(.boolFalse)
}
|> ignoreValues
}
let _ = signal.start()
}

View file

@ -1466,6 +1466,9 @@ public extension TelegramEngine {
public func updateExtendedMedia(messageIds: [EngineMessage.Id]) -> Signal<Never, NoError> {
return _internal_updateExtendedMedia(account: self.account, messageIds: messageIds)
}
public func markAdAction(peerId: EnginePeer.Id, opaqueId: Data) {
_internal_markAdAction(account: self.account, peerId: peerId, opaqueId: opaqueId)
}
public func getAllLocalChannels(count: Int) -> Signal<[EnginePeer.Id], NoError> {
return self.account.postbox.transaction { transaction -> [EnginePeer.Id] in

View file

@ -230,7 +230,7 @@ private func _internal_requestStarsSubscriptions(account: Account, peerId: Engin
}
|> castError(RequestStarsSubscriptionsError.self)
|> mapToSignal { peer -> Signal<InternalStarsStatus, RequestStarsSubscriptionsError> in
guard let peer, let inputPeer = apiInputPeer(peer) else {
guard let peer, let inputPeer = apiInputPeerOrSelf(peer, accountPeerId: peerId) else {
return .fail(.generic)
}
var flags: Int32 = 0
@ -965,6 +965,7 @@ private final class StarsSubscriptionsContextImpl {
guard let self else {
return
}
self.nextOffset = status.nextSubscriptionsOffset
var updatedState = self._state
@ -1002,13 +1003,18 @@ private final class StarsSubscriptionsContextImpl {
func load(force: Bool) {
assert(Queue.mainQueue().isCurrent())
guard !self._state.isLoading else {
return
}
let currentTimestamp = CFAbsoluteTimeGetCurrent()
if let previousLoadTimestamp = self.previousLoadTimestamp, currentTimestamp - previousLoadTimestamp < 60 && !force {
return
}
self.previousLoadTimestamp = currentTimestamp
self._state.isLoading = true
self.disposable.set((_internal_requestStarsSubscriptions(account: self.account, peerId: self.account.peerId, offset: "", missingBalance: false)
self.disposable.set((_internal_requestStarsSubscriptions(account: self.account, peerId: self.account.peerId, offset: "", missingBalance: self.missingBalance)
|> deliverOnMainQueue).start(next: { [weak self] status in
guard let self else {
return