StickerPack changes

This commit is contained in:
overtake 2017-02-28 13:29:48 +03:00
parent bfe71c295e
commit 449a36aa6b
2 changed files with 44 additions and 3 deletions

View File

@ -39,8 +39,15 @@ func manageStickerPacks(network: Network, postbox: Postbox) -> Signal<Void, NoEr
case let .allStickers(_, sets):
for apiPack in sets {
switch apiPack {
case let .stickerSet(_, id, accessHash, title, shortName, _, nHash):
stickerPackInfos.append(StickerPackCollectionInfo(id: ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id), accessHash: accessHash, title: title, shortName: shortName, hash: nHash))
case let .stickerSet(flags, id, accessHash, title, shortName, _, nHash):
var setFlags:StickerPackCollectionInfoFlags = StickerPackCollectionInfoFlags()
if (flags & (1 << 2)) != 0 {
setFlags.insert(.official)
}
if (flags & (1 << 3)) != 0 {
setFlags.insert(.masks)
}
stickerPackInfos.append(StickerPackCollectionInfo(id: ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id), flags: setFlags, accessHash: accessHash, title: title, shortName: shortName, hash: nHash))
}
}
break

View File

@ -5,15 +5,47 @@ import Foundation
import Postbox
#endif
public struct StickerPackCollectionInfoFlags : OptionSet {
public var rawValue: Int32
public init(rawValue: Int32) {
self.rawValue = rawValue
}
public init() {
self.rawValue = 0
}
public init(_ flags: StickerPackCollectionInfoFlags) {
var rawValue: Int32 = 0
if flags.contains(StickerPackCollectionInfoFlags.masks) {
rawValue |= StickerPackCollectionInfoFlags.masks.rawValue
}
if flags.contains(StickerPackCollectionInfoFlags.official) {
rawValue |= StickerPackCollectionInfoFlags.official.rawValue
}
self.rawValue = rawValue
}
public static let masks = StickerPackCollectionInfoFlags(rawValue: 1)
public static let official = StickerPackCollectionInfoFlags(rawValue: 2)
}
public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable {
public let id: ItemCollectionId
public let flags:StickerPackCollectionInfoFlags
public let accessHash: Int64
public let title: String
public let shortName: String
public let hash: Int32
public init(id: ItemCollectionId, accessHash: Int64, title: String, shortName: String, hash: Int32) {
public init(id: ItemCollectionId, flags: StickerPackCollectionInfoFlags, accessHash: Int64, title: String, shortName: String, hash: Int32) {
self.id = id
self.flags = flags
self.accessHash = accessHash
self.title = title
self.shortName = shortName
@ -26,6 +58,7 @@ public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable {
self.title = decoder.decodeStringForKey("t")
self.shortName = decoder.decodeStringForKey("s")
self.hash = decoder.decodeInt32ForKey("h")
self.flags = StickerPackCollectionInfoFlags(rawValue: decoder.decodeInt32ForKey("f"))
}
public func encode(_ encoder: Encoder) {
@ -34,6 +67,7 @@ public final class StickerPackCollectionInfo: ItemCollectionInfo, Equatable {
encoder.encodeString(self.title, forKey: "t")
encoder.encodeString(self.shortName, forKey: "s")
encoder.encodeInt32(self.hash, forKey: "h")
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
}
public static func ==(lhs: StickerPackCollectionInfo, rhs: StickerPackCollectionInfo) -> Bool {