mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-01 04:08:07 +00:00
Remove ad animation
This commit is contained in:
parent
bf3541fca2
commit
9e1fdb3c8d
@ -764,6 +764,31 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
}
|
}
|
||||||
let _ = signal.start()
|
let _ = signal.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func remove(opaqueId: Data) {
|
||||||
|
if var stateValue = self.stateValue {
|
||||||
|
if let index = stateValue.messages.firstIndex(where: { $0.adAttribute?.opaqueId == opaqueId }) {
|
||||||
|
stateValue.messages.remove(at: index)
|
||||||
|
self.stateValue = stateValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let peerId = self.peerId
|
||||||
|
let _ = (self.account.postbox.transaction { transaction -> Void in
|
||||||
|
let key = ValueBoxKey(length: 8)
|
||||||
|
key.setInt64(0, value: peerId.toInt64())
|
||||||
|
let id = ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedAdMessageStates, key: key)
|
||||||
|
guard var cachedState = transaction.retrieveItemCacheEntry(id: id)?.get(CachedState.self) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if let index = cachedState.messages.firstIndex(where: { $0.opaqueId == opaqueId }) {
|
||||||
|
cachedState.messages.remove(at: index)
|
||||||
|
if let entry = CodableEntry(cachedState) {
|
||||||
|
transaction.putItemCacheEntry(id: id, entry: entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).start()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AdMessagesHistoryContext {
|
public class AdMessagesHistoryContext {
|
||||||
@ -803,4 +828,10 @@ public class AdMessagesHistoryContext {
|
|||||||
impl.markAction(opaqueId: opaqueId)
|
impl.markAction(opaqueId: opaqueId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func remove(opaqueId: Data) {
|
||||||
|
self.impl.with { impl in
|
||||||
|
impl.remove(opaqueId: opaqueId)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
submodules/TelegramUI/Sources/ChatControllerRemoveAd.swift
Normal file
25
submodules/TelegramUI/Sources/ChatControllerRemoveAd.swift
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import Foundation
|
||||||
|
import TelegramPresentationData
|
||||||
|
import AccountContext
|
||||||
|
import Postbox
|
||||||
|
import TelegramCore
|
||||||
|
import SwiftSignalKit
|
||||||
|
import Display
|
||||||
|
import TelegramPresentationData
|
||||||
|
import PresentationDataUtils
|
||||||
|
import ChatMessageItemView
|
||||||
|
|
||||||
|
extension ChatControllerImpl {
|
||||||
|
func removeAd(opaqueId: Data) {
|
||||||
|
var foundItemNode: ChatMessageItemView?
|
||||||
|
self.chatDisplayNode.historyNode.forEachItemNode { itemNode in
|
||||||
|
if let itemNode = itemNode as? ChatMessageItemView, let item = itemNode.item, let adAttribute = item.message.adAttribute, adAttribute.opaqueId == opaqueId {
|
||||||
|
foundItemNode = itemNode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let foundItemNode, let message = foundItemNode.item?.message {
|
||||||
|
self.chatDisplayNode.historyNode.setCurrentDeleteAnimationCorrelationIds(Set([message.stableId]))
|
||||||
|
}
|
||||||
|
self.chatDisplayNode.historyNode.adMessagesContext?.remove(opaqueId: opaqueId)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -499,8 +499,14 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
|
|||||||
opaqueId: adAttribute.opaqueId,
|
opaqueId: adAttribute.opaqueId,
|
||||||
title: title,
|
title: title,
|
||||||
options: options,
|
options: options,
|
||||||
completed: {
|
completed: { [weak interfaceInteraction] in
|
||||||
|
guard let interfaceInteraction else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard let chatController = interfaceInteraction.chatController() as? ChatControllerImpl else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
chatController.removeAd(opaqueId: adAttribute.opaqueId)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user