mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Block field with toast if texts are not allowed.
This commit is contained in:
@@ -18,7 +18,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/shortcuts.h"
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "data/data_session.h"
|
||||
@@ -50,6 +52,7 @@ using EditLinkAction = Ui::InputField::EditLinkAction;
|
||||
using EditLinkSelection = Ui::InputField::EditLinkSelection;
|
||||
|
||||
constexpr auto kParseLinksTimeout = crl::time(1000);
|
||||
constexpr auto kTypesDuration = 4 * crl::time(1000);
|
||||
|
||||
// For mention / custom emoji tags save and validate selfId,
|
||||
// ignore tags for different users.
|
||||
@@ -773,3 +776,86 @@ void MessageLinksParser::apply(
|
||||
}
|
||||
_list = std::move(parsed);
|
||||
}
|
||||
|
||||
base::unique_qptr<Ui::RpWidget> CreateDisabledFieldView(
|
||||
QWidget *parent,
|
||||
not_null<PeerData*> peer) {
|
||||
auto result = base::make_unique_q<Ui::AbstractButton>(parent);
|
||||
const auto raw = result.get();
|
||||
const auto label = CreateChild<Ui::FlatLabel>(
|
||||
result.get(),
|
||||
tr::lng_send_text_no(),
|
||||
st::historySendDisabled);
|
||||
label->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
raw->setPointerCursor(false);
|
||||
raw->widthValue(
|
||||
) | rpl::start_with_next([=](int width) {
|
||||
const auto &st = st::historyComposeField;
|
||||
const auto margins = (st.textMargins + st.placeholderMargins);
|
||||
const auto available = width - margins.left() - margins.right();
|
||||
const auto skip = st::historySendDisabledIconSkip;
|
||||
label->resizeToWidth(available - skip);
|
||||
label->moveToLeft(margins.left() + skip, margins.top(), width);
|
||||
}, label->lifetime());
|
||||
raw->paintRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
auto p = QPainter(raw);
|
||||
const auto &st = st::historyComposeField;
|
||||
const auto margins = (st.textMargins + st.placeholderMargins);
|
||||
const auto &icon = st::historySendDisabledIcon;
|
||||
icon.paint(
|
||||
p,
|
||||
margins.left() + st::historySendDisabledPosition.x(),
|
||||
margins.top() + st::historySendDisabledPosition.y(),
|
||||
raw->width());
|
||||
}, raw->lifetime());
|
||||
using WeakToast = base::weak_ptr<Ui::Toast::Instance>;
|
||||
const auto toast = raw->lifetime().make_state<WeakToast>();
|
||||
raw->setClickedCallback([=] {
|
||||
if (toast->get()) {
|
||||
return;
|
||||
}
|
||||
using Flag = ChatRestriction;
|
||||
const auto map = base::flat_map<Flag, tr::phrase<>>{
|
||||
{ Flag::SendPhotos, tr::lng_send_text_type_photos },
|
||||
{ Flag::SendVideos, tr::lng_send_text_type_videos },
|
||||
{
|
||||
Flag::SendVideoMessages,
|
||||
tr::lng_send_text_type_video_messages,
|
||||
},
|
||||
{ Flag::SendMusic, tr::lng_send_text_type_music },
|
||||
{
|
||||
Flag::SendVoiceMessages,
|
||||
tr::lng_send_text_type_voice_messages,
|
||||
},
|
||||
{ Flag::SendFiles, tr::lng_send_text_type_files },
|
||||
{ Flag::SendStickers, tr::lng_send_text_type_stickers },
|
||||
{ Flag::SendPolls, tr::lng_send_text_type_polls },
|
||||
};
|
||||
auto list = QStringList();
|
||||
for (const auto &[flag, phrase] : map) {
|
||||
if (Data::CanSend(peer, flag, false)) {
|
||||
list.append(phrase(tr::now));
|
||||
}
|
||||
}
|
||||
if (list.empty()) {
|
||||
return;
|
||||
}
|
||||
const auto types = (list.size() > 1)
|
||||
? tr::lng_send_text_type_and_last(
|
||||
tr::now,
|
||||
lt_types,
|
||||
list.mid(0, list.size() - 1).join(", "),
|
||||
lt_last,
|
||||
list.back())
|
||||
: list.back();
|
||||
*toast = Ui::Toast::Show(parent, {
|
||||
.text = { tr::lng_send_text_no_about(tr::now, lt_types, types) },
|
||||
.st = &st::defaultMultilineToast,
|
||||
.durationMs = kTypesDuration,
|
||||
.multiline = true,
|
||||
.slideSide = RectPart::Bottom,
|
||||
});
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user