Skip to content

Commit 7482abf

Browse files
committed
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
# Conflicts: # submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift
2 parents a6a807f + 999f8c8 commit 7482abf

File tree

11 files changed

+97
-31
lines changed

11 files changed

+97
-31
lines changed

submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ func parseTelegramGroupOrChannel(chat: Api.Chat) -> Peer? {
131131
if (flags & Int32(1 << 30)) != 0 {
132132
channelFlags.insert(.isForum)
133133
}
134+
if (flags2 & Int32(1 << 15)) != 0 {
135+
channelFlags.insert(.autoTranslateEnabled)
136+
}
134137

135138
var storiesHidden: Bool?
136139
if flags2 & (1 << 2) == 0 { // stories_hidden_min

submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramChannel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public struct TelegramChannelFlags: OptionSet {
181181
public static let joinToSend = TelegramChannelFlags(rawValue: 1 << 9)
182182
public static let requestToJoin = TelegramChannelFlags(rawValue: 1 << 10)
183183
public static let isForum = TelegramChannelFlags(rawValue: 1 << 11)
184+
public static let autoTranslateEnabled = TelegramChannelFlags(rawValue: 1 << 12)
184185
}
185186

186187
public final class TelegramChannel: Peer, Equatable {

submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,5 +2467,32 @@ public extension TelegramEngine.EngineData.Item {
24672467
}
24682468
}
24692469
}
2470+
2471+
public struct AutoTranslateEnabled: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
2472+
public typealias Result = Bool
2473+
2474+
fileprivate var id: EnginePeer.Id
2475+
public var mapKey: EnginePeer.Id {
2476+
return self.id
2477+
}
2478+
2479+
public init(id: EnginePeer.Id) {
2480+
self.id = id
2481+
}
2482+
2483+
var key: PostboxViewKey {
2484+
return .peer(peerId: self.id, components: [])
2485+
}
2486+
2487+
func extract(view: PostboxView) -> Result {
2488+
guard let view = view as? PeerView else {
2489+
preconditionFailure()
2490+
}
2491+
if let channel = peerViewMainPeer(view) as? TelegramChannel {
2492+
return channel.flags.contains(.autoTranslateEnabled)
2493+
}
2494+
return false
2495+
}
2496+
}
24702497
}
24712498
}

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: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -847,15 +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
855854
case starGiftResellTooEarly(Int32)
856855
}
857856

858-
859857
public enum UpgradeStarGiftError {
860858
case generic
861859
}
@@ -865,12 +863,7 @@ func _internal_buyStarGift(account: Account, slug: String, peerId: EnginePeer.Id
865863
return _internal_fetchBotPaymentForm(accountPeerId: account.peerId, postbox: account.postbox, network: account.network, source: source, themeParams: nil)
866864
|> map(Optional.init)
867865
|> `catch` { error -> Signal<BotPaymentForm?, BuyStarGiftError> in
868-
switch error {
869-
case let .starGiftResellTooEarly(value):
870-
return .fail(.starGiftResellTooEarly(value))
871-
default:
872-
return .fail(.generic)
873-
}
866+
return .fail(.generic)
874867
}
875868
|> mapToSignal { paymentForm in
876869
if let paymentForm {
@@ -2360,10 +2353,10 @@ func _internal_updateStarGiftResalePrice(account: Account, reference: StarGiftRe
23602353
return account.network.request(Api.functions.payments.updateStarGiftPrice(stargift: starGift, resellStars: price ?? 0))
23612354
|> mapError { error -> UpdateStarGiftPriceError in
23622355
if error.errorDescription.hasPrefix("STARGIFT_RESELL_TOO_EARLY_") {
2363-
let timeout = String(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "STARGIFT_RESELL_TOO_EARLY_".count)...])
2364-
if let value = Int32(timeout) {
2365-
return .starGiftResellTooEarly(value)
2366-
}
2356+
let timeout = String(error.errorDescription[error.errorDescription.index(error.errorDescription.startIndex, offsetBy: "STARGIFT_RESELL_TOO_EARLY_".count)...])
2357+
if let value = Int32(timeout) {
2358+
return .starGiftResellTooEarly(value)
2359+
}
23672360
}
23682361
return .generic
23692362
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
import Postbox
3+
import SwiftSignalKit
4+
import TelegramApi
5+
import MtProtoKit
6+
7+
func _internal_toggleAutoTranslation(account: Account, peerId: PeerId, enabled: Bool) -> Signal<Never, NoError> {
8+
return account.postbox.transaction { transaction -> Signal<Void, NoError> in
9+
if let peer = transaction.getPeer(peerId), let inputChannel = apiInputChannel(peer) {
10+
return account.network.request(Api.functions.channels.toggleAutotranslation(channel: inputChannel, enabled: enabled ? .boolTrue : .boolFalse)) |> `catch` { _ in .complete() } |> map { updates -> Void in
11+
account.stateManager.addUpdates(updates)
12+
}
13+
} else {
14+
return .complete()
15+
}
16+
}
17+
|> switchToLatest
18+
|> ignoreValues
19+
}

submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,10 @@ public extension TelegramEngine {
16931693
let _ = _internal_removeChatManagingBot(account: self.account, chatId: chatId).startStandalone()
16941694
}
16951695

1696+
public func toggleAutoTranslation(peerId: EnginePeer.Id, enabled: Bool) -> Signal<Never, NoError> {
1697+
return _internal_toggleAutoTranslation(account: self.account, peerId: peerId, enabled: enabled)
1698+
}
1699+
16961700
public func resolveMessageLink(slug: String) -> Signal<TelegramResolvedMessageLink?, NoError> {
16971701
return self.account.network.request(Api.functions.account.resolveBusinessChatLink(slug: slug))
16981702
|> map(Optional.init)

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) {

0 commit comments

Comments
 (0)