mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-28 19:05:49 +00:00
no message
This commit is contained in:
parent
e840d27434
commit
44ff4fe420
@ -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) {
|
||||
|
||||
@ -90,3 +90,26 @@ func manageContacts(network: Network, postbox: Postbox) -> Signal<Void, NoError>
|
||||
|
||||
return appliedUpdatedPeers
|
||||
}
|
||||
|
||||
public func deleteContactPeerInteractively(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
return account.postbox.modify { modifier -> Signal<Void, NoError> 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<Api.contacts.Link?, NoError> in
|
||||
return .single(nil)
|
||||
}
|
||||
|> mapToSignal { _ -> Signal<Void, NoError> 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
|
||||
}
|
||||
|
||||
@ -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<Api.Bool, NoError>
|
||||
if let inputPeer = apiInputPeer(peer), operation.reportChatSpam {
|
||||
reportSignal = network.request(Api.functions.messages.reportSpam(peer: inputPeer))
|
||||
|> `catch` { _ -> Signal<Api.Bool, NoError> 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<Void, NoError>
|
||||
if let inputPeer = apiInputPeer(peer), operation.reportChatSpam {
|
||||
reportSignal = network.request(Api.functions.messages.reportSpam(peer: inputPeer))
|
||||
|> mapToSignal { _ -> Signal<Void, MTRpcError> in
|
||||
return .complete()
|
||||
}
|
||||
|> `catch` { _ -> Signal<Void, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
} else {
|
||||
reportSignal = .complete()
|
||||
}
|
||||
let deleteMessages: Signal<Void, NoError>
|
||||
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<Void, NoError>
|
||||
if let inputPeer = apiInputPeer(peer), operation.reportChatSpam {
|
||||
reportSignal = network.request(Api.functions.messages.reportSpam(peer: inputPeer))
|
||||
|> mapToSignal { _ -> Signal<Void, MTRpcError> in
|
||||
return .complete()
|
||||
}
|
||||
|> `catch` { _ -> Signal<Void, NoError> 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 {
|
||||
|
||||
@ -7,7 +7,7 @@ import Foundation
|
||||
import SwiftSignalKit
|
||||
#endif
|
||||
|
||||
public func removePeerChat(postbox: Postbox, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
public func removePeerChat(postbox: Postbox, peerId: PeerId, reportChatSpam: Bool) -> Signal<Void, NoError> {
|
||||
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<Void, NoE
|
||||
modifier.clearHistory(peerId)
|
||||
modifier.updatePeerChatListInclusion(peerId, inclusion: .never)
|
||||
} else {
|
||||
cloudChatAddRemoveChatOperation(modifier: modifier, peerId: peerId)
|
||||
cloudChatAddRemoveChatOperation(modifier: modifier, peerId: peerId, reportChatSpam: reportChatSpam)
|
||||
if peerId.namespace == Namespaces.Peer.CloudUser {
|
||||
modifier.updatePeerChatListInclusion(peerId, inclusion: .ifHasMessages)
|
||||
modifier.clearHistory(peerId)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user