diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 8c386fe18d..05797a9d24 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -13297,3 +13297,5 @@ Sorry for the inconvenience."; "WebApp.ShareMessage.PreviewTitle" = "MESSAGE PREVIEW"; "WebApp.ShareMessage.Info" = "%@ mini app suggests you to send this message to a chat you select."; "WebApp.ShareMessage.Share" = "Share With..."; + +"Notification.Gift" = "Gift"; diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index d91251f94f..5ed88feb23 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -2081,6 +2081,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { var currentSecretIconImage: UIImage? var currentForwardedIcon: UIImage? var currentStoryIcon: UIImage? + var currentGiftIcon: UIImage? var selectableControlSizeAndApply: (CGFloat, (CGSize, Bool) -> ItemListSelectableControlNode)? var reorderControlSizeAndApply: (CGFloat, (CGFloat, Bool, ContainedViewLayoutTransition) -> ItemListEditableReorderControlNode)? @@ -2254,6 +2255,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { var displayForwardedIcon = false var displayStoryReplyIcon = false + var displayGiftIcon = false var ignoreForwardedIcon = false switch contentData { @@ -2562,6 +2564,22 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { displayForwardedIcon = true } else if let _ = message.attributes.first(where: { $0 is ReplyStoryAttribute }) { displayStoryReplyIcon = true + } else { + for media in message.media { + if let action = media as? TelegramMediaAction { + switch action.action { + case .giftPremium, .giftStars, .starGift: + displayGiftIcon = true + case let .giftCode(_, _, _, boostPeerId, _, _, _, _, _, _, _): + if boostPeerId == nil { + displayGiftIcon = true + } + default: + break + } + } + break + } } } @@ -2716,6 +2734,10 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { currentStoryIcon = PresentationResourcesChatList.storyReplyIcon(item.presentationData.theme) } + if displayGiftIcon { + currentGiftIcon = PresentationResourcesChatList.giftIcon(item.presentationData.theme) + } + if let currentForwardedIcon { textLeftCutout += currentForwardedIcon.size.width if !contentImageSpecs.isEmpty { @@ -2734,6 +2756,15 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { } } + if let currentGiftIcon { + textLeftCutout += currentGiftIcon.size.width + if !contentImageSpecs.isEmpty { + textLeftCutout += forwardedIconSpacing + } else { + textLeftCutout += contentImageTrailingSpace + } + } + for i in 0 ..< contentImageSpecs.count { if i != 0 { textLeftCutout += contentImageSpacing @@ -4261,6 +4292,9 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode { messageTypeIconOffset.y += 3.0 } else if let currentStoryIcon { messageTypeIcon = currentStoryIcon + } else if let currentGiftIcon { + messageTypeIcon = currentGiftIcon + messageTypeIconOffset.y -= 2.0 - UIScreenPixel } if let messageTypeIcon { diff --git a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift index 373ef8fe9e..71a20e585e 100644 --- a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift +++ b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift @@ -119,6 +119,7 @@ public enum PresentationResourceKey: Int32 { case chatListForwardedIcon case chatListStoryReplyIcon + case chatListGiftIcon case chatListGeneralTopicIcon case chatListGeneralTopicSmallIcon diff --git a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift index 0273cfc4b5..44dbd95eba 100644 --- a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift +++ b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift @@ -259,6 +259,12 @@ public struct PresentationResourcesChatList { }) } + public static func giftIcon(_ theme: PresentationTheme) -> UIImage? { + return theme.image(PresentationResourceKey.chatListGiftIcon.rawValue, { theme in + return generateTintedImage(image: UIImage(bundleImageName: "Chat List/GiftIcon"), color: theme.chatList.muteIconColor) + }) + } + public static func verifiedIcon(_ theme: PresentationTheme) -> UIImage? { return theme.image(PresentationResourceKey.chatListVerifiedIcon.rawValue, { theme in if let backgroundImage = UIImage(bundleImageName: "Chat List/PeerVerifiedIconBackground"), let foregroundImage = UIImage(bundleImageName: "Chat List/PeerVerifiedIconForeground") { diff --git a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift index 1ca5659fc2..b06741c405 100644 --- a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift @@ -736,29 +736,37 @@ public func universalServiceMessageString(presentationData: (PresentationTheme, case let .webViewData(text): attributedString = NSAttributedString(string: strings.Notification_WebAppSentData(text).string, font: titleFont, textColor: primaryTextColor) case let .giftPremium(currency, amount, _, _, _, _, _): - let price = formatCurrencyAmount(amount, currency: currency) - if message.author?.id == accountPeerId { - attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes]) + if !forAdditionalServiceMessage { + attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor) } else { - var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]) - attributes[1] = boldAttributes - attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_Sent(compactAuthorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes) + let price = formatCurrencyAmount(amount, currency: currency) + if message.author?.id == accountPeerId { + attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes]) + } else { + var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]) + attributes[1] = boldAttributes + attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_Sent(compactAuthorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes) + } } case let .giftStars(currency, amount, count, _, _, _): let _ = count - let price = formatCurrencyAmount(amount, currency: currency) - if message.author?.id == accountPeerId { - attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes]) + if !forAdditionalServiceMessage { + attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor) } else { - var authorName = compactAuthorName - var peerIds: [(Int, EnginePeer.Id?)] = [(0, message.author?.id)] - if message.id.peerId.namespace == Namespaces.Peer.CloudUser && message.id.peerId.id._internalGetInt64Value() == 777000 { - authorName = strings.Notification_StarsGift_UnknownUser - peerIds = [] + let price = formatCurrencyAmount(amount, currency: currency) + if message.author?.id == accountPeerId { + attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes]) + } else { + var authorName = compactAuthorName + var peerIds: [(Int, EnginePeer.Id?)] = [(0, message.author?.id)] + if message.id.peerId.namespace == Namespaces.Peer.CloudUser && message.id.peerId.id._internalGetInt64Value() == 777000 { + authorName = strings.Notification_StarsGift_UnknownUser + peerIds = [] + } + var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: peerIds) + attributes[1] = boldAttributes + attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_Sent(authorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes) } - var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: peerIds) - attributes[1] = boldAttributes - attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_Sent(authorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes) } case let .topicCreated(title, iconColor, iconFileId): if forForumOverview { @@ -957,13 +965,17 @@ public func universalServiceMessageString(presentationData: (PresentationTheme, let mutableAttributedString = NSMutableAttributedString(attributedString: stringWithAppliedEntities(text, entities: entities ?? [], baseColor: primaryTextColor, linkColor: primaryTextColor, baseFont: titleFont, linkFont: titleBoldFont, boldFont: titleBoldFont, italicFont: titleFont, boldItalicFont: titleBoldFont, fixedFont: titleFont, blockQuoteFont: titleFont, underlineLinks: false, message: message._asMessage())) attributedString = mutableAttributedString } else if boostPeerId == nil, let currency, let amount { - let price = formatCurrencyAmount(amount, currency: currency) - if message.author?.id == accountPeerId { - attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes]) + if !forAdditionalServiceMessage { + attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor) } else { - var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]) - attributes[1] = boldAttributes - attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_Sent(compactAuthorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes) + let price = formatCurrencyAmount(amount, currency: currency) + if message.author?.id == accountPeerId { + attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes]) + } else { + var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]) + attributes[1] = boldAttributes + attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_Sent(compactAuthorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes) + } } } else { attributedString = NSAttributedString(string: strings.Notification_GiftLink, font: titleFont, textColor: primaryTextColor) @@ -1055,9 +1067,13 @@ public func universalServiceMessageString(presentationData: (PresentationTheme, case .prizeStars: attributedString = NSAttributedString(string: strings.Notification_StarsPrize, font: titleFont, textColor: primaryTextColor) case let .starGift(gift, _, text, entities, _, _, _): - if !forAdditionalServiceMessage, let text { - let mutableAttributedString = NSMutableAttributedString(attributedString: stringWithAppliedEntities(text, entities: entities ?? [], baseColor: primaryTextColor, linkColor: primaryTextColor, baseFont: titleFont, linkFont: titleBoldFont, boldFont: titleBoldFont, italicFont: titleFont, boldItalicFont: titleBoldFont, fixedFont: titleFont, blockQuoteFont: titleFont, underlineLinks: false, message: message._asMessage())) - attributedString = mutableAttributedString + if !forAdditionalServiceMessage { + if let text { + let mutableAttributedString = NSMutableAttributedString(attributedString: stringWithAppliedEntities(text, entities: entities ?? [], baseColor: primaryTextColor, linkColor: primaryTextColor, baseFont: titleFont, linkFont: titleBoldFont, boldFont: titleBoldFont, italicFont: titleFont, boldItalicFont: titleBoldFont, fixedFont: titleFont, blockQuoteFont: titleFont, underlineLinks: false, message: message._asMessage())) + attributedString = mutableAttributedString + } else { + attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor) + } } else { let starsPrice = strings.Notification_StarsGift_Stars(Int32(gift.price)) var authorName = compactAuthorName diff --git a/submodules/TelegramUI/Images.xcassets/Chat List/GiftIcon.imageset/Contents.json b/submodules/TelegramUI/Images.xcassets/Chat List/GiftIcon.imageset/Contents.json new file mode 100644 index 0000000000..b27b0dd894 --- /dev/null +++ b/submodules/TelegramUI/Images.xcassets/Chat List/GiftIcon.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "gift (3).pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/submodules/TelegramUI/Images.xcassets/Chat List/GiftIcon.imageset/gift (3).pdf b/submodules/TelegramUI/Images.xcassets/Chat List/GiftIcon.imageset/gift (3).pdf new file mode 100644 index 0000000000..2fb301a72a Binary files /dev/null and b/submodules/TelegramUI/Images.xcassets/Chat List/GiftIcon.imageset/gift (3).pdf differ