mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-01 12:17:53 +00:00
Merge commit '8f60d4e90d899ea56d1293e0cd90f8feeadad6a3'
This commit is contained in:
commit
224cce972c
@ -206,6 +206,7 @@ private var declaredEncodables: Void = {
|
||||
declareEncodable(TelegramMediaGiveawayResults.self, f: { TelegramMediaGiveawayResults(decoder: $0) })
|
||||
declareEncodable(WebpagePreviewMessageAttribute.self, f: { WebpagePreviewMessageAttribute(decoder: $0) })
|
||||
declareEncodable(DerivedDataMessageAttribute.self, f: { DerivedDataMessageAttribute(decoder: $0) })
|
||||
declareEncodable(TelegramApplicationIcons.self, f: { TelegramApplicationIcons(decoder: $0) })
|
||||
return
|
||||
}()
|
||||
|
||||
|
||||
@ -177,4 +177,75 @@ public func downloadAppUpdate(account: Account, source: String, messageId: Int32
|
||||
}
|
||||
}
|
||||
|
||||
public func requestApplicationIcons(engine: TelegramEngine, source: String = "macos_app_icons") -> Signal<Void, NoError> {
|
||||
return engine.peers.resolvePeerByName(name: source)
|
||||
|> mapToSignal { result -> Signal<Peer?, NoError> in
|
||||
switch result {
|
||||
case .progress:
|
||||
return .never()
|
||||
case let .result(peer):
|
||||
return .single(peer?._asPeer())
|
||||
}
|
||||
} |> mapToSignal { peer -> Signal<Void, NoError> in
|
||||
if let peer = peer, let inputPeer = apiInputPeer(peer) {
|
||||
return engine.account.network.request(Api.functions.messages.getHistory(peer: inputPeer, offsetId: 0, offsetDate: 0, addOffset: 0, limit: 100, maxId: Int32.max, minId: 0, hash: 0))
|
||||
|> retryRequest
|
||||
|> mapToSignal { result in
|
||||
|
||||
switch result {
|
||||
case let .channelMessages(_, _, _, _, apiMessages, _, apiChats, apiUsers):
|
||||
var icons: [TelegramApplicationIcons.Icon] = []
|
||||
for apiMessage in apiMessages.reversed() {
|
||||
if let storeMessage = StoreMessage(apiMessage: apiMessage, accountPeerId: engine.account.peerId, peerIsForum: peer.isForum) {
|
||||
var peers: [PeerId: Peer] = [:]
|
||||
for chat in apiChats {
|
||||
if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) {
|
||||
peers[groupOrChannel.id] = groupOrChannel
|
||||
}
|
||||
}
|
||||
for user in apiUsers {
|
||||
let telegramUser = TelegramUser(user: user)
|
||||
peers[telegramUser.id] = telegramUser
|
||||
}
|
||||
|
||||
if let message = locallyRenderedMessage(message: storeMessage, peers: peers), let media = message.media.first as? TelegramMediaFile {
|
||||
icons.append(.init(file: media, reference: MessageReference(message)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _internal_updateApplicationIcons(postbox: engine.account.postbox, icons: .init(icons: icons))
|
||||
default:
|
||||
break
|
||||
}
|
||||
return .complete()
|
||||
}
|
||||
} else {
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
return Signal { subscriber in
|
||||
let fetchDispsable = fetchedMediaResource(mediaBox: engine.account.postbox.mediaBox, userLocation: .other, userContentType: .other, reference: MediaResourceReference.media(media: AnyMediaReference.message(message: MessageReference(message), media: media), resource: media.resource)).start()
|
||||
|
||||
let dataDisposable = engine.account.postbox.mediaBox.resourceData(media.resource, option: .complete(waitUntilFetchStatus: true)).start(next: { data in
|
||||
if data.complete {
|
||||
if let data = try? Data(contentsOf: URL.init(fileURLWithPath: data.path)) {
|
||||
subscriber.putNext(data)
|
||||
subscriber.putCompletion()
|
||||
} else {
|
||||
subscriber.putError(.xmlLoad)
|
||||
}
|
||||
}
|
||||
})
|
||||
return ActionDisposable {
|
||||
fetchDispsable.dispose()
|
||||
dataDisposable.dispose()
|
||||
}
|
||||
}
|
||||
*/
|
||||
@ -0,0 +1,71 @@
|
||||
//
|
||||
// File.swift
|
||||
//
|
||||
//
|
||||
// Created by Mikhail Filimonov on 25.01.2024.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
|
||||
public struct TelegramApplicationIcons : PostboxCoding, Equatable {
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.icons = (try? decoder.decodeObjectArrayWithCustomDecoderForKey("i", decoder: { Icon(decoder: $0) })) ?? []
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObjectArray(self.icons, forKey: "i")
|
||||
}
|
||||
|
||||
public struct Icon : PostboxCoding, Equatable {
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.file = decoder.decodeObjectForKey("f") as! TelegramMediaFile
|
||||
self.reference = decoder.decodeObjectForKey("r", decoder: { MessageReference(decoder: $0) }) as! MessageReference
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObject(self.file, forKey: "f")
|
||||
encoder.encodeObject(self.reference, forKey: "r")
|
||||
}
|
||||
|
||||
public let file: TelegramMediaFile
|
||||
public let reference: MessageReference
|
||||
init(file: TelegramMediaFile, reference: MessageReference) {
|
||||
self.file = file
|
||||
self.reference = reference
|
||||
}
|
||||
}
|
||||
public var icons: [Icon]
|
||||
|
||||
init(icons: [Icon]) {
|
||||
self.icons = icons
|
||||
}
|
||||
|
||||
static var entryId: ItemCacheEntryId {
|
||||
let cacheKey = ValueBoxKey(length: 1)
|
||||
cacheKey.setInt8(0, value: 0)
|
||||
return ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.applicationIcons, key: cacheKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func _internal_applicationIcons(account: Account) -> Signal<TelegramApplicationIcons, NoError> {
|
||||
let key = PostboxViewKey.cachedItem(TelegramApplicationIcons.entryId)
|
||||
return account.postbox.combinedView(keys: [key])
|
||||
|> mapToSignal { views -> Signal<TelegramApplicationIcons, NoError> in
|
||||
guard let icons = (views.views[key] as? CachedItemView)?.value?.getLegacy(TelegramApplicationIcons.self) as? TelegramApplicationIcons else {
|
||||
return .single(.init(icons: []))
|
||||
}
|
||||
return .single(icons)
|
||||
}
|
||||
}
|
||||
|
||||
func _internal_updateApplicationIcons(postbox: Postbox, icons: TelegramApplicationIcons) -> Signal<Void, NoError> {
|
||||
return postbox.transaction { transaction -> Void in
|
||||
let entry = CodableEntry(legacyValue: icons)
|
||||
transaction.putItemCacheEntry(id: TelegramApplicationIcons.entryId, entry: entry)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -120,6 +120,7 @@ public struct Namespaces {
|
||||
public static let recommendedChannels: Int8 = 33
|
||||
public static let peerColorOptions: Int8 = 34
|
||||
public static let savedMessageTags: Int8 = 35
|
||||
public static let applicationIcons: Int8 = 36
|
||||
}
|
||||
|
||||
public struct UnorderedItemList {
|
||||
|
||||
@ -412,5 +412,9 @@ public extension TelegramEngine {
|
||||
public func pushPriorityDownload(resourceId: String, priority: Int = 1) -> Disposable {
|
||||
return self.account.network.multiplexedRequestManager.pushPriority(resourceId: resourceId, priority: priority)
|
||||
}
|
||||
|
||||
public func applicationIcons() -> Signal<TelegramApplicationIcons, NoError> {
|
||||
return _internal_applicationIcons(account: account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user