diff --git a/TelegramCore/BotPaymentForm.swift b/TelegramCore/BotPaymentForm.swift index 0edfdf433c..f24d623ad8 100644 --- a/TelegramCore/BotPaymentForm.swift +++ b/TelegramCore/BotPaymentForm.swift @@ -400,8 +400,30 @@ public func requestBotPaymentReceipt(network: Network, messageId: MessageId) -> } } -public func clearBotPaymentInfo(network: Network) -> Signal { - return network.request(Api.functions.payments.clearSavedInfo(flags: 1 | 2)) +public struct BotPaymentInfo: OptionSet { + public var rawValue: Int32 + + public init(rawValue: Int32) { + self.rawValue = rawValue + } + + public init() { + self.rawValue = 0 + } + + public static let paymentInfo = BotPaymentInfo(rawValue: 1 << 0) + public static let shippingInfo = BotPaymentInfo(rawValue: 1 << 1) +} + +public func clearBotPaymentInfo(network: Network, info: BotPaymentInfo) -> Signal { + var flags: Int32 = 0 + if info.contains(.paymentInfo) { + flags |= (1 << 0) + } + if info.contains(.shippingInfo) { + flags |= (1 << 1) + } + return network.request(Api.functions.payments.clearSavedInfo(flags: flags)) |> retryRequest |> mapToSignal { _ -> Signal in return .complete() diff --git a/TelegramCore/CachedUserData.swift b/TelegramCore/CachedUserData.swift index c92027d541..b1b9cb1b68 100644 --- a/TelegramCore/CachedUserData.swift +++ b/TelegramCore/CachedUserData.swift @@ -11,6 +11,8 @@ public final class CachedUserData: CachedPeerData { public let reportStatus: PeerReportStatus public let isBlocked: Bool public let commonGroupCount: Int32 + public let callsAvailable: Bool + public let callsPrivate: Bool public let peerIds = Set() public let messageIds = Set() @@ -22,14 +24,18 @@ public final class CachedUserData: CachedPeerData { self.reportStatus = .unknown self.isBlocked = false self.commonGroupCount = 0 + self.callsAvailable = false + self.callsPrivate = false } - init(about: String?, botInfo: BotInfo?, reportStatus: PeerReportStatus, isBlocked: Bool, commonGroupCount: Int32) { + init(about: String?, botInfo: BotInfo?, reportStatus: PeerReportStatus, isBlocked: Bool, commonGroupCount: Int32, callsAvailable: Bool, callsPrivate: Bool) { self.about = about self.botInfo = botInfo self.reportStatus = reportStatus self.isBlocked = isBlocked self.commonGroupCount = commonGroupCount + self.callsAvailable = callsAvailable + self.callsPrivate = callsPrivate } public init(decoder: PostboxDecoder) { @@ -38,6 +44,8 @@ public final class CachedUserData: CachedPeerData { self.reportStatus = PeerReportStatus(rawValue: decoder.decodeInt32ForKey("r", orElse: 0))! self.isBlocked = decoder.decodeInt32ForKey("b", orElse: 0) != 0 self.commonGroupCount = decoder.decodeInt32ForKey("cg", orElse: 0) + self.callsAvailable = decoder.decodeInt32ForKey("ca", orElse: 0) != 0 + self.callsPrivate = decoder.decodeInt32ForKey("cp", orElse: 0) != 0 } public func encode(_ encoder: PostboxEncoder) { @@ -54,6 +62,8 @@ public final class CachedUserData: CachedPeerData { encoder.encodeInt32(self.reportStatus.rawValue, forKey: "r") encoder.encodeInt32(self.isBlocked ? 1 : 0, forKey: "b") encoder.encodeInt32(self.commonGroupCount, forKey: "cg") + encoder.encodeInt32(self.callsAvailable ? 1 : 0, forKey: "ca") + encoder.encodeInt32(self.callsPrivate ? 1 : 0, forKey: "cp") } public func isEqual(to: CachedPeerData) -> Bool { @@ -61,26 +71,34 @@ public final class CachedUserData: CachedPeerData { return false } - return other.about == self.about && other.botInfo == self.botInfo && self.reportStatus == other.reportStatus && self.isBlocked == other.isBlocked && self.commonGroupCount == other.commonGroupCount + return other.about == self.about && other.botInfo == self.botInfo && self.reportStatus == other.reportStatus && self.isBlocked == other.isBlocked && self.commonGroupCount == other.commonGroupCount && self.callsAvailable == other.callsAvailable && self.callsPrivate == other.callsPrivate } func withUpdatedAbout(_ about: String?) -> CachedUserData { - return CachedUserData(about: about, botInfo: self.botInfo, reportStatus: self.reportStatus, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount) + return CachedUserData(about: about, botInfo: self.botInfo, reportStatus: self.reportStatus, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate) } func withUpdatedBotInfo(_ botInfo: BotInfo?) -> CachedUserData { - return CachedUserData(about: self.about, botInfo: botInfo, reportStatus: self.reportStatus, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount) + return CachedUserData(about: self.about, botInfo: botInfo, reportStatus: self.reportStatus, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate) } func withUpdatedReportStatus(_ reportStatus: PeerReportStatus) -> CachedUserData { - return CachedUserData(about: self.about, botInfo: self.botInfo, reportStatus: reportStatus, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount) + return CachedUserData(about: self.about, botInfo: self.botInfo, reportStatus: reportStatus, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate) } func withUpdatedIsBlocked(_ isBlocked: Bool) -> CachedUserData { - return CachedUserData(about: self.about, botInfo: self.botInfo, reportStatus: self.reportStatus, isBlocked: isBlocked, commonGroupCount: self.commonGroupCount) + return CachedUserData(about: self.about, botInfo: self.botInfo, reportStatus: self.reportStatus, isBlocked: isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate) } func withUpdatedCommonGroupCount(_ commonGroupCount: Int32) -> CachedUserData { - return CachedUserData(about: self.about, botInfo: self.botInfo, reportStatus: self.reportStatus, isBlocked: self.isBlocked, commonGroupCount: commonGroupCount) + return CachedUserData(about: self.about, botInfo: self.botInfo, reportStatus: self.reportStatus, isBlocked: self.isBlocked, commonGroupCount: commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: self.callsPrivate) + } + + func withUpdatedCallsAvailable(_ callsAvailable: Bool) -> CachedUserData { + return CachedUserData(about: self.about, botInfo: self.botInfo, reportStatus: self.reportStatus, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: callsAvailable, callsPrivate: self.callsPrivate) + } + + func withUpdatedCallsPrivate(_ callsPrivate: Bool) -> CachedUserData { + return CachedUserData(about: self.about, botInfo: self.botInfo, reportStatus: self.reportStatus, isBlocked: self.isBlocked, commonGroupCount: self.commonGroupCount, callsAvailable: self.callsAvailable, callsPrivate: callsPrivate) } } diff --git a/TelegramCore/PendingMessageUploadedContent.swift b/TelegramCore/PendingMessageUploadedContent.swift index cfcc9e6357..8d92d44975 100644 --- a/TelegramCore/PendingMessageUploadedContent.swift +++ b/TelegramCore/PendingMessageUploadedContent.swift @@ -230,7 +230,7 @@ private func uploadedMediaImageContent(network: Network, postbox: Postbox, trans var flags: Int32 = 0 var ttlSeconds: Int32? if let autoremoveAttribute = autoremoveAttribute { - flags |= 1 << 1 + flags |= 1 << 0 ttlSeconds = autoremoveAttribute.timeout } return .single(.progress(1.0)) @@ -337,7 +337,7 @@ private func uploadedMediaImageContent(network: Network, postbox: Postbox, trans var flags: Int32 = 0 var ttlSeconds: Int32? if let autoremoveAttribute = autoremoveAttribute { - flags |= 1 << 1 + flags |= 1 << 0 ttlSeconds = autoremoveAttribute.timeout } return maybeCacheUploadedResource(postbox: postbox, key: referenceKey, result: .content(PendingMessageUploadedContentAndReuploadInfo(content: .media(.inputMediaPhoto(flags: flags, id: .inputPhoto(id: id, accessHash: accessHash, fileReference: Buffer(data: fileReference)), ttlSeconds: ttlSeconds), text), reuploadInfo: nil)), media: mediaImage) diff --git a/TelegramCore/UpdateCachedPeerData.swift b/TelegramCore/UpdateCachedPeerData.swift index 50a1ae9d1e..ee40f4f490 100644 --- a/TelegramCore/UpdateCachedPeerData.swift +++ b/TelegramCore/UpdateCachedPeerData.swift @@ -139,7 +139,9 @@ func fetchAndUpdateCachedPeerData(peerId: PeerId, network: Network, postbox: Pos botInfo = nil } let isBlocked = (flags & (1 << 0)) != 0 - return previous.withUpdatedAbout(about).withUpdatedBotInfo(botInfo).withUpdatedCommonGroupCount(commonChatsCount).withUpdatedIsBlocked(isBlocked) + let callsAvailable = (flags & (1 << 4)) != 0 + let callsPrivate = (flags & (1 << 5)) != 0 + return previous.withUpdatedAbout(about).withUpdatedBotInfo(botInfo).withUpdatedCommonGroupCount(commonChatsCount).withUpdatedIsBlocked(isBlocked).withUpdatedCallsAvailable(callsAvailable).withUpdatedCallsPrivate(callsPrivate) } }) }