mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 21:41:45 +00:00
Merge branch 'group_calls' of https://github.com/peter-iakovlev/TelegramCoreDev into group_calls
This commit is contained in:
commit
b55d22f2fa
@ -31,19 +31,23 @@ public final class CallListView {
|
||||
}
|
||||
}
|
||||
|
||||
private func pendingWebpages(entries: [MessageHistoryEntry]) -> Set<MessageId> {
|
||||
private func pendingWebpages(entries: [MessageHistoryEntry]) -> (Set<MessageId>, [MessageId: (MediaId, String)]) {
|
||||
var messageIds = Set<MessageId>()
|
||||
var localWebpages: [MessageId: (MediaId, String)] = [:]
|
||||
for case let .MessageEntry(message, _, _, _) in entries {
|
||||
for media in message.media {
|
||||
if let media = media as? TelegramMediaWebpage {
|
||||
if case .Pending = media.content {
|
||||
if case let .Pending(_, url) = media.content {
|
||||
messageIds.insert(message.id)
|
||||
if let url = url, media.webpageId.namespace == Namespaces.Media.LocalWebpage {
|
||||
localWebpages[message.id] = (media.webpageId, url)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return messageIds
|
||||
return (messageIds, localWebpages)
|
||||
}
|
||||
|
||||
private func fetchWebpage(account: Account, messageId: MessageId) -> Signal<Void, NoError> {
|
||||
@ -235,7 +239,7 @@ public final class AccountViewTracker {
|
||||
self.updatedViewCountDisposables.dispose()
|
||||
}
|
||||
|
||||
private func updatePendingWebpages(viewId: Int32, messageIds: Set<MessageId>) {
|
||||
private func updatePendingWebpages(viewId: Int32, messageIds: Set<MessageId>, localWebpages: [MessageId: (MediaId, String)]) {
|
||||
self.queue.async {
|
||||
var addedMessageIds: [MessageId] = []
|
||||
var removedMessageIds: [MessageId] = []
|
||||
@ -280,6 +284,34 @@ public final class AccountViewTracker {
|
||||
if let account = self.account {
|
||||
for messageId in addedMessageIds {
|
||||
if self.webpageDisposables[messageId] == nil {
|
||||
if let (_, url) = localWebpages[messageId] {
|
||||
self.webpageDisposables[messageId] = (webpagePreview(account: account, url: url) |> mapToSignal { webpage -> Signal<Void, NoError> in
|
||||
return account.postbox.modify { modifier -> Void in
|
||||
if let webpage = webpage {
|
||||
modifier.updateMessage(messageId, update: { currentMessage in
|
||||
var storeForwardInfo: StoreMessageForwardInfo?
|
||||
if let forwardInfo = currentMessage.forwardInfo {
|
||||
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature)
|
||||
}
|
||||
var media = currentMessage.media
|
||||
for i in 0 ..< media.count {
|
||||
if let _ = media[i] as? TelegramMediaWebpage {
|
||||
media[i] = webpage
|
||||
break
|
||||
}
|
||||
}
|
||||
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: media))
|
||||
})
|
||||
}
|
||||
}
|
||||
}).start(completed: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
strongSelf.queue.async {
|
||||
strongSelf.webpageDisposables.removeValue(forKey: messageId)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if messageId.namespace == Namespaces.Message.Cloud {
|
||||
self.webpageDisposables[messageId] = fetchWebpage(account: account, messageId: messageId).start(completed: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
strongSelf.queue.async {
|
||||
@ -287,6 +319,7 @@ public final class AccountViewTracker {
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
assertionFailure()
|
||||
}
|
||||
@ -555,8 +588,8 @@ public final class AccountViewTracker {
|
||||
}, next: { [weak self] next, viewId in
|
||||
if let strongSelf = self {
|
||||
strongSelf.queue.async {
|
||||
let messageIds = pendingWebpages(entries: next.0.entries)
|
||||
strongSelf.updatePendingWebpages(viewId: viewId, messageIds: messageIds)
|
||||
let (messageIds, localWebpages) = pendingWebpages(entries: next.0.entries)
|
||||
strongSelf.updatePendingWebpages(viewId: viewId, messageIds: messageIds, localWebpages: localWebpages)
|
||||
if case let .peer(peerId) = chatLocation, peerId.namespace == Namespaces.Peer.CloudChannel {
|
||||
strongSelf.historyViewStateValidationContexts.updateView(id: viewId, view: next.0)
|
||||
} else if case .group = chatLocation {
|
||||
@ -567,7 +600,7 @@ public final class AccountViewTracker {
|
||||
}, disposed: { [weak self] viewId in
|
||||
if let strongSelf = self {
|
||||
strongSelf.queue.async {
|
||||
strongSelf.updatePendingWebpages(viewId: viewId, messageIds: [])
|
||||
strongSelf.updatePendingWebpages(viewId: viewId, messageIds: [], localWebpages: [:])
|
||||
switch chatLocation {
|
||||
case let .peer(peerId):
|
||||
if peerId.namespace == Namespaces.Peer.CloudChannel {
|
||||
|
||||
@ -243,7 +243,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-1970352846] = { return Api.messages.Stickers.parse_stickers($0) }
|
||||
dict[1008755359] = { return Api.InlineBotSwitchPM.parse_inlineBotSwitchPM($0) }
|
||||
dict[223655517] = { return Api.messages.FoundStickerSets.parse_foundStickerSetsNotModified($0) }
|
||||
dict[-1285828951] = { return Api.messages.FoundStickerSets.parse_foundStickerSets($0) }
|
||||
dict[1359533640] = { return Api.messages.FoundStickerSets.parse_foundStickerSets($0) }
|
||||
dict[1158290442] = { return Api.messages.FoundGifs.parse_foundGifs($0) }
|
||||
dict[2086234950] = { return Api.FileLocation.parse_fileLocationUnavailable($0) }
|
||||
dict[1406570614] = { return Api.FileLocation.parse_fileLocation($0) }
|
||||
@ -309,6 +309,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[548253432] = { return Api.InputPeer.parse_inputPeerChannel($0) }
|
||||
dict[568808380] = { return Api.upload.WebFile.parse_webFile($0) }
|
||||
dict[-116274796] = { return Api.Contact.parse_contact($0) }
|
||||
dict[1648543603] = { return Api.FileHash.parse_fileHash($0) }
|
||||
dict[-1679053127] = { return Api.BotInlineResult.parse_botInlineResult($0) }
|
||||
dict[400266251] = { return Api.BotInlineResult.parse_botInlineMediaResult($0) }
|
||||
dict[911761060] = { return Api.messages.BotCallbackAnswer.parse_botCallbackAnswer($0) }
|
||||
@ -378,7 +379,6 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[1218642516] = { return Api.ReplyMarkup.parse_replyInlineMarkup($0) }
|
||||
dict[1493171408] = { return Api.HighScore.parse_highScore($0) }
|
||||
dict[-305282981] = { return Api.TopPeer.parse_topPeer($0) }
|
||||
dict[2012136335] = { return Api.CdnFileHash.parse_cdnFileHash($0) }
|
||||
dict[986597452] = { return Api.contacts.Link.parse_link($0) }
|
||||
dict[1444661369] = { return Api.ContactBlocked.parse_contactBlocked($0) }
|
||||
dict[-2128698738] = { return Api.auth.CheckedPhone.parse_checkedPhone($0) }
|
||||
@ -388,7 +388,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-1908433218] = { return Api.Page.parse_pagePart($0) }
|
||||
dict[1433323434] = { return Api.Page.parse_pageFull($0) }
|
||||
dict[157948117] = { return Api.upload.File.parse_file($0) }
|
||||
dict[-363659686] = { return Api.upload.File.parse_fileCdnRedirect($0) }
|
||||
dict[-242427324] = { return Api.upload.File.parse_fileCdnRedirect($0) }
|
||||
dict[182649427] = { return Api.MessageRange.parse_messageRange($0) }
|
||||
dict[946083368] = { return Api.messages.StickerSetInstallResult.parse_stickerSetInstallResultSuccess($0) }
|
||||
dict[904138920] = { return Api.messages.StickerSetInstallResult.parse_stickerSetInstallResultArchive($0) }
|
||||
@ -841,6 +841,8 @@ public struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.Contact:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.FileHash:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.BotInlineResult:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.messages.BotCallbackAnswer:
|
||||
@ -903,8 +905,6 @@ public struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.TopPeer:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.CdnFileHash:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.contacts.Link:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.ContactBlocked:
|
||||
@ -1319,7 +1319,7 @@ public struct Api {
|
||||
|
||||
public enum FoundStickerSets {
|
||||
case foundStickerSetsNotModified
|
||||
case foundStickerSets(hash: Int32, sets: [Api.StickerSet])
|
||||
case foundStickerSets(hash: Int32, sets: [Api.StickerSetCovered])
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
@ -1331,7 +1331,7 @@ public struct Api {
|
||||
break
|
||||
case .foundStickerSets(let hash, let sets):
|
||||
if boxed {
|
||||
buffer.appendInt32(-1285828951)
|
||||
buffer.appendInt32(1359533640)
|
||||
}
|
||||
serializeInt32(hash, buffer: buffer, boxed: false)
|
||||
buffer.appendInt32(481674261)
|
||||
@ -1348,9 +1348,9 @@ public struct Api {
|
||||
fileprivate static func parse_foundStickerSets(_ reader: BufferReader) -> FoundStickerSets? {
|
||||
var _1: Int32?
|
||||
_1 = reader.readInt32()
|
||||
var _2: [Api.StickerSet]?
|
||||
var _2: [Api.StickerSetCovered]?
|
||||
if let _ = reader.readInt32() {
|
||||
_2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StickerSet.self)
|
||||
_2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StickerSetCovered.self)
|
||||
}
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
@ -9146,6 +9146,42 @@ public struct Api {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum FileHash {
|
||||
case fileHash(offset: Int32, limit: Int32, hash: Buffer)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
case .fileHash(let offset, let limit, let hash):
|
||||
if boxed {
|
||||
buffer.appendInt32(1648543603)
|
||||
}
|
||||
serializeInt32(offset, buffer: buffer, boxed: false)
|
||||
serializeInt32(limit, buffer: buffer, boxed: false)
|
||||
serializeBytes(hash, buffer: buffer, boxed: false)
|
||||
break
|
||||
}
|
||||
}
|
||||
fileprivate static func parse_fileHash(_ reader: BufferReader) -> FileHash? {
|
||||
var _1: Int32?
|
||||
_1 = reader.readInt32()
|
||||
var _2: Int32?
|
||||
_2 = reader.readInt32()
|
||||
var _3: Buffer?
|
||||
_3 = parseBytes(reader)
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
let _c3 = _3 != nil
|
||||
if _c1 && _c2 && _c3 {
|
||||
return Api.FileHash.fileHash(offset: _1!, limit: _2!, hash: _3!)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum BotInlineResult {
|
||||
@ -10414,42 +10450,6 @@ public struct Api {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum CdnFileHash {
|
||||
case cdnFileHash(offset: Int32, limit: Int32, hash: Buffer)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
case .cdnFileHash(let offset, let limit, let hash):
|
||||
if boxed {
|
||||
buffer.appendInt32(2012136335)
|
||||
}
|
||||
serializeInt32(offset, buffer: buffer, boxed: false)
|
||||
serializeInt32(limit, buffer: buffer, boxed: false)
|
||||
serializeBytes(hash, buffer: buffer, boxed: false)
|
||||
break
|
||||
}
|
||||
}
|
||||
fileprivate static func parse_cdnFileHash(_ reader: BufferReader) -> CdnFileHash? {
|
||||
var _1: Int32?
|
||||
_1 = reader.readInt32()
|
||||
var _2: Int32?
|
||||
_2 = reader.readInt32()
|
||||
var _3: Buffer?
|
||||
_3 = parseBytes(reader)
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
let _c3 = _3 != nil
|
||||
if _c1 && _c2 && _c3 {
|
||||
return Api.CdnFileHash.cdnFileHash(offset: _1!, limit: _2!, hash: _3!)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public enum ContactBlocked {
|
||||
@ -18337,7 +18337,7 @@ public struct Api {
|
||||
|
||||
public enum File {
|
||||
case file(type: Api.storage.FileType, mtime: Int32, bytes: Buffer)
|
||||
case fileCdnRedirect(dcId: Int32, fileToken: Buffer, encryptionKey: Buffer, encryptionIv: Buffer, cdnFileHashes: [Api.CdnFileHash])
|
||||
case fileCdnRedirect(dcId: Int32, fileToken: Buffer, encryptionKey: Buffer, encryptionIv: Buffer, fileHashes: [Api.FileHash])
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
@ -18349,17 +18349,17 @@ public struct Api {
|
||||
serializeInt32(mtime, buffer: buffer, boxed: false)
|
||||
serializeBytes(bytes, buffer: buffer, boxed: false)
|
||||
break
|
||||
case .fileCdnRedirect(let dcId, let fileToken, let encryptionKey, let encryptionIv, let cdnFileHashes):
|
||||
case .fileCdnRedirect(let dcId, let fileToken, let encryptionKey, let encryptionIv, let fileHashes):
|
||||
if boxed {
|
||||
buffer.appendInt32(-363659686)
|
||||
buffer.appendInt32(-242427324)
|
||||
}
|
||||
serializeInt32(dcId, buffer: buffer, boxed: false)
|
||||
serializeBytes(fileToken, buffer: buffer, boxed: false)
|
||||
serializeBytes(encryptionKey, buffer: buffer, boxed: false)
|
||||
serializeBytes(encryptionIv, buffer: buffer, boxed: false)
|
||||
buffer.appendInt32(481674261)
|
||||
buffer.appendInt32(Int32(cdnFileHashes.count))
|
||||
for item in cdnFileHashes {
|
||||
buffer.appendInt32(Int32(fileHashes.count))
|
||||
for item in fileHashes {
|
||||
item.serialize(buffer, true)
|
||||
}
|
||||
break
|
||||
@ -18393,9 +18393,9 @@ public struct Api {
|
||||
_3 = parseBytes(reader)
|
||||
var _4: Buffer?
|
||||
_4 = parseBytes(reader)
|
||||
var _5: [Api.CdnFileHash]?
|
||||
var _5: [Api.FileHash]?
|
||||
if let _ = reader.readInt32() {
|
||||
_5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.CdnFileHash.self)
|
||||
_5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.FileHash.self)
|
||||
}
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
@ -18403,7 +18403,7 @@ public struct Api {
|
||||
let _c4 = _4 != nil
|
||||
let _c5 = _5 != nil
|
||||
if _c1 && _c2 && _c3 && _c4 && _c5 {
|
||||
return Api.upload.File.fileCdnRedirect(dcId: _1!, fileToken: _2!, encryptionKey: _3!, encryptionIv: _4!, cdnFileHashes: _5!)
|
||||
return Api.upload.File.fileCdnRedirect(dcId: _1!, fileToken: _2!, encryptionKey: _3!, encryptionIv: _4!, fileHashes: _5!)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
@ -22253,31 +22253,46 @@ public struct Api {
|
||||
})
|
||||
}
|
||||
|
||||
public static func reuploadCdnFile(fileToken: Buffer, requestToken: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.CdnFileHash]?) {
|
||||
public static func reuploadCdnFile(fileToken: Buffer, requestToken: Buffer) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.FileHash]?) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(452533257)
|
||||
buffer.appendInt32(-1691921240)
|
||||
serializeBytes(fileToken, buffer: buffer, boxed: false)
|
||||
serializeBytes(requestToken, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription({return "(upload.reuploadCdnFile fileToken: \(fileToken), requestToken: \(requestToken))"}), buffer, { (buffer: Buffer) -> [Api.CdnFileHash]? in
|
||||
return (FunctionDescription({return "(upload.reuploadCdnFile fileToken: \(fileToken), requestToken: \(requestToken))"}), buffer, { (buffer: Buffer) -> [Api.FileHash]? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: [Api.CdnFileHash]?
|
||||
var result: [Api.FileHash]?
|
||||
if let _ = reader.readInt32() {
|
||||
result = Api.parseVector(reader, elementSignature: 0, elementType: Api.CdnFileHash.self)
|
||||
result = Api.parseVector(reader, elementSignature: 0, elementType: Api.FileHash.self)
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
public static func getCdnFileHashes(fileToken: Buffer, offset: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.CdnFileHash]?) {
|
||||
public static func getCdnFileHashes(fileToken: Buffer, offset: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.FileHash]?) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(-149567365)
|
||||
buffer.appendInt32(1302676017)
|
||||
serializeBytes(fileToken, buffer: buffer, boxed: false)
|
||||
serializeInt32(offset, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription({return "(upload.getCdnFileHashes fileToken: \(fileToken), offset: \(offset))"}), buffer, { (buffer: Buffer) -> [Api.CdnFileHash]? in
|
||||
return (FunctionDescription({return "(upload.getCdnFileHashes fileToken: \(fileToken), offset: \(offset))"}), buffer, { (buffer: Buffer) -> [Api.FileHash]? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: [Api.CdnFileHash]?
|
||||
var result: [Api.FileHash]?
|
||||
if let _ = reader.readInt32() {
|
||||
result = Api.parseVector(reader, elementSignature: 0, elementType: Api.CdnFileHash.self)
|
||||
result = Api.parseVector(reader, elementSignature: 0, elementType: Api.FileHash.self)
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
public static func getFileHashes(location: Api.InputFileLocation, offset: Int32) -> (CustomStringConvertible, Buffer, (Buffer) -> [Api.FileHash]?) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(-956147407)
|
||||
location.serialize(buffer, true)
|
||||
serializeInt32(offset, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription({return "(upload.getFileHashes location: \(location), offset: \(offset))"}), buffer, { (buffer: Buffer) -> [Api.FileHash]? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: [Api.FileHash]?
|
||||
if let _ = reader.readInt32() {
|
||||
result = Api.parseVector(reader, elementSignature: 0, elementType: Api.FileHash.self)
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
@ -7,7 +7,7 @@ import Foundation
|
||||
import SwiftSignalKit
|
||||
#endif
|
||||
|
||||
private func applyMediaResourceChanges(from: Media, to: Media, postbox: Postbox) {
|
||||
func applyMediaResourceChanges(from: Media, to: Media, postbox: Postbox) {
|
||||
if let fromImage = from as? TelegramMediaImage, let toImage = to as? TelegramMediaImage {
|
||||
let fromSmallestRepresentation = smallestImageRepresentation(fromImage.representations)
|
||||
if let fromSmallestRepresentation = fromSmallestRepresentation, let toSmallestRepresentation = smallestImageRepresentation(toImage.representations) {
|
||||
|
||||
@ -73,6 +73,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
||||
deinit {
|
||||
self.mtProto.remove(self.requestService)
|
||||
self.mtProto.stop()
|
||||
self.mtProto.finalize()
|
||||
self.shouldKeepConnectionDisposable?.dispose()
|
||||
}
|
||||
|
||||
|
||||
@ -711,11 +711,11 @@ private func boxedDecryptedMessage(modifier: Modifier, message: Message, globall
|
||||
}
|
||||
}
|
||||
|
||||
if let voiceDuration = voiceDuration {
|
||||
/*if let voiceDuration = voiceDuration {
|
||||
decryptedMedia = SecretApi73.DecryptedMessageMedia.decryptedMessageMediaAudio(duration: voiceDuration, mimeType: file.mimeType, size: uploadedFile.size, key: Buffer(data: uploadedFile.key.aesKey), iv: Buffer(data: uploadedFile.key.aesIv))
|
||||
} else {
|
||||
} else { */
|
||||
decryptedMedia = SecretApi73.DecryptedMessageMedia.decryptedMessageMediaDocument(thumb: thumb, thumbW: thumbW, thumbH: thumbH, mimeType: file.mimeType, size: uploadedFile.size, key: Buffer(data: uploadedFile.key.aesKey), iv: Buffer(data: uploadedFile.key.aesIv), attributes: decryptedAttributes73(file.attributes), caption: "")
|
||||
}
|
||||
//}
|
||||
} else {
|
||||
if let resource = file.resource as? CloudDocumentMediaResource, let size = file.size {
|
||||
let thumb: SecretApi73.PhotoSize
|
||||
@ -736,6 +736,9 @@ private func boxedDecryptedMessage(modifier: Modifier, message: Message, globall
|
||||
if let _ = decryptedEntites {
|
||||
flags |= (1 << 7)
|
||||
}
|
||||
if message.groupingKey != nil {
|
||||
flags |= (1 << 17)
|
||||
}
|
||||
flags |= (1 << 9)
|
||||
return .layer73(.decryptedMessage(flags: flags, randomId: globallyUniqueId, ttl: messageAutoremoveTimeout, message: message.text, media: decryptedMedia, entities: decryptedEntites, viaBotName: viaBotName, replyToRandomId: replyGlobalId, groupedId: message.groupingKey))
|
||||
}
|
||||
@ -1036,12 +1039,14 @@ private func sendMessage(postbox: Postbox, network: Network, messageId: MessageI
|
||||
}
|
||||
|
||||
var timestamp = message.timestamp
|
||||
var encryptedFile: SecretChatFileReference?
|
||||
if let result = result {
|
||||
switch result {
|
||||
case let .sentEncryptedMessage(date):
|
||||
timestamp = date
|
||||
case let .sentEncryptedFile(date, _):
|
||||
case let .sentEncryptedFile(date, file):
|
||||
timestamp = date
|
||||
encryptedFile = SecretChatFileReference(file)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1060,7 +1065,22 @@ private func sendMessage(postbox: Postbox, network: Network, messageId: MessageI
|
||||
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature)
|
||||
}
|
||||
|
||||
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
|
||||
var updatedMedia = currentMessage.media
|
||||
|
||||
if let fromMedia = currentMessage.media.first, let encryptedFile = encryptedFile, let file = file {
|
||||
var toMedia: Media?
|
||||
if let fromMedia = fromMedia as? TelegramMediaFile {
|
||||
let updatedFile = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.CloudSecretFile, id: encryptedFile.id), resource: SecretFileMediaResource(fileId: encryptedFile.id, accessHash: encryptedFile.accessHash, containerSize: encryptedFile.size, decryptedSize: file.size, datacenterId: Int(encryptedFile.datacenterId), key: file.key), previewRepresentations: fromMedia.previewRepresentations, mimeType: fromMedia.mimeType, size: fromMedia.size, attributes: fromMedia.attributes)
|
||||
toMedia = updatedFile
|
||||
updatedMedia = [updatedFile]
|
||||
}
|
||||
|
||||
if let toMedia = toMedia {
|
||||
applyMediaResourceChanges(from: fromMedia, to: toMedia, postbox: postbox)
|
||||
}
|
||||
}
|
||||
|
||||
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: updatedMedia))
|
||||
})
|
||||
|
||||
maybeReadSecretOutgoingMessage(modifier: modifier, index: MessageIndex(id: message.id, timestamp: timestamp))
|
||||
|
||||
@ -247,7 +247,7 @@ private final class MultipartCdnHashSource {
|
||||
var parsedPartHashes: [Int32: Data] = [:]
|
||||
for part in partHashes {
|
||||
switch part {
|
||||
case let .cdnFileHash(offset, limit, bytes):
|
||||
case let .fileHash(offset, limit, bytes):
|
||||
assert(limit == 128 * 1024)
|
||||
parsedPartHashes[offset] = bytes.makeData()
|
||||
}
|
||||
@ -322,7 +322,7 @@ private enum MultipartFetchSource {
|
||||
var parsedPartHashes: [Int32: Data] = [:]
|
||||
for part in partHashes {
|
||||
switch part {
|
||||
case let .cdnFileHash(offset, limit, bytes):
|
||||
case let .fileHash(offset, limit, bytes):
|
||||
assert(limit == 128 * 1024)
|
||||
parsedPartHashes[offset] = bytes.makeData()
|
||||
}
|
||||
@ -591,9 +591,9 @@ private final class MultipartFetchManager {
|
||||
case let .cdn(_, fileToken, _, _, _, masterDownload, _):
|
||||
if !strongSelf.reuploadingToCdn {
|
||||
strongSelf.reuploadingToCdn = true
|
||||
let reupload: Signal<[Api.CdnFileHash], NoError> = masterDownload.get() |> mapToSignal { download -> Signal<[Api.CdnFileHash], NoError> in
|
||||
let reupload: Signal<[Api.FileHash], NoError> = masterDownload.get() |> mapToSignal { download -> Signal<[Api.FileHash], NoError> in
|
||||
return download.request(Api.functions.upload.reuploadCdnFile(fileToken: Buffer(data: fileToken), requestToken: Buffer(data: token)))
|
||||
|> `catch` { _ -> Signal<[Api.CdnFileHash], NoError> in
|
||||
|> `catch` { _ -> Signal<[Api.FileHash], NoError> in
|
||||
return .single([])
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func messageContentToUpload(network: Network, postbox: Postbox, auxiliaryMethods
|
||||
if let reference = image.reference, case let .cloud(id, accessHash) = reference {
|
||||
return .ready(.media(Api.InputMedia.inputMediaPhoto(flags: 0, id: Api.InputPhoto.inputPhoto(id: id, accessHash: accessHash), ttlSeconds: nil), text))
|
||||
} else {
|
||||
return .upload(uploadedMediaImageContent(network: network, postbox: postbox, peerId: peerId, image: image, text: text, autoremoveAttribute: autoremoveAttribute))
|
||||
return .upload(uploadedMediaImageContent(network: network, postbox: postbox, transformOutgoingMessageMedia: transformOutgoingMessageMedia, peerId: peerId, image: image, text: text, autoremoveAttribute: autoremoveAttribute))
|
||||
}
|
||||
} else if let file = media as? TelegramMediaFile {
|
||||
if let resource = file.resource as? CloudDocumentMediaResource {
|
||||
@ -193,7 +193,7 @@ private func maybeCacheUploadedResource(postbox: Postbox, key: CachedSentMediaRe
|
||||
}
|
||||
}
|
||||
|
||||
private func uploadedMediaImageContent(network: Network, postbox: Postbox, peerId: PeerId, image: TelegramMediaImage, text: String, autoremoveAttribute: AutoremoveTimeoutMessageAttribute?) -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> {
|
||||
private func uploadedMediaImageContent(network: Network, postbox: Postbox, transformOutgoingMessageMedia: TransformOutgoingMessageMedia?, peerId: PeerId, image: TelegramMediaImage, text: String, autoremoveAttribute: AutoremoveTimeoutMessageAttribute?) -> Signal<PendingMessageUploadedContentResult, PendingMessageUploadError> {
|
||||
if let largestRepresentation = largestImageRepresentation(image.representations) {
|
||||
let predownloadedResource: Signal<PredownloadedResource, PendingMessageUploadError> = maybePredownloadedImageResource(postbox: postbox, peerId: peerId, resource: largestRepresentation.resource)
|
||||
return predownloadedResource
|
||||
|
||||
@ -726,9 +726,8 @@ private func parseMessage(peerId: PeerId, authorId: PeerId, tagLocalIndex: Int32
|
||||
}
|
||||
}
|
||||
|
||||
private func parseEntities(_ entities: [SecretApi73.MessageEntity]?) -> TextEntitiesMessageAttribute {
|
||||
private func parseEntities(_ entities: [SecretApi73.MessageEntity]) -> TextEntitiesMessageAttribute {
|
||||
var result: [MessageTextEntity] = []
|
||||
if let entities = entities {
|
||||
for entity in entities {
|
||||
switch entity {
|
||||
case let .messageEntityMention(offset, length):
|
||||
@ -755,7 +754,6 @@ private func parseEntities(_ entities: [SecretApi73.MessageEntity]?) -> TextEnti
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return TextEntitiesMessageAttribute(entities: result)
|
||||
}
|
||||
|
||||
@ -771,7 +769,9 @@ private func parseMessage(peerId: PeerId, authorId: PeerId, tagLocalIndex: Int32
|
||||
attributes.append(AutoremoveTimeoutMessageAttribute(timeout: ttl, countdownBeginTime: nil))
|
||||
}
|
||||
|
||||
attributes.append(parseEntities(entities))
|
||||
if let entitiesAttribute = entities.flatMap(parseEntities) {
|
||||
attributes.append(entitiesAttribute)
|
||||
}
|
||||
|
||||
if let viaBotName = viaBotName, !viaBotName.isEmpty {
|
||||
attributes.append(InlineBotMessageAttribute(peerId: nil, title: viaBotName))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user