diff --git a/TelegramCore/Api0.swift b/TelegramCore/Api0.swift index b8a27e24e0..6179c07bd3 100644 --- a/TelegramCore/Api0.swift +++ b/TelegramCore/Api0.swift @@ -447,7 +447,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1160215659] = { return Api.InputMessage.parse_inputMessageReplyTo($0) } dict[-2037963464] = { return Api.InputMessage.parse_inputMessagePinned($0) } dict[-1564789301] = { return Api.PhoneCallProtocol.parse_phoneCallProtocol($0) } - dict[-1695098544] = { return Api.WallPaper.parse_wallPaper($0) } + dict[-263220756] = { return Api.WallPaper.parse_wallPaper($0) } dict[-1938715001] = { return Api.messages.Messages.parse_messages($0) } dict[1951620897] = { return Api.messages.Messages.parse_messagesNotModified($0) } dict[-1497072982] = { return Api.messages.Messages.parse_messagesSlice($0) } diff --git a/TelegramCore/Api1.swift b/TelegramCore/Api1.swift index b01d93b3c2..d6668274b5 100644 --- a/TelegramCore/Api1.swift +++ b/TelegramCore/Api1.swift @@ -11234,28 +11234,27 @@ extension Api { } enum WallPaper: TypeConstructorDescription { - case wallPaper(id: Int64, flags: Int32, accessHash: Int64, slug: String, document: Api.Document, color: Int32?) + case wallPaper(id: Int64, flags: Int32, accessHash: Int64, slug: String, document: Api.Document) func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .wallPaper(let id, let flags, let accessHash, let slug, let document, let color): + case .wallPaper(let id, let flags, let accessHash, let slug, let document): if boxed { - buffer.appendInt32(-1695098544) + buffer.appendInt32(-263220756) } serializeInt64(id, buffer: buffer, boxed: false) serializeInt32(flags, buffer: buffer, boxed: false) serializeInt64(accessHash, buffer: buffer, boxed: false) serializeString(slug, buffer: buffer, boxed: false) document.serialize(buffer, true) - if Int(flags) & Int(1 << 2) != 0 {serializeInt32(color!, buffer: buffer, boxed: false)} break } } func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .wallPaper(let id, let flags, let accessHash, let slug, let document, let color): - return ("wallPaper", [("id", id), ("flags", flags), ("accessHash", accessHash), ("slug", slug), ("document", document), ("color", color)]) + case .wallPaper(let id, let flags, let accessHash, let slug, let document): + return ("wallPaper", [("id", id), ("flags", flags), ("accessHash", accessHash), ("slug", slug), ("document", document)]) } } @@ -11272,16 +11271,13 @@ extension Api { if let signature = reader.readInt32() { _5 = Api.parse(reader, signature: signature) as? Api.Document } - var _6: Int32? - if Int(_2!) & Int(1 << 2) != 0 {_6 = reader.readInt32() } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil let _c4 = _4 != nil let _c5 = _5 != nil - let _c6 = (Int(_2!) & Int(1 << 2) == 0) || _6 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 { - return Api.WallPaper.wallPaper(id: _1!, flags: _2!, accessHash: _3!, slug: _4!, document: _5!, color: _6) + if _c1 && _c2 && _c3 && _c4 && _c5 { + return Api.WallPaper.wallPaper(id: _1!, flags: _2!, accessHash: _3!, slug: _4!, document: _5!) } else { return nil diff --git a/TelegramCore/Wallpaper.swift b/TelegramCore/Wallpaper.swift index ae8477d251..de9ff5b45e 100644 --- a/TelegramCore/Wallpaper.swift +++ b/TelegramCore/Wallpaper.swift @@ -11,7 +11,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { case builtin case color(Int32) case image([TelegramMediaImageRepresentation]) - case file(id: Int64, accessHash: Int64, isCreator: Bool, slug: String, file: TelegramMediaFile, color: Int32?) + case file(id: Int64, accessHash: Int64, isCreator: Bool, isDefault: Bool, slug: String, file: TelegramMediaFile) public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("v", orElse: 0) { @@ -22,7 +22,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { case 2: self = .image(decoder.decodeObjectArrayWithDecoderForKey("i")) case 3: - self = .file(id: decoder.decodeInt64ForKey("id", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), isCreator: decoder.decodeInt32ForKey("isCreator", orElse: 0) != 0, slug: decoder.decodeStringForKey("slug", orElse: ""), file: decoder.decodeObjectForKey("file", decoder: { TelegramMediaFile(decoder: $0) }) as! TelegramMediaFile, color: decoder.decodeOptionalInt32ForKey("color")) + self = .file(id: decoder.decodeInt64ForKey("id", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), isCreator: decoder.decodeInt32ForKey("isCreator", orElse: 0) != 0, isDefault: decoder.decodeInt32ForKey("isDefault", orElse: 0) != 0, slug: decoder.decodeStringForKey("slug", orElse: ""), file: decoder.decodeObjectForKey("file", decoder: { TelegramMediaFile(decoder: $0) }) as! TelegramMediaFile) default: assertionFailure() self = .color(0xffffff) @@ -48,18 +48,14 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { case let .image(representations): encoder.encodeInt32(2, forKey: "v") encoder.encodeObjectArray(representations, forKey: "i") - case let .file(id, accessHash, isCreator, slug, file, color): + case let .file(id, accessHash, isCreator, isDefault, slug, file): encoder.encodeInt32(3, forKey: "v") encoder.encodeInt64(id, forKey: "id") encoder.encodeInt64(accessHash, forKey: "accessHash") encoder.encodeInt32(isCreator ? 1 : 0, forKey: "isCreator") + encoder.encodeInt32(isDefault ? 1 : 0, forKey: "isDefault") encoder.encodeString(slug, forKey: "slug") encoder.encodeObject(file, forKey: "file") - if let color = color { - encoder.encodeInt32(color, forKey: "color") - } else { - encoder.encodeNil(forKey: "color") - } } } @@ -83,8 +79,8 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { } else { return false } - case let .file(lhsId, _, lhsIsCreator, lhsSlug, _, lhsColor): - if case let .file(rhsId, _, rhsIsCreator, rhsSlug, _, rhsColor) = rhs, lhsId == rhsId, lhsIsCreator == rhsIsCreator, lhsSlug == rhsSlug, lhsColor == rhsColor { + case let .file(lhsId, _, lhsIsCreator, lhsIsDefault, lhsSlug, lhsFile): + if case let .file(rhsId, _, rhsIsCreator, rhsIsDefault, rhsSlug, rhsFile) = rhs, lhsId == rhsId, lhsIsCreator == rhsIsCreator, lhsIsDefault == rhsIsDefault, lhsSlug == rhsSlug, lhsFile == rhsFile { return true } else { return false @@ -96,9 +92,9 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { extension TelegramWallpaper { init(apiWallpaper: Api.WallPaper) { switch apiWallpaper { - case let .wallPaper(id, flags, accessHash, slug, document, color): + case let .wallPaper(id, flags, accessHash, slug, document): if let file = telegramMediaFileFromApiDocument(document) { - self = .file(id: id, accessHash: accessHash, isCreator: (flags & 1 << 0) != 0, slug: slug, file: file, color: color) + self = .file(id: id, accessHash: accessHash, isCreator: (flags & 1 << 0) != 0, isDefault: (flags & 1 << 1) != 0, slug: slug, file: file) } else { assertionFailure() self = .color(0xffffff) diff --git a/TelegramCore/Wallpapers.swift b/TelegramCore/Wallpapers.swift index ce7d44cb34..754bd980fa 100644 --- a/TelegramCore/Wallpapers.swift +++ b/TelegramCore/Wallpapers.swift @@ -34,7 +34,7 @@ public func telegramWallpapers(postbox: Postbox, network: Network) -> Signal<[Te } } |> mapToSignal { list, hash -> Signal<[TelegramWallpaper], NoError> in - let remote = network.request(Api.functions.account.getWallPapers(hash: hash ?? 0)) + let remote = network.request(Api.functions.account.getWallPapers(hash: 0)) |> retryRequest |> mapToSignal { result -> Signal<[TelegramWallpaper], NoError> in switch result { @@ -43,7 +43,7 @@ public func telegramWallpapers(postbox: Postbox, network: Network) -> Signal<[Te var addedBuiltin = false for apiWallpaper in wallpapers { let wallpaper = TelegramWallpaper(apiWallpaper: apiWallpaper) - if case .file = wallpaper { + if case let .file(_, _, _, isDefault, _, _) = wallpaper, !isDefault { } else if !addedBuiltin { addedBuiltin = true items.append(.builtin) @@ -134,7 +134,7 @@ public func uploadWallpaper(account: Account, resource: MediaResource, mimeType: |> map { result, resource -> UploadWallpaperStatus in switch result { case let .complete(wallpaper): - if case let .file(_, _, _, _, file, _) = wallpaper, let resource = resource { + if case let .file(_, _, _, _, _, file) = wallpaper, let resource = resource { account.postbox.mediaBox.moveResourceData(from: resource.id, to: file.resource.id) } default: @@ -165,7 +165,7 @@ public func deleteWallpaper(account: Account, wallpaper: TelegramWallpaper) -> S } private func saveUnsaveWallpaper(account: Account, wallpaper: TelegramWallpaper, unsave: Bool) -> Signal { - guard case let .file(_, _, _, slug, _, _) = wallpaper else { + guard case let .file(_, _, _, _, slug, _) = wallpaper else { return .complete() } return account.network.request(Api.functions.account.saveWallPaper(wallpaper: Api.InputWallPaper.inputWallPaperSlug(slug: slug), unsave: unsave ? Api.Bool.boolTrue : Api.Bool.boolFalse)) @@ -178,7 +178,7 @@ private func saveUnsaveWallpaper(account: Account, wallpaper: TelegramWallpaper, } public func installWallpaper(account: Account, wallpaper: TelegramWallpaper) -> Signal { - guard case let .file(_, _, _, slug, _, _) = wallpaper else { + guard case let .file(_, _, _, _, slug, _) = wallpaper else { return .complete() } return account.network.request(Api.functions.account.installWallPaper(wallpaper: Api.InputWallPaper.inputWallPaperSlug(slug: slug)))