Don't allow removing the screenshot message

This commit is contained in:
Ali 2021-07-27 23:41:46 +02:00
parent f7f6fc43cd
commit 62b7494872
6 changed files with 36 additions and 4 deletions

View File

@ -145,10 +145,12 @@ public struct ChatAvailableMessageActionOptions: OptionSet {
public struct ChatAvailableMessageActions {
public var options: ChatAvailableMessageActionOptions
public var banAuthor: Peer?
public var disableDelete: Bool
public init(options: ChatAvailableMessageActionOptions, banAuthor: Peer?) {
public init(options: ChatAvailableMessageActionOptions, banAuthor: Peer?, disableDelete: Bool) {
self.options = options
self.banAuthor = banAuthor
self.disableDelete = disableDelete
}
}

View File

@ -79,6 +79,8 @@ public protocol Media: class, PostboxCoding {
var indexableText: String? { get }
func isLikelyToBeUpdated() -> Bool
func preventsAutomaticMessageSendingFailure() -> Bool
func isEqual(to other: Media) -> Bool
func isSemanticallyEqual(to other: Media) -> Bool
@ -89,6 +91,10 @@ public extension Media {
return false
}
func preventsAutomaticMessageSendingFailure() -> Bool {
return false
}
var indexableText: String? {
return nil
}

View File

@ -1603,6 +1603,12 @@ public final class Postbox {
for id in self.messageHistoryUnsentTable.get() {
transaction.updateMessage(id, update: { message in
if !message.flags.contains(.Failed) {
for media in message.media {
if media.preventsAutomaticMessageSendingFailure() {
return .skip
}
}
if message.timestamp + 60 * 10 > timestampForAbsoluteTimeBasedOperations {
return .skip
}

View File

@ -251,6 +251,13 @@ public final class TelegramMediaAction: Media {
}
public let action: TelegramMediaActionType
public func preventsAutomaticMessageSendingFailure() -> Bool {
if case .historyScreenshot = self.action {
return true
}
return false
}
public init(action: TelegramMediaActionType) {
self.action = action

View File

@ -1059,6 +1059,7 @@ func chatAvailableMessageActionsImpl(postbox: Postbox, accountPeerId: PeerId, me
var banPeer: Peer?
var hadPersonalIncoming = false
var hadBanPeerId = false
var disableDelete = false
func getPeer(_ peerId: PeerId) -> Peer? {
if let peer = transaction.getPeer(peerId) {
@ -1229,6 +1230,15 @@ func chatAvailableMessageActionsImpl(postbox: Postbox, accountPeerId: PeerId, me
if canDeleteGlobally {
optionsMap[id]!.insert(.deleteGlobally)
}
for media in message.media {
if let action = media as? TelegramMediaAction {
if case .historyScreenshot = action.action {
optionsMap[id]!.remove(.deleteLocally)
optionsMap[id]!.remove(.deleteGlobally)
disableDelete = true
}
}
}
if user.botInfo != nil && message.flags.contains(.Incoming) && !user.id.isReplies && !isAction {
optionsMap[id]!.insert(.report)
}
@ -1239,6 +1249,7 @@ func chatAvailableMessageActionsImpl(postbox: Postbox, accountPeerId: PeerId, me
switch action.action {
case .historyScreenshot:
isNonRemovableServiceAction = true
disableDelete = true
default:
break
}
@ -1265,9 +1276,9 @@ func chatAvailableMessageActionsImpl(postbox: Postbox, accountPeerId: PeerId, me
if hadPersonalIncoming && optionsMap.values.contains(where: { $0.contains(.deleteGlobally) }) && !reducedOptions.contains(.deleteGlobally) {
reducedOptions.insert(.unsendPersonal)
}
return ChatAvailableMessageActions(options: reducedOptions, banAuthor: banPeer)
return ChatAvailableMessageActions(options: reducedOptions, banAuthor: banPeer, disableDelete: disableDelete)
} else {
return ChatAvailableMessageActions(options: [], banAuthor: nil)
return ChatAvailableMessageActions(options: [], banAuthor: nil, disableDelete: false)
}
}
}

View File

@ -154,7 +154,7 @@ final class ChatMessageSelectionInputPanelNode: ChatInputPanelNode {
if self.peerMedia {
self.deleteButton.isEnabled = !actions.options.intersection([.deleteLocally, .deleteGlobally]).isEmpty
} else {
self.deleteButton.isEnabled = true
self.deleteButton.isEnabled = !actions.disableDelete
}
self.shareButton.isEnabled = !actions.options.intersection([.forward]).isEmpty
self.reportButton.isEnabled = !actions.options.intersection([.report]).isEmpty