mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
commit
c7ab78a8a1
@ -896,10 +896,10 @@ public enum JoinAffiliateProgramScreenMode {
|
|||||||
|
|
||||||
public final class Active {
|
public final class Active {
|
||||||
public let targetPeer: EnginePeer
|
public let targetPeer: EnginePeer
|
||||||
public let bot: TelegramConnectedStarRefBotList.Item
|
public let bot: EngineConnectedStarRefBotsContext.Item
|
||||||
public let copyLink: (TelegramConnectedStarRefBotList.Item) -> Void
|
public let copyLink: (EngineConnectedStarRefBotsContext.Item) -> Void
|
||||||
|
|
||||||
public init(targetPeer: EnginePeer, bot: TelegramConnectedStarRefBotList.Item, copyLink: @escaping (TelegramConnectedStarRefBotList.Item) -> Void) {
|
public init(targetPeer: EnginePeer, bot: EngineConnectedStarRefBotsContext.Item, copyLink: @escaping (EngineConnectedStarRefBotsContext.Item) -> Void) {
|
||||||
self.targetPeer = targetPeer
|
self.targetPeer = targetPeer
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.copyLink = copyLink
|
self.copyLink = copyLink
|
||||||
|
@ -333,6 +333,11 @@ public final class AccountStateManager {
|
|||||||
return self.sentScheduledMessageIdsPipe.signal()
|
return self.sentScheduledMessageIdsPipe.signal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileprivate let starRefBotConnectionEventsPipe = ValuePipe<StarRefBotConnectionEvent>()
|
||||||
|
public var starRefBotConnectionEvents: Signal<StarRefBotConnectionEvent, NoError> {
|
||||||
|
return self.starRefBotConnectionEventsPipe.signal()
|
||||||
|
}
|
||||||
|
|
||||||
private var updatedWebpageContexts: [MediaId: UpdatedWebpageSubscriberContext] = [:]
|
private var updatedWebpageContexts: [MediaId: UpdatedWebpageSubscriberContext] = [:]
|
||||||
private var updatedPeersNearbyContext = UpdatedPeersNearbySubscriberContext()
|
private var updatedPeersNearbyContext = UpdatedPeersNearbySubscriberContext()
|
||||||
private var updatedRevenueBalancesContext = UpdatedRevenueBalancesSubscriberContext()
|
private var updatedRevenueBalancesContext = UpdatedRevenueBalancesSubscriberContext()
|
||||||
@ -1804,6 +1809,10 @@ public final class AccountStateManager {
|
|||||||
self.removePossiblyDeliveredMessagesUniqueIds.merge(uniqueIds, uniquingKeysWith: { _, rhs in rhs })
|
self.removePossiblyDeliveredMessagesUniqueIds.merge(uniqueIds, uniquingKeysWith: { _, rhs in rhs })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addStarRefBotConnectionEvent(event: StarRefBotConnectionEvent) {
|
||||||
|
self.starRefBotConnectionEventsPipe.putNext(event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private let impl: QueueLocalObject<Impl>
|
private let impl: QueueLocalObject<Impl>
|
||||||
@ -2183,6 +2192,18 @@ public final class AccountStateManager {
|
|||||||
public func synchronouslyIsMessageDeletedRemotely(ids: [EngineMessage.Id]) -> [EngineMessage.Id] {
|
public func synchronouslyIsMessageDeletedRemotely(ids: [EngineMessage.Id]) -> [EngineMessage.Id] {
|
||||||
return self.messagesRemovedContext.synchronouslyIsMessageDeletedRemotely(ids: ids)
|
return self.messagesRemovedContext.synchronouslyIsMessageDeletedRemotely(ids: ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func starRefBotConnectionEvents() -> Signal<StarRefBotConnectionEvent, NoError> {
|
||||||
|
return self.impl.signalWith { impl, subscriber in
|
||||||
|
return impl.starRefBotConnectionEventsPipe.signal().start(next: subscriber.putNext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addStarRefBotConnectionEvent(event: StarRefBotConnectionEvent) {
|
||||||
|
self.impl.with { impl in
|
||||||
|
impl.addStarRefBotConnectionEvent(event: event)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveNotificationSettings(list: [TelegramPeerNotificationSettings], defaultSettings: MessageNotificationSettings) -> (sound: PeerMessageSound, notify: Bool, displayContents: Bool) {
|
func resolveNotificationSettings(list: [TelegramPeerNotificationSettings], defaultSettings: MessageNotificationSettings) -> (sound: PeerMessageSound, notify: Bool, displayContents: Bool) {
|
||||||
|
@ -601,49 +601,12 @@ public func formatPermille(_ value: Int) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _internal_updateStarRefProgram(account: Account, id: EnginePeer.Id, program: (commissionPermille: Int32, durationMonths: Int32?)?) -> Signal<Never, NoError> {
|
public enum StarRefBotConnectionEvent {
|
||||||
return account.postbox.transaction { transaction -> Api.InputUser? in
|
case add(peerId: EnginePeer.Id, item: EngineConnectedStarRefBotsContext.Item)
|
||||||
return transaction.getPeer(id).flatMap(apiInputUser)
|
case remove(peerId: EnginePeer.Id, url: String)
|
||||||
}
|
|
||||||
|> mapToSignal { inputPeer -> Signal<Never, NoError> in
|
|
||||||
guard let inputPeer else {
|
|
||||||
return .complete()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var flags: Int32 = 0
|
public final class EngineConnectedStarRefBotsContext {
|
||||||
if let program, program.durationMonths != nil {
|
|
||||||
flags |= 1 << 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return account.network.request(Api.functions.bots.updateStarRefProgram(
|
|
||||||
flags: flags,
|
|
||||||
bot: inputPeer,
|
|
||||||
commissionPermille: program?.commissionPermille ?? 0,
|
|
||||||
durationMonths: program?.durationMonths
|
|
||||||
))
|
|
||||||
|> map(Optional.init)
|
|
||||||
|> `catch` { _ -> Signal<Api.StarRefProgram?, NoError> in
|
|
||||||
return .single(nil)
|
|
||||||
}
|
|
||||||
|> mapToSignal { result -> Signal<Never, NoError> in
|
|
||||||
guard let result else {
|
|
||||||
return .complete()
|
|
||||||
}
|
|
||||||
return account.postbox.transaction { transaction -> Void in
|
|
||||||
transaction.updatePeerCachedData(peerIds: Set([id]), update: { _, current in
|
|
||||||
guard var current = current as? CachedUserData else {
|
|
||||||
return current ?? CachedUserData()
|
|
||||||
}
|
|
||||||
current = current.withUpdatedStarRefProgram(TelegramStarRefProgram(apiStarRefProgram: result))
|
|
||||||
return current
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|> ignoreValues
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class TelegramConnectedStarRefBotList : Equatable {
|
|
||||||
public final class Item: Equatable {
|
public final class Item: Equatable {
|
||||||
public let peer: EnginePeer
|
public let peer: EnginePeer
|
||||||
public let url: String
|
public let url: String
|
||||||
@ -689,84 +652,176 @@ public final class TelegramConnectedStarRefBotList : Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public let items: [Item]
|
public struct State: Equatable {
|
||||||
public let totalCount: Int
|
public struct Offset: Equatable {
|
||||||
|
fileprivate var isInitial: Bool
|
||||||
|
fileprivate var timestamp: Int32
|
||||||
|
fileprivate var link: String
|
||||||
|
|
||||||
public init(items: [Item], totalCount: Int) {
|
fileprivate init(isInitial: Bool, timestamp: Int32, link: String) {
|
||||||
|
self.isInitial = isInitial
|
||||||
|
self.timestamp = timestamp
|
||||||
|
self.link = link
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public var items: [Item]
|
||||||
|
public var totalCount: Int
|
||||||
|
public var nextOffset: Offset?
|
||||||
|
public var isLoaded: Bool
|
||||||
|
|
||||||
|
public init(items: [Item], totalCount: Int, nextOffset: Offset?, isLoaded: Bool) {
|
||||||
self.items = items
|
self.items = items
|
||||||
self.totalCount = totalCount
|
self.totalCount = totalCount
|
||||||
}
|
self.nextOffset = nextOffset
|
||||||
|
self.isLoaded = isLoaded
|
||||||
public static func == (lhs: TelegramConnectedStarRefBotList, rhs: TelegramConnectedStarRefBotList) -> Bool {
|
|
||||||
return lhs.items == rhs.items && lhs.totalCount == rhs.totalCount
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _internal_requestConnectedStarRefBots(account: Account, id: EnginePeer.Id, offset: (timestamp: Int32, link: String)?, limit: Int) -> Signal<TelegramConnectedStarRefBotList?, NoError> {
|
private final class Impl {
|
||||||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
let queue: Queue
|
||||||
return transaction.getPeer(id).flatMap(apiInputPeer)
|
let account: Account
|
||||||
}
|
let peerId: EnginePeer.Id
|
||||||
|> mapToSignal { inputPeer -> Signal<TelegramConnectedStarRefBotList?, NoError> in
|
|
||||||
guard let inputPeer else {
|
|
||||||
return .single(nil)
|
|
||||||
}
|
|
||||||
var flags: Int32 = 0
|
|
||||||
if offset != nil {
|
|
||||||
flags |= 1 << 2
|
|
||||||
}
|
|
||||||
return account.network.request(Api.functions.payments.getConnectedStarRefBots(
|
|
||||||
flags: flags,
|
|
||||||
peer: inputPeer,
|
|
||||||
offsetDate: offset?.timestamp,
|
|
||||||
offsetLink: offset?.link,
|
|
||||||
limit: Int32(limit)
|
|
||||||
))
|
|
||||||
|> map(Optional.init)
|
|
||||||
|> `catch` { _ -> Signal<Api.payments.ConnectedStarRefBots?, NoError> in
|
|
||||||
return .single(nil)
|
|
||||||
}
|
|
||||||
|> mapToSignal { result -> Signal<TelegramConnectedStarRefBotList?, NoError> in
|
|
||||||
guard let result else {
|
|
||||||
return .single(nil)
|
|
||||||
}
|
|
||||||
return account.postbox.transaction { transaction -> TelegramConnectedStarRefBotList? in
|
|
||||||
switch result {
|
|
||||||
case let .connectedStarRefBots(count, connectedBots, users):
|
|
||||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
|
||||||
|
|
||||||
var items: [TelegramConnectedStarRefBotList.Item] = []
|
var state: State
|
||||||
for connectedBot in connectedBots {
|
var pendingRemoveItems = Set<String>()
|
||||||
switch connectedBot {
|
var statePromise = Promise<State>()
|
||||||
case let .connectedBotStarRef(_, url, date, botId, commissionPermille, durationMonths, participants, revenue):
|
|
||||||
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
|
var loadMoreDisposable: Disposable?
|
||||||
continue
|
var isLoadingMore: Bool = false
|
||||||
|
|
||||||
|
var eventsDisposable: Disposable?
|
||||||
|
|
||||||
|
init(queue: Queue, account: Account, peerId: EnginePeer.Id) {
|
||||||
|
self.queue = queue
|
||||||
|
self.account = account
|
||||||
|
self.peerId = peerId
|
||||||
|
|
||||||
|
self.state = State(items: [], totalCount: 0, nextOffset: State.Offset(isInitial: true, timestamp: 0, link: ""), isLoaded: false)
|
||||||
|
self.updateState()
|
||||||
|
|
||||||
|
self.loadMore()
|
||||||
|
|
||||||
|
self.eventsDisposable = (account.stateManager.starRefBotConnectionEvents()
|
||||||
|
|> deliverOn(self.queue)).startStrict(next: { [weak self] event in
|
||||||
|
guard let self else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
items.append(TelegramConnectedStarRefBotList.Item(
|
switch event {
|
||||||
peer: EnginePeer(botPeer),
|
case let .add(peerId, item):
|
||||||
url: url,
|
if peerId == self.peerId {
|
||||||
timestamp: date,
|
self.state.items.insert(item, at: 0)
|
||||||
commissionPermille: commissionPermille,
|
self.updateState()
|
||||||
durationMonths: durationMonths,
|
}
|
||||||
participants: participants,
|
case let .remove(peerId, url):
|
||||||
revenue: revenue
|
if peerId == self.peerId {
|
||||||
))
|
self.state.items.removeAll(where: { $0.url == url })
|
||||||
|
self.updateState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
assert(self.queue.isCurrent())
|
||||||
|
self.loadMoreDisposable?.dispose()
|
||||||
|
self.eventsDisposable?.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadMore() {
|
||||||
|
if self.isLoadingMore {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard let offset = self.state.nextOffset else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.isLoadingMore = true
|
||||||
|
|
||||||
|
var effectiveOffset: (timestamp: Int32, link: String)?
|
||||||
|
if !offset.isInitial {
|
||||||
|
effectiveOffset = (timestamp: offset.timestamp, link: offset.link)
|
||||||
|
}
|
||||||
|
self.loadMoreDisposable?.dispose()
|
||||||
|
self.loadMoreDisposable = (_internal_requestConnectedStarRefBots(account: self.account, id: self.peerId, offset: effectiveOffset, limit: 100)
|
||||||
|
|> deliverOn(self.queue)).startStrict(next: { [weak self] result in
|
||||||
|
guard let self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.isLoadingMore = false
|
||||||
|
|
||||||
|
self.state.isLoaded = true
|
||||||
|
if let result, !result.items.isEmpty {
|
||||||
|
for item in result.items {
|
||||||
|
if !self.state.items.contains(where: { $0.url == item.url }) {
|
||||||
|
self.state.items.append(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if result.nextOffset != nil {
|
||||||
|
self.state.totalCount = result.totalCount
|
||||||
|
} else {
|
||||||
|
self.state.totalCount = self.state.items.count
|
||||||
|
}
|
||||||
|
self.state.nextOffset = result.nextOffset.flatMap { value in
|
||||||
|
return State.Offset(isInitial: false, timestamp: value.timestamp, link: value.link)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.state.totalCount = self.state.items.count
|
||||||
|
self.state.nextOffset = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.updateState()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateState() {
|
||||||
|
var state = self.state
|
||||||
|
if !self.pendingRemoveItems.isEmpty {
|
||||||
|
state.items = state.items.filter { item in
|
||||||
|
return !self.pendingRemoveItems.contains(item.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.statePromise.set(.single(state))
|
||||||
|
}
|
||||||
|
|
||||||
|
func remove(url: String) {
|
||||||
|
self.pendingRemoveItems.insert(url)
|
||||||
|
let _ = _internal_removeConnectedStarRefBot(account: self.account, id: self.peerId, link: url).startStandalone()
|
||||||
|
self.updateState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TelegramConnectedStarRefBotList(items: items, totalCount: Int(count))
|
private let queue: Queue
|
||||||
|
private let impl: QueueLocalObject<Impl>
|
||||||
|
|
||||||
|
public var state: Signal<State, NoError> {
|
||||||
|
return self.impl.signalWith { impl, subscriber in
|
||||||
|
return impl.statePromise.get().start(next: subscriber.putNext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init(account: Account, peerId: EnginePeer.Id) {
|
||||||
|
let queue = Queue.mainQueue()
|
||||||
|
self.queue = queue
|
||||||
|
self.impl = QueueLocalObject(queue: queue, generate: {
|
||||||
|
return Impl(queue: queue, account: account, peerId: peerId)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public func loadMore() {
|
||||||
|
self.impl.with { impl in
|
||||||
|
impl.loadMore()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func remove(url: String) {
|
||||||
|
self.impl.with { impl in
|
||||||
|
impl.remove(url: url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class TelegramSuggestedStarRefBotList: Equatable {
|
public final class EngineSuggestedStarRefBotsContext {
|
||||||
public enum SortMode {
|
|
||||||
case date
|
|
||||||
case profitability
|
|
||||||
case revenue
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class Item: Equatable {
|
public final class Item: Equatable {
|
||||||
public let peer: EnginePeer
|
public let peer: EnginePeer
|
||||||
public let program: TelegramStarRefProgram
|
public let program: TelegramStarRefProgram
|
||||||
@ -787,26 +842,237 @@ public final class TelegramSuggestedStarRefBotList: Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public let items: [Item]
|
public struct State: Equatable {
|
||||||
public let totalCount: Int
|
public var items: [Item]
|
||||||
public let nextOffset: String?
|
public var totalCount: Int
|
||||||
|
public var nextOffset: String?
|
||||||
|
public var isLoaded: Bool
|
||||||
|
|
||||||
public init(items: [Item], totalCount: Int, nextOffset: String?) {
|
public init(items: [Item], totalCount: Int, nextOffset: String?, isLoaded: Bool) {
|
||||||
self.items = items
|
self.items = items
|
||||||
self.totalCount = totalCount
|
self.totalCount = totalCount
|
||||||
self.nextOffset = nextOffset
|
self.nextOffset = nextOffset
|
||||||
}
|
self.isLoaded = isLoaded
|
||||||
|
|
||||||
public static func == (lhs: TelegramSuggestedStarRefBotList, rhs: TelegramSuggestedStarRefBotList) -> Bool {
|
|
||||||
return lhs.items == rhs.items && lhs.totalCount == rhs.totalCount && lhs.nextOffset == rhs.nextOffset
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id, sortMode: TelegramSuggestedStarRefBotList.SortMode, offset: String?, limit: Int) -> Signal<TelegramSuggestedStarRefBotList?, NoError> {
|
public enum SortMode {
|
||||||
|
case date
|
||||||
|
case profitability
|
||||||
|
case revenue
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class Impl {
|
||||||
|
let queue: Queue
|
||||||
|
let account: Account
|
||||||
|
let peerId: EnginePeer.Id
|
||||||
|
let sortMode: SortMode
|
||||||
|
|
||||||
|
var state: State
|
||||||
|
var statePromise = Promise<State>()
|
||||||
|
|
||||||
|
var loadMoreDisposable: Disposable?
|
||||||
|
var isLoadingMore: Bool = false
|
||||||
|
|
||||||
|
init(queue: Queue, account: Account, peerId: EnginePeer.Id, sortMode: SortMode) {
|
||||||
|
self.queue = queue
|
||||||
|
self.account = account
|
||||||
|
self.peerId = peerId
|
||||||
|
self.sortMode = sortMode
|
||||||
|
|
||||||
|
self.state = State(items: [], totalCount: 0, nextOffset: "", isLoaded: false)
|
||||||
|
self.updateState()
|
||||||
|
|
||||||
|
self.loadMore()
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
assert(self.queue.isCurrent())
|
||||||
|
self.loadMoreDisposable?.dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadMore() {
|
||||||
|
if self.isLoadingMore {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard let offset = self.state.nextOffset else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.isLoadingMore = true
|
||||||
|
|
||||||
|
self.loadMoreDisposable?.dispose()
|
||||||
|
self.loadMoreDisposable = (_internal_requestSuggestedStarRefBots(account: self.account, id: self.peerId, sortMode: self.sortMode, offset: offset, limit: 100)
|
||||||
|
|> deliverOn(self.queue)).startStrict(next: { [weak self] result in
|
||||||
|
guard let self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.isLoadingMore = false
|
||||||
|
|
||||||
|
self.state.isLoaded = true
|
||||||
|
if let result, !result.items.isEmpty {
|
||||||
|
for item in result.items {
|
||||||
|
if !self.state.items.contains(where: { $0.peer.id == item.peer.id }) {
|
||||||
|
self.state.items.append(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if result.nextOffset != nil {
|
||||||
|
self.state.totalCount = result.totalCount
|
||||||
|
} else {
|
||||||
|
self.state.totalCount = self.state.items.count
|
||||||
|
}
|
||||||
|
self.state.nextOffset = result.nextOffset
|
||||||
|
} else {
|
||||||
|
self.state.totalCount = self.state.items.count
|
||||||
|
self.state.nextOffset = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.updateState()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateState() {
|
||||||
|
self.statePromise.set(.single(self.state))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private let queue: Queue
|
||||||
|
public let sortMode: SortMode
|
||||||
|
private let impl: QueueLocalObject<Impl>
|
||||||
|
|
||||||
|
public var state: Signal<State, NoError> {
|
||||||
|
return self.impl.signalWith { impl, subscriber in
|
||||||
|
return impl.statePromise.get().start(next: subscriber.putNext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init(account: Account, peerId: EnginePeer.Id, sortMode: SortMode) {
|
||||||
|
let queue = Queue.mainQueue()
|
||||||
|
self.queue = queue
|
||||||
|
self.sortMode = sortMode
|
||||||
|
self.impl = QueueLocalObject(queue: queue, generate: {
|
||||||
|
return Impl(queue: queue, account: account, peerId: peerId, sortMode: sortMode)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public func loadMore() {
|
||||||
|
self.impl.with { impl in
|
||||||
|
impl.loadMore()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func _internal_updateStarRefProgram(account: Account, id: EnginePeer.Id, program: (commissionPermille: Int32, durationMonths: Int32?)?) -> Signal<Never, NoError> {
|
||||||
|
return account.postbox.transaction { transaction -> Api.InputUser? in
|
||||||
|
return transaction.getPeer(id).flatMap(apiInputUser)
|
||||||
|
}
|
||||||
|
|> mapToSignal { inputPeer -> Signal<Never, NoError> in
|
||||||
|
guard let inputPeer else {
|
||||||
|
return .complete()
|
||||||
|
}
|
||||||
|
|
||||||
|
var flags: Int32 = 0
|
||||||
|
if let program, program.durationMonths != nil {
|
||||||
|
flags |= 1 << 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return account.network.request(Api.functions.bots.updateStarRefProgram(
|
||||||
|
flags: flags,
|
||||||
|
bot: inputPeer,
|
||||||
|
commissionPermille: program?.commissionPermille ?? 0,
|
||||||
|
durationMonths: program?.durationMonths
|
||||||
|
))
|
||||||
|
|> map(Optional.init)
|
||||||
|
|> `catch` { _ -> Signal<Api.StarRefProgram?, NoError> in
|
||||||
|
return .single(nil)
|
||||||
|
}
|
||||||
|
|> mapToSignal { result -> Signal<Never, NoError> in
|
||||||
|
guard let result else {
|
||||||
|
return .complete()
|
||||||
|
}
|
||||||
|
return account.postbox.transaction { transaction -> Void in
|
||||||
|
transaction.updatePeerCachedData(peerIds: Set([id]), update: { _, current in
|
||||||
|
guard var current = current as? CachedUserData else {
|
||||||
|
return current ?? CachedUserData()
|
||||||
|
}
|
||||||
|
current = current.withUpdatedStarRefProgram(TelegramStarRefProgram(apiStarRefProgram: result))
|
||||||
|
return current
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|> ignoreValues
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func _internal_requestConnectedStarRefBots(account: Account, id: EnginePeer.Id, offset: (timestamp: Int32, link: String)?, limit: Int) -> Signal<(items: [EngineConnectedStarRefBotsContext.Item], totalCount: Int, nextOffset: (timestamp: Int32, link: String)?)?, NoError> {
|
||||||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||||
return transaction.getPeer(id).flatMap(apiInputPeer)
|
return transaction.getPeer(id).flatMap(apiInputPeer)
|
||||||
}
|
}
|
||||||
|> mapToSignal { inputPeer -> Signal<TelegramSuggestedStarRefBotList?, NoError> in
|
|> mapToSignal { inputPeer -> Signal<(items: [EngineConnectedStarRefBotsContext.Item], totalCount: Int, nextOffset: (timestamp: Int32, link: String)?)?, NoError> in
|
||||||
|
guard let inputPeer else {
|
||||||
|
return .single(nil)
|
||||||
|
}
|
||||||
|
var flags: Int32 = 0
|
||||||
|
if offset != nil {
|
||||||
|
flags |= 1 << 2
|
||||||
|
}
|
||||||
|
return account.network.request(Api.functions.payments.getConnectedStarRefBots(
|
||||||
|
flags: flags,
|
||||||
|
peer: inputPeer,
|
||||||
|
offsetDate: offset?.timestamp,
|
||||||
|
offsetLink: offset?.link,
|
||||||
|
limit: Int32(limit)
|
||||||
|
))
|
||||||
|
|> map(Optional.init)
|
||||||
|
|> `catch` { _ -> Signal<Api.payments.ConnectedStarRefBots?, NoError> in
|
||||||
|
return .single(nil)
|
||||||
|
}
|
||||||
|
|> mapToSignal { result -> Signal<(items: [EngineConnectedStarRefBotsContext.Item], totalCount: Int, nextOffset: (timestamp: Int32, link: String)?)?, NoError> in
|
||||||
|
guard let result else {
|
||||||
|
return .single(nil)
|
||||||
|
}
|
||||||
|
return account.postbox.transaction { transaction -> (items: [EngineConnectedStarRefBotsContext.Item], totalCount: Int, nextOffset: (timestamp: Int32, link: String)?)? in
|
||||||
|
switch result {
|
||||||
|
case let .connectedStarRefBots(count, connectedBots, users):
|
||||||
|
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
||||||
|
|
||||||
|
var items: [EngineConnectedStarRefBotsContext.Item] = []
|
||||||
|
for connectedBot in connectedBots {
|
||||||
|
switch connectedBot {
|
||||||
|
case let .connectedBotStarRef(_, url, date, botId, commissionPermille, durationMonths, participants, revenue):
|
||||||
|
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
items.append(EngineConnectedStarRefBotsContext.Item(
|
||||||
|
peer: EnginePeer(botPeer),
|
||||||
|
url: url,
|
||||||
|
timestamp: date,
|
||||||
|
commissionPermille: commissionPermille,
|
||||||
|
durationMonths: durationMonths,
|
||||||
|
participants: participants,
|
||||||
|
revenue: revenue
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var nextOffset: (timestamp: Int32, link: String)?
|
||||||
|
if !connectedBots.isEmpty {
|
||||||
|
nextOffset = items.last.flatMap { item in
|
||||||
|
return (item.timestamp, item.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (items: items, totalCount: Int(count), nextOffset: nextOffset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id, sortMode: EngineSuggestedStarRefBotsContext.SortMode, offset: String?, limit: Int) -> Signal<(items: [EngineSuggestedStarRefBotsContext.Item], totalCount: Int, nextOffset: String?)?, NoError> {
|
||||||
|
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||||
|
return transaction.getPeer(id).flatMap(apiInputPeer)
|
||||||
|
}
|
||||||
|
|> mapToSignal { inputPeer -> Signal<(items: [EngineSuggestedStarRefBotsContext.Item], totalCount: Int, nextOffset: String?)?, NoError> in
|
||||||
guard let inputPeer else {
|
guard let inputPeer else {
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
}
|
}
|
||||||
@ -829,28 +1095,28 @@ func _internal_requestSuggestedStarRefBots(account: Account, id: EnginePeer.Id,
|
|||||||
|> `catch` { _ -> Signal<Api.payments.SuggestedStarRefBots?, NoError> in
|
|> `catch` { _ -> Signal<Api.payments.SuggestedStarRefBots?, NoError> in
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
}
|
}
|
||||||
|> mapToSignal { result -> Signal<TelegramSuggestedStarRefBotList?, NoError> in
|
|> mapToSignal { result -> Signal<(items: [EngineSuggestedStarRefBotsContext.Item], totalCount: Int, nextOffset: String?)?, NoError> in
|
||||||
guard let result else {
|
guard let result else {
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
}
|
}
|
||||||
return account.postbox.transaction { transaction -> TelegramSuggestedStarRefBotList? in
|
return account.postbox.transaction { transaction -> (items: [EngineSuggestedStarRefBotsContext.Item], totalCount: Int, nextOffset: String?)? in
|
||||||
switch result {
|
switch result {
|
||||||
case let .suggestedStarRefBots(_, count, suggestedBots, users, nextOffset):
|
case let .suggestedStarRefBots(_, count, suggestedBots, users, nextOffset):
|
||||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
||||||
|
|
||||||
var items: [TelegramSuggestedStarRefBotList.Item] = []
|
var items: [EngineSuggestedStarRefBotsContext.Item] = []
|
||||||
for starRefProgram in suggestedBots {
|
for starRefProgram in suggestedBots {
|
||||||
let parsedProgram = TelegramStarRefProgram(apiStarRefProgram: starRefProgram)
|
let parsedProgram = TelegramStarRefProgram(apiStarRefProgram: starRefProgram)
|
||||||
guard let botPeer = transaction.getPeer(parsedProgram.botId) else {
|
guard let botPeer = transaction.getPeer(parsedProgram.botId) else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
items.append(TelegramSuggestedStarRefBotList.Item(
|
items.append(EngineSuggestedStarRefBotsContext.Item(
|
||||||
peer: EnginePeer(botPeer),
|
peer: EnginePeer(botPeer),
|
||||||
program: parsedProgram
|
program: parsedProgram
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
return TelegramSuggestedStarRefBotList(items: items, totalCount: Int(count), nextOffset: nextOffset)
|
return (items: items, totalCount: Int(count), nextOffset: nextOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -861,7 +1127,7 @@ public enum ConnectStarRefBotError {
|
|||||||
case generic
|
case generic
|
||||||
}
|
}
|
||||||
|
|
||||||
func _internal_connectStarRefBot(account: Account, id: EnginePeer.Id, botId: EnginePeer.Id) -> Signal<TelegramConnectedStarRefBotList.Item, ConnectStarRefBotError> {
|
func _internal_connectStarRefBot(account: Account, id: EnginePeer.Id, botId: EnginePeer.Id) -> Signal<EngineConnectedStarRefBotsContext.Item, ConnectStarRefBotError> {
|
||||||
return account.postbox.transaction { transaction -> (Api.InputPeer?, Api.InputUser?) in
|
return account.postbox.transaction { transaction -> (Api.InputPeer?, Api.InputUser?) in
|
||||||
return (
|
return (
|
||||||
transaction.getPeer(id).flatMap(apiInputPeer),
|
transaction.getPeer(id).flatMap(apiInputPeer),
|
||||||
@ -869,7 +1135,7 @@ func _internal_connectStarRefBot(account: Account, id: EnginePeer.Id, botId: Eng
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|> castError(ConnectStarRefBotError.self)
|
|> castError(ConnectStarRefBotError.self)
|
||||||
|> mapToSignal { inputPeer, inputBotUser -> Signal<TelegramConnectedStarRefBotList.Item, ConnectStarRefBotError> in
|
|> mapToSignal { inputPeer, inputBotUser -> Signal<EngineConnectedStarRefBotsContext.Item, ConnectStarRefBotError> in
|
||||||
guard let inputPeer, let inputBotUser else {
|
guard let inputPeer, let inputBotUser else {
|
||||||
return .fail(.generic)
|
return .fail(.generic)
|
||||||
}
|
}
|
||||||
@ -877,8 +1143,8 @@ func _internal_connectStarRefBot(account: Account, id: EnginePeer.Id, botId: Eng
|
|||||||
|> mapError { _ -> ConnectStarRefBotError in
|
|> mapError { _ -> ConnectStarRefBotError in
|
||||||
return .generic
|
return .generic
|
||||||
}
|
}
|
||||||
|> mapToSignal { result -> Signal<TelegramConnectedStarRefBotList.Item, ConnectStarRefBotError> in
|
|> mapToSignal { result -> Signal<EngineConnectedStarRefBotsContext.Item, ConnectStarRefBotError> in
|
||||||
return account.postbox.transaction { transaction -> TelegramConnectedStarRefBotList.Item? in
|
return account.postbox.transaction { transaction -> EngineConnectedStarRefBotsContext.Item? in
|
||||||
switch result {
|
switch result {
|
||||||
case let .connectedStarRefBots(_, connectedBots, users):
|
case let .connectedStarRefBots(_, connectedBots, users):
|
||||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
||||||
@ -889,7 +1155,7 @@ func _internal_connectStarRefBot(account: Account, id: EnginePeer.Id, botId: Eng
|
|||||||
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
|
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return TelegramConnectedStarRefBotList.Item(
|
return EngineConnectedStarRefBotsContext.Item(
|
||||||
peer: EnginePeer(botPeer),
|
peer: EnginePeer(botPeer),
|
||||||
url: url,
|
url: url,
|
||||||
timestamp: date,
|
timestamp: date,
|
||||||
@ -905,8 +1171,9 @@ func _internal_connectStarRefBot(account: Account, id: EnginePeer.Id, botId: Eng
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> castError(ConnectStarRefBotError.self)
|
|> castError(ConnectStarRefBotError.self)
|
||||||
|> mapToSignal { item -> Signal<TelegramConnectedStarRefBotList.Item, ConnectStarRefBotError> in
|
|> mapToSignal { item -> Signal<EngineConnectedStarRefBotsContext.Item, ConnectStarRefBotError> in
|
||||||
if let item {
|
if let item {
|
||||||
|
account.stateManager.addStarRefBotConnectionEvent(event: .add(peerId: id, item: item))
|
||||||
return .single(item)
|
return .single(item)
|
||||||
} else {
|
} else {
|
||||||
return .fail(.generic)
|
return .fail(.generic)
|
||||||
@ -916,7 +1183,7 @@ func _internal_connectStarRefBot(account: Account, id: EnginePeer.Id, botId: Eng
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _internal_removeConnectedStarRefBot(account: Account, id: EnginePeer.Id, link: String) -> Signal<Never, ConnectStarRefBotError> {
|
fileprivate func _internal_removeConnectedStarRefBot(account: Account, id: EnginePeer.Id, link: String) -> Signal<Never, ConnectStarRefBotError> {
|
||||||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||||
return transaction.getPeer(id).flatMap(apiInputPeer)
|
return transaction.getPeer(id).flatMap(apiInputPeer)
|
||||||
}
|
}
|
||||||
@ -938,26 +1205,9 @@ func _internal_removeConnectedStarRefBot(account: Account, id: EnginePeer.Id, li
|
|||||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
||||||
|
|
||||||
let _ = connectedBots
|
let _ = connectedBots
|
||||||
/*if let bot = connectedBots.first {
|
|
||||||
switch bot {
|
|
||||||
case let .connectedBotStarRef(_, url, date, botId, commissionPermille, durationMonths, participants, revenue):
|
|
||||||
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return TelegramConnectedStarRefBotList.Item(
|
|
||||||
peer: EnginePeer(botPeer),
|
|
||||||
url: url,
|
|
||||||
timestamp: date,
|
|
||||||
commissionPermille: commissionPermille,
|
|
||||||
durationMonths: durationMonths,
|
|
||||||
participants: participants,
|
|
||||||
revenue: revenue
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
account.stateManager.addStarRefBotConnectionEvent(event: .remove(peerId: id, url: link))
|
||||||
}
|
}
|
||||||
|> castError(ConnectStarRefBotError.self)
|
|> castError(ConnectStarRefBotError.self)
|
||||||
|> ignoreValues
|
|> ignoreValues
|
||||||
@ -965,14 +1215,14 @@ func _internal_removeConnectedStarRefBot(account: Account, id: EnginePeer.Id, li
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _internal_getStarRefBotConnection(account: Account, id: EnginePeer.Id, targetId: EnginePeer.Id) -> Signal<TelegramConnectedStarRefBotList.Item?, NoError> {
|
func _internal_getStarRefBotConnection(account: Account, id: EnginePeer.Id, targetId: EnginePeer.Id) -> Signal<EngineConnectedStarRefBotsContext.Item?, NoError> {
|
||||||
return account.postbox.transaction { transaction -> (Api.InputUser?, Api.InputPeer?) in
|
return account.postbox.transaction { transaction -> (Api.InputUser?, Api.InputPeer?) in
|
||||||
return (
|
return (
|
||||||
transaction.getPeer(id).flatMap(apiInputUser),
|
transaction.getPeer(id).flatMap(apiInputUser),
|
||||||
transaction.getPeer(targetId).flatMap(apiInputPeer)
|
transaction.getPeer(targetId).flatMap(apiInputPeer)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|> mapToSignal { inputPeer, targetPeer -> Signal<TelegramConnectedStarRefBotList.Item?, NoError> in
|
|> mapToSignal { inputPeer, targetPeer -> Signal<EngineConnectedStarRefBotsContext.Item?, NoError> in
|
||||||
guard let inputPeer, let targetPeer else {
|
guard let inputPeer, let targetPeer else {
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
}
|
}
|
||||||
@ -981,11 +1231,11 @@ func _internal_getStarRefBotConnection(account: Account, id: EnginePeer.Id, targ
|
|||||||
|> `catch` { _ -> Signal<Api.payments.ConnectedStarRefBots?, NoError> in
|
|> `catch` { _ -> Signal<Api.payments.ConnectedStarRefBots?, NoError> in
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
}
|
}
|
||||||
|> mapToSignal { result -> Signal<TelegramConnectedStarRefBotList.Item?, NoError> in
|
|> mapToSignal { result -> Signal<EngineConnectedStarRefBotsContext.Item?, NoError> in
|
||||||
guard let result else {
|
guard let result else {
|
||||||
return .single(nil)
|
return .single(nil)
|
||||||
}
|
}
|
||||||
return account.postbox.transaction { transaction -> TelegramConnectedStarRefBotList.Item? in
|
return account.postbox.transaction { transaction -> EngineConnectedStarRefBotsContext.Item? in
|
||||||
switch result {
|
switch result {
|
||||||
case let .connectedStarRefBots(_, connectedBots, users):
|
case let .connectedStarRefBots(_, connectedBots, users):
|
||||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(users: users))
|
||||||
@ -1001,7 +1251,7 @@ func _internal_getStarRefBotConnection(account: Account, id: EnginePeer.Id, targ
|
|||||||
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
|
guard let botPeer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(botId))) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return TelegramConnectedStarRefBotList.Item(
|
return EngineConnectedStarRefBotsContext.Item(
|
||||||
peer: EnginePeer(botPeer),
|
peer: EnginePeer(botPeer),
|
||||||
url: url,
|
url: url,
|
||||||
timestamp: date,
|
timestamp: date,
|
||||||
|
@ -1637,23 +1637,19 @@ public extension TelegramEngine {
|
|||||||
return _internal_updateStarRefProgram(account: self.account, id: id, program: program)
|
return _internal_updateStarRefProgram(account: self.account, id: id, program: program)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func requestConnectedStarRefBots(id: EnginePeer.Id, offset: (timestamp: Int32, link: String)?, limit: Int) -> Signal<TelegramConnectedStarRefBotList?, NoError> {
|
public func connectedStarRefBots(id: EnginePeer.Id) -> EngineConnectedStarRefBotsContext {
|
||||||
return _internal_requestConnectedStarRefBots(account: self.account, id: id, offset: offset, limit: limit)
|
return EngineConnectedStarRefBotsContext(account: self.account, peerId: id)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func requestSuggestedStarRefBots(id: EnginePeer.Id, sortMode: TelegramSuggestedStarRefBotList.SortMode, offset: String?, limit: Int) -> Signal<TelegramSuggestedStarRefBotList?, NoError> {
|
public func suggestedStarRefBots(id: EnginePeer.Id, sortMode: EngineSuggestedStarRefBotsContext.SortMode) -> EngineSuggestedStarRefBotsContext {
|
||||||
return _internal_requestSuggestedStarRefBots(account: self.account, id: id, sortMode: sortMode, offset: offset, limit: limit)
|
return EngineSuggestedStarRefBotsContext(account: self.account, peerId: id, sortMode: sortMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func connectStarRefBot(id: EnginePeer.Id, botId: EnginePeer.Id) -> Signal<TelegramConnectedStarRefBotList.Item, ConnectStarRefBotError> {
|
public func connectStarRefBot(id: EnginePeer.Id, botId: EnginePeer.Id) -> Signal<EngineConnectedStarRefBotsContext.Item, ConnectStarRefBotError> {
|
||||||
return _internal_connectStarRefBot(account: self.account, id: id, botId: botId)
|
return _internal_connectStarRefBot(account: self.account, id: id, botId: botId)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func removeConnectedStarRefBot(id: EnginePeer.Id, link: String) -> Signal<Never, ConnectStarRefBotError> {
|
public func getStarRefBotConnection(id: EnginePeer.Id, targetId: EnginePeer.Id) -> Signal<EngineConnectedStarRefBotsContext.Item?, NoError> {
|
||||||
return _internal_removeConnectedStarRefBot(account: self.account, id: id, link: link)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func getStarRefBotConnection(id: EnginePeer.Id, targetId: EnginePeer.Id) -> Signal<TelegramConnectedStarRefBotList.Item?, NoError> {
|
|
||||||
return _internal_getStarRefBotConnection(account: self.account, id: id, targetId: targetId)
|
return _internal_getStarRefBotConnection(account: self.account, id: id, targetId: targetId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,18 +127,23 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
private var durationValue: Int = 0
|
private var durationValue: Int = 0
|
||||||
private var durationMinValue: Int = 0
|
private var durationMinValue: Int = 0
|
||||||
|
|
||||||
|
private var ignoreScrolling: Bool = false
|
||||||
|
|
||||||
private var isApplying: Bool = false
|
private var isApplying: Bool = false
|
||||||
private var applyDisposable: Disposable?
|
private var applyDisposable: Disposable?
|
||||||
|
|
||||||
private var currentProgram: TelegramStarRefProgram?
|
private var currentProgram: TelegramStarRefProgram?
|
||||||
private var programEndTimer: Foundation.Timer?
|
private var programEndTimer: Foundation.Timer?
|
||||||
|
|
||||||
private var connectedStarBotList: TelegramConnectedStarRefBotList?
|
private var connectedStarBots: EngineConnectedStarRefBotsContext?
|
||||||
private var connectedStarBotListDisposable: Disposable?
|
private var connectedStarBotsState: EngineConnectedStarRefBotsContext.State?
|
||||||
|
private var connectedStarBotsStateDisposable: Disposable?
|
||||||
|
private var expectedManualRemoveConnectedBotUrl: String?
|
||||||
|
|
||||||
|
private var suggestedStarBots: EngineSuggestedStarRefBotsContext?
|
||||||
|
private var suggestedStarBotsState: EngineSuggestedStarRefBotsContext.State?
|
||||||
|
private var suggestedStarBotsStateDisposable: Disposable?
|
||||||
|
|
||||||
private var suggestedStarBotList: TelegramSuggestedStarRefBotList?
|
|
||||||
private var suggestedStarBotListDisposable: Disposable?
|
|
||||||
private var suggestedSortMode: TelegramSuggestedStarRefBotList.SortMode = .profitability
|
|
||||||
private var isSuggestedSortModeUpdating: Bool = false
|
private var isSuggestedSortModeUpdating: Bool = false
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
@ -169,8 +174,8 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
deinit {
|
deinit {
|
||||||
self.applyDisposable?.dispose()
|
self.applyDisposable?.dispose()
|
||||||
self.programEndTimer?.invalidate()
|
self.programEndTimer?.invalidate()
|
||||||
self.connectedStarBotListDisposable?.dispose()
|
self.connectedStarBotsStateDisposable?.dispose()
|
||||||
self.suggestedStarBotListDisposable?.dispose()
|
self.suggestedStarBotsStateDisposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
func scrollToTop() {
|
func scrollToTop() {
|
||||||
@ -182,8 +187,10 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||||
|
if !self.ignoreScrolling {
|
||||||
self.updateScrolling(transition: .immediate)
|
self.updateScrolling(transition: .immediate)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func requestApplyProgram() {
|
private func requestApplyProgram() {
|
||||||
guard let component = self.component, let environment = self.environment else {
|
guard let component = self.component, let environment = self.environment else {
|
||||||
@ -353,9 +360,27 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
alphaTransition.setAlpha(view: bottomPanelBackgroundView, alpha: bottomPanelAlpha)
|
alphaTransition.setAlpha(view: bottomPanelBackgroundView, alpha: bottomPanelAlpha)
|
||||||
alphaTransition.setAlpha(layer: self.bottomPanelSeparator, alpha: bottomPanelAlpha)
|
alphaTransition.setAlpha(layer: self.bottomPanelSeparator, alpha: bottomPanelAlpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.scrollView.bounds.maxY >= self.scrollView.contentSize.height - 100.0 {
|
||||||
|
var shouldLoadMoreConnected = false
|
||||||
|
if let connectedStarBotsState = self.connectedStarBotsState, connectedStarBotsState.isLoaded, connectedStarBotsState.nextOffset != nil {
|
||||||
|
shouldLoadMoreConnected = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private func openConnectedBot(bot: TelegramConnectedStarRefBotList.Item) {
|
var shouldLoadMoreSuggested = false
|
||||||
|
if let suggestedStarBotsState = self.suggestedStarBotsState, suggestedStarBotsState.isLoaded, suggestedStarBotsState.nextOffset != nil {
|
||||||
|
shouldLoadMoreSuggested = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if shouldLoadMoreConnected {
|
||||||
|
self.connectedStarBots?.loadMore()
|
||||||
|
} else if shouldLoadMoreSuggested {
|
||||||
|
self.suggestedStarBots?.loadMore()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func openConnectedBot(bot: EngineConnectedStarRefBotsContext.Item) {
|
||||||
guard let component = self.component else {
|
guard let component = self.component else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -393,44 +418,28 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private func leaveProgram(bot: TelegramConnectedStarRefBotList.Item) {
|
private func leaveProgram(bot: EngineConnectedStarRefBotsContext.Item) {
|
||||||
guard let component = self.component else {
|
self.expectedManualRemoveConnectedBotUrl = bot.url
|
||||||
return
|
self.connectedStarBots?.remove(url: bot.url)
|
||||||
}
|
|
||||||
|
|
||||||
let _ = (component.context.engine.peers.removeConnectedStarRefBot(id: component.initialContent.peerId, link: bot.url)
|
|
||||||
|> deliverOnMainQueue).startStandalone(completed: { [weak self] in
|
|
||||||
guard let self else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if let connectedStarBotList = self.connectedStarBotList {
|
|
||||||
var updatedItems = connectedStarBotList.items
|
|
||||||
if let index = updatedItems.firstIndex(where: { $0.peer.id == bot.peer.id }) {
|
|
||||||
updatedItems.remove(at: index)
|
|
||||||
}
|
|
||||||
self.connectedStarBotList = TelegramConnectedStarRefBotList(
|
|
||||||
items: updatedItems,
|
|
||||||
totalCount: connectedStarBotList.totalCount + 1
|
|
||||||
)
|
|
||||||
self.state?.updated(transition: .immediate)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func openSortModeMenu(sourceView: UIView) {
|
private func openSortModeMenu(sourceView: UIView) {
|
||||||
guard let component = self.component, let environment = self.environment, let controller = environment.controller() else {
|
guard let component = self.component, let environment = self.environment, let controller = environment.controller() else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
guard let suggestedStarBots = self.suggestedStarBots else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var items: [ContextMenuItem] = []
|
var items: [ContextMenuItem] = []
|
||||||
|
|
||||||
let availableModes: [(TelegramSuggestedStarRefBotList.SortMode, String)] = [
|
let availableModes: [(EngineSuggestedStarRefBotsContext.SortMode, String)] = [
|
||||||
(.profitability, environment.strings.AffiliateProgram_SortSelectorProfitability),
|
(.profitability, environment.strings.AffiliateProgram_SortSelectorProfitability),
|
||||||
(.revenue, environment.strings.AffiliateProgram_SortSelectorRevenue),
|
(.revenue, environment.strings.AffiliateProgram_SortSelectorRevenue),
|
||||||
(.date, environment.strings.AffiliateProgram_SortSelectorDate)
|
(.date, environment.strings.AffiliateProgram_SortSelectorDate)
|
||||||
]
|
]
|
||||||
for (mode, title) in availableModes {
|
for (mode, title) in availableModes {
|
||||||
let isSelected = mode == self.suggestedSortMode
|
let isSelected = mode == suggestedStarBots.sortMode
|
||||||
items.append(.action(ContextMenuActionItem(text: title, icon: { theme in
|
items.append(.action(ContextMenuActionItem(text: title, icon: { theme in
|
||||||
if isSelected {
|
if isSelected {
|
||||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Check"), color: theme.actionSheet.primaryTextColor)
|
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Check"), color: theme.actionSheet.primaryTextColor)
|
||||||
@ -443,23 +452,20 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if self.suggestedSortMode != mode {
|
if self.suggestedStarBots?.sortMode != mode {
|
||||||
self.suggestedSortMode = mode
|
|
||||||
self.isSuggestedSortModeUpdating = true
|
self.isSuggestedSortModeUpdating = true
|
||||||
self.state?.updated(transition: .immediate)
|
self.state?.updated(transition: .immediate)
|
||||||
|
|
||||||
self.suggestedStarBotListDisposable?.dispose()
|
let suggestedStarBots = component.context.engine.peers.suggestedStarRefBots(id: component.initialContent.peerId, sortMode: mode)
|
||||||
self.suggestedStarBotListDisposable = (component.context.engine.peers.requestSuggestedStarRefBots(
|
self.suggestedStarBots = suggestedStarBots
|
||||||
id: component.initialContent.peerId,
|
self.suggestedStarBotsStateDisposable?.dispose()
|
||||||
sortMode: self.suggestedSortMode,
|
self.suggestedStarBotsStateDisposable = (suggestedStarBots.state
|
||||||
offset: nil,
|
|> deliverOnMainQueue).startStrict(next: { [weak self] state in
|
||||||
limit: 100)
|
|
||||||
|> deliverOnMainQueue).startStrict(next: { [weak self] list in
|
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.suggestedStarBotList = list
|
|
||||||
self.isSuggestedSortModeUpdating = false
|
self.isSuggestedSortModeUpdating = false
|
||||||
|
self.suggestedStarBotsState = state
|
||||||
self.state?.updated(transition: .immediate)
|
self.state?.updated(transition: .immediate)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -491,6 +497,11 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
self.isUpdating = false
|
self.isUpdating = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var transition = transition
|
||||||
|
if !self.scrollView.isDecelerating && !self.scrollView.isDragging {
|
||||||
|
transition = transition.withUserData(PeerBadgeAvatarComponent.SynchronousLoadHint())
|
||||||
|
}
|
||||||
|
|
||||||
let durationItems: [Int32] = [
|
let durationItems: [Int32] = [
|
||||||
1,
|
1,
|
||||||
3,
|
3,
|
||||||
@ -576,28 +587,35 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
self.durationMinValue = 0
|
self.durationMinValue = 0
|
||||||
}
|
}
|
||||||
case .connectedPrograms:
|
case .connectedPrograms:
|
||||||
self.connectedStarBotListDisposable = (component.context.engine.peers.requestConnectedStarRefBots(
|
let connectedStarBots = component.context.engine.peers.connectedStarRefBots(id: component.initialContent.peerId)
|
||||||
id: component.initialContent.peerId,
|
self.connectedStarBots = connectedStarBots
|
||||||
offset: nil,
|
self.connectedStarBotsStateDisposable = (connectedStarBots.state
|
||||||
limit: 100)
|
|> deliverOnMainQueue).startStrict(next: { [weak self] state in
|
||||||
|> deliverOnMainQueue).startStrict(next: { [weak self] list in
|
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.connectedStarBotList = list
|
var transition: ComponentTransition = .immediate
|
||||||
self.state?.updated(transition: .immediate)
|
if let expectedManualRemoveConnectedBotUrl = self.expectedManualRemoveConnectedBotUrl {
|
||||||
|
self.expectedManualRemoveConnectedBotUrl = nil
|
||||||
|
|
||||||
|
if let currentState = self.connectedStarBotsState {
|
||||||
|
if currentState.items.count == state.items.count + 1 && currentState.items.contains(where: { $0.url == expectedManualRemoveConnectedBotUrl }) && !state.items.contains(where: { $0.url == expectedManualRemoveConnectedBotUrl }) {
|
||||||
|
transition = .easeInOut(duration: 0.25)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.connectedStarBotsState = state
|
||||||
|
self.state?.updated(transition: transition)
|
||||||
})
|
})
|
||||||
|
|
||||||
self.suggestedStarBotListDisposable = (component.context.engine.peers.requestSuggestedStarRefBots(
|
let suggestedStarBots = component.context.engine.peers.suggestedStarRefBots(id: component.initialContent.peerId, sortMode: .profitability)
|
||||||
id: component.initialContent.peerId,
|
self.suggestedStarBots = suggestedStarBots
|
||||||
sortMode: self.suggestedSortMode,
|
self.suggestedStarBotsStateDisposable = (suggestedStarBots.state
|
||||||
offset: nil,
|
|> deliverOnMainQueue).startStrict(next: { [weak self] state in
|
||||||
limit: 100)
|
|
||||||
|> deliverOnMainQueue).startStrict(next: { [weak self] list in
|
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.suggestedStarBotList = list
|
self.suggestedStarBotsState = state
|
||||||
self.state?.updated(transition: .immediate)
|
self.state?.updated(transition: .immediate)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1187,12 +1205,12 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
|
|
||||||
contentHeight += bottomPanelFrame.height
|
contentHeight += bottomPanelFrame.height
|
||||||
case .connectedPrograms:
|
case .connectedPrograms:
|
||||||
if let connectedStarBotList = self.connectedStarBotList, let suggestedStarBotList = self.suggestedStarBotList {
|
if let connectedStarBotsState = self.connectedStarBotsState, connectedStarBotsState.isLoaded, let suggestedStarBots = self.suggestedStarBots, let suggestedStarBotsState = self.suggestedStarBotsState, suggestedStarBotsState.isLoaded {
|
||||||
let suggestedStarBotListItems = suggestedStarBotList.items.filter({ item in !connectedStarBotList.items.contains(where: { $0.peer.id == item.peer.id }) })
|
let suggestedStarBotListItems = suggestedStarBotsState.items.filter({ item in !connectedStarBotsState.items.contains(where: { $0.peer.id == item.peer.id }) })
|
||||||
|
|
||||||
do {
|
do {
|
||||||
var activeSectionItems: [AnyComponentWithIdentity<Empty>] = []
|
var activeSectionItems: [AnyComponentWithIdentity<Empty>] = []
|
||||||
for item in connectedStarBotList.items {
|
for item in connectedStarBotsState.items {
|
||||||
let durationTitle: String
|
let durationTitle: String
|
||||||
if let durationMonths = item.durationMonths {
|
if let durationMonths = item.durationMonths {
|
||||||
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (30 * 24 * 60 * 60))
|
durationTitle = timeIntervalString(strings: environment.strings, value: durationMonths * (30 * 24 * 60 * 60))
|
||||||
@ -1362,13 +1380,9 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
self.scrollView.addSubview(activeProgramsSectionView)
|
self.scrollView.addSubview(activeProgramsSectionView)
|
||||||
}
|
}
|
||||||
transition.setFrame(view: activeProgramsSectionView, frame: activeProgramsSectionFrame)
|
transition.setFrame(view: activeProgramsSectionView, frame: activeProgramsSectionFrame)
|
||||||
if let connectedStarBotList = self.connectedStarBotList, !connectedStarBotList.items.isEmpty {
|
transition.setAlpha(view: activeProgramsSectionView, alpha: connectedStarBotsState.items.isEmpty ? 0.0 : 1.0)
|
||||||
activeProgramsSectionView.isHidden = false
|
|
||||||
} else {
|
|
||||||
activeProgramsSectionView.isHidden = true
|
|
||||||
}
|
}
|
||||||
}
|
if !connectedStarBotsState.items.isEmpty {
|
||||||
if let connectedStarBotList = self.connectedStarBotList, !connectedStarBotList.items.isEmpty {
|
|
||||||
contentHeight += activeProgramsSectionSize.height
|
contentHeight += activeProgramsSectionSize.height
|
||||||
contentHeight += sectionSpacing
|
contentHeight += sectionSpacing
|
||||||
}
|
}
|
||||||
@ -1454,24 +1468,13 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
guard let self, let component = self.component else {
|
guard let self, let component = self.component else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = (component.context.engine.peers.connectStarRefBot(id: component.initialContent.peerId, botId: peer.id)
|
let _ = (component.context.engine.peers.connectStarRefBot(id: component.initialContent.peerId, botId: peer.id)
|
||||||
|> deliverOnMainQueue).startStandalone(next: { [weak self] result in
|
|> deliverOnMainQueue).startStandalone(next: { [weak self] result in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let connectedStarBotList = self.connectedStarBotList {
|
|
||||||
var updatedItems = connectedStarBotList.items
|
|
||||||
if !updatedItems.contains(where: { $0.peer.id == peer.id }) {
|
|
||||||
updatedItems.insert(result, at: 0)
|
|
||||||
}
|
|
||||||
self.connectedStarBotList = TelegramConnectedStarRefBotList(
|
|
||||||
items: updatedItems,
|
|
||||||
totalCount: connectedStarBotList.totalCount + 1
|
|
||||||
)
|
|
||||||
self.state?.updated(transition: .immediate)
|
|
||||||
|
|
||||||
self.openConnectedBot(bot: result)
|
self.openConnectedBot(bot: result)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
@ -1496,7 +1499,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
suggestedHeaderItems.append(AnyComponentWithIdentity(id: 1, component: AnyComponent(BotSectionSortButtonComponent(
|
suggestedHeaderItems.append(AnyComponentWithIdentity(id: 1, component: AnyComponent(BotSectionSortButtonComponent(
|
||||||
theme: environment.theme,
|
theme: environment.theme,
|
||||||
strings: environment.strings,
|
strings: environment.strings,
|
||||||
sortMode: self.suggestedSortMode,
|
sortMode: suggestedStarBots.sortMode,
|
||||||
action: { [weak self] sourceView in
|
action: { [weak self] sourceView in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
@ -1526,15 +1529,20 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
}
|
}
|
||||||
transition.setFrame(view: suggestedProgramsSectionView, frame: suggestedProgramsSectionFrame)
|
transition.setFrame(view: suggestedProgramsSectionView, frame: suggestedProgramsSectionFrame)
|
||||||
|
|
||||||
|
suggestedProgramsSectionView.isHidden = connectedStarBotsState.nextOffset != nil
|
||||||
|
|
||||||
suggestedProgramsSectionView.contentViewImpl.alpha = self.isSuggestedSortModeUpdating ? 0.6 : 1.0
|
suggestedProgramsSectionView.contentViewImpl.alpha = self.isSuggestedSortModeUpdating ? 0.6 : 1.0
|
||||||
suggestedProgramsSectionView.contentViewImpl.isUserInteractionEnabled = !self.isSuggestedSortModeUpdating
|
suggestedProgramsSectionView.contentViewImpl.isUserInteractionEnabled = !self.isSuggestedSortModeUpdating
|
||||||
}
|
}
|
||||||
|
if connectedStarBotsState.nextOffset == nil {
|
||||||
contentHeight += suggestedProgramsSectionSize.height
|
contentHeight += suggestedProgramsSectionSize.height
|
||||||
contentHeight += sectionSpacing
|
contentHeight += sectionSpacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.ignoreScrolling = true
|
||||||
let contentSize = CGSize(width: availableSize.width, height: contentHeight)
|
let contentSize = CGSize(width: availableSize.width, height: contentHeight)
|
||||||
if self.scrollView.frame != CGRect(origin: CGPoint(), size: availableSize) {
|
if self.scrollView.frame != CGRect(origin: CGPoint(), size: availableSize) {
|
||||||
self.scrollView.frame = CGRect(origin: CGPoint(), size: availableSize)
|
self.scrollView.frame = CGRect(origin: CGPoint(), size: availableSize)
|
||||||
@ -1546,6 +1554,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
|
|||||||
if self.scrollView.scrollIndicatorInsets != scrollInsets {
|
if self.scrollView.scrollIndicatorInsets != scrollInsets {
|
||||||
self.scrollView.scrollIndicatorInsets = scrollInsets
|
self.scrollView.scrollIndicatorInsets = scrollInsets
|
||||||
}
|
}
|
||||||
|
self.ignoreScrolling = false
|
||||||
|
|
||||||
self.updateScrolling(transition: transition)
|
self.updateScrolling(transition: transition)
|
||||||
|
|
||||||
|
@ -1863,13 +1863,13 @@ final class AffiliatePeerSubtitleComponent: Component {
|
|||||||
final class BotSectionSortButtonComponent: Component {
|
final class BotSectionSortButtonComponent: Component {
|
||||||
let theme: PresentationTheme
|
let theme: PresentationTheme
|
||||||
let strings: PresentationStrings
|
let strings: PresentationStrings
|
||||||
let sortMode: TelegramSuggestedStarRefBotList.SortMode
|
let sortMode: EngineSuggestedStarRefBotsContext.SortMode
|
||||||
let action: (UIView) -> Void
|
let action: (UIView) -> Void
|
||||||
|
|
||||||
init(
|
init(
|
||||||
theme: PresentationTheme,
|
theme: PresentationTheme,
|
||||||
strings: PresentationStrings,
|
strings: PresentationStrings,
|
||||||
sortMode: TelegramSuggestedStarRefBotList.SortMode,
|
sortMode: EngineSuggestedStarRefBotsContext.SortMode,
|
||||||
action: @escaping (UIView) -> Void
|
action: @escaping (UIView) -> Void
|
||||||
) {
|
) {
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
@ -1990,6 +1990,9 @@ final class BotSectionSortButtonComponent: Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final class PeerBadgeAvatarComponent: Component {
|
final class PeerBadgeAvatarComponent: Component {
|
||||||
|
final class SynchronousLoadHint {
|
||||||
|
}
|
||||||
|
|
||||||
let context: AccountContext
|
let context: AccountContext
|
||||||
let peer: EnginePeer
|
let peer: EnginePeer
|
||||||
let theme: PresentationTheme
|
let theme: PresentationTheme
|
||||||
@ -2042,6 +2045,11 @@ final class PeerBadgeAvatarComponent: Component {
|
|||||||
self.component = component
|
self.component = component
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
|
var synchronousLoad = false
|
||||||
|
if transition.userData(SynchronousLoadHint.self) != nil {
|
||||||
|
synchronousLoad = true
|
||||||
|
}
|
||||||
|
|
||||||
let size = CGSize(width: 40.0, height: 40.0)
|
let size = CGSize(width: 40.0, height: 40.0)
|
||||||
let badgeSize: CGFloat = 18.0
|
let badgeSize: CGFloat = 18.0
|
||||||
|
|
||||||
@ -2062,7 +2070,7 @@ final class PeerBadgeAvatarComponent: Component {
|
|||||||
context: component.context,
|
context: component.context,
|
||||||
theme: component.context.sharedContext.currentPresentationData.with({ $0 }).theme,
|
theme: component.context.sharedContext.currentPresentationData.with({ $0 }).theme,
|
||||||
peer: component.peer,
|
peer: component.peer,
|
||||||
synchronousLoad: false,
|
synchronousLoad: synchronousLoad,
|
||||||
displayDimensions: size,
|
displayDimensions: size,
|
||||||
cutoutRect: component.hasBadge ? badgeFrame.insetBy(dx: -(1.0 + UIScreenPixel), dy: -(1.0 + UIScreenPixel)) : nil
|
cutoutRect: component.hasBadge ? badgeFrame.insetBy(dx: -(1.0 + UIScreenPixel), dy: -(1.0 + UIScreenPixel)) : nil
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user