mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-15 21:45:19 +00:00
Various fixes
This commit is contained in:
parent
9b062fd5b8
commit
999f8c8032
@ -179,7 +179,6 @@ public enum BotPaymentFormRequestError {
|
||||
case alreadyActive
|
||||
case noPaymentNeeded
|
||||
case disallowedStarGift
|
||||
case starGiftResellTooEarly(Int32)
|
||||
}
|
||||
|
||||
extension BotPaymentInvoice {
|
||||
@ -483,11 +482,6 @@ func _internal_fetchBotPaymentForm(accountPeerId: PeerId, postbox: Postbox, netw
|
||||
return .fail(.noPaymentNeeded)
|
||||
} else if error.errorDescription == "USER_DISALLOWED_STARGIFTS" {
|
||||
return .fail(.disallowedStarGift)
|
||||
} else if error.errorDescription.hasPrefix("STARGIFT_RESELL_TOO_EARLY_") {
|
||||
let timeout = String(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "STARGIFT_RESELL_TOO_EARLY_".count)...])
|
||||
if let value = Int32(timeout) {
|
||||
return .fail(.starGiftResellTooEarly(value))
|
||||
}
|
||||
}
|
||||
return .fail(.generic)
|
||||
}
|
||||
|
@ -847,14 +847,13 @@ public enum TransferStarGiftError {
|
||||
|
||||
public enum BuyStarGiftError {
|
||||
case generic
|
||||
case starGiftResellTooEarly(Int32)
|
||||
}
|
||||
|
||||
public enum UpdateStarGiftPriceError {
|
||||
case generic
|
||||
case starGiftResellTooEarly(Int32)
|
||||
}
|
||||
|
||||
|
||||
public enum UpgradeStarGiftError {
|
||||
case generic
|
||||
}
|
||||
@ -864,12 +863,7 @@ func _internal_buyStarGift(account: Account, slug: String, peerId: EnginePeer.Id
|
||||
return _internal_fetchBotPaymentForm(accountPeerId: account.peerId, postbox: account.postbox, network: account.network, source: source, themeParams: nil)
|
||||
|> map(Optional.init)
|
||||
|> `catch` { error -> Signal<BotPaymentForm?, BuyStarGiftError> in
|
||||
switch error {
|
||||
case let .starGiftResellTooEarly(value):
|
||||
return .fail(.starGiftResellTooEarly(value))
|
||||
default:
|
||||
return .fail(.generic)
|
||||
}
|
||||
return .fail(.generic)
|
||||
}
|
||||
|> mapToSignal { paymentForm in
|
||||
if let paymentForm {
|
||||
@ -2325,6 +2319,12 @@ func _internal_updateStarGiftResalePrice(account: Account, reference: StarGiftRe
|
||||
}
|
||||
return account.network.request(Api.functions.payments.updateStarGiftPrice(stargift: starGift, resellStars: price ?? 0))
|
||||
|> mapError { error -> UpdateStarGiftPriceError in
|
||||
if error.errorDescription.hasPrefix("STARGIFT_RESELL_TOO_EARLY_") {
|
||||
let timeout = String(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "STARGIFT_RESELL_TOO_EARLY_".count)...])
|
||||
if let value = Int32(timeout) {
|
||||
return .starGiftResellTooEarly(value)
|
||||
}
|
||||
}
|
||||
return .generic
|
||||
}
|
||||
|> mapToSignal { updates -> Signal<Void, UpdateStarGiftPriceError> in
|
||||
|
@ -8155,7 +8155,9 @@ public final class MediaEditorScreenImpl: ViewController, MediaEditorScreen, UID
|
||||
let trimmedValues = values.withUpdatedVideoTrimRange(start ..< min(start + storyMaxVideoDuration, originalDuration))
|
||||
|
||||
var editingItem = EditingItem(asset: asset)
|
||||
editingItem.caption = self.node.getCaption()
|
||||
if i == 0 {
|
||||
editingItem.caption = self.node.getCaption()
|
||||
}
|
||||
editingItem.values = trimmedValues
|
||||
multipleItems.append(editingItem)
|
||||
|
||||
|
@ -2007,7 +2007,7 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
|
||||
return result
|
||||
}
|
||||
|
||||
private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatLocation: ChatLocation, context: AccountContext, presentationData: PresentationData, interaction: PeerInfoInteraction) -> [(AnyHashable, [PeerInfoScreenItem])] {
|
||||
private func editingItems(data: PeerInfoScreenData?, boostStatus: ChannelBoostStatus?, state: PeerInfoState, chatLocation: ChatLocation, context: AccountContext, presentationData: PresentationData, interaction: PeerInfoInteraction) -> [(AnyHashable, [PeerInfoScreenItem])] {
|
||||
enum Section: Int, CaseIterable {
|
||||
case notifications
|
||||
case groupLocation
|
||||
@ -2276,11 +2276,12 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL
|
||||
interaction.editingOpenNameColorSetup()
|
||||
}))
|
||||
|
||||
let premiumConfiguration = PremiumConfiguration.with(appConfiguration: context.currentAppConfiguration.with { $0 })
|
||||
var isLocked = true
|
||||
if let approximateBoostLevel = channel.approximateBoostLevel, approximateBoostLevel >= 3 {
|
||||
if let boostLevel = boostStatus?.level, boostLevel >= BoostSubject.autoTranslate.requiredLevel(group: false, context: context, configuration: premiumConfiguration) {
|
||||
isLocked = false
|
||||
}
|
||||
items[.peerSettings]!.append(PeerInfoScreenSwitchItem(id: ItemPeerAutoTranslate, text: presentationData.strings.Channel_Info_AutoTranslate, value: false, icon: UIImage(bundleImageName: "Settings/Menu/AutoTranslate"), isLocked: isLocked, toggled: { value in
|
||||
items[.peerSettings]!.append(PeerInfoScreenSwitchItem(id: ItemPeerAutoTranslate, text: presentationData.strings.Channel_Info_AutoTranslate, value: channel.flags.contains(.autoTranslateEnabled), icon: UIImage(bundleImageName: "Settings/Menu/AutoTranslate"), isLocked: isLocked, toggled: { value in
|
||||
if isLocked {
|
||||
interaction.displayAutoTranslateLocked()
|
||||
} else {
|
||||
@ -9157,7 +9158,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
}
|
||||
|
||||
private func toggleAutoTranslate(isEnabled: Bool) {
|
||||
|
||||
self.activeActionDisposable.set(self.context.engine.peers.toggleAutoTranslation(peerId: self.peerId, enabled: isEnabled).start())
|
||||
}
|
||||
|
||||
private func displayAutoTranslateLocked() {
|
||||
@ -11918,7 +11919,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
}
|
||||
|
||||
var validEditingSections: [AnyHashable] = []
|
||||
let editItems = (self.isSettings || self.isMyProfile) ? settingsEditingItems(data: self.data, state: self.state, context: self.context, presentationData: self.presentationData, interaction: self.interaction, isMyProfile: self.isMyProfile) : editingItems(data: self.data, state: self.state, chatLocation: self.chatLocation, context: self.context, presentationData: self.presentationData, interaction: self.interaction)
|
||||
let editItems = (self.isSettings || self.isMyProfile) ? settingsEditingItems(data: self.data, state: self.state, context: self.context, presentationData: self.presentationData, interaction: self.interaction, isMyProfile: self.isMyProfile) : editingItems(data: self.data, boostStatus: self.boostStatus, state: self.state, chatLocation: self.chatLocation, context: self.context, presentationData: self.presentationData, interaction: self.interaction)
|
||||
|
||||
for (sectionId, sectionItems) in editItems {
|
||||
var insets = UIEdgeInsets()
|
||||
|
@ -675,17 +675,22 @@ extension ChatControllerImpl {
|
||||
|
||||
let isHidden = self.context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.TranslationHidden(id: peerId))
|
||||
|> distinctUntilChanged
|
||||
|
||||
let hasAutoTranslate = self.context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.AutoTranslateEnabled(id: peerId))
|
||||
|> distinctUntilChanged
|
||||
|
||||
self.translationStateDisposable = (combineLatest(
|
||||
queue: .concurrentDefaultQueue(),
|
||||
isPremium,
|
||||
isHidden,
|
||||
hasAutoTranslate,
|
||||
ApplicationSpecificNotice.translationSuggestion(accountManager: self.context.sharedContext.accountManager)
|
||||
) |> mapToSignal { isPremium, isHidden, counterAndTimestamp -> Signal<ChatPresentationTranslationState?, NoError> in
|
||||
) |> mapToSignal { isPremium, isHidden, hasAutoTranslate, counterAndTimestamp -> Signal<ChatPresentationTranslationState?, NoError> in
|
||||
var maybeSuggestPremium = false
|
||||
if counterAndTimestamp.0 >= 3 {
|
||||
maybeSuggestPremium = true
|
||||
}
|
||||
if (isPremium || maybeSuggestPremium) && !isHidden {
|
||||
if (isPremium || maybeSuggestPremium || hasAutoTranslate) && !isHidden {
|
||||
return chatTranslationState(context: context, peerId: peerId)
|
||||
|> map { translationState -> ChatPresentationTranslationState? in
|
||||
if let translationState, !translationState.fromLang.isEmpty && (translationState.fromLang != baseLanguageCode || translationState.isEnabled) {
|
||||
|
@ -180,10 +180,17 @@ public func chatTranslationState(context: AccountContext, peerId: EnginePeer.Id)
|
||||
baseLang = String(baseLang.dropLast(rawSuffix.count))
|
||||
}
|
||||
|
||||
return context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.translationSettings])
|
||||
|> mapToSignal { sharedData in
|
||||
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.translationSettings]?.get(TranslationSettings.self) ?? TranslationSettings.defaultSettings
|
||||
if !settings.translateChats {
|
||||
|
||||
|
||||
return combineLatest(
|
||||
context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.translationSettings])
|
||||
|> map { sharedData -> TranslationSettings in
|
||||
return sharedData.entries[ApplicationSpecificSharedDataKeys.translationSettings]?.get(TranslationSettings.self) ?? TranslationSettings.defaultSettings
|
||||
},
|
||||
context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.AutoTranslateEnabled(id: peerId))
|
||||
)
|
||||
|> mapToSignal { settings, autoTranslateEnabled in
|
||||
if !settings.translateChats && !autoTranslateEnabled {
|
||||
return .single(nil)
|
||||
}
|
||||
|
||||
@ -286,12 +293,22 @@ public func chatTranslationState(context: AccountContext, peerId: EnginePeer.Id)
|
||||
if loggingEnabled {
|
||||
Logger.shared.log("ChatTranslation", "Ended with: \(fromLang)")
|
||||
}
|
||||
|
||||
let isEnabled: Bool
|
||||
if let currentIsEnabled = cached?.isEnabled {
|
||||
isEnabled = currentIsEnabled
|
||||
} else if autoTranslateEnabled {
|
||||
isEnabled = true
|
||||
} else {
|
||||
isEnabled = false
|
||||
}
|
||||
|
||||
let state = ChatTranslationState(
|
||||
baseLang: baseLang,
|
||||
fromLang: fromLang,
|
||||
timestamp: currentTime,
|
||||
toLang: cached?.toLang,
|
||||
isEnabled: cached?.isEnabled ?? false
|
||||
isEnabled: isEnabled
|
||||
)
|
||||
let _ = updateChatTranslationState(engine: context.engine, peerId: peerId, state: state).start()
|
||||
if !dontTranslateLanguages.contains(fromLang) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user