mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-15 21:45:19 +00:00
Update API
This commit is contained in:
parent
2962851527
commit
9b062fd5b8
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user