no message

This commit is contained in:
Ilya Laktyushin 2018-09-05 00:49:02 +03:00
parent d8eac512ba
commit e6d646db71
4 changed files with 54 additions and 12 deletions

View File

@ -400,8 +400,30 @@ public func requestBotPaymentReceipt(network: Network, messageId: MessageId) ->
} }
} }
public func clearBotPaymentInfo(network: Network) -> Signal<Void, NoError> { public struct BotPaymentInfo: OptionSet {
return network.request(Api.functions.payments.clearSavedInfo(flags: 1 | 2)) 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<Void, NoError> {
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 |> retryRequest
|> mapToSignal { _ -> Signal<Void, NoError> in |> mapToSignal { _ -> Signal<Void, NoError> in
return .complete() return .complete()

View File

@ -11,6 +11,8 @@ public final class CachedUserData: CachedPeerData {
public let reportStatus: PeerReportStatus public let reportStatus: PeerReportStatus
public let isBlocked: Bool public let isBlocked: Bool
public let commonGroupCount: Int32 public let commonGroupCount: Int32
public let callsAvailable: Bool
public let callsPrivate: Bool
public let peerIds = Set<PeerId>() public let peerIds = Set<PeerId>()
public let messageIds = Set<MessageId>() public let messageIds = Set<MessageId>()
@ -22,14 +24,18 @@ public final class CachedUserData: CachedPeerData {
self.reportStatus = .unknown self.reportStatus = .unknown
self.isBlocked = false self.isBlocked = false
self.commonGroupCount = 0 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.about = about
self.botInfo = botInfo self.botInfo = botInfo
self.reportStatus = reportStatus self.reportStatus = reportStatus
self.isBlocked = isBlocked self.isBlocked = isBlocked
self.commonGroupCount = commonGroupCount self.commonGroupCount = commonGroupCount
self.callsAvailable = callsAvailable
self.callsPrivate = callsPrivate
} }
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
@ -38,6 +44,8 @@ public final class CachedUserData: CachedPeerData {
self.reportStatus = PeerReportStatus(rawValue: decoder.decodeInt32ForKey("r", orElse: 0))! self.reportStatus = PeerReportStatus(rawValue: decoder.decodeInt32ForKey("r", orElse: 0))!
self.isBlocked = decoder.decodeInt32ForKey("b", orElse: 0) != 0 self.isBlocked = decoder.decodeInt32ForKey("b", orElse: 0) != 0
self.commonGroupCount = decoder.decodeInt32ForKey("cg", orElse: 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) { public func encode(_ encoder: PostboxEncoder) {
@ -54,6 +62,8 @@ public final class CachedUserData: CachedPeerData {
encoder.encodeInt32(self.reportStatus.rawValue, forKey: "r") encoder.encodeInt32(self.reportStatus.rawValue, forKey: "r")
encoder.encodeInt32(self.isBlocked ? 1 : 0, forKey: "b") encoder.encodeInt32(self.isBlocked ? 1 : 0, forKey: "b")
encoder.encodeInt32(self.commonGroupCount, forKey: "cg") 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 { public func isEqual(to: CachedPeerData) -> Bool {
@ -61,26 +71,34 @@ public final class CachedUserData: CachedPeerData {
return false 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 { 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 { 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 { 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 { 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 { 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)
} }
} }

View File

@ -230,7 +230,7 @@ private func uploadedMediaImageContent(network: Network, postbox: Postbox, trans
var flags: Int32 = 0 var flags: Int32 = 0
var ttlSeconds: Int32? var ttlSeconds: Int32?
if let autoremoveAttribute = autoremoveAttribute { if let autoremoveAttribute = autoremoveAttribute {
flags |= 1 << 1 flags |= 1 << 0
ttlSeconds = autoremoveAttribute.timeout ttlSeconds = autoremoveAttribute.timeout
} }
return .single(.progress(1.0)) return .single(.progress(1.0))
@ -337,7 +337,7 @@ private func uploadedMediaImageContent(network: Network, postbox: Postbox, trans
var flags: Int32 = 0 var flags: Int32 = 0
var ttlSeconds: Int32? var ttlSeconds: Int32?
if let autoremoveAttribute = autoremoveAttribute { if let autoremoveAttribute = autoremoveAttribute {
flags |= 1 << 1 flags |= 1 << 0
ttlSeconds = autoremoveAttribute.timeout 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) 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)

View File

@ -139,7 +139,9 @@ func fetchAndUpdateCachedPeerData(peerId: PeerId, network: Network, postbox: Pos
botInfo = nil botInfo = nil
} }
let isBlocked = (flags & (1 << 0)) != 0 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)
} }
}) })
} }