no message

This commit is contained in:
Peter 2017-03-15 19:05:03 +03:00
parent 3521580e99
commit b74ce8978d
2 changed files with 20 additions and 4 deletions

View File

@ -46,20 +46,36 @@ final class CloudChatRemoveMessagesOperation: Coding {
final class CloudChatRemoveChatOperation: Coding {
let peerId: PeerId
let reportChatSpam: Bool
let topMessageId: MessageId?
init(peerId: PeerId, reportChatSpam: Bool) {
init(peerId: PeerId, reportChatSpam: Bool, topMessageId: MessageId?) {
self.peerId = peerId
self.reportChatSpam = reportChatSpam
self.topMessageId = topMessageId
}
init(decoder: Decoder) {
self.peerId = PeerId(decoder.decodeInt64ForKey("p"))
self.reportChatSpam = (decoder.decodeInt32ForKey("r") as Int32) != 0
if let messageIdPeerId = (decoder.decodeInt64ForKey("m.p") as Int64?), let messageIdNamespace = (decoder.decodeInt32ForKey("m.n") as Int32?), let messageIdId = (decoder.decodeInt32ForKey("m.i") as Int32?) {
self.topMessageId = MessageId(peerId: PeerId(messageIdPeerId), namespace: messageIdNamespace, id: messageIdId)
} else {
self.topMessageId = nil
}
}
func encode(_ encoder: Encoder) {
encoder.encodeInt64(self.peerId.toInt64(), forKey: "p")
encoder.encodeInt32(self.reportChatSpam ? 1 : 0, forKey: "r")
if let topMessageId = self.topMessageId {
encoder.encodeInt64(topMessageId.peerId.toInt64(), forKey: "m.p")
encoder.encodeInt32(topMessageId.namespace, forKey: "m.n")
encoder.encodeInt32(topMessageId.id, forKey: "m.i")
} else {
encoder.encodeNil(forKey: "m.p")
encoder.encodeNil(forKey: "m.n")
encoder.encodeNil(forKey: "m.i")
}
}
}
@ -90,7 +106,7 @@ func cloudChatAddRemoveMessagesOperation(modifier: Modifier, peerId: PeerId, mes
}
func cloudChatAddRemoveChatOperation(modifier: Modifier, peerId: PeerId, reportChatSpam: Bool) {
modifier.operationLogAddEntry(peerId: peerId, tag: OperationLogTags.CloudChatRemoveMessages, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: CloudChatRemoveChatOperation(peerId: peerId, reportChatSpam: reportChatSpam))
modifier.operationLogAddEntry(peerId: peerId, tag: OperationLogTags.CloudChatRemoveMessages, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: CloudChatRemoveChatOperation(peerId: peerId, reportChatSpam: reportChatSpam, topMessageId: modifier.getTopPeerMessageId(peerId: peerId, namespace: Namespaces.Message.Cloud)))
}
func cloudChatAddClearHistoryOperation(modifier: Modifier, peerId: PeerId) {

View File

@ -249,7 +249,7 @@ private func removeChat(modifier: Modifier, postbox: Postbox, network: Network,
modifier.clearHistory(peer.id)
})
} else if peer.id.namespace == Namespaces.Peer.CloudUser {
if let inputPeer = apiInputPeer(peer), let topMessageId = modifier.getTopPeerMessageId(peerId: peer.id, namespace: Namespaces.Message.Cloud) {
if let inputPeer = apiInputPeer(peer) {
let reportSignal: Signal<Void, NoError>
if let inputPeer = apiInputPeer(peer), operation.reportChatSpam {
reportSignal = network.request(Api.functions.messages.reportSpam(peer: inputPeer))
@ -262,7 +262,7 @@ private func removeChat(modifier: Modifier, postbox: Postbox, network: Network,
} else {
reportSignal = .complete()
}
return requestClearHistory(postbox: postbox, network: network, stateManager: stateManager, inputPeer: inputPeer, maxId: topMessageId.id, justClear: false) |> then(reportSignal) |> then(postbox.modify { modifier -> Void in
return requestClearHistory(postbox: postbox, network: network, stateManager: stateManager, inputPeer: inputPeer, maxId: operation.topMessageId?.id ?? Int32.max - 1, justClear: false) |> then(reportSignal) |> then(postbox.modify { modifier -> Void in
modifier.clearHistory(peer.id)
})
} else {