mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 21:41:45 +00:00
Merge branch 'temp'
This commit is contained in:
commit
957122c3b4
@ -30,18 +30,24 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[1216809369] = { return Api.PageBlock.parse_pageBlockFooter($0) }
|
||||
dict[-618614392] = { return Api.PageBlock.parse_pageBlockDivider($0) }
|
||||
dict[-837994576] = { return Api.PageBlock.parse_pageBlockAnchor($0) }
|
||||
dict[978896884] = { return Api.PageBlock.parse_pageBlockList($0) }
|
||||
dict[641563686] = { return Api.PageBlock.parse_pageBlockBlockquote($0) }
|
||||
dict[1329878739] = { return Api.PageBlock.parse_pageBlockPullquote($0) }
|
||||
dict[-372860542] = { return Api.PageBlock.parse_pageBlockPhoto($0) }
|
||||
dict[-640214938] = { return Api.PageBlock.parse_pageBlockVideo($0) }
|
||||
dict[972174080] = { return Api.PageBlock.parse_pageBlockCover($0) }
|
||||
dict[-840826671] = { return Api.PageBlock.parse_pageBlockEmbed($0) }
|
||||
dict[690781161] = { return Api.PageBlock.parse_pageBlockEmbedPost($0) }
|
||||
dict[145955919] = { return Api.PageBlock.parse_pageBlockCollage($0) }
|
||||
dict[319588707] = { return Api.PageBlock.parse_pageBlockSlideshow($0) }
|
||||
dict[-283684427] = { return Api.PageBlock.parse_pageBlockChannel($0) }
|
||||
dict[834148991] = { return Api.PageBlock.parse_pageBlockAudio($0) }
|
||||
dict[504660880] = { return Api.PageBlock.parse_pageBlockKicker($0) }
|
||||
dict[-1085412734] = { return Api.PageBlock.parse_pageBlockTable($0) }
|
||||
dict[391759200] = { return Api.PageBlock.parse_pageBlockPhoto($0) }
|
||||
dict[2089805750] = { return Api.PageBlock.parse_pageBlockVideo($0) }
|
||||
dict[-2143067670] = { return Api.PageBlock.parse_pageBlockAudio($0) }
|
||||
dict[-1468953147] = { return Api.PageBlock.parse_pageBlockEmbed($0) }
|
||||
dict[-229005301] = { return Api.PageBlock.parse_pageBlockEmbedPost($0) }
|
||||
dict[1705048653] = { return Api.PageBlock.parse_pageBlockCollage($0) }
|
||||
dict[52401552] = { return Api.PageBlock.parse_pageBlockSlideshow($0) }
|
||||
dict[-454524911] = { return Api.PageBlock.parse_pageBlockList($0) }
|
||||
dict[-1702174239] = { return Api.PageBlock.parse_pageBlockOrderedList($0) }
|
||||
dict[1987480557] = { return Api.PageBlock.parse_pageBlockDetails($0) }
|
||||
dict[370236054] = { return Api.PageBlock.parse_pageBlockRelatedArticles($0) }
|
||||
dict[-1538310410] = { return Api.PageBlock.parse_pageBlockMap($0) }
|
||||
dict[-614138572] = { return Api.account.TmpPassword.parse_tmpPassword($0) }
|
||||
dict[-2103600678] = { return Api.SecureRequiredType.parse_secureRequiredType($0) }
|
||||
dict[41187252] = { return Api.SecureRequiredType.parse_secureRequiredTypeOneOf($0) }
|
||||
@ -73,12 +79,17 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[1009288385] = { return Api.RichText.parse_textUrl($0) }
|
||||
dict[-564523562] = { return Api.RichText.parse_textEmail($0) }
|
||||
dict[2120376535] = { return Api.RichText.parse_textConcat($0) }
|
||||
dict[-311786236] = { return Api.RichText.parse_textSubscript($0) }
|
||||
dict[-939827711] = { return Api.RichText.parse_textSuperscript($0) }
|
||||
dict[55281185] = { return Api.RichText.parse_textMarked($0) }
|
||||
dict[483104362] = { return Api.RichText.parse_textPhone($0) }
|
||||
dict[136105807] = { return Api.RichText.parse_textImage($0) }
|
||||
dict[253890367] = { return Api.UserFull.parse_userFull($0) }
|
||||
dict[-292807034] = { return Api.InputChannel.parse_inputChannelEmpty($0) }
|
||||
dict[-1343524562] = { return Api.InputChannel.parse_inputChannel($0) }
|
||||
dict[414687501] = { return Api.DcOption.parse_dcOption($0) }
|
||||
dict[-1705233435] = { return Api.account.PasswordSettings.parse_passwordSettings($0) }
|
||||
dict[292985073] = { return Api.LangPackLanguage.parse_langPackLanguage($0) }
|
||||
dict[711286046] = { return Api.LangPackLanguage.parse_langPackLanguage($0) }
|
||||
dict[-1987579119] = { return Api.help.AppUpdate.parse_appUpdate($0) }
|
||||
dict[-1000708810] = { return Api.help.AppUpdate.parse_noAppUpdate($0) }
|
||||
dict[-209337866] = { return Api.LangPackDifference.parse_langPackDifference($0) }
|
||||
@ -133,6 +144,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-1137792208] = { return Api.PrivacyKey.parse_privacyKeyStatusTimestamp($0) }
|
||||
dict[1343122938] = { return Api.PrivacyKey.parse_privacyKeyChatInvite($0) }
|
||||
dict[1030105979] = { return Api.PrivacyKey.parse_privacyKeyPhoneCall($0) }
|
||||
dict[961092808] = { return Api.PrivacyKey.parse_privacyKeyPhoneP2P($0) }
|
||||
dict[522914557] = { return Api.Update.parse_updateNewMessage($0) }
|
||||
dict[1318109142] = { return Api.Update.parse_updateMessageID($0) }
|
||||
dict[-1576161051] = { return Api.Update.parse_updateDeleteMessages($0) }
|
||||
@ -337,6 +349,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[569137759] = { return Api.SecurePlainData.parse_securePlainEmail($0) }
|
||||
dict[-1269012015] = { return Api.messages.AffectedHistory.parse_affectedHistory($0) }
|
||||
dict[-1036572727] = { return Api.account.PasswordInputSettings.parse_passwordInputSettings($0) }
|
||||
dict[878078826] = { return Api.PageTableCell.parse_pageTableCell($0) }
|
||||
dict[649453030] = { return Api.messages.MessageEditData.parse_messageEditData($0) }
|
||||
dict[-886477832] = { return Api.LabeledPrice.parse_labeledPrice($0) }
|
||||
dict[-438840932] = { return Api.messages.ChatFull.parse_chatFull($0) }
|
||||
@ -351,6 +364,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-512463606] = { return Api.ReportReason.parse_inputReportReasonOther($0) }
|
||||
dict[-1685456582] = { return Api.ReportReason.parse_inputReportReasonCopyright($0) }
|
||||
dict[-247351839] = { return Api.InputEncryptedChat.parse_inputEncryptedChat($0) }
|
||||
dict[-524237339] = { return Api.PageTableRow.parse_pageTableRow($0) }
|
||||
dict[-40996577] = { return Api.DraftMessage.parse_draftMessage($0) }
|
||||
dict[453805082] = { return Api.DraftMessage.parse_draftMessageEmpty($0) }
|
||||
dict[1568467877] = { return Api.ChannelAdminRights.parse_channelAdminRights($0) }
|
||||
@ -373,6 +387,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[1335282456] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyStatusTimestamp($0) }
|
||||
dict[-1107622874] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyChatInvite($0) }
|
||||
dict[-88417185] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyPhoneCall($0) }
|
||||
dict[-610373422] = { return Api.InputPrivacyKey.parse_inputPrivacyKeyPhoneP2P($0) }
|
||||
dict[235081943] = { return Api.help.RecentMeUrls.parse_recentMeUrls($0) }
|
||||
dict[-1606526075] = { return Api.ReplyMarkup.parse_replyKeyboardHide($0) }
|
||||
dict[-200242528] = { return Api.ReplyMarkup.parse_replyKeyboardForceReply($0) }
|
||||
@ -385,11 +400,12 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-316748368] = { return Api.SecureValueHash.parse_secureValueHash($0) }
|
||||
dict[1444661369] = { return Api.ContactBlocked.parse_contactBlocked($0) }
|
||||
dict[-2128698738] = { return Api.auth.CheckedPhone.parse_checkedPhone($0) }
|
||||
dict[-1188055347] = { return Api.PageListItem.parse_pageListItemText($0) }
|
||||
dict[635466748] = { return Api.PageListItem.parse_pageListItemBlocks($0) }
|
||||
dict[-1182234929] = { return Api.InputUser.parse_inputUserEmpty($0) }
|
||||
dict[-138301121] = { return Api.InputUser.parse_inputUserSelf($0) }
|
||||
dict[-668391402] = { return Api.InputUser.parse_inputUser($0) }
|
||||
dict[-1908433218] = { return Api.Page.parse_pagePart($0) }
|
||||
dict[1433323434] = { return Api.Page.parse_pageFull($0) }
|
||||
dict[-241590104] = { return Api.Page.parse_page($0) }
|
||||
dict[871426631] = { return Api.SecureCredentialsEncrypted.parse_secureCredentialsEncrypted($0) }
|
||||
dict[157948117] = { return Api.upload.File.parse_file($0) }
|
||||
dict[-242427324] = { return Api.upload.File.parse_fileCdnRedirect($0) }
|
||||
@ -459,6 +475,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[307276766] = { return Api.account.Authorizations.parse_authorizations($0) }
|
||||
dict[935395612] = { return Api.ChatPhoto.parse_chatPhotoEmpty($0) }
|
||||
dict[1632839530] = { return Api.ChatPhoto.parse_chatPhoto($0) }
|
||||
dict[1869903447] = { return Api.PageCaption.parse_pageCaption($0) }
|
||||
dict[1062645411] = { return Api.payments.PaymentForm.parse_paymentForm($0) }
|
||||
dict[1342771681] = { return Api.payments.PaymentReceipt.parse_paymentReceipt($0) }
|
||||
dict[863093588] = { return Api.messages.PeerDialogs.parse_peerDialogs($0) }
|
||||
@ -555,7 +572,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[1776236393] = { return Api.ExportedChatInvite.parse_chatInviteEmpty($0) }
|
||||
dict[-64092740] = { return Api.ExportedChatInvite.parse_chatInviteExported($0) }
|
||||
dict[-1389486888] = { return Api.account.AuthorizationForm.parse_authorizationForm($0) }
|
||||
dict[2079516406] = { return Api.Authorization.parse_authorization($0) }
|
||||
dict[-1392388579] = { return Api.Authorization.parse_authorization($0) }
|
||||
dict[-1361650766] = { return Api.MaskCoords.parse_maskCoords($0) }
|
||||
dict[-395967805] = { return Api.messages.AllStickers.parse_allStickersNotModified($0) }
|
||||
dict[-302170017] = { return Api.messages.AllStickers.parse_allStickers($0) }
|
||||
@ -614,8 +631,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[462375633] = { return Api.PhoneCall.parse_phoneCallWaiting($0) }
|
||||
dict[-2089411356] = { return Api.PhoneCall.parse_phoneCallRequested($0) }
|
||||
dict[1828732223] = { return Api.PhoneCall.parse_phoneCallAccepted($0) }
|
||||
dict[-1660057] = { return Api.PhoneCall.parse_phoneCall($0) }
|
||||
dict[1355435489] = { return Api.PhoneCall.parse_phoneCallDiscarded($0) }
|
||||
dict[-419832333] = { return Api.PhoneCall.parse_phoneCall($0) }
|
||||
dict[-483352705] = { return Api.help.TermsOfServiceUpdate.parse_termsOfServiceUpdateEmpty($0) }
|
||||
dict[686618977] = { return Api.help.TermsOfServiceUpdate.parse_termsOfServiceUpdate($0) }
|
||||
dict[-445792507] = { return Api.DialogPeer.parse_dialogPeer($0) }
|
||||
@ -630,6 +647,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[1889961234] = { return Api.PeerNotifySettings.parse_peerNotifySettingsEmpty($0) }
|
||||
dict[-1353671392] = { return Api.PeerNotifySettings.parse_peerNotifySettings($0) }
|
||||
dict[-1995686519] = { return Api.InputBotInlineMessageID.parse_inputBotInlineMessageID($0) }
|
||||
dict[-242812612] = { return Api.PageRelatedArticle.parse_pageRelatedArticle($0) }
|
||||
dict[313694676] = { return Api.StickerPack.parse_stickerPack($0) }
|
||||
dict[1326562017] = { return Api.UserProfilePhoto.parse_userProfilePhotoEmpty($0) }
|
||||
dict[-715532088] = { return Api.UserProfilePhoto.parse_userProfilePhoto($0) }
|
||||
@ -663,6 +681,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-1073693790] = { return Api.auth.SentCodeType.parse_sentCodeTypeSms($0) }
|
||||
dict[1398007207] = { return Api.auth.SentCodeType.parse_sentCodeTypeCall($0) }
|
||||
dict[-1425815847] = { return Api.auth.SentCodeType.parse_sentCodeTypeFlashCall($0) }
|
||||
dict[1577484359] = { return Api.PageListOrderedItem.parse_pageListOrderedItemText($0) }
|
||||
dict[-1730311882] = { return Api.PageListOrderedItem.parse_pageListOrderedItemBlocks($0) }
|
||||
dict[-1417756512] = { return Api.EncryptedChat.parse_encryptedChatEmpty($0) }
|
||||
dict[1006044124] = { return Api.EncryptedChat.parse_encryptedChatWaiting($0) }
|
||||
dict[-931638658] = { return Api.EncryptedChat.parse_encryptedChatRequested($0) }
|
||||
@ -914,6 +934,8 @@ struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.account.PasswordInputSettings:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.PageTableCell:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.messages.MessageEditData:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.LabeledPrice:
|
||||
@ -932,6 +954,8 @@ struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.InputEncryptedChat:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.PageTableRow:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.DraftMessage:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.ChannelAdminRights:
|
||||
@ -966,6 +990,8 @@ struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.auth.CheckedPhone:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.PageListItem:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.InputUser:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.Page:
|
||||
@ -1030,6 +1056,8 @@ struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.ChatPhoto:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.PageCaption:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.payments.PaymentForm:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.payments.PaymentReceipt:
|
||||
@ -1158,6 +1186,8 @@ struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.InputBotInlineMessageID:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.PageRelatedArticle:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.StickerPack:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.UserProfilePhoto:
|
||||
@ -1178,6 +1208,8 @@ struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.auth.SentCodeType:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.PageListOrderedItem:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.EncryptedChat:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.Document:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -4922,6 +4922,21 @@ extension Api {
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
static func confirmPasswordEmail(email: String, code: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.Bool>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(-558870880)
|
||||
serializeString(email, buffer: buffer, boxed: false)
|
||||
serializeString(code, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription(name: "account.confirmPasswordEmail", parameters: [("email", email), ("code", code)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Bool? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: Api.Bool?
|
||||
if let signature = reader.readInt32() {
|
||||
result = Api.parse(reader, signature: signature) as? Api.Bool
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
}
|
||||
struct langpack {
|
||||
static func getDifference(fromVersion: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.LangPackDifference>) {
|
||||
@ -4986,6 +5001,21 @@ extension Api {
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
static func getLanguage(langPack: String, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.LangPackLanguage>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(1784243458)
|
||||
serializeString(langPack, buffer: buffer, boxed: false)
|
||||
serializeString(langCode, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription(name: "langpack.getLanguage", parameters: [("langPack", langPack), ("langCode", langCode)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.LangPackLanguage? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: Api.LangPackLanguage?
|
||||
if let signature = reader.readInt32() {
|
||||
result = Api.parse(reader, signature: signature) as? Api.LangPackLanguage
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
}
|
||||
struct photos {
|
||||
static func updateProfilePhoto(id: Api.InputPhoto) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.UserProfilePhoto>) {
|
||||
|
||||
@ -557,7 +557,7 @@ private final class CallSessionManagerContext {
|
||||
//assertionFailure()
|
||||
}
|
||||
}
|
||||
case let .phoneCall(id, _, _, _, _, gAOrB, keyFingerprint, callProtocol, connection, alternativeConnections, startDate):
|
||||
case let .phoneCall(_, id, _, _, _, _, gAOrB, keyFingerprint, callProtocol, connection, alternativeConnections, startDate):
|
||||
if let internalId = self.contextIdByStableId[id] {
|
||||
if let context = self.contexts[internalId] {
|
||||
switch context.state {
|
||||
@ -820,7 +820,7 @@ private func acceptCallSession(postbox: Postbox, network: Network, stableId: Cal
|
||||
return .failed
|
||||
case .phoneCallWaiting:
|
||||
return .success(.waiting(config: config))
|
||||
case let .phoneCall(id, _, _, _, _, gAOrB, keyFingerprint, callProtocol, connection, alternativeConnections, startDate):
|
||||
case let .phoneCall(_, id, _, _, _, _, gAOrB, keyFingerprint, callProtocol, connection, alternativeConnections, startDate):
|
||||
if id == stableId {
|
||||
switch callProtocol{
|
||||
case let .phoneCallProtocol(_, _, maxLayer):
|
||||
|
||||
@ -58,7 +58,7 @@ public enum ChannelAdminLogEventError {
|
||||
case generic
|
||||
}
|
||||
|
||||
public struct AdminLogEventsFlags : OptionSet {
|
||||
public struct AdminLogEventsFlags: OptionSet {
|
||||
public var rawValue: UInt32
|
||||
|
||||
public init(rawValue: UInt32) {
|
||||
|
||||
@ -29,6 +29,30 @@ private enum InstantPageBlockType: Int32 {
|
||||
case slideshow = 20
|
||||
case channelBanner = 21
|
||||
case audio = 22
|
||||
case kicker = 23
|
||||
case table = 24
|
||||
case details = 25
|
||||
case relatedArticles = 26
|
||||
case map = 27
|
||||
}
|
||||
|
||||
private func decodeListItems(_ decoder: PostboxDecoder) -> [InstantPageListItem] {
|
||||
let legacyItems: [RichText] = decoder.decodeObjectArrayWithDecoderForKey("l")
|
||||
if !legacyItems.isEmpty {
|
||||
var items: [InstantPageListItem] = []
|
||||
for item in legacyItems {
|
||||
items.append(.text(item, nil))
|
||||
}
|
||||
return items
|
||||
}
|
||||
return decoder.decodeObjectArrayWithDecoderForKey("ml")
|
||||
}
|
||||
|
||||
private func decodeCaption(_ decoder: PostboxDecoder) -> InstantPageCaption {
|
||||
if let legacyCaption = decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as? RichText {
|
||||
return InstantPageCaption(text: legacyCaption, credit: .empty)
|
||||
}
|
||||
return decoder.decodeObjectForKey("mc", decoder: { InstantPageCaption(decoder: $0) }) as! InstantPageCaption
|
||||
}
|
||||
|
||||
public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
@ -43,18 +67,23 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
case footer(RichText)
|
||||
case divider
|
||||
case anchor(String)
|
||||
case list(items: [RichText], ordered: Bool)
|
||||
case list(items: [InstantPageListItem], ordered: Bool)
|
||||
case blockQuote(text: RichText, caption: RichText)
|
||||
case pullQuote(text: RichText, caption: RichText)
|
||||
case image(id: MediaId, caption: RichText)
|
||||
case video(id: MediaId, caption: RichText, autoplay: Bool, loop: Bool)
|
||||
case audio(id: MediaId, caption: RichText)
|
||||
case image(id: MediaId, caption: InstantPageCaption, url: String?, webpageId: MediaId?)
|
||||
case video(id: MediaId, caption: InstantPageCaption, autoplay: Bool, loop: Bool)
|
||||
case audio(id: MediaId, caption: InstantPageCaption)
|
||||
case cover(InstantPageBlock)
|
||||
case webEmbed(url: String?, html: String?, dimensions: CGSize, caption: RichText, stretchToWidth: Bool, allowScrolling: Bool, coverId: MediaId?)
|
||||
case postEmbed(url: String, webpageId: MediaId?, avatarId: MediaId?, author: String, date: Int32, blocks: [InstantPageBlock], caption: RichText)
|
||||
case collage(items: [InstantPageBlock], caption: RichText)
|
||||
case slideshow(items: [InstantPageBlock], caption: RichText)
|
||||
case webEmbed(url: String?, html: String?, dimensions: CGSize?, caption: InstantPageCaption, stretchToWidth: Bool, allowScrolling: Bool, coverId: MediaId?)
|
||||
case postEmbed(url: String, webpageId: MediaId?, avatarId: MediaId?, author: String, date: Int32, blocks: [InstantPageBlock], caption: InstantPageCaption)
|
||||
case collage(items: [InstantPageBlock], caption: InstantPageCaption)
|
||||
case slideshow(items: [InstantPageBlock], caption: InstantPageCaption)
|
||||
case channelBanner(TelegramChannel?)
|
||||
case kicker(RichText)
|
||||
case table(title: RichText, rows: [InstantPageTableRow], bordered: Bool, striped: Bool)
|
||||
case details(title: RichText, blocks: [InstantPageBlock], open: Bool)
|
||||
case relatedArticles(title: RichText, articles: [InstantPageRelatedArticle])
|
||||
case map(latitude: Double, longitude: Double, zoom: Int32, dimensions: CGSize, caption: InstantPageCaption)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("r", orElse: 0) {
|
||||
@ -81,15 +110,19 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
case InstantPageBlockType.anchor.rawValue:
|
||||
self = .anchor(decoder.decodeStringForKey("s", orElse: ""))
|
||||
case InstantPageBlockType.list.rawValue:
|
||||
self = .list(items: decoder.decodeObjectArrayWithDecoderForKey("l"), ordered: decoder.decodeOptionalInt32ForKey("o") != 0)
|
||||
self = .list(items: decodeListItems(decoder), ordered: decoder.decodeOptionalInt32ForKey("o") != 0)
|
||||
case InstantPageBlockType.blockQuote.rawValue:
|
||||
self = .blockQuote(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
case InstantPageBlockType.pullQuote.rawValue:
|
||||
self = .pullQuote(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
case InstantPageBlockType.image.rawValue:
|
||||
self = .image(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
var webpageId: MediaId?
|
||||
if let webpageIdNamespace = decoder.decodeOptionalInt32ForKey("wi.n"), let webpageIdId = decoder.decodeOptionalInt64ForKey("wi.i") {
|
||||
webpageId = MediaId(namespace: webpageIdNamespace, id: webpageIdId)
|
||||
}
|
||||
self = .image(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder), url: decoder.decodeOptionalStringForKey("u"), webpageId: webpageId)
|
||||
case InstantPageBlockType.video.rawValue:
|
||||
self = .video(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText, autoplay: decoder.decodeInt32ForKey("ap", orElse: 0) != 0, loop: decoder.decodeInt32ForKey("lo", orElse: 0) != 0)
|
||||
self = .video(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder), autoplay: decoder.decodeInt32ForKey("ap", orElse: 0) != 0, loop: decoder.decodeInt32ForKey("lo", orElse: 0) != 0)
|
||||
case InstantPageBlockType.cover.rawValue:
|
||||
self = .cover(decoder.decodeObjectForKey("c", decoder: { InstantPageBlock(decoder: $0) }) as! InstantPageBlock)
|
||||
case InstantPageBlockType.webEmbed.rawValue:
|
||||
@ -97,7 +130,11 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
if let coverIdNamespace = decoder.decodeOptionalInt32ForKey("ci.n"), let coverIdId = decoder.decodeOptionalInt64ForKey("ci.i") {
|
||||
coverId = MediaId(namespace: coverIdNamespace, id: coverIdId)
|
||||
}
|
||||
self = .webEmbed(url: decoder.decodeOptionalStringForKey("u"), html: decoder.decodeOptionalStringForKey("h"), dimensions: CGSize(width: CGFloat(decoder.decodeInt32ForKey("sw", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("sh", orElse: 0))), caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText, stretchToWidth: decoder.decodeInt32ForKey("st", orElse: 0) != 0, allowScrolling: decoder.decodeInt32ForKey("as", orElse: 0) != 0, coverId: coverId)
|
||||
var dimensions: CGSize?
|
||||
if let width = decoder.decodeOptionalInt32ForKey("sw"), let height = decoder.decodeOptionalInt32ForKey("sh") {
|
||||
dimensions = CGSize(width: CGFloat(width), height: CGFloat(height))
|
||||
}
|
||||
self = .webEmbed(url: decoder.decodeOptionalStringForKey("u"), html: decoder.decodeOptionalStringForKey("h"), dimensions: dimensions, caption: decodeCaption(decoder), stretchToWidth: decoder.decodeInt32ForKey("st", orElse: 0) != 0, allowScrolling: decoder.decodeInt32ForKey("as", orElse: 0) != 0, coverId: coverId)
|
||||
case InstantPageBlockType.postEmbed.rawValue:
|
||||
var avatarId: MediaId?
|
||||
let avatarIdNamespace: Int32? = decoder.decodeOptionalInt32ForKey("av.n")
|
||||
@ -105,15 +142,25 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
if let avatarIdNamespace = avatarIdNamespace, let avatarIdId = avatarIdId {
|
||||
avatarId = MediaId(namespace: avatarIdNamespace, id: avatarIdId)
|
||||
}
|
||||
self = .postEmbed(url: decoder.decodeStringForKey("u", orElse: ""), webpageId: MediaId(namespace: decoder.decodeInt32ForKey("w.n", orElse: 0), id: decoder.decodeInt64ForKey("w.i", orElse: 0)), avatarId: avatarId, author: decoder.decodeStringForKey("a", orElse: ""), date: decoder.decodeInt32ForKey("d", orElse: 0), blocks: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
self = .postEmbed(url: decoder.decodeStringForKey("u", orElse: ""), webpageId: MediaId(namespace: decoder.decodeInt32ForKey("w.n", orElse: 0), id: decoder.decodeInt64ForKey("w.i", orElse: 0)), avatarId: avatarId, author: decoder.decodeStringForKey("a", orElse: ""), date: decoder.decodeInt32ForKey("d", orElse: 0), blocks: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder))
|
||||
case InstantPageBlockType.collage.rawValue:
|
||||
self = .collage(items: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
self = .collage(items: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder))
|
||||
case InstantPageBlockType.slideshow.rawValue:
|
||||
self = .slideshow(items: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
self = .slideshow(items: decoder.decodeObjectArrayWithDecoderForKey("b"), caption: decodeCaption(decoder))
|
||||
case InstantPageBlockType.channelBanner.rawValue:
|
||||
self = .channelBanner(decoder.decodeObjectForKey("c") as? TelegramChannel)
|
||||
case InstantPageBlockType.audio.rawValue:
|
||||
self = .audio(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
self = .audio(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), caption: decodeCaption(decoder))
|
||||
case InstantPageBlockType.kicker.rawValue:
|
||||
self = .kicker(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
case InstantPageBlockType.table.rawValue:
|
||||
self = .table(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, rows: decoder.decodeObjectArrayWithDecoderForKey("r"), bordered: decoder.decodeInt32ForKey("b", orElse: 0) != 0, striped: decoder.decodeInt32ForKey("s", orElse: 0) != 0)
|
||||
case InstantPageBlockType.details.rawValue:
|
||||
self = .details(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, blocks: decoder.decodeObjectArrayWithDecoderForKey("b"), open: decoder.decodeInt32ForKey("o", orElse: 0) != 0)
|
||||
case InstantPageBlockType.relatedArticles.rawValue:
|
||||
self = .relatedArticles(title: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, articles: decoder.decodeObjectArrayWithDecoderForKey("a"))
|
||||
case InstantPageBlockType.map.rawValue:
|
||||
self = .map(latitude: decoder.decodeDoubleForKey("lat", orElse: 0.0), longitude: decoder.decodeDoubleForKey("lon", orElse: 0.0), zoom: decoder.decodeInt32ForKey("z", orElse: 0), dimensions: CGSize(width: CGFloat(decoder.decodeInt32ForKey("sw", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("sh", orElse: 0))), caption: decodeCaption(decoder))
|
||||
default:
|
||||
self = .unsupported
|
||||
}
|
||||
@ -155,7 +202,7 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
encoder.encodeString(anchor, forKey: "s")
|
||||
case let .list(items, ordered):
|
||||
encoder.encodeInt32(InstantPageBlockType.list.rawValue, forKey: "r")
|
||||
encoder.encodeObjectArray(items, forKey: "l")
|
||||
encoder.encodeObjectArray(items, forKey: "ml")
|
||||
encoder.encodeInt32(ordered ? 1 : 0, forKey: "o")
|
||||
case let .blockQuote(text, caption):
|
||||
encoder.encodeInt32(InstantPageBlockType.blockQuote.rawValue, forKey: "r")
|
||||
@ -165,16 +212,28 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
encoder.encodeInt32(InstantPageBlockType.pullQuote.rawValue, forKey: "r")
|
||||
encoder.encodeObject(text, forKey: "t")
|
||||
encoder.encodeObject(caption, forKey: "c")
|
||||
case let .image(id, caption):
|
||||
case let .image(id, caption, url, webpageId):
|
||||
encoder.encodeInt32(InstantPageBlockType.image.rawValue, forKey: "r")
|
||||
encoder.encodeInt32(id.namespace, forKey: "i.n")
|
||||
encoder.encodeInt64(id.id, forKey: "i.i")
|
||||
encoder.encodeObject(caption, forKey: "c")
|
||||
encoder.encodeObject(caption, forKey: "mc")
|
||||
if let url = url {
|
||||
encoder.encodeString(url, forKey: "u")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "u")
|
||||
}
|
||||
if let webpageId = webpageId {
|
||||
encoder.encodeInt32(webpageId.namespace, forKey: "wi.n")
|
||||
encoder.encodeInt64(webpageId.id, forKey: "wi.i")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "wi.n")
|
||||
encoder.encodeNil(forKey: "wi.i")
|
||||
}
|
||||
case let .video(id, caption, autoplay, loop):
|
||||
encoder.encodeInt32(InstantPageBlockType.video.rawValue, forKey: "r")
|
||||
encoder.encodeInt32(id.namespace, forKey: "i.n")
|
||||
encoder.encodeInt64(id.id, forKey: "i.i")
|
||||
encoder.encodeObject(caption, forKey: "c")
|
||||
encoder.encodeObject(caption, forKey: "mc")
|
||||
encoder.encodeInt32(autoplay ? 1 : 0, forKey: "ap")
|
||||
encoder.encodeInt32(loop ? 1 : 0, forKey: "lo")
|
||||
case let .cover(block):
|
||||
@ -199,9 +258,14 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "h")
|
||||
}
|
||||
encoder.encodeInt32(Int32(dimensions.width), forKey: "sw")
|
||||
encoder.encodeInt32(Int32(dimensions.height), forKey: "sh")
|
||||
encoder.encodeObject(caption, forKey: "c")
|
||||
if let dimensions = dimensions {
|
||||
encoder.encodeInt32(Int32(dimensions.width), forKey: "sw")
|
||||
encoder.encodeInt32(Int32(dimensions.height), forKey: "sh")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "sw")
|
||||
encoder.encodeNil(forKey: "sh")
|
||||
}
|
||||
encoder.encodeObject(caption, forKey: "mc")
|
||||
encoder.encodeInt32(stretchToWidth ? 1 : 0, forKey: "st")
|
||||
encoder.encodeInt32(allowScrolling ? 1 : 0, forKey: "as")
|
||||
case let .postEmbed(url, webpageId, avatarId, author, date, blocks, caption):
|
||||
@ -224,15 +288,15 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
encoder.encodeString(author, forKey: "a")
|
||||
encoder.encodeInt32(date, forKey: "d")
|
||||
encoder.encodeObjectArray(blocks, forKey: "b")
|
||||
encoder.encodeObject(caption, forKey: "c")
|
||||
encoder.encodeObject(caption, forKey: "mc")
|
||||
case let .collage(items, caption):
|
||||
encoder.encodeInt32(InstantPageBlockType.collage.rawValue, forKey: "r")
|
||||
encoder.encodeObjectArray(items, forKey: "b")
|
||||
encoder.encodeObject(caption, forKey: "c")
|
||||
encoder.encodeObject(caption, forKey: "mc")
|
||||
case let .slideshow(items, caption):
|
||||
encoder.encodeInt32(InstantPageBlockType.slideshow.rawValue, forKey: "r")
|
||||
encoder.encodeObjectArray(items, forKey: "b")
|
||||
encoder.encodeObject(caption, forKey: "c")
|
||||
encoder.encodeObject(caption, forKey: "mc")
|
||||
case let .channelBanner(channel):
|
||||
encoder.encodeInt32(InstantPageBlockType.channelBanner.rawValue, forKey: "r")
|
||||
if let channel = channel {
|
||||
@ -244,7 +308,33 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
encoder.encodeInt32(InstantPageBlockType.audio.rawValue, forKey: "r")
|
||||
encoder.encodeInt32(id.namespace, forKey: "i.n")
|
||||
encoder.encodeInt64(id.id, forKey: "i.i")
|
||||
encoder.encodeObject(caption, forKey: "c")
|
||||
encoder.encodeObject(caption, forKey: "mc")
|
||||
case let .kicker(text):
|
||||
encoder.encodeInt32(InstantPageBlockType.kicker.rawValue, forKey: "r")
|
||||
encoder.encodeObject(text, forKey: "t")
|
||||
case let .table(title, rows, bordered, striped):
|
||||
encoder.encodeInt32(InstantPageBlockType.table.rawValue, forKey: "r")
|
||||
encoder.encodeObject(title, forKey: "t")
|
||||
encoder.encodeObjectArray(rows, forKey: "r")
|
||||
encoder.encodeInt32(bordered ? 1 : 0, forKey: "b")
|
||||
encoder.encodeInt32(striped ? 1 : 0, forKey: "s")
|
||||
case let .details(title, blocks, open):
|
||||
encoder.encodeInt32(InstantPageBlockType.details.rawValue, forKey: "r")
|
||||
encoder.encodeObject(title, forKey: "t")
|
||||
encoder.encodeObjectArray(blocks, forKey: "b")
|
||||
encoder.encodeInt32(open ? 1 : 0, forKey: "o")
|
||||
case let .relatedArticles(title, articles):
|
||||
encoder.encodeInt32(InstantPageBlockType.relatedArticles.rawValue, forKey: "r")
|
||||
encoder.encodeObject(title, forKey: "t")
|
||||
encoder.encodeObjectArray(articles, forKey: "a")
|
||||
case let .map(latitude, longitude, zoom, dimensions, caption):
|
||||
encoder.encodeInt32(InstantPageBlockType.map.rawValue, forKey: "r")
|
||||
encoder.encodeDouble(latitude, forKey: "lat")
|
||||
encoder.encodeDouble(longitude, forKey: "lon")
|
||||
encoder.encodeInt32(zoom, forKey: "z")
|
||||
encoder.encodeInt32(Int32(dimensions.width), forKey: "sw")
|
||||
encoder.encodeInt32(Int32(dimensions.height), forKey: "sh")
|
||||
encoder.encodeObject(caption, forKey: "mc")
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,8 +424,8 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .image(id, caption):
|
||||
if case .image(id, caption) = rhs {
|
||||
case let .image(lhsId, lhsCaption, lhsUrl, lhsWebpageId):
|
||||
if case let .image(rhsId, rhsCaption, rhsUrl, rhsWebpageId) = rhs, lhsId == rhsId, lhsCaption == rhsCaption, lhsUrl == rhsUrl, lhsWebpageId == rhsWebpageId {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@ -395,10 +485,307 @@ public indirect enum InstantPageBlock: PostboxCoding, Equatable {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .kicker(text):
|
||||
if case .kicker(text) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .table(lhsTitle, lhsRows, lhsBordered, lhsStriped):
|
||||
if case let .table(rhsTitle, rhsRows, rhsBordered, rhsStriped) = rhs, lhsTitle == rhsTitle, lhsRows == rhsRows, lhsBordered == rhsBordered, lhsStriped == rhsStriped {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .details(lhsTitle, lhsBlocks, lhsOpen):
|
||||
if case let .details(rhsTitle, rhsBlocks, rhsOpen) = rhs, lhsTitle == rhsTitle, lhsBlocks == rhsBlocks, lhsOpen == rhsOpen {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .relatedArticles(lhsTitle, lhsArticles):
|
||||
if case let .relatedArticles(rhsTitle, rhsArticles) = rhs, lhsTitle == rhsTitle, lhsArticles == rhsArticles {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .map(latitude, longitude, zoom, dimensions, caption):
|
||||
if case .map(latitude, longitude, zoom, dimensions, caption) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final class InstantPageCaption: PostboxCoding, Equatable {
|
||||
public let text: RichText
|
||||
public let credit: RichText
|
||||
|
||||
init(text: RichText, credit: RichText) {
|
||||
self.text = text
|
||||
self.credit = credit
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.text = decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText
|
||||
self.credit = decoder.decodeObjectForKey("c", decoder: { RichText(decoder: $0) }) as! RichText
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObject(self.text, forKey: "t")
|
||||
encoder.encodeObject(self.credit, forKey: "c")
|
||||
}
|
||||
|
||||
public static func ==(lhs: InstantPageCaption, rhs: InstantPageCaption) -> Bool {
|
||||
if lhs.text != rhs.text {
|
||||
return false
|
||||
}
|
||||
if lhs.credit != rhs.credit {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private enum InstantPageListItemType: Int32 {
|
||||
case unknown = 0
|
||||
case text = 1
|
||||
case blocks = 2
|
||||
}
|
||||
|
||||
public indirect enum InstantPageListItem: PostboxCoding, Equatable {
|
||||
case unknown
|
||||
case text(RichText, String?)
|
||||
case blocks([InstantPageBlock], String?)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("r", orElse: 0) {
|
||||
case InstantPageListItemType.text.rawValue:
|
||||
self = .text(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, decoder.decodeOptionalStringForKey("n"))
|
||||
case InstantPageListItemType.blocks.rawValue:
|
||||
self = .blocks(decoder.decodeObjectArrayWithDecoderForKey("b"), decoder.decodeOptionalStringForKey("n"))
|
||||
default:
|
||||
self = .unknown
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
switch self {
|
||||
case let .text(text, num):
|
||||
encoder.encodeInt32(InstantPageListItemType.text.rawValue, forKey: "r")
|
||||
encoder.encodeObject(text, forKey: "t")
|
||||
if let num = num {
|
||||
encoder.encodeString(num, forKey: "n")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "n")
|
||||
}
|
||||
case let .blocks(blocks, num):
|
||||
encoder.encodeInt32(InstantPageListItemType.blocks.rawValue, forKey: "r")
|
||||
encoder.encodeObjectArray(blocks, forKey: "b")
|
||||
if let num = num {
|
||||
encoder.encodeString(num, forKey: "n")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "n")
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
public static func ==(lhs: InstantPageListItem, rhs: InstantPageListItem) -> Bool {
|
||||
switch lhs {
|
||||
case .unknown:
|
||||
if case .unknown = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .text(lhsText, lhsNum):
|
||||
if case let .text(rhsText, rhsNum) = rhs, lhsText == rhsText, lhsNum == rhsNum {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .blocks(lhsBlocks, lhsNum):
|
||||
if case let .blocks(rhsBlocks, rhsNum) = rhs, lhsBlocks == rhsBlocks, lhsNum == rhsNum {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum TableHorizontalAlignment: Int32 {
|
||||
case left = 0
|
||||
case center = 1
|
||||
case right = 2
|
||||
}
|
||||
|
||||
public enum TableVerticalAlignment: Int32 {
|
||||
case top = 0
|
||||
case middle = 1
|
||||
case bottom = 2
|
||||
}
|
||||
|
||||
public final class InstantPageTableCell: PostboxCoding, Equatable {
|
||||
public let text: RichText?
|
||||
public let header: Bool
|
||||
public let alignment: TableHorizontalAlignment
|
||||
public let verticalAlignment: TableVerticalAlignment
|
||||
public let colspan: Int32
|
||||
public let rowspan: Int32
|
||||
|
||||
public init(text: RichText?, header: Bool, alignment: TableHorizontalAlignment, verticalAlignment: TableVerticalAlignment, colspan: Int32, rowspan: Int32) {
|
||||
self.text = text
|
||||
self.header = header
|
||||
self.alignment = alignment
|
||||
self.verticalAlignment = verticalAlignment
|
||||
self.colspan = colspan
|
||||
self.rowspan = rowspan
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.text = decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as? RichText
|
||||
self.header = decoder.decodeInt32ForKey("h", orElse: 0) != 0
|
||||
self.alignment = TableHorizontalAlignment(rawValue: decoder.decodeInt32ForKey("ha", orElse: 0))!
|
||||
self.verticalAlignment = TableVerticalAlignment(rawValue: decoder.decodeInt32ForKey("va", orElse: 0))!
|
||||
self.colspan = decoder.decodeInt32ForKey("sc", orElse: 0)
|
||||
self.rowspan = decoder.decodeInt32ForKey("sr", orElse: 0)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
if let text = self.text {
|
||||
encoder.encodeObject(text, forKey: "t")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "t")
|
||||
}
|
||||
encoder.encodeInt32(self.header ? 1 : 0, forKey: "h")
|
||||
encoder.encodeInt32(self.alignment.rawValue, forKey: "ha")
|
||||
encoder.encodeInt32(self.verticalAlignment.rawValue, forKey: "va")
|
||||
encoder.encodeInt32(self.colspan, forKey: "sc")
|
||||
encoder.encodeInt32(self.rowspan, forKey: "sr")
|
||||
}
|
||||
|
||||
public static func ==(lhs: InstantPageTableCell, rhs: InstantPageTableCell) -> Bool {
|
||||
if lhs.text != rhs.text {
|
||||
return false
|
||||
}
|
||||
if lhs.header != rhs.header {
|
||||
return false
|
||||
}
|
||||
if lhs.alignment != rhs.alignment {
|
||||
return false
|
||||
}
|
||||
if lhs.verticalAlignment != rhs.verticalAlignment {
|
||||
return false
|
||||
}
|
||||
if lhs.colspan != rhs.colspan {
|
||||
return false
|
||||
}
|
||||
if lhs.rowspan != rhs.rowspan {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public final class InstantPageTableRow: PostboxCoding, Equatable {
|
||||
public let cells: [InstantPageTableCell]
|
||||
|
||||
public init(cells: [InstantPageTableCell]) {
|
||||
self.cells = cells
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.cells = decoder.decodeObjectArrayWithDecoderForKey("c")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObjectArray(self.cells, forKey: "c")
|
||||
}
|
||||
|
||||
public static func ==(lhs: InstantPageTableRow, rhs: InstantPageTableRow) -> Bool {
|
||||
return lhs.cells == rhs.cells
|
||||
}
|
||||
}
|
||||
|
||||
public final class InstantPageRelatedArticle: PostboxCoding, Equatable {
|
||||
public let url: String
|
||||
public let webpageId: MediaId
|
||||
public let title: String?
|
||||
public let description: String?
|
||||
public let photoId: MediaId?
|
||||
|
||||
init(url: String, webpageId: MediaId, title: String?, description: String?, photoId: MediaId?) {
|
||||
self.url = url
|
||||
self.webpageId = webpageId
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.photoId = photoId
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.url = decoder.decodeStringForKey("u", orElse: "")
|
||||
let webpageIdNamespace = decoder.decodeInt32ForKey("w.n", orElse: 0)
|
||||
let webpageIdId = decoder.decodeInt64ForKey("w.i", orElse: 0)
|
||||
self.webpageId = MediaId(namespace: webpageIdNamespace, id: webpageIdId)
|
||||
|
||||
self.title = decoder.decodeOptionalStringForKey("t")
|
||||
self.description = decoder.decodeOptionalStringForKey("d")
|
||||
|
||||
var photoId: MediaId?
|
||||
if let photoIdNamespace = decoder.decodeOptionalInt32ForKey("p.n"), let photoIdId = decoder.decodeOptionalInt64ForKey("p.i") {
|
||||
photoId = MediaId(namespace: photoIdNamespace, id: photoIdId)
|
||||
}
|
||||
self.photoId = photoId
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeString(self.url, forKey: "u")
|
||||
encoder.encodeInt32(self.webpageId.namespace, forKey: "w.n")
|
||||
encoder.encodeInt64(self.webpageId.id, forKey: "w.i")
|
||||
if let title = self.title {
|
||||
encoder.encodeString(title, forKey: "t")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "t")
|
||||
}
|
||||
if let description = self.description {
|
||||
encoder.encodeString(description, forKey: "d")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "d")
|
||||
}
|
||||
if let photoId = photoId {
|
||||
encoder.encodeInt32(photoId.namespace, forKey: "p.n")
|
||||
encoder.encodeInt64(photoId.id, forKey: "p.i")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "p.n")
|
||||
encoder.encodeNil(forKey: "p.i")
|
||||
}
|
||||
}
|
||||
|
||||
public static func ==(lhs: InstantPageRelatedArticle, rhs: InstantPageRelatedArticle) -> Bool {
|
||||
if lhs.url != rhs.url {
|
||||
return false
|
||||
}
|
||||
if lhs.webpageId != rhs.webpageId {
|
||||
return false
|
||||
}
|
||||
if lhs.title != rhs.title {
|
||||
return false
|
||||
}
|
||||
if lhs.description != rhs.description {
|
||||
return false
|
||||
}
|
||||
if lhs.photoId != rhs.photoId {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private final class MediaDictionary: PostboxCoding {
|
||||
let dict: [MediaId: Media]
|
||||
|
||||
@ -438,30 +825,33 @@ public final class InstantPage: PostboxCoding, Equatable {
|
||||
public let blocks: [InstantPageBlock]
|
||||
public let media: [MediaId: Media]
|
||||
public let isComplete: Bool
|
||||
public let rtl: Bool
|
||||
|
||||
init(blocks: [InstantPageBlock], media: [MediaId: Media], isComplete: Bool) {
|
||||
init(blocks: [InstantPageBlock], media: [MediaId: Media], isComplete: Bool, rtl: Bool) {
|
||||
self.blocks = blocks
|
||||
self.media = media
|
||||
self.isComplete = isComplete
|
||||
self.rtl = rtl
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.blocks = decoder.decodeObjectArrayWithDecoderForKey("b")
|
||||
self.media = MediaDictionary(decoder: decoder).dict
|
||||
self.isComplete = decoder.decodeInt32ForKey("c", orElse: 0) != 0
|
||||
self.rtl = decoder.decodeInt32ForKey("r", orElse: 0) != 0
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObjectArray(self.blocks, forKey: "b")
|
||||
MediaDictionary(dict: self.media).encode(encoder)
|
||||
encoder.encodeInt32(self.isComplete ? 1 : 0, forKey: "c")
|
||||
encoder.encodeInt32(self.rtl ? 1 : 0, forKey: "r")
|
||||
}
|
||||
|
||||
public static func ==(lhs: InstantPage, rhs: InstantPage) -> Bool {
|
||||
if lhs.blocks != rhs.blocks {
|
||||
return false
|
||||
}
|
||||
|
||||
if lhs.media.count != rhs.media.count {
|
||||
return false
|
||||
} else {
|
||||
@ -475,14 +865,101 @@ public final class InstantPage: PostboxCoding, Equatable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if lhs.isComplete != rhs.isComplete {
|
||||
return false
|
||||
}
|
||||
if lhs.rtl != rhs.rtl {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension InstantPageCaption {
|
||||
convenience init(apiCaption: Api.PageCaption) {
|
||||
switch apiCaption {
|
||||
case let .pageCaption(text, credit):
|
||||
self.init(text: RichText(apiText: text), credit: RichText(apiText: credit))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension InstantPageListItem {
|
||||
public var num: String? {
|
||||
switch self {
|
||||
case let .text(_, num):
|
||||
return num
|
||||
case let .blocks(_, num):
|
||||
return num
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstantPageListItem {
|
||||
init(apiListItem: Api.PageListItem) {
|
||||
switch apiListItem {
|
||||
case let .pageListItemText(text):
|
||||
self = .text(RichText(apiText: text), nil)
|
||||
case let .pageListItemBlocks(blocks):
|
||||
self = .blocks(blocks.map({ InstantPageBlock(apiBlock: $0) }), nil)
|
||||
}
|
||||
}
|
||||
|
||||
init(apiListOrderedItem: Api.PageListOrderedItem) {
|
||||
switch apiListOrderedItem {
|
||||
case let .pageListOrderedItemText(num, text):
|
||||
self = .text(RichText(apiText: text), num)
|
||||
case let .pageListOrderedItemBlocks(num, blocks):
|
||||
self = .blocks(blocks.map({ InstantPageBlock(apiBlock: $0) }), num)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstantPageTableCell {
|
||||
convenience init(apiTableCell: Api.PageTableCell) {
|
||||
switch apiTableCell {
|
||||
case let .pageTableCell(flags, text, colspan, rowspan):
|
||||
var alignment = TableHorizontalAlignment.left
|
||||
if (flags & (1 << 3)) != 0 {
|
||||
alignment = .center
|
||||
} else if (flags & (1 << 4)) != 0 {
|
||||
alignment = .right
|
||||
}
|
||||
var verticalAlignment = TableVerticalAlignment.top
|
||||
if (flags & (1 << 5)) != 0 {
|
||||
verticalAlignment = .middle
|
||||
} else if (flags & (1 << 6)) != 0 {
|
||||
verticalAlignment = .bottom
|
||||
}
|
||||
self.init(text: text != nil ? RichText(apiText: text!) : nil, header: (flags & (1 << 0)) != 0, alignment: alignment, verticalAlignment: verticalAlignment, colspan: colspan ?? 0, rowspan: rowspan ?? 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstantPageTableRow {
|
||||
convenience init(apiTableRow: Api.PageTableRow) {
|
||||
switch apiTableRow {
|
||||
case let .pageTableRow(cells):
|
||||
self.init(cells: cells.map({ InstantPageTableCell(apiTableCell: $0) }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstantPageRelatedArticle {
|
||||
convenience init(apiRelatedArticle: Api.PageRelatedArticle) {
|
||||
switch apiRelatedArticle {
|
||||
case let .pageRelatedArticle(flags, url, webpageId, title, description, photoId):
|
||||
var posterPhotoId: MediaId?
|
||||
if let photoId = photoId {
|
||||
posterPhotoId = MediaId(namespace: Namespaces.Media.CloudImage, id: photoId)
|
||||
}
|
||||
self.init(url: url, webpageId: MediaId(namespace: Namespaces.Media.CloudWebpage, id: webpageId), title: title, description: description, photoId: posterPhotoId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstantPageBlock {
|
||||
init(apiBlock: Api.PageBlock) {
|
||||
switch apiBlock {
|
||||
@ -508,30 +985,51 @@ extension InstantPageBlock {
|
||||
self = .divider
|
||||
case let .pageBlockAnchor(name):
|
||||
self = .anchor(name)
|
||||
case let .pageBlockList(ordered, items):
|
||||
self = .list(items: items.map({ RichText(apiText: $0) }), ordered: ordered == .boolTrue)
|
||||
case let .pageBlockBlockquote(text, caption):
|
||||
self = .blockQuote(text: RichText(apiText: text), caption: RichText(apiText: caption))
|
||||
case let .pageBlockPullquote(text, caption):
|
||||
self = .pullQuote(text: RichText(apiText: text), caption: RichText(apiText: caption))
|
||||
case let .pageBlockPhoto(photoId, caption):
|
||||
self = .image(id: MediaId(namespace: Namespaces.Media.CloudImage, id: photoId), caption: RichText(apiText: caption))
|
||||
case let .pageBlockPhoto(_, photoId, caption, url, webpageId):
|
||||
self = .image(id: MediaId(namespace: Namespaces.Media.CloudImage, id: photoId), caption: InstantPageCaption(apiCaption: caption), url: url, webpageId: webpageId != nil ? MediaId(namespace: Namespaces.Media.CloudWebpage, id: webpageId!) : nil)
|
||||
case let .pageBlockVideo(flags, videoId, caption):
|
||||
self = .video(id: MediaId(namespace: Namespaces.Media.CloudFile, id: videoId), caption: RichText(apiText: caption), autoplay: (flags & (1 << 0)) != 0, loop: (flags & (1 << 1)) != 0)
|
||||
self = .video(id: MediaId(namespace: Namespaces.Media.CloudFile, id: videoId), caption: InstantPageCaption(apiCaption: caption), autoplay: (flags & (1 << 0)) != 0, loop: (flags & (1 << 1)) != 0)
|
||||
case let .pageBlockCover(cover):
|
||||
self = .cover(InstantPageBlock(apiBlock: cover))
|
||||
case let .pageBlockEmbed(flags, url, html, posterPhotoId, w, h, caption):
|
||||
self = .webEmbed(url: url, html: html, dimensions: CGSize(width: CGFloat(w), height: CGFloat(h)), caption: RichText(apiText: caption), stretchToWidth: (flags & (1 << 0)) != 0, allowScrolling: (flags & (1 << 3)) != 0, coverId: posterPhotoId.flatMap { MediaId(namespace: Namespaces.Media.CloudImage, id: $0) })
|
||||
var dimensions: CGSize?
|
||||
if let w = w, let h = h {
|
||||
dimensions = CGSize(width: CGFloat(w), height: CGFloat(h))
|
||||
}
|
||||
self = .webEmbed(url: url, html: html, dimensions: dimensions, caption: InstantPageCaption(apiCaption: caption), stretchToWidth: (flags & (1 << 0)) != 0, allowScrolling: (flags & (1 << 3)) != 0, coverId: posterPhotoId.flatMap { MediaId(namespace: Namespaces.Media.CloudImage, id: $0) })
|
||||
case let .pageBlockEmbedPost(url, webpageId, authorPhotoId, author, date, blocks, caption):
|
||||
self = .postEmbed(url: url, webpageId: webpageId == 0 ? nil : MediaId(namespace: Namespaces.Media.CloudWebpage, id: webpageId), avatarId: authorPhotoId == 0 ? nil : MediaId(namespace: Namespaces.Media.CloudImage, id: authorPhotoId), author: author, date: date, blocks: blocks.map({ InstantPageBlock(apiBlock: $0) }), caption: RichText(apiText: caption))
|
||||
self = .postEmbed(url: url, webpageId: webpageId == 0 ? nil : MediaId(namespace: Namespaces.Media.CloudWebpage, id: webpageId), avatarId: authorPhotoId == 0 ? nil : MediaId(namespace: Namespaces.Media.CloudImage, id: authorPhotoId), author: author, date: date, blocks: blocks.map({ InstantPageBlock(apiBlock: $0) }), caption: InstantPageCaption(apiCaption: caption))
|
||||
case let .pageBlockCollage(items, caption):
|
||||
self = .collage(items: items.map({ InstantPageBlock(apiBlock: $0) }), caption: RichText(apiText: caption))
|
||||
self = .collage(items: items.map({ InstantPageBlock(apiBlock: $0) }), caption: InstantPageCaption(apiCaption: caption))
|
||||
case let .pageBlockSlideshow(items, caption):
|
||||
self = .slideshow(items: items.map({ InstantPageBlock(apiBlock: $0) }), caption: RichText(apiText: caption))
|
||||
self = .slideshow(items: items.map({ InstantPageBlock(apiBlock: $0) }), caption: InstantPageCaption(apiCaption: caption))
|
||||
case let .pageBlockChannel(channel: apiChat):
|
||||
self = .channelBanner(parseTelegramGroupOrChannel(chat: apiChat) as? TelegramChannel)
|
||||
case let .pageBlockAudio(audioId, caption):
|
||||
self = .audio(id: MediaId(namespace: Namespaces.Media.CloudFile, id: audioId), caption: RichText(apiText: caption))
|
||||
self = .audio(id: MediaId(namespace: Namespaces.Media.CloudFile, id: audioId), caption: InstantPageCaption(apiCaption: caption))
|
||||
case let .pageBlockKicker(text):
|
||||
self = .kicker(RichText(apiText: text))
|
||||
case let .pageBlockTable(flags, title, rows):
|
||||
self = .table(title: RichText(apiText: title), rows: rows.map({ InstantPageTableRow(apiTableRow: $0) }), bordered: (flags & (1 << 0)) != 0, striped: (flags & (1 << 1)) != 0)
|
||||
case let .pageBlockList(items):
|
||||
self = .list(items: items.map({ InstantPageListItem(apiListItem: $0) }), ordered: false)
|
||||
case let .pageBlockOrderedList(items):
|
||||
self = .list(items: items.map({ InstantPageListItem(apiListOrderedItem: $0) }), ordered: true)
|
||||
case let .pageBlockDetails(flags, blocks, title):
|
||||
self = .details(title: RichText(apiText: title), blocks: blocks.map({ InstantPageBlock(apiBlock: $0) }), open: (flags & (1 << 0)) != 0)
|
||||
case let .pageBlockRelatedArticles(title, articles):
|
||||
self = .relatedArticles(title: RichText(apiText: title), articles: articles.map({ InstantPageRelatedArticle(apiRelatedArticle: $0) }))
|
||||
case let .pageBlockMap(geo, zoom, w, h, caption):
|
||||
switch geo {
|
||||
case let .geoPoint(long, lat, _):
|
||||
self = .map(latitude: lat, longitude: long, zoom: zoom, dimensions: CGSize(width: CGFloat(w), height: CGFloat(h)), caption: InstantPageCaption(apiCaption: caption))
|
||||
default:
|
||||
self = .unsupported
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -542,17 +1040,14 @@ extension InstantPage {
|
||||
let photos: [Api.Photo]
|
||||
let files: [Api.Document]
|
||||
let isComplete: Bool
|
||||
let rtl: Bool
|
||||
switch apiPage {
|
||||
case let .pageFull(apiBlocks, apiPhotos, apiVideos):
|
||||
case let .page(flags, apiBlocks, apiPhotos, apiVideos):
|
||||
blocks = apiBlocks
|
||||
photos = apiPhotos
|
||||
files = apiVideos
|
||||
isComplete = true
|
||||
case let .pagePart(apiBlocks, apiPhotos, apiVideos):
|
||||
blocks = apiBlocks
|
||||
photos = apiPhotos
|
||||
files = apiVideos
|
||||
isComplete = false
|
||||
isComplete = (flags & (1 << 0)) == 0
|
||||
rtl = (flags & (1 << 1)) != 0
|
||||
}
|
||||
var media: [MediaId: Media] = [:]
|
||||
for photo in photos {
|
||||
@ -565,6 +1060,6 @@ extension InstantPage {
|
||||
media[id] = file
|
||||
}
|
||||
}
|
||||
self.init(blocks: blocks.map({ InstantPageBlock(apiBlock: $0) }), media: media, isComplete: isComplete)
|
||||
self.init(blocks: blocks.map({ InstantPageBlock(apiBlock: $0) }), media: media, isComplete: isComplete, rtl: rtl)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,20 @@
|
||||
import Foundation
|
||||
|
||||
public struct AccountSessionFlags: OptionSet {
|
||||
public var rawValue: Int32
|
||||
|
||||
public init() {
|
||||
self.rawValue = 0
|
||||
}
|
||||
|
||||
public init(rawValue: Int32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
public static let isOfficial = AccountSessionFlags(rawValue: (1 << 1))
|
||||
public static let passwordPending = AccountSessionFlags(rawValue: (1 << 2))
|
||||
}
|
||||
|
||||
public struct RecentAccountSession: Equatable {
|
||||
public let hash: Int64
|
||||
public let deviceModel: String
|
||||
@ -13,6 +28,7 @@ public struct RecentAccountSession: Equatable {
|
||||
public let ip: String
|
||||
public let country: String
|
||||
public let region: String
|
||||
public let flags: AccountSessionFlags
|
||||
|
||||
public var isCurrent: Bool {
|
||||
return self.hash == 0
|
||||
@ -55,6 +71,9 @@ public struct RecentAccountSession: Equatable {
|
||||
if lhs.region != rhs.region {
|
||||
return false
|
||||
}
|
||||
if lhs.flags != rhs.flags {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -62,8 +81,15 @@ public struct RecentAccountSession: Equatable {
|
||||
extension RecentAccountSession {
|
||||
init(apiAuthorization: Api.Authorization) {
|
||||
switch apiAuthorization {
|
||||
case let .authorization(hash, flags, deviceModel, platform, systemVersion, apiId, appName, appVersion, dateCreated, dateActive, ip, country, region):
|
||||
self.init(hash: hash, deviceModel: deviceModel, platform: platform, systemVersion: systemVersion, apiId: apiId, appName: appName, appVersion: appVersion, creationDate: dateCreated, activityDate: dateActive, ip: ip, country: country, region: region)
|
||||
case let .authorization(flags, hash, deviceModel, platform, systemVersion, apiId, appName, appVersion, dateCreated, dateActive, ip, country, region):
|
||||
var accountSessionFlags: AccountSessionFlags = []
|
||||
if (flags & (1 << 1)) != 0 {
|
||||
accountSessionFlags.insert(.isOfficial)
|
||||
}
|
||||
if (flags & (1 << 2)) != 0 {
|
||||
accountSessionFlags.insert(.passwordPending)
|
||||
}
|
||||
self.init(hash: hash, deviceModel: deviceModel, platform: platform, systemVersion: systemVersion, apiId: apiId, appName: appName, appVersion: appVersion, creationDate: dateCreated, activityDate: dateActive, ip: ip, country: country, region: region, flags: accountSessionFlags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,6 +16,11 @@ private enum RichTextTypes: Int32 {
|
||||
case url = 7
|
||||
case email = 8
|
||||
case concat = 9
|
||||
case `subscript` = 10
|
||||
case superscript = 11
|
||||
case marked = 12
|
||||
case phone = 13
|
||||
case image = 14
|
||||
}
|
||||
|
||||
public indirect enum RichText: PostboxCoding, Equatable {
|
||||
@ -29,6 +34,11 @@ public indirect enum RichText: PostboxCoding, Equatable {
|
||||
case url(text: RichText, url: String, webpageId: MediaId?)
|
||||
case email(text: RichText, email: String)
|
||||
case concat([RichText])
|
||||
case `subscript`(RichText)
|
||||
case superscript(RichText)
|
||||
case marked(RichText)
|
||||
case phone(text: RichText, phone: String)
|
||||
case image(id: MediaId, dimensions: CGSize)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("r", orElse: 0) {
|
||||
@ -58,6 +68,16 @@ public indirect enum RichText: PostboxCoding, Equatable {
|
||||
self = .email(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, email: decoder.decodeStringForKey("e", orElse: ""))
|
||||
case RichTextTypes.concat.rawValue:
|
||||
self = .concat(decoder.decodeObjectArrayWithDecoderForKey("a"))
|
||||
case RichTextTypes.subscript.rawValue:
|
||||
self = .subscript(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
case RichTextTypes.superscript.rawValue:
|
||||
self = .superscript(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
case RichTextTypes.marked.rawValue:
|
||||
self = .marked(decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText)
|
||||
case RichTextTypes.phone.rawValue:
|
||||
self = .phone(text: decoder.decodeObjectForKey("t", decoder: { RichText(decoder: $0) }) as! RichText, phone: decoder.decodeStringForKey("p", orElse: ""))
|
||||
case RichTextTypes.image.rawValue:
|
||||
self = .image(id: MediaId(namespace: decoder.decodeInt32ForKey("i.n", orElse: 0), id: decoder.decodeInt64ForKey("i.i", orElse: 0)), dimensions: CGSize(width: CGFloat(decoder.decodeInt32ForKey("sw", orElse: 0)), height: CGFloat(decoder.decodeInt32ForKey("sh", orElse: 0))))
|
||||
default:
|
||||
self = .empty
|
||||
}
|
||||
@ -103,6 +123,25 @@ public indirect enum RichText: PostboxCoding, Equatable {
|
||||
case let .concat(texts):
|
||||
encoder.encodeInt32(RichTextTypes.concat.rawValue, forKey: "r")
|
||||
encoder.encodeObjectArray(texts, forKey: "a")
|
||||
case let .subscript(text):
|
||||
encoder.encodeInt32(RichTextTypes.subscript.rawValue, forKey: "r")
|
||||
encoder.encodeObject(text, forKey: "t")
|
||||
case let .superscript(text):
|
||||
encoder.encodeInt32(RichTextTypes.superscript.rawValue, forKey: "r")
|
||||
encoder.encodeObject(text, forKey: "t")
|
||||
case let .marked(text):
|
||||
encoder.encodeInt32(RichTextTypes.marked.rawValue, forKey: "r")
|
||||
encoder.encodeObject(text, forKey: "t")
|
||||
case let .phone(text, phone):
|
||||
encoder.encodeInt32(RichTextTypes.phone.rawValue, forKey: "r")
|
||||
encoder.encodeObject(text, forKey: "t")
|
||||
encoder.encodeString(phone, forKey: "p")
|
||||
case let .image(id, dimensions):
|
||||
encoder.encodeInt32(RichTextTypes.image.rawValue, forKey: "r")
|
||||
encoder.encodeInt32(id.namespace, forKey: "i.n")
|
||||
encoder.encodeInt64(id.id, forKey: "i.i")
|
||||
encoder.encodeInt32(Int32(dimensions.width), forKey: "sw")
|
||||
encoder.encodeInt32(Int32(dimensions.height), forKey: "sh")
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,6 +207,36 @@ public indirect enum RichText: PostboxCoding, Equatable {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .subscript(text):
|
||||
if case .subscript(text) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .superscript(text):
|
||||
if case .superscript(text) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .marked(text):
|
||||
if case .marked(text) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .phone(text, phone):
|
||||
if case .phone(text, phone) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .image(id, dimensions):
|
||||
if case .image(id, dimensions) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -199,6 +268,16 @@ public extension RichText {
|
||||
string += text.plainText
|
||||
}
|
||||
return string
|
||||
case let .subscript(text):
|
||||
return text.plainText
|
||||
case let .superscript(text):
|
||||
return text.plainText
|
||||
case let .marked(text):
|
||||
return text.plainText
|
||||
case let .phone(text, _):
|
||||
return text.plainText
|
||||
case .image:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,6 +305,16 @@ extension RichText {
|
||||
self = .email(text: RichText(apiText: text), email: email)
|
||||
case let .textConcat(texts):
|
||||
self = .concat(texts.map({ RichText(apiText: $0) }))
|
||||
case let .textSubscript(text):
|
||||
self = .subscript(RichText(apiText: text))
|
||||
case let .textSuperscript(text):
|
||||
self = .superscript(RichText(apiText: text))
|
||||
case let .textMarked(text):
|
||||
self = .marked(RichText(apiText: text))
|
||||
case let .textPhone(text, phone):
|
||||
self = .phone(text: RichText(apiText: text), phone: phone)
|
||||
case let .textImage(documentId, w, h):
|
||||
self = .image(id: MediaId(namespace: Namespaces.Media.CloudFile, id: documentId), dimensions: CGSize(width: CGFloat(w), height: CGFloat(h)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ public class BoxedMessage: NSObject {
|
||||
|
||||
public class Serialization: NSObject, MTSerialization {
|
||||
public func currentLayer() -> UInt {
|
||||
return 86
|
||||
return 88
|
||||
}
|
||||
|
||||
public func parseMessage(_ data: Data!) -> Any! {
|
||||
|
||||
@ -5,7 +5,7 @@ import Foundation
|
||||
import Postbox
|
||||
#endif
|
||||
|
||||
public struct StickerPackCollectionInfoFlags : OptionSet {
|
||||
public struct StickerPackCollectionInfoFlags: OptionSet {
|
||||
public var rawValue: Int32
|
||||
|
||||
public init(rawValue: Int32) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user