mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-15 18:59:54 +00:00
Merge branch 'local-temp'
This commit is contained in:
commit
da4f5a67bb
@ -1638,7 +1638,10 @@ public final class ChatListNode: ListView {
|
||||
} else {
|
||||
self.push?(NewSessionInfoScreen(context: self.context, newSessionReview: newSessionReview))
|
||||
|
||||
//#if DEBUG
|
||||
//#else
|
||||
let _ = self.context.engine.privacy.terminateAnotherSession(id: newSessionReview.id).start()
|
||||
//#endif
|
||||
}
|
||||
}, openChatFolderUpdates: { [weak self] in
|
||||
guard let self else {
|
||||
|
||||
@ -143,6 +143,10 @@ public final class NavigationBackgroundNode: ASDisplayNode {
|
||||
|
||||
public var effectView: UIVisualEffectView?
|
||||
private let backgroundNode: ASDisplayNode
|
||||
|
||||
public var backgroundView: UIView {
|
||||
return self.backgroundNode.view
|
||||
}
|
||||
|
||||
private var validLayout: (CGSize, CGFloat)?
|
||||
|
||||
|
||||
@ -757,6 +757,10 @@ public extension CALayer {
|
||||
static func blur() -> NSObject? {
|
||||
return makeBlurFilter()
|
||||
}
|
||||
|
||||
static func luminanceToAlpha() -> NSObject? {
|
||||
return makeLuminanceToAlphaFilter()
|
||||
}
|
||||
}
|
||||
|
||||
public extension CALayer {
|
||||
|
||||
@ -151,6 +151,7 @@ final class ReactionContextBackgroundNode: ASDisplayNode {
|
||||
}
|
||||
|
||||
self.backgroundView.updateColor(color: theme.contextMenu.backgroundColor, transition: .immediate)
|
||||
//self.backgroundView.updateColor(color: UIColor(white: 1.0, alpha: 0.0), forceKeepBlur: true, transition: .immediate)
|
||||
|
||||
let shadowColor = UIColor(white: 0.0, alpha: 0.4)
|
||||
|
||||
|
||||
117
submodules/TelegramCore/Sources/State/ChannelBoost.swift
Normal file
117
submodules/TelegramCore/Sources/State/ChannelBoost.swift
Normal file
@ -0,0 +1,117 @@
|
||||
import Foundation
|
||||
import TelegramApi
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
|
||||
public final class ChannelBoostStatus: Equatable {
|
||||
public let level: Int
|
||||
public let boosts: Int
|
||||
public let nextLevelBoosts: Int?
|
||||
|
||||
public init(level: Int, boosts: Int, nextLevelBoosts: Int?) {
|
||||
self.level = level
|
||||
self.boosts = boosts
|
||||
self.nextLevelBoosts = nextLevelBoosts
|
||||
}
|
||||
|
||||
public static func ==(lhs: ChannelBoostStatus, rhs: ChannelBoostStatus) -> Bool {
|
||||
if lhs.level != rhs.level {
|
||||
return false
|
||||
}
|
||||
if lhs.boosts != rhs.boosts {
|
||||
return false
|
||||
}
|
||||
if lhs.nextLevelBoosts != rhs.nextLevelBoosts {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func _internal_getChannelBoostStatus(account: Account, peerId: PeerId) -> Signal<ChannelBoostStatus?, NoError> {
|
||||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||
return transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
|> mapToSignal { inputPeer -> Signal<ChannelBoostStatus?, NoError> in
|
||||
guard let inputPeer = inputPeer else {
|
||||
return .single(nil)
|
||||
}
|
||||
return account.network.request(Api.functions.stories.getBoostsStatus(peer: inputPeer))
|
||||
|> map(Optional.init)
|
||||
|> `catch` { _ -> Signal<Api.stories.BoostsStatus?, NoError> in
|
||||
return .single(nil)
|
||||
}
|
||||
|> map { result -> ChannelBoostStatus? in
|
||||
guard let result = result else {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch result {
|
||||
case let .boostsStatus(_, level, boosts, nextLevelBoosts):
|
||||
return ChannelBoostStatus(level: Int(level), boosts: Int(boosts), nextLevelBoosts: nextLevelBoosts.flatMap(Int.init))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum CanApplyBoostStatus {
|
||||
public enum ErrorReason {
|
||||
case generic
|
||||
case premiumRequired
|
||||
case floodWait
|
||||
case peerBoostAlreadyActive
|
||||
}
|
||||
|
||||
case ok
|
||||
case replace(currentBoost: EnginePeer)
|
||||
case error(ErrorReason)
|
||||
}
|
||||
|
||||
func _internal_canApplyChannelBoost(account: Account, peerId: PeerId) -> Signal<CanApplyBoostStatus?, NoError> {
|
||||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||
return transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
|> mapToSignal { inputPeer -> Signal<CanApplyBoostStatus?, NoError> in
|
||||
guard let inputPeer = inputPeer else {
|
||||
return .single(nil)
|
||||
}
|
||||
return account.network.request(Api.functions.stories.canApplyBoost(peer: inputPeer), automaticFloodWait: false)
|
||||
|> map { result -> (Api.stories.CanApplyBoostResult?, CanApplyBoostStatus.ErrorReason?) in
|
||||
return (result, nil)
|
||||
}
|
||||
|> `catch` { error -> Signal<(Api.stories.CanApplyBoostResult?, CanApplyBoostStatus.ErrorReason?), NoError> in
|
||||
let reason: CanApplyBoostStatus.ErrorReason
|
||||
if error.errorDescription == "PREMIUM_ACCOUNT_REQUIRED" {
|
||||
reason = .premiumRequired
|
||||
} else if error.errorDescription.hasPrefix("FLOOD_WAIT_") {
|
||||
reason = .floodWait
|
||||
} else if error.errorDescription == "SAME_BOOST_ALREADY_ACTIVE" {
|
||||
reason = .peerBoostAlreadyActive
|
||||
} else {
|
||||
reason = .generic
|
||||
}
|
||||
|
||||
return .single((nil, reason))
|
||||
}
|
||||
|> mapToSignal { result, errorReason -> Signal<CanApplyBoostStatus?, NoError> in
|
||||
guard let result = result else {
|
||||
return .single(.error(errorReason ?? .generic))
|
||||
}
|
||||
|
||||
return account.postbox.transaction { transaction -> CanApplyBoostStatus? in
|
||||
switch result {
|
||||
case .canApplyBoostOk:
|
||||
return .ok
|
||||
case let .canApplyBoostReplace(currentBoost, chats):
|
||||
updatePeers(transaction: transaction, accountPeerId: account.peerId, peers: AccumulatedPeers(transaction: transaction, chats: chats, users: []))
|
||||
|
||||
if let peer = transaction.getPeer(currentBoost.peerId) {
|
||||
return .replace(currentBoost: EnginePeer(peer))
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1279,28 +1279,45 @@ public enum StoriesUploadAvailability {
|
||||
case expiringLimit
|
||||
case premiumRequired
|
||||
case unknownLimit
|
||||
case channelBoostRequired
|
||||
}
|
||||
|
||||
func _internal_checkStoriesUploadAvailability(account: Account) -> Signal<StoriesUploadAvailability, NoError> {
|
||||
return account.network.request(Api.functions.stories.canSendStory(peer: .inputPeerSelf))
|
||||
|> map { result -> StoriesUploadAvailability in
|
||||
if result == .boolTrue {
|
||||
return .available
|
||||
} else {
|
||||
return .unknownLimit
|
||||
func _internal_checkStoriesUploadAvailability(account: Account, target: Stories.PendingTarget) -> Signal<StoriesUploadAvailability, NoError> {
|
||||
return account.postbox.transaction { transaction -> Api.InputPeer? in
|
||||
switch target {
|
||||
case .myStories:
|
||||
return .inputPeerSelf
|
||||
case let .peer(peerId):
|
||||
return transaction.getPeer(peerId).flatMap(apiInputPeer)
|
||||
}
|
||||
}
|
||||
|> `catch` { error -> Signal<StoriesUploadAvailability, NoError> in
|
||||
if error.errorDescription.hasPrefix("STORY_SEND_FLOOD_WEEKLY_") {
|
||||
return .single(.weeklyLimit)
|
||||
} else if error.errorDescription.hasPrefix("STORY_SEND_FLOOD_MONTHLY_") {
|
||||
return .single(.monthlyLimit)
|
||||
} else if error.errorDescription.hasPrefix("PREMIUM_ACCOUNT_REQUIRED") {
|
||||
return .single(.premiumRequired)
|
||||
} else if error.errorDescription.hasPrefix("STORIES_TOO_MUCH") {
|
||||
return .single(.expiringLimit)
|
||||
|> mapToSignal { inputPeer -> Signal<StoriesUploadAvailability, NoError> in
|
||||
guard let inputPeer = inputPeer else {
|
||||
return .single(.unknownLimit)
|
||||
}
|
||||
|
||||
return account.network.request(Api.functions.stories.canSendStory(peer: inputPeer))
|
||||
|> map { result -> StoriesUploadAvailability in
|
||||
if result == .boolTrue {
|
||||
return .available
|
||||
} else {
|
||||
return .unknownLimit
|
||||
}
|
||||
}
|
||||
|> `catch` { error -> Signal<StoriesUploadAvailability, NoError> in
|
||||
if error.errorDescription.hasPrefix("STORY_SEND_FLOOD_WEEKLY_") {
|
||||
return .single(.weeklyLimit)
|
||||
} else if error.errorDescription.hasPrefix("STORY_SEND_FLOOD_MONTHLY_") {
|
||||
return .single(.monthlyLimit)
|
||||
} else if error.errorDescription.hasPrefix("PREMIUM_ACCOUNT_REQUIRED") {
|
||||
return .single(.premiumRequired)
|
||||
} else if error.errorDescription.hasPrefix("STORIES_TOO_MUCH") {
|
||||
return .single(.expiringLimit)
|
||||
} else if error.errorDescription.hasPrefix("BOOSTS_REQUIRED") {
|
||||
return .single(.channelBoostRequired)
|
||||
}
|
||||
return .single(.unknownLimit)
|
||||
}
|
||||
return .single(.unknownLimit)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1213,8 +1213,8 @@ public extension TelegramEngine {
|
||||
return _internal_editStoryPrivacy(account: self.account, id: id, privacy: privacy)
|
||||
}
|
||||
|
||||
public func checkStoriesUploadAvailability() -> Signal<StoriesUploadAvailability, NoError> {
|
||||
return _internal_checkStoriesUploadAvailability(account: self.account)
|
||||
public func checkStoriesUploadAvailability(target: Stories.PendingTarget) -> Signal<StoriesUploadAvailability, NoError> {
|
||||
return _internal_checkStoriesUploadAvailability(account: self.account, target: target)
|
||||
}
|
||||
|
||||
public func deleteStories(peerId: EnginePeer.Id, ids: [Int32]) -> Signal<Never, NoError> {
|
||||
|
||||
@ -1188,6 +1188,14 @@ public extension TelegramEngine {
|
||||
public func updatePeerStoriesHidden(id: PeerId, isHidden: Bool) {
|
||||
let _ = _internal_updatePeerStoriesHidden(account: self.account, id: id, isHidden: isHidden).start()
|
||||
}
|
||||
|
||||
public func getChannelBoostStatus(peerId: EnginePeer.Id) -> Signal<ChannelBoostStatus?, NoError> {
|
||||
return _internal_getChannelBoostStatus(account: self.account, peerId: peerId)
|
||||
}
|
||||
|
||||
public func canApplyChannelBoost(peerId: EnginePeer.Id) -> Signal<CanApplyBoostStatus?, NoError> {
|
||||
return _internal_canApplyChannelBoost(account: self.account, peerId: peerId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2410,7 +2410,7 @@ public class CameraScreen: ViewController {
|
||||
|
||||
self.requestAudioSession()
|
||||
|
||||
self.postingAvailabilityPromise.set(self.context.engine.messages.checkStoriesUploadAvailability())
|
||||
self.postingAvailabilityPromise.set(self.context.engine.messages.checkStoriesUploadAvailability(target: .myStories))
|
||||
}
|
||||
|
||||
required public init(coder: NSCoder) {
|
||||
|
||||
@ -26,3 +26,4 @@ void applySmoothRoundedCornersImpl(CALayer * _Nonnull layer);
|
||||
UIView<UIKitPortalViewProtocol> * _Nullable makePortalView(bool matchPosition);
|
||||
|
||||
NSObject * _Nullable makeBlurFilter();
|
||||
NSObject * _Nullable makeLuminanceToAlphaFilter();
|
||||
|
||||
@ -210,3 +210,7 @@ UIView<UIKitPortalViewProtocol> * _Nullable makePortalView(bool matchPosition) {
|
||||
NSObject * _Nullable makeBlurFilter() {
|
||||
return [(id<GraphicsFilterProtocol>)NSClassFromString(@"CAFilter") filterWithName:@"gaussianBlur"];
|
||||
}
|
||||
|
||||
NSObject * _Nullable makeLuminanceToAlphaFilter() {
|
||||
return [(id<GraphicsFilterProtocol>)NSClassFromString(@"CAFilter") filterWithName:@"luminanceToAlpha"];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user