mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Show length limit when editing a factcheck.
This commit is contained in:
parent
493f0450b4
commit
d13bf19b79
7 changed files with 65 additions and 16 deletions
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_app_config.h"
|
#include "main/main_app_config.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "ui/layers/show.h"
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -196,4 +197,20 @@ void Factchecks::save(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Factchecks::save(
|
||||||
|
FullMsgId itemId,
|
||||||
|
TextWithEntities was,
|
||||||
|
TextWithEntities text,
|
||||||
|
std::shared_ptr<Ui::Show> 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
|
} // namespace Data
|
||||||
|
|
|
@ -21,6 +21,10 @@ namespace Main {
|
||||||
class Session;
|
class Session;
|
||||||
} // namespace Main
|
} // namespace Main
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class Show;
|
||||||
|
} // namespace Ui
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
|
||||||
class Factchecks final {
|
class Factchecks final {
|
||||||
|
@ -39,6 +43,11 @@ public:
|
||||||
FullMsgId itemId,
|
FullMsgId itemId,
|
||||||
TextWithEntities text,
|
TextWithEntities text,
|
||||||
Fn<void(QString)> done);
|
Fn<void(QString)> done);
|
||||||
|
void save(
|
||||||
|
FullMsgId itemId,
|
||||||
|
TextWithEntities was,
|
||||||
|
TextWithEntities text,
|
||||||
|
std::shared_ptr<Ui::Show> show);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] bool canEdit() const;
|
[[nodiscard]] bool canEdit() const;
|
||||||
|
|
|
@ -2179,21 +2179,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||||
? tr::lng_context_add_factcheck(tr::now)
|
? tr::lng_context_add_factcheck(tr::now)
|
||||||
: tr::lng_context_edit_factcheck(tr::now);
|
: tr::lng_context_edit_factcheck(tr::now);
|
||||||
_menu->addAction(phrase, [=] {
|
_menu->addAction(phrase, [=] {
|
||||||
controller->show(Box(EditFactcheckBox, text, [=](
|
const auto limit = session->factchecks().lengthLimit();
|
||||||
|
controller->show(Box(EditFactcheckBox, text, limit, [=](
|
||||||
TextWithEntities result) {
|
TextWithEntities result) {
|
||||||
const auto done = [=](QString error) {
|
const auto show = controller->uiShow();
|
||||||
controller->showToast(!error.isEmpty()
|
session->factchecks().save(itemId, text, result, show);
|
||||||
? 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));
|
|
||||||
}));
|
}));
|
||||||
}, &st::menuIconFactcheck);
|
}, &st::menuIconFactcheck);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/controls/delete_message_context_action.h"
|
#include "ui/controls/delete_message_context_action.h"
|
||||||
#include "ui/controls/who_reacted_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/boxes/report_box.h"
|
||||||
#include "ui/ui_utility.h"
|
#include "ui/ui_utility.h"
|
||||||
#include "menu/menu_item_download_files.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/sticker_set_box.h"
|
||||||
#include "boxes/stickers_box.h"
|
#include "boxes/stickers_box.h"
|
||||||
#include "boxes/translate_box.h"
|
#include "boxes/translate_box.h"
|
||||||
|
#include "data/components/factchecks.h"
|
||||||
#include "data/data_photo.h"
|
#include "data/data_photo.h"
|
||||||
#include "data/data_photo_media.h"
|
#include "data/data_photo_media.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
|
@ -713,6 +715,31 @@ bool AddEditMessageAction(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddFactcheckAction(
|
||||||
|
not_null<Ui::PopupMenu*> menu,
|
||||||
|
const ContextMenuRequest &request,
|
||||||
|
not_null<ListWidget*> 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(
|
bool AddPinMessageAction(
|
||||||
not_null<Ui::PopupMenu*> menu,
|
not_null<Ui::PopupMenu*> menu,
|
||||||
const ContextMenuRequest &request,
|
const ContextMenuRequest &request,
|
||||||
|
@ -972,6 +999,7 @@ void AddTopMessageActions(
|
||||||
AddGoToMessageAction(menu, request, list);
|
AddGoToMessageAction(menu, request, list);
|
||||||
AddViewRepliesAction(menu, request, list);
|
AddViewRepliesAction(menu, request, list);
|
||||||
AddEditMessageAction(menu, request, list);
|
AddEditMessageAction(menu, request, list);
|
||||||
|
AddFactcheckAction(menu, request, list);
|
||||||
AddPinMessageAction(menu, request, list);
|
AddPinMessageAction(menu, request, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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_media_common.h"
|
||||||
#include "history/view/media/history_view_sticker_player.h"
|
#include "history/view/media/history_view_sticker_player.h"
|
||||||
#include "history/view/history_view_about_view.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/view/history_view_element.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
@ -168,7 +167,6 @@ private:
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
rpl::producer<std::shared_ptr<StickerPlayer>> IconPlayerValue(
|
rpl::producer<std::shared_ptr<StickerPlayer>> IconPlayerValue(
|
||||||
not_null<DocumentData*> sticker,
|
not_null<DocumentData*> sticker,
|
||||||
Fn<void()> update) {
|
Fn<void()> update) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
void EditFactcheckBox(
|
void EditFactcheckBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
TextWithEntities current,
|
TextWithEntities current,
|
||||||
|
int limit,
|
||||||
Fn<void(TextWithEntities)> save) {
|
Fn<void(TextWithEntities)> save) {
|
||||||
box->setTitle(tr::lng_factcheck_title());
|
box->setTitle(tr::lng_factcheck_title());
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ void EditFactcheckBox(
|
||||||
current.text,
|
current.text,
|
||||||
TextUtilities::ConvertEntitiesToTextTags(current.entities)
|
TextUtilities::ConvertEntitiesToTextTags(current.entities)
|
||||||
}));
|
}));
|
||||||
|
AddLengthLimitLabel(field, limit);
|
||||||
|
|
||||||
enum class State {
|
enum class State {
|
||||||
Initial,
|
Initial,
|
||||||
|
@ -62,6 +64,10 @@ void EditFactcheckBox(
|
||||||
} else {
|
} else {
|
||||||
box->addButton(tr::lng_settings_save(), [=] {
|
box->addButton(tr::lng_settings_save(), [=] {
|
||||||
auto result = field->getTextWithAppliedMarkdown();
|
auto result = field->getTextWithAppliedMarkdown();
|
||||||
|
if (result.text.size() > limit) {
|
||||||
|
field->showError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
save({
|
save({
|
||||||
|
|
|
@ -12,4 +12,5 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
void EditFactcheckBox(
|
void EditFactcheckBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
TextWithEntities current,
|
TextWithEntities current,
|
||||||
|
int limit,
|
||||||
Fn<void(TextWithEntities)> save);
|
Fn<void(TextWithEntities)> save);
|
||||||
|
|
Loading…
Add table
Reference in a new issue