mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
# Conflicts: # submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift
This commit is contained in:
commit
7482abfd3c
@ -131,6 +131,9 @@ func parseTelegramGroupOrChannel(chat: Api.Chat) -> Peer? {
|
||||
if (flags & Int32(1 << 30)) != 0 {
|
||||
channelFlags.insert(.isForum)
|
||||
}
|
||||
if (flags2 & Int32(1 << 15)) != 0 {
|
||||
channelFlags.insert(.autoTranslateEnabled)
|
||||
}
|
||||
|
||||
var storiesHidden: Bool?
|
||||
if flags2 & (1 << 2) == 0 { // stories_hidden_min
|
||||
|
@ -181,6 +181,7 @@ public struct TelegramChannelFlags: OptionSet {
|
||||
public static let joinToSend = TelegramChannelFlags(rawValue: 1 << 9)
|
||||
public static let requestToJoin = TelegramChannelFlags(rawValue: 1 << 10)
|
||||
public static let isForum = TelegramChannelFlags(rawValue: 1 << 11)
|
||||
public static let autoTranslateEnabled = TelegramChannelFlags(rawValue: 1 << 12)
|
||||
}
|
||||
|
||||
public final class TelegramChannel: Peer, Equatable {
|
||||
|
@ -2467,5 +2467,32 @@ public extension TelegramEngine.EngineData.Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct AutoTranslateEnabled: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
|
||||
public typealias Result = Bool
|
||||
|
||||
fileprivate var id: EnginePeer.Id
|
||||
public var mapKey: EnginePeer.Id {
|
||||
return self.id
|
||||
}
|
||||
|
||||
public init(id: EnginePeer.Id) {
|
||||
self.id = id
|
||||
}
|
||||
|
||||
var key: PostboxViewKey {
|
||||
return .peer(peerId: self.id, components: [])
|
||||
}
|
||||
|
||||
func extract(view: PostboxView) -> Result {
|
||||
guard let view = view as? PeerView else {
|
||||
preconditionFailure()
|
||||
}
|
||||
if let channel = peerViewMainPeer(view) as? TelegramChannel {
|
||||
return channel.flags.contains(.autoTranslateEnabled)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,7 +847,6 @@ public enum TransferStarGiftError {
|
||||
|
||||
public enum BuyStarGiftError {
|
||||
case generic
|
||||
case starGiftResellTooEarly(Int32)
|
||||
}
|
||||
|
||||
public enum UpdateStarGiftPriceError {
|
||||
@ -855,7 +854,6 @@ public enum UpdateStarGiftPriceError {
|
||||
case starGiftResellTooEarly(Int32)
|
||||
}
|
||||
|
||||
|
||||
public enum UpgradeStarGiftError {
|
||||
case generic
|
||||
}
|
||||
@ -865,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 {
|
||||
@ -2360,10 +2353,10 @@ 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)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
import TelegramApi
|
||||
import MtProtoKit
|
||||
|
||||
func _internal_toggleAutoTranslation(account: Account, peerId: PeerId, enabled: Bool) -> Signal<Never, NoError> {
|
||||
return account.postbox.transaction { transaction -> Signal<Void, NoError> in
|
||||
if let peer = transaction.getPeer(peerId), let inputChannel = apiInputChannel(peer) {
|
||||
return account.network.request(Api.functions.channels.toggleAutotranslation(channel: inputChannel, enabled: enabled ? .boolTrue : .boolFalse)) |> `catch` { _ in .complete() } |> map { updates -> Void in
|
||||
account.stateManager.addUpdates(updates)
|
||||
}
|
||||
} else {
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
|> switchToLatest
|
||||
|> ignoreValues
|
||||
}
|
@ -1693,6 +1693,10 @@ public extension TelegramEngine {
|
||||
let _ = _internal_removeChatManagingBot(account: self.account, chatId: chatId).startStandalone()
|
||||
}
|
||||
|
||||
public func toggleAutoTranslation(peerId: EnginePeer.Id, enabled: Bool) -> Signal<Never, NoError> {
|
||||
return _internal_toggleAutoTranslation(account: self.account, peerId: peerId, enabled: enabled)
|
||||
}
|
||||
|
||||
public func resolveMessageLink(slug: String) -> Signal<TelegramResolvedMessageLink?, NoError> {
|
||||
return self.account.network.request(Api.functions.account.resolveBusinessChatLink(slug: slug))
|
||||
|> map(Optional.init)
|
||||
|
@ -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