Skip to content

Commit 9b062fd

Browse files
committed
Update API
1 parent 2962851 commit 9b062fd

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
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
}
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)

0 commit comments

Comments
 (0)