diff --git a/Telegram/SourceFiles/data/components/factchecks.cpp b/Telegram/SourceFiles/data/components/factchecks.cpp index af72d8aff9..07051dabd8 100644 --- a/Telegram/SourceFiles/data/components/factchecks.cpp +++ b/Telegram/SourceFiles/data/components/factchecks.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "main/main_app_config.h" #include "main/main_session.h" +#include "ui/layers/show.h" namespace Data { namespace { @@ -196,4 +197,20 @@ void Factchecks::save( } } +void Factchecks::save( + FullMsgId itemId, + TextWithEntities was, + TextWithEntities text, + std::shared_ptr show) { + const auto done = [=](QString error) { + show->showToast(!error.isEmpty() + ? error + : was.empty() + ? tr::lng_factcheck_remove_done(tr::now) + : text.empty() + ? tr::lng_factcheck_add_done(tr::now) + : tr::lng_factcheck_edit_done(tr::now)); + }; +} + } // namespace Data diff --git a/Telegram/SourceFiles/data/components/factchecks.h b/Telegram/SourceFiles/data/components/factchecks.h index 7054a3c571..515e52286e 100644 --- a/Telegram/SourceFiles/data/components/factchecks.h +++ b/Telegram/SourceFiles/data/components/factchecks.h @@ -21,6 +21,10 @@ namespace Main { class Session; } // namespace Main +namespace Ui { +class Show; +} // namespace Ui + namespace Data { class Factchecks final { @@ -39,6 +43,11 @@ public: FullMsgId itemId, TextWithEntities text, Fn done); + void save( + FullMsgId itemId, + TextWithEntities was, + TextWithEntities text, + std::shared_ptr show); private: [[nodiscard]] bool canEdit() const; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index e6950859d9..76fa5c4634 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2179,21 +2179,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { ? tr::lng_context_add_factcheck(tr::now) : tr::lng_context_edit_factcheck(tr::now); _menu->addAction(phrase, [=] { - controller->show(Box(EditFactcheckBox, text, [=]( + const auto limit = session->factchecks().lengthLimit(); + controller->show(Box(EditFactcheckBox, text, limit, [=]( TextWithEntities result) { - const auto done = [=](QString error) { - controller->showToast(!error.isEmpty() - ? error - : result.empty() - ? tr::lng_factcheck_remove_done(tr::now) - : text.empty() - ? tr::lng_factcheck_add_done(tr::now) - : tr::lng_factcheck_edit_done(tr::now)); - }; - session->factchecks().save( - itemId, - result, - crl::guard(controller, done)); + const auto show = controller->uiShow(); + session->factchecks().save(itemId, text, result, show); })); }, &st::menuIconFactcheck); } diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index a02f4c7865..3d47b358e1 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -39,6 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/controls/delete_message_context_action.h" #include "ui/controls/who_reacted_context_action.h" +#include "ui/boxes/edit_factcheck_box.h" #include "ui/boxes/report_box.h" #include "ui/ui_utility.h" #include "menu/menu_item_download_files.h" @@ -53,6 +54,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/sticker_set_box.h" #include "boxes/stickers_box.h" #include "boxes/translate_box.h" +#include "data/components/factchecks.h" #include "data/data_photo.h" #include "data/data_photo_media.h" #include "data/data_document.h" @@ -713,6 +715,31 @@ bool AddEditMessageAction( return true; } +void AddFactcheckAction( + not_null menu, + const ContextMenuRequest &request, + not_null list) { + const auto item = request.item; + if (!item || !item->history()->session().factchecks().canEdit(item)) { + return; + } + const auto itemId = item->fullId(); + const auto text = item->factcheckText(); + const auto session = &item->history()->session(); + const auto phrase = text.empty() + ? tr::lng_context_add_factcheck(tr::now) + : tr::lng_context_edit_factcheck(tr::now); + menu->addAction(phrase, [=] { + const auto limit = session->factchecks().lengthLimit(); + const auto controller = request.navigation->parentController(); + controller->show(Box(EditFactcheckBox, text, limit, [=]( + TextWithEntities result) { + const auto show = controller->uiShow(); + session->factchecks().save(itemId, text, result, show); + })); + }, &st::menuIconFactcheck); +} + bool AddPinMessageAction( not_null menu, const ContextMenuRequest &request, @@ -972,6 +999,7 @@ void AddTopMessageActions( AddGoToMessageAction(menu, request, list); AddViewRepliesAction(menu, request, list); AddEditMessageAction(menu, request, list); + AddFactcheckAction(menu, request, list); AddPinMessageAction(menu, request, list); } diff --git a/Telegram/SourceFiles/settings/business/settings_chat_intro.cpp b/Telegram/SourceFiles/settings/business/settings_chat_intro.cpp index b9fa7c68c2..e9bc2f73ec 100644 --- a/Telegram/SourceFiles/settings/business/settings_chat_intro.cpp +++ b/Telegram/SourceFiles/settings/business/settings_chat_intro.cpp @@ -21,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_media_common.h" #include "history/view/media/history_view_sticker_player.h" #include "history/view/history_view_about_view.h" -#include "history/view/history_view_context_menu.h" #include "history/view/history_view_element.h" #include "history/history.h" #include "lang/lang_keys.h" @@ -168,7 +167,6 @@ private: return field; } - rpl::producer> IconPlayerValue( not_null sticker, Fn update) { diff --git a/Telegram/SourceFiles/ui/boxes/edit_factcheck_box.cpp b/Telegram/SourceFiles/ui/boxes/edit_factcheck_box.cpp index f13c3e9768..16a5b14afc 100644 --- a/Telegram/SourceFiles/ui/boxes/edit_factcheck_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/edit_factcheck_box.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL void EditFactcheckBox( not_null box, TextWithEntities current, + int limit, Fn save) { box->setTitle(tr::lng_factcheck_title()); @@ -27,6 +28,7 @@ void EditFactcheckBox( current.text, TextUtilities::ConvertEntitiesToTextTags(current.entities) })); + AddLengthLimitLabel(field, limit); enum class State { Initial, @@ -62,6 +64,10 @@ void EditFactcheckBox( } else { box->addButton(tr::lng_settings_save(), [=] { auto result = field->getTextWithAppliedMarkdown(); + if (result.text.size() > limit) { + field->showError(); + return; + } box->closeBox(); save({ diff --git a/Telegram/SourceFiles/ui/boxes/edit_factcheck_box.h b/Telegram/SourceFiles/ui/boxes/edit_factcheck_box.h index f09f52eb4a..7eb104af3c 100644 --- a/Telegram/SourceFiles/ui/boxes/edit_factcheck_box.h +++ b/Telegram/SourceFiles/ui/boxes/edit_factcheck_box.h @@ -12,4 +12,5 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL void EditFactcheckBox( not_null box, TextWithEntities current, + int limit, Fn save);