Update API [skip ci]

This commit is contained in:
Ilya Laktyushin 2021-01-13 18:48:29 +03:00
parent 545608e8d4
commit b078caa4f4
6 changed files with 42 additions and 62 deletions

View File

@ -2,16 +2,18 @@ import Postbox
public struct ExportedInvitation: PostboxCoding, Equatable {
public let link: String
public let revoked: Bool
public let isPermanent: Bool
public let isRevoked: Bool
public let adminId: PeerId
public let date: Int32
public let expireDate: Int32?
public let usageLimit: Int32?
public let count: Int32?
public init(link: String, revoked: Bool, adminId: PeerId, date: Int32, expireDate: Int32?, usageLimit: Int32?, count: Int32?) {
public init(link: String, isPermanent: Bool, isRevoked: Bool, adminId: PeerId, date: Int32, expireDate: Int32?, usageLimit: Int32?, count: Int32?) {
self.link = link
self.revoked = revoked
self.isPermanent = isPermanent
self.isRevoked = isRevoked
self.adminId = adminId
self.date = date
self.expireDate = expireDate
@ -21,7 +23,8 @@ public struct ExportedInvitation: PostboxCoding, Equatable {
public init(decoder: PostboxDecoder) {
self.link = decoder.decodeStringForKey("l", orElse: "")
self.revoked = decoder.decodeBoolForKey("revoked", orElse: false)
self.isPermanent = decoder.decodeBoolForKey("permanent", orElse: false)
self.isRevoked = decoder.decodeBoolForKey("revoked", orElse: false)
self.adminId = PeerId(decoder.decodeInt64ForKey("adminId", orElse: 0))
self.date = decoder.decodeInt32ForKey("date", orElse: 0)
self.expireDate = decoder.decodeOptionalInt32ForKey("expireDate")
@ -31,7 +34,8 @@ public struct ExportedInvitation: PostboxCoding, Equatable {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.link, forKey: "l")
encoder.encodeBool(self.revoked, forKey: "revoked")
encoder.encodeBool(self.isPermanent, forKey: "permanent")
encoder.encodeBool(self.isRevoked, forKey: "revoked")
encoder.encodeInt64(self.adminId.toInt64(), forKey: "adminId")
encoder.encodeInt32(self.date, forKey: "date")
if let expireDate = self.expireDate {
@ -52,6 +56,6 @@ public struct ExportedInvitation: PostboxCoding, Equatable {
}
public static func ==(lhs: ExportedInvitation, rhs: ExportedInvitation) -> Bool {
return lhs.link == rhs.link && lhs.revoked == rhs.revoked && lhs.adminId == rhs.adminId && lhs.date == rhs.date && lhs.expireDate == rhs.expireDate && lhs.usageLimit == rhs.usageLimit && lhs.count == rhs.count
return lhs.link == rhs.link && lhs.isPermanent == rhs.isPermanent && lhs.isRevoked == rhs.isRevoked && lhs.adminId == rhs.adminId && lhs.date == rhs.date && lhs.expireDate == rhs.expireDate && lhs.usageLimit == rhs.usageLimit && lhs.count == rhs.count
}
}

View File

@ -150,7 +150,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1649296275] = { return Api.Peer.parse_peerUser($0) }
dict[-1160714821] = { return Api.Peer.parse_peerChat($0) }
dict[-1109531342] = { return Api.Peer.parse_peerChannel($0) }
dict[-1748638807] = { return Api.messages.ExportedChatInvite.parse_exportedChatInvite($0) }
dict[410107472] = { return Api.messages.ExportedChatInvite.parse_exportedChatInvite($0) }
dict[-1868808300] = { return Api.PaymentRequestedInfo.parse_paymentRequestedInfo($0) }
dict[164646985] = { return Api.UserStatus.parse_userStatusEmpty($0) }
dict[-306628279] = { return Api.UserStatus.parse_userStatusOnline($0) }

View File

@ -221,21 +221,16 @@ public struct messages {
}
public enum ExportedChatInvite: TypeConstructorDescription {
case exportedChatInvite(invite: Api.ExportedChatInvite, recentImporters: [Int32], users: [Api.User])
case exportedChatInvite(invite: Api.ExportedChatInvite, users: [Api.User])
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .exportedChatInvite(let invite, let recentImporters, let users):
case .exportedChatInvite(let invite, let users):
if boxed {
buffer.appendInt32(-1748638807)
buffer.appendInt32(410107472)
}
invite.serialize(buffer, true)
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(recentImporters.count))
for item in recentImporters {
serializeInt32(item, buffer: buffer, boxed: false)
}
buffer.appendInt32(481674261)
buffer.appendInt32(Int32(users.count))
for item in users {
item.serialize(buffer, true)
@ -246,8 +241,8 @@ public struct messages {
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .exportedChatInvite(let invite, let recentImporters, let users):
return ("exportedChatInvite", [("invite", invite), ("recentImporters", recentImporters), ("users", users)])
case .exportedChatInvite(let invite, let users):
return ("exportedChatInvite", [("invite", invite), ("users", users)])
}
}
@ -256,19 +251,14 @@ public struct messages {
if let signature = reader.readInt32() {
_1 = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite
}
var _2: [Int32]?
var _2: [Api.User]?
if let _ = reader.readInt32() {
_2 = Api.parseVector(reader, elementSignature: -1471112230, elementType: Int32.self)
}
var _3: [Api.User]?
if let _ = reader.readInt32() {
_3 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self)
_2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self)
}
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
if _c1 && _c2 && _c3 {
return Api.messages.ExportedChatInvite.exportedChatInvite(invite: _1!, recentImporters: _2!, users: _3!)
if _c1 && _c2 {
return Api.messages.ExportedChatInvite.exportedChatInvite(invite: _1!, users: _2!)
}
else {
return nil

View File

@ -3903,23 +3903,6 @@ public extension Api {
})
}
public static func exportChatInvite(flags: Int32, peer: Api.InputPeer, expireDate: Int32?, usageLimit: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.ExportedChatInvite>) {
let buffer = Buffer()
buffer.appendInt32(347716823)
serializeInt32(flags, buffer: buffer, boxed: false)
peer.serialize(buffer, true)
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(expireDate!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 1) != 0 {serializeInt32(usageLimit!, buffer: buffer, boxed: false)}
return (FunctionDescription(name: "messages.exportChatInvite", parameters: [("flags", flags), ("peer", peer), ("expireDate", expireDate), ("usageLimit", usageLimit)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.ExportedChatInvite? in
let reader = BufferReader(buffer)
var result: Api.ExportedChatInvite?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite
}
return result
})
}
public static func getExportedChatInvites(flags: Int32, peer: Api.InputPeer, adminId: Api.InputUser?, offsetLink: String?, limit: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.ExportedChatInvites>) {
let buffer = Buffer()
buffer.appendInt32(1838984707)
@ -3938,6 +3921,23 @@ public extension Api {
})
}
public static func exportChatInvite(flags: Int32, peer: Api.InputPeer, expireDate: Int32?, usageLimit: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.ExportedChatInvite>) {
let buffer = Buffer()
buffer.appendInt32(347716823)
serializeInt32(flags, buffer: buffer, boxed: false)
peer.serialize(buffer, true)
if Int(flags) & Int(1 << 0) != 0 {serializeInt32(expireDate!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 1) != 0 {serializeInt32(usageLimit!, buffer: buffer, boxed: false)}
return (FunctionDescription(name: "messages.exportChatInvite", parameters: [("flags", flags), ("peer", peer), ("expireDate", expireDate), ("usageLimit", usageLimit)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.ExportedChatInvite? in
let reader = BufferReader(buffer)
var result: Api.ExportedChatInvite?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite
}
return result
})
}
public static func editExportedChatInvite(flags: Int32, peer: Api.InputPeer, link: String, expireDate: Int32?, usageLimit: Int32?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.ExportedChatInvite>) {
let buffer = Buffer()
buffer.appendInt32(48562110)
@ -3956,21 +3956,6 @@ public extension Api {
})
}
public static func getExportedChatInvite(peer: Api.InputPeer, link: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.ExportedChatInvite>) {
let buffer = Buffer()
buffer.appendInt32(1937010524)
peer.serialize(buffer, true)
serializeString(link, buffer: buffer, boxed: false)
return (FunctionDescription(name: "messages.getExportedChatInvite", parameters: [("peer", peer), ("link", link)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.ExportedChatInvite? in
let reader = BufferReader(buffer)
var result: Api.messages.ExportedChatInvite?
if let signature = reader.readInt32() {
result = Api.parse(reader, signature: signature) as? Api.messages.ExportedChatInvite
}
return result
})
}
public static func getChatInviteImporters(peer: Api.InputPeer, link: String, offsetDate: Int32, offsetUser: Api.InputUser, limit: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.ChatInviteImporters>) {
let buffer = Buffer()
buffer.appendInt32(654013065)

View File

@ -10,7 +10,7 @@ extension ExportedInvitation {
case .chatInviteEmpty:
return nil
case let .chatInviteExported(flags, link, adminId, date, expireDate, usageLimit, usage):
self = ExportedInvitation(link: link, revoked: (flags & (1 << 0)) != 0, adminId: PeerId(namespace: Namespaces.Peer.CloudUser, id: adminId), date: date, expireDate: expireDate, usageLimit: usageLimit, count: usage)
self = ExportedInvitation(link: link, isPermanent: (flags & (1 << 5)) != 0, isRevoked: (flags & (1 << 0)) != 0, adminId: PeerId(namespace: Namespaces.Peer.CloudUser, id: adminId), date: date, expireDate: expireDate, usageLimit: usageLimit, count: usage)
}
}
}

View File

@ -9,11 +9,12 @@ import SyncCore
public func ensuredExistingPeerExportedInvitation(account: Account, peerId: PeerId, revokeExisted: Bool = false) -> Signal<ExportedInvitation?, NoError> {
return account.postbox.transaction { transaction -> Signal<ExportedInvitation?, NoError> in
if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) {
var flags: Int32 = (1 << 2)
if let _ = peer as? TelegramChannel {
if let cachedData = transaction.getPeerCachedData(peerId: peerId) as? CachedChannelData, cachedData.exportedInvitation != nil && !revokeExisted {
return .complete()
} else {
return account.network.request(Api.functions.messages.exportChatInvite(flags: 0, peer: inputPeer, expireDate: nil, usageLimit: nil))
return account.network.request(Api.functions.messages.exportChatInvite(flags: flags, peer: inputPeer, expireDate: nil, usageLimit: nil))
|> retryRequest
|> mapToSignal { result -> Signal<ExportedInvitation?, NoError> in
return account.postbox.transaction { transaction -> ExportedInvitation? in
@ -36,7 +37,7 @@ public func ensuredExistingPeerExportedInvitation(account: Account, peerId: Peer
if let cachedData = transaction.getPeerCachedData(peerId: peerId) as? CachedGroupData, cachedData.exportedInvitation != nil && !revokeExisted {
return .complete()
} else {
return account.network.request(Api.functions.messages.exportChatInvite(flags: 0, peer: inputPeer, expireDate: nil, usageLimit: nil))
return account.network.request(Api.functions.messages.exportChatInvite(flags: flags, peer: inputPeer, expireDate: nil, usageLimit: nil))
|> retryRequest
|> mapToSignal { result -> Signal<ExportedInvitation?, NoError> in
return account.postbox.transaction { transaction -> ExportedInvitation? in
@ -146,7 +147,7 @@ public func editPeerExportedInvitation(account: Account, peerId: PeerId, link: S
return account.network.request(Api.functions.messages.editExportedChatInvite(flags: flags, peer: inputPeer, link: link, expireDate: expireDate, usageLimit: usageLimit))
|> mapError { _ in return EditPeerExportedInvitationError.generic }
|> map { result -> ExportedInvitation? in
if case let .exportedChatInvite(invite, recentImporters, users) = result {
if case let .exportedChatInvite(invite, users) = result {
var peers: [Peer] = []
for user in users {
let telegramUser = TelegramUser(user: user)