Update API

This commit is contained in:
Ilya Laktyushin 2022-06-30 16:44:44 +03:00
parent 4a9c3dacc8
commit f288fe8eda
14 changed files with 161 additions and 34 deletions

View File

@ -307,7 +307,7 @@ extension InAppPurchaseManager: SKPaymentTransactionObserver {
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), sending receipt for transactions [\(transactionIds)]") Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), sending receipt for transactions [\(transactionIds)]")
self.disposableSet.set( self.disposableSet.set(
self.engine.payments.sendAppStoreReceipt(receipt: getReceiptData() ?? Data(), restore: false).start(error: { [weak self] _ in self.engine.payments.sendAppStoreReceipt(receipt: getReceiptData() ?? Data(), purpose: .subscription).start(error: { [weak self] _ in
Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transactions [\(transactionIds)] failed to assign") Logger.shared.log("InAppPurchaseManager", "Account \(accountPeerId), transactions [\(transactionIds)] failed to assign")
for transaction in transactions { for transaction in transactions {
self?.stateQueue.async { self?.stateQueue.async {
@ -337,7 +337,7 @@ extension InAppPurchaseManager: SKPaymentTransactionObserver {
if let receiptData = getReceiptData() { if let receiptData = getReceiptData() {
self.disposableSet.set( self.disposableSet.set(
self.engine.payments.sendAppStoreReceipt(receipt: receiptData, restore: true).start(error: { error in self.engine.payments.sendAppStoreReceipt(receipt: receiptData, purpose: .restore).start(error: { error in
Queue.mainQueue().async { Queue.mainQueue().async {
if case .serverProvided = error { if case .serverProvided = error {
onRestoreCompletion(.succeed(true)) onRestoreCompletion(.succeed(true))

View File

@ -347,6 +347,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-6249322] = { return Api.InputStickerSetItem.parse_inputStickerSetItem($0) } dict[-6249322] = { return Api.InputStickerSetItem.parse_inputStickerSetItem($0) }
dict[70813275] = { return Api.InputStickeredMedia.parse_inputStickeredMediaDocument($0) } dict[70813275] = { return Api.InputStickeredMedia.parse_inputStickeredMediaDocument($0) }
dict[1251549527] = { return Api.InputStickeredMedia.parse_inputStickeredMediaPhoto($0) } dict[1251549527] = { return Api.InputStickeredMedia.parse_inputStickeredMediaPhoto($0) }
dict[1147243133] = { return Api.InputStorePaymentPurpose.parse_inputStorePaymentGiftPremium($0) }
dict[-764193027] = { return Api.InputStorePaymentPurpose.parse_inputStorePaymentPremiumSubscription($0) }
dict[1012306921] = { return Api.InputTheme.parse_inputTheme($0) } dict[1012306921] = { return Api.InputTheme.parse_inputTheme($0) }
dict[-175567375] = { return Api.InputTheme.parse_inputThemeSlug($0) } dict[-175567375] = { return Api.InputTheme.parse_inputThemeSlug($0) }
dict[-1881255857] = { return Api.InputThemeSettings.parse_inputThemeSettings($0) } dict[-1881255857] = { return Api.InputThemeSettings.parse_inputThemeSettings($0) }
@ -411,6 +413,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1230047312] = { return Api.MessageAction.parse_messageActionEmpty($0) } dict[-1230047312] = { return Api.MessageAction.parse_messageActionEmpty($0) }
dict[-1834538890] = { return Api.MessageAction.parse_messageActionGameScore($0) } dict[-1834538890] = { return Api.MessageAction.parse_messageActionGameScore($0) }
dict[-1730095465] = { return Api.MessageAction.parse_messageActionGeoProximityReached($0) } dict[-1730095465] = { return Api.MessageAction.parse_messageActionGeoProximityReached($0) }
dict[380460460] = { return Api.MessageAction.parse_messageActionGiftPremium($0) }
dict[2047704898] = { return Api.MessageAction.parse_messageActionGroupCall($0) } dict[2047704898] = { return Api.MessageAction.parse_messageActionGroupCall($0) }
dict[-1281329567] = { return Api.MessageAction.parse_messageActionGroupCallScheduled($0) } dict[-1281329567] = { return Api.MessageAction.parse_messageActionGroupCallScheduled($0) }
dict[-1615153660] = { return Api.MessageAction.parse_messageActionHistoryClear($0) } dict[-1615153660] = { return Api.MessageAction.parse_messageActionHistoryClear($0) }
@ -828,7 +831,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
dict[-1831650802] = { return Api.UrlAuthResult.parse_urlAuthResultRequest($0) } dict[-1831650802] = { return Api.UrlAuthResult.parse_urlAuthResultRequest($0) }
dict[1073147056] = { return Api.User.parse_user($0) } dict[1073147056] = { return Api.User.parse_user($0) }
dict[-742634630] = { return Api.User.parse_userEmpty($0) } dict[-742634630] = { return Api.User.parse_userEmpty($0) }
dict[-1938625919] = { return Api.UserFull.parse_userFull($0) } dict[-1514584156] = { return Api.UserFull.parse_userFull($0) }
dict[-2100168954] = { return Api.UserProfilePhoto.parse_userProfilePhoto($0) } dict[-2100168954] = { return Api.UserProfilePhoto.parse_userProfilePhoto($0) }
dict[1326562017] = { return Api.UserProfilePhoto.parse_userProfilePhotoEmpty($0) } dict[1326562017] = { return Api.UserProfilePhoto.parse_userProfilePhotoEmpty($0) }
dict[164646985] = { return Api.UserStatus.parse_userStatusEmpty($0) } dict[164646985] = { return Api.UserStatus.parse_userStatusEmpty($0) }
@ -1322,6 +1325,8 @@ public extension Api {
_1.serialize(buffer, boxed) _1.serialize(buffer, boxed)
case let _1 as Api.InputStickeredMedia: case let _1 as Api.InputStickeredMedia:
_1.serialize(buffer, boxed) _1.serialize(buffer, boxed)
case let _1 as Api.InputStorePaymentPurpose:
_1.serialize(buffer, boxed)
case let _1 as Api.InputTheme: case let _1 as Api.InputTheme:
_1.serialize(buffer, boxed) _1.serialize(buffer, boxed)
case let _1 as Api.InputThemeSettings: case let _1 as Api.InputThemeSettings:

View File

@ -1005,6 +1005,7 @@ public extension Api {
case messageActionEmpty case messageActionEmpty
case messageActionGameScore(gameId: Int64, score: Int32) case messageActionGameScore(gameId: Int64, score: Int32)
case messageActionGeoProximityReached(fromId: Api.Peer, toId: Api.Peer, distance: Int32) case messageActionGeoProximityReached(fromId: Api.Peer, toId: Api.Peer, distance: Int32)
case messageActionGiftPremium(currency: String, amount: Int64, duration: Int32)
case messageActionGroupCall(flags: Int32, call: Api.InputGroupCall, duration: Int32?) case messageActionGroupCall(flags: Int32, call: Api.InputGroupCall, duration: Int32?)
case messageActionGroupCallScheduled(call: Api.InputGroupCall, scheduleDate: Int32) case messageActionGroupCallScheduled(call: Api.InputGroupCall, scheduleDate: Int32)
case messageActionHistoryClear case messageActionHistoryClear
@ -1138,6 +1139,14 @@ public extension Api {
toId.serialize(buffer, true) toId.serialize(buffer, true)
serializeInt32(distance, buffer: buffer, boxed: false) serializeInt32(distance, buffer: buffer, boxed: false)
break break
case .messageActionGiftPremium(let currency, let amount, let duration):
if boxed {
buffer.appendInt32(380460460)
}
serializeString(currency, buffer: buffer, boxed: false)
serializeInt64(amount, buffer: buffer, boxed: false)
serializeInt32(duration, buffer: buffer, boxed: false)
break
case .messageActionGroupCall(let flags, let call, let duration): case .messageActionGroupCall(let flags, let call, let duration):
if boxed { if boxed {
buffer.appendInt32(2047704898) buffer.appendInt32(2047704898)
@ -1297,6 +1306,8 @@ public extension Api {
return ("messageActionGameScore", [("gameId", String(describing: gameId)), ("score", String(describing: score))]) return ("messageActionGameScore", [("gameId", String(describing: gameId)), ("score", String(describing: score))])
case .messageActionGeoProximityReached(let fromId, let toId, let distance): case .messageActionGeoProximityReached(let fromId, let toId, let distance):
return ("messageActionGeoProximityReached", [("fromId", String(describing: fromId)), ("toId", String(describing: toId)), ("distance", String(describing: distance))]) return ("messageActionGeoProximityReached", [("fromId", String(describing: fromId)), ("toId", String(describing: toId)), ("distance", String(describing: distance))])
case .messageActionGiftPremium(let currency, let amount, let duration):
return ("messageActionGiftPremium", [("currency", String(describing: currency)), ("amount", String(describing: amount)), ("duration", String(describing: duration))])
case .messageActionGroupCall(let flags, let call, let duration): case .messageActionGroupCall(let flags, let call, let duration):
return ("messageActionGroupCall", [("flags", String(describing: flags)), ("call", String(describing: call)), ("duration", String(describing: duration))]) return ("messageActionGroupCall", [("flags", String(describing: flags)), ("call", String(describing: call)), ("duration", String(describing: duration))])
case .messageActionGroupCallScheduled(let call, let scheduleDate): case .messageActionGroupCallScheduled(let call, let scheduleDate):
@ -1510,6 +1521,23 @@ public extension Api {
return nil return nil
} }
} }
public static func parse_messageActionGiftPremium(_ reader: BufferReader) -> MessageAction? {
var _1: String?
_1 = parseString(reader)
var _2: Int64?
_2 = reader.readInt64()
var _3: Int32?
_3 = reader.readInt32()
let _c1 = _1 != nil
let _c2 = _2 != nil
let _c3 = _3 != nil
if _c1 && _c2 && _c3 {
return Api.MessageAction.messageActionGiftPremium(currency: _1!, amount: _2!, duration: _3!)
}
else {
return nil
}
}
public static func parse_messageActionGroupCall(_ reader: BufferReader) -> MessageAction? { public static func parse_messageActionGroupCall(_ reader: BufferReader) -> MessageAction? {
var _1: Int32? var _1: Int32?
_1 = reader.readInt32() _1 = reader.readInt32()

View File

@ -566,13 +566,13 @@ public extension Api {
} }
public extension Api { public extension Api {
enum UserFull: TypeConstructorDescription { 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?, botGroupAdminRights: Api.ChatAdminRights?, botBroadcastAdminRights: Api.ChatAdminRights?) 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?, botGroupAdminRights: Api.ChatAdminRights?, botBroadcastAdminRights: Api.ChatAdminRights?, giftPremiumUrl: String?)
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self { 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, let botGroupAdminRights, let botBroadcastAdminRights): 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, let botGroupAdminRights, let botBroadcastAdminRights, let giftPremiumUrl):
if boxed { if boxed {
buffer.appendInt32(-1938625919) buffer.appendInt32(-1514584156)
} }
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
serializeInt64(id, buffer: buffer, boxed: false) serializeInt64(id, buffer: buffer, boxed: false)
@ -589,14 +589,15 @@ public extension Api {
if Int(flags) & Int(1 << 16) != 0 {serializeString(privateForwardName!, buffer: buffer, boxed: false)} if Int(flags) & Int(1 << 16) != 0 {serializeString(privateForwardName!, buffer: buffer, boxed: false)}
if Int(flags) & Int(1 << 17) != 0 {botGroupAdminRights!.serialize(buffer, true)} if Int(flags) & Int(1 << 17) != 0 {botGroupAdminRights!.serialize(buffer, true)}
if Int(flags) & Int(1 << 18) != 0 {botBroadcastAdminRights!.serialize(buffer, true)} if Int(flags) & Int(1 << 18) != 0 {botBroadcastAdminRights!.serialize(buffer, true)}
if Int(flags) & Int(1 << 19) != 0 {serializeString(giftPremiumUrl!, buffer: buffer, boxed: false)}
break break
} }
} }
public func descriptionFields() -> (String, [(String, Any)]) { public func descriptionFields() -> (String, [(String, Any)]) {
switch self { 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, let botGroupAdminRights, let botBroadcastAdminRights): 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, let botGroupAdminRights, let botBroadcastAdminRights, let giftPremiumUrl):
return ("userFull", [("flags", String(describing: flags)), ("id", String(describing: id)), ("about", String(describing: about)), ("settings", String(describing: settings)), ("profilePhoto", String(describing: profilePhoto)), ("notifySettings", String(describing: notifySettings)), ("botInfo", String(describing: botInfo)), ("pinnedMsgId", String(describing: pinnedMsgId)), ("commonChatsCount", String(describing: commonChatsCount)), ("folderId", String(describing: folderId)), ("ttlPeriod", String(describing: ttlPeriod)), ("themeEmoticon", String(describing: themeEmoticon)), ("privateForwardName", String(describing: privateForwardName)), ("botGroupAdminRights", String(describing: botGroupAdminRights)), ("botBroadcastAdminRights", String(describing: botBroadcastAdminRights))]) return ("userFull", [("flags", String(describing: flags)), ("id", String(describing: id)), ("about", String(describing: about)), ("settings", String(describing: settings)), ("profilePhoto", String(describing: profilePhoto)), ("notifySettings", String(describing: notifySettings)), ("botInfo", String(describing: botInfo)), ("pinnedMsgId", String(describing: pinnedMsgId)), ("commonChatsCount", String(describing: commonChatsCount)), ("folderId", String(describing: folderId)), ("ttlPeriod", String(describing: ttlPeriod)), ("themeEmoticon", String(describing: themeEmoticon)), ("privateForwardName", String(describing: privateForwardName)), ("botGroupAdminRights", String(describing: botGroupAdminRights)), ("botBroadcastAdminRights", String(describing: botBroadcastAdminRights)), ("giftPremiumUrl", String(describing: giftPremiumUrl))])
} }
} }
@ -643,6 +644,8 @@ public extension Api {
if Int(_1!) & Int(1 << 18) != 0 {if let signature = reader.readInt32() { if Int(_1!) & Int(1 << 18) != 0 {if let signature = reader.readInt32() {
_15 = Api.parse(reader, signature: signature) as? Api.ChatAdminRights _15 = Api.parse(reader, signature: signature) as? Api.ChatAdminRights
} } } }
var _16: String?
if Int(_1!) & Int(1 << 19) != 0 {_16 = parseString(reader) }
let _c1 = _1 != nil let _c1 = _1 != nil
let _c2 = _2 != nil let _c2 = _2 != nil
let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil let _c3 = (Int(_1!) & Int(1 << 1) == 0) || _3 != nil
@ -658,8 +661,9 @@ public extension Api {
let _c13 = (Int(_1!) & Int(1 << 16) == 0) || _13 != nil let _c13 = (Int(_1!) & Int(1 << 16) == 0) || _13 != nil
let _c14 = (Int(_1!) & Int(1 << 17) == 0) || _14 != nil let _c14 = (Int(_1!) & Int(1 << 17) == 0) || _14 != nil
let _c15 = (Int(_1!) & Int(1 << 18) == 0) || _15 != nil let _c15 = (Int(_1!) & Int(1 << 18) == 0) || _15 != nil
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 { let _c16 = (Int(_1!) & Int(1 << 19) == 0) || _16 != nil
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, botGroupAdminRights: _14, botBroadcastAdminRights: _15) if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 && _c14 && _c15 && _c16 {
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, botGroupAdminRights: _14, botBroadcastAdminRights: _15, giftPremiumUrl: _16)
} }
else { else {
return nil return nil

View File

@ -6229,12 +6229,13 @@ public extension Api.functions.messages {
} }
} }
public extension Api.functions.payments { public extension Api.functions.payments {
static func assignAppStoreTransaction(flags: Int32, receipt: Buffer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) { static func assignAppStoreTransaction(flags: Int32, receipt: Buffer, purpose: Api.InputStorePaymentPurpose) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer() let buffer = Buffer()
buffer.appendInt32(224186320) buffer.appendInt32(296120783)
serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false)
serializeBytes(receipt, buffer: buffer, boxed: false) serializeBytes(receipt, buffer: buffer, boxed: false)
return (FunctionDescription(name: "payments.assignAppStoreTransaction", parameters: [("flags", String(describing: flags)), ("receipt", String(describing: receipt))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in purpose.serialize(buffer, true)
return (FunctionDescription(name: "payments.assignAppStoreTransaction", parameters: [("flags", String(describing: flags)), ("receipt", String(describing: receipt)), ("purpose", String(describing: purpose))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
let reader = BufferReader(buffer) let reader = BufferReader(buffer)
var result: Api.Updates? var result: Api.Updates?
if let signature = reader.readInt32() { if let signature = reader.readInt32() {
@ -6245,11 +6246,12 @@ public extension Api.functions.payments {
} }
} }
public extension Api.functions.payments { public extension Api.functions.payments {
static func assignPlayMarketTransaction(purchaseToken: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) { static func assignPlayMarketTransaction(purchaseToken: String, purpose: Api.InputStorePaymentPurpose) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Updates>) {
let buffer = Buffer() let buffer = Buffer()
buffer.appendInt32(1336560365) buffer.appendInt32(-179907586)
serializeString(purchaseToken, buffer: buffer, boxed: false) serializeString(purchaseToken, buffer: buffer, boxed: false)
return (FunctionDescription(name: "payments.assignPlayMarketTransaction", parameters: [("purchaseToken", String(describing: purchaseToken))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in purpose.serialize(buffer, true)
return (FunctionDescription(name: "payments.assignPlayMarketTransaction", parameters: [("purchaseToken", String(describing: purchaseToken)), ("purpose", String(describing: purpose))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in
let reader = BufferReader(buffer) let reader = BufferReader(buffer)
var result: Api.Updates? var result: Api.Updates?
if let signature = reader.readInt32() { if let signature = reader.readInt32() {

View File

@ -454,6 +454,56 @@ public extension Api {
} }
} }
public extension Api {
enum InputStorePaymentPurpose: TypeConstructorDescription {
case inputStorePaymentGiftPremium(userId: Api.InputUser)
case inputStorePaymentPremiumSubscription
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
switch self {
case .inputStorePaymentGiftPremium(let userId):
if boxed {
buffer.appendInt32(1147243133)
}
userId.serialize(buffer, true)
break
case .inputStorePaymentPremiumSubscription:
if boxed {
buffer.appendInt32(-764193027)
}
break
}
}
public func descriptionFields() -> (String, [(String, Any)]) {
switch self {
case .inputStorePaymentGiftPremium(let userId):
return ("inputStorePaymentGiftPremium", [("userId", String(describing: userId))])
case .inputStorePaymentPremiumSubscription:
return ("inputStorePaymentPremiumSubscription", [])
}
}
public static func parse_inputStorePaymentGiftPremium(_ reader: BufferReader) -> InputStorePaymentPurpose? {
var _1: Api.InputUser?
if let signature = reader.readInt32() {
_1 = Api.parse(reader, signature: signature) as? Api.InputUser
}
let _c1 = _1 != nil
if _c1 {
return Api.InputStorePaymentPurpose.inputStorePaymentGiftPremium(userId: _1!)
}
else {
return nil
}
}
public static func parse_inputStorePaymentPremiumSubscription(_ reader: BufferReader) -> InputStorePaymentPurpose? {
return Api.InputStorePaymentPurpose.inputStorePaymentPremiumSubscription
}
}
}
public extension Api { public extension Api {
enum InputTheme: TypeConstructorDescription { enum InputTheme: TypeConstructorDescription {
case inputTheme(id: Int64, accessHash: Int64) case inputTheme(id: Int64, accessHash: Int64)

View File

@ -201,7 +201,7 @@ func apiMessagePeerIds(_ message: Api.Message) -> [PeerId] {
} }
switch action { switch action {
case .messageActionChannelCreate, .messageActionChatDeletePhoto, .messageActionChatEditPhoto, .messageActionChatEditTitle, .messageActionEmpty, .messageActionPinMessage, .messageActionHistoryClear, .messageActionGameScore, .messageActionPaymentSent, .messageActionPaymentSentMe, .messageActionPhoneCall, .messageActionScreenshotTaken, .messageActionCustomAction, .messageActionBotAllowed, .messageActionSecureValuesSent, .messageActionSecureValuesSentMe, .messageActionContactSignUp, .messageActionGroupCall, .messageActionSetMessagesTTL, .messageActionGroupCallScheduled, .messageActionSetChatTheme, .messageActionChatJoinedByRequest, .messageActionWebViewDataSent, .messageActionWebViewDataSentMe: case .messageActionChannelCreate, .messageActionChatDeletePhoto, .messageActionChatEditPhoto, .messageActionChatEditTitle, .messageActionEmpty, .messageActionPinMessage, .messageActionHistoryClear, .messageActionGameScore, .messageActionPaymentSent, .messageActionPaymentSentMe, .messageActionPhoneCall, .messageActionScreenshotTaken, .messageActionCustomAction, .messageActionBotAllowed, .messageActionSecureValuesSent, .messageActionSecureValuesSentMe, .messageActionContactSignUp, .messageActionGroupCall, .messageActionSetMessagesTTL, .messageActionGroupCallScheduled, .messageActionSetChatTheme, .messageActionChatJoinedByRequest, .messageActionWebViewDataSent, .messageActionWebViewDataSentMe, .messageActionGiftPremium:
break break
case let .messageActionChannelMigrateFrom(_, chatId): case let .messageActionChannelMigrateFrom(_, chatId):
result.append(PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId))) result.append(PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(chatId)))

View File

@ -85,6 +85,8 @@ func telegramMediaActionFromApiAction(_ action: Api.MessageAction) -> TelegramMe
return TelegramMediaAction(action: .joinedByRequest) return TelegramMediaAction(action: .joinedByRequest)
case let .messageActionWebViewDataSentMe(text, _), let .messageActionWebViewDataSent(text): case let .messageActionWebViewDataSentMe(text, _), let .messageActionWebViewDataSent(text):
return TelegramMediaAction(action: .webViewData(text)) return TelegramMediaAction(action: .webViewData(text))
case let .messageActionGiftPremium(currency, amount, duration):
return TelegramMediaAction(action: .giftPremium(currency: currency, amount: amount, duration: duration))
} }
} }

View File

@ -51,6 +51,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case setChatTheme(emoji: String) case setChatTheme(emoji: String)
case joinedByRequest case joinedByRequest
case webViewData(String) case webViewData(String)
case giftPremium(currency: String, amount: Int64, duration: Int32)
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0) let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
@ -119,6 +120,8 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
self = .joinedByRequest self = .joinedByRequest
case 26: case 26:
self = .webViewData(decoder.decodeStringForKey("t", orElse: "")) self = .webViewData(decoder.decodeStringForKey("t", orElse: ""))
case 27:
self = .giftPremium(currency: decoder.decodeStringForKey("currency", orElse: ""), amount: decoder.decodeInt64ForKey("amount", orElse: 0), duration: decoder.decodeInt32ForKey("duration", orElse: 0))
default: default:
self = .unknown self = .unknown
} }
@ -243,6 +246,11 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
case let .webViewData(text): case let .webViewData(text):
encoder.encodeInt32(26, forKey: "_rawValue") encoder.encodeInt32(26, forKey: "_rawValue")
encoder.encodeString(text, forKey: "t") encoder.encodeString(text, forKey: "t")
case let .giftPremium(currency, amount, duration):
encoder.encodeInt32(27, forKey: "_rawValue")
encoder.encodeString(currency, forKey: "currency")
encoder.encodeInt64(amount, forKey: "amount")
encoder.encodeInt32(duration, forKey: "duration")
} }
} }

View File

@ -10,12 +10,37 @@ public enum AssignAppStoreTransactionError {
case serverProvided case serverProvided
} }
func _internal_sendAppStoreReceipt(account: Account, receipt: Data, restore: Bool) -> Signal<Never, AssignAppStoreTransactionError> { public enum AppStoreTransactionPurpose {
case subscription
case gift(EnginePeer.Id)
case restore
}
func _internal_sendAppStoreReceipt(account: Account, receipt: Data, purpose: AppStoreTransactionPurpose) -> Signal<Never, AssignAppStoreTransactionError> {
var flags: Int32 = 0 var flags: Int32 = 0
if restore { if case .restore = purpose {
flags |= (1 << 0) flags |= (1 << 0)
} }
return account.network.request(Api.functions.payments.assignAppStoreTransaction(flags: flags, receipt: Buffer(data: receipt)))
var purposeSignal: Signal<Api.InputStorePaymentPurpose, NoError>
switch purpose {
case .subscription, .restore:
purposeSignal = .single(.inputStorePaymentPremiumSubscription)
case let .gift(peerId):
purposeSignal = account.postbox.loadedPeerWithId(peerId)
|> mapToSignal { peer -> Signal<Api.InputStorePaymentPurpose, NoError> in
if let inputUser = apiInputUser(peer) {
return .single(.inputStorePaymentGiftPremium(userId: inputUser))
} else {
return .complete()
}
}
}
return purposeSignal
|> castError(AssignAppStoreTransactionError.self)
|> mapToSignal { purpose -> Signal<Never, AssignAppStoreTransactionError> in
return account.network.request(Api.functions.payments.assignAppStoreTransaction(flags: flags, receipt: Buffer(data: receipt), purpose: purpose))
|> mapError { error -> AssignAppStoreTransactionError in |> mapError { error -> AssignAppStoreTransactionError in
if error.errorCode == 406 { if error.errorCode == 406 {
return .serverProvided return .serverProvided
@ -27,6 +52,7 @@ func _internal_sendAppStoreReceipt(account: Account, receipt: Data, restore: Boo
account.stateManager.addUpdates(updates) account.stateManager.addUpdates(updates)
return .complete() return .complete()
} }
}
} }
public enum RestoreAppStoreReceiptError { public enum RestoreAppStoreReceiptError {

View File

@ -38,8 +38,8 @@ public extension TelegramEngine {
return _internal_clearBotPaymentInfo(network: self.account.network, info: info) return _internal_clearBotPaymentInfo(network: self.account.network, info: info)
} }
public func sendAppStoreReceipt(receipt: Data, restore: Bool) -> Signal<Never, AssignAppStoreTransactionError> { public func sendAppStoreReceipt(receipt: Data, purpose: AppStoreTransactionPurpose) -> Signal<Never, AssignAppStoreTransactionError> {
return _internal_sendAppStoreReceipt(account: self.account, receipt: receipt, restore: restore) return _internal_sendAppStoreReceipt(account: self.account, receipt: receipt, purpose: purpose)
} }
public func canPurchasePremium() -> Signal<Bool, NoError> { public func canPurchasePremium() -> Signal<Bool, NoError> {

View File

@ -216,7 +216,7 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
} }
switch fullUser { switch fullUser {
case let .userFull(_, _, _, _, _, userFullNotifySettings, _, _, _, _, _, _, _, _, _): case let .userFull(_, _, _, _, _, userFullNotifySettings, _, _, _, _, _, _, _, _, _, _):
updatePeers(transaction: transaction, peers: peers, update: { previous, updated -> Peer in updatePeers(transaction: transaction, peers: peers, update: { previous, updated -> Peer in
if previous?.id == accountPeerId, let accountUser = accountUser, let user = TelegramUser.merge(previous as? TelegramUser, rhs: accountUser) { if previous?.id == accountPeerId, let accountUser = accountUser, let user = TelegramUser.merge(previous as? TelegramUser, rhs: accountUser) {
return user return user
@ -234,7 +234,7 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
previous = CachedUserData() previous = CachedUserData()
} }
switch fullUser { switch fullUser {
case let .userFull(userFullFlags, _, userFullAbout, userFullSettings, profilePhoto, _, userFullBotInfo, userFullPinnedMsgId, userFullCommonChatsCount, _, userFullTtlPeriod, userFullThemeEmoticon, _, _, _): case let .userFull(userFullFlags, _, userFullAbout, userFullSettings, profilePhoto, _, userFullBotInfo, userFullPinnedMsgId, userFullCommonChatsCount, _, userFullTtlPeriod, userFullThemeEmoticon, _, _, _, _):
let botInfo = userFullBotInfo.flatMap(BotInfo.init(apiBotInfo:)) let botInfo = userFullBotInfo.flatMap(BotInfo.init(apiBotInfo:))
let isBlocked = (userFullFlags & (1 << 0)) != 0 let isBlocked = (userFullFlags & (1 << 0)) != 0
let voiceCallsAvailable = (userFullFlags & (1 << 4)) != 0 let voiceCallsAvailable = (userFullFlags & (1 << 4)) != 0

View File

@ -652,6 +652,8 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
} }
case let .webViewData(text): case let .webViewData(text):
attributedString = NSAttributedString(string: strings.Notification_WebAppSentData(text).string, font: titleFont, textColor: primaryTextColor) attributedString = NSAttributedString(string: strings.Notification_WebAppSentData(text).string, font: titleFont, textColor: primaryTextColor)
case .giftPremium:
attributedString = nil
case .unknown: case .unknown:
attributedString = nil attributedString = nil
} }

View File

@ -172,7 +172,7 @@ extension ImageYUVA420 {
let sourcePixels = sourceBytes.baseAddress!.assumingMemoryBound(to: UInt8.self) let sourcePixels = sourceBytes.baseAddress!.assumingMemoryBound(to: UInt8.self)
targetPlane.data.withUnsafeMutableBytes { bytes in targetPlane.data.withUnsafeMutableBytes { bytes in
let coefficients = bytes.baseAddress!.assumingMemoryBound(to: UInt16.self) let coefficients = bytes.baseAddress!.assumingMemoryBound(to: Int16.self)
performForwardDct(sourcePixels, coefficients, Int32(sourcePlane.width), Int32(sourcePlane.height), Int32(sourcePlane.bytesPerRow), dctData.dctData) performForwardDct(sourcePixels, coefficients, Int32(sourcePlane.width), Int32(sourcePlane.height), Int32(sourcePlane.bytesPerRow), dctData.dctData)
} }
@ -212,7 +212,7 @@ extension DctCoefficientsYUVA420 {
} }
sourcePlane.data.withUnsafeBytes { sourceBytes in sourcePlane.data.withUnsafeBytes { sourceBytes in
let coefficients = sourceBytes.baseAddress!.assumingMemoryBound(to: UInt16.self) let coefficients = sourceBytes.baseAddress!.assumingMemoryBound(to: Int16.self)
targetPlane.data.withUnsafeMutableBytes { bytes in targetPlane.data.withUnsafeMutableBytes { bytes in
let pixels = bytes.baseAddress!.assumingMemoryBound(to: UInt8.self) let pixels = bytes.baseAddress!.assumingMemoryBound(to: UInt8.self)