mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Allow editing quick replies from the suggestions.
This commit is contained in:
parent
49ec051760
commit
288979d8e7
6 changed files with 87 additions and 8 deletions
|
@ -2228,6 +2228,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_replies_message_placeholder" = "Add a Quick Reply";
|
"lng_replies_message_placeholder" = "Add a Quick Reply";
|
||||||
"lng_replies_delete_sure" = "Are you sure you want to delete this quick reply with all its messages?";
|
"lng_replies_delete_sure" = "Are you sure you want to delete this quick reply with all its messages?";
|
||||||
"lng_replies_error_occupied" = "This shortcut is already used.";
|
"lng_replies_error_occupied" = "This shortcut is already used.";
|
||||||
|
"lng_replies_edit_button" = "Edit Quick Replies";
|
||||||
|
|
||||||
"lng_greeting_title" = "Greeting Message";
|
"lng_greeting_title" = "Greeting Message";
|
||||||
"lng_greeting_about" = "Greet customers when they message you the first time or after a period of no activity.";
|
"lng_greeting_about" = "Greet customers when they message you the first time or after a period of no activity.";
|
||||||
|
|
|
@ -641,7 +641,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||||
const auto shortcuts = (_user && !_user->isBot())
|
const auto shortcuts = (_user && !_user->isBot())
|
||||||
? _user->owner().shortcutMessages().shortcuts().list
|
? _user->owner().shortcutMessages().shortcuts().list
|
||||||
: base::flat_map<BusinessShortcutId, Data::Shortcut>();
|
: base::flat_map<BusinessShortcutId, Data::Shortcut>();
|
||||||
if (!hasUsername && !shortcuts.empty()) {
|
if (!hasUsername && brows.empty() && !shortcuts.empty()) {
|
||||||
const auto self = _user->session().user();
|
const auto self = _user->session().user();
|
||||||
for (const auto &[id, shortcut] : shortcuts) {
|
for (const auto &[id, shortcut] : shortcuts) {
|
||||||
if (shortcut.count < 1) {
|
if (shortcut.count < 1) {
|
||||||
|
@ -658,6 +658,9 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||||
self->activeUserpicView()
|
self->activeUserpicView()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!brows.empty()) {
|
||||||
|
brows.insert(begin(brows), BotCommandRow{ self }); // Edit.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rowsUpdated(
|
rowsUpdated(
|
||||||
|
@ -1096,6 +1099,15 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) {
|
||||||
} else {
|
} else {
|
||||||
auto &row = _brows->at(i);
|
auto &row = _brows->at(i);
|
||||||
const auto user = row.user;
|
const auto user = row.user;
|
||||||
|
if (user->isSelf() && row.command.isEmpty()) {
|
||||||
|
p.setPen(st::windowActiveTextFg);
|
||||||
|
p.setFont(st::semiboldFont);
|
||||||
|
p.drawText(
|
||||||
|
QRect(0, i * st::mentionHeight, width(), st::mentionHeight),
|
||||||
|
tr::lng_replies_edit_button(tr::now),
|
||||||
|
style::al_center);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto toHighlight = row.command;
|
auto toHighlight = row.command;
|
||||||
int32 botStatus = _parent->chat() ? _parent->chat()->botStatus : ((_parent->channel() && _parent->channel()->isMegagroup()) ? _parent->channel()->mgInfo->botStatus : -1);
|
int32 botStatus = _parent->chat() ? _parent->chat()->botStatus : ((_parent->channel() && _parent->channel()->isMegagroup()) ? _parent->channel()->mgInfo->botStatus : -1);
|
||||||
|
@ -1163,7 +1175,13 @@ void FieldAutocomplete::Inner::clearSel(bool hidden) {
|
||||||
_overDelete = false;
|
_overDelete = false;
|
||||||
_mouseSelection = false;
|
_mouseSelection = false;
|
||||||
_lastMousePosition = std::nullopt;
|
_lastMousePosition = std::nullopt;
|
||||||
setSel((_mrows->empty() && _brows->empty() && _hrows->empty()) ? -1 : 0);
|
setSel((_mrows->empty() && _brows->empty() && _hrows->empty())
|
||||||
|
? -1
|
||||||
|
: (_brows->size() > 1
|
||||||
|
&& _brows->front().user->isSelf()
|
||||||
|
&& _brows->front().command.isEmpty())
|
||||||
|
? 1
|
||||||
|
: 0);
|
||||||
if (hidden) {
|
if (hidden) {
|
||||||
_down = -1;
|
_down = -1;
|
||||||
_previewShown = false;
|
_previewShown = false;
|
||||||
|
@ -1269,7 +1287,6 @@ bool FieldAutocomplete::Inner::chooseAtIndex(
|
||||||
const auto commandString = QString("/%1%2").arg(
|
const auto commandString = QString("/%1%2").arg(
|
||||||
command,
|
command,
|
||||||
insertUsername ? ('@' + PrimaryUsername(user)) : QString());
|
insertUsername ? ('@' + PrimaryUsername(user)) : QString());
|
||||||
|
|
||||||
_botCommandChosen.fire({ user, commandString, method });
|
_botCommandChosen.fire({ user, commandString, method });
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "settings/business/settings_quick_replies.h"
|
||||||
#include "storage/localimageloader.h"
|
#include "storage/localimageloader.h"
|
||||||
#include "storage/storage_account.h"
|
#include "storage/storage_account.h"
|
||||||
#include "storage/file_upload.h"
|
#include "storage/file_upload.h"
|
||||||
|
@ -378,6 +379,11 @@ HistoryWidget::HistoryWidget(
|
||||||
checkFieldAutocomplete();
|
checkFieldAutocomplete();
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
|
controller->session().data().shortcutMessages().shortcutsChanged(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
checkFieldAutocomplete();
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
_fieldBarCancel->hide();
|
_fieldBarCancel->hide();
|
||||||
|
|
||||||
_topBar->hide();
|
_topBar->hide();
|
||||||
|
@ -435,12 +441,15 @@ HistoryWidget::HistoryWidget(
|
||||||
) | rpl::start_with_next([=](FieldAutocomplete::BotCommandChosen data) {
|
) | rpl::start_with_next([=](FieldAutocomplete::BotCommandChosen data) {
|
||||||
using Method = FieldAutocomplete::ChooseMethod;
|
using Method = FieldAutocomplete::ChooseMethod;
|
||||||
const auto messages = &data.user->owner().shortcutMessages();
|
const auto messages = &data.user->owner().shortcutMessages();
|
||||||
const auto shortcutId = (_peer
|
const auto shortcut = data.user->isSelf();
|
||||||
&& data.user->isSelf()
|
const auto command = data.command.mid(1);
|
||||||
&& data.method != Method::ByTab)
|
const auto byTab = (data.method == Method::ByTab);
|
||||||
? messages->lookupShortcutId(data.command.mid(1))
|
const auto shortcutId = (_peer && shortcut && !byTab)
|
||||||
|
? messages->lookupShortcutId(command)
|
||||||
: BusinessShortcutId();
|
: BusinessShortcutId();
|
||||||
if (!shortcutId) {
|
if (shortcut && command.isEmpty()) {
|
||||||
|
controller->showSettings(Settings::QuickRepliesId());
|
||||||
|
} else if (!shortcutId) {
|
||||||
insertHashtagOrBotCommand(data.command, data.method);
|
insertHashtagOrBotCommand(data.command, data.method);
|
||||||
} else if (!_peer->session().premium()) {
|
} else if (!_peer->session().premium()) {
|
||||||
ShowPremiumPreviewToBuy(
|
ShowPremiumPreviewToBuy(
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "settings/business/settings_quick_replies.h"
|
#include "settings/business/settings_quick_replies.h"
|
||||||
|
|
||||||
|
#include "boxes/premium_preview_box.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "data/business/data_shortcut_messages.h"
|
#include "data/business/data_shortcut_messages.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -96,6 +97,12 @@ void QuickReplies::setupContent(
|
||||||
));
|
));
|
||||||
|
|
||||||
add->setClickedCallback([=] {
|
add->setClickedCallback([=] {
|
||||||
|
if (!controller->session().premium()) {
|
||||||
|
ShowPremiumPreviewToBuy(
|
||||||
|
controller,
|
||||||
|
PremiumFeature::QuickReplies);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto submit = [=](QString name, Fn<void()> close) {
|
const auto submit = [=](QString name, Fn<void()> close) {
|
||||||
const auto id = messages->emplaceShortcut(name);
|
const auto id = messages->emplaceShortcut(name);
|
||||||
showOther(ShortcutMessagesId(id));
|
showOther(ShortcutMessagesId(id));
|
||||||
|
|
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/call_delayed.h"
|
#include "base/call_delayed.h"
|
||||||
#include "boxes/delete_messages_box.h"
|
#include "boxes/delete_messages_box.h"
|
||||||
#include "boxes/premium_limits_box.h"
|
#include "boxes/premium_limits_box.h"
|
||||||
|
#include "boxes/premium_preview_box.h"
|
||||||
#include "boxes/send_files_box.h"
|
#include "boxes/send_files_box.h"
|
||||||
#include "chat_helpers/tabbed_selector.h"
|
#include "chat_helpers/tabbed_selector.h"
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
|
@ -253,6 +254,7 @@ private:
|
||||||
void showAtEnd();
|
void showAtEnd();
|
||||||
void finishSending();
|
void finishSending();
|
||||||
void refreshEmptyText();
|
void refreshEmptyText();
|
||||||
|
bool showPremiumRequired() const;
|
||||||
|
|
||||||
const not_null<Window::SessionController*> _controller;
|
const not_null<Window::SessionController*> _controller;
|
||||||
const not_null<Main::Session*> _session;
|
const not_null<Main::Session*> _session;
|
||||||
|
@ -508,6 +510,12 @@ void ShortcutMessages::fillTopBarMenu(
|
||||||
const auto messages = &owner->shortcutMessages();
|
const auto messages = &owner->shortcutMessages();
|
||||||
|
|
||||||
addAction(tr::lng_context_edit_shortcut(tr::now), [=] {
|
addAction(tr::lng_context_edit_shortcut(tr::now), [=] {
|
||||||
|
if (!_controller->session().premium()) {
|
||||||
|
ShowPremiumPreviewToBuy(
|
||||||
|
_controller,
|
||||||
|
PremiumFeature::QuickReplies);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto submit = [=](QString name, Fn<void()> close) {
|
const auto submit = [=](QString name, Fn<void()> close) {
|
||||||
const auto id = _shortcutId.current();
|
const auto id = _shortcutId.current();
|
||||||
const auto error = [=](QString text) {
|
const auto error = [=](QString text) {
|
||||||
|
@ -773,6 +781,7 @@ QPointer<Ui::RpWidget> ShortcutMessages::createPinnedToBottom(
|
||||||
_composeControls = std::make_unique<ComposeControls>(
|
_composeControls = std::make_unique<ComposeControls>(
|
||||||
dynamic_cast<Ui::RpWidget*>(_scroll->parentWidget()),
|
dynamic_cast<Ui::RpWidget*>(_scroll->parentWidget()),
|
||||||
ComposeControlsDescriptor{
|
ComposeControlsDescriptor{
|
||||||
|
.stOverride = &st::repliesComposeControls,
|
||||||
.show = _controller->uiShow(),
|
.show = _controller->uiShow(),
|
||||||
.unavailableEmojiPasted = [=](not_null<DocumentData*> emoji) {
|
.unavailableEmojiPasted = [=](not_null<DocumentData*> emoji) {
|
||||||
listShowPremiumToast(emoji);
|
listShowPremiumToast(emoji);
|
||||||
|
@ -1127,6 +1136,9 @@ bool ShortcutMessages::showSendingFilesError(
|
||||||
bool ShortcutMessages::showSendingFilesError(
|
bool ShortcutMessages::showSendingFilesError(
|
||||||
const Ui::PreparedList &list,
|
const Ui::PreparedList &list,
|
||||||
std::optional<bool> compress) const {
|
std::optional<bool> compress) const {
|
||||||
|
if (showPremiumRequired()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const auto text = [&] {
|
const auto text = [&] {
|
||||||
using Error = Ui::PreparedList::Error;
|
using Error = Ui::PreparedList::Error;
|
||||||
switch (list.error) {
|
switch (list.error) {
|
||||||
|
@ -1171,6 +1183,9 @@ void ShortcutMessages::send() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutMessages::sendVoice(ComposeControls::VoiceToSend &&data) {
|
void ShortcutMessages::sendVoice(ComposeControls::VoiceToSend &&data) {
|
||||||
|
if (showPremiumRequired()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto action = prepareSendAction(data.options);
|
auto action = prepareSendAction(data.options);
|
||||||
_session->api().sendVoiceMessage(
|
_session->api().sendVoiceMessage(
|
||||||
data.bytes,
|
data.bytes,
|
||||||
|
@ -1184,6 +1199,9 @@ void ShortcutMessages::sendVoice(ComposeControls::VoiceToSend &&data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShortcutMessages::send(Api::SendOptions options) {
|
void ShortcutMessages::send(Api::SendOptions options) {
|
||||||
|
if (showPremiumRequired()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_cornerButtons.clearReplyReturns();
|
_cornerButtons.clearReplyReturns();
|
||||||
|
|
||||||
auto message = Api::MessageToSend(prepareSendAction(options));
|
auto message = Api::MessageToSend(prepareSendAction(options));
|
||||||
|
@ -1409,6 +1427,9 @@ void ShortcutMessages::sendingFilesConfirmed(
|
||||||
|
|
||||||
void ShortcutMessages::chooseAttach(
|
void ShortcutMessages::chooseAttach(
|
||||||
std::optional<bool> overrideSendImagesAsPhotos) {
|
std::optional<bool> overrideSendImagesAsPhotos) {
|
||||||
|
if (showPremiumRequired()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_choosingAttach = false;
|
_choosingAttach = false;
|
||||||
|
|
||||||
const auto filter = (overrideSendImagesAsPhotos == true)
|
const auto filter = (overrideSendImagesAsPhotos == true)
|
||||||
|
@ -1472,6 +1493,10 @@ bool ShortcutMessages::sendExistingDocument(
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
std::optional<MsgId> localId) {
|
std::optional<MsgId> localId) {
|
||||||
|
if (showPremiumRequired()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Api::SendExistingDocument(
|
Api::SendExistingDocument(
|
||||||
Api::MessageToSend(prepareSendAction(options)),
|
Api::MessageToSend(prepareSendAction(options)),
|
||||||
document,
|
document,
|
||||||
|
@ -1489,6 +1514,9 @@ void ShortcutMessages::sendExistingPhoto(not_null<PhotoData*> photo) {
|
||||||
bool ShortcutMessages::sendExistingPhoto(
|
bool ShortcutMessages::sendExistingPhoto(
|
||||||
not_null<PhotoData*> photo,
|
not_null<PhotoData*> photo,
|
||||||
Api::SendOptions options) {
|
Api::SendOptions options) {
|
||||||
|
if (showPremiumRequired()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Api::SendExistingPhoto(
|
Api::SendExistingPhoto(
|
||||||
Api::MessageToSend(prepareSendAction(options)),
|
Api::MessageToSend(prepareSendAction(options)),
|
||||||
photo);
|
photo);
|
||||||
|
@ -1501,6 +1529,9 @@ bool ShortcutMessages::sendExistingPhoto(
|
||||||
void ShortcutMessages::sendInlineResult(
|
void ShortcutMessages::sendInlineResult(
|
||||||
not_null<InlineBots::Result*> result,
|
not_null<InlineBots::Result*> result,
|
||||||
not_null<UserData*> bot) {
|
not_null<UserData*> bot) {
|
||||||
|
if (showPremiumRequired()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto errorText = result->getErrorOnSend(_history);
|
const auto errorText = result->getErrorOnSend(_history);
|
||||||
if (!errorText.isEmpty()) {
|
if (!errorText.isEmpty()) {
|
||||||
_controller->showToast(errorText);
|
_controller->showToast(errorText);
|
||||||
|
@ -1520,6 +1551,9 @@ void ShortcutMessages::sendInlineResult(
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
Api::SendOptions options,
|
Api::SendOptions options,
|
||||||
std::optional<MsgId> localMessageId) {
|
std::optional<MsgId> localMessageId) {
|
||||||
|
if (showPremiumRequired()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto action = prepareSendAction(options);
|
auto action = prepareSendAction(options);
|
||||||
action.generateLocal = true;
|
action.generateLocal = true;
|
||||||
_session->api().sendInlineResult(bot, result, action, localMessageId);
|
_session->api().sendInlineResult(bot, result, action, localMessageId);
|
||||||
|
@ -1564,6 +1598,14 @@ FullReplyTo ShortcutMessages::replyTo() const {
|
||||||
return _composeControls->replyingToMessage();
|
return _composeControls->replyingToMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ShortcutMessages::showPremiumRequired() const {
|
||||||
|
if (!_controller->session().premium()) {
|
||||||
|
ShowPremiumPreviewToBuy(_controller, PremiumFeature::QuickReplies);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Type ShortcutMessagesId(int shortcutId) {
|
Type ShortcutMessagesId(int shortcutId) {
|
||||||
|
|
|
@ -1050,6 +1050,9 @@ awayEmptyIcon: icon{{ "chat/large_away", msgServiceFg }};
|
||||||
repliesEmptyWidth: 264px;
|
repliesEmptyWidth: 264px;
|
||||||
repliesEmptySkip: 16px;
|
repliesEmptySkip: 16px;
|
||||||
repliesEmptyPadding: margins(10px, 20px, 10px, 16px);
|
repliesEmptyPadding: margins(10px, 20px, 10px, 16px);
|
||||||
|
repliesComposeControls: ComposeControls(defaultComposeControls) {
|
||||||
|
tabbedHeightMin: 220px;
|
||||||
|
}
|
||||||
|
|
||||||
boostMessageIcon: icon {{ "stories/boost_mini", windowFg }};
|
boostMessageIcon: icon {{ "stories/boost_mini", windowFg }};
|
||||||
boostMessageIconPadding: margins(0px, 2px, 0px, 0px);
|
boostMessageIconPadding: margins(0px, 2px, 0px, 0px);
|
||||||
|
|
Loading…
Add table
Reference in a new issue