Various improvements

This commit is contained in:
Isaac 2025-06-24 14:23:39 +02:00
parent f2e96efdb5
commit 4513f7d2e4
6 changed files with 118 additions and 19 deletions

View File

@ -3542,7 +3542,7 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
if suggestedPostInfoNode !== strongSelf.suggestedPostInfoNode {
strongSelf.suggestedPostInfoNode?.removeFromSupernode()
strongSelf.suggestedPostInfoNode = suggestedPostInfoNode
strongSelf.mainContextSourceNode.contentNode.addSubnode(suggestedPostInfoNode)
strongSelf.addSubnode(suggestedPostInfoNode)
}
let suggestedPostInfoFrame = CGRect(origin: CGPoint(x: floor((params.width - suggestedPostInfoSize.width) * 0.5), y: 4.0), size: suggestedPostInfoSize)
suggestedPostInfoNode.frame = suggestedPostInfoFrame

View File

@ -291,7 +291,7 @@ public func canAddMessageReactions(message: Message) -> Bool {
return true
} else {
switch action.action {
case .unknown, .groupCreated, .channelMigratedFromGroup, .groupMigratedToChannel, .historyCleared, .customText, .botDomainAccessGranted, .botAppAccessGranted, .botSentSecureValues, .phoneNumberRequest, .webViewData, .topicCreated, .attachMenuBotAllowed, .requestedPeer, .giveawayLaunched:
case .unknown, .groupCreated, .channelMigratedFromGroup, .groupMigratedToChannel, .historyCleared, .customText, .botDomainAccessGranted, .botAppAccessGranted, .botSentSecureValues, .phoneNumberRequest, .webViewData, .topicCreated, .attachMenuBotAllowed, .requestedPeer, .giveawayLaunched, .suggestedPostApprovalStatus:
return false
default:
return true

View File

@ -93,15 +93,82 @@ public final class ChatMessageSuggestedPostInfoNode: ASDisplayNode {
//TODO:localize
let titleText: String
if !item.message.effectivelyIncoming(item.context.account.peerId) {
if item.message.attributes.contains(where: { $0 is ReplyMessageAttribute }) {
titleText = "You suggest a new price,\ntime and text for this message."
if let attribute = item.message.attributes.first(where: { $0 is ReplyMessageAttribute }) as? ReplyMessageAttribute {
var changedText = false
var changedMedia = false
var changedTime = false
var changedPrice = false
if let previousMessage = item.message.associatedMessages[attribute.messageId] {
if previousMessage.text != item.message.text {
changedText = true
}
let filteredMediaIds = item.message.media.compactMap { media -> EngineMedia.Id? in
if media is TelegramMediaImage || media is TelegramMediaFile {
return media.id
} else {
return nil
}
}
let filteredPreviousMediaIds = previousMessage.media.compactMap { media -> EngineMedia.Id? in
if media is TelegramMediaImage || media is TelegramMediaFile {
return media.id
} else {
return nil
}
}
if Set(filteredPreviousMediaIds) != Set(filteredMediaIds) {
changedMedia = true
}
if let previousAttribute = previousMessage.attributes.first(where: { $0 is SuggestedPostMessageAttribute }) as? SuggestedPostMessageAttribute {
if previousAttribute.amount != amount {
changedPrice = true
}
if previousAttribute.timestamp != timestamp {
changedTime = true
}
}
}
if !item.message.effectivelyIncoming(item.context.account.peerId) {
if changedText && changedMedia && changedPrice && changedTime {
titleText = "You suggest a new price,\ntime and contents for this message."
} else if changedText && changedPrice && changedTime {
titleText = "You suggest a new price,\ntime and text for this message."
} else if changedMedia && changedPrice && changedTime {
titleText = "You suggest a new price,\ntime and attachments for this message."
} else if changedPrice && changedTime {
titleText = "You suggest a new price and time\nfor this message."
} else if changedPrice {
titleText = "You suggest a new price\nfor this message."
} else if changedTime {
titleText = "You suggest a new time\nfor this message."
} else {
titleText = "You suggest changes\nfor this message."
}
} else {
titleText = "You suggest to post\nthis message."
var channelName = ""
if item.message.author is TelegramChannel {
channelName = item.message.author.flatMap(EnginePeer.init)?.compactDisplayTitle ?? " "
}
if changedText && changedMedia && changedPrice && changedTime {
titleText = "**\(channelName)** suggests a new price,\ntime and contents for this message."
} else if changedText && changedPrice && changedTime {
titleText = "**\(channelName)** suggests a new price,\ntime and text for this message."
} else if changedMedia && changedPrice && changedTime {
titleText = "**\(channelName)** suggests a new price,\ntime and attachments for this message."
} else if changedPrice && changedTime {
titleText = "**\(channelName)** suggests a new price and time\nfor this message."
} else if changedPrice {
titleText = "**\(channelName)** suggests a new price\nfor this message."
} else if changedTime {
titleText = "**\(channelName)** suggests a new time\nfor this message."
} else {
titleText = "**\(channelName)** suggests changes\nfor this message."
}
}
} else {
if item.message.author is TelegramChannel {
titleText = "**\(item.message.author.flatMap(EnginePeer.init)?.compactDisplayTitle ?? " ")** suggests a new price,\ntime, and text for your message."
if !item.message.effectivelyIncoming(item.context.account.peerId) {
titleText = "You suggest to post\nthis message."
} else {
titleText = "**\(item.message.author.flatMap(EnginePeer.init)?.compactDisplayTitle ?? " ")** suggests to post\nthis message."
}

View File

@ -2361,7 +2361,17 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
timestamp = Int32(Date().timeIntervalSince1970) + 1 * 60 * 60
} else {
let _ = strongSelf.context.engine.messages.monoforumPerformSuggestedPostAction(id: message.id, action: .approve(timestamp: timestamp)).startStandalone()
//TODO:localize
let textString = "Publish this message now?"
strongSelf.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: strongSelf.presentationData), title: nil, text: textString, actions: [
TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: {}),
TextAlertAction(type: .defaultAction, title: "Publish", action: { [weak strongSelf] in
guard let strongSelf else {
return
}
let _ = strongSelf.context.engine.messages.monoforumPerformSuggestedPostAction(id: message.id, action: .approve(timestamp: timestamp)).startStandalone()
})
]), in: .window(.root))
}
case 2:
strongSelf.interfaceInteraction?.openSuggestPost(message)

View File

@ -820,12 +820,20 @@ extension ChatControllerImpl {
if channel.isMonoForum {
if let linkedMonoforumId = channel.linkedMonoforumId, let mainChannel = peerView.peers[linkedMonoforumId] as? TelegramChannel, mainChannel.hasPermission(.manageDirect) {
} else {
sendPaidMessageStars = channel.sendPaidMessageStars
sendPaidMessageStars = cachedData.sendPaidMessageStars
}
} else {
if channel.flags.contains(.isCreator) || channel.adminRights != nil {
} else {
sendPaidMessageStars = channel.sendPaidMessageStars
if let personalSendPaidMessageStars = cachedData.sendPaidMessageStars {
if personalSendPaidMessageStars == .zero {
sendPaidMessageStars = nil
} else {
sendPaidMessageStars = personalSendPaidMessageStars
}
} else {
sendPaidMessageStars = channel.sendPaidMessageStars
}
}
}
}

View File

@ -1512,14 +1512,23 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
}
if let message = messages.first, message.id.namespace == Namespaces.Message.Cloud, let channel = message.peers[message.id.peerId] as? TelegramChannel, channel.isMonoForum {
//TODO:localize
actions.append(.action(ContextMenuActionItem(text: "Suggest a Post", icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Customize"), color: theme.actionSheet.primaryTextColor)
}, action: { c, _ in
c?.dismiss(completion: {
interfaceInteraction.openSuggestPost(message)
})
})))
var canSuggestPost = true
for media in message.media {
if media is TelegramMediaAction {
canSuggestPost = false
}
}
if canSuggestPost {
//TODO:localize
actions.append(.action(ContextMenuActionItem(text: "Suggest a Post", icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Customize"), color: theme.actionSheet.primaryTextColor)
}, action: { c, _ in
c?.dismiss(completion: {
interfaceInteraction.openSuggestPost(message)
})
})))
}
}
if let activePoll = activePoll, let voters = activePoll.results.voters {
@ -1935,6 +1944,11 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
if let channel = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramChannel, channel.isMonoForum, let associatedPeerId = channel.associatedPeerId {
if message.effectivelyIncoming(context.account.peerId), message.author?.id == associatedPeerId {
canViewAuthor = true
for media in message.media {
if media is TelegramMediaAction {
canViewAuthor = false
}
}
}
} else if let messageReadStatsAreHidden = infoSummaryData.messageReadStatsAreHidden, !messageReadStatsAreHidden {
canViewStats = canViewReadStats(message: message, participantCount: infoSummaryData.participantCount, isMessageRead: isMessageRead, isPremium: isPremium, appConfig: appConfig)