Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
laktyushin committed Dec 28, 2024
1 parent 3bbb677 commit 45fa1b5
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 15 deletions.
1 change: 1 addition & 0 deletions Telegram/Telegram-iOS/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
"PUSH_MESSAGE_SAME_WALLPAPER" = "%1$@ set the same wallpaper for the chat with you";

"PUSH_MESSAGE_UNIQUE_STARGIFT" = "%1$@ sent you a Gift";
"PUSH_MESSAGE_STARGIFT_UPGRADE" = "%1$@ upgraded your Gift";

"PUSH_REMINDER_TITLE" = "🗓 Reminder";
"PUSH_SENDER_YOU" = "📅 You";
Expand Down
58 changes: 56 additions & 2 deletions submodules/ChatListUI/Sources/Node/ChatListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,8 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
var verifiedIconComponent: EmojiStatusComponent?
var credibilityIconView: ComponentHostView<Empty>?
var credibilityIconComponent: EmojiStatusComponent?
var statusIconView: ComponentHostView<Empty>?
var statusIconComponent: EmojiStatusComponent?
let mutedIconNode: ASImageNode
var itemTagList: ComponentView<Empty>?
var actionButtonTitleNode: TextNode?
Expand Down Expand Up @@ -2142,6 +2144,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
var currentMutedIconImage: UIImage?
var currentCredibilityIconContent: EmojiStatusComponent.Content?
var currentVerifiedIconContent: EmojiStatusComponent.Content?
var currentStatusIconContent: EmojiStatusComponent.Content?
var currentSecretIconImage: UIImage?
var currentForwardedIcon: UIImage?
var currentStoryIcon: UIImage?
Expand Down Expand Up @@ -3098,7 +3101,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
} else if peer.isFake {
currentCredibilityIconContent = .text(color: item.presentationData.theme.chat.message.incoming.scamColor, string: item.presentationData.strings.Message_FakeAccount.uppercased())
} else if let emojiStatus = peer.emojiStatus, !premiumConfiguration.isPremiumDisabled {
currentCredibilityIconContent = .animation(content: .customEmoji(fileId: emojiStatus.fileId), size: CGSize(width: 32.0, height: 32.0), placeholderColor: item.presentationData.theme.list.mediaPlaceholderColor, themeColor: item.presentationData.theme.list.itemAccentColor, loopMode: .count(2))
currentStatusIconContent = .animation(content: .customEmoji(fileId: emojiStatus.fileId), size: CGSize(width: 32.0, height: 32.0), placeholderColor: item.presentationData.theme.list.mediaPlaceholderColor, themeColor: item.presentationData.theme.list.itemAccentColor, loopMode: .count(2))
} else if peer.isPremium && !premiumConfiguration.isPremiumDisabled {
currentCredibilityIconContent = .premium(color: item.presentationData.theme.list.itemAccentColor)
}
Expand Down Expand Up @@ -3126,7 +3129,7 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
} else if peer.isFake {
currentCredibilityIconContent = .text(color: item.presentationData.theme.chat.message.incoming.scamColor, string: item.presentationData.strings.Message_FakeAccount.uppercased())
} else if let emojiStatus = peer.emojiStatus, !premiumConfiguration.isPremiumDisabled {
currentCredibilityIconContent = .animation(content: .customEmoji(fileId: emojiStatus.fileId), size: CGSize(width: 32.0, height: 32.0), placeholderColor: item.presentationData.theme.list.mediaPlaceholderColor, themeColor: item.presentationData.theme.list.itemAccentColor, loopMode: .count(2))
currentStatusIconContent = .animation(content: .customEmoji(fileId: emojiStatus.fileId), size: CGSize(width: 32.0, height: 32.0), placeholderColor: item.presentationData.theme.list.mediaPlaceholderColor, themeColor: item.presentationData.theme.list.itemAccentColor, loopMode: .count(2))
} else if peer.isPremium && !premiumConfiguration.isPremiumDisabled {
currentCredibilityIconContent = .premium(color: item.presentationData.theme.list.itemAccentColor)
}
Expand Down Expand Up @@ -3180,6 +3183,22 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
}
}

if let currentStatusIconContent {
if titleIconsWidth.isZero {
titleIconsWidth += 4.0
} else {
titleIconsWidth += 2.0
}
switch currentStatusIconContent {
case let .text(_, string):
let textString = NSAttributedString(string: string, font: Font.bold(10.0), textColor: .black, paragraphAlignment: .center)
let stringRect = textString.boundingRect(with: CGSize(width: 100.0, height: 16.0), options: .usesLineFragmentOrigin, context: nil)
titleIconsWidth += floor(stringRect.width) + 11.0
default:
titleIconsWidth += 8.0
}
}

let layoutOffset: CGFloat = 0.0

let rawContentWidth = params.width - leftInset - params.rightInset - 10.0 - editingOffset
Expand Down Expand Up @@ -4514,6 +4533,41 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
} else {
lastLineRect = CGRect(origin: CGPoint(), size: titleLayout.size)
}

if let currentStatusIconContent {
let statusIconView: ComponentHostView<Empty>
if let current = strongSelf.statusIconView {
statusIconView = current
} else {
statusIconView = ComponentHostView<Empty>()
strongSelf.statusIconView = statusIconView
strongSelf.mainContentContainerNode.view.addSubview(statusIconView)
}

let statusIconComponent = EmojiStatusComponent(
context: item.context,
animationCache: item.interaction.animationCache,
animationRenderer: item.interaction.animationRenderer,
content: currentStatusIconContent,
isVisibleForAnimations: strongSelf.visibilityStatus && item.context.sharedContext.energyUsageSettings.loopEmoji,
action: nil
)
strongSelf.statusIconComponent = statusIconComponent

let iconOrigin: CGFloat = nextTitleIconOrigin
let containerSize = CGSize(width: 20.0, height: 20.0)
let iconSize = statusIconView.update(
transition: .immediate,
component: AnyComponent(statusIconComponent),
environment: {},
containerSize: containerSize
)
transition.updateFrame(view: statusIconView, frame: CGRect(origin: CGPoint(x: iconOrigin, y: floorToScreenPixels(titleFrame.maxY - lastLineRect.height * 0.5 - iconSize.height / 2.0) - UIScreenPixel), size: iconSize))
nextTitleIconOrigin += statusIconView.bounds.width + 4.0
} else if let statusIconView = strongSelf.statusIconView {
strongSelf.statusIconView = nil
statusIconView.removeFromSuperview()
}

if let currentCredibilityIconContent {
let credibilityIconView: ComponentHostView<Empty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,12 +950,13 @@ public final class ChatTitleView: UIView, NavigationBarTitleView {
titleTransition = .immediate
}

let iconSpacing: CGFloat = 2.0
let titleSideInset: CGFloat = 6.0
var titleFrame: CGRect
if size.height > 40.0 {
var titleInsets: UIEdgeInsets = .zero
if case .emojiStatus = self.titleVerifiedIcon, verifiedIconWidth > 0.0 {
titleInsets.left = verifiedIconWidth + 2.0
titleInsets.left = verifiedIconWidth + iconSpacing
}

var titleSize = self.titleTextNode.updateLayout(size: CGSize(width: clearBounds.width - leftIconWidth - credibilityIconWidth - verifiedIconWidth - statusIconWidth - rightIconWidth - titleSideInset * 2.0, height: size.height), insets: titleInsets, animated: titleTransition.isAnimated)
Expand Down
Loading

0 comments on commit 45fa1b5

Please sign in to comment.