Skip to content

Commit 999f8c8

Browse files
committed
Various fixes
1 parent 9b062fd commit 999f8c8

File tree

6 files changed

+46
-27
lines changed

6 files changed

+46
-27
lines changed

submodules/TelegramCore/Sources/TelegramEngine/Payments/BotPaymentForm.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public enum BotPaymentFormRequestError {
179179
case alreadyActive
180180
case noPaymentNeeded
181181
case disallowedStarGift
182-
case starGiftResellTooEarly(Int32)
183182
}
184183

185184
extension BotPaymentInvoice {
@@ -483,11 +482,6 @@ func _internal_fetchBotPaymentForm(accountPeerId: PeerId, postbox: Postbox, netw
483482
return .fail(.noPaymentNeeded)
484483
} else if error.errorDescription == "USER_DISALLOWED_STARGIFTS" {
485484
return .fail(.disallowedStarGift)
486-
} else if error.errorDescription.hasPrefix("STARGIFT_RESELL_TOO_EARLY_") {
487-
let timeout = String(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "STARGIFT_RESELL_TOO_EARLY_".count)...])
488-
if let value = Int32(timeout) {
489-
return .fail(.starGiftResellTooEarly(value))
490-
}
491485
}
492486
return .fail(.generic)
493487
}

submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,13 @@ public enum TransferStarGiftError {
847847

848848
public enum BuyStarGiftError {
849849
case generic
850-
case starGiftResellTooEarly(Int32)
851850
}
852851

853852
public enum UpdateStarGiftPriceError {
854853
case generic
854+
case starGiftResellTooEarly(Int32)
855855
}
856856

857-
858857
public enum UpgradeStarGiftError {
859858
case generic
860859
}
@@ -864,12 +863,7 @@ func _internal_buyStarGift(account: Account, slug: String, peerId: EnginePeer.Id
864863
return _internal_fetchBotPaymentForm(accountPeerId: account.peerId, postbox: account.postbox, network: account.network, source: source, themeParams: nil)
865864
|> map(Optional.init)
866865
|> `catch` { error -> Signal<BotPaymentForm?, BuyStarGiftError> in
867-
switch error {
868-
case let .starGiftResellTooEarly(value):
869-
return .fail(.starGiftResellTooEarly(value))
870-
default:
871-
return .fail(.generic)
872-
}
866+
return .fail(.generic)
873867
}
874868
|> mapToSignal { paymentForm in
875869
if let paymentForm {
@@ -2325,6 +2319,12 @@ func _internal_updateStarGiftResalePrice(account: Account, reference: StarGiftRe
23252319
}
23262320
return account.network.request(Api.functions.payments.updateStarGiftPrice(stargift: starGift, resellStars: price ?? 0))
23272321
|> mapError { error -> UpdateStarGiftPriceError in
2322+
if error.errorDescription.hasPrefix("STARGIFT_RESELL_TOO_EARLY_") {
2323+
let timeout = String(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "STARGIFT_RESELL_TOO_EARLY_".count)...])
2324+
if let value = Int32(timeout) {
2325+
return .starGiftResellTooEarly(value)
2326+
}
2327+
}
23282328
return .generic
23292329
}
23302330
|> mapToSignal { updates -> Signal<Void, UpdateStarGiftPriceError> in

submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8155,7 +8155,9 @@ public final class MediaEditorScreenImpl: ViewController, MediaEditorScreen, UID
81558155
let trimmedValues = values.withUpdatedVideoTrimRange(start ..< min(start + storyMaxVideoDuration, originalDuration))
81568156

81578157
var editingItem = EditingItem(asset: asset)
8158-
editingItem.caption = self.node.getCaption()
8158+
if i == 0 {
8159+
editingItem.caption = self.node.getCaption()
8160+
}
81598161
editingItem.values = trimmedValues
81608162
multipleItems.append(editingItem)
81618163

submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,7 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
20072007
return result
20082008
}
20092009

2010-
private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatLocation: ChatLocation, context: AccountContext, presentationData: PresentationData, interaction: PeerInfoInteraction) -> [(AnyHashable, [PeerInfoScreenItem])] {
2010+
private func editingItems(data: PeerInfoScreenData?, boostStatus: ChannelBoostStatus?, state: PeerInfoState, chatLocation: ChatLocation, context: AccountContext, presentationData: PresentationData, interaction: PeerInfoInteraction) -> [(AnyHashable, [PeerInfoScreenItem])] {
20112011
enum Section: Int, CaseIterable {
20122012
case notifications
20132013
case groupLocation
@@ -2276,11 +2276,12 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL
22762276
interaction.editingOpenNameColorSetup()
22772277
}))
22782278

2279+
let premiumConfiguration = PremiumConfiguration.with(appConfiguration: context.currentAppConfiguration.with { $0 })
22792280
var isLocked = true
2280-
if let approximateBoostLevel = channel.approximateBoostLevel, approximateBoostLevel >= 3 {
2281+
if let boostLevel = boostStatus?.level, boostLevel >= BoostSubject.autoTranslate.requiredLevel(group: false, context: context, configuration: premiumConfiguration) {
22812282
isLocked = false
22822283
}
2283-
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
2284+
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
22842285
if isLocked {
22852286
interaction.displayAutoTranslateLocked()
22862287
} else {
@@ -9157,7 +9158,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
91579158
}
91589159

91599160
private func toggleAutoTranslate(isEnabled: Bool) {
9160-
9161+
self.activeActionDisposable.set(self.context.engine.peers.toggleAutoTranslation(peerId: self.peerId, enabled: isEnabled).start())
91619162
}
91629163

91639164
private func displayAutoTranslateLocked() {
@@ -11918,7 +11919,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
1191811919
}
1191911920

1192011921
var validEditingSections: [AnyHashable] = []
11921-
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)
11922+
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)
1192211923

