mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-07-20 22:40:50 +02:00
Update Ghostgram features
This commit is contained in:
@@ -42,7 +42,8 @@ func _internal_archivedStickerPacks(account: Account, namespace: ArchivedSticker
|
||||
|> map { result -> [ArchivedStickerPackItem] in
|
||||
var archivedItems: [ArchivedStickerPackItem] = []
|
||||
switch result {
|
||||
case let .archivedStickers(_, sets):
|
||||
case let .archivedStickers(archivedStickersData):
|
||||
let sets = archivedStickersData.sets
|
||||
for set in sets {
|
||||
let (info, items) = parsePreviewStickerSet(set, namespace: namespace.itemCollectionNamespace)
|
||||
archivedItems.append(ArchivedStickerPackItem(info: info, topItems: items))
|
||||
@@ -55,7 +56,7 @@ func _internal_archivedStickerPacks(account: Account, namespace: ArchivedSticker
|
||||
}
|
||||
|
||||
func _internal_removeArchivedStickerPack(account: Account, info: StickerPackCollectionInfo) -> Signal<Void, NoError> {
|
||||
return account.network.request(Api.functions.messages.uninstallStickerSet(stickerset: Api.InputStickerSet.inputStickerSetID(id: info.id.id, accessHash: info.accessHash)))
|
||||
return account.network.request(Api.functions.messages.uninstallStickerSet(stickerset: Api.InputStickerSet.inputStickerSetID(.init(id: info.id.id, accessHash: info.accessHash))))
|
||||
|> `catch` { _ -> Signal<Api.Bool, NoError> in
|
||||
return .single(.boolFalse)
|
||||
}
|
||||
|
||||
@@ -78,16 +78,17 @@ func _internal_uploadSticker(account: Account, peer: Peer, resource: MediaResour
|
||||
flags |= (1 << 2)
|
||||
}
|
||||
var attributes: [Api.DocumentAttribute] = []
|
||||
attributes.append(.documentAttributeSticker(flags: 0, alt: alt, stickerset: .inputStickerSetEmpty, maskCoords: nil))
|
||||
attributes.append(.documentAttributeSticker(.init(flags: 0, alt: alt, stickerset: .inputStickerSetEmpty, maskCoords: nil)))
|
||||
if let duration {
|
||||
attributes.append(.documentAttributeVideo(flags: 0, duration: duration, w: dimensions.width, h: dimensions.height, preloadPrefixSize: nil, videoStartTs: nil, videoCodec: nil))
|
||||
attributes.append(.documentAttributeVideo(.init(flags: 0, duration: duration, w: dimensions.width, h: dimensions.height, preloadPrefixSize: nil, videoStartTs: nil, videoCodec: nil)))
|
||||
}
|
||||
attributes.append(.documentAttributeImageSize(w: dimensions.width, h: dimensions.height))
|
||||
return account.network.request(Api.functions.messages.uploadMedia(flags: 0, businessConnectionId: nil, peer: inputPeer, media: Api.InputMedia.inputMediaUploadedDocument(flags: flags, file: file, thumb: thumbnailFile, mimeType: mimeType, attributes: attributes, stickers: nil, videoCover: nil, videoTimestamp: nil, ttlSeconds: nil)))
|
||||
attributes.append(.documentAttributeImageSize(.init(w: dimensions.width, h: dimensions.height)))
|
||||
return account.network.request(Api.functions.messages.uploadMedia(flags: 0, businessConnectionId: nil, peer: inputPeer, media: Api.InputMedia.inputMediaUploadedDocument(.init(flags: flags, file: file, thumb: thumbnailFile, mimeType: mimeType, attributes: attributes, stickers: nil, videoCover: nil, videoTimestamp: nil, ttlSeconds: nil))))
|
||||
|> mapError { _ -> UploadStickerError in return .generic }
|
||||
|> mapToSignal { media -> Signal<UploadStickerStatus, UploadStickerError> in
|
||||
switch media {
|
||||
case let .messageMediaDocument(_, document, altDocuments, _, _, _):
|
||||
case let .messageMediaDocument(messageMediaDocumentData):
|
||||
let (document, altDocuments) = (messageMediaDocumentData.document, messageMediaDocumentData.altDocuments)
|
||||
if let document = document, let file = telegramMediaFileFromApiDocument(document, altDocuments: altDocuments), let uploadedResource = file.resource as? CloudDocumentMediaResource {
|
||||
account.postbox.mediaBox.copyResourceData(from: resource.id, to: uploadedResource.id, synchronous: true)
|
||||
if let thumbnail, let previewRepresentation = file.previewRepresentations.first(where: { $0.dimensions == PixelDimensions(width: 320, height: 320) }) {
|
||||
@@ -243,12 +244,12 @@ func _internal_createStickerSet(account: Account, title: String, shortName: Stri
|
||||
flags |= (1 << 1)
|
||||
}
|
||||
|
||||
inputStickers.append(.inputStickerSetItem(flags: flags, document: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data())), emoji: sticker.emojis.joined(), maskCoords: nil, keywords: sticker.keywords))
|
||||
inputStickers.append(.inputStickerSetItem(.init(flags: flags, document: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data()))), emoji: sticker.emojis.joined(), maskCoords: nil, keywords: sticker.keywords)))
|
||||
}
|
||||
var thumbnailDocument: Api.InputDocument?
|
||||
if thumbnail != nil, let resource = resources.last {
|
||||
flags |= (1 << 2)
|
||||
thumbnailDocument = .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data()))
|
||||
thumbnailDocument = .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data())))
|
||||
}
|
||||
if let software = software, !software.isEmpty {
|
||||
flags |= (1 << 3)
|
||||
@@ -388,7 +389,7 @@ func _internal_addStickerToStickerSet(account: Account, packReference: StickerPa
|
||||
if sticker.keywords.count > 0 {
|
||||
flags |= (1 << 1)
|
||||
}
|
||||
let inputSticker: Api.InputStickerSetItem = .inputStickerSetItem(flags: flags, document: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data())), emoji: sticker.emojis.joined(), maskCoords: nil, keywords: sticker.keywords)
|
||||
let inputSticker: Api.InputStickerSetItem = .inputStickerSetItem(.init(flags: flags, document: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data()))), emoji: sticker.emojis.joined(), maskCoords: nil, keywords: sticker.keywords))
|
||||
return account.network.request(Api.functions.stickers.addStickerToSet(stickerset: packReference.apiInputStickerSet, sticker: inputSticker))
|
||||
|> `catch` { error -> Signal<Api.messages.StickerSet, MTRpcError> in
|
||||
if error.errorDescription == "FILE_REFERENCE_EXPIRED" {
|
||||
@@ -400,8 +401,8 @@ func _internal_addStickerToStickerSet(account: Account, packReference: StickerPa
|
||||
guard let resource = result.updatedResource as? CloudDocumentMediaResource else {
|
||||
return .fail(MTRpcError(errorCode: 500, errorDescription: "Internal"))
|
||||
}
|
||||
|
||||
let inputSticker: Api.InputStickerSetItem = .inputStickerSetItem(flags: flags, document: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)), emoji: sticker.emojis.joined(), maskCoords: nil, keywords: sticker.keywords)
|
||||
|
||||
let inputSticker: Api.InputStickerSetItem = .inputStickerSetItem(.init(flags: flags, document: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))), emoji: sticker.emojis.joined(), maskCoords: nil, keywords: sticker.keywords))
|
||||
|
||||
return account.network.request(Api.functions.stickers.addStickerToSet(stickerset: packReference.apiInputStickerSet, sticker: inputSticker))
|
||||
}
|
||||
@@ -434,7 +435,7 @@ public enum ReorderStickerError {
|
||||
|
||||
func _internal_reorderSticker(account: Account, sticker: FileMediaReference, position: Int) -> Signal<Never, ReorderStickerError> {
|
||||
return revalidatedSticker(account: account, sticker: sticker, signal: { resource in
|
||||
return account.network.request(Api.functions.stickers.changeStickerPosition(sticker: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)), position: Int32(position)))
|
||||
return account.network.request(Api.functions.stickers.changeStickerPosition(sticker: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))), position: Int32(position)))
|
||||
})
|
||||
|> mapError { error -> ReorderStickerError in
|
||||
return .generic
|
||||
@@ -461,7 +462,7 @@ public enum DeleteStickerError {
|
||||
|
||||
func _internal_deleteStickerFromStickerSet(account: Account, sticker: FileMediaReference) -> Signal<Never, DeleteStickerError> {
|
||||
return revalidatedSticker(account: account, sticker: sticker, signal: { resource in
|
||||
return account.network.request(Api.functions.stickers.removeStickerFromSet(sticker: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference))))
|
||||
return account.network.request(Api.functions.stickers.removeStickerFromSet(sticker: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference)))))
|
||||
})
|
||||
|> mapError { error -> DeleteStickerError in
|
||||
return .generic
|
||||
@@ -508,9 +509,9 @@ func _internal_replaceSticker(account: Account, previousSticker: FileMediaRefere
|
||||
if sticker.keywords.count > 0 {
|
||||
flags |= (1 << 1)
|
||||
}
|
||||
let inputSticker: Api.InputStickerSetItem = .inputStickerSetItem(flags: flags, document: .inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data())), emoji: sticker.emojis.joined(), maskCoords: nil, keywords: sticker.keywords)
|
||||
let inputSticker: Api.InputStickerSetItem = .inputStickerSetItem(.init(flags: flags, document: .inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data()))), emoji: sticker.emojis.joined(), maskCoords: nil, keywords: sticker.keywords))
|
||||
return revalidatedSticker(account: account, sticker: previousSticker, signal: { previousResource in
|
||||
return account.network.request(Api.functions.stickers.replaceSticker(sticker: .inputDocument(id: previousResource.fileId, accessHash: previousResource.accessHash, fileReference: Buffer(data: previousResource.fileReference)), newSticker: inputSticker))
|
||||
return account.network.request(Api.functions.stickers.replaceSticker(sticker: .inputDocument(.init(id: previousResource.fileId, accessHash: previousResource.accessHash, fileReference: Buffer(data: previousResource.fileReference))), newSticker: inputSticker))
|
||||
})
|
||||
|> mapError { error -> ReplaceStickerError in
|
||||
return .generic
|
||||
@@ -543,13 +544,16 @@ func _internal_getMyStickerSets(account: Account) -> Signal<[(StickerPackCollect
|
||||
}
|
||||
var infos: [(StickerPackCollectionInfo, StickerPackItem?)] = []
|
||||
switch result {
|
||||
case let .myStickers(_, sets):
|
||||
case let .myStickers(myStickersData):
|
||||
let sets = myStickersData.sets
|
||||
for set in sets {
|
||||
switch set {
|
||||
case let .stickerSetCovered(set, cover):
|
||||
case let .stickerSetCovered(stickerSetCoveredData):
|
||||
let (set, cover) = (stickerSetCoveredData.set, stickerSetCoveredData.cover)
|
||||
let namespace: ItemCollectionId.Namespace
|
||||
switch set {
|
||||
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _, _, _):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let flags = stickerSetData.flags
|
||||
if (flags & (1 << 3)) != 0 {
|
||||
namespace = Namespaces.ItemCollection.CloudMaskPacks
|
||||
} else if (flags & (1 << 7)) != 0 {
|
||||
@@ -564,10 +568,12 @@ func _internal_getMyStickerSets(account: Account) -> Signal<[(StickerPackCollect
|
||||
firstItem = StickerPackItem(index: ItemCollectionItemIndex(index: 0, id: id.id), file: file, indexKeys: [])
|
||||
}
|
||||
infos.append((info, firstItem))
|
||||
case let .stickerSetFullCovered(set, _, _, documents):
|
||||
case let .stickerSetFullCovered(stickerSetFullCoveredData):
|
||||
let (set, documents) = (stickerSetFullCoveredData.set, stickerSetFullCoveredData.documents)
|
||||
let namespace: ItemCollectionId.Namespace
|
||||
switch set {
|
||||
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _, _, _):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let flags = stickerSetData.flags
|
||||
if (flags & (1 << 3)) != 0 {
|
||||
namespace = Namespaces.ItemCollection.CloudMaskPacks
|
||||
} else if (flags & (1 << 7)) != 0 {
|
||||
@@ -597,10 +603,12 @@ private func parseStickerSetInfoAndItems(apiStickerSet: Api.messages.StickerSet)
|
||||
switch apiStickerSet {
|
||||
case .stickerSetNotModified:
|
||||
return nil
|
||||
case let .stickerSet(set, packs, keywords, documents):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let (set, packs, keywords, documents) = (stickerSetData.set, stickerSetData.packs, stickerSetData.keywords, stickerSetData.documents)
|
||||
let namespace: ItemCollectionId.Namespace
|
||||
switch set {
|
||||
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _, _, _):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let flags = stickerSetData.flags
|
||||
if (flags & (1 << 3)) != 0 {
|
||||
namespace = Namespaces.ItemCollection.CloudMaskPacks
|
||||
} else if (flags & (1 << 7)) != 0 {
|
||||
@@ -613,7 +621,8 @@ private func parseStickerSetInfoAndItems(apiStickerSet: Api.messages.StickerSet)
|
||||
var indexKeysByFile: [MediaId: [MemoryBuffer]] = [:]
|
||||
for pack in packs {
|
||||
switch pack {
|
||||
case let .stickerPack(text, fileIds):
|
||||
case let .stickerPack(stickerPackData):
|
||||
let (text, fileIds) = (stickerPackData.emoticon, stickerPackData.documents)
|
||||
let key = ValueBoxKey(text).toMemoryBuffer()
|
||||
for fileId in fileIds {
|
||||
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: fileId)
|
||||
@@ -627,7 +636,8 @@ private func parseStickerSetInfoAndItems(apiStickerSet: Api.messages.StickerSet)
|
||||
}
|
||||
for keyword in keywords {
|
||||
switch keyword {
|
||||
case let .stickerKeyword(documentId, texts):
|
||||
case let .stickerKeyword(stickerKeywordData):
|
||||
let (documentId, texts) = (stickerKeywordData.documentId, stickerKeywordData.keyword)
|
||||
for text in texts {
|
||||
let key = ValueBoxKey(text).toMemoryBuffer()
|
||||
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: documentId)
|
||||
@@ -667,8 +677,8 @@ func _internal_getStickerSetShortNameSuggestion(account: Account, title: String)
|
||||
return nil
|
||||
}
|
||||
switch result {
|
||||
case let .suggestedShortName(shortName):
|
||||
return shortName
|
||||
case let .suggestedShortName(suggestedShortNameData):
|
||||
return suggestedShortNameData.shortName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ extension StickerPackReference {
|
||||
var apiInputStickerSet: Api.InputStickerSet {
|
||||
switch self {
|
||||
case let .id(id, accessHash):
|
||||
return .inputStickerSetID(id: id, accessHash: accessHash)
|
||||
return .inputStickerSetID(.init(id: id, accessHash: accessHash))
|
||||
case let .name(name):
|
||||
return .inputStickerSetShortName(shortName: name)
|
||||
return .inputStickerSetShortName(.init(shortName: name))
|
||||
case .animatedEmoji:
|
||||
return .inputStickerSetAnimatedEmoji
|
||||
case let .dice(emoji):
|
||||
return .inputStickerSetDice(emoticon: emoji)
|
||||
return .inputStickerSetDice(.init(emoticon: emoji))
|
||||
case .animatedEmojiAnimations:
|
||||
return .inputStickerSetAnimatedEmojiAnimations
|
||||
case .premiumGifts:
|
||||
@@ -58,10 +58,12 @@ func updatedRemoteStickerPack(postbox: Postbox, network: Network, reference: Sti
|
||||
switch result {
|
||||
case .stickerSetNotModified:
|
||||
return .complete()
|
||||
case let .stickerSet(set, packs, keywords, documents):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let (set, packs, keywords, documents) = (stickerSetData.set, stickerSetData.packs, stickerSetData.keywords, stickerSetData.documents)
|
||||
let namespace: ItemCollectionId.Namespace
|
||||
switch set {
|
||||
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _, _, _):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let flags = stickerSetData.flags
|
||||
if (flags & (1 << 3)) != 0 {
|
||||
namespace = Namespaces.ItemCollection.CloudMaskPacks
|
||||
} else if (flags & (1 << 7)) != 0 {
|
||||
@@ -74,7 +76,8 @@ func updatedRemoteStickerPack(postbox: Postbox, network: Network, reference: Sti
|
||||
var indexKeysByFile: [MediaId: [MemoryBuffer]] = [:]
|
||||
for pack in packs {
|
||||
switch pack {
|
||||
case let .stickerPack(text, fileIds):
|
||||
case let .stickerPack(stickerPackData):
|
||||
let (text, fileIds) = (stickerPackData.emoticon, stickerPackData.documents)
|
||||
let key = ValueBoxKey(text).toMemoryBuffer()
|
||||
for fileId in fileIds {
|
||||
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: fileId)
|
||||
@@ -88,7 +91,8 @@ func updatedRemoteStickerPack(postbox: Postbox, network: Network, reference: Sti
|
||||
}
|
||||
for keyword in keywords {
|
||||
switch keyword {
|
||||
case let .stickerKeyword(documentId, texts):
|
||||
case let .stickerKeyword(stickerKeywordData):
|
||||
let (documentId, texts) = (stickerKeywordData.documentId, stickerKeywordData.keyword)
|
||||
for text in texts {
|
||||
let key = ValueBoxKey(text).toMemoryBuffer()
|
||||
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: documentId)
|
||||
|
||||
@@ -300,18 +300,19 @@ func _internal_searchStickers(account: Account, query: String?, emoticon: [Strin
|
||||
let flags: Int32 = 0
|
||||
remote = account.network.request(Api.functions.messages.searchStickers(flags: flags, q: query, emoticon: emoticon.joined(separator: ""), langCode: [inputLanguageCode], offset: 0, limit: 128, hash: cached?.hash ?? 0))
|
||||
|> `catch` { _ -> Signal<Api.messages.FoundStickers, NoError> in
|
||||
return .single(.foundStickersNotModified(flags: 0, nextOffset: nil))
|
||||
return .single(.foundStickersNotModified(.init(flags: 0, nextOffset: nil)))
|
||||
}
|
||||
|> mapToSignal { result -> Signal<(items: [FoundStickerItem], isFinalResult: Bool), NoError> in
|
||||
return account.postbox.transaction { transaction -> (items: [FoundStickerItem], isFinalResult: Bool) in
|
||||
switch result {
|
||||
case let .foundStickers(_, _, hash, stickers):
|
||||
case let .foundStickers(foundStickersData):
|
||||
let (_, _, hash, stickers) = (foundStickersData.flags, foundStickersData.nextOffset, foundStickersData.hash, foundStickersData.stickers)
|
||||
var result: [FoundStickerItem] = []
|
||||
let currentItemIds = Set<MediaId>(localItems.map { $0.file.fileId })
|
||||
|
||||
|
||||
var premiumItems: [FoundStickerItem] = []
|
||||
var otherItems: [FoundStickerItem] = []
|
||||
|
||||
|
||||
for item in localItems {
|
||||
if item.file.isPremiumSticker {
|
||||
premiumItems.append(item)
|
||||
@@ -319,11 +320,11 @@ func _internal_searchStickers(account: Account, query: String?, emoticon: [Strin
|
||||
otherItems.append(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var foundItems: [FoundStickerItem] = []
|
||||
var foundAnimatedItems: [FoundStickerItem] = []
|
||||
var foundPremiumItems: [FoundStickerItem] = []
|
||||
|
||||
|
||||
var files: [TelegramMediaFile] = []
|
||||
for sticker in stickers {
|
||||
if let file = telegramMediaFileFromApiDocument(sticker, altDocuments: []), let id = file.id {
|
||||
@@ -339,10 +340,10 @@ func _internal_searchStickers(account: Account, query: String?, emoticon: [Strin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let allPremiumItems = premiumItems + foundPremiumItems
|
||||
let allOtherItems = otherItems + foundAnimatedItems + foundItems
|
||||
|
||||
|
||||
if isPremium {
|
||||
let batchCount = Int(searchStickersConfiguration.normalStickersPerPremiumCount)
|
||||
if batchCount == 0 {
|
||||
@@ -373,12 +374,12 @@ func _internal_searchStickers(account: Account, query: String?, emoticon: [Strin
|
||||
result.append(contentsOf: allOtherItems)
|
||||
result.append(contentsOf: allPremiumItems.prefix(max(0, Int(searchStickersConfiguration.premiumStickersCount))))
|
||||
}
|
||||
|
||||
|
||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||
if hash != 0, let entry = CodableEntry(CachedStickerQueryResult(items: files, hash: hash, timestamp: currentTime)) {
|
||||
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerQueryResults, key: CachedStickerQueryResult.cacheKey(cacheKey)), entry: entry)
|
||||
}
|
||||
|
||||
|
||||
return (result, true)
|
||||
case .foundStickersNotModified:
|
||||
break
|
||||
@@ -394,7 +395,8 @@ func _internal_searchStickers(account: Account, query: String?, emoticon: [Strin
|
||||
|> mapToSignal { result -> Signal<(items: [FoundStickerItem], isFinalResult: Bool), NoError> in
|
||||
return account.postbox.transaction { transaction -> (items: [FoundStickerItem], isFinalResult: Bool) in
|
||||
switch result {
|
||||
case let .stickers(hash, stickers):
|
||||
case let .stickers(stickersData):
|
||||
let (hash, stickers) = (stickersData.hash, stickersData.stickers)
|
||||
var result: [FoundStickerItem] = []
|
||||
let currentItemIds = Set<MediaId>(localItems.map { $0.file.fileId })
|
||||
|
||||
@@ -784,13 +786,14 @@ func _internal_searchStickers(account: Account, category: EmojiSearchCategories.
|
||||
|> mapToSignal { result -> Signal<(items: [FoundStickerItem], isFinalResult: Bool), NoError> in
|
||||
return account.postbox.transaction { transaction -> (items: [FoundStickerItem], isFinalResult: Bool) in
|
||||
switch result {
|
||||
case let .stickers(hash, stickers):
|
||||
case let .stickers(stickersData):
|
||||
let (hash, stickers) = (stickersData.hash, stickersData.stickers)
|
||||
var result: [FoundStickerItem] = []
|
||||
let currentItemIds = Set<MediaId>(localItems.map { $0.file.fileId })
|
||||
|
||||
|
||||
var premiumItems: [FoundStickerItem] = []
|
||||
var otherItems: [FoundStickerItem] = []
|
||||
|
||||
|
||||
for item in localItems {
|
||||
if item.file.isPremiumSticker {
|
||||
premiumItems.append(item)
|
||||
@@ -798,11 +801,11 @@ func _internal_searchStickers(account: Account, category: EmojiSearchCategories.
|
||||
otherItems.append(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var foundItems: [FoundStickerItem] = []
|
||||
var foundAnimatedItems: [FoundStickerItem] = []
|
||||
var foundPremiumItems: [FoundStickerItem] = []
|
||||
|
||||
|
||||
var files: [TelegramMediaFile] = []
|
||||
for sticker in stickers {
|
||||
if let file = telegramMediaFileFromApiDocument(sticker, altDocuments: []), let id = file.id {
|
||||
@@ -818,10 +821,10 @@ func _internal_searchStickers(account: Account, category: EmojiSearchCategories.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let allPremiumItems = premiumItems + foundPremiumItems
|
||||
let allOtherItems = otherItems + foundAnimatedItems + foundItems
|
||||
|
||||
|
||||
if isPremium {
|
||||
let batchCount = Int(searchStickersConfiguration.normalStickersPerPremiumCount)
|
||||
if batchCount == 0 {
|
||||
@@ -852,12 +855,12 @@ func _internal_searchStickers(account: Account, category: EmojiSearchCategories.
|
||||
result.append(contentsOf: allOtherItems)
|
||||
result.append(contentsOf: allPremiumItems.prefix(max(0, Int(searchStickersConfiguration.premiumStickersCount))))
|
||||
}
|
||||
|
||||
|
||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||
if let entry = CodableEntry(CachedStickerQueryResult(items: files, hash: hash, timestamp: currentTime)) {
|
||||
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerQueryResults, key: CachedStickerQueryResult.cacheKey(query.joined(separator: ""))), entry: entry)
|
||||
}
|
||||
|
||||
|
||||
return (result, true)
|
||||
case .stickersNotModified:
|
||||
break
|
||||
@@ -953,12 +956,13 @@ func _internal_searchEmoji(account: Account, query: String?, emoticon: [String],
|
||||
let flags: Int32 = 1 << 0
|
||||
remote = account.network.request(Api.functions.messages.searchStickers(flags: flags, q: query, emoticon: emoticon.joined(separator: ""), langCode: [inputLanguageCode], offset: 0, limit: 128, hash: cached?.hash ?? 0))
|
||||
|> `catch` { _ -> Signal<Api.messages.FoundStickers, NoError> in
|
||||
return .single(.foundStickersNotModified(flags: 0, nextOffset: nil))
|
||||
return .single(.foundStickersNotModified(.init(flags: 0, nextOffset: nil)))
|
||||
}
|
||||
|> mapToSignal { result -> Signal<(items: [FoundStickerItem], isFinalResult: Bool), NoError> in
|
||||
return account.postbox.transaction { transaction -> (items: [FoundStickerItem], isFinalResult: Bool) in
|
||||
switch result {
|
||||
case let .foundStickers(_, _, hash, stickers):
|
||||
case let .foundStickers(foundStickersData):
|
||||
let (_, _, hash, stickers) = (foundStickersData.flags, foundStickersData.nextOffset, foundStickersData.hash, foundStickersData.stickers)
|
||||
var result: [FoundStickerItem] = localItems
|
||||
var currentItemIds = Set<MediaId>(localItems.map { $0.file.fileId })
|
||||
|
||||
@@ -973,12 +977,12 @@ func _internal_searchEmoji(account: Account, query: String?, emoticon: [String],
|
||||
result.append(FoundStickerItem(file: file, stringRepresentations: []))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||
if let entry = CodableEntry(CachedStickerQueryResult(items: files, hash: hash, timestamp: currentTime)) {
|
||||
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedEmojiQueryResults, key: CachedStickerQueryResult.cacheKey(cacheKey)), entry: entry)
|
||||
}
|
||||
|
||||
|
||||
return (result, true)
|
||||
case .foundStickersNotModified:
|
||||
break
|
||||
@@ -995,7 +999,8 @@ func _internal_searchEmoji(account: Account, query: String?, emoticon: [String],
|
||||
switch result {
|
||||
case .emojiListNotModified:
|
||||
return .single(nil)
|
||||
case let .emojiList(hash, documentIds):
|
||||
case let .emojiList(emojiListData):
|
||||
let (hash, documentIds) = (emojiListData.hash, emojiListData.documentId)
|
||||
return TelegramEngine(account: account).stickers.resolveInlineStickers(fileIds: documentIds)
|
||||
|> map { fileMap -> (files: [TelegramMediaFile], hash: Int64)? in
|
||||
var files: [TelegramMediaFile] = []
|
||||
@@ -1068,7 +1073,8 @@ func _internal_searchStickerSetsRemotely(network: Network, query: String) -> Sig
|
||||
|> mapToSignal { value in
|
||||
var index: Int32 = 1000
|
||||
switch value {
|
||||
case let .foundStickerSets(_, sets: sets):
|
||||
case let .foundStickerSets(foundStickerSetsData):
|
||||
let (_, sets) = (foundStickerSetsData.hash, foundStickerSetsData.sets)
|
||||
var result = FoundStickerSets()
|
||||
for set in sets {
|
||||
let parsed = parsePreviewStickerSet(set, namespace: Namespaces.ItemCollection.CloudStickerPacks)
|
||||
@@ -1080,7 +1086,7 @@ func _internal_searchStickerSetsRemotely(network: Network, query: String) -> Sig
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
return .complete()
|
||||
}
|
||||
|> `catch` { _ -> Signal<FoundStickerSets, NoError> in
|
||||
@@ -1094,7 +1100,8 @@ func _internal_searchEmojiSetsRemotely(postbox: Postbox, network: Network, query
|
||||
|> mapToSignal { value in
|
||||
var index: Int32 = 1000
|
||||
switch value {
|
||||
case let .foundStickerSets(_, sets: sets):
|
||||
case let .foundStickerSets(foundStickerSetsData):
|
||||
let (_, sets) = (foundStickerSetsData.hash, foundStickerSetsData.sets)
|
||||
var result = FoundStickerSets()
|
||||
for set in sets {
|
||||
let parsed = parsePreviewStickerSet(set, namespace: Namespaces.ItemCollection.CloudEmojiPacks)
|
||||
@@ -1106,7 +1113,7 @@ func _internal_searchEmojiSetsRemotely(postbox: Postbox, network: Network, query
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
return .complete()
|
||||
}
|
||||
|> `catch` { _ -> Signal<FoundStickerSets, NoError> in
|
||||
|
||||
@@ -21,16 +21,20 @@ func telegramStickerPackThumbnailRepresentationFromApiSizes(datacenterId: Int32,
|
||||
var representations: [TelegramMediaImageRepresentation] = []
|
||||
for size in sizes {
|
||||
switch size {
|
||||
case let .photoCachedSize(type, w, h, _):
|
||||
case let .photoCachedSize(photoCachedSizeData):
|
||||
let (type, w, h) = (photoCachedSizeData.type, photoCachedSizeData.w, photoCachedSizeData.h)
|
||||
let resource = CloudStickerPackThumbnailMediaResource(datacenterId: datacenterId, thumbVersion: thumbVersion, volumeId: nil, localId: nil)
|
||||
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, typeHint: stickerTypeHint(for: type)))
|
||||
case let .photoSize(type, w, h, _):
|
||||
case let .photoSize(photoSizeData):
|
||||
let (type, w, h) = (photoSizeData.type, photoSizeData.w, photoSizeData.h)
|
||||
let resource = CloudStickerPackThumbnailMediaResource(datacenterId: datacenterId, thumbVersion: thumbVersion, volumeId: nil, localId: nil)
|
||||
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: [], immediateThumbnailData: nil, typeHint: stickerTypeHint(for: type)))
|
||||
case let .photoSizeProgressive(type, w, h, sizes):
|
||||
case let .photoSizeProgressive(photoSizeProgressiveData):
|
||||
let (type, w, h, sizes) = (photoSizeProgressiveData.type, photoSizeProgressiveData.w, photoSizeProgressiveData.h, photoSizeProgressiveData.sizes)
|
||||
let resource = CloudStickerPackThumbnailMediaResource(datacenterId: datacenterId, thumbVersion: thumbVersion, volumeId: nil, localId: nil)
|
||||
representations.append(TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: w, height: h), resource: resource, progressiveSizes: sizes, immediateThumbnailData: nil, typeHint: stickerTypeHint(for: type)))
|
||||
case let .photoPathSize(_, data):
|
||||
case let .photoPathSize(photoPathSizeData):
|
||||
let data = photoPathSizeData.bytes
|
||||
immediateThumbnailData = data.makeData()
|
||||
case .photoStrippedSize:
|
||||
break
|
||||
@@ -44,7 +48,8 @@ func telegramStickerPackThumbnailRepresentationFromApiSizes(datacenterId: Int32,
|
||||
extension StickerPackCollectionInfo {
|
||||
convenience init(apiSet: Api.StickerSet, namespace: ItemCollectionId.Namespace) {
|
||||
switch apiSet {
|
||||
case let .stickerSet(flags, _, id, accessHash, title, shortName, thumbs, thumbDcId, thumbVersion, thumbDocumentId, count, nHash):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let (flags, _, id, accessHash, title, shortName, thumbs, thumbDcId, thumbVersion, thumbDocumentId, count, nHash) = (stickerSetData.flags, stickerSetData.installedDate, stickerSetData.id, stickerSetData.accessHash, stickerSetData.title, stickerSetData.shortName, stickerSetData.thumbs, stickerSetData.thumbDcId, stickerSetData.thumbVersion, stickerSetData.thumbDocumentId, stickerSetData.count, stickerSetData.hash)
|
||||
var setFlags: StickerPackCollectionInfoFlags = StickerPackCollectionInfoFlags()
|
||||
if (flags & (1 << 2)) != 0 {
|
||||
setFlags.insert(.isOfficial)
|
||||
@@ -82,10 +87,10 @@ func _internal_stickerPacksAttachedToMedia(account: Account, media: AnyMediaRefe
|
||||
let inputMedia: Api.InputStickeredMedia
|
||||
let resourceReference: MediaResourceReference
|
||||
if let imageReference = media.concrete(TelegramMediaImage.self), let reference = imageReference.media.reference, case let .cloud(imageId, accessHash, fileReference) = reference, let representation = largestImageRepresentation(imageReference.media.representations) {
|
||||
inputMedia = .inputStickeredMediaPhoto(id: Api.InputPhoto.inputPhoto(id: imageId, accessHash: accessHash, fileReference: Buffer(data: fileReference ?? Data())))
|
||||
inputMedia = .inputStickeredMediaPhoto(.init(id: Api.InputPhoto.inputPhoto(.init(id: imageId, accessHash: accessHash, fileReference: Buffer(data: fileReference ?? Data())))))
|
||||
resourceReference = imageReference.resourceReference(representation.resource)
|
||||
} else if let fileReference = media.concrete(TelegramMediaFile.self), let resource = fileReference.media.resource as? CloudDocumentMediaResource {
|
||||
inputMedia = .inputStickeredMediaDocument(id: Api.InputDocument.inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data())))
|
||||
inputMedia = .inputStickeredMediaDocument(.init(id: Api.InputDocument.inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: resource.fileReference ?? Data())))))
|
||||
resourceReference = fileReference.resourceReference(fileReference.media.resource)
|
||||
} else {
|
||||
return .single([])
|
||||
@@ -101,9 +106,9 @@ func _internal_stickerPacksAttachedToMedia(account: Account, media: AnyMediaRefe
|
||||
let inputMedia: Api.InputStickeredMedia
|
||||
if let resource = reference.updatedResource as? TelegramCloudMediaResourceWithFileReference, let updatedReference = resource.fileReference {
|
||||
if let imageReference = media.concrete(TelegramMediaImage.self), let reference = imageReference.media.reference, case let .cloud(imageId, accessHash, _) = reference, let _ = largestImageRepresentation(imageReference.media.representations) {
|
||||
inputMedia = .inputStickeredMediaPhoto(id: Api.InputPhoto.inputPhoto(id: imageId, accessHash: accessHash, fileReference: Buffer(data: updatedReference)))
|
||||
inputMedia = .inputStickeredMediaPhoto(.init(id: Api.InputPhoto.inputPhoto(.init(id: imageId, accessHash: accessHash, fileReference: Buffer(data: updatedReference)))))
|
||||
} else if let fileReference = media.concrete(TelegramMediaFile.self), let resource = fileReference.media.resource as? CloudDocumentMediaResource {
|
||||
inputMedia = .inputStickeredMediaDocument(id: Api.InputDocument.inputDocument(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: updatedReference)))
|
||||
inputMedia = .inputStickeredMediaDocument(.init(id: Api.InputDocument.inputDocument(.init(id: resource.fileId, accessHash: resource.accessHash, fileReference: Buffer(data: updatedReference)))))
|
||||
} else {
|
||||
return .single([])
|
||||
}
|
||||
@@ -118,11 +123,19 @@ func _internal_stickerPacksAttachedToMedia(account: Account, media: AnyMediaRefe
|
||||
}
|
||||
|> map { result -> [StickerPackReference] in
|
||||
return result.map { pack in
|
||||
let set: Api.StickerSet
|
||||
switch pack {
|
||||
case let .stickerSetCovered(set, _), let .stickerSetMultiCovered(set, _), let .stickerSetFullCovered(set, _, _, _), let .stickerSetNoCovered(set):
|
||||
let info = StickerPackCollectionInfo(apiSet: set, namespace: Namespaces.ItemCollection.CloudStickerPacks)
|
||||
return .id(id: info.id.id, accessHash: info.accessHash)
|
||||
case let .stickerSetCovered(stickerSetCoveredData):
|
||||
set = stickerSetCoveredData.set
|
||||
case let .stickerSetMultiCovered(stickerSetMultiCoveredData):
|
||||
set = stickerSetMultiCoveredData.set
|
||||
case let .stickerSetFullCovered(stickerSetFullCoveredData):
|
||||
set = stickerSetFullCoveredData.set
|
||||
case let .stickerSetNoCovered(stickerSetNoCoveredData):
|
||||
set = stickerSetNoCoveredData.set
|
||||
}
|
||||
let info = StickerPackCollectionInfo(apiSet: set, namespace: Namespaces.ItemCollection.CloudStickerPacks)
|
||||
return .id(id: info.id.id, accessHash: info.accessHash)
|
||||
}
|
||||
}
|
||||
|> `catch` { _ -> Signal<[StickerPackReference], NoError> in
|
||||
|
||||
+23
-14
@@ -30,16 +30,16 @@ func _internal_requestStickerSet(postbox: Postbox, network: Network, reference:
|
||||
switch reference {
|
||||
case let .name(name):
|
||||
collectionId = nil
|
||||
input = .inputStickerSetShortName(shortName: name)
|
||||
input = .inputStickerSetShortName(.init(shortName: name))
|
||||
case let .id(id, accessHash):
|
||||
collectionId = ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id)
|
||||
input = .inputStickerSetID(id: id, accessHash: accessHash)
|
||||
input = .inputStickerSetID(.init(id: id, accessHash: accessHash))
|
||||
case .animatedEmoji:
|
||||
collectionId = nil
|
||||
input = .inputStickerSetAnimatedEmoji
|
||||
case let .dice(emoji):
|
||||
collectionId = nil
|
||||
input = .inputStickerSetDice(emoticon: emoji)
|
||||
input = .inputStickerSetDice(.init(emoticon: emoji))
|
||||
case .animatedEmojiAnimations:
|
||||
collectionId = nil
|
||||
input = .inputStickerSetAnimatedEmojiAnimations
|
||||
@@ -80,18 +80,21 @@ func _internal_requestStickerSet(postbox: Postbox, network: Network, reference:
|
||||
switch result {
|
||||
case .stickerSetNotModified:
|
||||
return .complete()
|
||||
case let .stickerSet(set, packs, keywords, documents):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let (set, packs, keywords, documents) = (stickerSetData.set, stickerSetData.packs, stickerSetData.keywords, stickerSetData.documents)
|
||||
info = StickerPackCollectionInfo(apiSet: set, namespace: Namespaces.ItemCollection.CloudStickerPacks)
|
||||
|
||||
switch set {
|
||||
case let .stickerSet(flags, _, _, _, _, _, _, _, _, _, _, _):
|
||||
case let .stickerSet(stickerSetData):
|
||||
let flags = stickerSetData.flags
|
||||
installed = (flags & (1 << 0) != 0)
|
||||
}
|
||||
|
||||
var indexKeysByFile: [MediaId: [MemoryBuffer]] = [:]
|
||||
for pack in packs {
|
||||
switch pack {
|
||||
case let .stickerPack(text, fileIds):
|
||||
case let .stickerPack(stickerPackData):
|
||||
let (text, fileIds) = (stickerPackData.emoticon, stickerPackData.documents)
|
||||
let key = ValueBoxKey(text).toMemoryBuffer()
|
||||
for fileId in fileIds {
|
||||
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: fileId)
|
||||
@@ -106,7 +109,8 @@ func _internal_requestStickerSet(postbox: Postbox, network: Network, reference:
|
||||
}
|
||||
for keyword in keywords {
|
||||
switch keyword {
|
||||
case let .stickerKeyword(documentId, texts):
|
||||
case let .stickerKeyword(stickerKeywordData):
|
||||
let (documentId, texts) = (stickerKeywordData.documentId, stickerKeywordData.keyword)
|
||||
for text in texts {
|
||||
let key = ValueBoxKey(text).toMemoryBuffer()
|
||||
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: documentId)
|
||||
@@ -170,7 +174,7 @@ public final class CoveredStickerSet : Equatable {
|
||||
}
|
||||
|
||||
func _internal_installStickerSetInteractively(account: Account, info: StickerPackCollectionInfo, items: [ItemCollectionItem]) -> Signal<InstallStickerSetResult, InstallStickerSetError> {
|
||||
return account.network.request(Api.functions.messages.installStickerSet(stickerset: .inputStickerSetID(id: info.id.id, accessHash: info.accessHash), archived: .boolFalse)) |> mapError { _ -> InstallStickerSetError in
|
||||
return account.network.request(Api.functions.messages.installStickerSet(stickerset: .inputStickerSetID(.init(id: info.id.id, accessHash: info.accessHash)), archived: .boolFalse)) |> mapError { _ -> InstallStickerSetError in
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { result -> Signal<InstallStickerSetResult, InstallStickerSetError> in
|
||||
@@ -178,22 +182,27 @@ func _internal_installStickerSetInteractively(account: Account, info: StickerPac
|
||||
switch result {
|
||||
case .stickerSetInstallResultSuccess:
|
||||
addResult = .successful
|
||||
case let .stickerSetInstallResultArchive(sets: archived):
|
||||
case let .stickerSetInstallResultArchive(stickerSetInstallResultArchiveData):
|
||||
let archived = stickerSetInstallResultArchiveData.sets
|
||||
var coveredSets: [CoveredStickerSet] = []
|
||||
for archived in archived {
|
||||
let apiDocuments:[Api.Document]
|
||||
let apiSet:Api.StickerSet
|
||||
switch archived {
|
||||
case let .stickerSetCovered(set: set, cover: cover):
|
||||
case let .stickerSetCovered(stickerSetCoveredData):
|
||||
let (set, cover) = (stickerSetCoveredData.set, stickerSetCoveredData.cover)
|
||||
apiSet = set
|
||||
apiDocuments = [cover]
|
||||
case let .stickerSetMultiCovered(set: set, covers: covers):
|
||||
case let .stickerSetMultiCovered(stickerSetMultiCoveredData):
|
||||
let (set, covers) = (stickerSetMultiCoveredData.set, stickerSetMultiCoveredData.covers)
|
||||
apiSet = set
|
||||
apiDocuments = covers
|
||||
case let .stickerSetFullCovered(set, _, _, documents):
|
||||
case let .stickerSetFullCovered(stickerSetFullCoveredData):
|
||||
let (set, documents) = (stickerSetFullCoveredData.set, stickerSetFullCoveredData.documents)
|
||||
apiSet = set
|
||||
apiDocuments = documents
|
||||
case let .stickerSetNoCovered(set):
|
||||
case let .stickerSetNoCovered(stickerSetNoCoveredData):
|
||||
let set = stickerSetNoCoveredData.set
|
||||
apiSet = set
|
||||
apiDocuments = []
|
||||
}
|
||||
@@ -243,7 +252,7 @@ func _internal_installStickerSetInteractively(account: Account, info: StickerPac
|
||||
|
||||
|
||||
func _internal_uninstallStickerSetInteractively(account: Account, info: StickerPackCollectionInfo) -> Signal<Void, NoError> {
|
||||
return account.network.request(Api.functions.messages.uninstallStickerSet(stickerset: .inputStickerSetID(id: info.id.id, accessHash: info.accessHash)))
|
||||
return account.network.request(Api.functions.messages.uninstallStickerSet(stickerset: .inputStickerSetID(.init(id: info.id.id, accessHash: info.accessHash))))
|
||||
|> `catch` { _ -> Signal<Api.Bool, NoError> in
|
||||
return .single(.boolFalse)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user