mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 22:11:22 +00:00
API support
This commit is contained in:
parent
58d362381e
commit
6573493174
@ -84,6 +84,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
|||||||
dict[55281185] = { return Api.RichText.parse_textMarked($0) }
|
dict[55281185] = { return Api.RichText.parse_textMarked($0) }
|
||||||
dict[483104362] = { return Api.RichText.parse_textPhone($0) }
|
dict[483104362] = { return Api.RichText.parse_textPhone($0) }
|
||||||
dict[136105807] = { return Api.RichText.parse_textImage($0) }
|
dict[136105807] = { return Api.RichText.parse_textImage($0) }
|
||||||
|
dict[894777186] = { return Api.RichText.parse_textAnchor($0) }
|
||||||
dict[-1901811583] = { return Api.UserFull.parse_userFull($0) }
|
dict[-1901811583] = { return Api.UserFull.parse_userFull($0) }
|
||||||
dict[-292807034] = { return Api.InputChannel.parse_inputChannelEmpty($0) }
|
dict[-292807034] = { return Api.InputChannel.parse_inputChannelEmpty($0) }
|
||||||
dict[-1343524562] = { return Api.InputChannel.parse_inputChannel($0) }
|
dict[-1343524562] = { return Api.InputChannel.parse_inputChannel($0) }
|
||||||
@ -408,7 +409,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
|||||||
dict[-1182234929] = { return Api.InputUser.parse_inputUserEmpty($0) }
|
dict[-1182234929] = { return Api.InputUser.parse_inputUserEmpty($0) }
|
||||||
dict[-138301121] = { return Api.InputUser.parse_inputUserSelf($0) }
|
dict[-138301121] = { return Api.InputUser.parse_inputUserSelf($0) }
|
||||||
dict[-668391402] = { return Api.InputUser.parse_inputUser($0) }
|
dict[-668391402] = { return Api.InputUser.parse_inputUser($0) }
|
||||||
dict[-241590104] = { return Api.Page.parse_page($0) }
|
dict[-1366746132] = { return Api.Page.parse_page($0) }
|
||||||
dict[871426631] = { return Api.SecureCredentialsEncrypted.parse_secureCredentialsEncrypted($0) }
|
dict[871426631] = { return Api.SecureCredentialsEncrypted.parse_secureCredentialsEncrypted($0) }
|
||||||
dict[157948117] = { return Api.upload.File.parse_file($0) }
|
dict[157948117] = { return Api.upload.File.parse_file($0) }
|
||||||
dict[-242427324] = { return Api.upload.File.parse_fileCdnRedirect($0) }
|
dict[-242427324] = { return Api.upload.File.parse_fileCdnRedirect($0) }
|
||||||
|
|||||||
@ -1843,6 +1843,7 @@ extension Api {
|
|||||||
case textMarked(text: Api.RichText)
|
case textMarked(text: Api.RichText)
|
||||||
case textPhone(text: Api.RichText, phone: String)
|
case textPhone(text: Api.RichText, phone: String)
|
||||||
case textImage(documentId: Int64, w: Int32, h: Int32)
|
case textImage(documentId: Int64, w: Int32, h: Int32)
|
||||||
|
case textAnchor(text: Api.RichText, name: String)
|
||||||
|
|
||||||
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||||
switch self {
|
switch self {
|
||||||
@ -1946,6 +1947,13 @@ extension Api {
|
|||||||
serializeInt32(w, buffer: buffer, boxed: false)
|
serializeInt32(w, buffer: buffer, boxed: false)
|
||||||
serializeInt32(h, buffer: buffer, boxed: false)
|
serializeInt32(h, buffer: buffer, boxed: false)
|
||||||
break
|
break
|
||||||
|
case .textAnchor(let text, let name):
|
||||||
|
if boxed {
|
||||||
|
buffer.appendInt32(894777186)
|
||||||
|
}
|
||||||
|
text.serialize(buffer, true)
|
||||||
|
serializeString(name, buffer: buffer, boxed: false)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1981,6 +1989,8 @@ extension Api {
|
|||||||
return ("textPhone", [("text", text), ("phone", phone)])
|
return ("textPhone", [("text", text), ("phone", phone)])
|
||||||
case .textImage(let documentId, let w, let h):
|
case .textImage(let documentId, let w, let h):
|
||||||
return ("textImage", [("documentId", documentId), ("w", w), ("h", h)])
|
return ("textImage", [("documentId", documentId), ("w", w), ("h", h)])
|
||||||
|
case .textAnchor(let text, let name):
|
||||||
|
return ("textAnchor", [("text", text), ("name", name)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2183,6 +2193,22 @@ extension Api {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static func parse_textAnchor(_ reader: BufferReader) -> RichText? {
|
||||||
|
var _1: Api.RichText?
|
||||||
|
if let signature = reader.readInt32() {
|
||||||
|
_1 = Api.parse(reader, signature: signature) as? Api.RichText
|
||||||
|
}
|
||||||
|
var _2: String?
|
||||||
|
_2 = parseString(reader)
|
||||||
|
let _c1 = _1 != nil
|
||||||
|
let _c2 = _2 != nil
|
||||||
|
if _c1 && _c2 {
|
||||||
|
return Api.RichText.textAnchor(text: _1!, name: _2!)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
enum UserFull: TypeConstructorDescription {
|
enum UserFull: TypeConstructorDescription {
|
||||||
@ -10006,15 +10032,16 @@ extension Api {
|
|||||||
|
|
||||||
}
|
}
|
||||||
enum Page: TypeConstructorDescription {
|
enum Page: TypeConstructorDescription {
|
||||||
case page(flags: Int32, blocks: [Api.PageBlock], photos: [Api.Photo], documents: [Api.Document])
|
case page(flags: Int32, url: String, blocks: [Api.PageBlock], photos: [Api.Photo], documents: [Api.Document])
|
||||||
|
|
||||||
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||||
switch self {
|
switch self {
|
||||||
case .page(let flags, let blocks, let photos, let documents):
|
case .page(let flags, let url, let blocks, let photos, let documents):
|
||||||
if boxed {
|
if boxed {
|
||||||
buffer.appendInt32(-241590104)
|
buffer.appendInt32(-1366746132)
|
||||||
}
|
}
|
||||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||||
|
serializeString(url, buffer: buffer, boxed: false)
|
||||||
buffer.appendInt32(481674261)
|
buffer.appendInt32(481674261)
|
||||||
buffer.appendInt32(Int32(blocks.count))
|
buffer.appendInt32(Int32(blocks.count))
|
||||||
for item in blocks {
|
for item in blocks {
|
||||||
@ -10036,32 +10063,35 @@ extension Api {
|
|||||||
|
|
||||||
func descriptionFields() -> (String, [(String, Any)]) {
|
func descriptionFields() -> (String, [(String, Any)]) {
|
||||||
switch self {
|
switch self {
|
||||||
case .page(let flags, let blocks, let photos, let documents):
|
case .page(let flags, let url, let blocks, let photos, let documents):
|
||||||
return ("page", [("flags", flags), ("blocks", blocks), ("photos", photos), ("documents", documents)])
|
return ("page", [("flags", flags), ("url", url), ("blocks", blocks), ("photos", photos), ("documents", documents)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static func parse_page(_ reader: BufferReader) -> Page? {
|
static func parse_page(_ reader: BufferReader) -> Page? {
|
||||||
var _1: Int32?
|
var _1: Int32?
|
||||||
_1 = reader.readInt32()
|
_1 = reader.readInt32()
|
||||||
var _2: [Api.PageBlock]?
|
var _2: String?
|
||||||
|
_2 = parseString(reader)
|
||||||
|
var _3: [Api.PageBlock]?
|
||||||
if let _ = reader.readInt32() {
|
if let _ = reader.readInt32() {
|
||||||
_2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PageBlock.self)
|
_3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.PageBlock.self)
|
||||||
}
|
}
|
||||||
var _3: [Api.Photo]?
|
var _4: [Api.Photo]?
|
||||||
if let _ = reader.readInt32() {
|
if let _ = reader.readInt32() {
|
||||||
_3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Photo.self)
|
_4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Photo.self)
|
||||||
}
|
}
|
||||||
var _4: [Api.Document]?
|
var _5: [Api.Document]?
|
||||||
if let _ = reader.readInt32() {
|
if let _ = reader.readInt32() {
|
||||||
_4 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Document.self)
|
_5 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Document.self)
|
||||||
}
|
}
|
||||||
let _c1 = _1 != nil
|
let _c1 = _1 != nil
|
||||||
let _c2 = _2 != nil
|
let _c2 = _2 != nil
|
||||||
let _c3 = _3 != nil
|
let _c3 = _3 != nil
|
||||||
let _c4 = _4 != nil
|
let _c4 = _4 != nil
|
||||||
if _c1 && _c2 && _c3 && _c4 {
|
let _c5 = _5 != nil
|
||||||
return Api.Page.page(flags: _1!, blocks: _2!, photos: _3!, documents: _4!)
|
if _c1 && _c2 && _c3 && _c4 && _c5 {
|
||||||
|
return Api.Page.page(flags: _1!, url: _2!, blocks: _3!, photos: _4!, documents: _5!)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -4967,6 +4967,20 @@ extension Api {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func cancelPasswordEmail() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
||||||
|
let buffer = Buffer()
|
||||||
|
buffer.appendInt32(-1043606090)
|
||||||
|
|
||||||
|
return (FunctionDescription(name: "account.cancelPasswordEmail", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
|
||||||
|
let reader = BufferReader(buffer)
|
||||||
|
var result: Api.Bool?
|
||||||
|
if let signature = reader.readInt32() {
|
||||||
|
result = Api.parse(reader, signature: signature) as? Api.Bool
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
static func getContactSignUpNotification() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
static func getContactSignUpNotification() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
||||||
let buffer = Buffer()
|
let buffer = Buffer()
|
||||||
buffer.appendInt32(-1626880216)
|
buffer.appendInt32(-1626880216)
|
||||||
|
|||||||
@ -47,3 +47,15 @@ public func resendTwoStepRecoveryEmail(network: Network) -> Signal<Never, Resend
|
|||||||
}
|
}
|
||||||
|> ignoreValues
|
|> ignoreValues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum CancelTwoStepRecoveryEmailError {
|
||||||
|
case generic
|
||||||
|
}
|
||||||
|
|
||||||
|
public func cancelTwoStepRecoveryEmail(network: Network) -> Signal<Never, CancelTwoStepRecoveryEmailError> {
|
||||||
|
return network.request(Api.functions.account.cancelPasswordEmail(), automaticFloodWait: false)
|
||||||
|
|> mapError { _ -> CancelTwoStepRecoveryEmailError in
|
||||||
|
return .generic
|
||||||
|
}
|
||||||
|
|> ignoreValues
|
||||||
|
}
|
||||||
|
|||||||
@ -848,12 +848,14 @@ public final class InstantPage: PostboxCoding, Equatable {
|
|||||||
public let media: [MediaId: Media]
|
public let media: [MediaId: Media]
|
||||||
public let isComplete: Bool
|
public let isComplete: Bool
|
||||||
public let rtl: Bool
|
public let rtl: Bool
|
||||||
|
public let url: String
|
||||||
|
|
||||||
init(blocks: [InstantPageBlock], media: [MediaId: Media], isComplete: Bool, rtl: Bool) {
|
init(blocks: [InstantPageBlock], media: [MediaId: Media], isComplete: Bool, rtl: Bool, url: String) {
|
||||||
self.blocks = blocks
|
self.blocks = blocks
|
||||||
self.media = media
|
self.media = media
|
||||||
self.isComplete = isComplete
|
self.isComplete = isComplete
|
||||||
self.rtl = rtl
|
self.rtl = rtl
|
||||||
|
self.url = url
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(decoder: PostboxDecoder) {
|
public init(decoder: PostboxDecoder) {
|
||||||
@ -861,6 +863,7 @@ public final class InstantPage: PostboxCoding, Equatable {
|
|||||||
self.media = MediaDictionary(decoder: decoder).dict
|
self.media = MediaDictionary(decoder: decoder).dict
|
||||||
self.isComplete = decoder.decodeInt32ForKey("c", orElse: 0) != 0
|
self.isComplete = decoder.decodeInt32ForKey("c", orElse: 0) != 0
|
||||||
self.rtl = decoder.decodeInt32ForKey("r", orElse: 0) != 0
|
self.rtl = decoder.decodeInt32ForKey("r", orElse: 0) != 0
|
||||||
|
self.url = decoder.decodeStringForKey("url", orElse: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(_ encoder: PostboxEncoder) {
|
public func encode(_ encoder: PostboxEncoder) {
|
||||||
@ -868,6 +871,7 @@ public final class InstantPage: PostboxCoding, Equatable {
|
|||||||
MediaDictionary(dict: self.media).encode(encoder)
|
MediaDictionary(dict: self.media).encode(encoder)
|
||||||
encoder.encodeInt32(self.isComplete ? 1 : 0, forKey: "c")
|
encoder.encodeInt32(self.isComplete ? 1 : 0, forKey: "c")
|
||||||
encoder.encodeInt32(self.rtl ? 1 : 0, forKey: "r")
|
encoder.encodeInt32(self.rtl ? 1 : 0, forKey: "r")
|
||||||
|
encoder.encodeString(self.url, forKey: "url")
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func ==(lhs: InstantPage, rhs: InstantPage) -> Bool {
|
public static func ==(lhs: InstantPage, rhs: InstantPage) -> Bool {
|
||||||
@ -893,6 +897,9 @@ public final class InstantPage: PostboxCoding, Equatable {
|
|||||||
if lhs.rtl != rhs.rtl {
|
if lhs.rtl != rhs.rtl {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if lhs.url != rhs.url {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -900,8 +907,8 @@ public final class InstantPage: PostboxCoding, Equatable {
|
|||||||
extension InstantPageCaption {
|
extension InstantPageCaption {
|
||||||
convenience init(apiCaption: Api.PageCaption) {
|
convenience init(apiCaption: Api.PageCaption) {
|
||||||
switch apiCaption {
|
switch apiCaption {
|
||||||
case let .pageCaption(text, credit):
|
case let .pageCaption(text, credit):
|
||||||
self.init(text: RichText(apiText: text), credit: RichText(apiText: credit))
|
self.init(text: RichText(apiText: text), credit: RichText(apiText: credit))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1063,13 +1070,15 @@ extension InstantPage {
|
|||||||
let files: [Api.Document]
|
let files: [Api.Document]
|
||||||
let isComplete: Bool
|
let isComplete: Bool
|
||||||
let rtl: Bool
|
let rtl: Bool
|
||||||
|
let url: String
|
||||||
switch apiPage {
|
switch apiPage {
|
||||||
case let .page(flags, apiBlocks, apiPhotos, apiVideos):
|
case let .page(page):
|
||||||
blocks = apiBlocks
|
url = page.url
|
||||||
photos = apiPhotos
|
blocks = page.blocks
|
||||||
files = apiVideos
|
photos = page.photos
|
||||||
isComplete = (flags & (1 << 0)) == 0
|
files = page.documents
|
||||||
rtl = (flags & (1 << 1)) != 0
|
isComplete = (page.flags & (1 << 0)) == 0
|
||||||
|
rtl = (page.flags & (1 << 1)) != 0
|
||||||
}
|
}
|
||||||
var media: [MediaId: Media] = [:]
|
var media: [MediaId: Media] = [:]
|
||||||
for photo in photos {
|
for photo in photos {
|
||||||
@ -1082,6 +1091,6 @@ extension InstantPage {
|
|||||||
media[id] = file
|
media[id] = file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.init(blocks: blocks.map({ InstantPageBlock(apiBlock: $0) }), media: media, isComplete: isComplete, rtl: rtl)
|
self.init(blocks: blocks.map({ InstantPageBlock(apiBlock: $0) }), media: media, isComplete: isComplete, rtl: rtl, url: url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -315,6 +315,8 @@ extension RichText {
|
|||||||
self = .phone(text: RichText(apiText: text), phone: phone)
|
self = .phone(text: RichText(apiText: text), phone: phone)
|
||||||
case let .textImage(documentId, w, h):
|
case let .textImage(documentId, w, h):
|
||||||
self = .image(id: MediaId(namespace: Namespaces.Media.CloudFile, id: documentId), dimensions: CGSize(width: CGFloat(w), height: CGFloat(h)))
|
self = .image(id: MediaId(namespace: Namespaces.Media.CloudFile, id: documentId), dimensions: CGSize(width: CGFloat(w), height: CGFloat(h)))
|
||||||
|
case let .textAnchor(text, name):
|
||||||
|
self = RichText(apiText: text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user