Skip to content

Commit 43741a3

Browse files
committed
Chat list gift icon
1 parent 06defbb commit 43741a3

File tree

7 files changed

+97
-26
lines changed

7 files changed

+97
-26
lines changed

Telegram/Telegram-iOS/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13297,3 +13297,5 @@ Sorry for the inconvenience.";
1329713297
"WebApp.ShareMessage.PreviewTitle" = "MESSAGE PREVIEW";
1329813298
"WebApp.ShareMessage.Info" = "%@ mini app suggests you to send this message to a chat you select.";
1329913299
"WebApp.ShareMessage.Share" = "Share With...";
13300+
13301+
"Notification.Gift" = "Gift";

submodules/ChatListUI/Sources/Node/ChatListItem.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,6 +2081,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
20812081
var currentSecretIconImage: UIImage?
20822082
var currentForwardedIcon: UIImage?
20832083
var currentStoryIcon: UIImage?
2084+
var currentGiftIcon: UIImage?
20842085

20852086
var selectableControlSizeAndApply: (CGFloat, (CGSize, Bool) -> ItemListSelectableControlNode)?
20862087
var reorderControlSizeAndApply: (CGFloat, (CGFloat, Bool, ContainedViewLayoutTransition) -> ItemListEditableReorderControlNode)?
@@ -2254,6 +2255,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
22542255

22552256
var displayForwardedIcon = false
22562257
var displayStoryReplyIcon = false
2258+
var displayGiftIcon = false
22572259
var ignoreForwardedIcon = false
22582260

22592261
switch contentData {
@@ -2562,6 +2564,22 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
25622564
displayForwardedIcon = true
25632565
} else if let _ = message.attributes.first(where: { $0 is ReplyStoryAttribute }) {
25642566
displayStoryReplyIcon = true
2567+
} else {
2568+
for media in message.media {
2569+
if let action = media as? TelegramMediaAction {
2570+
switch action.action {
2571+
case .giftPremium, .giftStars, .starGift:
2572+
displayGiftIcon = true
2573+
case let .giftCode(_, _, _, boostPeerId, _, _, _, _, _, _, _):
2574+
if boostPeerId == nil {
2575+
displayGiftIcon = true
2576+
}
2577+
default:
2578+
break
2579+
}
2580+
}
2581+
break
2582+
}
25652583
}
25662584
}
25672585

@@ -2716,6 +2734,10 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
27162734
currentStoryIcon = PresentationResourcesChatList.storyReplyIcon(item.presentationData.theme)
27172735
}
27182736

2737+
if displayGiftIcon {
2738+
currentGiftIcon = PresentationResourcesChatList.giftIcon(item.presentationData.theme)
2739+
}
2740+
27192741
if let currentForwardedIcon {
27202742
textLeftCutout += currentForwardedIcon.size.width
27212743
if !contentImageSpecs.isEmpty {
@@ -2734,6 +2756,15 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
27342756
}
27352757
}
27362758

