[WIP] Business

This commit is contained in:
Isaac
2024-02-20 14:45:25 +04:00
parent 31260e710b
commit f259829c8a
68 changed files with 3331 additions and 762 deletions

View File

@@ -92,10 +92,12 @@ public enum ChatListItemContent {
public struct CustomMessageListData: Equatable {
public var commandPrefix: String?
public var searchQuery: String?
public var messageCount: Int?
public init(commandPrefix: String?, messageCount: Int?) {
public init(commandPrefix: String?, searchQuery: String?, messageCount: Int?) {
self.commandPrefix = commandPrefix
self.searchQuery = searchQuery
self.messageCount = messageCount
}
}
@@ -1625,7 +1627,19 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
isForumAvatar = true
}
}
var avatarDiameter = min(60.0, floor(item.presentationData.fontSize.baseDisplaySize * 60.0 / 17.0))
if case let .peer(peerData) = item.content, let customMessageListData = peerData.customMessageListData, customMessageListData.commandPrefix != nil {
avatarDiameter = 40.0
}
if avatarDiameter != 60.0 {
let avatarFontSize = floor(avatarDiameter * 26.0 / 60.0)
if self.avatarNode.font.pointSize != avatarFontSize {
self.avatarNode.font = avatarPlaceholderFont(size: avatarFontSize)
}
}
self.avatarNode.setPeer(context: item.context, theme: item.presentationData.theme, peer: peer, overrideImage: overrideImage, emptyColor: item.presentationData.theme.list.mediaPlaceholderColor, clipStyle: isForumAvatar ? .roundedRect : .round, synchronousLoad: synchronousLoads, displayDimensions: CGSize(width: 60.0, height: 60.0))
if peer.isPremium && peer.id != item.context.account.peerId {
@@ -2011,33 +2025,48 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
let editingOffset: CGFloat
var reorderInset: CGFloat = 0.0
if item.editing {
let sizeAndApply = selectableControlLayout(item.presentationData.theme.list.itemCheckColors.strokeColor, item.presentationData.theme.list.itemCheckColors.fillColor, item.presentationData.theme.list.itemCheckColors.foregroundColor, item.selected, true)
let selectionControlStyle: ItemListSelectableControlNode.Style
if case let .peer(peerData) = item.content, let customMessageListData = peerData.customMessageListData, customMessageListData.commandPrefix != nil {
selectionControlStyle = .small
} else {
selectionControlStyle = .compact
}
let sizeAndApply = selectableControlLayout(item.presentationData.theme.list.itemCheckColors.strokeColor, item.presentationData.theme.list.itemCheckColors.fillColor, item.presentationData.theme.list.itemCheckColors.foregroundColor, item.selected, selectionControlStyle)
if promoInfo == nil && !isPeerGroup {
selectableControlSizeAndApply = sizeAndApply
}
editingOffset = sizeAndApply.0
var canReorder = false
if case let .chatList(index) = item.index, index.pinningIndex != nil, promoInfo == nil, !isPeerGroup {
let sizeAndApply = reorderControlLayout(item.presentationData.theme)
reorderControlSizeAndApply = sizeAndApply
reorderInset = sizeAndApply.0
canReorder = true
} else if case let .forum(pinnedIndex, _, _, _, _) = item.index, case .index = pinnedIndex {
if case let .chat(itemPeer) = contentPeer, case let .channel(channel) = itemPeer.peer {
let canPin = channel.flags.contains(.isCreator) || channel.hasPermission(.pinMessages)
if canPin {
let sizeAndApply = reorderControlLayout(item.presentationData.theme)
reorderControlSizeAndApply = sizeAndApply
reorderInset = sizeAndApply.0
canReorder = true
}
}
}
if case let .peer(peerData) = item.content, let customMessageListData = peerData.customMessageListData, customMessageListData.commandPrefix != nil {
canReorder = true
}
if canReorder {
let sizeAndApply = reorderControlLayout(item.presentationData.theme)
reorderControlSizeAndApply = sizeAndApply
reorderInset = sizeAndApply.0
}
} else {
editingOffset = 0.0
}
let enableChatListPhotos = true
// if changed, adjust setupItem accordingly
var avatarDiameter = min(60.0, floor(item.presentationData.fontSize.baseDisplaySize * 60.0 / 17.0))
let avatarLeftInset: CGFloat
@@ -2427,6 +2456,12 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
let mutableAttributedText = NSMutableAttributedString(attributedString: attributedText)
let boldTextFont = Font.semibold(floor(item.presentationData.fontSize.itemListBaseFontSize * 15.0 / 17.0))
mutableAttributedText.insert(NSAttributedString(string: commandPrefix + " ", font: boldTextFont, textColor: theme.titleColor), at: 0)
if let searchQuery = customMessageListData.searchQuery {
let range = (mutableAttributedText.string as NSString).range(of: searchQuery)
if range.location == 0 {
mutableAttributedText.addAttribute(.foregroundColor, value: item.presentationData.theme.list.itemAccentColor, range: range)
}
}
attributedText = mutableAttributedText
}
@@ -3127,7 +3162,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
itemHeight -= 21.0
if case let .peer(peerData) = item.content, let customMessageListData = peerData.customMessageListData, customMessageListData.commandPrefix != nil {
itemHeight += measureLayout.size.height * 2.0
itemHeight += 22.0
itemHeight += 20.0
} else {
itemHeight += titleLayout.size.height
itemHeight += measureLayout.size.height * 3.0