mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-01 12:17:53 +00:00
Update API
This commit is contained in:
parent
64c94d1fba
commit
a81421bdc9
@ -1806,7 +1806,8 @@ public final class PostboxDecoder {
|
|||||||
let result = try AdaptedPostboxDecoder().decode(T.self, from: innerData)
|
let result = try AdaptedPostboxDecoder().decode(T.self, from: innerData)
|
||||||
return result
|
return result
|
||||||
} catch let error {
|
} catch let error {
|
||||||
assertionFailure("Decoding error: \(error)")
|
postboxLog("Decoding error: \(error)")
|
||||||
|
//assertionFailure("Decoding error: \(error)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -758,7 +758,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
|||||||
dict[-1625153079] = { return Api.InputWebFileLocation.parse_inputWebFileGeoPointLocation($0) }
|
dict[-1625153079] = { return Api.InputWebFileLocation.parse_inputWebFileGeoPointLocation($0) }
|
||||||
dict[-1275374751] = { return Api.EmojiLanguage.parse_emojiLanguage($0) }
|
dict[-1275374751] = { return Api.EmojiLanguage.parse_emojiLanguage($0) }
|
||||||
dict[1601666510] = { return Api.MessageFwdHeader.parse_messageFwdHeader($0) }
|
dict[1601666510] = { return Api.MessageFwdHeader.parse_messageFwdHeader($0) }
|
||||||
dict[-783162982] = { return Api.SponsoredMessage.parse_sponsoredMessage($0) }
|
dict[981691896] = { return Api.SponsoredMessage.parse_sponsoredMessage($0) }
|
||||||
dict[-1012849566] = { return Api.BaseTheme.parse_baseThemeClassic($0) }
|
dict[-1012849566] = { return Api.BaseTheme.parse_baseThemeClassic($0) }
|
||||||
dict[-69724536] = { return Api.BaseTheme.parse_baseThemeDay($0) }
|
dict[-69724536] = { return Api.BaseTheme.parse_baseThemeDay($0) }
|
||||||
dict[-1212997976] = { return Api.BaseTheme.parse_baseThemeNight($0) }
|
dict[-1212997976] = { return Api.BaseTheme.parse_baseThemeNight($0) }
|
||||||
@ -791,7 +791,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
|||||||
dict[594408994] = { return Api.EmojiKeyword.parse_emojiKeywordDeleted($0) }
|
dict[594408994] = { return Api.EmojiKeyword.parse_emojiKeywordDeleted($0) }
|
||||||
dict[-290921362] = { return Api.upload.CdnFile.parse_cdnFileReuploadNeeded($0) }
|
dict[-290921362] = { return Api.upload.CdnFile.parse_cdnFileReuploadNeeded($0) }
|
||||||
dict[-1449145777] = { return Api.upload.CdnFile.parse_cdnFile($0) }
|
dict[-1449145777] = { return Api.upload.CdnFile.parse_cdnFile($0) }
|
||||||
dict[1679961905] = { return Api.AvailableReaction.parse_availableReaction($0) }
|
dict[1424116867] = { return Api.AvailableReaction.parse_availableReaction($0) }
|
||||||
dict[415997816] = { return Api.help.InviteText.parse_inviteText($0) }
|
dict[415997816] = { return Api.help.InviteText.parse_inviteText($0) }
|
||||||
dict[-1826077446] = { return Api.MessageUserReaction.parse_messageUserReaction($0) }
|
dict[-1826077446] = { return Api.MessageUserReaction.parse_messageUserReaction($0) }
|
||||||
dict[1984755728] = { return Api.BotInlineMessage.parse_botInlineMessageMediaAuto($0) }
|
dict[1984755728] = { return Api.BotInlineMessage.parse_botInlineMessageMediaAuto($0) }
|
||||||
|
|||||||
@ -19708,17 +19708,19 @@ public extension Api {
|
|||||||
|
|
||||||
}
|
}
|
||||||
public enum SponsoredMessage: TypeConstructorDescription {
|
public enum SponsoredMessage: TypeConstructorDescription {
|
||||||
case sponsoredMessage(flags: Int32, randomId: Buffer, fromId: Api.Peer, channelPost: Int32?, startParam: String?, message: String, entities: [Api.MessageEntity]?)
|
case sponsoredMessage(flags: Int32, randomId: Buffer, fromId: Api.Peer?, chatInvite: Api.ChatInvite?, chatInviteHash: String?, channelPost: Int32?, startParam: String?, message: String, entities: [Api.MessageEntity]?)
|
||||||
|
|
||||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||||
switch self {
|
switch self {
|
||||||
case .sponsoredMessage(let flags, let randomId, let fromId, let channelPost, let startParam, let message, let entities):
|
case .sponsoredMessage(let flags, let randomId, let fromId, let chatInvite, let chatInviteHash, let channelPost, let startParam, let message, let entities):
|
||||||
if boxed {
|
if boxed {
|
||||||
buffer.appendInt32(-783162982)
|
buffer.appendInt32(981691896)
|
||||||
}
|
}
|
||||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||||
serializeBytes(randomId, buffer: buffer, boxed: false)
|
serializeBytes(randomId, buffer: buffer, boxed: false)
|
||||||
fromId.serialize(buffer, true)
|
if Int(flags) & Int(1 << 3) != 0 {fromId!.serialize(buffer, true)}
|
||||||
|
if Int(flags) & Int(1 << 4) != 0 {chatInvite!.serialize(buffer, true)}
|
||||||
|
if Int(flags) & Int(1 << 4) != 0 {serializeString(chatInviteHash!, buffer: buffer, boxed: false)}
|
||||||
if Int(flags) & Int(1 << 2) != 0 {serializeInt32(channelPost!, buffer: buffer, boxed: false)}
|
if Int(flags) & Int(1 << 2) != 0 {serializeInt32(channelPost!, buffer: buffer, boxed: false)}
|
||||||
if Int(flags) & Int(1 << 0) != 0 {serializeString(startParam!, buffer: buffer, boxed: false)}
|
if Int(flags) & Int(1 << 0) != 0 {serializeString(startParam!, buffer: buffer, boxed: false)}
|
||||||
serializeString(message, buffer: buffer, boxed: false)
|
serializeString(message, buffer: buffer, boxed: false)
|
||||||
@ -19733,8 +19735,8 @@ public extension Api {
|
|||||||
|
|
||||||
public func descriptionFields() -> (String, [(String, Any)]) {
|
public func descriptionFields() -> (String, [(String, Any)]) {
|
||||||
switch self {
|
switch self {
|
||||||
case .sponsoredMessage(let flags, let randomId, let fromId, let channelPost, let startParam, let message, let entities):
|
case .sponsoredMessage(let flags, let randomId, let fromId, let chatInvite, let chatInviteHash, let channelPost, let startParam, let message, let entities):
|
||||||
return ("sponsoredMessage", [("flags", flags), ("randomId", randomId), ("fromId", fromId), ("channelPost", channelPost), ("startParam", startParam), ("message", message), ("entities", entities)])
|
return ("sponsoredMessage", [("flags", flags), ("randomId", randomId), ("fromId", fromId), ("chatInvite", chatInvite), ("chatInviteHash", chatInviteHash), ("channelPost", channelPost), ("startParam", startParam), ("message", message), ("entities", entities)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19744,28 +19746,36 @@ public extension Api {
|
|||||||
var _2: Buffer?
|
var _2: Buffer?
|
||||||
_2 = parseBytes(reader)
|
_2 = parseBytes(reader)
|
||||||
var _3: Api.Peer?
|
var _3: Api.Peer?
|
||||||
if let signature = reader.readInt32() {
|
if Int(_1!) & Int(1 << 3) != 0 {if let signature = reader.readInt32() {
|
||||||
_3 = Api.parse(reader, signature: signature) as? Api.Peer
|
_3 = Api.parse(reader, signature: signature) as? Api.Peer
|
||||||
}
|
} }
|
||||||
var _4: Int32?
|
var _4: Api.ChatInvite?
|
||||||
if Int(_1!) & Int(1 << 2) != 0 {_4 = reader.readInt32() }
|
if Int(_1!) & Int(1 << 4) != 0 {if let signature = reader.readInt32() {
|
||||||
|
_4 = Api.parse(reader, signature: signature) as? Api.ChatInvite
|
||||||
|
} }
|
||||||
var _5: String?
|
var _5: String?
|
||||||
if Int(_1!) & Int(1 << 0) != 0 {_5 = parseString(reader) }
|
if Int(_1!) & Int(1 << 4) != 0 {_5 = parseString(reader) }
|
||||||
var _6: String?
|
var _6: Int32?
|
||||||
_6 = parseString(reader)
|
if Int(_1!) & Int(1 << 2) != 0 {_6 = reader.readInt32() }
|
||||||
var _7: [Api.MessageEntity]?
|
var _7: String?
|
||||||
|
if Int(_1!) & Int(1 << 0) != 0 {_7 = parseString(reader) }
|
||||||
|
var _8: String?
|
||||||
|
_8 = parseString(reader)
|
||||||
|
var _9: [Api.MessageEntity]?
|
||||||
if Int(_1!) & Int(1 << 1) != 0 {if let _ = reader.readInt32() {
|
if Int(_1!) & Int(1 << 1) != 0 {if let _ = reader.readInt32() {
|
||||||
_7 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self)
|
_9 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self)
|
||||||
} }
|
} }
|
||||||
let _c1 = _1 != nil
|
let _c1 = _1 != nil
|
||||||
let _c2 = _2 != nil
|
let _c2 = _2 != nil
|
||||||
let _c3 = _3 != nil
|
let _c3 = (Int(_1!) & Int(1 << 3) == 0) || _3 != nil
|
||||||
let _c4 = (Int(_1!) & Int(1 << 2) == 0) || _4 != nil
|
let _c4 = (Int(_1!) & Int(1 << 4) == 0) || _4 != nil
|
||||||
let _c5 = (Int(_1!) & Int(1 << 0) == 0) || _5 != nil
|
let _c5 = (Int(_1!) & Int(1 << 4) == 0) || _5 != nil
|
||||||
let _c6 = _6 != nil
|
let _c6 = (Int(_1!) & Int(1 << 2) == 0) || _6 != nil
|
||||||
let _c7 = (Int(_1!) & Int(1 << 1) == 0) || _7 != nil
|
let _c7 = (Int(_1!) & Int(1 << 0) == 0) || _7 != nil
|
||||||
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 {
|
let _c8 = _8 != nil
|
||||||
return Api.SponsoredMessage.sponsoredMessage(flags: _1!, randomId: _2!, fromId: _3!, channelPost: _4, startParam: _5, message: _6!, entities: _7)
|
let _c9 = (Int(_1!) & Int(1 << 1) == 0) || _9 != nil
|
||||||
|
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 {
|
||||||
|
return Api.SponsoredMessage.sponsoredMessage(flags: _1!, randomId: _2!, fromId: _3, chatInvite: _4, chatInviteHash: _5, channelPost: _6, startParam: _7, message: _8!, entities: _9)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
@ -20190,17 +20200,18 @@ public extension Api {
|
|||||||
|
|
||||||
}
|
}
|
||||||
public enum AvailableReaction: TypeConstructorDescription {
|
public enum AvailableReaction: TypeConstructorDescription {
|
||||||
case availableReaction(reaction: String, title: String, staticIcon: Api.Document, selectAnimation: Api.Document, activateAnimation: Api.Document, effectAnimation: Api.Document)
|
case availableReaction(reaction: String, title: String, staticIcon: Api.Document, appearAnimation: Api.Document, selectAnimation: Api.Document, activateAnimation: Api.Document, effectAnimation: Api.Document)
|
||||||
|
|
||||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||||
switch self {
|
switch self {
|
||||||
case .availableReaction(let reaction, let title, let staticIcon, let selectAnimation, let activateAnimation, let effectAnimation):
|
case .availableReaction(let reaction, let title, let staticIcon, let appearAnimation, let selectAnimation, let activateAnimation, let effectAnimation):
|
||||||
if boxed {
|
if boxed {
|
||||||
buffer.appendInt32(1679961905)
|
buffer.appendInt32(1424116867)
|
||||||
}
|
}
|
||||||
serializeString(reaction, buffer: buffer, boxed: false)
|
serializeString(reaction, buffer: buffer, boxed: false)
|
||||||
serializeString(title, buffer: buffer, boxed: false)
|
serializeString(title, buffer: buffer, boxed: false)
|
||||||
staticIcon.serialize(buffer, true)
|
staticIcon.serialize(buffer, true)
|
||||||
|
appearAnimation.serialize(buffer, true)
|
||||||
selectAnimation.serialize(buffer, true)
|
selectAnimation.serialize(buffer, true)
|
||||||
activateAnimation.serialize(buffer, true)
|
activateAnimation.serialize(buffer, true)
|
||||||
effectAnimation.serialize(buffer, true)
|
effectAnimation.serialize(buffer, true)
|
||||||
@ -20210,8 +20221,8 @@ public extension Api {
|
|||||||
|
|
||||||
public func descriptionFields() -> (String, [(String, Any)]) {
|
public func descriptionFields() -> (String, [(String, Any)]) {
|
||||||
switch self {
|
switch self {
|
||||||
case .availableReaction(let reaction, let title, let staticIcon, let selectAnimation, let activateAnimation, let effectAnimation):
|
case .availableReaction(let reaction, let title, let staticIcon, let appearAnimation, let selectAnimation, let activateAnimation, let effectAnimation):
|
||||||
return ("availableReaction", [("reaction", reaction), ("title", title), ("staticIcon", staticIcon), ("selectAnimation", selectAnimation), ("activateAnimation", activateAnimation), ("effectAnimation", effectAnimation)])
|
return ("availableReaction", [("reaction", reaction), ("title", title), ("staticIcon", staticIcon), ("appearAnimation", appearAnimation), ("selectAnimation", selectAnimation), ("activateAnimation", activateAnimation), ("effectAnimation", effectAnimation)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20236,14 +20247,19 @@ public extension Api {
|
|||||||
if let signature = reader.readInt32() {
|
if let signature = reader.readInt32() {
|
||||||
_6 = Api.parse(reader, signature: signature) as? Api.Document
|
_6 = Api.parse(reader, signature: signature) as? Api.Document
|
||||||
}
|
}
|
||||||
|
var _7: Api.Document?
|
||||||
|
if let signature = reader.readInt32() {
|
||||||
|
_7 = Api.parse(reader, signature: signature) as? Api.Document
|
||||||
|
}
|
||||||
let _c1 = _1 != nil
|
let _c1 = _1 != nil
|
||||||
let _c2 = _2 != nil
|
let _c2 = _2 != nil
|
||||||
let _c3 = _3 != nil
|
let _c3 = _3 != nil
|
||||||
let _c4 = _4 != nil
|
let _c4 = _4 != nil
|
||||||
let _c5 = _5 != nil
|
let _c5 = _5 != nil
|
||||||
let _c6 = _6 != nil
|
let _c6 = _6 != nil
|
||||||
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 {
|
let _c7 = _7 != nil
|
||||||
return Api.AvailableReaction.availableReaction(reaction: _1!, title: _2!, staticIcon: _3!, selectAnimation: _4!, activateAnimation: _5!, effectAnimation: _6!)
|
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 {
|
||||||
|
return Api.AvailableReaction.availableReaction(reaction: _1!, title: _2!, staticIcon: _3!, appearAnimation: _4!, selectAnimation: _5!, activateAnimation: _6!, effectAnimation: _7!)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -4591,6 +4591,20 @@ public extension Api {
|
|||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func setDefaultReaction(emoji: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
||||||
|
let buffer = Buffer()
|
||||||
|
buffer.appendInt32(1474910882)
|
||||||
|
serializeString(emoji, buffer: buffer, boxed: false)
|
||||||
|
return (FunctionDescription(name: "messages.setDefaultReaction", parameters: [("emoji", emoji)]), 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
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public struct channels {
|
public struct channels {
|
||||||
public static func readHistory(channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
public static func readHistory(channel: Api.InputChannel, maxId: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ public final class AvailableReactions: Equatable, Codable {
|
|||||||
case value
|
case value
|
||||||
case title
|
case title
|
||||||
case staticIcon
|
case staticIcon
|
||||||
|
case appearAnimation
|
||||||
case selectAnimation
|
case selectAnimation
|
||||||
case activateAnimation
|
case activateAnimation
|
||||||
case effectAnimation
|
case effectAnimation
|
||||||
@ -17,6 +18,7 @@ public final class AvailableReactions: Equatable, Codable {
|
|||||||
public let value: String
|
public let value: String
|
||||||
public let title: String
|
public let title: String
|
||||||
public let staticIcon: TelegramMediaFile
|
public let staticIcon: TelegramMediaFile
|
||||||
|
public let appearAnimation: TelegramMediaFile
|
||||||
public let selectAnimation: TelegramMediaFile
|
public let selectAnimation: TelegramMediaFile
|
||||||
public let activateAnimation: TelegramMediaFile
|
public let activateAnimation: TelegramMediaFile
|
||||||
public let effectAnimation: TelegramMediaFile
|
public let effectAnimation: TelegramMediaFile
|
||||||
@ -25,6 +27,7 @@ public final class AvailableReactions: Equatable, Codable {
|
|||||||
value: String,
|
value: String,
|
||||||
title: String,
|
title: String,
|
||||||
staticIcon: TelegramMediaFile,
|
staticIcon: TelegramMediaFile,
|
||||||
|
appearAnimation: TelegramMediaFile,
|
||||||
selectAnimation: TelegramMediaFile,
|
selectAnimation: TelegramMediaFile,
|
||||||
activateAnimation: TelegramMediaFile,
|
activateAnimation: TelegramMediaFile,
|
||||||
effectAnimation: TelegramMediaFile
|
effectAnimation: TelegramMediaFile
|
||||||
@ -32,6 +35,7 @@ public final class AvailableReactions: Equatable, Codable {
|
|||||||
self.value = value
|
self.value = value
|
||||||
self.title = title
|
self.title = title
|
||||||
self.staticIcon = staticIcon
|
self.staticIcon = staticIcon
|
||||||
|
self.appearAnimation = appearAnimation
|
||||||
self.selectAnimation = selectAnimation
|
self.selectAnimation = selectAnimation
|
||||||
self.activateAnimation = activateAnimation
|
self.activateAnimation = activateAnimation
|
||||||
self.effectAnimation = effectAnimation
|
self.effectAnimation = effectAnimation
|
||||||
@ -47,6 +51,9 @@ public final class AvailableReactions: Equatable, Codable {
|
|||||||
if lhs.staticIcon != rhs.staticIcon {
|
if lhs.staticIcon != rhs.staticIcon {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if lhs.appearAnimation != rhs.appearAnimation {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if lhs.selectAnimation != rhs.selectAnimation {
|
if lhs.selectAnimation != rhs.selectAnimation {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -68,6 +75,9 @@ public final class AvailableReactions: Equatable, Codable {
|
|||||||
let staticIconData = try container.decode(AdaptedPostboxDecoder.RawObjectData.self, forKey: .staticIcon)
|
let staticIconData = try container.decode(AdaptedPostboxDecoder.RawObjectData.self, forKey: .staticIcon)
|
||||||
self.staticIcon = TelegramMediaFile(decoder: PostboxDecoder(buffer: MemoryBuffer(data: staticIconData.data)))
|
self.staticIcon = TelegramMediaFile(decoder: PostboxDecoder(buffer: MemoryBuffer(data: staticIconData.data)))
|
||||||
|
|
||||||
|
let appearAnimationData = try container.decode(AdaptedPostboxDecoder.RawObjectData.self, forKey: .appearAnimation)
|
||||||
|
self.appearAnimation = TelegramMediaFile(decoder: PostboxDecoder(buffer: MemoryBuffer(data: appearAnimationData.data)))
|
||||||
|
|
||||||
let selectAnimationData = try container.decode(AdaptedPostboxDecoder.RawObjectData.self, forKey: .selectAnimation)
|
let selectAnimationData = try container.decode(AdaptedPostboxDecoder.RawObjectData.self, forKey: .selectAnimation)
|
||||||
self.selectAnimation = TelegramMediaFile(decoder: PostboxDecoder(buffer: MemoryBuffer(data: selectAnimationData.data)))
|
self.selectAnimation = TelegramMediaFile(decoder: PostboxDecoder(buffer: MemoryBuffer(data: selectAnimationData.data)))
|
||||||
|
|
||||||
@ -85,6 +95,7 @@ public final class AvailableReactions: Equatable, Codable {
|
|||||||
try container.encode(self.title, forKey: .title)
|
try container.encode(self.title, forKey: .title)
|
||||||
|
|
||||||
try container.encode(PostboxEncoder().encodeObjectToRawData(self.staticIcon), forKey: .staticIcon)
|
try container.encode(PostboxEncoder().encodeObjectToRawData(self.staticIcon), forKey: .staticIcon)
|
||||||
|
try container.encode(PostboxEncoder().encodeObjectToRawData(self.appearAnimation), forKey: .appearAnimation)
|
||||||
try container.encode(PostboxEncoder().encodeObjectToRawData(self.selectAnimation), forKey: .selectAnimation)
|
try container.encode(PostboxEncoder().encodeObjectToRawData(self.selectAnimation), forKey: .selectAnimation)
|
||||||
try container.encode(PostboxEncoder().encodeObjectToRawData(self.activateAnimation), forKey: .activateAnimation)
|
try container.encode(PostboxEncoder().encodeObjectToRawData(self.activateAnimation), forKey: .activateAnimation)
|
||||||
try container.encode(PostboxEncoder().encodeObjectToRawData(self.effectAnimation), forKey: .effectAnimation)
|
try container.encode(PostboxEncoder().encodeObjectToRawData(self.effectAnimation), forKey: .effectAnimation)
|
||||||
@ -135,10 +146,13 @@ public final class AvailableReactions: Equatable, Codable {
|
|||||||
private extension AvailableReactions.Reaction {
|
private extension AvailableReactions.Reaction {
|
||||||
convenience init?(apiReaction: Api.AvailableReaction) {
|
convenience init?(apiReaction: Api.AvailableReaction) {
|
||||||
switch apiReaction {
|
switch apiReaction {
|
||||||
case let .availableReaction(reaction, title, staticIcon, selectAnimation, activateAnimation, effectAnimation):
|
case let .availableReaction(reaction, title, staticIcon, appearAnimation, selectAnimation, activateAnimation, effectAnimation):
|
||||||
guard let staticIconFile = telegramMediaFileFromApiDocument(staticIcon) else {
|
guard let staticIconFile = telegramMediaFileFromApiDocument(staticIcon) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
guard let appearAnimationFile = telegramMediaFileFromApiDocument(appearAnimation) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
guard let selectAnimationFile = telegramMediaFileFromApiDocument(selectAnimation) else {
|
guard let selectAnimationFile = telegramMediaFileFromApiDocument(selectAnimation) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -152,6 +166,7 @@ private extension AvailableReactions.Reaction {
|
|||||||
value: reaction,
|
value: reaction,
|
||||||
title: title,
|
title: title,
|
||||||
staticIcon: staticIconFile,
|
staticIcon: staticIconFile,
|
||||||
|
appearAnimation: appearAnimationFile,
|
||||||
selectAnimation: selectAnimationFile,
|
selectAnimation: selectAnimationFile,
|
||||||
activateAnimation: activateAnimationFile,
|
activateAnimation: activateAnimationFile,
|
||||||
effectAnimation: effectAnimationFile
|
effectAnimation: effectAnimationFile
|
||||||
|
|||||||
@ -10,16 +10,38 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
case text
|
case text
|
||||||
case textEntities
|
case textEntities
|
||||||
case media
|
case media
|
||||||
case authorId
|
case target
|
||||||
case messageId
|
case messageId
|
||||||
case startParam
|
case startParam
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Target: Equatable, Codable {
|
||||||
|
enum DecodingError: Error {
|
||||||
|
case generic
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case peer
|
||||||
|
}
|
||||||
|
|
||||||
|
case peer(PeerId)
|
||||||
|
|
||||||
|
init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
|
if let peer = try container.decodeIfPresent(Int64.self, forKey: .peer) {
|
||||||
|
self = .peer(PeerId(peer))
|
||||||
|
} else {
|
||||||
|
throw DecodingError.generic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public let opaqueId: Data
|
public let opaqueId: Data
|
||||||
public let text: String
|
public let text: String
|
||||||
public let textEntities: [MessageTextEntity]
|
public let textEntities: [MessageTextEntity]
|
||||||
public let media: [Media]
|
public let media: [Media]
|
||||||
public let authorId: PeerId
|
public let target: Target
|
||||||
public let messageId: MessageId?
|
public let messageId: MessageId?
|
||||||
public let startParam: String?
|
public let startParam: String?
|
||||||
|
|
||||||
@ -28,7 +50,7 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
text: String,
|
text: String,
|
||||||
textEntities: [MessageTextEntity],
|
textEntities: [MessageTextEntity],
|
||||||
media: [Media],
|
media: [Media],
|
||||||
authorId: PeerId,
|
target: Target,
|
||||||
messageId: MessageId?,
|
messageId: MessageId?,
|
||||||
startParam: String?
|
startParam: String?
|
||||||
) {
|
) {
|
||||||
@ -36,7 +58,7 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
self.text = text
|
self.text = text
|
||||||
self.textEntities = textEntities
|
self.textEntities = textEntities
|
||||||
self.media = media
|
self.media = media
|
||||||
self.authorId = authorId
|
self.target = target
|
||||||
self.messageId = messageId
|
self.messageId = messageId
|
||||||
self.startParam = startParam
|
self.startParam = startParam
|
||||||
}
|
}
|
||||||
@ -54,7 +76,7 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
return PostboxDecoder(buffer: MemoryBuffer(data: data)).decodeRootObject() as? Media
|
return PostboxDecoder(buffer: MemoryBuffer(data: data)).decodeRootObject() as? Media
|
||||||
}
|
}
|
||||||
|
|
||||||
self.authorId = try container.decode(PeerId.self, forKey: .authorId)
|
self.target = try container.decode(Target.self, forKey: .target)
|
||||||
self.messageId = try container.decodeIfPresent(MessageId.self, forKey: .messageId)
|
self.messageId = try container.decodeIfPresent(MessageId.self, forKey: .messageId)
|
||||||
self.startParam = try container.decodeIfPresent(String.self, forKey: .startParam)
|
self.startParam = try container.decodeIfPresent(String.self, forKey: .startParam)
|
||||||
}
|
}
|
||||||
@ -73,7 +95,7 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
}
|
}
|
||||||
try container.encode(mediaData, forKey: .media)
|
try container.encode(mediaData, forKey: .media)
|
||||||
|
|
||||||
try container.encode(self.authorId, forKey: .authorId)
|
try container.encode(self.target, forKey: .target)
|
||||||
try container.encodeIfPresent(self.messageId, forKey: .messageId)
|
try container.encodeIfPresent(self.messageId, forKey: .messageId)
|
||||||
try container.encodeIfPresent(self.startParam, forKey: .startParam)
|
try container.encodeIfPresent(self.startParam, forKey: .startParam)
|
||||||
}
|
}
|
||||||
@ -96,7 +118,7 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lhs.authorId != rhs.authorId {
|
if lhs.target != rhs.target {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if lhs.messageId != rhs.messageId {
|
if lhs.messageId != rhs.messageId {
|
||||||
@ -108,7 +130,7 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func toMessage(peerId: PeerId, transaction: Transaction) -> Message {
|
func toMessage(peerId: PeerId, transaction: Transaction) -> Message? {
|
||||||
var attributes: [MessageAttribute] = []
|
var attributes: [MessageAttribute] = []
|
||||||
|
|
||||||
attributes.append(AdMessageAttribute(opaqueId: self.opaqueId, startParam: self.startParam, messageId: self.messageId))
|
attributes.append(AdMessageAttribute(opaqueId: self.opaqueId, startParam: self.startParam, messageId: self.messageId))
|
||||||
@ -122,9 +144,18 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
if let peer = transaction.getPeer(peerId) {
|
if let peer = transaction.getPeer(peerId) {
|
||||||
messagePeers[peer.id] = peer
|
messagePeers[peer.id] = peer
|
||||||
}
|
}
|
||||||
if let peer = transaction.getPeer(self.authorId) {
|
|
||||||
messagePeers[peer.id] = peer
|
let author: Peer
|
||||||
|
switch self.target {
|
||||||
|
case let .peer(peerId):
|
||||||
|
if let peer = transaction.getPeer(peerId) {
|
||||||
|
author = peer
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
messagePeers[author.id] = author
|
||||||
|
|
||||||
return Message(
|
return Message(
|
||||||
stableId: 0,
|
stableId: 0,
|
||||||
@ -140,7 +171,7 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
globalTags: [],
|
globalTags: [],
|
||||||
localTags: [],
|
localTags: [],
|
||||||
forwardInfo: nil,
|
forwardInfo: nil,
|
||||||
author: transaction.getPeer(self.authorId),
|
author: author,
|
||||||
text: self.text,
|
text: self.text,
|
||||||
attributes: attributes,
|
attributes: attributes,
|
||||||
media: self.media,
|
media: self.media,
|
||||||
@ -270,7 +301,7 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
|> mapToSignal { cachedState -> Signal<State, NoError> in
|
|> mapToSignal { cachedState -> Signal<State, NoError> in
|
||||||
if let cachedState = cachedState, cachedState.timestamp >= Int32(Date().timeIntervalSince1970) - 5 * 60 {
|
if let cachedState = cachedState, cachedState.timestamp >= Int32(Date().timeIntervalSince1970) - 5 * 60 {
|
||||||
return account.postbox.transaction { transaction -> State in
|
return account.postbox.transaction { transaction -> State in
|
||||||
return State(messages: cachedState.messages.map { message in
|
return State(messages: cachedState.messages.compactMap { message -> Message? in
|
||||||
return message.toMessage(peerId: peerId, transaction: transaction)
|
return message.toMessage(peerId: peerId, transaction: transaction)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -325,35 +356,42 @@ private class AdMessagesHistoryContextImpl {
|
|||||||
|
|
||||||
for message in messages {
|
for message in messages {
|
||||||
switch message {
|
switch message {
|
||||||
case let .sponsoredMessage(_, randomId, fromId, channelPost, startParam, message, entities):
|
case let .sponsoredMessage(_, randomId, fromId, chatInvite, chatInviteHash, channelPost, startParam, message, entities):
|
||||||
var parsedEntities: [MessageTextEntity] = []
|
var parsedEntities: [MessageTextEntity] = []
|
||||||
if let entities = entities {
|
if let entities = entities {
|
||||||
parsedEntities = messageTextEntitiesFromApiEntities(entities)
|
parsedEntities = messageTextEntitiesFromApiEntities(entities)
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsedMedia: [Media] = []
|
let _ = chatInvite
|
||||||
/*if let media = media {
|
let _ = chatInviteHash
|
||||||
let (mediaValue, _) = textMediaAndExpirationTimerFromApiMedia(media, peerId)
|
|
||||||
if let mediaValue = mediaValue {
|
|
||||||
parsedMedia.append(mediaValue)
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
var target: CachedMessage.Target?
|
||||||
|
if let fromId = fromId {
|
||||||
|
target = .peer(fromId.peerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
var messageId: MessageId?
|
||||||
|
if let fromId = fromId, let channelPost = channelPost {
|
||||||
|
messageId = MessageId(peerId: fromId.peerId, namespace: Namespaces.Message.Cloud, id: channelPost)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let target = target {
|
||||||
parsedMessages.append(CachedMessage(
|
parsedMessages.append(CachedMessage(
|
||||||
opaqueId: randomId.makeData(),
|
opaqueId: randomId.makeData(),
|
||||||
text: message,
|
text: message,
|
||||||
textEntities: parsedEntities,
|
textEntities: parsedEntities,
|
||||||
media: parsedMedia,
|
media: [],
|
||||||
authorId: fromId.peerId,
|
target: target,
|
||||||
messageId: channelPost.flatMap { MessageId(peerId: fromId.peerId, namespace: Namespaces.Message.Cloud, id: $0) },
|
messageId: messageId,
|
||||||
startParam: startParam
|
startParam: startParam
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CachedState.setCached(transaction: transaction, peerId: peerId, state: CachedState(timestamp: Int32(Date().timeIntervalSince1970), messages: parsedMessages))
|
CachedState.setCached(transaction: transaction, peerId: peerId, state: CachedState(timestamp: Int32(Date().timeIntervalSince1970), messages: parsedMessages))
|
||||||
|
|
||||||
return parsedMessages.map { message in
|
return parsedMessages.compactMap { message -> Message? in
|
||||||
return message.toMessage(peerId: peerId, transaction: transaction)
|
return message.toMessage(peerId: peerId, transaction: transaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user