2759+
if let currentGiftIcon {
2760+
textLeftCutout += currentGiftIcon.size.width
2761+
if !contentImageSpecs.isEmpty {
2762+
textLeftCutout += forwardedIconSpacing
2763+
} else {
2764+
textLeftCutout += contentImageTrailingSpace
2765+
}
2766+
}
2767+
27372768
for i in 0 ..< contentImageSpecs.count {
27382769
if i != 0 {
27392770
textLeftCutout += contentImageSpacing
@@ -4261,6 +4292,9 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
42614292
messageTypeIconOffset.y += 3.0
42624293
} else if let currentStoryIcon {
42634294
messageTypeIcon = currentStoryIcon
4295+
} else if let currentGiftIcon {
4296+
messageTypeIcon = currentGiftIcon
4297+
messageTypeIconOffset.y -= 2.0 - UIScreenPixel
42644298
}
42654299

42664300
if let messageTypeIcon {

submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public enum PresentationResourceKey: Int32 {
119119

120120
case chatListForwardedIcon
121121
case chatListStoryReplyIcon
122+
case chatListGiftIcon
122123

123124
case chatListGeneralTopicIcon
124125
case chatListGeneralTopicSmallIcon

submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ public struct PresentationResourcesChatList {
259259
})
260260
}
261261

262+
public static func giftIcon(_ theme: PresentationTheme) -> UIImage? {
263+
return theme.image(PresentationResourceKey.chatListGiftIcon.rawValue, { theme in
264+
return generateTintedImage(image: UIImage(bundleImageName: "Chat List/GiftIcon"), color: theme.chatList.muteIconColor)
265+
})
266+
}
267+
262268
public static func verifiedIcon(_ theme: PresentationTheme) -> UIImage? {
263269
return theme.image(PresentationResourceKey.chatListVerifiedIcon.rawValue, { theme in
264270
if let backgroundImage = UIImage(bundleImageName: "Chat List/PeerVerifiedIconBackground"), let foregroundImage = UIImage(bundleImageName: "Chat List/PeerVerifiedIconForeground") {

submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -736,29 +736,37 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
736736
case let .webViewData(text):
737737
attributedString = NSAttributedString(string: strings.Notification_WebAppSentData(text).string, font: titleFont, textColor: primaryTextColor)
738738
case let .giftPremium(currency, amount, _, _, _, _, _):
739-
let price = formatCurrencyAmount(amount, currency: currency)
740-
if message.author?.id == accountPeerId {
741-
attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
739+
if !forAdditionalServiceMessage {
740+
attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor)
742741
} else {
743-
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)])
744-
attributes[1] = boldAttributes
745-
attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_Sent(compactAuthorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes)
742+
let price = formatCurrencyAmount(amount, currency: currency)
743+
if message.author?.id == accountPeerId {
744+
attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
745+
} else {
746+
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)])
747+
attributes[1] = boldAttributes
748+
attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_Sent(compactAuthorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes)
749+
}
746750
}
747751
case let .giftStars(currency, amount, count, _, _, _):
748752
let _ = count
749-
let price = formatCurrencyAmount(amount, currency: currency)
750-
if message.author?.id == accountPeerId {
751-
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
753+
if !forAdditionalServiceMessage {
754+
attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor)
752755
} else {
753-
var authorName = compactAuthorName
754-
var peerIds: [(Int, EnginePeer.Id?)] = [(0, message.author?.id)]
755-
if message.id.peerId.namespace == Namespaces.Peer.CloudUser && message.id.peerId.id._internalGetInt64Value() == 777000 {
756-
authorName = strings.Notification_StarsGift_UnknownUser
757-
peerIds = []
756+
let price = formatCurrencyAmount(amount, currency: currency)
757+
if message.author?.id == accountPeerId {
758+
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
759+
} else {
760+
var authorName = compactAuthorName
761+
var peerIds: [(Int, EnginePeer.Id?)] = [(0, message.author?.id)]
762+
if message.id.peerId.namespace == Namespaces.Peer.CloudUser && message.id.peerId.id._internalGetInt64Value() == 777000 {
763+
authorName = strings.Notification_StarsGift_UnknownUser
764+
peerIds = []
765+
}
766+
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: peerIds)
767+
attributes[1] = boldAttributes
768+
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_Sent(authorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes)
758769
}
759-
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: peerIds)
760-
attributes[1] = boldAttributes
761-
attributedString = addAttributesToStringWithRanges(strings.Notification_StarsGift_Sent(authorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes)
762770
}
763771
case let .topicCreated(title, iconColor, iconFileId):
764772
if forForumOverview {
@@ -957,13 +965,17 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
957965
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()))
958966
attributedString = mutableAttributedString
959967
} else if boostPeerId == nil, let currency, let amount {
960-
let price = formatCurrencyAmount(amount, currency: currency)
961-
if message.author?.id == accountPeerId {
962-
attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
968+
if !forAdditionalServiceMessage {
969+
attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor)
963970
} else {
964-
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)])
965-
attributes[1] = boldAttributes
966-
attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_Sent(compactAuthorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes)
971+
let price = formatCurrencyAmount(amount, currency: currency)
972+
if message.author?.id == accountPeerId {
973+
attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_SentYou(price)._tuple, body: bodyAttributes, argumentAttributes: [0: boldAttributes])
974+
} else {
975+
var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)])
976+
attributes[1] = boldAttributes
977+
attributedString = addAttributesToStringWithRanges(strings.Notification_PremiumGift_Sent(compactAuthorName, price)._tuple, body: bodyAttributes, argumentAttributes: attributes)
978+
}
967979
}
968980
} else {
969981
attributedString = NSAttributedString(string: strings.Notification_GiftLink, font: titleFont, textColor: primaryTextColor)
@@ -1055,9 +1067,13 @@ public func universalServiceMessageString(presentationData: (PresentationTheme,
10551067
case .prizeStars:
10561068
attributedString = NSAttributedString(string: strings.Notification_StarsPrize, font: titleFont, textColor: primaryTextColor)
10571069
case let .starGift(gift, _, text, entities, _, _, _):
1058-
if !forAdditionalServiceMessage, let text {
1059-
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()))
1060-
attributedString = mutableAttributedString
1070+
if !forAdditionalServiceMessage {
1071+
if let text {
1072+
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()))
1073+
attributedString = mutableAttributedString
1074+
} else {
1075+
attributedString = NSAttributedString(string: strings.Notification_Gift, font: titleFont, textColor: primaryTextColor)
1076+
}
10611077
} else {
10621078
let starsPrice = strings.Notification_StarsGift_Stars(Int32(gift.price))
10631079
var authorName = compactAuthorName
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "gift (3).pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Binary file not shown.

0 commit comments

Comments
 (0)