mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Message autoremove fixes
This commit is contained in:
parent
d366ea37d7
commit
3cdb545029
@ -2,20 +2,14 @@ import Foundation
|
||||
import Postbox
|
||||
|
||||
public class AutoremoveTimeoutMessageAttribute: MessageAttribute {
|
||||
public enum Action: Int32 {
|
||||
case remove = 0
|
||||
case clear = 1
|
||||
}
|
||||
|
||||
public let timeout: Int32
|
||||
public let countdownBeginTime: Int32?
|
||||
public let action: Action
|
||||
|
||||
public var associatedMessageIds: [MessageId] = []
|
||||
|
||||
public let automaticTimestampBasedAttribute: (UInt16, Int32)?
|
||||
|
||||
public init(timeout: Int32, countdownBeginTime: Int32?, action: Action = .remove) {
|
||||
public init(timeout: Int32, countdownBeginTime: Int32?) {
|
||||
self.timeout = timeout
|
||||
self.countdownBeginTime = countdownBeginTime
|
||||
|
||||
@ -24,8 +18,6 @@ public class AutoremoveTimeoutMessageAttribute: MessageAttribute {
|
||||
} else {
|
||||
self.automaticTimestampBasedAttribute = nil
|
||||
}
|
||||
|
||||
self.action = action
|
||||
}
|
||||
|
||||
required public init(decoder: PostboxDecoder) {
|
||||
@ -37,8 +29,6 @@ public class AutoremoveTimeoutMessageAttribute: MessageAttribute {
|
||||
} else {
|
||||
self.automaticTimestampBasedAttribute = nil
|
||||
}
|
||||
|
||||
self.action = Action(rawValue: decoder.decodeInt32ForKey("a", orElse: 0)) ?? .remove
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
@ -48,24 +38,30 @@ public class AutoremoveTimeoutMessageAttribute: MessageAttribute {
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "c")
|
||||
}
|
||||
encoder.encodeInt32(self.action.rawValue, forKey: "a")
|
||||
}
|
||||
}
|
||||
|
||||
public extension Message {
|
||||
var containsSecretMedia: Bool {
|
||||
var found = false
|
||||
var minAutoremoveOrClearTimeout: Int32? {
|
||||
var timeout: Int32?
|
||||
for attribute in self.attributes {
|
||||
if let attribute = attribute as? AutoremoveTimeoutMessageAttribute {
|
||||
if attribute.timeout > 1 * 60 {
|
||||
return false
|
||||
if let timeoutValue = timeout {
|
||||
timeout = min(timeoutValue, attribute.timeout)
|
||||
} else {
|
||||
timeout = attribute.timeout
|
||||
}
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return timeout
|
||||
}
|
||||
|
||||
var containsSecretMedia: Bool {
|
||||
guard let timeout = self.minAutoremoveOrClearTimeout else {
|
||||
return false
|
||||
}
|
||||
if timeout > 1 * 60 {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -86,11 +82,7 @@ public extension Message {
|
||||
}
|
||||
|
||||
var isSelfExpiring: Bool {
|
||||
for attribute in self.attributes {
|
||||
if let _ = attribute as? AutoremoveTimeoutMessageAttribute {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return self.minAutoremoveOrClearTimeout != nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -324,36 +324,55 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
|
||||
|
||||
switch message {
|
||||
case let .message(text, requestedAttributes, mediaReference, replyToMessageId, localGroupingKey):
|
||||
var peerAutoremoveTimeout: Int32?
|
||||
if let peer = peer as? TelegramSecretChat {
|
||||
var isAction = false
|
||||
if let _ = mediaReference?.media as? TelegramMediaAction {
|
||||
isAction = true
|
||||
}
|
||||
if !disableAutoremove, let messageAutoremoveTimeout = peer.messageAutoremoveTimeout, !isAction {
|
||||
attributes.append(AutoremoveTimeoutMessageAttribute(timeout: messageAutoremoveTimeout, countdownBeginTime: nil))
|
||||
peerAutoremoveTimeout = messageAutoremoveTimeout
|
||||
}
|
||||
} else if let cachedData = transaction.getPeerCachedData(peerId: peer.id) {
|
||||
var messageAutoremoveTimeout: Int32?
|
||||
if let cachedData = cachedData as? CachedUserData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
}
|
||||
} else if let cachedData = cachedData as? CachedGroupData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
}
|
||||
} else if let cachedData = cachedData as? CachedChannelData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
} else if let cachedData = transaction.getPeerCachedData(peerId: peer.id), !disableAutoremove {
|
||||
var isScheduled = false
|
||||
for attribute in requestedAttributes {
|
||||
if let _ = attribute as? OutgoingScheduleInfoMessageAttribute {
|
||||
isScheduled = true
|
||||
}
|
||||
}
|
||||
|
||||
if let messageAutoremoveTimeout = messageAutoremoveTimeout {
|
||||
attributes.append(AutoremoveTimeoutMessageAttribute(timeout: messageAutoremoveTimeout, countdownBeginTime: nil))
|
||||
if !isScheduled {
|
||||
var messageAutoremoveTimeout: Int32?
|
||||
if let cachedData = cachedData as? CachedUserData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
}
|
||||
} else if let cachedData = cachedData as? CachedGroupData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
}
|
||||
} else if let cachedData = cachedData as? CachedChannelData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
}
|
||||
}
|
||||
|
||||
if let messageAutoremoveTimeout = messageAutoremoveTimeout {
|
||||
peerAutoremoveTimeout = messageAutoremoveTimeout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
attributes.append(contentsOf: filterMessageAttributesForOutgoingMessage(requestedAttributes))
|
||||
for attribute in filterMessageAttributesForOutgoingMessage(requestedAttributes) {
|
||||
if let _ = attribute as? AutoremoveTimeoutMessageAttribute {
|
||||
peerAutoremoveTimeout = nil
|
||||
}
|
||||
attributes.append(attribute)
|
||||
}
|
||||
|
||||
if let peerAutoremoveTimeout = peerAutoremoveTimeout {
|
||||
attributes.append(AutoremoveTimeoutMessageAttribute(timeout: peerAutoremoveTimeout, countdownBeginTime: nil))
|
||||
}
|
||||
|
||||
if let replyToMessageId = replyToMessageId, replyToMessageId.peerId == peerId {
|
||||
var threadMessageId: MessageId?
|
||||
@ -470,7 +489,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
|
||||
}
|
||||
|
||||
storeMessages.append(StoreMessage(peerId: peerId, namespace: messageNamespace, globallyUniqueId: randomId, groupingKey: localGroupingKey, threadId: threadId, timestamp: effectiveTimestamp, flags: flags, tags: tags, globalTags: globalTags, localTags: localTags, forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: mediaList))
|
||||
case let .forward(source, grouping, requestedAttributes):
|
||||
case let .forward(source, grouping, requestedAttributes):
|
||||
let sourceMessage = transaction.getMessage(source)
|
||||
if let sourceMessage = sourceMessage, let author = sourceMessage.author ?? sourceMessage.peers[sourceMessage.id.peerId] {
|
||||
if let peer = peer as? TelegramSecretChat {
|
||||
@ -483,6 +502,35 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
|
||||
if !disableAutoremove, let messageAutoremoveTimeout = peer.messageAutoremoveTimeout, !isAction {
|
||||
attributes.append(AutoremoveTimeoutMessageAttribute(timeout: messageAutoremoveTimeout, countdownBeginTime: nil))
|
||||
}
|
||||
} else if let cachedData = transaction.getPeerCachedData(peerId: peer.id), !disableAutoremove {
|
||||
var isScheduled = false
|
||||
for attribute in attributes {
|
||||
if let _ = attribute as? OutgoingScheduleInfoMessageAttribute {
|
||||
isScheduled = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !isScheduled {
|
||||
var messageAutoremoveTimeout: Int32?
|
||||
if let cachedData = cachedData as? CachedUserData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
}
|
||||
} else if let cachedData = cachedData as? CachedGroupData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
}
|
||||
} else if let cachedData = cachedData as? CachedChannelData {
|
||||
if case let .known(value) = cachedData.autoremoveTimeout {
|
||||
messageAutoremoveTimeout = value?.effectiveValue
|
||||
}
|
||||
}
|
||||
|
||||
if let messageAutoremoveTimeout = messageAutoremoveTimeout {
|
||||
attributes.append(AutoremoveTimeoutMessageAttribute(timeout: messageAutoremoveTimeout, countdownBeginTime: nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var forwardInfo: StoreMessageForwardInfo?
|
||||
|
@ -76,14 +76,13 @@ func managedAutoremoveMessageOperations(network: Network, postbox: Postbox) -> S
|
||||
|> suspendAwareDelay(max(0.0, Double(entry.timestamp) - timestamp), queue: Queue.concurrentDefaultQueue())
|
||||
|> then(postbox.transaction { transaction -> Void in
|
||||
if let message = transaction.getMessage(entry.messageId) {
|
||||
var action: AutoremoveTimeoutMessageAttribute.Action = .remove
|
||||
for attribute in message.attributes {
|
||||
if let attribute = attribute as? AutoremoveTimeoutMessageAttribute {
|
||||
action = attribute.action
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if message.id.peerId.namespace == Namespaces.Peer.SecretChat || action == .remove {
|
||||
if message.id.peerId.namespace == Namespaces.Peer.SecretChat || true {
|
||||
deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [entry.messageId])
|
||||
} else {
|
||||
transaction.updateMessage(message.id, update: { currentMessage in
|
||||
|
@ -5585,7 +5585,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
if let tooltipController = strongSelf.silentPostTooltipController {
|
||||
tooltipController.updateContent(.text(text), animated: true, extendTimer: true)
|
||||
} else {
|
||||
let tooltipController = TooltipController(content: .text(text), baseFontSize: strongSelf.presentationData.listsFontSize.baseDisplaySize)
|
||||
let tooltipController = TooltipController(content: .text(text), baseFontSize: strongSelf.presentationData.listsFontSize.baseDisplaySize, timeout: 4.0)
|
||||
strongSelf.silentPostTooltipController = tooltipController
|
||||
tooltipController.dismissed = { [weak tooltipController] _ in
|
||||
if let strongSelf = self, let tooltipController = tooltipController, strongSelf.silentPostTooltipController === tooltipController {
|
||||
@ -7737,9 +7737,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
var currentAutoremoveTimeout: Int32? = self.presentationInterfaceState.autoremoveTimeout
|
||||
var canSetupAutoremoveTimeout = false
|
||||
|
||||
if let secretChat = peer as? TelegramSecretChat {
|
||||
currentAutoremoveTimeout = secretChat.messageAutoremoveTimeout
|
||||
canSetupAutoremoveTimeout = true
|
||||
if let _ = peer as? TelegramSecretChat {
|
||||
} else if let group = peer as? TelegramGroup {
|
||||
if case .creator = group.role {
|
||||
canSetupAutoremoveTimeout = true
|
||||
|
@ -255,8 +255,11 @@ func inputTextPanelStateForChatPresentationInterfaceState(_ chatPresentationInte
|
||||
}
|
||||
|
||||
if canSetupAutoremoveTimeout {
|
||||
if currentAutoremoveTimeout != nil || chatPresentationInterfaceState.renderedPeer?.peer is TelegramSecretChat {
|
||||
accessoryItems.append(.messageAutoremoveTimeout(currentAutoremoveTimeout))
|
||||
if case .scheduledMessages = chatPresentationInterfaceState.subject {
|
||||
} else {
|
||||
if currentAutoremoveTimeout != nil || chatPresentationInterfaceState.renderedPeer?.peer is TelegramSecretChat {
|
||||
accessoryItems.append(.messageAutoremoveTimeout(currentAutoremoveTimeout))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,10 +282,13 @@ func inputTextPanelStateForChatPresentationInterfaceState(_ chatPresentationInte
|
||||
}
|
||||
}
|
||||
if !extendedSearchLayout {
|
||||
if let peer = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramSecretChat {
|
||||
accessoryItems.append(.messageAutoremoveTimeout(peer.messageAutoremoveTimeout))
|
||||
} else if currentAutoremoveTimeout != nil && chatPresentationInterfaceState.interfaceState.composeInputState.inputText.length == 0 {
|
||||
accessoryItems.append(.messageAutoremoveTimeout(currentAutoremoveTimeout))
|
||||
if case .scheduledMessages = chatPresentationInterfaceState.subject {
|
||||
} else {
|
||||
if let peer = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramSecretChat {
|
||||
accessoryItems.append(.messageAutoremoveTimeout(peer.messageAutoremoveTimeout))
|
||||
} else if currentAutoremoveTimeout != nil && chatPresentationInterfaceState.interfaceState.composeInputState.inputText.length == 0 {
|
||||
accessoryItems.append(.messageAutoremoveTimeout(currentAutoremoveTimeout))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user