From 44ff4fe4202f373a18c56ab4518246028dfa7e65 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 12 Mar 2017 19:01:07 +0300 Subject: [PATCH] no message --- .../CloudChatRemoveMessagesOperation.swift | 10 +++-- TelegramCore/ContactManagement.swift | 23 ++++++++++ ...gedCloudChatRemoveMessagesOperations.swift | 44 ++++++++++++++++--- TelegramCore/RemovePeerChat.swift | 4 +- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/TelegramCore/CloudChatRemoveMessagesOperation.swift b/TelegramCore/CloudChatRemoveMessagesOperation.swift index 5b2ae679fd..bd9605690d 100644 --- a/TelegramCore/CloudChatRemoveMessagesOperation.swift +++ b/TelegramCore/CloudChatRemoveMessagesOperation.swift @@ -45,17 +45,21 @@ final class CloudChatRemoveMessagesOperation: Coding { final class CloudChatRemoveChatOperation: Coding { let peerId: PeerId + let reportChatSpam: Bool - init(peerId: PeerId) { + init(peerId: PeerId, reportChatSpam: Bool) { self.peerId = peerId + self.reportChatSpam = reportChatSpam } init(decoder: Decoder) { self.peerId = PeerId(decoder.decodeInt64ForKey("p")) + self.reportChatSpam = (decoder.decodeInt32ForKey("r") as Int32) != 0 } func encode(_ encoder: Encoder) { encoder.encodeInt64(self.peerId.toInt64(), forKey: "p") + encoder.encodeInt32(self.reportChatSpam ? 1 : 0, forKey: "r") } } @@ -85,8 +89,8 @@ func cloudChatAddRemoveMessagesOperation(modifier: Modifier, peerId: PeerId, mes modifier.operationLogAddEntry(peerId: peerId, tag: OperationLogTags.CloudChatRemoveMessages, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: CloudChatRemoveMessagesOperation(messageIds: messageIds, type: type)) } -func cloudChatAddRemoveChatOperation(modifier: Modifier, peerId: PeerId) { - modifier.operationLogAddEntry(peerId: peerId, tag: OperationLogTags.CloudChatRemoveMessages, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: CloudChatRemoveChatOperation(peerId: peerId)) +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)) } func cloudChatAddClearHistoryOperation(modifier: Modifier, peerId: PeerId) { diff --git a/TelegramCore/ContactManagement.swift b/TelegramCore/ContactManagement.swift index 62dc28e76b..642c494618 100644 --- a/TelegramCore/ContactManagement.swift +++ b/TelegramCore/ContactManagement.swift @@ -90,3 +90,26 @@ func manageContacts(network: Network, postbox: Postbox) -> Signal return appliedUpdatedPeers } + +public func deleteContactPeerInteractively(account: Account, peerId: PeerId) -> Signal { + return account.postbox.modify { modifier -> Signal in + if let peer = modifier.getPeer(peerId), let inputUser = apiInputUser(peer) { + account.network.request(Api.functions.contacts.deleteContact(id: inputUser)) + |> map { Optional($0) } + |> `catch` { _ -> Signal in + return .single(nil) + } + |> mapToSignal { _ -> Signal in + return account.postbox.modify { modifier -> Void in + var peerIds = modifier.getContactPeerIds() + if peerIds.contains(peerId) { + peerIds.remove(peerId) + modifier.repaceContactPeerIds(peerIds) + } + } + } + } else { + return .complete() + } + } |> switchToLatest +} diff --git a/TelegramCore/ManagedCloudChatRemoveMessagesOperations.swift b/TelegramCore/ManagedCloudChatRemoveMessagesOperations.swift index 060ea91b4e..2b915cfec6 100644 --- a/TelegramCore/ManagedCloudChatRemoveMessagesOperations.swift +++ b/TelegramCore/ManagedCloudChatRemoveMessagesOperations.swift @@ -187,14 +187,24 @@ private func removeChat(modifier: Modifier, postbox: Postbox, network: Network, } else { signal = network.request(Api.functions.channels.leaveChannel(channel: inputChannel)) } - return signal + let reportSignal: Signal + if let inputPeer = apiInputPeer(peer), operation.reportChatSpam { + reportSignal = network.request(Api.functions.messages.reportSpam(peer: inputPeer)) + |> `catch` { _ -> Signal in + return .single(.boolFalse) + } + } else { + reportSignal = .single(.boolTrue) + } + + return combineLatest(signal |> map { result -> Api.Updates? in return result } |> `catch` { _ in return .single(nil) - } - |> mapToSignal { updates in + }, reportSignal) + |> mapToSignal { updates, _ in if let updates = updates { stateManager.addUpdates(updates) } @@ -217,18 +227,42 @@ private func removeChat(modifier: Modifier, postbox: Postbox, network: Network, } return .complete() } + let reportSignal: Signal + if let inputPeer = apiInputPeer(peer), operation.reportChatSpam { + reportSignal = network.request(Api.functions.messages.reportSpam(peer: inputPeer)) + |> mapToSignal { _ -> Signal in + return .complete() + } + |> `catch` { _ -> Signal in + return .complete() + } + } else { + reportSignal = .complete() + } let deleteMessages: Signal if let inputPeer = apiInputPeer(peer), let topMessageId = modifier.getTopPeerMessageId(peerId: peer.id, namespace: Namespaces.Message.Cloud) { deleteMessages = requestClearHistory(postbox: postbox, network: network, stateManager: stateManager, inputPeer: inputPeer, maxId: topMessageId.id, justClear: false) } else { deleteMessages = .complete() } - return deleteMessages |> then(deleteUser) |> then(postbox.modify { modifier -> Void in + return deleteMessages |> then(deleteUser) |> then(reportSignal) |> then(postbox.modify { modifier -> Void in 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) { - return requestClearHistory(postbox: postbox, network: network, stateManager: stateManager, inputPeer: inputPeer, maxId: topMessageId.id, justClear: false) |> then(postbox.modify { modifier -> Void in + let reportSignal: Signal + if let inputPeer = apiInputPeer(peer), operation.reportChatSpam { + reportSignal = network.request(Api.functions.messages.reportSpam(peer: inputPeer)) + |> mapToSignal { _ -> Signal in + return .complete() + } + |> `catch` { _ -> Signal in + return .complete() + } + } 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 modifier.clearHistory(peer.id) }) } else { diff --git a/TelegramCore/RemovePeerChat.swift b/TelegramCore/RemovePeerChat.swift index b0638f13a0..61d445f816 100644 --- a/TelegramCore/RemovePeerChat.swift +++ b/TelegramCore/RemovePeerChat.swift @@ -7,7 +7,7 @@ import Foundation import SwiftSignalKit #endif -public func removePeerChat(postbox: Postbox, peerId: PeerId) -> Signal { +public func removePeerChat(postbox: Postbox, peerId: PeerId, reportChatSpam: Bool) -> Signal { return postbox.modify { modifier -> Void in if peerId.namespace == Namespaces.Peer.SecretChat { if let state = modifier.getPeerChatState(peerId) as? SecretChatState { @@ -24,7 +24,7 @@ public func removePeerChat(postbox: Postbox, peerId: PeerId) -> Signal