Refactoring [skip ci]

This commit is contained in:
Ali 2023-04-20 19:22:25 +04:00
parent 95947fdb99
commit 1640a8c76f
17 changed files with 121 additions and 80 deletions

View File

@ -1,6 +1,5 @@
import Foundation
import UIKit
import Postbox
import TelegramCore
import LegacyComponents
import SwiftSignalKit
@ -49,8 +48,8 @@ public final class LegacyLiveUploadInterface: VideoConversionWatcher, TGLiveUplo
private var path: String?
private var size: Int?
private let data = Promise<MediaResourceData>()
private let dataValue = Atomic<MediaResourceData?>(value: nil)
private let data = Promise<EngineMediaResource.ResourceData>()
private let dataValue = Atomic<EngineMediaResource.ResourceData?>(value: nil)
public init(context: AccountContext) {
self.context = context
@ -70,14 +69,13 @@ public final class LegacyLiveUploadInterface: VideoConversionWatcher, TGLiveUplo
strongSelf.size = size
let result = strongSelf.dataValue.modify { dataValue in
if let dataValue = dataValue, dataValue.complete {
return MediaResourceData(path: path, offset: 0, size: Int64(size), complete: true)
if let dataValue = dataValue, dataValue.isComplete {
return EngineMediaResource.ResourceData(path: path, availableSize: Int64(size), isComplete: true)
} else {
return MediaResourceData(path: path, offset: 0, size: Int64(size), complete: false)
return EngineMediaResource.ResourceData(path: path, availableSize: Int64(size), isComplete: false)
}
}
if let result = result {
print("**set1 \(result) \(result.complete)")
strongSelf.data.set(.single(result))
}
}
@ -89,17 +87,15 @@ public final class LegacyLiveUploadInterface: VideoConversionWatcher, TGLiveUplo
override public func fileUpdated(_ completed: Bool) -> Any! {
let _ = super.fileUpdated(completed)
print("**fileUpdated \(completed)")
if completed {
let result = self.dataValue.modify { dataValue in
if let dataValue = dataValue {
return MediaResourceData(path: dataValue.path, offset: dataValue.offset, size: dataValue.size, complete: true)
return EngineMediaResource.ResourceData(path: dataValue.path, availableSize: dataValue.availableSize, isComplete: true)
} else {
return nil
}
}
if let result = result {
print("**set2 \(result) \(completed)")
self.data.set(.single(result))
return LegacyLiveUploadInterfaceResult(id: self.id)
} else {

View File

@ -303,7 +303,7 @@ final class SecureIdAuthControllerNode: ViewControllerTracingNode {
current.updateValues(formData.values)
contentNode = current
} else {
let current = SecureIdAuthFormContentNode(theme: self.presentationData.theme, strings: self.presentationData.strings, nameDisplayOrder: self.presentationData.nameDisplayOrder, peer: encryptedFormData.servicePeer, privacyPolicyUrl: encryptedFormData.form.termsUrl, form: formData, primaryLanguageByCountry: encryptedFormData.primaryLanguageByCountry, openField: { [weak self] field in
let current = SecureIdAuthFormContentNode(theme: self.presentationData.theme, strings: self.presentationData.strings, nameDisplayOrder: self.presentationData.nameDisplayOrder, peer: EnginePeer(encryptedFormData.servicePeer), privacyPolicyUrl: encryptedFormData.form.termsUrl, form: formData, primaryLanguageByCountry: encryptedFormData.primaryLanguageByCountry, openField: { [weak self] field in
if let strongSelf = self {
switch field {
case .identity, .address:

View File

@ -2,7 +2,6 @@ import Foundation
import UIKit
import AsyncDisplayKit
import Display
import Postbox
import TelegramCore
import TelegramPresentationData
import TelegramUIPreferences
@ -24,7 +23,7 @@ final class SecureIdAuthFormContentNode: ASDisplayNode, SecureIdAuthContentNode,
private let requestLayout: () -> Void
private var validLayout: CGFloat?
init(theme: PresentationTheme, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, peer: Peer, privacyPolicyUrl: String?, form: SecureIdForm, primaryLanguageByCountry: [String: String], openField: @escaping (SecureIdParsedRequestedFormField) -> Void, openURL: @escaping (String) -> Void, openMention: @escaping (TelegramPeerMention) -> Void, requestLayout: @escaping () -> Void) {
init(theme: PresentationTheme, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, peer: EnginePeer, privacyPolicyUrl: String?, form: SecureIdForm, primaryLanguageByCountry: [String: String], openField: @escaping (SecureIdParsedRequestedFormField) -> Void, openURL: @escaping (String) -> Void, openMention: @escaping (TelegramPeerMention) -> Void, requestLayout: @escaping () -> Void) {
self.requestLayout = requestLayout
self.primaryLanguageByCountry = primaryLanguageByCountry
@ -57,13 +56,13 @@ final class SecureIdAuthFormContentNode: ASDisplayNode, SecureIdAuthContentNode,
let privacyPolicyAttributes = MarkdownAttributeSet(font: infoFont, textColor: theme.list.freeTextColor)
let privacyPolicyLinkAttributes = MarkdownAttributeSet(font: infoFont, textColor: theme.list.itemAccentColor, additionalAttributes: [NSAttributedString.Key.underlineStyle.rawValue: NSUnderlineStyle.single.rawValue as NSNumber, TelegramTextAttributes.URL: privacyPolicyUrl])
text = parseMarkdownIntoAttributedString(strings.Passport_PrivacyPolicy(EnginePeer(peer).displayTitle(strings: strings, displayOrder: nameDisplayOrder), (EnginePeer(peer).addressName ?? "")).string.replacingOccurrences(of: "]", with: "]()"), attributes: MarkdownAttributes(body: privacyPolicyAttributes, bold: privacyPolicyAttributes, link: privacyPolicyLinkAttributes, linkAttribute: { _ in
text = parseMarkdownIntoAttributedString(strings.Passport_PrivacyPolicy(peer.displayTitle(strings: strings, displayOrder: nameDisplayOrder), (peer.addressName ?? "")).string.replacingOccurrences(of: "]", with: "]()"), attributes: MarkdownAttributes(body: privacyPolicyAttributes, bold: privacyPolicyAttributes, link: privacyPolicyLinkAttributes, linkAttribute: { _ in
return nil
}), textAlignment: .center)
} else {
text = NSAttributedString(string: strings.Passport_AcceptHelp(EnginePeer(peer).displayTitle(strings: strings, displayOrder: nameDisplayOrder), (peer.addressName ?? "")).string, font: infoFont, textColor: theme.list.freeTextColor, paragraphAlignment: .left)
text = NSAttributedString(string: strings.Passport_AcceptHelp(peer.displayTitle(strings: strings, displayOrder: nameDisplayOrder), (peer.addressName ?? "")).string, font: infoFont, textColor: theme.list.freeTextColor, paragraphAlignment: .left)
}
self.textNode.attributedText = text

View File

@ -2,7 +2,6 @@ import Foundation
import UIKit
import AsyncDisplayKit
import Display
import Postbox
import TelegramCore
import SwiftSignalKit
import TelegramPresentationData

View File

@ -2,7 +2,6 @@ import Foundation
import UIKit
import Display
import SwiftSignalKit
import Postbox
import TelegramCore
import TelegramPresentationData
import TelegramUIPreferences
@ -17,12 +16,12 @@ import ItemListPeerItem
private final class ChannelBlacklistControllerArguments {
let context: AccountContext
let setPeerIdWithRevealedOptions: (PeerId?, PeerId?) -> Void
let setPeerIdWithRevealedOptions: (EnginePeer.Id?, EnginePeer.Id?) -> Void
let addPeer: () -> Void
let removePeer: (PeerId) -> Void
let removePeer: (EnginePeer.Id) -> Void
let openPeer: (RenderedChannelParticipant) -> Void
init(context: AccountContext, setPeerIdWithRevealedOptions: @escaping (PeerId?, PeerId?) -> Void, addPeer: @escaping () -> Void, removePeer: @escaping (PeerId) -> Void, openPeer: @escaping (RenderedChannelParticipant) -> Void) {
init(context: AccountContext, setPeerIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, addPeer: @escaping () -> Void, removePeer: @escaping (EnginePeer.Id) -> Void, openPeer: @escaping (RenderedChannelParticipant) -> Void) {
self.context = context
self.addPeer = addPeer
self.setPeerIdWithRevealedOptions = setPeerIdWithRevealedOptions
@ -38,7 +37,7 @@ private enum ChannelBlacklistSection: Int32 {
private enum ChannelBlacklistEntryStableId: Hashable {
case index(Int)
case peer(PeerId)
case peer(EnginePeer.Id)
}
private enum ChannelBlacklistEntry: ItemListNodeEntry {
@ -182,8 +181,8 @@ private enum ChannelBlacklistEntry: ItemListNodeEntry {
private struct ChannelBlacklistControllerState: Equatable {
let referenceTimestamp: Int32
let editing: Bool
let peerIdWithRevealedOptions: PeerId?
let removingPeerId: PeerId?
let peerIdWithRevealedOptions: EnginePeer.Id?
let removingPeerId: EnginePeer.Id?
let searchingMembers: Bool
init(referenceTimestamp: Int32) {
@ -194,7 +193,7 @@ private struct ChannelBlacklistControllerState: Equatable {
self.searchingMembers = false
}
init(referenceTimestamp: Int32, editing: Bool, peerIdWithRevealedOptions: PeerId?, removingPeerId: PeerId?, searchingMembers: Bool) {
init(referenceTimestamp: Int32, editing: Bool, peerIdWithRevealedOptions: EnginePeer.Id?, removingPeerId: EnginePeer.Id?, searchingMembers: Bool) {
self.referenceTimestamp = referenceTimestamp
self.editing = editing
self.peerIdWithRevealedOptions = peerIdWithRevealedOptions
@ -231,19 +230,19 @@ private struct ChannelBlacklistControllerState: Equatable {
}
func withUpdatedPeerIdWithRevealedOptions(_ peerIdWithRevealedOptions: PeerId?) -> ChannelBlacklistControllerState {
func withUpdatedPeerIdWithRevealedOptions(_ peerIdWithRevealedOptions: EnginePeer.Id?) -> ChannelBlacklistControllerState {
return ChannelBlacklistControllerState(referenceTimestamp: self.referenceTimestamp, editing: self.editing, peerIdWithRevealedOptions: peerIdWithRevealedOptions, removingPeerId: self.removingPeerId, searchingMembers: self.searchingMembers)
}
func withUpdatedRemovingPeerId(_ removingPeerId: PeerId?) -> ChannelBlacklistControllerState {
func withUpdatedRemovingPeerId(_ removingPeerId: EnginePeer.Id?) -> ChannelBlacklistControllerState {
return ChannelBlacklistControllerState(referenceTimestamp: self.referenceTimestamp, editing: self.editing, peerIdWithRevealedOptions: self.peerIdWithRevealedOptions, removingPeerId: removingPeerId, searchingMembers: self.searchingMembers)
}
}
private func channelBlacklistControllerEntries(presentationData: PresentationData, view: PeerView, state: ChannelBlacklistControllerState, participants: [RenderedChannelParticipant]?) -> [ChannelBlacklistEntry] {
private func channelBlacklistControllerEntries(presentationData: PresentationData, peer: EnginePeer?, state: ChannelBlacklistControllerState, participants: [RenderedChannelParticipant]?) -> [ChannelBlacklistEntry] {
var entries: [ChannelBlacklistEntry] = []
if let channel = view.peers[view.peerId] as? TelegramChannel, let participants = participants {
if case let .channel(channel) = peer, let participants = participants {
entries.append(.add(presentationData.theme, presentationData.strings.GroupRemoved_Remove))
let isGroup: Bool
@ -267,7 +266,7 @@ private func channelBlacklistControllerEntries(presentationData: PresentationDat
return entries
}
public func channelBlacklistController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, peerId: PeerId) -> ViewController {
public func channelBlacklistController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, peerId: EnginePeer.Id) -> ViewController {
let statePromise = ValuePromise(ChannelBlacklistControllerState(referenceTimestamp: Int32(Date().timeIntervalSince1970)), ignoreRepeated: true)
let stateValue = Atomic(value: ChannelBlacklistControllerState(referenceTimestamp: Int32(Date().timeIntervalSince1970)))
let updateState: ((ChannelBlacklistControllerState) -> ChannelBlacklistControllerState) -> Void = { f in
@ -287,8 +286,8 @@ public func channelBlacklistController(context: AccountContext, updatedPresentat
let removePeerDisposable = MetaDisposable()
actionsDisposable.add(removePeerDisposable)
let peerView = Promise<PeerView>()
peerView.set(context.account.viewTracker.peerView(peerId))
actionsDisposable.add(context.engine.peers.keepPeerUpdated(id: peerId, forceUpdate: false).start())
let blacklistPromise = Promise<[RenderedChannelParticipant]?>(nil)
let arguments = ChannelBlacklistControllerArguments(context: context, setPeerIdWithRevealedOptions: { peerId, fromPeerId in
@ -347,10 +346,11 @@ public func channelBlacklistController(context: AccountContext, updatedPresentat
}
}))
}, openPeer: { participant in
let _ = (peerView.get()
|> take(1)
|> deliverOnMainQueue).start(next: { peerView in
guard let channel = peerView.peers[peerId] as? TelegramChannel else {
let _ = (context.engine.data.get(
TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)
)
|> deliverOnMainQueue).start(next: { peer in
guard case let .channel(channel) = peer else {
return
}
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
@ -435,10 +435,14 @@ public func channelBlacklistController(context: AccountContext, updatedPresentat
let previousParticipantsValue = Atomic<[RenderedChannelParticipant]?>(value: nil)
let peer = context.engine.data.get(
TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)
)
let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData
let signal = combineLatest(queue: .mainQueue(), presentationData, statePromise.get(), peerView.get(), blacklistPromise.get())
let signal = combineLatest(queue: .mainQueue(), presentationData, statePromise.get(), peer, blacklistPromise.get())
|> deliverOnMainQueue
|> map { presentationData, state, view, participants -> (ItemListControllerState, (ItemListNodeState, Any)) in
|> map { presentationData, state, peer, participants -> (ItemListControllerState, (ItemListNodeState, Any)) in
var rightNavigationButton: ItemListNavigationButton?
var secondaryRightNavigationButton: ItemListNavigationButton?
if let participants = participants, !participants.isEmpty {
@ -498,7 +502,7 @@ public func channelBlacklistController(context: AccountContext, updatedPresentat
}
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.GroupRemoved_Title), leftNavigationButton: nil, rightNavigationButton: rightNavigationButton, secondaryRightNavigationButton: secondaryRightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true)
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelBlacklistControllerEntries(presentationData: presentationData, view: view, state: state, participants: participants), style: .blocks, emptyStateItem: emptyStateItem, searchItem: searchItem, animateChanges: previous != nil && participants != nil && previous!.count >= participants!.count)
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: channelBlacklistControllerEntries(presentationData: presentationData, peer: peer, state: state, participants: participants), style: .blocks, emptyStateItem: emptyStateItem, searchItem: searchItem, animateChanges: previous != nil && participants != nil && previous!.count >= participants!.count)
return (controllerState, (listState, arguments))
}

View File

@ -341,7 +341,7 @@ public func proxySettingsController(accountManager: AccountManager<TelegramAccou
return current
}).start()
}, addNewServer: {
pushControllerImpl?(proxyServerSettingsController(presentationData: presentationData, updatedPresentationData: updatedPresentationData, accountManager: accountManager, postbox: postbox, network: network, currentSettings: nil))
pushControllerImpl?(proxyServerSettingsController(presentationData: presentationData, updatedPresentationData: updatedPresentationData, accountManager: accountManager, network: network, currentSettings: nil))
}, activateServer: { server in
let _ = updateProxySettingsInteractively(accountManager: accountManager, { current in
var current = current
@ -354,7 +354,7 @@ public func proxySettingsController(accountManager: AccountManager<TelegramAccou
return current
}).start()
}, editServer: { server in
pushControllerImpl?(proxyServerSettingsController(presentationData: presentationData, updatedPresentationData: updatedPresentationData, accountManager: accountManager, postbox: postbox, network: network, currentSettings: server))
pushControllerImpl?(proxyServerSettingsController(presentationData: presentationData, updatedPresentationData: updatedPresentationData, accountManager: accountManager, network: network, currentSettings: server))
}, removeServer: { server in
let _ = updateProxySettingsInteractively(accountManager: accountManager, { current in
var current = current

View File

@ -2,7 +2,6 @@ import Foundation
import UIKit
import Display
import SwiftSignalKit
import Postbox
import TelegramCore
import MtProtoKit
import TelegramPresentationData
@ -266,10 +265,10 @@ private func proxyServerSettings(with state: ProxyServerSettingsControllerState)
public func proxyServerSettingsController(context: AccountContext, currentSettings: ProxyServerSettings? = nil) -> ViewController {
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
return proxyServerSettingsController(context: context, presentationData: presentationData, updatedPresentationData: context.sharedContext.presentationData, accountManager: context.sharedContext.accountManager, postbox: context.account.postbox, network: context.account.network, currentSettings: currentSettings)
return proxyServerSettingsController(context: context, presentationData: presentationData, updatedPresentationData: context.sharedContext.presentationData, accountManager: context.sharedContext.accountManager, network: context.account.network, currentSettings: currentSettings)
}
func proxyServerSettingsController(context: AccountContext? = nil, presentationData: PresentationData, updatedPresentationData: Signal<PresentationData, NoError>, accountManager: AccountManager<TelegramAccountManagerTypes>, postbox: Postbox, network: Network, currentSettings: ProxyServerSettings?) -> ViewController {
func proxyServerSettingsController(context: AccountContext? = nil, presentationData: PresentationData, updatedPresentationData: Signal<PresentationData, NoError>, accountManager: AccountManager<TelegramAccountManagerTypes>, network: Network, currentSettings: ProxyServerSettings?) -> ViewController {
var currentMode: ProxyServerSettingsControllerMode = .socks5
var currentUsername: String?
var currentPassword: String?

View File

@ -3,7 +3,6 @@ import UIKit
import Display
import AsyncDisplayKit
import SwiftSignalKit
import Postbox
import TelegramCore
import TelegramPresentationData
import ItemListUI

View File

@ -717,7 +717,7 @@ public final class VoiceChatControllerImpl: ViewController, VoiceChatController
expandedText = .text(about, textIcon, .generic)
}
return VoiceChatParticipantItem(presentationData: ItemListPresentationData(presentationData), dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, context: context, peer: peer, text: text, expandedText: expandedText, icon: icon, getAudioLevel: { return interaction.getAudioLevel(peer.id) }, action: { node in
return VoiceChatParticipantItem(presentationData: ItemListPresentationData(presentationData), dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, context: context, peer: EnginePeer(peer), text: text, expandedText: expandedText, icon: icon, getAudioLevel: { return interaction.getAudioLevel(peer.id) }, action: { node in
if let node = node {
interaction.peerContextAction(peerEntry, node, nil, false)
}

View File

@ -3,7 +3,6 @@ import UIKit
import Display
import AsyncDisplayKit
import SwiftSignalKit
import Postbox
import TelegramCore
import TelegramPresentationData
import TelegramUIPreferences
@ -59,7 +58,7 @@ final class VoiceChatParticipantItem: ListViewItem {
let dateTimeFormat: PresentationDateTimeFormat
let nameDisplayOrder: PresentationPersonNameOrder
let context: AccountContext
let peer: Peer
let peer: EnginePeer
let text: ParticipantText
let expandedText: ParticipantText?
let icon: Icon
@ -71,7 +70,7 @@ final class VoiceChatParticipantItem: ListViewItem {
public let selectable: Bool = true
public init(presentationData: ItemListPresentationData, dateTimeFormat: PresentationDateTimeFormat, nameDisplayOrder: PresentationPersonNameOrder, context: AccountContext, peer: Peer, text: ParticipantText, expandedText: ParticipantText?, icon: Icon, getAudioLevel: (() -> Signal<Float, NoError>)?, action: ((ASDisplayNode?) -> Void)?, contextAction: ((ASDisplayNode, ContextGesture?) -> Void)? = nil, getIsExpanded: @escaping () -> Bool, getUpdatingAvatar: @escaping () -> Signal<(TelegramMediaImageRepresentation, Float)?, NoError>) {
public init(presentationData: ItemListPresentationData, dateTimeFormat: PresentationDateTimeFormat, nameDisplayOrder: PresentationPersonNameOrder, context: AccountContext, peer: EnginePeer, text: ParticipantText, expandedText: ParticipantText?, icon: Icon, getAudioLevel: (() -> Signal<Float, NoError>)?, action: ((ASDisplayNode?) -> Void)?, contextAction: ((ASDisplayNode, ContextGesture?) -> Void)? = nil, getIsExpanded: @escaping () -> Bool, getUpdatingAvatar: @escaping () -> Signal<(TelegramMediaImageRepresentation, Float)?, NoError>) {
self.presentationData = presentationData
self.dateTimeFormat = dateTimeFormat
self.nameDisplayOrder = nameDisplayOrder
@ -512,7 +511,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode {
let avatarListNode = PeerInfoAvatarListContainerNode(context: item.context)
avatarListWrapperNode.contentNode.clipsToBounds = true
avatarListNode.backgroundColor = .clear
avatarListNode.peer = EnginePeer(item.peer)
avatarListNode.peer = item.peer
avatarListNode.firstFullSizeOnly = true
avatarListNode.offsetLocation = true
avatarListNode.customCenterTapAction = { [weak self] in
@ -528,7 +527,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode {
avatarListContainerNode.addSubnode(avatarListNode.controlsClippingOffsetNode)
avatarListWrapperNode.contentNode.addSubnode(avatarListContainerNode)
avatarListNode.update(size: targetRect.size, peer: EnginePeer(item.peer), customNode: nil, additionalEntry: item.getUpdatingAvatar(), isExpanded: true, transition: .immediate)
avatarListNode.update(size: targetRect.size, peer: item.peer, customNode: nil, additionalEntry: item.getUpdatingAvatar(), isExpanded: true, transition: .immediate)
strongSelf.offsetContainerNode.supernode?.addSubnode(avatarListWrapperNode)
strongSelf.audioLevelView?.alpha = 0.0
@ -785,7 +784,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode {
let rightInset: CGFloat = params.rightInset
var updatedTitle = false
if let user = item.peer as? TelegramUser {
if case let .user(user) = item.peer {
if let firstName = user.firstName, let lastName = user.lastName, !firstName.isEmpty, !lastName.isEmpty {
let string = NSMutableAttributedString()
switch item.nameDisplayOrder {
@ -806,9 +805,9 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode {
} else {
titleAttributedString = NSAttributedString(string: item.presentationData.strings.User_DeletedAccount, font: titleFont, textColor: titleColor)
}
} else if let group = item.peer as? TelegramGroup {
} else if case let .legacyGroup(group) = item.peer {
titleAttributedString = NSAttributedString(string: group.title, font: titleFont, textColor: titleColor)
} else if let channel = item.peer as? TelegramChannel {
} else if case let .channel(channel) = item.peer {
titleAttributedString = NSAttributedString(string: channel.title, font: titleFont, textColor: titleColor)
}
if let currentTitle = currentTitle, currentTitle != titleAttributedString?.string {
@ -840,7 +839,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode {
credibilityIcon = .text(color: item.presentationData.theme.chat.message.incoming.scamColor, string: item.presentationData.strings.Message_ScamAccount.uppercased())
} else if item.peer.isFake {
credibilityIcon = .text(color: item.presentationData.theme.chat.message.incoming.scamColor, string: item.presentationData.strings.Message_FakeAccount.uppercased())
} else if let user = item.peer as? TelegramUser, let emojiStatus = user.emojiStatus, !premiumConfiguration.isPremiumDisabled {
} else if case let .user(user) = item.peer, let emojiStatus = user.emojiStatus, !premiumConfiguration.isPremiumDisabled {
credibilityIcon = .animation(content: .customEmoji(fileId: emojiStatus.fileId), size: CGSize(width: 20.0, height: 20.0), placeholderColor: item.presentationData.theme.list.mediaPlaceholderColor, themeColor: item.presentationData.theme.list.itemAccentColor, loopMode: .count(2))
} else if item.peer.isVerified {
credibilityIcon = .verified(fillColor: item.presentationData.theme.list.itemCheckColors.fillColor, foregroundColor: item.presentationData.theme.list.itemCheckColors.foregroundColor, sizeType: .compact)
@ -1133,7 +1132,7 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode {
if item.peer.isDeleted {
overrideImage = .deletedIcon
}
strongSelf.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: EnginePeer(item.peer), overrideImage: overrideImage, emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, synchronousLoad: synchronousLoad, storeUnrounded: true)
strongSelf.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: item.peer, overrideImage: overrideImage, emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, synchronousLoad: synchronousLoad, storeUnrounded: true)
strongSelf.highlightContainerNode.frame = CGRect(origin: CGPoint(x: params.leftInset, y: -UIScreenPixel), size: CGSize(width: params.width - params.leftInset - params.rightInset, height: layout.contentSize.height + UIScreenPixel + UIScreenPixel + 11.0))

View File

@ -32,11 +32,18 @@ private final class MessageMediaPreuploadManagerContext {
assert(self.queue.isCurrent())
}
func add(network: Network, postbox: Postbox, id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal<MediaResourceData, NoError>, onComplete: (()->Void)? = nil) {
func add(network: Network, postbox: Postbox, id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal<EngineMediaResource.ResourceData, NoError>, onComplete: (()->Void)? = nil) {
let context = MessageMediaPreuploadManagerUploadContext()
self.uploadContexts[id] = context
let queue = self.queue
context.disposable.set(multipartUpload(network: network, postbox: postbox, source: .custom(source), encrypt: encrypt, tag: tag, hintFileSize: nil, hintFileIsLarge: false, forceNoBigParts: false).start(next: { [weak self] next in
context.disposable.set(multipartUpload(network: network, postbox: postbox, source: .custom(source |> map { data in
return MediaResourceData(
path: data.path,
offset: 0,
size: data.availableSize,
complete: data.isComplete
)
}), encrypt: encrypt, tag: tag, hintFileSize: nil, hintFileIsLarge: false, forceNoBigParts: false).start(next: { [weak self] next in
queue.async {
if let strongSelf = self, let context = strongSelf.uploadContexts[id] {
switch next {
@ -112,7 +119,7 @@ final class MessageMediaPreuploadManager {
})
}
func add(network: Network, postbox: Postbox, id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal<MediaResourceData, NoError>, onComplete:(()->Void)? = nil) {
func add(network: Network, postbox: Postbox, id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal<EngineMediaResource.ResourceData, NoError>, onComplete:(()->Void)? = nil) {
self.impl.with { context in
context.add(network: network, postbox: postbox, id: id, encrypt: encrypt, tag: tag, source: source, onComplete: onComplete)
}

View File

@ -2,6 +2,48 @@ import SwiftSignalKit
import Postbox
public extension TelegramEngine.EngineData.Item {
enum Collections {
public struct FeaturedStickerPacks: TelegramEngineDataItem, PostboxViewDataItem {
public typealias Result = [FeaturedStickerPackItem]
public init() {
}
var key: PostboxViewKey {
return .orderedItemList(id: Namespaces.OrderedItemList.CloudFeaturedStickerPacks)
}
func extract(view: PostboxView) -> Result {
guard let view = view as? OrderedItemListView else {
preconditionFailure()
}
return view.items.compactMap { item in
return item.contents.get(FeaturedStickerPackItem.self)
}
}
}
public struct FeaturedEmojiPacks: TelegramEngineDataItem, PostboxViewDataItem {
public typealias Result = [FeaturedStickerPackItem]
public init() {
}
var key: PostboxViewKey {
return .orderedItemList(id: Namespaces.OrderedItemList.CloudFeaturedEmojiPacks)
}
func extract(view: PostboxView) -> Result {
guard let view = view as? OrderedItemListView else {
preconditionFailure()
}
return view.items.compactMap { item in
return item.contents.get(FeaturedStickerPackItem.self)
}
}
}
}
enum OrderedLists {
public struct ListItems: TelegramEngineDataItem, PostboxViewDataItem {
public typealias Result = [OrderedItemListEntry]

View File

@ -231,7 +231,7 @@ public extension TelegramEngine {
self.account = account
}
public func preUpload(id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal<MediaResourceData, NoError>, onComplete: (()->Void)? = nil) {
public func preUpload(id: Int64, encrypt: Bool, tag: MediaResourceFetchTag?, source: Signal<EngineMediaResource.ResourceData, NoError>, onComplete: (()->Void)? = nil) {
return self.account.messageMediaPreuploadManager.add(network: self.account.network, postbox: self.account.postbox, id: id, encrypt: encrypt, tag: tag, source: source, onComplete: onComplete)
}

View File

@ -1,7 +1,6 @@
import Foundation
import UIKit
import Display
import Postbox
import TelegramCore
import TelegramUIPreferences
import AppBundle

View File

@ -2,7 +2,6 @@ import Foundation
import UIKit
import Display
import SwiftSignalKit
import Postbox
import TelegramCore
import ComponentFlow
import TelegramPresentationData

View File

@ -11,7 +11,6 @@ import ComponentDisplayAdapters
import TelegramPresentationData
import AccountContext
import PagerComponent
import Postbox
import TelegramCore
import Lottie
import EmojiTextAttachmentView
@ -19,6 +18,7 @@ import TextFormat
import AppBundle
import GZip
import EmojiStatusComponent
import Postbox
private func randomGenericReactionEffect(context: AccountContext) -> Signal<String?, NoError> {
return context.engine.stickers.loadedStickerPack(reference: .emojiGenericAnimations, forceActualized: false)
@ -344,16 +344,16 @@ public final class EmojiStatusSelectionController: ViewController {
self.layer.addSublayer(self.cloudLayer0)
self.layer.addSublayer(self.cloudLayer1)
let viewKey = PostboxViewKey.orderedItemList(id: Namespaces.OrderedItemList.CloudFeaturedEmojiPacks)
self.stableEmptyResultEmojiDisposable.set((self.context.account.postbox.combinedView(keys: [viewKey])
|> take(1)
|> deliverOnMainQueue).start(next: { [weak self] views in
guard let strongSelf = self, let view = views.views[viewKey] as? OrderedItemListView else {
self.stableEmptyResultEmojiDisposable.set((self.context.engine.data.get(
TelegramEngine.EngineData.Item.Collections.FeaturedEmojiPacks()
)
|> deliverOnMainQueue).start(next: { [weak self] featuredEmojiPacks in
guard let strongSelf = self else {
return
}
var filteredFiles: [TelegramMediaFile] = []
let filterList: [String] = ["😖", "😫", "🫠", "😨", ""]
for featuredEmojiPack in view.items.lazy.map({ $0.contents.get(FeaturedStickerPackItem.self)! }) {
for featuredEmojiPack in featuredEmojiPacks {
for item in featuredEmojiPack.topItems {
for attribute in item.file.attributes {
switch attribute {
@ -423,14 +423,14 @@ public final class EmojiStatusSelectionController: ViewController {
return
}
let viewKey = PostboxViewKey.orderedItemList(id: Namespaces.OrderedItemList.CloudFeaturedEmojiPacks)
let _ = (strongSelf.context.account.postbox.combinedView(keys: [viewKey])
|> take(1)
|> deliverOnMainQueue).start(next: { views in
guard let strongSelf = self, let view = views.views[viewKey] as? OrderedItemListView else {
let _ = (strongSelf.context.engine.data.get(
TelegramEngine.EngineData.Item.Collections.FeaturedEmojiPacks()
)
|> deliverOnMainQueue).start(next: { featuredEmojiPacks in
guard let strongSelf = self else {
return
}
for featuredEmojiPack in view.items.lazy.map({ $0.contents.get(FeaturedStickerPackItem.self)! }) {
for featuredEmojiPack in featuredEmojiPacks {
if featuredEmojiPack.info.id == collectionId {
if let strongSelf = self {
strongSelf.scheduledEmojiContentAnimationHint = EmojiPagerContentComponent.ContentAnimation(type: .groupInstalled(id: collectionId, scrollToGroup: true))
@ -592,7 +592,7 @@ public final class EmojiStatusSelectionController: ViewController {
|> mapToSignal { files, isFinalResult -> Signal<(items: [EmojiPagerContentComponent.ItemGroup], isFinalResult: Bool), NoError> in
var items: [EmojiPagerContentComponent.Item] = []
var existingIds = Set<MediaId>()
var existingIds = Set<EngineMedia.Id>()
for itemFile in files {
if existingIds.contains(itemFile.fileId) {
continue

View File

@ -7,7 +7,6 @@ import MultiAnimationRenderer
import ComponentFlow
import AccountContext
import TelegramCore
import Postbox
import TelegramPresentationData
import EmojiTextAttachmentView
import TextFormat
@ -52,7 +51,7 @@ public final class EmojiSuggestionsComponent: Component {
let normalizedQuery = query.basicEmoji.0
var existingIds = Set<MediaId>()
var existingIds = Set<EngineMedia.Id>()
for entry in view.entries {
guard let item = entry.item as? StickerPackItem else {
continue
@ -179,7 +178,7 @@ public final class EmojiSuggestionsComponent: Component {
private var itemLayout: ItemLayout?
private var ignoreScrolling: Bool = false
private var visibleLayers: [MediaId: InlineStickerItemLayer] = [:]
private var visibleLayers: [EngineMedia.Id: InlineStickerItemLayer] = [:]
override init(frame: CGRect) {
self.blurView = BlurredBackgroundView(color: .clear, enableBlur: true)
@ -296,7 +295,7 @@ public final class EmojiSuggestionsComponent: Component {
let visibleBounds = self.scrollView.bounds
var visibleIds = Set<MediaId>()
var visibleIds = Set<EngineMedia.Id>()
for i in 0 ..< component.files.count {
let itemFrame = itemLayout.frame(at: i)
if visibleBounds.intersects(itemFrame) {
@ -330,7 +329,7 @@ public final class EmojiSuggestionsComponent: Component {
}
}
var removedIds: [MediaId] = []
var removedIds: [EngineMedia.Id] = []
for (id, itemLayer) in self.visibleLayers {
if !visibleIds.contains(id) {
itemLayer.removeFromSuperlayer()