Update API [skip ci]

This commit is contained in:
Ilya Laktyushin 2020-04-16 22:25:36 +04:00
parent eed8cb0b3f
commit 0f1211e427
7 changed files with 33 additions and 21 deletions

View File

@ -1,20 +1,24 @@
import Postbox
public final class TelegramMediaDice: Media {
public let emoji: String
public let value: Int32?
public let id: MediaId? = nil
public let peerIds: [PeerId] = []
public init(value: Int32? = nil) {
public init(emoji: String, value: Int32? = nil) {
self.emoji = emoji
self.value = value
}
public init(decoder: PostboxDecoder) {
self.emoji = decoder.decodeStringForKey("e", orElse: "🎲")
self.value = decoder.decodeOptionalInt32ForKey("v")
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.emoji, forKey: "e")
if let value = self.value {
encoder.encodeInt32(value, forKey: "v")
} else {
@ -24,6 +28,9 @@ public final class TelegramMediaDice: Media {
public func isEqual(to other: Media) -> Bool {
if let other = other as? TelegramMediaDice {
if self.emoji != other.emoji {
return false
}
if self.value != other.value {
return false
}

View File

@ -13,7 +13,7 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable {
case id(id: Int64, accessHash: Int64)
case name(String)
case animatedEmoji
case dice
case dice(String)
public init(decoder: PostboxDecoder) {
switch decoder.decodeInt32ForKey("r", orElse: 0) {
@ -24,7 +24,7 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable {
case 2:
self = .animatedEmoji
case 3:
self = .dice
self = .dice(decoder.decodeStringForKey("e", orElse: "🎲"))
default:
self = .name("")
assertionFailure()
@ -42,8 +42,9 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable {
encoder.encodeString(name, forKey: "n")
case .animatedEmoji:
encoder.encodeInt32(2, forKey: "r")
case .dice:
case let .dice(emoji):
encoder.encodeInt32(3, forKey: "r")
encoder.encodeString(emoji, forKey: "e")
}
}
@ -67,8 +68,8 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable {
} else {
return false
}
case .dice:
if case .dice = rhs {
case let .dice(emoji):
if case .dice(emoji) = rhs {
return true
} else {
return false

View File

@ -1,6 +1,7 @@
import Foundation
import Postbox
import SwiftSignalKit
import MurMurHash32
import SyncCore
@ -18,16 +19,19 @@ func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo,
if let reference = reference {
var namespace: Int32?
var id: ItemCollectionId.Id?
switch reference {
case .animatedEmoji:
namespace = Namespaces.ItemCollection.CloudAnimatedEmoji
case .dice:
id = 0
case let .dice(emoji):
namespace = Namespaces.ItemCollection.CloudDice
id = Int64(murMurHashString32(emoji))
default:
break
}
if let namespace = namespace {
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: 0))), entry: CachedStickerPack(info: info, items: items.map { $0 as! StickerPackItem }, hash: info.hash), collectionSpec: collectionSpec)
if let namespace = namespace, let id = id {
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))), entry: CachedStickerPack(info: info, items: items.map { $0 as! StickerPackItem }, hash: info.hash), collectionSpec: collectionSpec)
}
}
}
@ -87,9 +91,9 @@ public func cachedStickerPack(postbox: Postbox, network: Network, reference: Sti
} else {
return (.fetching, true, nil)
}
case .dice:
case let .dice(emoji):
let namespace = Namespaces.ItemCollection.CloudDice
let id: ItemCollectionId.Id = 0
let id: ItemCollectionId.Id = Int64(murMurHashString32(emoji))
if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info {
previousHash = cached.hash
let current: CachedStickerPackResult = .result(info, cached.items, false)
@ -173,9 +177,9 @@ func cachedStickerPack(transaction: Transaction, reference: StickerPackReference
if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info {
return (info, cached.items, false)
}
case .dice:
case let .dice(emoji):
let namespace = Namespaces.ItemCollection.CloudDice
let id: ItemCollectionId.Id = 0
let id: ItemCollectionId.Id = Int64(murMurHashString32(emoji))
if let currentInfo = transaction.getItemCollectionInfo(collectionId: ItemCollectionId(namespace: namespace, id: id)) as? StickerPackCollectionInfo {
let items = transaction.getItemCollectionItems(collectionId: ItemCollectionId(namespace: namespace, id: id))
if !items.isEmpty {

View File

@ -18,8 +18,8 @@ extension StickerPackReference {
return .inputStickerSetShortName(shortName: name)
case .animatedEmoji:
return .inputStickerSetAnimatedEmoji
case .dice:
return .inputStickerSetDice
case let .dice(emoji):
return .inputStickerSetDice(emoticon: emoji)
}
}
}

View File

@ -38,9 +38,9 @@ public func requestStickerSet(postbox: Postbox, network: Network, reference: Sti
case .animatedEmoji:
collectionId = nil
input = .inputStickerSetAnimatedEmoji
case .dice:
case let .dice(emoji):
collectionId = nil
input = .inputStickerSetDice
input = .inputStickerSetDice(emoticon: emoji)
}
let localSignal: (ItemCollectionId) -> Signal<(ItemCollectionInfo, [ItemCollectionItem])?, NoError> = { collectionId in

View File

@ -342,8 +342,8 @@ func textMediaAndExpirationTimerFromApiMedia(_ media: Api.MessageMedia?, _ peerI
}
return (TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.CloudPoll, id: id), publicity: publicity, kind: kind, text: question, options: answers.map(TelegramMediaPollOption.init(apiOption:)), correctAnswers: nil, results: TelegramMediaPollResults(apiResults: results), isClosed: (flags & (1 << 0)) != 0, deadlineTimeout: closePeriod), nil)
}
case let .messageMediaDice(value):
return (TelegramMediaDice(value: value), nil)
case let .messageMediaDice(emoticon, value):
return (TelegramMediaDice(emoji: emoticon, value: value), nil)
}
}

View File

@ -59,8 +59,8 @@ extension StickerPackReference {
self = .name(shortName)
case .inputStickerSetAnimatedEmoji:
self = .animatedEmoji
case .inputStickerSetDice:
self = .dice
case let .inputStickerSetDice(emoticon):
self = .dice(emoticon)
}
}
}