mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 21:41:45 +00:00
Added prepareSecretThumbnailData
This commit is contained in:
parent
c45aa06aa7
commit
7351bd6b26
@ -707,11 +707,13 @@ public final class AccountAuxiliaryMethods {
|
|||||||
public let updatePeerChatInputState: (PeerChatInterfaceState?, SynchronizeableChatInputState?) -> PeerChatInterfaceState?
|
public let updatePeerChatInputState: (PeerChatInterfaceState?, SynchronizeableChatInputState?) -> PeerChatInterfaceState?
|
||||||
public let fetchResource: (Account, MediaResource, Signal<[(Range<Int>, MediaBoxFetchPriority)], NoError>, MediaResourceFetchParameters?) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError>?
|
public let fetchResource: (Account, MediaResource, Signal<[(Range<Int>, MediaBoxFetchPriority)], NoError>, MediaResourceFetchParameters?) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError>?
|
||||||
public let fetchResourceMediaReferenceHash: (MediaResource) -> Signal<Data?, NoError>
|
public let fetchResourceMediaReferenceHash: (MediaResource) -> Signal<Data?, NoError>
|
||||||
|
public let prepareSecretThumbnailData: (MediaResourceData) -> (CGSize, Data)?
|
||||||
|
|
||||||
public init(updatePeerChatInputState: @escaping (PeerChatInterfaceState?, SynchronizeableChatInputState?) -> PeerChatInterfaceState?, fetchResource: @escaping (Account, MediaResource, Signal<[(Range<Int>, MediaBoxFetchPriority)], NoError>, MediaResourceFetchParameters?) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError>?, fetchResourceMediaReferenceHash: @escaping (MediaResource) -> Signal<Data?, NoError>) {
|
public init(updatePeerChatInputState: @escaping (PeerChatInterfaceState?, SynchronizeableChatInputState?) -> PeerChatInterfaceState?, fetchResource: @escaping (Account, MediaResource, Signal<[(Range<Int>, MediaBoxFetchPriority)], NoError>, MediaResourceFetchParameters?) -> Signal<MediaResourceDataFetchResult, MediaResourceDataFetchError>?, fetchResourceMediaReferenceHash: @escaping (MediaResource) -> Signal<Data?, NoError>, prepareSecretThumbnailData: @escaping (MediaResourceData) -> (CGSize, Data)?) {
|
||||||
self.updatePeerChatInputState = updatePeerChatInputState
|
self.updatePeerChatInputState = updatePeerChatInputState
|
||||||
self.fetchResource = fetchResource
|
self.fetchResource = fetchResource
|
||||||
self.fetchResourceMediaReferenceHash = fetchResourceMediaReferenceHash
|
self.fetchResourceMediaReferenceHash = fetchResourceMediaReferenceHash
|
||||||
|
self.prepareSecretThumbnailData = prepareSecretThumbnailData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1106,7 +1108,7 @@ public class Account {
|
|||||||
pendingMessageManager?.updatePendingMessageIds(view.ids)
|
pendingMessageManager?.updatePendingMessageIds(view.ids)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
self.managedOperationsDisposable.add(managedSecretChatOutgoingOperations(postbox: self.postbox, network: self.network).start())
|
self.managedOperationsDisposable.add(managedSecretChatOutgoingOperations(auxiliaryMethods: auxiliaryMethods, postbox: self.postbox, network: self.network).start())
|
||||||
self.managedOperationsDisposable.add(managedCloudChatRemoveMessagesOperations(postbox: self.postbox, network: self.network, stateManager: self.stateManager).start())
|
self.managedOperationsDisposable.add(managedCloudChatRemoveMessagesOperations(postbox: self.postbox, network: self.network, stateManager: self.stateManager).start())
|
||||||
self.managedOperationsDisposable.add(managedAutoremoveMessageOperations(postbox: self.postbox).start())
|
self.managedOperationsDisposable.add(managedAutoremoveMessageOperations(postbox: self.postbox).start())
|
||||||
self.managedOperationsDisposable.add(managedGlobalNotificationSettings(postbox: self.postbox, network: self.network).start())
|
self.managedOperationsDisposable.add(managedGlobalNotificationSettings(postbox: self.postbox, network: self.network).start())
|
||||||
|
|||||||
@ -109,7 +109,7 @@ private func takenImmutableOperation(postbox: Postbox, peerId: PeerId, tagLocalI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func managedSecretChatOutgoingOperations(postbox: Postbox, network: Network) -> Signal<Void, NoError> {
|
func managedSecretChatOutgoingOperations(auxiliaryMethods: AccountAuxiliaryMethods, postbox: Postbox, network: Network) -> Signal<Void, NoError> {
|
||||||
return Signal { _ in
|
return Signal { _ in
|
||||||
let helper = Atomic<ManagedSecretChatOutgoingOperationsHelper>(value: ManagedSecretChatOutgoingOperationsHelper())
|
let helper = Atomic<ManagedSecretChatOutgoingOperationsHelper>(value: ManagedSecretChatOutgoingOperationsHelper())
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ func managedSecretChatOutgoingOperations(postbox: Postbox, network: Network) ->
|
|||||||
case let .initialHandshakeAccept(gA, accessHash, b):
|
case let .initialHandshakeAccept(gA, accessHash, b):
|
||||||
return initialHandshakeAccept(postbox: postbox, network: network, peerId: entry.peerId, accessHash: accessHash, gA: gA, b: b, tagLocalIndex: entry.tagLocalIndex)
|
return initialHandshakeAccept(postbox: postbox, network: network, peerId: entry.peerId, accessHash: accessHash, gA: gA, b: b, tagLocalIndex: entry.tagLocalIndex)
|
||||||
case let .sendMessage(layer, id, file):
|
case let .sendMessage(layer, id, file):
|
||||||
return sendMessage(postbox: postbox, network: network, messageId: id, file: file, tagLocalIndex: entry.tagLocalIndex, wasDelivered: operation.delivered, layer: layer)
|
return sendMessage(auxiliaryMethods: auxiliaryMethods, postbox: postbox, network: network, messageId: id, file: file, tagLocalIndex: entry.tagLocalIndex, wasDelivered: operation.delivered, layer: layer)
|
||||||
case let .reportLayerSupport(layer, actionGloballyUniqueId, layerSupport):
|
case let .reportLayerSupport(layer, actionGloballyUniqueId, layerSupport):
|
||||||
return sendServiceActionMessage(postbox: postbox, network: network, peerId: entry.peerId, action: .reportLayerSupport(layer: layer, actionGloballyUniqueId: actionGloballyUniqueId, layerSupport: layerSupport), tagLocalIndex: entry.tagLocalIndex, wasDelivered: operation.delivered)
|
return sendServiceActionMessage(postbox: postbox, network: network, peerId: entry.peerId, action: .reportLayerSupport(layer: layer, actionGloballyUniqueId: actionGloballyUniqueId, layerSupport: layerSupport), tagLocalIndex: entry.tagLocalIndex, wasDelivered: operation.delivered)
|
||||||
case let .deleteMessages(layer, actionGloballyUniqueId, globallyUniqueIds):
|
case let .deleteMessages(layer, actionGloballyUniqueId, globallyUniqueIds):
|
||||||
@ -598,7 +598,7 @@ private func decryptedEntities73(_ entities: [MessageTextEntity]?) -> [SecretApi
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private func boxedDecryptedMessage(transaction: Transaction, message: Message, globallyUniqueId: Int64, uploadedFile: SecretChatOutgoingFile?, thumbnailData: [MediaId: Data], layer: SecretChatLayer) -> BoxedDecryptedMessage {
|
private func boxedDecryptedMessage(transaction: Transaction, message: Message, globallyUniqueId: Int64, uploadedFile: SecretChatOutgoingFile?, thumbnailData: [MediaId: (CGSize, Data)], layer: SecretChatLayer) -> BoxedDecryptedMessage {
|
||||||
let media: Media? = message.media.first
|
let media: Media? = message.media.first
|
||||||
var messageAutoremoveTimeout: Int32 = 0
|
var messageAutoremoveTimeout: Int32 = 0
|
||||||
var replyGlobalId: Int64? = nil
|
var replyGlobalId: Int64? = nil
|
||||||
@ -635,9 +635,9 @@ private func boxedDecryptedMessage(transaction: Transaction, message: Message, g
|
|||||||
let thumbW: Int32
|
let thumbW: Int32
|
||||||
let thumbH: Int32
|
let thumbH: Int32
|
||||||
let thumb: Buffer
|
let thumb: Buffer
|
||||||
if let smallestRepresentation = smallestImageRepresentation(image.representations), smallestRepresentation.dimensions.width < 100.0 && smallestRepresentation.dimensions.height < 100.0, let data = thumbnailData[image.imageId] {
|
if let (thumbnailSize, data) = thumbnailData[image.imageId] {
|
||||||
thumbW = Int32(smallestRepresentation.dimensions.width)
|
thumbW = Int32(thumbnailSize.width)
|
||||||
thumbH = Int32(smallestRepresentation.dimensions.height)
|
thumbH = Int32(thumbnailSize.height)
|
||||||
thumb = Buffer(data: data)
|
thumb = Buffer(data: data)
|
||||||
} else {
|
} else {
|
||||||
thumbW = 90
|
thumbW = 90
|
||||||
@ -680,9 +680,9 @@ private func boxedDecryptedMessage(transaction: Transaction, message: Message, g
|
|||||||
let thumbW: Int32
|
let thumbW: Int32
|
||||||
let thumbH: Int32
|
let thumbH: Int32
|
||||||
let thumb: Buffer
|
let thumb: Buffer
|
||||||
if let smallestRepresentation = smallestImageRepresentation(file.previewRepresentations), let data = thumbnailData[file.fileId] {
|
if let (thumbnailSize, data) = thumbnailData[file.fileId] {
|
||||||
thumbW = Int32(smallestRepresentation.dimensions.width)
|
thumbW = Int32(thumbnailSize.width)
|
||||||
thumbH = Int32(smallestRepresentation.dimensions.height)
|
thumbH = Int32(thumbnailSize.height)
|
||||||
thumb = Buffer(data: data)
|
thumb = Buffer(data: data)
|
||||||
} else {
|
} else {
|
||||||
thumbW = 0
|
thumbW = 0
|
||||||
@ -1078,47 +1078,47 @@ private func replaceOutgoingOperationWithEmptyMessage(transaction: Transaction,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func resourceThumbnailData(mediaBox: MediaBox, resource: MediaResource, mediaId: MediaId) -> Signal<(MediaId, Data)?, NoError> {
|
private func resourceThumbnailData(auxiliaryMethods: AccountAuxiliaryMethods, mediaBox: MediaBox, resource: MediaResource, mediaId: MediaId) -> Signal<(MediaId, CGSize, Data)?, NoError> {
|
||||||
return mediaBox.resourceData(resource, option: .complete(waitUntilFetchStatus: false))
|
return mediaBox.resourceData(resource, option: .complete(waitUntilFetchStatus: false))
|
||||||
|> take(1)
|
|> take(1)
|
||||||
|> map { data -> (MediaId, Data)? in
|
|> map { data -> (MediaId, CGSize, Data)? in
|
||||||
if data.complete, data.size < 1024 * 1024, let content = try? Data(contentsOf: URL(fileURLWithPath: data.path)) {
|
if data.complete, let (mappedSize, mappedData) = auxiliaryMethods.prepareSecretThumbnailData(data) {
|
||||||
return (mediaId, content)
|
return (mediaId, mappedSize, mappedData)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func messageWithThumbnailData(mediaBox: MediaBox, message: Message) -> Signal<[MediaId: Data], NoError> {
|
private func messageWithThumbnailData(auxiliaryMethods: AccountAuxiliaryMethods, mediaBox: MediaBox, message: Message) -> Signal<[MediaId: (CGSize, Data)], NoError> {
|
||||||
var signals: [Signal<(MediaId, Data)?, NoError>] = []
|
var signals: [Signal<(MediaId, CGSize, Data)?, NoError>] = []
|
||||||
for media in message.media {
|
for media in message.media {
|
||||||
if let image = media as? TelegramMediaImage {
|
if let image = media as? TelegramMediaImage {
|
||||||
if let smallestRepresentation = smallestImageRepresentation(image.representations) {
|
if let smallestRepresentation = smallestImageRepresentation(image.representations) {
|
||||||
signals.append(resourceThumbnailData(mediaBox: mediaBox, resource: smallestRepresentation.resource, mediaId: image.imageId))
|
signals.append(resourceThumbnailData(auxiliaryMethods: auxiliaryMethods, mediaBox: mediaBox, resource: smallestRepresentation.resource, mediaId: image.imageId))
|
||||||
}
|
}
|
||||||
} else if let file = media as? TelegramMediaFile {
|
} else if let file = media as? TelegramMediaFile {
|
||||||
if let smallestRepresentation = smallestImageRepresentation(file.previewRepresentations) {
|
if let smallestRepresentation = smallestImageRepresentation(file.previewRepresentations) {
|
||||||
signals.append(resourceThumbnailData(mediaBox: mediaBox, resource: smallestRepresentation.resource, mediaId: file.fileId))
|
signals.append(resourceThumbnailData(auxiliaryMethods: auxiliaryMethods, mediaBox: mediaBox, resource: smallestRepresentation.resource, mediaId: file.fileId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return combineLatest(signals)
|
return combineLatest(signals)
|
||||||
|> map { values in
|
|> map { values in
|
||||||
var result: [MediaId: Data] = [:]
|
var result: [MediaId: (CGSize, Data)] = [:]
|
||||||
for value in values {
|
for value in values {
|
||||||
if let value = value {
|
if let value = value {
|
||||||
result[value.0] = value.1
|
result[value.0] = (value.1, value.2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func sendMessage(postbox: Postbox, network: Network, messageId: MessageId, file: SecretChatOutgoingFile?, tagLocalIndex: Int32, wasDelivered: Bool, layer: SecretChatLayer) -> Signal<Void, NoError> {
|
private func sendMessage(auxiliaryMethods: AccountAuxiliaryMethods, postbox: Postbox, network: Network, messageId: MessageId, file: SecretChatOutgoingFile?, tagLocalIndex: Int32, wasDelivered: Bool, layer: SecretChatLayer) -> Signal<Void, NoError> {
|
||||||
return postbox.transaction { transaction -> Signal<[MediaId: Data], NoError> in
|
return postbox.transaction { transaction -> Signal<[MediaId: (CGSize, Data)], NoError> in
|
||||||
if let message = transaction.getMessage(messageId) {
|
if let message = transaction.getMessage(messageId) {
|
||||||
return messageWithThumbnailData(mediaBox: postbox.mediaBox, message: message)
|
return messageWithThumbnailData(auxiliaryMethods: auxiliaryMethods, mediaBox: postbox.mediaBox, message: message)
|
||||||
} else {
|
} else {
|
||||||
return .single([:])
|
return .single([:])
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user