mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-06 05:02:54 +00:00
Update API
This commit is contained in:
@@ -1,5 +1,185 @@
|
||||
import Postbox
|
||||
|
||||
public enum ReplyMarkupButtonRequestPeerType: Codable, Equatable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case discriminator = "d"
|
||||
case user = "u"
|
||||
case group = "g"
|
||||
case channel = "c"
|
||||
}
|
||||
|
||||
enum Discriminator: Int32 {
|
||||
case user = 0
|
||||
case group = 1
|
||||
case channel = 2
|
||||
}
|
||||
|
||||
public struct User: Codable, Equatable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case isBot = "b"
|
||||
case isPremium = "p"
|
||||
}
|
||||
|
||||
public var isBot: Bool?
|
||||
public var isPremium: Bool?
|
||||
|
||||
public init(isBot: Bool?, isPremium: Bool?) {
|
||||
self.isBot = isBot
|
||||
self.isPremium = isPremium
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
self.isBot = try container.decodeIfPresent(Bool.self, forKey: .isBot)
|
||||
self.isPremium = try container.decodeIfPresent(Bool.self, forKey: .isPremium)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
try container.encodeIfPresent(self.isBot, forKey: .isBot)
|
||||
try container.encodeIfPresent(self.isPremium, forKey: .isPremium)
|
||||
}
|
||||
}
|
||||
|
||||
public struct Group: Codable, Equatable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case isCreator = "cr"
|
||||
case hasUsername = "un"
|
||||
case isForum = "fo"
|
||||
case botParticipant = "bo"
|
||||
case userAdminRights = "ur"
|
||||
case botAdminRights = "br"
|
||||
}
|
||||
|
||||
public var isCreator: Bool?
|
||||
public var hasUsername: Bool?
|
||||
public var isForum: Bool?
|
||||
public var botParticipant: Bool
|
||||
public var userAdminRights: TelegramChatAdminRights?
|
||||
public var botAdminRights: TelegramChatAdminRights?
|
||||
|
||||
public init(
|
||||
isCreator: Bool?,
|
||||
hasUsername: Bool?,
|
||||
isForum: Bool?,
|
||||
botParticipant: Bool,
|
||||
userAdminRights: TelegramChatAdminRights?,
|
||||
botAdminRights: TelegramChatAdminRights?
|
||||
) {
|
||||
self.isCreator = isCreator
|
||||
self.hasUsername = hasUsername
|
||||
self.isForum = isForum
|
||||
self.botParticipant = botParticipant
|
||||
self.userAdminRights = userAdminRights
|
||||
self.botAdminRights = botAdminRights
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
self.isCreator = try container.decodeIfPresent(Bool.self, forKey: .isCreator)
|
||||
self.hasUsername = try container.decodeIfPresent(Bool.self, forKey: .hasUsername)
|
||||
self.isForum = try container.decodeIfPresent(Bool.self, forKey: .isForum)
|
||||
self.botParticipant = try container.decode(Bool.self, forKey: .botParticipant)
|
||||
self.userAdminRights = try container.decodeIfPresent(TelegramChatAdminRights.self, forKey: .userAdminRights)
|
||||
self.botAdminRights = try container.decodeIfPresent(TelegramChatAdminRights.self, forKey: .botAdminRights)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
try container.encodeIfPresent(self.isCreator, forKey: .isCreator)
|
||||
try container.encodeIfPresent(self.hasUsername, forKey: .hasUsername)
|
||||
try container.encodeIfPresent(self.isForum, forKey: .isForum)
|
||||
try container.encode(self.botParticipant, forKey: .botParticipant)
|
||||
try container.encodeIfPresent(self.userAdminRights, forKey: .userAdminRights)
|
||||
try container.encodeIfPresent(self.botAdminRights, forKey: .botAdminRights)
|
||||
}
|
||||
}
|
||||
|
||||
public struct Channel: Codable, Equatable {
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case isCreator = "cr"
|
||||
case hasUsername = "un"
|
||||
case userAdminRights = "ur"
|
||||
case botAdminRights = "br"
|
||||
}
|
||||
|
||||
public var isCreator: Bool?
|
||||
public var hasUsername: Bool?
|
||||
public var userAdminRights: TelegramChatAdminRights?
|
||||
public var botAdminRights: TelegramChatAdminRights?
|
||||
|
||||
public init(
|
||||
isCreator: Bool?,
|
||||
hasUsername: Bool?,
|
||||
userAdminRights: TelegramChatAdminRights?,
|
||||
botAdminRights: TelegramChatAdminRights?
|
||||
) {
|
||||
self.isCreator = isCreator
|
||||
self.hasUsername = hasUsername
|
||||
self.userAdminRights = userAdminRights
|
||||
self.botAdminRights = botAdminRights
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
self.isCreator = try container.decodeIfPresent(Bool.self, forKey: .isCreator)
|
||||
self.hasUsername = try container.decodeIfPresent(Bool.self, forKey: .hasUsername)
|
||||
self.userAdminRights = try container.decodeIfPresent(TelegramChatAdminRights.self, forKey: .userAdminRights)
|
||||
self.botAdminRights = try container.decodeIfPresent(TelegramChatAdminRights.self, forKey: .botAdminRights)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
try container.encodeIfPresent(self.isCreator, forKey: .isCreator)
|
||||
try container.encodeIfPresent(self.hasUsername, forKey: .hasUsername)
|
||||
try container.encodeIfPresent(self.userAdminRights, forKey: .userAdminRights)
|
||||
try container.encodeIfPresent(self.botAdminRights, forKey: .botAdminRights)
|
||||
}
|
||||
}
|
||||
|
||||
case user(User)
|
||||
case group(Group)
|
||||
case channel(Channel)
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
switch try container.decode(Int32.self, forKey: .discriminator) {
|
||||
case Discriminator.user.rawValue:
|
||||
self = .user(try container.decode(User.self, forKey: .user))
|
||||
case Discriminator.group.rawValue:
|
||||
self = .group(try container.decode(Group.self, forKey: .group))
|
||||
case Discriminator.channel.rawValue:
|
||||
self = .channel(try container.decode(Channel.self, forKey: .channel))
|
||||
default:
|
||||
assertionFailure()
|
||||
self = .user(User(isBot: nil, isPremium: nil))
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
switch self {
|
||||
case let .user(user):
|
||||
try container.encode(Discriminator.user.rawValue, forKey: .discriminator)
|
||||
try container.encode(user, forKey: .user)
|
||||
case let .group(group):
|
||||
try container.encode(Discriminator.group.rawValue, forKey: .discriminator)
|
||||
try container.encode(group, forKey: .group)
|
||||
case let .channel(channel):
|
||||
try container.encode(Discriminator.channel.rawValue, forKey: .discriminator)
|
||||
try container.encode(channel, forKey: .channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ReplyMarkupButtonAction: PostboxCoding, Equatable {
|
||||
case text
|
||||
case url(String)
|
||||
@@ -13,6 +193,7 @@ public enum ReplyMarkupButtonAction: PostboxCoding, Equatable {
|
||||
case setupPoll(isQuiz: Bool?)
|
||||
case openUserProfile(peerId: PeerId)
|
||||
case openWebView(url: String, simple: Bool)
|
||||
case requestPeer(peerType: ReplyMarkupButtonRequestPeerType, buttonId: Int32)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("v", orElse: 0) {
|
||||
@@ -40,6 +221,8 @@ public enum ReplyMarkupButtonAction: PostboxCoding, Equatable {
|
||||
self = .openUserProfile(peerId: PeerId(decoder.decodeInt64ForKey("peerId", orElse: 0)))
|
||||
case 11:
|
||||
self = .openWebView(url: decoder.decodeStringForKey("u", orElse: ""), simple: decoder.decodeInt32ForKey("s", orElse: 0) != 0)
|
||||
case 12:
|
||||
self = .requestPeer(peerType: decoder.decode(ReplyMarkupButtonRequestPeerType.self, forKey: "pt") ?? ReplyMarkupButtonRequestPeerType.user(ReplyMarkupButtonRequestPeerType.User(isBot: nil, isPremium: nil)), buttonId: decoder.decodeInt32ForKey("b", orElse: 0))
|
||||
default:
|
||||
self = .text
|
||||
}
|
||||
@@ -86,6 +269,10 @@ public enum ReplyMarkupButtonAction: PostboxCoding, Equatable {
|
||||
encoder.encodeInt32(11, forKey: "v")
|
||||
encoder.encodeString(url, forKey: "u")
|
||||
encoder.encodeInt32(simple ? 1 : 0, forKey: "s")
|
||||
case let .requestPeer(peerType, buttonId):
|
||||
encoder.encodeInt32(12, forKey: "v")
|
||||
encoder.encodeInt32(buttonId, forKey: "b")
|
||||
encoder.encode(peerType, forKey: "pt")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public struct TelegramChatAdminRightsFlags: OptionSet, Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct TelegramChatAdminRights: PostboxCoding, Equatable {
|
||||
public struct TelegramChatAdminRights: PostboxCoding, Codable, Equatable {
|
||||
public let rights: TelegramChatAdminRightsFlags
|
||||
|
||||
public init(rights: TelegramChatAdminRightsFlags) {
|
||||
@@ -95,10 +95,22 @@ public struct TelegramChatAdminRights: PostboxCoding, Equatable {
|
||||
self.rights = TelegramChatAdminRightsFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.rights = TelegramChatAdminRightsFlags(rawValue: try container.decode(Int32.self, forKey: "f"))
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.rights.rawValue, forKey: "f")
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.rights.rawValue, forKey: "f")
|
||||
}
|
||||
|
||||
public static func ==(lhs: TelegramChatAdminRights, rhs: TelegramChatAdminRights) -> Bool {
|
||||
return lhs.rights == rhs.rights
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
case topicEdited(components: [ForumTopicEditComponent])
|
||||
case suggestedProfilePhoto(image: TelegramMediaImage?)
|
||||
case attachMenuBotAllowed
|
||||
case requestedPeer(buttonId: Int32, peerId: PeerId)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
|
||||
@@ -178,6 +179,8 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
self = .suggestedProfilePhoto(image: decoder.decodeObjectForKey("image") as? TelegramMediaImage)
|
||||
case 31:
|
||||
self = .attachMenuBotAllowed
|
||||
case 32:
|
||||
self = .requestedPeer(buttonId: decoder.decodeInt32ForKey("b", orElse: 0), peerId: PeerId(decoder.decodeInt64ForKey("pi", orElse: 0)))
|
||||
default:
|
||||
self = .unknown
|
||||
}
|
||||
@@ -331,6 +334,10 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
}
|
||||
case .attachMenuBotAllowed:
|
||||
encoder.encodeInt32(31, forKey: "_rawValue")
|
||||
case let .requestedPeer(buttonId, peerId):
|
||||
encoder.encodeInt32(32, forKey: "_rawValue")
|
||||
encoder.encodeInt32(buttonId, forKey: "b")
|
||||
encoder.encodeInt64(peerId.toInt64(), forKey: "pi")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user