mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-01 04:08:07 +00:00
no message
This commit is contained in:
parent
d47a174cd8
commit
1af33ce618
@ -7,20 +7,34 @@ import Postbox
|
|||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
private func removeMessageMedia(message: Message, mediaBox: MediaBox) {
|
||||||
|
for media in message.media {
|
||||||
|
if let image = media as? TelegramMediaImage {
|
||||||
|
let _ = mediaBox.removeCachedResources(Set(image.representations.map({ WrappedMediaResourceId($0.resource.id) }))).start()
|
||||||
|
} else if let file = media as? TelegramMediaFile {
|
||||||
|
let _ = mediaBox.removeCachedResources(Set(file.previewRepresentations.map({ WrappedMediaResourceId($0.resource.id) }))).start()
|
||||||
|
let _ = mediaBox.removeCachedResources(Set([WrappedMediaResourceId(file.resource.id)])).start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func deleteMessages(transaction: Transaction, mediaBox: MediaBox, ids: [MessageId]) {
|
public func deleteMessages(transaction: Transaction, mediaBox: MediaBox, ids: [MessageId]) {
|
||||||
for id in ids {
|
for id in ids {
|
||||||
if id.peerId.namespace == Namespaces.Peer.SecretChat {
|
if id.peerId.namespace == Namespaces.Peer.SecretChat {
|
||||||
if let message = transaction.getMessage(id) {
|
if let message = transaction.getMessage(id) {
|
||||||
for media in message.media {
|
removeMessageMedia(message: message, mediaBox: mediaBox)
|
||||||
if let image = media as? TelegramMediaImage {
|
|
||||||
let _ = mediaBox.removeCachedResources(Set(image.representations.map({ WrappedMediaResourceId($0.resource.id) }))).start()
|
|
||||||
} else if let file = media as? TelegramMediaFile {
|
|
||||||
let _ = mediaBox.removeCachedResources(Set(file.previewRepresentations.map({ WrappedMediaResourceId($0.resource.id) }))).start()
|
|
||||||
let _ = mediaBox.removeCachedResources(Set([WrappedMediaResourceId(file.resource.id)])).start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
transaction.deleteMessages(ids)
|
transaction.deleteMessages(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func clearHistory(transaction: Transaction, mediaBox: MediaBox, peerId: PeerId) {
|
||||||
|
if peerId.namespace == Namespaces.Peer.SecretChat {
|
||||||
|
transaction.withAllMessages(peerId: peerId, { message in
|
||||||
|
removeMessageMedia(message: message, mediaBox: mediaBox)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
transaction.clearHistory(peerId)
|
||||||
|
}
|
||||||
|
|||||||
@ -65,16 +65,16 @@ public func clearHistoryInteractively(postbox: Postbox, peerId: PeerId) -> Signa
|
|||||||
topTimestamp = topIndex.timestamp
|
topTimestamp = topIndex.timestamp
|
||||||
}
|
}
|
||||||
cloudChatAddClearHistoryOperation(transaction: transaction, peerId: peerId, explicitTopMessageId: nil)
|
cloudChatAddClearHistoryOperation(transaction: transaction, peerId: peerId, explicitTopMessageId: nil)
|
||||||
transaction.clearHistory(peerId)
|
clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId)
|
||||||
if let cachedData = transaction.getPeerCachedData(peerId: peerId) as? CachedChannelData, let migrationReference = cachedData.migrationReference {
|
if let cachedData = transaction.getPeerCachedData(peerId: peerId) as? CachedChannelData, let migrationReference = cachedData.migrationReference {
|
||||||
cloudChatAddClearHistoryOperation(transaction: transaction, peerId: migrationReference.maxMessageId.peerId, explicitTopMessageId: MessageId(peerId: migrationReference.maxMessageId.peerId, namespace: migrationReference.maxMessageId.namespace, id: migrationReference.maxMessageId.id + 1))
|
cloudChatAddClearHistoryOperation(transaction: transaction, peerId: migrationReference.maxMessageId.peerId, explicitTopMessageId: MessageId(peerId: migrationReference.maxMessageId.peerId, namespace: migrationReference.maxMessageId.namespace, id: migrationReference.maxMessageId.id + 1))
|
||||||
transaction.clearHistory(migrationReference.maxMessageId.peerId)
|
clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: migrationReference.maxMessageId.peerId)
|
||||||
}
|
}
|
||||||
if let topTimestamp = topTimestamp {
|
if let topTimestamp = topTimestamp {
|
||||||
updatePeerChatInclusionWithMinTimestamp(transaction: transaction, id: peerId, minTimestamp: topTimestamp)
|
updatePeerChatInclusionWithMinTimestamp(transaction: transaction, id: peerId, minTimestamp: topTimestamp)
|
||||||
}
|
}
|
||||||
} else if peerId.namespace == Namespaces.Peer.SecretChat {
|
} else if peerId.namespace == Namespaces.Peer.SecretChat {
|
||||||
transaction.clearHistory(peerId)
|
clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId)
|
||||||
|
|
||||||
if let state = transaction.getPeerChatState(peerId) as? SecretChatState {
|
if let state = transaction.getPeerChatState(peerId) as? SecretChatState {
|
||||||
var layer: SecretChatLayer?
|
var layer: SecretChatLayer?
|
||||||
|
|||||||
@ -241,8 +241,11 @@ private func removeChat(transaction: Transaction, postbox: Postbox, network: Net
|
|||||||
} else {
|
} else {
|
||||||
deleteMessages = .complete()
|
deleteMessages = .complete()
|
||||||
}
|
}
|
||||||
return deleteMessages |> then(deleteUser) |> then(reportSignal) |> then(postbox.transaction { transaction -> Void in
|
return deleteMessages
|
||||||
transaction.clearHistory(peer.id)
|
|> then(deleteUser)
|
||||||
|
|> then(reportSignal)
|
||||||
|
|> then(postbox.transaction { transaction -> Void in
|
||||||
|
clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peer.id)
|
||||||
})
|
})
|
||||||
} else if peer.id.namespace == Namespaces.Peer.CloudUser {
|
} else if peer.id.namespace == Namespaces.Peer.CloudUser {
|
||||||
if let inputPeer = apiInputPeer(peer) {
|
if let inputPeer = apiInputPeer(peer) {
|
||||||
@ -258,8 +261,10 @@ private func removeChat(transaction: Transaction, postbox: Postbox, network: Net
|
|||||||
} else {
|
} else {
|
||||||
reportSignal = .complete()
|
reportSignal = .complete()
|
||||||
}
|
}
|
||||||
return requestClearHistory(postbox: postbox, network: network, stateManager: stateManager, inputPeer: inputPeer, maxId: operation.topMessageId?.id ?? Int32.max - 1, justClear: false) |> then(reportSignal) |> then(postbox.transaction { transaction -> Void in
|
return requestClearHistory(postbox: postbox, network: network, stateManager: stateManager, inputPeer: inputPeer, maxId: operation.topMessageId?.id ?? Int32.max - 1, justClear: false)
|
||||||
transaction.clearHistory(peer.id)
|
|> then(reportSignal)
|
||||||
|
|> then(postbox.transaction { transaction -> Void in
|
||||||
|
clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peer.id)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
return .complete()
|
return .complete()
|
||||||
|
|||||||
@ -246,7 +246,7 @@ func processSecretChatIncomingDecryptedOperations(mediaBox: MediaBox, transactio
|
|||||||
deleteMessages(transaction: transaction, mediaBox: mediaBox, ids: messageIds)
|
deleteMessages(transaction: transaction, mediaBox: mediaBox, ids: messageIds)
|
||||||
}
|
}
|
||||||
case .clearHistory:
|
case .clearHistory:
|
||||||
transaction.clearHistory(peerId)
|
clearHistory(transaction: transaction, mediaBox: mediaBox, peerId: peerId)
|
||||||
case let .markMessagesContentAsConsumed(globallyUniqueIds):
|
case let .markMessagesContentAsConsumed(globallyUniqueIds):
|
||||||
var messageIds: [MessageId] = []
|
var messageIds: [MessageId] = []
|
||||||
for id in globallyUniqueIds {
|
for id in globallyUniqueIds {
|
||||||
|
|||||||
@ -22,17 +22,17 @@ public func removePeerChat(postbox: Postbox, peerId: PeerId, reportChatSpam: Boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
transaction.clearHistory(peerId)
|
clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId)
|
||||||
transaction.updatePeerChatListInclusion(peerId, inclusion: .never)
|
transaction.updatePeerChatListInclusion(peerId, inclusion: .never)
|
||||||
transaction.removeOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, itemId: RecentPeerItemId(peerId).rawValue)
|
transaction.removeOrderedItemListItem(collectionId: Namespaces.OrderedItemList.RecentlySearchedPeerIds, itemId: RecentPeerItemId(peerId).rawValue)
|
||||||
} else {
|
} else {
|
||||||
cloudChatAddRemoveChatOperation(transaction: transaction, peerId: peerId, reportChatSpam: reportChatSpam)
|
cloudChatAddRemoveChatOperation(transaction: transaction, peerId: peerId, reportChatSpam: reportChatSpam)
|
||||||
if peerId.namespace == Namespaces.Peer.CloudUser {
|
if peerId.namespace == Namespaces.Peer.CloudUser {
|
||||||
transaction.updatePeerChatListInclusion(peerId, inclusion: .ifHasMessages)
|
transaction.updatePeerChatListInclusion(peerId, inclusion: .ifHasMessages)
|
||||||
transaction.clearHistory(peerId)
|
clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId)
|
||||||
} else if peerId.namespace == Namespaces.Peer.CloudGroup {
|
} else if peerId.namespace == Namespaces.Peer.CloudGroup {
|
||||||
transaction.updatePeerChatListInclusion(peerId, inclusion: .never)
|
transaction.updatePeerChatListInclusion(peerId, inclusion: .never)
|
||||||
transaction.clearHistory(peerId)
|
clearHistory(transaction: transaction, mediaBox: postbox.mediaBox, peerId: peerId)
|
||||||
} else {
|
} else {
|
||||||
transaction.updatePeerChatListInclusion(peerId, inclusion: .never)
|
transaction.updatePeerChatListInclusion(peerId, inclusion: .never)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user