Added support for personal message revocation

This commit is contained in:
Peter 2019-03-18 01:14:51 +04:00
parent 826e1291d6
commit 6041f76b05
6 changed files with 2487 additions and 2437 deletions

View File

@ -5888,7 +5888,13 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal
}
}))
}
if options.contains(.deleteGlobally) {
var unsendPersonalMessages = false
if options.contains(.unsendPersonal) {
items.append(ActionSheetTextItem(title: self.presentationData.strings.Chat_UnsendMyMessagesAlertTitle(personalPeerName ?? "").0))
items.append(ActionSheetSwitchItem(title: self.presentationData.strings.Chat_UnsendMyMessages, isOn: false, action: { value in
unsendPersonalMessages = value
}))
} else if options.contains(.deleteGlobally) {
let globalTitle: String
if isChannel {
globalTitle = self.presentationData.strings.Conversation_DeleteMessagesForEveryone
@ -5907,7 +5913,9 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal
}
if options.contains(.deleteLocally) {
var localOptionText = self.presentationData.strings.Conversation_DeleteMessagesForMe
if case .peer(self.context.account.peerId) = self.chatLocation {
if options.contains(.unsendPersonal) {
localOptionText = self.presentationData.strings.Chat_DeleteMessagesConfirmation(Int32(messageIds.count))
} else if case .peer(self.context.account.peerId) = self.chatLocation {
if messageIds.count == 1 {
localOptionText = self.presentationData.strings.Conversation_Moderate_Delete
} else {
@ -5918,7 +5926,7 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal
actionSheet?.dismissAnimated()
if let strongSelf = self {
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { $0.updatedInterfaceState { $0.withoutSelectionState() } })
let _ = deleteMessagesInteractively(postbox: strongSelf.context.account.postbox, messageIds: Array(messageIds), type: .forLocalPeer).start()
let _ = deleteMessagesInteractively(postbox: strongSelf.context.account.postbox, messageIds: Array(messageIds), type: unsendPersonalMessages ? .forEveryone : .forLocalPeer).start()
}
}))
}

View File

@ -570,6 +570,7 @@ struct ChatAvailableMessageActionOptions: OptionSet {
static let viewStickerPack = ChatAvailableMessageActionOptions(rawValue: 1 << 4)
static let rateCall = ChatAvailableMessageActionOptions(rawValue: 1 << 5)
static let cancelSending = ChatAvailableMessageActionOptions(rawValue: 1 << 6)
static let unsendPersonal = ChatAvailableMessageActionOptions(rawValue: 1 << 7)
}
struct ChatAvailableMessageActions {
@ -590,11 +591,34 @@ private func canPerformEditingActions(limits: LimitsConfiguration, accountPeerId
return false
}
private func canPerformDeleteActions(limits: LimitsConfiguration, accountPeerId: PeerId, message: Message) -> Bool {
if message.id.peerId == accountPeerId {
return true
}
if message.id.peerId.namespace == Namespaces.Peer.SecretChat {
return true
}
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
if message.id.peerId.namespace == Namespaces.Peer.CloudUser {
if message.timestamp + limits.maxMessageRevokeIntervalInPrivateChats > timestamp {
return true
}
} else {
if message.timestamp + limits.maxMessageRevokeInterval > timestamp {
return true
}
}
return false
}
func chatAvailableMessageActions(postbox: Postbox, accountPeerId: PeerId, messageIds: Set<MessageId>) -> Signal<ChatAvailableMessageActions, NoError> {
return postbox.transaction { transaction -> ChatAvailableMessageActions in
let limitsConfiguration: LimitsConfiguration = transaction.getPreferencesEntry(key: PreferencesKeys.limitsConfiguration) as? LimitsConfiguration ?? LimitsConfiguration.defaultValue
var optionsMap: [MessageId: ChatAvailableMessageActionOptions] = [:]
var banPeer: Peer?
var hadPersonalIncoming = false
var hadBanPeerId = false
for id in messageIds {
if optionsMap[id] == nil {
@ -699,9 +723,16 @@ func chatAvailableMessageActions(postbox: Postbox, accountPeerId: PeerId, messag
}
}
optionsMap[id]!.insert(.deleteLocally)
if canPerformEditingActions(limits: limitsConfiguration, accountPeerId: accountPeerId, message: message) && !message.flags.contains(.Incoming) {
optionsMap[id]!.insert(.deleteGlobally)
var canDeleteGlobally = false
if canPerformDeleteActions(limits: limitsConfiguration, accountPeerId: accountPeerId, message: message) {
canDeleteGlobally = true
} else if limitsConfiguration.canRemoveIncomingMessagesInPrivateChats {
canDeleteGlobally = true
}
if message.flags.contains(.Incoming) {
hadPersonalIncoming = true
}
if canDeleteGlobally {
optionsMap[id]!.insert(.deleteGlobally)
}
if user.botInfo != nil {
@ -737,6 +768,9 @@ func chatAvailableMessageActions(postbox: Postbox, accountPeerId: PeerId, messag
for value in optionsMap.values {
reducedOptions.formIntersection(value)
}
if hadPersonalIncoming && optionsMap.values.contains(where: { $0.contains(.deleteGlobally) }) && !reducedOptions.contains(.deleteGlobally) {
reducedOptions.insert(.unsendPersonal)
}
return ChatAvailableMessageActions(options: reducedOptions, banAuthor: banPeer)
} else {
return ChatAvailableMessageActions(options: [], banAuthor: nil)

View File

@ -30,7 +30,7 @@ public extension NavigationBarPresentationData {
extension ActionSheetControllerTheme {
convenience init(presentationTheme: PresentationTheme) {
let actionSheet = presentationTheme.actionSheet
self.init(dimColor: actionSheet.dimColor, backgroundType: actionSheet.backgroundType == .light ? .light : .dark, itemBackgroundColor: actionSheet.itemBackgroundColor, itemHighlightedBackgroundColor: actionSheet.itemHighlightedBackgroundColor, standardActionTextColor: actionSheet.standardActionTextColor, destructiveActionTextColor: actionSheet.destructiveActionTextColor, disabledActionTextColor: actionSheet.disabledActionTextColor, primaryTextColor: actionSheet.primaryTextColor, secondaryTextColor: actionSheet.secondaryTextColor, controlAccentColor: actionSheet.controlAccentColor, controlColor: presentationTheme.list.disclosureArrowColor)
self.init(dimColor: actionSheet.dimColor, backgroundType: actionSheet.backgroundType == .light ? .light : .dark, itemBackgroundColor: actionSheet.itemBackgroundColor, itemHighlightedBackgroundColor: actionSheet.itemHighlightedBackgroundColor, standardActionTextColor: actionSheet.standardActionTextColor, destructiveActionTextColor: actionSheet.destructiveActionTextColor, disabledActionTextColor: actionSheet.disabledActionTextColor, primaryTextColor: actionSheet.primaryTextColor, secondaryTextColor: actionSheet.secondaryTextColor, controlAccentColor: actionSheet.controlAccentColor, controlColor: presentationTheme.list.disclosureArrowColor, switchFrameColor: presentationTheme.list.itemSwitchColors.frameColor, switchContentColor: presentationTheme.list.itemSwitchColors.contentColor, switchHandleColor: presentationTheme.list.itemSwitchColors.handleColor)
}
}

View File

@ -320,7 +320,7 @@ func instantPageThemeForType(_ type: InstantPageThemeType, settings: InstantPage
extension ActionSheetControllerTheme {
convenience init(instantPageTheme: InstantPageTheme) {
self.init(dimColor: UIColor(white: 0.0, alpha: 0.4), backgroundType: instantPageTheme.type != .dark ? .light : .dark, itemBackgroundColor: instantPageTheme.overlayPanelColor, itemHighlightedBackgroundColor: instantPageTheme.panelHighlightedBackgroundColor, standardActionTextColor: instantPageTheme.panelAccentColor, destructiveActionTextColor: instantPageTheme.panelAccentColor, disabledActionTextColor: instantPageTheme.panelAccentColor, primaryTextColor: instantPageTheme.textCategories.paragraph.color, secondaryTextColor: instantPageTheme.textCategories.caption.color, controlAccentColor: instantPageTheme.panelAccentColor, controlColor: instantPageTheme.tableBorderColor)
self.init(dimColor: UIColor(white: 0.0, alpha: 0.4), backgroundType: instantPageTheme.type != .dark ? .light : .dark, itemBackgroundColor: instantPageTheme.overlayPanelColor, itemHighlightedBackgroundColor: instantPageTheme.panelHighlightedBackgroundColor, standardActionTextColor: instantPageTheme.panelAccentColor, destructiveActionTextColor: instantPageTheme.panelAccentColor, disabledActionTextColor: instantPageTheme.panelAccentColor, primaryTextColor: instantPageTheme.textCategories.paragraph.color, secondaryTextColor: instantPageTheme.textCategories.caption.color, controlAccentColor: instantPageTheme.panelAccentColor, controlColor: instantPageTheme.tableBorderColor, switchFrameColor: .white, switchContentColor: .white, switchHandleColor: .white)
}
}

File diff suppressed because it is too large Load Diff