mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Add dice [skip ci]
This commit is contained in:
parent
c5f219a5af
commit
8341247b5d
38
submodules/SyncCore/Sources/TelegramMediaDice.swift
Normal file
38
submodules/SyncCore/Sources/TelegramMediaDice.swift
Normal 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)
|
||||
}
|
||||
}
|
@ -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
|
||||
}()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user