mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Update API
This commit is contained in:
@@ -12,6 +12,17 @@ func telegramMediaWebpageAttributeFromApiWebpageAttribute(_ attribute: Api.WebPa
|
||||
files = documents.compactMap { telegramMediaFileFromApiDocument($0) }
|
||||
}
|
||||
return .theme(TelegraMediaWebpageThemeAttribute(files: files, settings: settings.flatMap { TelegramThemeSettings(apiThemeSettings: $0) }))
|
||||
case let .webPageAttributeStickerSet(apiFlags, stickers):
|
||||
var flags = TelegramMediaWebpageStickerPackAttribute.Flags()
|
||||
if (apiFlags & (1 << 0)) != 0 {
|
||||
flags.insert(.isEmoji)
|
||||
}
|
||||
if (apiFlags & (1 << 1)) != 0 {
|
||||
flags.insert(.isTemplate)
|
||||
}
|
||||
var files: [TelegramMediaFile] = []
|
||||
files = stickers.compactMap { telegramMediaFileFromApiDocument($0) }
|
||||
return .stickerPack(TelegramMediaWebpageStickerPackAttribute(flags: flags, files: files))
|
||||
case .webPageAttributeStory:
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -145,7 +145,11 @@ func mediaContentToUpload(accountPeerId: PeerId, network: Network, postbox: Post
|
||||
if let mediaReference = mediaReference {
|
||||
finalMediaReference = mediaReference
|
||||
} else if file.isSticker {
|
||||
finalMediaReference = .standalone(media: file)
|
||||
if let partialReference = file.partialReference {
|
||||
finalMediaReference = partialReference.mediaReference(file)
|
||||
} else {
|
||||
finalMediaReference = .standalone(media: file)
|
||||
}
|
||||
} else {
|
||||
finalMediaReference = .savedGif(media: file)
|
||||
}
|
||||
|
||||
@@ -3,16 +3,20 @@ import Postbox
|
||||
private enum TelegramMediaWebpageAttributeTypes: Int32 {
|
||||
case unsupported
|
||||
case theme
|
||||
case stickerPack
|
||||
}
|
||||
|
||||
public enum TelegramMediaWebpageAttribute: PostboxCoding, Equatable {
|
||||
case unsupported
|
||||
case theme(TelegraMediaWebpageThemeAttribute)
|
||||
case stickerPack(TelegramMediaWebpageStickerPackAttribute)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("r", orElse: 0) {
|
||||
case TelegramMediaWebpageAttributeTypes.theme.rawValue:
|
||||
self = .theme(decoder.decodeObjectForKey("a", decoder: { TelegraMediaWebpageThemeAttribute(decoder: $0) }) as! TelegraMediaWebpageThemeAttribute)
|
||||
case TelegramMediaWebpageAttributeTypes.stickerPack.rawValue:
|
||||
self = .stickerPack(decoder.decodeObjectForKey("a", decoder: { TelegramMediaWebpageStickerPackAttribute(decoder: $0) }) as! TelegramMediaWebpageStickerPackAttribute)
|
||||
default:
|
||||
self = .unsupported
|
||||
}
|
||||
@@ -25,6 +29,9 @@ public enum TelegramMediaWebpageAttribute: PostboxCoding, Equatable {
|
||||
case let .theme(attribute):
|
||||
encoder.encodeInt32(TelegramMediaWebpageAttributeTypes.theme.rawValue, forKey: "r")
|
||||
encoder.encodeObject(attribute, forKey: "a")
|
||||
case let .stickerPack(attribute):
|
||||
encoder.encodeInt32(TelegramMediaWebpageAttributeTypes.stickerPack.rawValue, forKey: "r")
|
||||
encoder.encodeObject(attribute, forKey: "a")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,6 +76,57 @@ public final class TelegraMediaWebpageThemeAttribute: PostboxCoding, Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
public final class TelegramMediaWebpageStickerPackAttribute: PostboxCoding, Equatable {
|
||||
public struct Flags: OptionSet {
|
||||
public var rawValue: Int32
|
||||
|
||||
public init() {
|
||||
self.rawValue = 0
|
||||
}
|
||||
|
||||
public init(rawValue: Int32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
public static let isEmoji = Flags(rawValue: 1 << 0)
|
||||
public static let isTemplate = Flags(rawValue: 1 << 1)
|
||||
}
|
||||
|
||||
public static func == (lhs: TelegramMediaWebpageStickerPackAttribute, rhs: TelegramMediaWebpageStickerPackAttribute) -> Bool {
|
||||
if lhs.flags != rhs.flags {
|
||||
return false
|
||||
}
|
||||
if lhs.files.count != rhs.files.count {
|
||||
return false
|
||||
} else {
|
||||
for i in 0 ..< lhs.files.count {
|
||||
if !lhs.files[i].isEqual(to: rhs.files[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public let flags: Flags
|
||||
public let files: [TelegramMediaFile]
|
||||
|
||||
public init(flags: Flags, files: [TelegramMediaFile]) {
|
||||
self.flags = flags
|
||||
self.files = files
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.flags = Flags(rawValue: decoder.decodeInt32ForKey("flags", orElse: 0))
|
||||
self.files = decoder.decodeObjectArrayForKey("files")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.flags.rawValue, forKey: "flags")
|
||||
encoder.encodeObjectArray(self.files, forKey: "files")
|
||||
}
|
||||
}
|
||||
|
||||
public final class TelegramMediaWebpageLoadedContent: PostboxCoding, Equatable {
|
||||
public let url: String
|
||||
public let displayUrl: String
|
||||
|
||||
@@ -12,6 +12,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
case text
|
||||
case textEntities
|
||||
case media
|
||||
case color
|
||||
case backgroundEmojiId
|
||||
case url
|
||||
case buttonText
|
||||
case sponsorInfo
|
||||
@@ -30,6 +32,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
public let text: String
|
||||
public let textEntities: [MessageTextEntity]
|
||||
public let media: [Media]
|
||||
public let color: PeerNameColor?
|
||||
public let backgroundEmojiId: Int64?
|
||||
public let url: String
|
||||
public let buttonText: String
|
||||
public let sponsorInfo: String?
|
||||
@@ -43,6 +47,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
text: String,
|
||||
textEntities: [MessageTextEntity],
|
||||
media: [Media],
|
||||
color: PeerNameColor?,
|
||||
backgroundEmojiId: Int64?,
|
||||
url: String,
|
||||
buttonText: String,
|
||||
sponsorInfo: String?,
|
||||
@@ -55,6 +61,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
self.text = text
|
||||
self.textEntities = textEntities
|
||||
self.media = media
|
||||
self.color = color
|
||||
self.backgroundEmojiId = backgroundEmojiId
|
||||
self.url = url
|
||||
self.buttonText = buttonText
|
||||
self.sponsorInfo = sponsorInfo
|
||||
@@ -81,6 +89,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
self.media = mediaData.compactMap { data -> Media? in
|
||||
return PostboxDecoder(buffer: MemoryBuffer(data: data)).decodeRootObject() as? Media
|
||||
}
|
||||
self.color = try container.decodeIfPresent(Int32.self, forKey: .color).flatMap { PeerNameColor(rawValue: $0) }
|
||||
self.backgroundEmojiId = try container.decodeIfPresent(Int64.self, forKey: .backgroundEmojiId)
|
||||
|
||||
self.url = try container.decode(String.self, forKey: .url)
|
||||
self.buttonText = try container.decode(String.self, forKey: .buttonText)
|
||||
@@ -107,6 +117,9 @@ private class AdMessagesHistoryContextImpl {
|
||||
}
|
||||
try container.encode(mediaData, forKey: .media)
|
||||
|
||||
try container.encodeIfPresent(self.color?.rawValue, forKey: .color)
|
||||
try container.encodeIfPresent(self.backgroundEmojiId, forKey: .backgroundEmojiId)
|
||||
|
||||
try container.encode(self.url, forKey: .url)
|
||||
try container.encode(self.buttonText, forKey: .buttonText)
|
||||
|
||||
@@ -197,8 +210,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
defaultBannedRights: nil,
|
||||
usernames: [],
|
||||
storiesHidden: nil,
|
||||
nameColor: .blue,
|
||||
backgroundEmojiId: nil,
|
||||
nameColor: self.color ?? .blue,
|
||||
backgroundEmojiId: self.backgroundEmojiId,
|
||||
profileColor: nil,
|
||||
profileBackgroundEmojiId: nil,
|
||||
emojiStatus: nil,
|
||||
@@ -408,7 +421,7 @@ private class AdMessagesHistoryContextImpl {
|
||||
|
||||
for message in messages {
|
||||
switch message {
|
||||
case let .sponsoredMessage(flags, randomId, url, title, message, entities, photo, buttonText, sponsorInfo, additionalInfo):
|
||||
case let .sponsoredMessage(flags, randomId, url, title, message, entities, photo, color, buttonText, sponsorInfo, additionalInfo):
|
||||
var parsedEntities: [MessageTextEntity] = []
|
||||
if let entities = entities {
|
||||
parsedEntities = messageTextEntitiesFromApiEntities(entities)
|
||||
@@ -417,8 +430,17 @@ private class AdMessagesHistoryContextImpl {
|
||||
let isRecommended = (flags & (1 << 5)) != 0
|
||||
let canReport = (flags & (1 << 12)) != 0
|
||||
|
||||
var nameColorIndex: Int32?
|
||||
var backgroundEmojiId: Int64?
|
||||
if let color = color {
|
||||
switch color {
|
||||
case let .peerColor(_, color, backgroundEmojiIdValue):
|
||||
nameColorIndex = color
|
||||
backgroundEmojiId = backgroundEmojiIdValue
|
||||
}
|
||||
}
|
||||
|
||||
let photo = photo.flatMap { telegramMediaImageFromApiPhoto($0) }
|
||||
|
||||
parsedMessages.append(CachedMessage(
|
||||
opaqueId: randomId.makeData(),
|
||||
messageType: isRecommended ? .recommended : .sponsored,
|
||||
@@ -426,6 +448,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
text: message,
|
||||
textEntities: parsedEntities,
|
||||
media: photo.flatMap { [$0] } ?? [],
|
||||
color: nameColorIndex.flatMap { PeerNameColor(rawValue: $0) },
|
||||
backgroundEmojiId: backgroundEmojiId,
|
||||
url: url,
|
||||
buttonText: buttonText,
|
||||
sponsorInfo: sponsorInfo,
|
||||
|
||||
Reference in New Issue
Block a user