mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Ad info
This commit is contained in:
parent
d8684de082
commit
774cca56cb
@ -753,7 +753,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[-651419003] = { return Api.SendMessageAction.parse_speakingInGroupCallAction($0) }
|
||||
dict[-1239335713] = { return Api.ShippingOption.parse_shippingOption($0) }
|
||||
dict[-2010155333] = { return Api.SimpleWebViewResult.parse_simpleWebViewResultUrl($0) }
|
||||
dict[981691896] = { return Api.SponsoredMessage.parse_sponsoredMessage($0) }
|
||||
dict[-64636888] = { return Api.SponsoredMessage.parse_sponsoredMessage($0) }
|
||||
dict[-884757282] = { return Api.StatsAbsValueAndPrev.parse_statsAbsValueAndPrev($0) }
|
||||
dict[-1237848657] = { return Api.StatsDateRangeDays.parse_statsDateRangeDays($0) }
|
||||
dict[-1901828938] = { return Api.StatsGraph.parse_statsGraph($0) }
|
||||
|
@ -434,13 +434,13 @@ public extension Api {
|
||||
}
|
||||
public extension Api {
|
||||
indirect enum SponsoredMessage: TypeConstructorDescription {
|
||||
case sponsoredMessage(flags: Int32, randomId: Buffer, fromId: Api.Peer?, chatInvite: Api.ChatInvite?, chatInviteHash: String?, channelPost: Int32?, startParam: String?, message: String, entities: [Api.MessageEntity]?)
|
||||
case sponsoredMessage(flags: Int32, randomId: Buffer, fromId: Api.Peer?, chatInvite: Api.ChatInvite?, chatInviteHash: String?, channelPost: Int32?, startParam: String?, message: String, entities: [Api.MessageEntity]?, sponsorInfo: String?, additionalInfo: String?)
|
||||
|
||||
public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
case .sponsoredMessage(let flags, let randomId, let fromId, let chatInvite, let chatInviteHash, let channelPost, let startParam, let message, let entities):
|
||||
case .sponsoredMessage(let flags, let randomId, let fromId, let chatInvite, let chatInviteHash, let channelPost, let startParam, let message, let entities, let sponsorInfo, let additionalInfo):
|
||||
if boxed {
|
||||
buffer.appendInt32(981691896)
|
||||
buffer.appendInt32(-64636888)
|
||||
}
|
||||
serializeInt32(flags, buffer: buffer, boxed: false)
|
||||
serializeBytes(randomId, buffer: buffer, boxed: false)
|
||||
@ -455,14 +455,16 @@ public extension Api {
|
||||
for item in entities! {
|
||||
item.serialize(buffer, true)
|
||||
}}
|
||||
if Int(flags) & Int(1 << 7) != 0 {serializeString(sponsorInfo!, buffer: buffer, boxed: false)}
|
||||
if Int(flags) & Int(1 << 8) != 0 {serializeString(additionalInfo!, buffer: buffer, boxed: false)}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
public func descriptionFields() -> (String, [(String, Any)]) {
|
||||
switch self {
|
||||
case .sponsoredMessage(let flags, let randomId, let fromId, let chatInvite, let chatInviteHash, let channelPost, let startParam, let message, let entities):
|
||||
return ("sponsoredMessage", [("flags", flags as Any), ("randomId", randomId as Any), ("fromId", fromId as Any), ("chatInvite", chatInvite as Any), ("chatInviteHash", chatInviteHash as Any), ("channelPost", channelPost as Any), ("startParam", startParam as Any), ("message", message as Any), ("entities", entities as Any)])
|
||||
case .sponsoredMessage(let flags, let randomId, let fromId, let chatInvite, let chatInviteHash, let channelPost, let startParam, let message, let entities, let sponsorInfo, let additionalInfo):
|
||||
return ("sponsoredMessage", [("flags", flags as Any), ("randomId", randomId as Any), ("fromId", fromId as Any), ("chatInvite", chatInvite as Any), ("chatInviteHash", chatInviteHash as Any), ("channelPost", channelPost as Any), ("startParam", startParam as Any), ("message", message as Any), ("entities", entities as Any), ("sponsorInfo", sponsorInfo as Any), ("additionalInfo", additionalInfo as Any)])
|
||||
}
|
||||
}
|
||||
|
||||
@ -491,6 +493,10 @@ public extension Api {
|
||||
if Int(_1!) & Int(1 << 1) != 0 {if let _ = reader.readInt32() {
|
||||
_9 = Api.parseVector(reader, elementSignature: 0, elementType: Api.MessageEntity.self)
|
||||
} }
|
||||
var _10: String?
|
||||
if Int(_1!) & Int(1 << 7) != 0 {_10 = parseString(reader) }
|
||||
var _11: String?
|
||||
if Int(_1!) & Int(1 << 8) != 0 {_11 = parseString(reader) }
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
let _c3 = (Int(_1!) & Int(1 << 3) == 0) || _3 != nil
|
||||
@ -500,8 +506,10 @@ public extension Api {
|
||||
let _c7 = (Int(_1!) & Int(1 << 0) == 0) || _7 != nil
|
||||
let _c8 = _8 != nil
|
||||
let _c9 = (Int(_1!) & Int(1 << 1) == 0) || _9 != nil
|
||||
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 {
|
||||
return Api.SponsoredMessage.sponsoredMessage(flags: _1!, randomId: _2!, fromId: _3, chatInvite: _4, chatInviteHash: _5, channelPost: _6, startParam: _7, message: _8!, entities: _9)
|
||||
let _c10 = (Int(_1!) & Int(1 << 7) == 0) || _10 != nil
|
||||
let _c11 = (Int(_1!) & Int(1 << 8) == 0) || _11 != nil
|
||||
if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 {
|
||||
return Api.SponsoredMessage.sponsoredMessage(flags: _1!, randomId: _2!, fromId: _3, chatInvite: _4, chatInviteHash: _5, channelPost: _6, startParam: _7, message: _8!, entities: _9, sponsorInfo: _10, additionalInfo: _11)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
|
@ -16,12 +16,16 @@ public final class AdMessageAttribute: MessageAttribute {
|
||||
public let messageType: MessageType
|
||||
public let displayAvatar: Bool
|
||||
public let target: MessageTarget
|
||||
public let sponsorInfo: String?
|
||||
public let additionalInfo: String?
|
||||
|
||||
public init(opaqueId: Data, messageType: MessageType, displayAvatar: Bool, target: MessageTarget) {
|
||||
public init(opaqueId: Data, messageType: MessageType, displayAvatar: Bool, target: MessageTarget, sponsorInfo: String?, additionalInfo: String?) {
|
||||
self.opaqueId = opaqueId
|
||||
self.messageType = messageType
|
||||
self.displayAvatar = displayAvatar
|
||||
self.target = target
|
||||
self.sponsorInfo = sponsorInfo
|
||||
self.additionalInfo = additionalInfo
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
|
@ -15,6 +15,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
case target
|
||||
case messageId
|
||||
case startParam
|
||||
case sponsorInfo
|
||||
case additionalInfo
|
||||
}
|
||||
|
||||
enum MessageType: Int32, Codable {
|
||||
@ -73,6 +75,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
public let target: Target
|
||||
public let messageId: MessageId?
|
||||
public let startParam: String?
|
||||
public let sponsorInfo: String?
|
||||
public let additionalInfo: String?
|
||||
|
||||
public init(
|
||||
opaqueId: Data,
|
||||
@ -83,7 +87,9 @@ private class AdMessagesHistoryContextImpl {
|
||||
media: [Media],
|
||||
target: Target,
|
||||
messageId: MessageId?,
|
||||
startParam: String?
|
||||
startParam: String?,
|
||||
sponsorInfo: String?,
|
||||
additionalInfo: String?
|
||||
) {
|
||||
self.opaqueId = opaqueId
|
||||
self.messageType = messageType
|
||||
@ -94,6 +100,8 @@ private class AdMessagesHistoryContextImpl {
|
||||
self.target = target
|
||||
self.messageId = messageId
|
||||
self.startParam = startParam
|
||||
self.sponsorInfo = sponsorInfo
|
||||
self.additionalInfo = additionalInfo
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
@ -120,6 +128,9 @@ private class AdMessagesHistoryContextImpl {
|
||||
self.target = try container.decode(Target.self, forKey: .target)
|
||||
self.messageId = try container.decodeIfPresent(MessageId.self, forKey: .messageId)
|
||||
self.startParam = try container.decodeIfPresent(String.self, forKey: .startParam)
|
||||
|
||||
self.sponsorInfo = try container.decodeIfPresent(String.self, forKey: .sponsorInfo)
|
||||
self.additionalInfo = try container.decodeIfPresent(String.self, forKey: .additionalInfo)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
@ -141,6 +152,9 @@ private class AdMessagesHistoryContextImpl {
|
||||
try container.encode(self.target, forKey: .target)
|
||||
try container.encodeIfPresent(self.messageId, forKey: .messageId)
|
||||
try container.encodeIfPresent(self.startParam, forKey: .startParam)
|
||||
|
||||
try container.encodeIfPresent(self.sponsorInfo, forKey: .sponsorInfo)
|
||||
try container.encodeIfPresent(self.additionalInfo, forKey: .additionalInfo)
|
||||
}
|
||||
|
||||
public static func ==(lhs: CachedMessage, rhs: CachedMessage) -> Bool {
|
||||
@ -173,6 +187,12 @@ private class AdMessagesHistoryContextImpl {
|
||||
if lhs.startParam != rhs.startParam {
|
||||
return false
|
||||
}
|
||||
if lhs.sponsorInfo != rhs.sponsorInfo {
|
||||
return false
|
||||
}
|
||||
if lhs.additionalInfo != rhs.additionalInfo {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -193,7 +213,7 @@ private class AdMessagesHistoryContextImpl {
|
||||
case .recommended:
|
||||
mappedMessageType = .recommended
|
||||
}
|
||||
attributes.append(AdMessageAttribute(opaqueId: self.opaqueId, messageType: mappedMessageType, displayAvatar: self.displayAvatar, target: target))
|
||||
attributes.append(AdMessageAttribute(opaqueId: self.opaqueId, messageType: mappedMessageType, displayAvatar: self.displayAvatar, target: target, sponsorInfo: self.sponsorInfo, additionalInfo: self.additionalInfo))
|
||||
if !self.textEntities.isEmpty {
|
||||
let attribute = TextEntitiesMessageAttribute(entities: self.textEntities)
|
||||
attributes.append(attribute)
|
||||
@ -450,7 +470,7 @@ private class AdMessagesHistoryContextImpl {
|
||||
|
||||
for message in messages {
|
||||
switch message {
|
||||
case let .sponsoredMessage(flags, randomId, fromId, chatInvite, chatInviteHash, channelPost, startParam, message, entities):
|
||||
case let .sponsoredMessage(flags, randomId, fromId, chatInvite, chatInviteHash, channelPost, startParam, message, entities, sponsorInfo, additionalInfo):
|
||||
var parsedEntities: [MessageTextEntity] = []
|
||||
if let entities = entities {
|
||||
parsedEntities = messageTextEntitiesFromApiEntities(entities)
|
||||
@ -509,7 +529,9 @@ private class AdMessagesHistoryContextImpl {
|
||||
media: [],
|
||||
target: target,
|
||||
messageId: messageId,
|
||||
startParam: startParam
|
||||
startParam: startParam,
|
||||
sponsorInfo: sponsorInfo,
|
||||
additionalInfo: additionalInfo
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -403,12 +403,52 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
|
||||
hasExpandedAudioTranscription = messageNode.hasExpandedAudioTranscription()
|
||||
}
|
||||
|
||||
if messages.count == 1, let _ = messages[0].adAttribute {
|
||||
if messages.count == 1, let adAttribute = messages[0].adAttribute {
|
||||
let message = messages[0]
|
||||
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
|
||||
|
||||
var actions: [ContextMenuItem] = []
|
||||
|
||||
if adAttribute.sponsorInfo != nil || adAttribute.additionalInfo != nil {
|
||||
//TODO:localize
|
||||
actions.append(.action(ContextMenuActionItem(text: "Sponsor Info", textColor: .primary, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Channels"), color: theme.actionSheet.primaryTextColor)
|
||||
}, iconSource: nil, action: { c, _ in
|
||||
var subItems: [ContextMenuItem] = []
|
||||
|
||||
subItems.append(.action(ContextMenuActionItem(text: presentationData.strings.Common_Back, textColor: .primary, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Back"), color: theme.actionSheet.primaryTextColor)
|
||||
}, iconSource: nil, iconPosition: .left, action: { c, _ in
|
||||
c.popItems()
|
||||
})))
|
||||
|
||||
subItems.append(.separator)
|
||||
|
||||
if let sponsorInfo = adAttribute.sponsorInfo {
|
||||
subItems.append(.action(ContextMenuActionItem(text: sponsorInfo, textColor: .primary, textLayout: .multiline, textFont: .custom(font: Font.regular(floor(presentationData.listsFontSize.baseDisplaySize * 0.8)), height: nil, verticalOffset: nil), badge: nil, icon: { theme in
|
||||
return nil
|
||||
}, iconSource: nil, action: { c, _ in
|
||||
c.dismiss(completion: {
|
||||
UIPasteboard.general.string = sponsorInfo
|
||||
})
|
||||
})))
|
||||
}
|
||||
if let additionalInfo = adAttribute.additionalInfo {
|
||||
subItems.append(.action(ContextMenuActionItem(text: additionalInfo, textColor: .primary, textLayout: .multiline, textFont: .custom(font: Font.regular(floor(presentationData.listsFontSize.baseDisplaySize * 0.8)), height: nil, verticalOffset: nil), badge: nil, icon: { theme in
|
||||
return nil
|
||||
}, iconSource: nil, action: { c, _ in
|
||||
c.dismiss(completion: {
|
||||
UIPasteboard.general.string = additionalInfo
|
||||
})
|
||||
})))
|
||||
}
|
||||
|
||||
c.pushItems(items: .single(ContextController.Items(content: .list(subItems))))
|
||||
})))
|
||||
actions.append(.separator)
|
||||
}
|
||||
|
||||
actions.append(.action(ContextMenuActionItem(text: presentationData.strings.SponsoredMessageMenu_Info, textColor: .primary, textLayout: .twoLinesMax, textFont: .custom(font: Font.regular(presentationData.listsFontSize.baseDisplaySize - 1.0), height: nil, verticalOffset: nil), badge: nil, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Info"), color: theme.actionSheet.primaryTextColor)
|
||||
}, iconSource: nil, action: { c, _ in
|
||||
|
Loading…
x
Reference in New Issue
Block a user