mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-04 11:50:38 +00:00
API update
This commit is contained in:
parent
ae844e1a20
commit
c45aa06aa7
@ -447,7 +447,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
|||||||
dict[-1160215659] = { return Api.InputMessage.parse_inputMessageReplyTo($0) }
|
dict[-1160215659] = { return Api.InputMessage.parse_inputMessageReplyTo($0) }
|
||||||
dict[-2037963464] = { return Api.InputMessage.parse_inputMessagePinned($0) }
|
dict[-2037963464] = { return Api.InputMessage.parse_inputMessagePinned($0) }
|
||||||
dict[-1564789301] = { return Api.PhoneCallProtocol.parse_phoneCallProtocol($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[-1938715001] = { return Api.messages.Messages.parse_messages($0) }
|
||||||
dict[1951620897] = { return Api.messages.Messages.parse_messagesNotModified($0) }
|
dict[1951620897] = { return Api.messages.Messages.parse_messagesNotModified($0) }
|
||||||
dict[-1497072982] = { return Api.messages.Messages.parse_messagesSlice($0) }
|
dict[-1497072982] = { return Api.messages.Messages.parse_messagesSlice($0) }
|
||||||
|
@ -11234,28 +11234,27 @@ extension Api {
|
|||||||
|
|
||||||
}
|
}
|
||||||
enum WallPaper: TypeConstructorDescription {
|
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) {
|
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||||
switch self {
|
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 {
|
if boxed {
|
||||||
buffer.appendInt32(-1695098544)
|
buffer.appendInt32(-263220756)
|
||||||
}
|
}
|
||||||
serializeInt64(id, buffer: buffer, boxed: false)
|
serializeInt64(id, buffer: buffer, boxed: false)
|
||||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||||
serializeInt64(accessHash, buffer: buffer, boxed: false)
|
serializeInt64(accessHash, buffer: buffer, boxed: false)
|
||||||
serializeString(slug, buffer: buffer, boxed: false)
|
serializeString(slug, buffer: buffer, boxed: false)
|
||||||
document.serialize(buffer, true)
|
document.serialize(buffer, true)
|
||||||
if Int(flags) & Int(1 << 2) != 0 {serializeInt32(color!, buffer: buffer, boxed: false)}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func descriptionFields() -> (String, [(String, Any)]) {
|
func descriptionFields() -> (String, [(String, Any)]) {
|
||||||
switch self {
|
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):
|
||||||
return ("wallPaper", [("id", id), ("flags", flags), ("accessHash", accessHash), ("slug", slug), ("document", document), ("color", color)])
|
return ("wallPaper", [("id", id), ("flags", flags), ("accessHash", accessHash), ("slug", slug), ("document", document)])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11272,16 +11271,13 @@ extension Api {
|
|||||||
if let signature = reader.readInt32() {
|
if let signature = reader.readInt32() {
|
||||||
_5 = Api.parse(reader, signature: signature) as? Api.Document
|
_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 _c1 = _1 != nil
|
||||||
let _c2 = _2 != nil
|
let _c2 = _2 != nil
|
||||||
let _c3 = _3 != nil
|
let _c3 = _3 != nil
|
||||||
let _c4 = _4 != nil
|
let _c4 = _4 != nil
|
||||||
let _c5 = _5 != nil
|
let _c5 = _5 != nil
|
||||||
let _c6 = (Int(_2!) & Int(1 << 2) == 0) || _6 != nil
|
if _c1 && _c2 && _c3 && _c4 && _c5 {
|
||||||
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 {
|
return Api.WallPaper.wallPaper(id: _1!, flags: _2!, accessHash: _3!, slug: _4!, document: _5!)
|
||||||
return Api.WallPaper.wallPaper(id: _1!, flags: _2!, accessHash: _3!, slug: _4!, document: _5!, color: _6)
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return nil
|
return nil
|
||||||
|
@ -11,7 +11,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable {
|
|||||||
case builtin
|
case builtin
|
||||||
case color(Int32)
|
case color(Int32)
|
||||||
case image([TelegramMediaImageRepresentation])
|
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) {
|
public init(decoder: PostboxDecoder) {
|
||||||
switch decoder.decodeInt32ForKey("v", orElse: 0) {
|
switch decoder.decodeInt32ForKey("v", orElse: 0) {
|
||||||
@ -22,7 +22,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable {
|
|||||||
case 2:
|
case 2:
|
||||||
self = .image(decoder.decodeObjectArrayWithDecoderForKey("i"))
|
self = .image(decoder.decodeObjectArrayWithDecoderForKey("i"))
|
||||||
case 3:
|
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:
|
default:
|
||||||
assertionFailure()
|
assertionFailure()
|
||||||
self = .color(0xffffff)
|
self = .color(0xffffff)
|
||||||
@ -48,18 +48,14 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable {
|
|||||||
case let .image(representations):
|
case let .image(representations):
|
||||||
encoder.encodeInt32(2, forKey: "v")
|
encoder.encodeInt32(2, forKey: "v")
|
||||||
encoder.encodeObjectArray(representations, forKey: "i")
|
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.encodeInt32(3, forKey: "v")
|
||||||
encoder.encodeInt64(id, forKey: "id")
|
encoder.encodeInt64(id, forKey: "id")
|
||||||
encoder.encodeInt64(accessHash, forKey: "accessHash")
|
encoder.encodeInt64(accessHash, forKey: "accessHash")
|
||||||
encoder.encodeInt32(isCreator ? 1 : 0, forKey: "isCreator")
|
encoder.encodeInt32(isCreator ? 1 : 0, forKey: "isCreator")
|
||||||
|
encoder.encodeInt32(isDefault ? 1 : 0, forKey: "isDefault")
|
||||||
encoder.encodeString(slug, forKey: "slug")
|
encoder.encodeString(slug, forKey: "slug")
|
||||||
encoder.encodeObject(file, forKey: "file")
|
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 {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case let .file(lhsId, _, lhsIsCreator, lhsSlug, _, lhsColor):
|
case let .file(lhsId, _, lhsIsCreator, lhsIsDefault, lhsSlug, lhsFile):
|
||||||
if case let .file(rhsId, _, rhsIsCreator, rhsSlug, _, rhsColor) = rhs, lhsId == rhsId, lhsIsCreator == rhsIsCreator, lhsSlug == rhsSlug, lhsColor == rhsColor {
|
if case let .file(rhsId, _, rhsIsCreator, rhsIsDefault, rhsSlug, rhsFile) = rhs, lhsId == rhsId, lhsIsCreator == rhsIsCreator, lhsIsDefault == rhsIsDefault, lhsSlug == rhsSlug, lhsFile == rhsFile {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
@ -96,9 +92,9 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable {
|
|||||||
extension TelegramWallpaper {
|
extension TelegramWallpaper {
|
||||||
init(apiWallpaper: Api.WallPaper) {
|
init(apiWallpaper: Api.WallPaper) {
|
||||||
switch apiWallpaper {
|
switch apiWallpaper {
|
||||||
case let .wallPaper(id, flags, accessHash, slug, document, color):
|
case let .wallPaper(id, flags, accessHash, slug, document):
|
||||||
if let file = telegramMediaFileFromApiDocument(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 {
|
} else {
|
||||||
assertionFailure()
|
assertionFailure()
|
||||||
self = .color(0xffffff)
|
self = .color(0xffffff)
|
||||||
|
@ -34,7 +34,7 @@ public func telegramWallpapers(postbox: Postbox, network: Network) -> Signal<[Te
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> mapToSignal { list, hash -> Signal<[TelegramWallpaper], NoError> in
|
|> 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
|
|> retryRequest
|
||||||
|> mapToSignal { result -> Signal<[TelegramWallpaper], NoError> in
|
|> mapToSignal { result -> Signal<[TelegramWallpaper], NoError> in
|
||||||
switch result {
|
switch result {
|
||||||
@ -43,7 +43,7 @@ public func telegramWallpapers(postbox: Postbox, network: Network) -> Signal<[Te
|
|||||||
var addedBuiltin = false
|
var addedBuiltin = false
|
||||||
for apiWallpaper in wallpapers {
|
for apiWallpaper in wallpapers {
|
||||||
let wallpaper = TelegramWallpaper(apiWallpaper: apiWallpaper)
|
let wallpaper = TelegramWallpaper(apiWallpaper: apiWallpaper)
|
||||||
if case .file = wallpaper {
|
if case let .file(_, _, _, isDefault, _, _) = wallpaper, !isDefault {
|
||||||
} else if !addedBuiltin {
|
} else if !addedBuiltin {
|
||||||
addedBuiltin = true
|
addedBuiltin = true
|
||||||
items.append(.builtin)
|
items.append(.builtin)
|
||||||
@ -134,7 +134,7 @@ public func uploadWallpaper(account: Account, resource: MediaResource, mimeType:
|
|||||||
|> map { result, resource -> UploadWallpaperStatus in
|
|> map { result, resource -> UploadWallpaperStatus in
|
||||||
switch result {
|
switch result {
|
||||||
case let .complete(wallpaper):
|
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)
|
account.postbox.mediaBox.moveResourceData(from: resource.id, to: file.resource.id)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -165,7 +165,7 @@ public func deleteWallpaper(account: Account, wallpaper: TelegramWallpaper) -> S
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func saveUnsaveWallpaper(account: Account, wallpaper: TelegramWallpaper, unsave: Bool) -> Signal<Void, NoError> {
|
private func saveUnsaveWallpaper(account: Account, wallpaper: TelegramWallpaper, unsave: Bool) -> Signal<Void, NoError> {
|
||||||
guard case let .file(_, _, _, slug, _, _) = wallpaper else {
|
guard case let .file(_, _, _, _, slug, _) = wallpaper else {
|
||||||
return .complete()
|
return .complete()
|
||||||
}
|
}
|
||||||
return account.network.request(Api.functions.account.saveWallPaper(wallpaper: Api.InputWallPaper.inputWallPaperSlug(slug: slug), unsave: unsave ? Api.Bool.boolTrue : Api.Bool.boolFalse))
|
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<Void, NoError> {
|
public func installWallpaper(account: Account, wallpaper: TelegramWallpaper) -> Signal<Void, NoError> {
|
||||||
guard case let .file(_, _, _, slug, _, _) = wallpaper else {
|
guard case let .file(_, _, _, _, slug, _) = wallpaper else {
|
||||||
return .complete()
|
return .complete()
|
||||||
}
|
}
|
||||||
return account.network.request(Api.functions.account.installWallPaper(wallpaper: Api.InputWallPaper.inputWallPaperSlug(slug: slug)))
|
return account.network.request(Api.functions.account.installWallPaper(wallpaper: Api.InputWallPaper.inputWallPaperSlug(slug: slug)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user