mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-03-02 22:55:18 +00:00
Update API
This commit is contained in:
@@ -160,6 +160,7 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
case paidMessagesRefunded(count: Int32, stars: Int64)
|
||||
case paidMessagesPriceEdited(stars: Int64, broadcastMessagesAllowed: Bool)
|
||||
case conferenceCall(ConferenceCall)
|
||||
case todoCompletions(completed: [Int32], incompleted: [Int32])
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
let rawValue: Int32 = decoder.decodeInt32ForKey("_rawValue", orElse: 0)
|
||||
@@ -295,6 +296,11 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
flags: ConferenceCall.Flags(rawValue: decoder.decodeInt32ForKey("flags", orElse: 0)),
|
||||
otherParticipants: decoder.decodeInt64ArrayForKey("part").map(PeerId.init)
|
||||
))
|
||||
case 49:
|
||||
self = .todoCompletions(
|
||||
completed: decoder.decodeInt32ArrayForKey("completed"),
|
||||
incompleted: decoder.decodeInt32ArrayForKey("incompleted")
|
||||
)
|
||||
default:
|
||||
self = .unknown
|
||||
}
|
||||
@@ -698,6 +704,10 @@ public enum TelegramMediaActionType: PostboxCoding, Equatable {
|
||||
}
|
||||
encoder.encodeInt32(conferenceCall.flags.rawValue, forKey: "flags")
|
||||
encoder.encodeInt64Array(conferenceCall.otherParticipants.map({ $0.toInt64() }), forKey: "part")
|
||||
case let .todoCompletions(completed, incompleted):
|
||||
encoder.encodeInt32(49, forKey: "_rawValue")
|
||||
encoder.encodeInt32Array(completed, forKey: "completed")
|
||||
encoder.encodeInt32Array(incompleted, forKey: "incompleted")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
public final class TelegramMediaTodo: Media, Equatable {
|
||||
public struct Flags: OptionSet {
|
||||
public var rawValue: Int32
|
||||
|
||||
public init() {
|
||||
self.rawValue = 0
|
||||
}
|
||||
|
||||
public init(rawValue: Int32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
public static let othersCanAppend = Flags(rawValue: 1 << 0)
|
||||
public static let othersCanComplete = Flags(rawValue: 1 << 1)
|
||||
}
|
||||
|
||||
public struct Item: Equatable, PostboxCoding {
|
||||
public let text: String
|
||||
public let entities: [MessageTextEntity]
|
||||
public let id: Int32
|
||||
|
||||
public init(text: String, entities: [MessageTextEntity], id: Int32) {
|
||||
self.text = text
|
||||
self.entities = entities
|
||||
self.id = id
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.text = decoder.decodeStringForKey("t", orElse: "")
|
||||
self.entities = decoder.decodeObjectArrayWithDecoderForKey("et")
|
||||
self.id = decoder.decodeInt32ForKey("i", orElse: 0)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeString(self.text, forKey: "t")
|
||||
encoder.encodeObjectArray(self.entities, forKey: "et")
|
||||
encoder.encodeInt32(self.id, forKey: "i")
|
||||
}
|
||||
}
|
||||
|
||||
public struct Completion: Equatable, PostboxCoding {
|
||||
public let id: Int32
|
||||
public let date: Int32
|
||||
public let completedBy: EnginePeer.Id
|
||||
|
||||
public init(id: Int32, date: Int32, completedBy: EnginePeer.Id) {
|
||||
self.id = id
|
||||
self.date = date
|
||||
self.completedBy = completedBy
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.id = decoder.decodeInt32ForKey("i", orElse: 0)
|
||||
self.date = decoder.decodeInt32ForKey("d", orElse: 0)
|
||||
self.completedBy = PeerId(decoder.decodeInt64ForKey("p", orElse: 0))
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.id, forKey: "i")
|
||||
encoder.encodeInt32(self.date, forKey: "d")
|
||||
encoder.encodeInt64(self.completedBy.toInt64(), forKey: "p")
|
||||
}
|
||||
}
|
||||
|
||||
public var id: MediaId? {
|
||||
return nil
|
||||
}
|
||||
public var peerIds: [PeerId] {
|
||||
return []
|
||||
}
|
||||
|
||||
public let flags: Flags
|
||||
public let text: String
|
||||
public let textEntities: [MessageTextEntity]
|
||||
public let items: [Item]
|
||||
public let completions: [Completion]
|
||||
|
||||
public init(flags: Flags, text: String, textEntities: [MessageTextEntity], items: [Item], completions: [Completion] = []) {
|
||||
self.flags = flags
|
||||
self.text = text
|
||||
self.textEntities = textEntities
|
||||
self.items = items
|
||||
self.completions = completions
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.flags = Flags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0))
|
||||
self.text = decoder.decodeStringForKey("t", orElse: "")
|
||||
self.textEntities = decoder.decodeObjectArrayWithDecoderForKey("te")
|
||||
self.items = decoder.decodeObjectArrayWithDecoderForKey("is")
|
||||
self.completions = decoder.decodeObjectArrayWithDecoderForKey("cs")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.flags.rawValue, forKey: "f")
|
||||
encoder.encodeString(self.text, forKey: "t")
|
||||
encoder.encodeObjectArray(self.textEntities, forKey: "te")
|
||||
encoder.encodeObjectArray(self.items, forKey: "is")
|
||||
encoder.encodeObjectArray(self.completions, forKey: "cs")
|
||||
}
|
||||
|
||||
public func isEqual(to other: Media) -> Bool {
|
||||
guard let other = other as? TelegramMediaTodo else {
|
||||
return false
|
||||
}
|
||||
return self == other
|
||||
}
|
||||
|
||||
public func isSemanticallyEqual(to other: Media) -> Bool {
|
||||
return self.isEqual(to: other)
|
||||
}
|
||||
|
||||
public static func ==(lhs: TelegramMediaTodo, rhs: TelegramMediaTodo) -> Bool {
|
||||
if lhs.flags != rhs.flags {
|
||||
return false
|
||||
}
|
||||
if lhs.text != rhs.text {
|
||||
return false
|
||||
}
|
||||
if lhs.textEntities != rhs.textEntities {
|
||||
return false
|
||||
}
|
||||
if lhs.items != rhs.items {
|
||||
return false
|
||||
}
|
||||
if lhs.completions != rhs.completions {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user