Moved api for report messages to separated file.
This commit is contained in:
		
							parent
							
								
									eef1da56c8
								
							
						
					
					
						commit
						6dce8dfa20
					
				
					 6 changed files with 101 additions and 55 deletions
				
			
		| 
						 | 
					@ -137,6 +137,8 @@ PRIVATE
 | 
				
			||||||
    api/api_peer_photo.h
 | 
					    api/api_peer_photo.h
 | 
				
			||||||
    api/api_polls.cpp
 | 
					    api/api_polls.cpp
 | 
				
			||||||
    api/api_polls.h
 | 
					    api/api_polls.h
 | 
				
			||||||
 | 
					    api/api_report.cpp
 | 
				
			||||||
 | 
					    api/api_report.h
 | 
				
			||||||
    api/api_ringtones.cpp
 | 
					    api/api_ringtones.cpp
 | 
				
			||||||
    api/api_ringtones.h
 | 
					    api/api_ringtones.h
 | 
				
			||||||
    api/api_self_destruct.cpp
 | 
					    api/api_self_destruct.cpp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										70
									
								
								Telegram/SourceFiles/api/api_report.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								Telegram/SourceFiles/api/api_report.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,70 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					This file is part of Telegram Desktop,
 | 
				
			||||||
 | 
					the official desktop application for the Telegram messaging service.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For license and copyright information please follow this link:
 | 
				
			||||||
 | 
					https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					#include "api/api_report.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "apiwrap.h"
 | 
				
			||||||
 | 
					#include "data/data_peer.h"
 | 
				
			||||||
 | 
					#include "lang/lang_keys.h"
 | 
				
			||||||
 | 
					#include "main/main_session.h"
 | 
				
			||||||
 | 
					#include "ui/boxes/report_box.h"
 | 
				
			||||||
 | 
					#include "ui/toast/toast.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Api {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					MTPreportReason ReasonToTL(const Ui::ReportReason &reason) {
 | 
				
			||||||
 | 
						using Reason = Ui::ReportReason;
 | 
				
			||||||
 | 
						switch (reason) {
 | 
				
			||||||
 | 
						case Reason::Spam: return MTP_inputReportReasonSpam();
 | 
				
			||||||
 | 
						case Reason::Fake: return MTP_inputReportReasonFake();
 | 
				
			||||||
 | 
						case Reason::Violence: return MTP_inputReportReasonViolence();
 | 
				
			||||||
 | 
						case Reason::ChildAbuse: return MTP_inputReportReasonChildAbuse();
 | 
				
			||||||
 | 
						case Reason::Pornography: return MTP_inputReportReasonPornography();
 | 
				
			||||||
 | 
						case Reason::Copyright: return MTP_inputReportReasonCopyright();
 | 
				
			||||||
 | 
						case Reason::IllegalDrugs: return MTP_inputReportReasonIllegalDrugs();
 | 
				
			||||||
 | 
						case Reason::PersonalDetails:
 | 
				
			||||||
 | 
							return MTP_inputReportReasonPersonalDetails();
 | 
				
			||||||
 | 
						case Reason::Other: return MTP_inputReportReasonOther();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						Unexpected("Bad reason group value.");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SendReport(
 | 
				
			||||||
 | 
							not_null<PeerData*> peer,
 | 
				
			||||||
 | 
							Ui::ReportReason reason,
 | 
				
			||||||
 | 
							const QString &comment,
 | 
				
			||||||
 | 
							MessageIdsList ids) {
 | 
				
			||||||
 | 
						if (ids.empty()) {
 | 
				
			||||||
 | 
							peer->session().api().request(MTPaccount_ReportPeer(
 | 
				
			||||||
 | 
								peer->input,
 | 
				
			||||||
 | 
								ReasonToTL(reason),
 | 
				
			||||||
 | 
								MTP_string(comment)
 | 
				
			||||||
 | 
							)).done([=] {
 | 
				
			||||||
 | 
								Ui::Toast::Show(tr::lng_report_thanks(tr::now));
 | 
				
			||||||
 | 
							}).send();
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							auto apiIds = QVector<MTPint>();
 | 
				
			||||||
 | 
							apiIds.reserve(ids.size());
 | 
				
			||||||
 | 
							for (const auto &fullId : ids) {
 | 
				
			||||||
 | 
								apiIds.push_back(MTP_int(fullId.msg));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							peer->session().api().request(MTPmessages_Report(
 | 
				
			||||||
 | 
								peer->input,
 | 
				
			||||||
 | 
								MTP_vector<MTPint>(apiIds),
 | 
				
			||||||
 | 
								ReasonToTL(reason),
 | 
				
			||||||
 | 
								MTP_string(comment)
 | 
				
			||||||
 | 
							)).done([=] {
 | 
				
			||||||
 | 
								Ui::Toast::Show(tr::lng_report_thanks(tr::now));
 | 
				
			||||||
 | 
							}).send();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Api
 | 
				
			||||||
							
								
								
									
										24
									
								
								Telegram/SourceFiles/api/api_report.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Telegram/SourceFiles/api/api_report.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					This file is part of Telegram Desktop,
 | 
				
			||||||
 | 
					the official desktop application for the Telegram messaging service.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For license and copyright information please follow this link:
 | 
				
			||||||
 | 
					https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PeerData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Ui {
 | 
				
			||||||
 | 
					enum class ReportReason;
 | 
				
			||||||
 | 
					} // namespace Ui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Api {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SendReport(
 | 
				
			||||||
 | 
						not_null<PeerData*> peer,
 | 
				
			||||||
 | 
						Ui::ReportReason reason,
 | 
				
			||||||
 | 
						const QString &comment,
 | 
				
			||||||
 | 
						MessageIdsList ids = {});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} // namespace Api
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "api/api_editing.h"
 | 
					#include "api/api_editing.h"
 | 
				
			||||||
#include "api/api_bot.h"
 | 
					#include "api/api_bot.h"
 | 
				
			||||||
#include "api/api_chat_participants.h"
 | 
					#include "api/api_chat_participants.h"
 | 
				
			||||||
 | 
					#include "api/api_report.h"
 | 
				
			||||||
#include "api/api_sending.h"
 | 
					#include "api/api_sending.h"
 | 
				
			||||||
#include "api/api_text_entities.h"
 | 
					#include "api/api_text_entities.h"
 | 
				
			||||||
#include "api/api_send_progress.h"
 | 
					#include "api/api_send_progress.h"
 | 
				
			||||||
| 
						 | 
					@ -3884,7 +3885,7 @@ void HistoryWidget::reportSelectedMessages() {
 | 
				
			||||||
				clearSelected();
 | 
									clearSelected();
 | 
				
			||||||
				controller()->clearChooseReportMessages();
 | 
									controller()->clearChooseReportMessages();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			HistoryView::SendReport(peer, reason, text, ids);
 | 
								Api::SendReport(peer, reason, text, ids);
 | 
				
			||||||
			box->closeBox();
 | 
								box->closeBox();
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}));
 | 
						}));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "api/api_attached_stickers.h"
 | 
					#include "api/api_attached_stickers.h"
 | 
				
			||||||