1192311924
for (sectionId, sectionItems) in editItems {
1192411925
var insets = UIEdgeInsets()

submodules/TelegramUI/Sources/Chat/ChatControllerLoadDisplayNode.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,17 +675,22 @@ extension ChatControllerImpl {
675675

676676
let isHidden = self.context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.TranslationHidden(id: peerId))
677677
|> distinctUntilChanged
678+
679+
let hasAutoTranslate = self.context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.AutoTranslateEnabled(id: peerId))
680+
|> distinctUntilChanged
681+
678682
self.translationStateDisposable = (combineLatest(
679683
queue: .concurrentDefaultQueue(),
680684
isPremium,
681685
isHidden,
686+
hasAutoTranslate,
682687
ApplicationSpecificNotice.translationSuggestion(accountManager: self.context.sharedContext.accountManager)
683-
) |> mapToSignal { isPremium, isHidden, counterAndTimestamp -> Signal<ChatPresentationTranslationState?, NoError> in
688+
) |> mapToSignal { isPremium, isHidden, hasAutoTranslate, counterAndTimestamp -> Signal<ChatPresentationTranslationState?, NoError> in
684689
var maybeSuggestPremium = false
685690
if counterAndTimestamp.0 >= 3 {
686691
maybeSuggestPremium = true
687692
}
688-
if (isPremium || maybeSuggestPremium) && !isHidden {
693+
if (isPremium || maybeSuggestPremium || hasAutoTranslate) && !isHidden {
689694
return chatTranslationState(context: context, peerId: peerId)
690695
|> map { translationState -> ChatPresentationTranslationState? in
691696
if let translationState, !translationState.fromLang.isEmpty && (translationState.fromLang != baseLanguageCode || translationState.isEnabled) {

submodules/TranslateUI/Sources/ChatTranslation.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,17 @@ public func chatTranslationState(context: AccountContext, peerId: EnginePeer.Id)
180180
baseLang = String(baseLang.dropLast(rawSuffix.count))
181181
}
182182

183-
return context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.translationSettings])
184-
|> mapToSignal { sharedData in
185-
let settings = sharedData.entries[ApplicationSpecificSharedDataKeys.translationSettings]?.get(TranslationSettings.self) ?? TranslationSettings.defaultSettings
186-
if !settings.translateChats {
183+
184+
185+
return combineLatest(
186+
context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.translationSettings])
187+
|> map { sharedData -> TranslationSettings in
188+
return sharedData.entries[ApplicationSpecificSharedDataKeys.translationSettings]?.get(TranslationSettings.self) ?? TranslationSettings.defaultSettings
189+
},
190+
context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.AutoTranslateEnabled(id: peerId))
191+
)
192+
|> mapToSignal { settings, autoTranslateEnabled in
193+
if !settings.translateChats && !autoTranslateEnabled {
187194
return .single(nil)
188195
}
189196

@@ -286,12 +293,22 @@ public func chatTranslationState(context: AccountContext, peerId: EnginePeer.Id)
286293
if loggingEnabled {
287294
Logger.shared.log("ChatTranslation", "Ended with: \(fromLang)")
288295
}
296+
297+
let isEnabled: Bool
298+
if let currentIsEnabled = cached?.isEnabled {
299+
isEnabled = currentIsEnabled
300+
} else if autoTranslateEnabled {
301+
isEnabled = true
302+
} else {
303+
isEnabled = false
304+
}
305+
289306
let state = ChatTranslationState(
290307
baseLang: baseLang,
291308
fromLang: fromLang,
292309
timestamp: currentTime,
293310
toLang: cached?.toLang,
294-
isEnabled: cached?.isEnabled ?? false
311+
isEnabled: isEnabled
295312
)
296313
let _ = updateChatTranslationState(engine: context.engine, peerId: peerId, state: state).start()
297314
if !dontTranslateLanguages.contains(fromLang) {

0 commit comments

Comments
 (0)