mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-04 18:41:00 +00:00
Fix report and leave
This commit is contained in:
parent
8190c2eb22
commit
b313383e5e
@ -881,7 +881,7 @@ public func channelInfoController(context: AccountContext, peerId: PeerId) -> Vi
|
|||||||
}, reportChannel: {
|
}, reportChannel: {
|
||||||
presentControllerImpl?(peerReportOptionsController(context: context, subject: .peer(peerId), present: { c, a in
|
presentControllerImpl?(peerReportOptionsController(context: context, subject: .peer(peerId), present: { c, a in
|
||||||
presentControllerImpl?(c, a)
|
presentControllerImpl?(c, a)
|
||||||
}), nil)
|
}, completion: { _ in }), nil)
|
||||||
}, leaveChannel: {
|
}, leaveChannel: {
|
||||||
let _ = (context.account.postbox.transaction { transaction -> Peer? in
|
let _ = (context.account.postbox.transaction { transaction -> Peer? in
|
||||||
return transaction.getPeer(peerId)
|
return transaction.getPeer(peerId)
|
||||||
|
@ -2618,14 +2618,14 @@ public final class ChatController: TelegramBaseController, GalleryHiddenMediaTar
|
|||||||
if let strongSelf = self, let messageIds = strongSelf.presentationInterfaceState.interfaceState.selectionState?.selectedIds, !messageIds.isEmpty {
|
if let strongSelf = self, let messageIds = strongSelf.presentationInterfaceState.interfaceState.selectionState?.selectedIds, !messageIds.isEmpty {
|
||||||
strongSelf.present(peerReportOptionsController(context: strongSelf.context, subject: .messages(Array(messageIds).sorted()), present: { c, a in
|
strongSelf.present(peerReportOptionsController(context: strongSelf.context, subject: .messages(Array(messageIds).sorted()), present: { c, a in
|
||||||
self?.present(c, in: .window(.root), with: a)
|
self?.present(c, in: .window(.root), with: a)
|
||||||
}), in: .window(.root))
|
}, completion: { _ in }), in: .window(.root))
|
||||||
}
|
}
|
||||||
}, reportMessages: { [weak self] messages in
|
}, reportMessages: { [weak self] messages in
|
||||||
if let strongSelf = self, !messages.isEmpty {
|
if let strongSelf = self, !messages.isEmpty {
|
||||||
strongSelf.chatDisplayNode.dismissInput()
|
strongSelf.chatDisplayNode.dismissInput()
|
||||||
strongSelf.present(peerReportOptionsController(context: strongSelf.context, subject: .messages(messages.map({ $0.id }).sorted()), present: { c, a in
|
strongSelf.present(peerReportOptionsController(context: strongSelf.context, subject: .messages(messages.map({ $0.id }).sorted()), present: { c, a in
|
||||||
self?.present(c, in: .window(.root), with: a)
|
self?.present(c, in: .window(.root), with: a)
|
||||||
}), in: .window(.root))
|
}, completion: { _ in }), in: .window(.root))
|
||||||
}
|
}
|
||||||
}, deleteMessages: { [weak self] messages, contextController, completion in
|
}, deleteMessages: { [weak self] messages, contextController, completion in
|
||||||
if let strongSelf = self, !messages.isEmpty {
|
if let strongSelf = self, !messages.isEmpty {
|
||||||
@ -6087,6 +6087,12 @@ public final class ChatController: TelegramBaseController, GalleryHiddenMediaTar
|
|||||||
if let peer = peer as? TelegramChannel, let username = peer.username, !username.isEmpty {
|
if let peer = peer as? TelegramChannel, let username = peer.username, !username.isEmpty {
|
||||||
self.present(peerReportOptionsController(context: self.context, subject: .peer(peer.id), present: { [weak self] c, a in
|
self.present(peerReportOptionsController(context: self.context, subject: .peer(peer.id), present: { [weak self] c, a in
|
||||||
self?.present(c, in: .window(.root))
|
self?.present(c, in: .window(.root))
|
||||||
|
}, completion: { [weak self] success in
|
||||||
|
guard let strongSelf = self, success else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let _ = removePeerChat(account: strongSelf.context.account, peerId: chatPeer.id, reportChatSpam: false).start()
|
||||||
|
(strongSelf.navigationController as? NavigationController)?.filterController(strongSelf, animated: true)
|
||||||
}), in: .window(.root))
|
}), in: .window(.root))
|
||||||
} else if let _ = peer as? TelegramUser {
|
} else if let _ = peer as? TelegramUser {
|
||||||
let presentationData = self.presentationData
|
let presentationData = self.presentationData
|
||||||
|
@ -294,7 +294,7 @@ public class PeerMediaCollectionController: TelegramBaseController {
|
|||||||
if let strongSelf = self, let messageIds = strongSelf.interfaceState.selectionState?.selectedIds, !messageIds.isEmpty {
|
if let strongSelf = self, let messageIds = strongSelf.interfaceState.selectionState?.selectedIds, !messageIds.isEmpty {
|
||||||
strongSelf.present(peerReportOptionsController(context: strongSelf.context, subject: .messages(Array(messageIds).sorted()), present: { c, a in
|
strongSelf.present(peerReportOptionsController(context: strongSelf.context, subject: .messages(Array(messageIds).sorted()), present: { c, a in
|
||||||
self?.present(c, in: .window(.root), with: a)
|
self?.present(c, in: .window(.root), with: a)
|
||||||
}), in: .window(.root))
|
}, completion: { _ in }), in: .window(.root))
|
||||||
}
|
}
|
||||||
}, reportMessages: { _ in
|
}, reportMessages: { _ in
|
||||||
}, deleteMessages: { _, _, f in
|
}, deleteMessages: { _, _, f in
|
||||||
|
@ -22,7 +22,7 @@ private enum PeerReportOption {
|
|||||||
case other
|
case other
|
||||||
}
|
}
|
||||||
|
|
||||||
func peerReportOptionsController(context: AccountContext, subject: PeerReportSubject, present: @escaping (ViewController, Any?) -> Void) -> ViewController {
|
func peerReportOptionsController(context: AccountContext, subject: PeerReportSubject, present: @escaping (ViewController, Any?) -> Void, completion: @escaping (Bool) -> Void) -> ViewController {
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
let controller = ActionSheetController(theme: ActionSheetControllerTheme(presentationTheme: presentationData.theme))
|
let controller = ActionSheetController(theme: ActionSheetControllerTheme(presentationTheme: presentationData.theme))
|
||||||
|
|
||||||
@ -75,15 +75,17 @@ func peerReportOptionsController(context: AccountContext, subject: PeerReportSub
|
|||||||
let _ = (reportPeer(account: context.account, peerId: peerId, reason: reportReason)
|
let _ = (reportPeer(account: context.account, peerId: peerId, reason: reportReason)
|
||||||
|> deliverOnMainQueue).start(completed: {
|
|> deliverOnMainQueue).start(completed: {
|
||||||
present(textAlertController(context: context, title: nil, text: presentationData.strings.ReportPeer_AlertSuccess, actions: [TextAlertAction(type: TextAlertActionType.defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
present(textAlertController(context: context, title: nil, text: presentationData.strings.ReportPeer_AlertSuccess, actions: [TextAlertAction(type: TextAlertActionType.defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||||
|
completion(true)
|
||||||
})
|
})
|
||||||
case let .messages(messageIds):
|
case let .messages(messageIds):
|
||||||
let _ = (reportPeerMessages(account: context.account, messageIds: messageIds, reason: reportReason)
|
let _ = (reportPeerMessages(account: context.account, messageIds: messageIds, reason: reportReason)
|
||||||
|> deliverOnMainQueue).start(completed: {
|
|> deliverOnMainQueue).start(completed: {
|
||||||
present(textAlertController(context: context, title: nil, text: presentationData.strings.ReportPeer_AlertSuccess, actions: [TextAlertAction.init(type: TextAlertActionType.defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
present(textAlertController(context: context, title: nil, text: presentationData.strings.ReportPeer_AlertSuccess, actions: [TextAlertAction.init(type: TextAlertActionType.defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||||
|
completion(true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
controller?.present(peerReportController(context: context, subject: subject), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
controller?.present(peerReportController(context: context, subject: subject, completion: completion), in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||||
}
|
}
|
||||||
|
|
||||||
controller?.dismissAnimated()
|
controller?.dismissAnimated()
|
||||||
@ -95,6 +97,7 @@ func peerReportOptionsController(context: AccountContext, subject: PeerReportSub
|
|||||||
ActionSheetItemGroup(items: [
|
ActionSheetItemGroup(items: [
|
||||||
ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { [weak controller] in
|
ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { [weak controller] in
|
||||||
controller?.dismissAnimated()
|
controller?.dismissAnimated()
|
||||||
|
completion(false)
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
@ -187,7 +190,7 @@ private func peerReportControllerEntries(presentationData: PresentationData, sta
|
|||||||
return entries
|
return entries
|
||||||
}
|
}
|
||||||
|
|
||||||
private func peerReportController(context: AccountContext, subject: PeerReportSubject) -> ViewController {
|
private func peerReportController(context: AccountContext, subject: PeerReportSubject, completion: @escaping (Bool) -> Void) -> ViewController {
|
||||||
var dismissImpl: (() -> Void)?
|
var dismissImpl: (() -> Void)?
|
||||||
var presentControllerImpl: ((ViewController, ViewControllerPresentationArguments?) -> Void)?
|
var presentControllerImpl: ((ViewController, ViewControllerPresentationArguments?) -> Void)?
|
||||||
|
|
||||||
@ -208,50 +211,52 @@ private func peerReportController(context: AccountContext, subject: PeerReportSu
|
|||||||
let reportDisposable = MetaDisposable()
|
let reportDisposable = MetaDisposable()
|
||||||
|
|
||||||
let signal = combineLatest(context.sharedContext.presentationData, statePromise.get())
|
let signal = combineLatest(context.sharedContext.presentationData, statePromise.get())
|
||||||
|> map { presentationData, state -> (ItemListControllerState, (ItemListNodeState<PeerReportControllerEntry>, PeerReportControllerEntry.ItemGenerationArguments)) in
|
|> map { presentationData, state -> (ItemListControllerState, (ItemListNodeState<PeerReportControllerEntry>, PeerReportControllerEntry.ItemGenerationArguments)) in
|
||||||
let rightButton: ItemListNavigationButton
|
let rightButton: ItemListNavigationButton
|
||||||
if state.isReporting {
|
if state.isReporting {
|
||||||
rightButton = ItemListNavigationButton(content: .none, style: .activity, enabled: true, action: {})
|
rightButton = ItemListNavigationButton(content: .none, style: .activity, enabled: true, action: {})
|
||||||
} else {
|
} else {
|
||||||
rightButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: .bold, enabled: !state.text.isEmpty, action: {
|
rightButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: .bold, enabled: !state.text.isEmpty, action: {
|
||||||
var text: String = ""
|
var text: String = ""
|
||||||
updateState { state in
|
updateState { state in
|
||||||
var state = state
|
var state = state
|
||||||
if !state.isReporting && !state.text.isEmpty {
|
if !state.isReporting && !state.text.isEmpty {
|
||||||
text = state.text
|
text = state.text
|
||||||
state.isReporting = true
|
state.isReporting = true
|
||||||
}
|
|
||||||
return state
|
|
||||||
}
|
}
|
||||||
|
return state
|
||||||
if !text.isEmpty {
|
}
|
||||||
let completed: () -> Void = {
|
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
if !text.isEmpty {
|
||||||
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.ReportPeer_AlertSuccess, actions: [TextAlertAction.init(type: TextAlertActionType.defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
let completed: () -> Void = {
|
||||||
dismissImpl?()
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
}
|
presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.ReportPeer_AlertSuccess, actions: [TextAlertAction.init(type: TextAlertActionType.defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||||
switch subject {
|
completion(true)
|
||||||
case let .peer(peerId):
|
dismissImpl?()
|
||||||
reportDisposable.set((reportPeer(account: context.account, peerId: peerId, reason: .custom(text))
|
|
||||||
|> deliverOnMainQueue).start(completed: {
|
|
||||||
completed()
|
|
||||||
}))
|
|
||||||
case let .messages(messageIds):
|
|
||||||
reportDisposable.set((reportPeerMessages(account: context.account, messageIds: messageIds, reason: .custom(text))
|
|
||||||
|> deliverOnMainQueue).start(completed: {
|
|
||||||
completed()
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
switch subject {
|
||||||
}
|
case let .peer(peerId):
|
||||||
|
reportDisposable.set((reportPeer(account: context.account, peerId: peerId, reason: .custom(text))
|
||||||
let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(presentationData.strings.ReportPeer_ReasonOther_Title), leftNavigationButton: ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: {
|
|> deliverOnMainQueue).start(completed: {
|
||||||
dismissImpl?()
|
completed()
|
||||||
}), rightNavigationButton: rightButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
|
}))
|
||||||
let listState = ItemListNodeState(entries: peerReportControllerEntries(presentationData: presentationData, state: state), style: .blocks, focusItemTag: PeerReportControllerEntryTag.text)
|
case let .messages(messageIds):
|
||||||
|
reportDisposable.set((reportPeerMessages(account: context.account, messageIds: messageIds, reason: .custom(text))
|
||||||
return (controllerState, (listState, arguments))
|
|> deliverOnMainQueue).start(completed: {
|
||||||
|
completed()
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(presentationData.strings.ReportPeer_ReasonOther_Title), leftNavigationButton: ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: {
|
||||||
|
dismissImpl?()
|
||||||
|
completion(false)
|
||||||
|
}), rightNavigationButton: rightButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
|
||||||
|
let listState = ItemListNodeState(entries: peerReportControllerEntries(presentationData: presentationData, state: state), style: .blocks, focusItemTag: PeerReportControllerEntryTag.text)
|
||||||
|
|
||||||
|
return (controllerState, (listState, arguments))
|
||||||
}
|
}
|
||||||
|> afterDisposed {
|
|> afterDisposed {
|
||||||
reportDisposable.dispose()
|
reportDisposable.dispose()
|
||||||
|
@ -1164,7 +1164,7 @@ public func userInfoController(context: AccountContext, peerId: PeerId, mode: Us
|
|||||||
}, report: {
|
}, report: {
|
||||||
presentControllerImpl?(peerReportOptionsController(context: context, subject: .peer(peerId), present: { c, a in
|
presentControllerImpl?(peerReportOptionsController(context: context, subject: .peer(peerId), present: { c, a in
|
||||||
presentControllerImpl?(c, a)
|
presentControllerImpl?(c, a)
|
||||||
}), nil)
|
}, completion: { _ in }), nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
let deviceContacts: Signal<[(DeviceContactStableId, DeviceContactBasicData)], NoError> = peerView.get()
|
let deviceContacts: Signal<[(DeviceContactStableId, DeviceContactBasicData)], NoError> = peerView.get()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user