#include "api/api_editing.h"
 | 
					#include "api/api_editing.h"
 | 
				
			||||||
#include "api/api_polls.h"
 | 
					#include "api/api_polls.h"
 | 
				
			||||||
 | 
					#include "api/api_report.h"
 | 
				
			||||||
#include "api/api_ringtones.h"
 | 
					#include "api/api_ringtones.h"
 | 
				
			||||||
#include "api/api_who_reacted.h"
 | 
					#include "api/api_who_reacted.h"
 | 
				
			||||||
#include "api/api_toggling_media.h" // Api::ToggleFavedSticker
 | 
					#include "api/api_toggling_media.h" // Api::ToggleFavedSticker
 | 
				
			||||||
| 
						 | 
					@ -1207,7 +1208,7 @@ void ShowWhoReactedMenu(
 | 
				
			||||||
void ShowReportItemsBox(not_null<PeerData*> peer, MessageIdsList ids) {
 | 
					void ShowReportItemsBox(not_null<PeerData*> peer, MessageIdsList ids) {
 | 
				
			||||||
	const auto chosen = [=](Ui::ReportReason reason) {
 | 
						const auto chosen = [=](Ui::ReportReason reason) {
 | 
				
			||||||
		Ui::show(Box(Ui::ReportDetailsBox, [=](const QString &text) {
 | 
							Ui::show(Box(Ui::ReportDetailsBox, [=](const QString &text) {
 | 
				
			||||||
			SendReport(peer, reason, text, ids);
 | 
								Api::SendReport(peer, reason, text, ids);
 | 
				
			||||||
			Ui::hideLayer();
 | 
								Ui::hideLayer();
 | 
				
			||||||
		}));
 | 
							}));
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
| 
						 | 
					@ -1229,7 +1230,7 @@ void ShowReportPeerBox(
 | 
				
			||||||
	const auto chosen = [=](Ui::ReportReason reason) {
 | 
						const auto chosen = [=](Ui::ReportReason reason) {
 | 
				
			||||||
		const auto send = [=](const QString &text) {
 | 
							const auto send = [=](const QString &text) {
 | 
				
			||||||
			window->clearChooseReportMessages();
 | 
								window->clearChooseReportMessages();
 | 
				
			||||||
			SendReport(peer, reason, text, std::move(state->ids));
 | 
								Api::SendReport(peer, reason, text, std::move(state->ids));
 | 
				
			||||||
			if (const auto strong = state->reasonBox.data()) {
 | 
								if (const auto strong = state->reasonBox.data()) {
 | 
				
			||||||
				strong->closeBox();
 | 
									strong->closeBox();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -1261,51 +1262,4 @@ void ShowReportPeerBox(
 | 
				
			||||||
		chosen));
 | 
							chosen));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SendReport(
 | 
					 | 
				
			||||||
		not_null<PeerData*> peer,
 | 
					 | 
				
			||||||
		Ui::ReportReason reason,
 | 
					 | 
				
			||||||
		const QString &comment,
 | 
					 | 
				
			||||||
		MessageIdsList ids) {
 | 
					 | 
				
			||||||
	const auto apiReason = [&] {
 | 
					 | 
				
			||||||
		using Reason = Ui::ReportReason;
 | 
					 | 
				
			||||||
		switch (reason) {
 | 
					 | 
				
			||||||
		case Reason::Spam: return MTP_inputReportReasonSpam();
 | 
					 | 
				
			||||||
		case Reason::Fake: return MTP_inputReportReasonFake();
 | 
					 | 
				
			||||||
		case Reason::Violence: return MTP_inputReportReasonViolence();
 | 
					 | 
				
			||||||
		case Reason::ChildAbuse: return MTP_inputReportReasonChildAbuse();
 | 
					 | 
				
			||||||
		case Reason::Pornography: return MTP_inputReportReasonPornography();
 | 
					 | 
				
			||||||
		case Reason::Copyright: return MTP_inputReportReasonCopyright();
 | 
					 | 
				
			||||||
		case Reason::IllegalDrugs:
 | 
					 | 
				
			||||||
			return MTP_inputReportReasonIllegalDrugs();
 | 
					 | 
				
			||||||
		case Reason::PersonalDetails:
 | 
					 | 
				
			||||||
			return MTP_inputReportReasonPersonalDetails();
 | 
					 | 
				
			||||||
		case Reason::Other: return MTP_inputReportReasonOther();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		Unexpected("Bad reason group value.");
 | 
					 | 
				
			||||||
	}();
 | 
					 | 
				
			||||||
	if (ids.empty()) {
 | 
					 | 
				
			||||||
		peer->session().api().request(MTPaccount_ReportPeer(
 | 
					 | 
				
			||||||
			peer->input,
 | 
					 | 
				
			||||||
			apiReason,
 | 
					 | 
				
			||||||
			MTP_string(comment)
 | 
					 | 
				
			||||||
		)).done([=] {
 | 
					 | 
				
			||||||
			Ui::Toast::Show(tr::lng_report_thanks(tr::now));
 | 
					 | 
				
			||||||
		}).send();
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		auto apiIds = QVector<MTPint>();
 | 
					 | 
				
			||||||
		apiIds.reserve(ids.size());
 | 
					 | 
				
			||||||
		for (const auto &fullId : ids) {
 | 
					 | 
				
			||||||
			apiIds.push_back(MTP_int(fullId.msg));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		peer->session().api().request(MTPmessages_Report(
 | 
					 | 
				
			||||||
			peer->input,
 | 
					 | 
				
			||||||
			MTP_vector<MTPint>(apiIds),
 | 
					 | 
				
			||||||
			apiReason,
 | 
					 | 
				
			||||||
			MTP_string(comment)
 | 
					 | 
				
			||||||
		)).done([=] {
 | 
					 | 
				
			||||||
			Ui::Toast::Show(tr::lng_report_thanks(tr::now));
 | 
					 | 
				
			||||||
		}).send();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
} // namespace HistoryView
 | 
					} // namespace HistoryView
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,10 +83,5 @@ void ShowReportItemsBox(not_null<PeerData*> peer, MessageIdsList ids);
 | 
				
			||||||
void ShowReportPeerBox(
 | 
					void ShowReportPeerBox(
 | 
				
			||||||
	not_null<Window::SessionController*> window,
 | 
						not_null<Window::SessionController*> window,
 | 
				
			||||||
	not_null<PeerData*> peer);
 | 
						not_null<PeerData*> peer);
 | 
				
			||||||
void SendReport(
 | 
					 | 
				
			||||||
	not_null<PeerData*> peer,
 | 
					 | 
				
			||||||
	Ui::ReportReason reason,
 | 
					 | 
				
			||||||
	const QString &comment,
 | 
					 | 
				
			||||||
	MessageIdsList ids = {});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace HistoryView
 | 
					} // namespace HistoryView
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue