Home telegram - user
Post
Cancel

telegram - user

User in Api Layer

Api.User

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
public enum User: TypeConstructorDescription {
    case userEmpty(id: Int64)
    case user(flags: Int32, id: Int64, accessHash: Int64?, firstName: String?, lastName: String?, username: String?, phone: String?, photo: Api.UserProfilePhoto?, status: Api.UserStatus?, botInfoVersion: Int32?, restrictionReason: [Api.RestrictionReason]?, botInlinePlaceholder: String?, langCode: String?)

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .userEmpty(let id):
            if boxed {
                buffer.appendInt32(-742634630)
            }
            serializeInt64(id, buffer: buffer, boxed: false)
            break
        case .user(let flags, let id, let accessHash, let firstName, let lastName, let username, let phone, let photo, let status, let botInfoVersion, let restrictionReason, let botInlinePlaceholder, let langCode):
            if boxed {
                buffer.appendInt32(1073147056)
            }
            serializeInt32(flags, buffer: buffer, boxed: false)
            serializeInt64(id, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 0) != 0 {serializeInt64(accessHash!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 1) != 0 {serializeString(firstName!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 2) != 0 {serializeString(lastName!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 3) != 0 {serializeString(username!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 4) != 0 {serializeString(phone!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 5) != 0 {photo!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 6) != 0 {status!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 14) != 0 {serializeInt32(botInfoVersion!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 18) != 0 {buffer.appendInt32(481674261)
                buffer.appendInt32(Int32(restrictionReason!.count))
                for item in restrictionReason! {
                    item.serialize(buffer, true)
                }}
            if Int(flags) & Int(1 << 19) != 0 {serializeString(botInlinePlaceholder!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 22) != 0 {serializeString(langCode!, buffer: buffer, boxed: false)}
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .userEmpty(let id):
            return ("userEmpty", [("id", id)])
        case .user(let flags, let id, let accessHash, let firstName, let lastName, let username, let phone, let photo, let status, let botInfoVersion, let restrictionReason, let botInlinePlaceholder, let langCode):
            return ("user", [("flags", flags), ("id", id), ("accessHash", accessHash), ("firstName", firstName), ("lastName", lastName), ("username", username), ("phone", phone), ("photo", photo), ("status", status), ("botInfoVersion", botInfoVersion), ("restrictionReason", restrictionReason), ("botInlinePlaceholder", botInlinePlaceholder), ("langCode", langCode)])
        }
    }

    public static func parse_userEmpty(_ reader: BufferReader) -> User? {
        var _1: Int64?
        _1 = reader.readInt64()
        let _c1 = _1 != nil
        if _c1 {
            return Api.User.userEmpty(id: _1!)
        }
        else {
            return nil
        }
    }
    public static func parse_user(_ reader: BufferReader) -> User? {
        var _1: Int32?
        _1 = reader.readInt32()
        var _2: Int64?
        _2 = reader.readInt64()
        var _3: Int64?
        if Int(_1!) & Int(1 << 0) != 0 {_3 = reader.readInt64() }
        var _4: String?
        if Int(_1!) & Int(1 << 1) != 0 {_4 = parseString(reader) }
        var _5: String?
        if Int(_1!) & Int(1 << 2) != 0 {_5 = parseString(reader) }
        var _6: String?
        if Int(_1!) & Int(1 << 3) != 0 {_6 = parseString(reader) }
        var _7: String?
        if Int(_1!) & Int(1 << 4) != 0 {_7 = parseString(reader) }
        var _8: Api.UserProfilePhoto?
        if Int(_1!) & Int(1 << 5) != 0 {if let signature = reader.readInt32() {
            _8 = Api.parse(reader, signature: signature) as? Api.UserProfilePhoto
        } }
        var _9: Api.UserStatus?
        if Int(_1!) & Int(1 << 6) != 0 {if let signature = reader.readInt32() {
            _9 = Api.parse(reader, signature: signature) as? Api.UserStatus
        } }
        var _10: Int32?
        if Int(_1!) & Int(1 << 14) != 0 {_10 = reader.readInt32() }
        var _11: [Api.RestrictionReason]?
        if Int(_1!) & Int(1 << 18) != 0 {if let _ = reader.readInt32() {
            _11 = Api.parseVector(reader, elementSignature: 0, elementType: Api.RestrictionReason.self)
        } }
        var _12: String?
        if Int(_1!) & Int(1 << 19) != 0 {_12 = parseString(reader) }
        var _13: String?
        if Int(_1!) & Int(1 << 22) != 0 {_13 = parseString(reader) }
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = (Int(_1!) & Int(1 << 0) == 0) || _3 != nil
        let _c4 = (Int(_1!) & Int(1 << 1) == 0) || _4 != nil
        let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil
        let _c6 = (Int(_1!) & Int(1 << 3) == 0) || _6 != nil
        let _c7 = (Int(_1!) & Int(1 << 4) == 0) || _7 != nil
        let _c8 = (Int(_1!) & Int(1 << 5) == 0) || _8 != nil
        let _c9 = (Int(_1!) & Int(1 << 6) == 0) || _9 != nil
        let _c10 = (Int(_1!) & Int(1 << 14) == 0) || _10 != nil
        let _c11 = (Int(_1!) & Int(1 << 18) == 0) || _11 != nil
        let _c12 = (Int(_1!) & Int(1 << 19) == 0) || _12 != nil
        let _c13 = (Int(_1!) & Int(1 << 22) == 0) || _13 != nil
        if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 {
            return Api.User.user(flags: _1!, id: _2!, accessHash: _3, firstName: _4, lastName: _5, username: _6, phone: _7, photo: _8, status: _9, botInfoVersion: _10, restrictionReason: _11, botInlinePlaceholder: _12, langCode: _13)
        }
        else {
            return nil
        }
    }

}

Api.UserFull

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
public enum UserFull: TypeConstructorDescription {
    case userFull(flags: Int32, id: Int64, about: String?, settings: Api.PeerSettings, profilePhoto: Api.Photo?, notifySettings: Api.PeerNotifySettings, botInfo: Api.BotInfo?, pinnedMsgId: Int32?, commonChatsCount: Int32, folderId: Int32?, ttlPeriod: Int32?, themeEmoticon: String?, privateForwardName: String?)

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .userFull(let flags, let id, let about, let settings, let profilePhoto, let notifySettings, let botInfo, let pinnedMsgId, let commonChatsCount, let folderId, let ttlPeriod, let themeEmoticon, let privateForwardName):
            if boxed {
                buffer.appendInt32(-818518751)
            }
            serializeInt32(flags, buffer: buffer, boxed: false)
            serializeInt64(id, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 1) != 0 {serializeString(about!, buffer: buffer, boxed: false)}
            settings.serialize(buffer, true)
            if Int(flags) & Int(1 << 2) != 0 {profilePhoto!.serialize(buffer, true)}
            notifySettings.serialize(buffer, true)
            if Int(flags) & Int(1 << 3) != 0 {botInfo!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 6) != 0 {serializeInt32(pinnedMsgId!, buffer: buffer, boxed: false)}
            serializeInt32(commonChatsCount, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 11) != 0 {serializeInt32(folderId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 14) != 0 {serializeInt32(ttlPeriod!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 15) != 0 {serializeString(themeEmoticon!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 16) != 0 {serializeString(privateForwardName!, buffer: buffer, boxed: false)}
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .userFull(let flags, let id, let about, let settings, let profilePhoto, let notifySettings, let botInfo, let pinnedMsgId, let commonChatsCount, let folderId, let ttlPeriod, let themeEmoticon, let privateForwardName):
            return ("userFull", [("flags", flags), ("id", id), ("about", about), ("settings", settings), ("profilePhoto", profilePhoto), ("notifySettings", notifySettings), ("botInfo", botInfo), ("pinnedMsgId", pinnedMsgId), ("commonChatsCount", commonChatsCount), ("folderId", folderId), ("ttlPeriod", ttlPeriod), ("themeEmoticon", themeEmoticon), ("privateForwardName", privateForwardName)])
        }
    }

    public static func parse_userFull(_ reader: BufferReader) -> UserFull? {
        var _1: Int32?
        _1 = reader.readInt32()
        var _2: Int64?
        _2 = reader.readInt64()
        var _3: String?
        if Int(_1!) & Int(1 << 1) != 0 {_3 = parseString(reader) }
        var _4: Api.PeerSettings?
        if let signature = reader.readInt32() {
            _4 = Api.parse(reader, signature: signature) as? Api.PeerSettings
        }
        var _5: Api.Photo?
        if Int(_1!) & Int(1 << 2) != 0 {if let signature = reader.readInt32() {
            _5 = Api.parse(reader, signature: signature) as? Api.Photo
        } }
        var _6: Api.PeerNotifySettings?
        if let signature = reader.readInt32() {
            _6 = Api.parse(reader, signature: signature) as? Api.PeerNotifySettings
        }
        var _7: Api.BotInfo?
        if Int(_1!) & Int(1 << 3) != 0 {if let signature = reader.readInt32() {
            _7 = Api.parse(reader, signature: signature) as? Api.BotInfo
        } }
        var _8: Int32?
        if Int(_1!) & Int(1 << 6) != 0 {_8 = reader.readInt32() }
        var _9: Int32?
        _9 = reader.readInt32()
        var _10: Int32?
        if Int(_1!) & Int(1 << 11) != 0 {_10 = reader.readInt32() }
        var _11: Int32?
        if Int(_1!) & Int(1 << 14) != 0 {_11 = reader.readInt32() }
        var _12: String?
        if Int(_1!) & Int(1 << 15) != 0 {_12 = parseString(reader) }
        var _13: String?
        if Int(_1!) & Int(1 << 16) != 0 {_13 = parseString(reader) }
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil
        let _c4 = _4 != nil
        let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil
        let _c6 = _6 != nil
        let _c7 = (Int(_1!) & Int(1 << 3) == 0) || _7 != nil
        let _c8 = (Int(_1!) & Int(1 << 6) == 0) || _8 != nil
        let _c9 = _9 != nil
        let _c10 = (Int(_1!) & Int(1 << 11) == 0) || _10 != nil
        let _c11 = (Int(_1!) & Int(1 << 14) == 0) || _11 != nil
        let _c12 = (Int(_1!) & Int(1 << 15) == 0) || _12 != nil
        let _c13 = (Int(_1!) & Int(1 << 16) == 0) || _13 != nil
        if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 {
            return Api.UserFull.userFull(flags: _1!, id: _2!, about: _3, settings: _4!, profilePhoto: _5, notifySettings: _6!, botInfo: _7, pinnedMsgId: _8, commonChatsCount: _9!, folderId: _10, ttlPeriod: _11, themeEmoticon: _12, privateForwardName: _13)
        }
        else {
            return nil
        }
    }

}

Api.users.UserFull

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public extension Api {
    public struct users {
        public enum UserFull: TypeConstructorDescription {
            case userFull(fullUser: Api.UserFull, chats: [Api.Chat], users: [Api.User])
            
            public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
                switch self {
                case .userFull(let fullUser, let chats, let users):
                    if boxed {
                        buffer.appendInt32(997004590)
                    }
                    fullUser.serialize(buffer, true)
                    buffer.appendInt32(481674261)
                    buffer.appendInt32(Int32(chats.count))
                    for item in chats {
                        item.serialize(buffer, true)
                    }
                    buffer.appendInt32(481674261)
                    buffer.appendInt32(Int32(users.count))
                    for item in users {
                        item.serialize(buffer, true)
                    }
                    break
                }
            }
            
            public func descriptionFields() -> (String, [(String, Any)]) {
                switch self {
                case .userFull(let fullUser, let chats, let users):
                    return ("userFull", [("fullUser", fullUser), ("chats", chats), ("users", users)])
                }
            }
            
            public static func parse_userFull(_ reader: BufferReader) -> UserFull? {
                var _1: Api.UserFull?
                if let signature = reader.readInt32() {
                    _1 = Api.parse(reader, signature: signature) as? Api.UserFull
                }
                var _2: [Api.Chat]?
                if let _ = reader.readInt32() {
                    _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self)
                }
                var _3: [Api.User]?
                if let _ = reader.readInt32() {
                    _3 = 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.users.UserFull.userFull(fullUser: _1!, chats: _2!, users: _3!)
                }
                else {
                    return nil
                }
            }
            
        }
    }
}

Api.Peer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
public enum Peer: TypeConstructorDescription {
    case peerUser(userId: Int64)
    case peerChat(chatId: Int64)
    case peerChannel(channelId: Int64)

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .peerUser(let userId):
            if boxed {
                buffer.appendInt32(1498486562)
            }
            serializeInt64(userId, buffer: buffer, boxed: false)
            break
        case .peerChat(let chatId):
            if boxed {
                buffer.appendInt32(918946202)
            }
            serializeInt64(chatId, buffer: buffer, boxed: false)
            break
        case .peerChannel(let channelId):
            if boxed {
                buffer.appendInt32(-1566230754)
            }
            serializeInt64(channelId, buffer: buffer, boxed: false)
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .peerUser(let userId):
            return ("peerUser", [("userId", userId)])
        case .peerChat(let chatId):
            return ("peerChat", [("chatId", chatId)])
        case .peerChannel(let channelId):
            return ("peerChannel", [("channelId", channelId)])
        }
    }

    public static func parse_peerUser(_ reader: BufferReader) -> Peer? {
        var _1: Int64?
        _1 = reader.readInt64()
        let _c1 = _1 != nil
        if _c1 {
            return Api.Peer.peerUser(userId: _1!)
        }
        else {
            return nil
        }
    }
    public static func parse_peerChat(_ reader: BufferReader) -> Peer? {
        var _1: Int64?
        _1 = reader.readInt64()
        let _c1 = _1 != nil
        if _c1 {
            return Api.Peer.peerChat(chatId: _1!)
        }
        else {
            return nil
        }
    }
    public static func parse_peerChannel(_ reader: BufferReader) -> Peer? {
        var _1: Int64?
        _1 = reader.readInt64()
        let _c1 = _1 != nil
        if _c1 {
            return Api.Peer.peerChannel(channelId: _1!)
        }
        else {
            return nil
        }
    }

}

Api.InputUser

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
public enum InputUser: TypeConstructorDescription {
    case inputUserEmpty
    case inputUserSelf
    case inputUser(userId: Int64, accessHash: Int64)
    case inputUserFromMessage(peer: Api.InputPeer, msgId: Int32, userId: Int64)

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .inputUserEmpty:
            if boxed {
                buffer.appendInt32(-1182234929)
            }

            break
        case .inputUserSelf:
            if boxed {
                buffer.appendInt32(-138301121)
            }

            break
        case .inputUser(let userId, let accessHash):
            if boxed {
                buffer.appendInt32(-233744186)
            }
            serializeInt64(userId, buffer: buffer, boxed: false)
            serializeInt64(accessHash, buffer: buffer, boxed: false)
            break
        case .inputUserFromMessage(let peer, let msgId, let userId):
            if boxed {
                buffer.appendInt32(497305826)
            }
            peer.serialize(buffer, true)
            serializeInt32(msgId, buffer: buffer, boxed: false)
            serializeInt64(userId, buffer: buffer, boxed: false)
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .inputUserEmpty:
            return ("inputUserEmpty", [])
        case .inputUserSelf:
            return ("inputUserSelf", [])
        case .inputUser(let userId, let accessHash):
            return ("inputUser", [("userId", userId), ("accessHash", accessHash)])
        case .inputUserFromMessage(let peer, let msgId, let userId):
            return ("inputUserFromMessage", [("peer", peer), ("msgId", msgId), ("userId", userId)])
        }
    }

    public static func parse_inputUserEmpty(_ reader: BufferReader) -> InputUser? {
        return Api.InputUser.inputUserEmpty
    }
    public static func parse_inputUserSelf(_ reader: BufferReader) -> InputUser? {
        return Api.InputUser.inputUserSelf
    }
    public static func parse_inputUser(_ reader: BufferReader) -> InputUser? {
        var _1: Int64?
        _1 = reader.readInt64()
        var _2: Int64?
        _2 = reader.readInt64()
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        if _c1 && _c2 {
            return Api.InputUser.inputUser(userId: _1!, accessHash: _2!)
        }
        else {
            return nil
        }
    }
    public static func parse_inputUserFromMessage(_ reader: BufferReader) -> InputUser? {
        var _1: Api.InputPeer?
        if let signature = reader.readInt32() {
            _1 = Api.parse(reader, signature: signature) as? Api.InputPeer
        }
        var _2: Int32?
        _2 = reader.readInt32()
        var _3: Int64?
        _3 = reader.readInt64()
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = _3 != nil
        if _c1 && _c2 && _c3 {
            return Api.InputUser.inputUserFromMessage(peer: _1!, msgId: _2!, userId: _3!)
        }
        else {
            return nil
        }
    }

}

Peer to Api.InputUser

1
2
3
4
5
6
7
func apiInputUser(_ peer: Peer) -> Api.InputUser? {
    if let user = peer as? TelegramUser, let accessHash = user.accessHash {
        return Api.InputUser.inputUser(userId: user.id.id._internalGetInt64Value(), accessHash: accessHash.value)
    } else {
        return nil
    }
}

Peer to Api.InputPeer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
func apiInputPeer(_ peer: Peer) -> Api.InputPeer? {
    switch peer {
    case let user as TelegramUser where user.accessHash != nil:
        return Api.InputPeer.inputPeerUser(userId: user.id.id._internalGetInt64Value(), accessHash: user.accessHash!.value)
    case let group as TelegramGroup:
        return Api.InputPeer.inputPeerChat(chatId: group.id.id._internalGetInt64Value())
    case let channel as TelegramChannel:
        if let accessHash = channel.accessHash {
            return Api.InputPeer.inputPeerChannel(channelId: channel.id.id._internalGetInt64Value(), accessHash: accessHash.value)
        } else {
            return nil
        }
    default:
        return nil
    }
}

func apiInputPeerOrSelf(_ peer: Peer, accountPeerId: PeerId) -> Api.InputPeer? {
    if peer.id == accountPeerId {
        return .inputPeerSelf
    }
    return apiInputPeer(peer)
}

PeerReference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public enum PeerReference: PostboxCoding, Hashable, Equatable {
    case user(id: Int64, accessHash: Int64)
    case group(id: Int64)
    case channel(id: Int64, accessHash: Int64)
    public init?(_ peer: Peer) {
        switch peer {
            case let user as TelegramUser:
                if let accessHash = user.accessHash {
                    self = .user(id: user.id.id._internalGetInt64Value(), accessHash: accessHash.value)
                } else {
                    return nil
                }
            case let group as TelegramGroup:
                self = .group(id: group.id.id._internalGetInt64Value())
            case let channel as TelegramChannel:
                if let accessHash = channel.accessHash {
                    self = .channel(id: channel.id.id._internalGetInt64Value(), accessHash: accessHash.value)
                } else {
                    return nil
                }
            default:
                return nil
        }
    }     
}    

Api.functions.users

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public struct users {
    public static func getUsers(id: [Api.InputUser]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.User]>) {
        let buffer = Buffer()
        buffer.appendInt32(227648840)
        buffer.appendInt32(481674261)
        buffer.appendInt32(Int32(id.count))
        for item in id {
            item.serialize(buffer, true)
        }
        return (FunctionDescription(name: "users.getUsers", parameters: [("id", id)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Api.User]? in
            let reader = BufferReader(buffer)
            var result: [Api.User]?
            if let _ = reader.readInt32() {
                result = Api.parseVector(reader, elementSignature: 0, elementType: Api.User.self)
            }
            return result
        })
    }

    public static func getFullUser(id: Api.InputUser) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.users.UserFull>) {
        let buffer = Buffer()
        buffer.appendInt32(-1240508136)
        id.serialize(buffer, true)
        return (FunctionDescription(name: "users.getFullUser", parameters: [("id", id)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.users.UserFull? in
            let reader = BufferReader(buffer)
            var result: Api.users.UserFull?
            if let signature = reader.readInt32() {
                result = Api.parse(reader, signature: signature) as? Api.users.UserFull
            }
            return result
        })
    }

    public static func setSecureValueErrors(id: Api.InputUser, errors: [Api.SecureValueError]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
        let buffer = Buffer()
        buffer.appendInt32(-1865902923)
        id.serialize(buffer, true)
        buffer.appendInt32(481674261)
        buffer.appendInt32(Int32(errors.count))
        for item in errors {
            item.serialize(buffer, true)
        }
        return (FunctionDescription(name: "users.setSecureValueErrors", parameters: [("id", id), ("errors", errors)]), 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
        })
    }
}

Api.Chat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
public enum Chat: TypeConstructorDescription {
    case chatEmpty(id: Int64)
    case chat(flags: Int32, id: Int64, title: String, photo: Api.ChatPhoto, participantsCount: Int32, date: Int32, version: Int32, migratedTo: Api.InputChannel?, adminRights: Api.ChatAdminRights?, defaultBannedRights: Api.ChatBannedRights?)
    case chatForbidden(id: Int64, title: String)
    case channel(flags: Int32, id: Int64, accessHash: Int64?, title: String, username: String?, photo: Api.ChatPhoto, date: Int32, restrictionReason: [Api.RestrictionReason]?, adminRights: Api.ChatAdminRights?, bannedRights: Api.ChatBannedRights?, defaultBannedRights: Api.ChatBannedRights?, participantsCount: Int32?)
    case channelForbidden(flags: Int32, id: Int64, accessHash: Int64, title: String, untilDate: Int32?)

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .chatEmpty(let id):
            if boxed {
                buffer.appendInt32(693512293)
            }
            serializeInt64(id, buffer: buffer, boxed: false)
            break
        case .chat(let flags, let id, let title, let photo, let participantsCount, let date, let version, let migratedTo, let adminRights, let defaultBannedRights):
            if boxed {
                buffer.appendInt32(1103884886)
            }
            serializeInt32(flags, buffer: buffer, boxed: false)
            serializeInt64(id, buffer: buffer, boxed: false)
            serializeString(title, buffer: buffer, boxed: false)
            photo.serialize(buffer, true)
            serializeInt32(participantsCount, buffer: buffer, boxed: false)
            serializeInt32(date, buffer: buffer, boxed: false)
            serializeInt32(version, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 6) != 0 {migratedTo!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 14) != 0 {adminRights!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 18) != 0 {defaultBannedRights!.serialize(buffer, true)}
            break
        case .chatForbidden(let id, let title):
            if boxed {
                buffer.appendInt32(1704108455)
            }
            serializeInt64(id, buffer: buffer, boxed: false)
            serializeString(title, buffer: buffer, boxed: false)
            break
        case .channel(let flags, let id, let accessHash, let title, let username, let photo, let date, let restrictionReason, let adminRights, let bannedRights, let defaultBannedRights, let participantsCount):
            if boxed {
                buffer.appendInt32(-2107528095)
            }
            serializeInt32(flags, buffer: buffer, boxed: false)
            serializeInt64(id, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 13) != 0 {serializeInt64(accessHash!, buffer: buffer, boxed: false)}
            serializeString(title, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 6) != 0 {serializeString(username!, buffer: buffer, boxed: false)}
            photo.serialize(buffer, true)
            serializeInt32(date, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 9) != 0 {buffer.appendInt32(481674261)
                buffer.appendInt32(Int32(restrictionReason!.count))
                for item in restrictionReason! {
                    item.serialize(buffer, true)
                }}
            if Int(flags) & Int(1 << 14) != 0 {adminRights!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 15) != 0 {bannedRights!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 18) != 0 {defaultBannedRights!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 17) != 0 {serializeInt32(participantsCount!, buffer: buffer, boxed: false)}
            break
        case .channelForbidden(let flags, let id, let accessHash, let title, let untilDate):
            if boxed {
                buffer.appendInt32(399807445)
            }
            serializeInt32(flags, buffer: buffer, boxed: false)
            serializeInt64(id, buffer: buffer, boxed: false)
            serializeInt64(accessHash, buffer: buffer, boxed: false)
            serializeString(title, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 16) != 0 {serializeInt32(untilDate!, buffer: buffer, boxed: false)}
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .chatEmpty(let id):
            return ("chatEmpty", [("id", id)])
        case .chat(let flags, let id, let title, let photo, let participantsCount, let date, let version, let migratedTo, let adminRights, let defaultBannedRights):
            return ("chat", [("flags", flags), ("id", id), ("title", title), ("photo", photo), ("participantsCount", participantsCount), ("date", date), ("version", version), ("migratedTo", migratedTo), ("adminRights", adminRights), ("defaultBannedRights", defaultBannedRights)])
        case .chatForbidden(let id, let title):
            return ("chatForbidden", [("id", id), ("title", title)])
        case .channel(let flags, let id, let accessHash, let title, let username, let photo, let date, let restrictionReason, let adminRights, let bannedRights, let defaultBannedRights, let participantsCount):
            return ("channel", [("flags", flags), ("id", id), ("accessHash", accessHash), ("title", title), ("username", username), ("photo", photo), ("date", date), ("restrictionReason", restrictionReason), ("adminRights", adminRights), ("bannedRights", bannedRights), ("defaultBannedRights", defaultBannedRights), ("participantsCount", participantsCount)])
        case .channelForbidden(let flags, let id, let accessHash, let title, let untilDate):
            return ("channelForbidden", [("flags", flags), ("id", id), ("accessHash", accessHash), ("title", title), ("untilDate", untilDate)])
        }
    }

    public static func parse_chatEmpty(_ reader: BufferReader) -> Chat? {
        var _1: Int64?
        _1 = reader.readInt64()
        let _c1 = _1 != nil
        if _c1 {
            return Api.Chat.chatEmpty(id: _1!)
        }
        else {
            return nil
        }
    }
    public static func parse_chat(_ reader: BufferReader) -> Chat? {
        var _1: Int32?
        _1 = reader.readInt32()
        var _2: Int64?
        _2 = reader.readInt64()
        var _3: String?
        _3 = parseString(reader)
        var _4: Api.ChatPhoto?
        if let signature = reader.readInt32() {
            _4 = Api.parse(reader, signature: signature) as? Api.ChatPhoto
        }
        var _5: Int32?
        _5 = reader.readInt32()
        var _6: Int32?
        _6 = reader.readInt32()
        var _7: Int32?
        _7 = reader.readInt32()
        var _8: Api.InputChannel?
        if Int(_1!) & Int(1 << 6) != 0 {if let signature = reader.readInt32() {
            _8 = Api.parse(reader, signature: signature) as? Api.InputChannel
        } }
        var _9: Api.ChatAdminRights?
        if Int(_1!) & Int(1 << 14) != 0 {if let signature = reader.readInt32() {
            _9 = Api.parse(reader, signature: signature) as? Api.ChatAdminRights
        } }
        var _10: Api.ChatBannedRights?
        if Int(_1!) & Int(1 << 18) != 0 {if let signature = reader.readInt32() {
            _10 = Api.parse(reader, signature: signature) as? Api.ChatBannedRights
        } }
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = _3 != nil
        let _c4 = _4 != nil
        let _c5 = _5 != nil
        let _c6 = _6 != nil
        let _c7 = _7 != nil
        let _c8 = (Int(_1!) & Int(1 << 6) == 0) || _8 != nil
        let _c9 = (Int(_1!) & Int(1 << 14) == 0) || _9 != nil
        let _c10 = (Int(_1!) & Int(1 << 18) == 0) || _10 != nil
        if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 {
            return Api.Chat.chat(flags: _1!, id: _2!, title: _3!, photo: _4!, participantsCount: _5!, date: _6!, version: _7!, migratedTo: _8, adminRights: _9, defaultBannedRights: _10)
        }
        else {
            return nil
        }
    }
    public static func parse_chatForbidden(_ reader: BufferReader) -> Chat? {
        var _1: Int64?
        _1 = reader.readInt64()
        var _2: String?
        _2 = parseString(reader)
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        if _c1 && _c2 {
            return Api.Chat.chatForbidden(id: _1!, title: _2!)
        }
        else {
            return nil
        }
    }
    public static func parse_channel(_ reader: BufferReader) -> Chat? {
        var _1: Int32?
        _1 = reader.readInt32()
        var _2: Int64?
        _2 = reader.readInt64()
        var _3: Int64?
        if Int(_1!) & Int(1 << 13) != 0 {_3 = reader.readInt64() }
        var _4: String?
        _4 = parseString(reader)
        var _5: String?
        if Int(_1!) & Int(1 << 6) != 0 {_5 = parseString(reader) }
        var _6: Api.ChatPhoto?
        if let signature = reader.readInt32() {
            _6 = Api.parse(reader, signature: signature) as? Api.ChatPhoto
        }
        var _7: Int32?
        _7 = reader.readInt32()
        var _8: [Api.RestrictionReason]?
        if Int(_1!) & Int(1 << 9) != 0 {if let _ = reader.readInt32() {
            _8 = Api.parseVector(reader, elementSignature: 0, elementType: Api.RestrictionReason.self)
        } }
        var _9: Api.ChatAdminRights?
        if Int(_1!) & Int(1 << 14) != 0 {if let signature = reader.readInt32() {
            _9 = Api.parse(reader, signature: signature) as? Api.ChatAdminRights
        } }
        var _10: Api.ChatBannedRights?
        if Int(_1!) & Int(1 << 15) != 0 {if let signature = reader.readInt32() {
            _10 = Api.parse(reader, signature: signature) as? Api.ChatBannedRights
        } }
        var _11: Api.ChatBannedRights?
        if Int(_1!) & Int(1 << 18) != 0 {if let signature = reader.readInt32() {
            _11 = Api.parse(reader, signature: signature) as? Api.ChatBannedRights
        } }
        var _12: Int32?
        if Int(_1!) & Int(1 << 17) != 0 {_12 = reader.readInt32() }
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = (Int(_1!) & Int(1 << 13) == 0) || _3 != nil
        let _c4 = _4 != nil
        let _c5 = (Int(_1!) & Int(1 << 6) == 0) || _5 != nil
        let _c6 = _6 != nil
        let _c7 = _7 != nil
        let _c8 = (Int(_1!) & Int(1 << 9) == 0) || _8 != nil
        let _c9 = (Int(_1!) & Int(1 << 14) == 0) || _9 != nil
        let _c10 = (Int(_1!) & Int(1 << 15) == 0) || _10 != nil
        let _c11 = (Int(_1!) & Int(1 << 18) == 0) || _11 != nil
        let _c12 = (Int(_1!) & Int(1 << 17) == 0) || _12 != nil
        if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 {
            return Api.Chat.channel(flags: _1!, id: _2!, accessHash: _3, title: _4!, username: _5, photo: _6!, date: _7!, restrictionReason: _8, adminRights: _9, bannedRights: _10, defaultBannedRights: _11, participantsCount: _12)
        }
        else {
            return nil
        }
    }
    public static func parse_channelForbidden(_ reader: BufferReader) -> Chat? {
        var _1: Int32?
        _1 = reader.readInt32()
        var _2: Int64?
        _2 = reader.readInt64()
        var _3: Int64?
        _3 = reader.readInt64()
        var _4: String?
        _4 = parseString(reader)
        var _5: Int32?
        if Int(_1!) & Int(1 << 16) != 0 {_5 = reader.readInt32() }
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = _3 != nil
        let _c4 = _4 != nil
        let _c5 = (Int(_1!) & Int(1 << 16) == 0) || _5 != nil
        if _c1 && _c2 && _c3 && _c4 && _c5 {
            return Api.Chat.channelForbidden(flags: _1!, id: _2!, accessHash: _3!, title: _4!, untilDate: _5)
        }
        else {
            return nil
        }
    }

}

Api.messages.Chats

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
public enum Chats: TypeConstructorDescription {
    case chats(chats: [Api.Chat])
    case chatsSlice(count: Int32, chats: [Api.Chat])

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .chats(let chats):
            if boxed {
                buffer.appendInt32(1694474197)
            }
            buffer.appendInt32(481674261)
            buffer.appendInt32(Int32(chats.count))
            for item in chats {
                item.serialize(buffer, true)
            }
            break
        case .chatsSlice(let count, let chats):
            if boxed {
                buffer.appendInt32(-1663561404)
            }
            serializeInt32(count, buffer: buffer, boxed: false)
            buffer.appendInt32(481674261)
            buffer.appendInt32(Int32(chats.count))
            for item in chats {
                item.serialize(buffer, true)
            }
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .chats(let chats):
            return ("chats", [("chats", chats)])
        case .chatsSlice(let count, let chats):
            return ("chatsSlice", [("count", count), ("chats", chats)])
        }
    }

    public static func parse_chats(_ reader: BufferReader) -> Chats? {
        var _1: [Api.Chat]?
        if let _ = reader.readInt32() {
            _1 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self)
        }
        let _c1 = _1 != nil
        if _c1 {
            return Api.messages.Chats.chats(chats: _1!)
        }
        else {
            return nil
        }
    }
    public static func parse_chatsSlice(_ reader: BufferReader) -> Chats? {
        var _1: Int32?
        _1 = reader.readInt32()
        var _2: [Api.Chat]?
        if let _ = reader.readInt32() {
            _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self)
        }
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        if _c1 && _c2 {
            return Api.messages.Chats.chatsSlice(count: _1!, chats: _2!)
        }
        else {
            return nil
        }
    }

}

Api.ChatFull

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
public enum ChatFull: TypeConstructorDescription {
    case chatFull(flags: Int32, id: Int64, about: String, participants: Api.ChatParticipants, chatPhoto: Api.Photo?, notifySettings: Api.PeerNotifySettings, exportedInvite: Api.ExportedChatInvite?, botInfo: [Api.BotInfo]?, pinnedMsgId: Int32?, folderId: Int32?, call: Api.InputGroupCall?, ttlPeriod: Int32?, groupcallDefaultJoinAs: Api.Peer?, themeEmoticon: String?, requestsPending: Int32?, recentRequesters: [Int64]?, availableReactions: [String]?)
    case channelFull(flags: Int32, id: Int64, about: String, participantsCount: Int32?, adminsCount: Int32?, kickedCount: Int32?, bannedCount: Int32?, onlineCount: Int32?, readInboxMaxId: Int32, readOutboxMaxId: Int32, unreadCount: Int32, chatPhoto: Api.Photo, notifySettings: Api.PeerNotifySettings, exportedInvite: Api.ExportedChatInvite?, botInfo: [Api.BotInfo], migratedFromChatId: Int64?, migratedFromMaxId: Int32?, pinnedMsgId: Int32?, stickerset: Api.StickerSet?, availableMinId: Int32?, folderId: Int32?, linkedChatId: Int64?, location: Api.ChannelLocation?, slowmodeSeconds: Int32?, slowmodeNextSendDate: Int32?, statsDc: Int32?, pts: Int32, call: Api.InputGroupCall?, ttlPeriod: Int32?, pendingSuggestions: [String]?, groupcallDefaultJoinAs: Api.Peer?, themeEmoticon: String?, requestsPending: Int32?, recentRequesters: [Int64]?, defaultSendAs: Api.Peer?, availableReactions: [String]?)

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .chatFull(let flags, let id, let about, let participants, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let pinnedMsgId, let folderId, let call, let ttlPeriod, let groupcallDefaultJoinAs, let themeEmoticon, let requestsPending, let recentRequesters, let availableReactions):
            if boxed {
                buffer.appendInt32(-779165146)
            }
            serializeInt32(flags, buffer: buffer, boxed: false)
            serializeInt64(id, buffer: buffer, boxed: false)
            serializeString(about, buffer: buffer, boxed: false)
            participants.serialize(buffer, true)
            if Int(flags) & Int(1 << 2) != 0 {chatPhoto!.serialize(buffer, true)}
            notifySettings.serialize(buffer, true)
            if Int(flags) & Int(1 << 13) != 0 {exportedInvite!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 3) != 0 {buffer.appendInt32(481674261)
                buffer.appendInt32(Int32(botInfo!.count))
                for item in botInfo! {
                    item.serialize(buffer, true)
                }}
            if Int(flags) & Int(1 << 6) != 0 {serializeInt32(pinnedMsgId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 11) != 0 {serializeInt32(folderId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 12) != 0 {call!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 14) != 0 {serializeInt32(ttlPeriod!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 15) != 0 {groupcallDefaultJoinAs!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 16) != 0 {serializeString(themeEmoticon!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 17) != 0 {serializeInt32(requestsPending!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 17) != 0 {buffer.appendInt32(481674261)
                buffer.appendInt32(Int32(recentRequesters!.count))
                for item in recentRequesters! {
                    serializeInt64(item, buffer: buffer, boxed: false)
                }}
            if Int(flags) & Int(1 << 18) != 0 {buffer.appendInt32(481674261)
                buffer.appendInt32(Int32(availableReactions!.count))
                for item in availableReactions! {
                    serializeString(item, buffer: buffer, boxed: false)
                }}
            break
        case .channelFull(let flags, let id, let about, let participantsCount, let adminsCount, let kickedCount, let bannedCount, let onlineCount, let readInboxMaxId, let readOutboxMaxId, let unreadCount, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let migratedFromChatId, let migratedFromMaxId, let pinnedMsgId, let stickerset, let availableMinId, let folderId, let linkedChatId, let location, let slowmodeSeconds, let slowmodeNextSendDate, let statsDc, let pts, let call, let ttlPeriod, let pendingSuggestions, let groupcallDefaultJoinAs, let themeEmoticon, let requestsPending, let recentRequesters, let defaultSendAs, let availableReactions):
            if boxed {
                buffer.appendInt32(-516145888)
            }
            serializeInt32(flags, buffer: buffer, boxed: false)
            serializeInt64(id, buffer: buffer, boxed: false)
            serializeString(about, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 0) != 0 {serializeInt32(participantsCount!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 1) != 0 {serializeInt32(adminsCount!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 2) != 0 {serializeInt32(kickedCount!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 2) != 0 {serializeInt32(bannedCount!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 13) != 0 {serializeInt32(onlineCount!, buffer: buffer, boxed: false)}
            serializeInt32(readInboxMaxId, buffer: buffer, boxed: false)
            serializeInt32(readOutboxMaxId, buffer: buffer, boxed: false)
            serializeInt32(unreadCount, buffer: buffer, boxed: false)
            chatPhoto.serialize(buffer, true)
            notifySettings.serialize(buffer, true)
            if Int(flags) & Int(1 << 23) != 0 {exportedInvite!.serialize(buffer, true)}
            buffer.appendInt32(481674261)
            buffer.appendInt32(Int32(botInfo.count))
            for item in botInfo {
                item.serialize(buffer, true)
            }
            if Int(flags) & Int(1 << 4) != 0 {serializeInt64(migratedFromChatId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 4) != 0 {serializeInt32(migratedFromMaxId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 5) != 0 {serializeInt32(pinnedMsgId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 8) != 0 {stickerset!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 9) != 0 {serializeInt32(availableMinId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 11) != 0 {serializeInt32(folderId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 14) != 0 {serializeInt64(linkedChatId!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 15) != 0 {location!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 17) != 0 {serializeInt32(slowmodeSeconds!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 18) != 0 {serializeInt32(slowmodeNextSendDate!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 12) != 0 {serializeInt32(statsDc!, buffer: buffer, boxed: false)}
            serializeInt32(pts, buffer: buffer, boxed: false)
            if Int(flags) & Int(1 << 21) != 0 {call!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 24) != 0 {serializeInt32(ttlPeriod!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 25) != 0 {buffer.appendInt32(481674261)
                buffer.appendInt32(Int32(pendingSuggestions!.count))
                for item in pendingSuggestions! {
                    serializeString(item, buffer: buffer, boxed: false)
                }}
            if Int(flags) & Int(1 << 26) != 0 {groupcallDefaultJoinAs!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 27) != 0 {serializeString(themeEmoticon!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 28) != 0 {serializeInt32(requestsPending!, buffer: buffer, boxed: false)}
            if Int(flags) & Int(1 << 28) != 0 {buffer.appendInt32(481674261)
                buffer.appendInt32(Int32(recentRequesters!.count))
                for item in recentRequesters! {
                    serializeInt64(item, buffer: buffer, boxed: false)
                }}
            if Int(flags) & Int(1 << 29) != 0 {defaultSendAs!.serialize(buffer, true)}
            if Int(flags) & Int(1 << 30) != 0 {buffer.appendInt32(481674261)
                buffer.appendInt32(Int32(availableReactions!.count))
                for item in availableReactions! {
                    serializeString(item, buffer: buffer, boxed: false)
                }}
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .chatFull(let flags, let id, let about, let participants, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let pinnedMsgId, let folderId, let call, let ttlPeriod, let groupcallDefaultJoinAs, let themeEmoticon, let requestsPending, let recentRequesters, let availableReactions):
            return ("chatFull", [("flags", flags), ("id", id), ("about", about), ("participants", participants), ("chatPhoto", chatPhoto), ("notifySettings", notifySettings), ("exportedInvite", exportedInvite), ("botInfo", botInfo), ("pinnedMsgId", pinnedMsgId), ("folderId", folderId), ("call", call), ("ttlPeriod", ttlPeriod), ("groupcallDefaultJoinAs", groupcallDefaultJoinAs), ("themeEmoticon", themeEmoticon), ("requestsPending", requestsPending), ("recentRequesters", recentRequesters), ("availableReactions", availableReactions)])
        case .channelFull(let flags, let id, let about, let participantsCount, let adminsCount, let kickedCount, let bannedCount, let onlineCount, let readInboxMaxId, let readOutboxMaxId, let unreadCount, let chatPhoto, let notifySettings, let exportedInvite, let botInfo, let migratedFromChatId, let migratedFromMaxId, let pinnedMsgId, let stickerset, let availableMinId, let folderId, let linkedChatId, let location, let slowmodeSeconds, let slowmodeNextSendDate, let statsDc, let pts, let call, let ttlPeriod, let pendingSuggestions, let groupcallDefaultJoinAs, let themeEmoticon, let requestsPending, let recentRequesters, let defaultSendAs, let availableReactions):
            return ("channelFull", [("flags", flags), ("id", id), ("about", about), ("participantsCount", participantsCount), ("adminsCount", adminsCount), ("kickedCount", kickedCount), ("bannedCount", bannedCount), ("onlineCount", onlineCount), ("readInboxMaxId", readInboxMaxId), ("readOutboxMaxId", readOutboxMaxId), ("unreadCount", unreadCount), ("chatPhoto", chatPhoto), ("notifySettings", notifySettings), ("exportedInvite", exportedInvite), ("botInfo", botInfo), ("migratedFromChatId", migratedFromChatId), ("migratedFromMaxId", migratedFromMaxId), ("pinnedMsgId", pinnedMsgId), ("stickerset", stickerset), ("availableMinId", availableMinId), ("folderId", folderId), ("linkedChatId", linkedChatId), ("location", location), ("slowmodeSeconds", slowmodeSeconds), ("slowmodeNextSendDate", slowmodeNextSendDate), ("statsDc", statsDc), ("pts", pts), ("call", call), ("ttlPeriod", ttlPeriod), ("pendingSuggestions", pendingSuggestions), ("groupcallDefaultJoinAs", groupcallDefaultJoinAs), ("themeEmoticon", themeEmoticon), ("requestsPending", requestsPending), ("recentRequesters", recentRequesters), ("defaultSendAs", defaultSendAs), ("availableReactions", availableReactions)])
        }
    }

    public static func parse_chatFull(_ reader: BufferReader) -> ChatFull? {
        var _1: Int32?
        _1 = reader.readInt32()
        var _2: Int64?
        _2 = reader.readInt64()
        var _3: String?
        _3 = parseString(reader)
        var _4: Api.ChatParticipants?
        if let signature = reader.readInt32() {
            _4 = Api.parse(reader, signature: signature) as? Api.ChatParticipants
        }
        var _5: Api.Photo?
        if Int(_1!) & Int(1 << 2) != 0 {if let signature = reader.readInt32() {
            _5 = Api.parse(reader, signature: signature) as? Api.Photo
        } }
        var _6: Api.PeerNotifySettings?
        if let signature = reader.readInt32() {
            _6 = Api.parse(reader, signature: signature) as? Api.PeerNotifySettings
        }
        var _7: Api.ExportedChatInvite?
        if Int(_1!) & Int(1 << 13) != 0 {if let signature = reader.readInt32() {
            _7 = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite
        } }
        var _8: [Api.BotInfo]?
        if Int(_1!) & Int(1 << 3) != 0 {if let _ = reader.readInt32() {
            _8 = Api.parseVector(reader, elementSignature: 0, elementType: Api.BotInfo.self)
        } }
        var _9: Int32?
        if Int(_1!) & Int(1 << 6) != 0 {_9 = reader.readInt32() }
        var _10: Int32?
        if Int(_1!) & Int(1 << 11) != 0 {_10 = reader.readInt32() }
        var _11: Api.InputGroupCall?
        if Int(_1!) & Int(1 << 12) != 0 {if let signature = reader.readInt32() {
            _11 = Api.parse(reader, signature: signature) as? Api.InputGroupCall
        } }
        var _12: Int32?
        if Int(_1!) & Int(1 << 14) != 0 {_12 = reader.readInt32() }
        var _13: Api.Peer?
        if Int(_1!) & Int(1 << 15) != 0 {if let signature = reader.readInt32() {
            _13 = Api.parse(reader, signature: signature) as? Api.Peer
        } }
        var _14: String?
        if Int(_1!) & Int(1 << 16) != 0 {_14 = parseString(reader) }
        var _15: Int32?
        if Int(_1!) & Int(1 << 17) != 0 {_15 = reader.readInt32() }
        var _16: [Int64]?
        if Int(_1!) & Int(1 << 17) != 0 {if let _ = reader.readInt32() {
            _16 = Api.parseVector(reader, elementSignature: 570911930, elementType: Int64.self)
        } }
        var _17: [String]?
        if Int(_1!) & Int(1 << 18) != 0 {if let _ = reader.readInt32() {
            _17 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self)
        } }
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = _3 != nil
        let _c4 = _4 != nil
        let _c5 = (Int(_1!) & Int(1 << 2) == 0) || _5 != nil
        let _c6 = _6 != nil
        let _c7 = (Int(_1!) & Int(1 << 13) == 0) || _7 != nil
        let _c8 = (Int(_1!) & Int(1 << 3) == 0) || _8 != nil
        let _c9 = (Int(_1!) & Int(1 << 6) == 0) || _9 != nil
        let _c10 = (Int(_1!) & Int(1 << 11) == 0) || _10 != nil
        let _c11 = (Int(_1!) & Int(1 << 12) == 0) || _11 != nil
        let _c12 = (Int(_1!) & Int(1 << 14) == 0) || _12 != nil
        let _c13 = (Int(_1!) & Int(1 << 15) == 0) || _13 != nil
        let _c14 = (Int(_1!) & Int(1 << 16) == 0) || _14 != nil
        let _c15 = (Int(_1!) & Int(1 << 17) == 0) || _15 != nil
        let _c16 = (Int(_1!) & Int(1 << 17) == 0) || _16 != nil
        let _c17 = (Int(_1!) & Int(1 << 18) == 0) || _17 != nil
        if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 {
            return Api.ChatFull.chatFull(flags: _1!, id: _2!, about: _3!, participants: _4!, chatPhoto: _5, notifySettings: _6!, exportedInvite: _7, botInfo: _8, pinnedMsgId: _9, folderId: _10, call: _11, ttlPeriod: _12, groupcallDefaultJoinAs: _13, themeEmoticon: _14, requestsPending: _15, recentRequesters: _16, availableReactions: _17)
        }
        else {
            return nil
        }
    }
    public static func parse_channelFull(_ reader: BufferReader) -> ChatFull? {
        var _1: Int32?
        _1 = reader.readInt32()
        var _2: Int64?
        _2 = reader.readInt64()
        var _3: String?
        _3 = parseString(reader)
        var _4: Int32?
        if Int(_1!) & Int(1 << 0) != 0 {_4 = reader.readInt32() }
        var _5: Int32?
        if Int(_1!) & Int(1 << 1) != 0 {_5 = reader.readInt32() }
        var _6: Int32?
        if Int(_1!) & Int(1 << 2) != 0 {_6 = reader.readInt32() }
        var _7: Int32?
        if Int(_1!) & Int(1 << 2) != 0 {_7 = reader.readInt32() }
        var _8: Int32?
        if Int(_1!) & Int(1 << 13) != 0 {_8 = reader.readInt32() }
        var _9: Int32?
        _9 = reader.readInt32()
        var _10: Int32?
        _10 = reader.readInt32()
        var _11: Int32?
        _11 = reader.readInt32()
        var _12: Api.Photo?
        if let signature = reader.readInt32() {
            _12 = Api.parse(reader, signature: signature) as? Api.Photo
        }
        var _13: Api.PeerNotifySettings?
        if let signature = reader.readInt32() {
            _13 = Api.parse(reader, signature: signature) as? Api.PeerNotifySettings
        }
        var _14: Api.ExportedChatInvite?
        if Int(_1!) & Int(1 << 23) != 0 {if let signature = reader.readInt32() {
            _14 = Api.parse(reader, signature: signature) as? Api.ExportedChatInvite
        } }
        var _15: [Api.BotInfo]?
        if let _ = reader.readInt32() {
            _15 = Api.parseVector(reader, elementSignature: 0, elementType: Api.BotInfo.self)
        }
        var _16: Int64?
        if Int(_1!) & Int(1 << 4) != 0 {_16 = reader.readInt64() }
        var _17: Int32?
        if Int(_1!) & Int(1 << 4) != 0 {_17 = reader.readInt32() }
        var _18: Int32?
        if Int(_1!) & Int(1 << 5) != 0 {_18 = reader.readInt32() }
        var _19: Api.StickerSet?
        if Int(_1!) & Int(1 << 8) != 0 {if let signature = reader.readInt32() {
            _19 = Api.parse(reader, signature: signature) as? Api.StickerSet
        } }
        var _20: Int32?
        if Int(_1!) & Int(1 << 9) != 0 {_20 = reader.readInt32() }
        var _21: Int32?
        if Int(_1!) & Int(1 << 11) != 0 {_21 = reader.readInt32() }
        var _22: Int64?
        if Int(_1!) & Int(1 << 14) != 0 {_22 = reader.readInt64() }
        var _23: Api.ChannelLocation?
        if Int(_1!) & Int(1 << 15) != 0 {if let signature = reader.readInt32() {
            _23 = Api.parse(reader, signature: signature) as? Api.ChannelLocation
        } }
        var _24: Int32?
        if Int(_1!) & Int(1 << 17) != 0 {_24 = reader.readInt32() }
        var _25: Int32?
        if Int(_1!) & Int(1 << 18) != 0 {_25 = reader.readInt32() }
        var _26: Int32?
        if Int(_1!) & Int(1 << 12) != 0 {_26 = reader.readInt32() }
        var _27: Int32?
        _27 = reader.readInt32()
        var _28: Api.InputGroupCall?
        if Int(_1!) & Int(1 << 21) != 0 {if let signature = reader.readInt32() {
            _28 = Api.parse(reader, signature: signature) as? Api.InputGroupCall
        } }
        var _29: Int32?
        if Int(_1!) & Int(1 << 24) != 0 {_29 = reader.readInt32() }
        var _30: [String]?
        if Int(_1!) & Int(1 << 25) != 0 {if let _ = reader.readInt32() {
            _30 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self)
        } }
        var _31: Api.Peer?
        if Int(_1!) & Int(1 << 26) != 0 {if let signature = reader.readInt32() {
            _31 = Api.parse(reader, signature: signature) as? Api.Peer
        } }
        var _32: String?
        if Int(_1!) & Int(1 << 27) != 0 {_32 = parseString(reader) }
        var _33: Int32?
        if Int(_1!) & Int(1 << 28) != 0 {_33 = reader.readInt32() }
        var _34: [Int64]?
        if Int(_1!) & Int(1 << 28) != 0 {if let _ = reader.readInt32() {
            _34 = Api.parseVector(reader, elementSignature: 570911930, elementType: Int64.self)
        } }
        var _35: Api.Peer?
        if Int(_1!) & Int(1 << 29) != 0 {if let signature = reader.readInt32() {
            _35 = Api.parse(reader, signature: signature) as? Api.Peer
        } }
        var _36: [String]?
        if Int(_1!) & Int(1 << 30) != 0 {if let _ = reader.readInt32() {
            _36 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self)
        } }
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = _3 != nil
        let _c4 = (Int(_1!) & Int(1 << 0) == 0) || _4 != nil
        let _c5 = (Int(_1!) & Int(1 << 1) == 0) || _5 != nil
        let _c6 = (Int(_1!) & Int(1 << 2) == 0) || _6 != nil
        let _c7 = (Int(_1!) & Int(1 << 2) == 0) || _7 != nil
        let _c8 = (Int(_1!) & Int(1 << 13) == 0) || _8 != nil
        let _c9 = _9 != nil
        let _c10 = _10 != nil
        let _c11 = _11 != nil
        let _c12 = _12 != nil
        let _c13 = _13 != nil
        let _c14 = (Int(_1!) & Int(1 << 23) == 0) || _14 != nil
        let _c15 = _15 != nil
        let _c16 = (Int(_1!) & Int(1 << 4) == 0) || _16 != nil
        let _c17 = (Int(_1!) & Int(1 << 4) == 0) || _17 != nil
        let _c18 = (Int(_1!) & Int(1 << 5) == 0) || _18 != nil
        let _c19 = (Int(_1!) & Int(1 << 8) == 0) || _19 != nil
        let _c20 = (Int(_1!) & Int(1 << 9) == 0) || _20 != nil
        let _c21 = (Int(_1!) & Int(1 << 11) == 0) || _21 != nil
        let _c22 = (Int(_1!) & Int(1 << 14) == 0) || _22 != nil
        let _c23 = (Int(_1!) & Int(1 << 15) == 0) || _23 != nil
        let _c24 = (Int(_1!) & Int(1 << 17) == 0) || _24 != nil
        let _c25 = (Int(_1!) & Int(1 << 18) == 0) || _25 != nil
        let _c26 = (Int(_1!) & Int(1 << 12) == 0) || _26 != nil
        let _c27 = _27 != nil
        let _c28 = (Int(_1!) & Int(1 << 21) == 0) || _28 != nil
        let _c29 = (Int(_1!) & Int(1 << 24) == 0) || _29 != nil
        let _c30 = (Int(_1!) & Int(1 << 25) == 0) || _30 != nil
        let _c31 = (Int(_1!) & Int(1 << 26) == 0) || _31 != nil
        let _c32 = (Int(_1!) & Int(1 << 27) == 0) || _32 != nil
        let _c33 = (Int(_1!) & Int(1 << 28) == 0) || _33 != nil
        let _c34 = (Int(_1!) & Int(1 << 28) == 0) || _34 != nil
        let _c35 = (Int(_1!) & Int(1 << 29) == 0) || _35 != nil
        let _c36 = (Int(_1!) & Int(1 << 30) == 0) || _36 != nil
        if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 && _c17 && _c18 && _c19 && _c20 && _c21 && _c22 && _c23 && _c24 && _c25 && _c26 && _c27 && _c28 && _c29 && _c30 && _c31 && _c32 && _c33 && _c34 && _c35 && _c36 {
            return Api.ChatFull.channelFull(flags: _1!, id: _2!, about: _3!, participantsCount: _4, adminsCount: _5, kickedCount: _6, bannedCount: _7, onlineCount: _8, readInboxMaxId: _9!, readOutboxMaxId: _10!, unreadCount: _11!, chatPhoto: _12!, notifySettings: _13!, exportedInvite: _14, botInfo: _15!, migratedFromChatId: _16, migratedFromMaxId: _17, pinnedMsgId: _18, stickerset: _19, availableMinId: _20, folderId: _21, linkedChatId: _22, location: _23, slowmodeSeconds: _24, slowmodeNextSendDate: _25, statsDc: _26, pts: _27!, call: _28, ttlPeriod: _29, pendingSuggestions: _30, groupcallDefaultJoinAs: _31, themeEmoticon: _32, requestsPending: _33, recentRequesters: _34, defaultSendAs: _35, availableReactions: _36)
        }
        else {
            return nil
        }
    }

}

Api.messages.ChatFull

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public enum ChatFull: TypeConstructorDescription {
    case chatFull(fullChat: Api.ChatFull, chats: [Api.Chat], users: [Api.User])

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .chatFull(let fullChat, let chats, let users):
            if boxed {
                buffer.appendInt32(-438840932)
            }
            fullChat.serialize(buffer, true)
            buffer.appendInt32(481674261)
            buffer.appendInt32(Int32(chats.count))
            for item in chats {
                item.serialize(buffer, true)
            }
            buffer.appendInt32(481674261)
            buffer.appendInt32(Int32(users.count))
            for item in users {
                item.serialize(buffer, true)
            }
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .chatFull(let fullChat, let chats, let users):
            return ("chatFull", [("fullChat", fullChat), ("chats", chats), ("users", users)])
        }
    }

    public static func parse_chatFull(_ reader: BufferReader) -> ChatFull? {
        var _1: Api.ChatFull?
        if let signature = reader.readInt32() {
            _1 = Api.parse(reader, signature: signature) as? Api.ChatFull
        }
        var _2: [Api.Chat]?
        if let _ = reader.readInt32() {
            _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Chat.self)
        }
        var _3: [Api.User]?
        if let _ = reader.readInt32() {
            _3 = 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.ChatFull.chatFull(fullChat: _1!, chats: _2!, users: _3!)
        }
        else {
            return nil
        }
    }

}

Api.functions.messages

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// get chats -> Api.messages.Chats
public static func getChats(id: [Int64]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.Chats>) {
    let buffer = Buffer()
    buffer.appendInt32(1240027791)
    buffer.appendInt32(481674261)
    buffer.appendInt32(Int32(id.count))
    for item in id {
        serializeInt64(item, buffer: buffer, boxed: false)
    }
    return (FunctionDescription(name: "messages.getChats", parameters: [("id", id)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Chats? in
        let reader = BufferReader(buffer)
        var result: Api.messages.Chats?
        if let signature = reader.readInt32() {
            result = Api.parse(reader, signature: signature) as? Api.messages.Chats
        }
        return result
    })
}

// get full chat -> Api.messages.ChatFull
public static func getFullChat(chatId: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.ChatFull>) {
    let buffer = Buffer()
    buffer.appendInt32(-1364194508)
    serializeInt64(chatId, buffer: buffer, boxed: false)
    return (FunctionDescription(name: "messages.getFullChat", parameters: [("chatId", chatId)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.ChatFull? in
        let reader = BufferReader(buffer)
        var result: Api.messages.ChatFull?
        if let signature = reader.readInt32() {
            result = Api.parse(reader, signature: signature) as? Api.messages.ChatFull
        }
        return result
    })
}

Api.InputChannel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
public enum InputChannel: TypeConstructorDescription {
    case inputChannelEmpty
    case inputChannel(channelId: Int64, accessHash: Int64)
    case inputChannelFromMessage(peer: Api.InputPeer, msgId: Int32, channelId: Int64)

    public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
        switch self {
        case .inputChannelEmpty:
            if boxed {
                buffer.appendInt32(-292807034)
            }

            break
        case .inputChannel(let channelId, let accessHash):
            if boxed {
                buffer.appendInt32(-212145112)
            }
            serializeInt64(channelId, buffer: buffer, boxed: false)
            serializeInt64(accessHash, buffer: buffer, boxed: false)
            break
        case .inputChannelFromMessage(let peer, let msgId, let channelId):
            if boxed {
                buffer.appendInt32(1536380829)
            }
            peer.serialize(buffer, true)
            serializeInt32(msgId, buffer: buffer, boxed: false)
            serializeInt64(channelId, buffer: buffer, boxed: false)
            break
        }
    }

    public func descriptionFields() -> (String, [(String, Any)]) {
        switch self {
        case .inputChannelEmpty:
            return ("inputChannelEmpty", [])
        case .inputChannel(let channelId, let accessHash):
            return ("inputChannel", [("channelId", channelId), ("accessHash", accessHash)])
        case .inputChannelFromMessage(let peer, let msgId, let channelId):
            return ("inputChannelFromMessage", [("peer", peer), ("msgId", msgId), ("channelId", channelId)])
        }
    }

    public static func parse_inputChannelEmpty(_ reader: BufferReader) -> InputChannel? {
        return Api.InputChannel.inputChannelEmpty
    }
    public static func parse_inputChannel(_ reader: BufferReader) -> InputChannel? {
        var _1: Int64?
        _1 = reader.readInt64()
        var _2: Int64?
        _2 = reader.readInt64()
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        if _c1 && _c2 {
            return Api.InputChannel.inputChannel(channelId: _1!, accessHash: _2!)
        }
        else {
            return nil
        }
    }
    public static func parse_inputChannelFromMessage(_ reader: BufferReader) -> InputChannel? {
        var _1: Api.InputPeer?
        if let signature = reader.readInt32() {
            _1 = Api.parse(reader, signature: signature) as? Api.InputPeer
        }
        var _2: Int32?
        _2 = reader.readInt32()
        var _3: Int64?
        _3 = reader.readInt64()
        let _c1 = _1 != nil
        let _c2 = _2 != nil
        let _c3 = _3 != nil
        if _c1 && _c2 && _c3 {
            return Api.InputChannel.inputChannelFromMessage(peer: _1!, msgId: _2!, channelId: _3!)
        }
        else {
            return nil
        }
    }

}

Peer to Api.InputChannel

1
2
3
4
5
6
7
func apiInputChannel(_ peer: Peer) -> Api.InputChannel? {
    if let channel = peer as? TelegramChannel, let accessHash = channel.accessHash {
        return Api.InputChannel.inputChannel(channelId: channel.id.id._internalGetInt64Value(), accessHash: accessHash.value)
    } else {
        return nil
    }
}

Api.functions.channels

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// get channels -> Api.messages.Chats 
public static func getChannels(id: [Api.InputChannel]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.Chats>) {
    let buffer = Buffer()
    buffer.appendInt32(176122811)
    buffer.appendInt32(481674261)
    buffer.appendInt32(Int32(id.count))
    for item in id {
        item.serialize(buffer, true)
    }
    return (FunctionDescription(name: "channels.getChannels", parameters: [("id", id)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Chats? in
        let reader = BufferReader(buffer)
        var result: Api.messages.Chats?
        if let signature = reader.readInt32() {
            result = Api.parse(reader, signature: signature) as? Api.messages.Chats
        }
        return result
    })
}

// get full channel -> Api.messages.ChatFull
public static func getFullChannel(channel: Api.InputChannel) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.messages.ChatFull>) {
    let buffer = Buffer()
    buffer.appendInt32(141781513)
    channel.serialize(buffer, true)
    return (FunctionDescription(name: "channels.getFullChannel", parameters: [("channel", channel)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.ChatFull? in
        let reader = BufferReader(buffer)
        var result: Api.messages.ChatFull?
        if let signature = reader.readInt32() {
            result = Api.parse(reader, signature: signature) as? Api.messages.ChatFull
        }
        return result
    })
}

Peer in Postbox Layer

Peer

1
2
3
4
5
6
7
8
public protocol Peer: AnyObject, PostboxCoding {
    var id: PeerId { get }
    var indexName: PeerIndexNameRepresentation { get }
    var associatedPeerId: PeerId? { get }
    var notificationSettingsPeerId: PeerId? { get }
    
    func isEqual(_ other: Peer) -> Bool
}

User in Business Layer

TelegramUser

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public final class TelegramUser: Peer, Equatable {
    public let id: PeerId
    public let accessHash: TelegramPeerAccessHash?
    public let firstName: String?
    public let lastName: String?
    public let username: String?
    public let phone: String?
    public let photo: [TelegramMediaImageRepresentation]
    public let botInfo: BotUserInfo?
    public let restrictionInfo: PeerAccessRestrictionInfo?
    public let flags: UserInfoFlags
    
    public var nameOrPhone: String {
        if let firstName = self.firstName {
            if let lastName = self.lastName {
                return "\(firstName) \(lastName)"
            } else {
                return firstName
            }
        } else if let lastName = self.lastName {
            return lastName
        } else if let phone = self.phone, !phone.isEmpty {
            return phone
        } else {
            return ""
        }
    }
    
    public var shortNameOrPhone: String {
        if let firstName = self.firstName {
            return firstName
        } else if let lastName = self.lastName {
            return lastName
        } else if let phone = self.phone, !phone.isEmpty {
            return phone
        } else {
            return ""
        }
    }
    
    public var indexName: PeerIndexNameRepresentation {
        return .personName(first: self.firstName ?? "", last: self.lastName ?? "", addressName: self.username, phoneNumber: self.phone)
    }
    
    public let associatedPeerId: PeerId? = nil
    public let notificationSettingsPeerId: PeerId? = nil
}    

TelgramUser from Api.User

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
extension TelegramUser {
    convenience init(user: Api.User) {
        switch user {
        case let .user(flags, id, accessHash, firstName, lastName, username, phone, photo, _, _, restrictionReason, botInlinePlaceholder, _):
            let representations: [TelegramMediaImageRepresentation] = photo.flatMap(parsedTelegramProfilePhoto) ?? []
            
            let isMin = (flags & (1 << 20)) != 0
            let accessHashValue = accessHash.flatMap { value -> TelegramPeerAccessHash in
                if isMin {
                    return .genericPublic(value)
                } else {
                    return .personal(value)
                }
            }
            
            var userFlags: UserInfoFlags = []
            if (flags & (1 << 17)) != 0 {
                userFlags.insert(.isVerified)
            }
            if (flags & (1 << 23)) != 0 {
                userFlags.insert(.isSupport)
            }
            if (flags & (1 << 24)) != 0 {
                userFlags.insert(.isScam)
            }
            if (flags & (1 << 26)) != 0 {
                userFlags.insert(.isFake)
            }

            var botInfo: BotUserInfo?
            if (flags & (1 << 14)) != 0 {
                var botFlags = BotUserInfoFlags()
                if (flags & (1 << 15)) != 0 {
                    botFlags.insert(.hasAccessToChatHistory)
                }
                if (flags & (1 << 16)) == 0 {
                    botFlags.insert(.worksWithGroups)
                }
                if (flags & (1 << 21)) != 0 {
                    botFlags.insert(.requiresGeolocationForInlineRequests)
                }
                botInfo = BotUserInfo(flags: botFlags, inlinePlaceholder: botInlinePlaceholder)
            }
            
            let restrictionInfo: PeerAccessRestrictionInfo? = restrictionReason.flatMap(PeerAccessRestrictionInfo.init(apiReasons:))
            
            self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id)), accessHash: accessHashValue, firstName: firstName, lastName: lastName, username: username, phone: phone, photo: representations, botInfo: botInfo, restrictionInfo: restrictionInfo, flags: userFlags)
        case let .userEmpty(id):
            self.init(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(id)), accessHash: nil, firstName: nil, lastName: nil, username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: [])
        }
    }
    
  // merge two TelegramUser
    static func merge(_ lhs: TelegramUser?, rhs: Api.User) -> TelegramUser? {
        switch rhs {
            case let .user(flags, _, rhsAccessHash, _, _, username, _, photo, _, _, restrictionReason, botInlinePlaceholder, _):
                let isMin = (flags & (1 << 20)) != 0
                if !isMin {
                    return TelegramUser(user: rhs)
                } else {
                    let telegramPhoto: [TelegramMediaImageRepresentation]
                    if let photo = photo {
                        telegramPhoto = parsedTelegramProfilePhoto(photo)
                    } else if let currentPhoto = lhs?.photo {
                        telegramPhoto = currentPhoto
                    } else {
                        telegramPhoto = []
                    }

                    if let lhs = lhs {
                        var userFlags: UserInfoFlags = []
                        if (flags & (1 << 17)) != 0 {
                            userFlags.insert(.isVerified)
                        }
                        if (flags & (1 << 23)) != 0 {
                            userFlags.insert(.isSupport)
                        }
                        if (flags & (1 << 24)) != 0 {
                            userFlags.insert(.isScam)
                        }
                        if (flags & Int32(1 << 26)) != 0 {
                            userFlags.insert(.isFake)
                        }
                        
                        var botInfo: BotUserInfo?
                        if (flags & (1 << 14)) != 0 {
                            var botFlags = BotUserInfoFlags()
                            if (flags & (1 << 15)) != 0 {
                                botFlags.insert(.hasAccessToChatHistory)
                            }
                            if (flags & (1 << 16)) == 0 {
                                botFlags.insert(.worksWithGroups)
                            }
                            if (flags & (1 << 21)) != 0 {
                                botFlags.insert(.requiresGeolocationForInlineRequests)
                            }
                            botInfo = BotUserInfo(flags: botFlags, inlinePlaceholder: botInlinePlaceholder)
                        }
                        
                        let restrictionInfo: PeerAccessRestrictionInfo? = restrictionReason.flatMap(PeerAccessRestrictionInfo.init)
                        
                        let rhsAccessHashValue = rhsAccessHash.flatMap { value -> TelegramPeerAccessHash in
                            if isMin {
                                return .genericPublic(value)
                            } else {
                                return .personal(value)
                            }
                        }
                        
                        let accessHash: TelegramPeerAccessHash?
                        if let rhsAccessHashValue = rhsAccessHashValue, case .personal = rhsAccessHashValue {
                            accessHash = rhsAccessHashValue
                        } else {
                            accessHash = lhs.accessHash ?? rhsAccessHashValue
                        }
                        
                        return TelegramUser(id: lhs.id, accessHash: accessHash, firstName: lhs.firstName, lastName: lhs.lastName, username: username, phone: lhs.phone, photo: telegramPhoto, botInfo: botInfo, restrictionInfo: restrictionInfo, flags: userFlags)
                    } else {
                        return TelegramUser(user: rhs)
                    }
                }
            case .userEmpty:
                return TelegramUser(user: rhs)
        }
    }
    
    static func merge(lhs: TelegramUser?, rhs: TelegramUser) -> TelegramUser {
        guard let lhs = lhs else {
            return rhs
        }
        if let rhsAccessHash = rhs.accessHash, case .personal = rhsAccessHash {
            return rhs
        } else {
            var userFlags: UserInfoFlags = []
            if rhs.flags.contains(.isVerified) {
                userFlags.insert(.isVerified)
            }
            if rhs.flags.contains(.isSupport) {
                userFlags.insert(.isSupport)
            }
            if rhs.flags.contains(.isScam) {
                userFlags.insert(.isScam)
            }
            if rhs.flags.contains(.isFake) {
                userFlags.insert(.isFake)
            }

            let botInfo: BotUserInfo? = rhs.botInfo
            
            let restrictionInfo: PeerAccessRestrictionInfo? = rhs.restrictionInfo
            
            let accessHash: TelegramPeerAccessHash?
            if let rhsAccessHashValue = lhs.accessHash, case .personal = rhsAccessHashValue {
                accessHash = rhsAccessHashValue
            } else {
                accessHash = lhs.accessHash ?? rhs.accessHash
            }
            
            return TelegramUser(id: lhs.id, accessHash: accessHash, firstName: lhs.firstName, lastName: lhs.lastName, username: rhs.username, phone: lhs.phone, photo: rhs.photo.isEmpty ? lhs.photo : rhs.photo, botInfo: botInfo, restrictionInfo: restrictionInfo, flags: userFlags)
        }
    }
}

TelegramGroup

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public final class TelegramGroup: Peer, Equatable {
    public let id: PeerId
    public let title: String
    public let photo: [TelegramMediaImageRepresentation]
    public let participantCount: Int
    public let role: TelegramGroupRole
    public let membership: TelegramGroupMembership
    public let flags: TelegramGroupFlags
    public let defaultBannedRights: TelegramChatBannedRights?
    public let migrationReference: TelegramGroupToChannelMigrationReference?
    public let creationDate: Int32
    public let version: Int
    
    public var indexName: PeerIndexNameRepresentation {
        return .title(title: self.title, addressName: nil)
    }
    
    public let associatedPeerId: PeerId? = nil
    public let notificationSettingsPeerId: PeerId? = nil
}    

TelegramChannel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public final class TelegramChannel: Peer, Equatable {
    public let id: PeerId
    public let accessHash: TelegramPeerAccessHash?
    public let title: String
    public let username: String?
    public let photo: [TelegramMediaImageRepresentation]
    public let creationDate: Int32
    public let version: Int32
    public let participationStatus: TelegramChannelParticipationStatus
    public let info: TelegramChannelInfo
    public let flags: TelegramChannelFlags
    public let restrictionInfo: PeerAccessRestrictionInfo?
    public let adminRights: TelegramChatAdminRights?
    public let bannedRights: TelegramChatBannedRights?
    public let defaultBannedRights: TelegramChatBannedRights?
    
    public var indexName: PeerIndexNameRepresentation {
        return .title(title: self.title, addressName: self.username)
    }
    
    public let associatedPeerId: PeerId? = nil
    public let notificationSettingsPeerId: PeerId? = nil
}    

Group or Channel from Api.Chat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
func parseTelegramGroupOrChannel(chat: Api.Chat) -> Peer? {
    switch chat {
    case let .chat(flags, id, title, photo, participantsCount, date, version, migratedTo, adminRights, defaultBannedRights):
        let left = (flags & ((1 << 1) | (1 << 2))) != 0
        var migrationReference: TelegramGroupToChannelMigrationReference?
        if let migratedTo = migratedTo {
            switch migratedTo {
            case let .inputChannel(channelId, accessHash):
                migrationReference = TelegramGroupToChannelMigrationReference(peerId: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId)), accessHash: accessHash)
            case .inputChannelEmpty:
                break
            case .inputChannelFromMessage:
                break
            }
        }
        var groupFlags = TelegramGroupFlags()
        var role: TelegramGroupRole = .member
        if (flags & (1 << 0)) != 0 {
            role = .creator(rank: nil)
        } else if let adminRights = adminRights {
            role = .admin(TelegramChatAdminRights(apiAdminRights: adminRights) ?? TelegramChatAdminRights(rights: []), rank: nil)
        }
        if (flags & (1 << 5)) != 0 {
            groupFlags.insert(.deactivated)
        }
        if (flags & Int32(1 << 23)) != 0 {
            groupFlags.insert(.hasVoiceChat)
        }
        if (flags & Int32(1 << 24)) != 0 {
            groupFlags.insert(.hasActiveVoiceChat)
        }
        if (flags & Int32(1 << 25)) != 0 {
            groupFlags.insert(.copyProtectionEnabled)
        }
        return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(id)), title: title, photo: imageRepresentationsForApiChatPhoto(photo), participantCount: Int(participantsCount), role: role, membership: left ? .Left : .Member, flags: groupFlags, defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init(apiBannedRights:)), migrationReference: migrationReference, creationDate: date, version: Int(version))
    case let .chatEmpty(id):
        return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(id)), title: "", photo: [], participantCount: 0, role: .member, membership: .Removed, flags: [], defaultBannedRights: nil, migrationReference: nil, creationDate: 0, version: 0)
    case let .chatForbidden(id, title):
        return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(id)), title: title, photo: [], participantCount: 0, role: .member, membership: .Removed, flags: [], defaultBannedRights: nil, migrationReference: nil, creationDate: 0, version: 0)
    case let .channel(flags, id, accessHash, title, username, photo, date, restrictionReason, adminRights, bannedRights, defaultBannedRights, _):
        let isMin = (flags & (1 << 12)) != 0
        
        let participationStatus: TelegramChannelParticipationStatus
        if (flags & Int32(1 << 1)) != 0 {
            participationStatus = .kicked
        } else if (flags & Int32(1 << 2)) != 0 {
            participationStatus = .left
        } else {
            participationStatus = .member
        }
        
        let info: TelegramChannelInfo
        if (flags & Int32(1 << 8)) != 0 {
            var infoFlags = TelegramChannelGroupFlags()
            if (flags & Int32(1 << 22)) != 0 {
                infoFlags.insert(.slowModeEnabled)
            }
            info = .group(TelegramChannelGroupInfo(flags: infoFlags))
        } else {
            var infoFlags = TelegramChannelBroadcastFlags()
            if (flags & Int32(1 << 11)) != 0 {
                infoFlags.insert(.messagesShouldHaveSignatures)
            }
            if (flags & Int32(1 << 20)) != 0 {
                infoFlags.insert(.hasDiscussionGroup)
            }
            info = .broadcast(TelegramChannelBroadcastInfo(flags: infoFlags))
        }
        
        var channelFlags = TelegramChannelFlags()
        if (flags & Int32(1 << 0)) != 0 {
            channelFlags.insert(.isCreator)
        }
        if (flags & Int32(1 << 7)) != 0 {
            channelFlags.insert(.isVerified)
        }
        if (flags & Int32(1 << 19)) != 0 {
            channelFlags.insert(.isScam)
        }
        if (flags & Int32(1 << 21)) != 0 {
            channelFlags.insert(.hasGeo)
        }
        if (flags & Int32(1 << 23)) != 0 {
            channelFlags.insert(.hasVoiceChat)
        }
        if (flags & Int32(1 << 24)) != 0 {
            channelFlags.insert(.hasActiveVoiceChat)
        }
        if (flags & Int32(1 << 25)) != 0 {
            channelFlags.insert(.isFake)
        }
        if (flags & Int32(1 << 26)) != 0 {
            channelFlags.insert(.isGigagroup)
        }
        if (flags & Int32(1 << 27)) != 0 {
            channelFlags.insert(.copyProtectionEnabled)
        }

        let restrictionInfo: PeerAccessRestrictionInfo?
        if let restrictionReason = restrictionReason {
            restrictionInfo = PeerAccessRestrictionInfo(apiReasons: restrictionReason)
        } else {
            restrictionInfo = nil
        }
        
        let accessHashValue = accessHash.flatMap { value -> TelegramPeerAccessHash in
            if isMin {
                return .genericPublic(value)
            } else {
                return .personal(value)
            }
        }
        
        return TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(id)), accessHash: accessHashValue, title: title, username: username, photo: imageRepresentationsForApiChatPhoto(photo), creationDate: date, version: 0, participationStatus: participationStatus, info: info, flags: channelFlags, restrictionInfo: restrictionInfo, adminRights: adminRights.flatMap(TelegramChatAdminRights.init), bannedRights: bannedRights.flatMap(TelegramChatBannedRights.init), defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init))
    case let .channelForbidden(flags, id, accessHash, title, untilDate):
        let info: TelegramChannelInfo
        if (flags & Int32(1 << 8)) != 0 {
            info = .group(TelegramChannelGroupInfo(flags: []))
        } else {
            info = .broadcast(TelegramChannelBroadcastInfo(flags: []))
        }
        
        return TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(id)), accessHash: .personal(accessHash), title: title, username: nil, photo: [], creationDate: 0, version: 0, participationStatus: .kicked, info: info, flags: TelegramChannelFlags(), restrictionInfo: nil, adminRights: nil, bannedRights: TelegramChatBannedRights(flags: [.banReadMessages], untilDate: untilDate ?? Int32.max), defaultBannedRights: nil)
    }
}
This post is licensed under CC BY 4.0 by the author.