mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Stars subscriptions
This commit is contained in:
@@ -956,10 +956,6 @@ private final class StarsSubscriptionsContextImpl {
|
||||
updatedState.isLoading = false
|
||||
updatedState.canLoadMore = self.nextOffset != nil
|
||||
self.updateState(updatedState)
|
||||
|
||||
if updatedState.canLoadMore {
|
||||
self.loadMore()
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -967,6 +963,22 @@ private final class StarsSubscriptionsContextImpl {
|
||||
self._state = state
|
||||
self._statePromise.set(.single(state))
|
||||
}
|
||||
|
||||
func updateSubscription(id: String, cancel: Bool) {
|
||||
var updatedState = self._state
|
||||
if let index = updatedState.subscriptions.firstIndex(where: { $0.id == id }) {
|
||||
let subscription = updatedState.subscriptions[index]
|
||||
var updatedFlags = subscription.flags
|
||||
if cancel {
|
||||
updatedFlags.insert(.isCancelled)
|
||||
} else {
|
||||
updatedFlags.remove(.isCancelled)
|
||||
}
|
||||
let updatedSubscription = StarsContext.State.Subscription(flags: updatedFlags, id: subscription.id, peer: subscription.peer, untilDate: subscription.untilDate, pricing: subscription.pricing)
|
||||
updatedState.subscriptions[index] = updatedSubscription
|
||||
}
|
||||
self.updateState(updatedState)
|
||||
}
|
||||
}
|
||||
|
||||
public final class StarsSubscriptionsContext {
|
||||
@@ -1007,6 +1019,12 @@ public final class StarsSubscriptionsContext {
|
||||
return StarsSubscriptionsContextImpl(account: account, starsContext: starsContext)
|
||||
})
|
||||
}
|
||||
|
||||
public func updateSubscription(id: String, cancel: Bool) {
|
||||
self.impl.with {
|
||||
$0.updateSubscription(id: id, cancel: cancel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1203,7 +1221,7 @@ func _internal_updateStarsSubscription(account: Account, peerId: EnginePeer.Id,
|
||||
return .complete()
|
||||
}
|
||||
let flags: Int32 = (1 << 0)
|
||||
return account.network.request(Api.functions.payments.changeStarsSubscription(flags: flags, peer: inputPeer, subscriptionId: subscriptionId, canceled: .boolTrue))
|
||||
return account.network.request(Api.functions.payments.changeStarsSubscription(flags: flags, peer: inputPeer, subscriptionId: subscriptionId, canceled: cancel ? .boolTrue : .boolFalse))
|
||||
|> mapError { _ -> UpdateStarsSubsciptionError in
|
||||
return .generic
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user