Add dice [skip ci]

This commit is contained in:
Ilya Laktyushin 2020-02-26 15:40:53 +04:00
parent c5f219a5af
commit 8341247b5d
4 changed files with 44 additions and 2 deletions

View File

@ -0,0 +1,38 @@
import Postbox
public final class TelegramMediaDice: Media {
public let value: Int32?
public let id: MediaId? = nil
public let peerIds: [PeerId] = []
public init(value: Int32? = nil) {
self.value = value
}
public init(decoder: PostboxDecoder) {
self.value = decoder.decodeOptionalInt32ForKey("v")
}
public func encode(_ encoder: PostboxEncoder) {
if let value = self.value {
encoder.encodeInt32(value, forKey: "v")
} else {
encoder.encodeNil(forKey: "v")
}
}
public func isEqual(to other: Media) -> Bool {
if let other = other as? TelegramMediaDice {
if self.value != other.value {
return false
}
return true
}
return false
}
public func isSemanticallyEqual(to other: Media) -> Bool {
return self.isEqual(to: other)
}
}

View File

@ -154,6 +154,7 @@ private var declaredEncodables: Void = {
declareEncodable(CachedPollOptionResult.self, f: { CachedPollOptionResult(decoder: $0) })
declareEncodable(ChatListFiltersState.self, f: { ChatListFiltersState(decoder: $0) })
declareEncodable(PeersNearbyState.self, f: { PeersNearbyState(decoder: $0) })
declareEncodable(TelegramMediaDice.self, f: { TelegramMediaDice(decoder: $0) })
return
}()

View File

@ -177,6 +177,9 @@ func mediaContentToUpload(network: Network, postbox: Postbox, auxiliaryMethods:
}
let inputPoll = Api.InputMedia.inputMediaPoll(flags: pollMediaFlags, poll: Api.Poll.poll(id: 0, flags: pollFlags, question: poll.text, answers: poll.options.map({ $0.apiOption })), correctAnswers: correctAnswers)
return .single(.content(PendingMessageUploadedContentAndReuploadInfo(content: .media(inputPoll, text), reuploadInfo: nil)))
} else if let dice = media as? TelegramMediaDice {
let input = Api.InputMedia.inputMediaDice
return .single(.content(PendingMessageUploadedContentAndReuploadInfo(content: .media(input, text), reuploadInfo: nil)))
} else {
return nil
}

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), nil)
}
case .messageMediaDice:
break
case let .messageMediaDice(value):
return (TelegramMediaDice(value: value), nil)
}
}