mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-23 08:46:55 +00:00
Added ability to schedule and send silently stickers from autocomplete.
This commit is contained in:
parent
cf56658664
commit
1eea07d88a
@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/stickers/data_stickers.h"
|
||||
#include "chat_helpers/send_context_menu.h" // FillSendMenu
|
||||
#include "chat_helpers/stickers_lottie.h"
|
||||
#include "mainwindow.h"
|
||||
#include "apiwrap.h"
|
||||
@ -24,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "lottie/lottie_single_player.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/ui_utility.h"
|
||||
@ -901,26 +903,38 @@ bool FieldAutocompleteInner::moveSel(int key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FieldAutocompleteInner::chooseSelected(FieldAutocomplete::ChooseMethod method) const {
|
||||
bool FieldAutocompleteInner::chooseSelected(
|
||||
FieldAutocomplete::ChooseMethod method) const {
|
||||
return chooseAtIndex(method, _sel);
|
||||
}
|
||||
|
||||
bool FieldAutocompleteInner::chooseAtIndex(
|
||||
FieldAutocomplete::ChooseMethod method,
|
||||
int index,
|
||||
Api::SendOptions options) const {
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
if (!_srows->empty()) {
|
||||
if (_sel >= 0 && _sel < _srows->size()) {
|
||||
_stickerChosen.fire({ (*_srows)[_sel].document, method });
|
||||
if (index < _srows->size()) {
|
||||
const auto document = (*_srows)[index].document;
|
||||
_stickerChosen.fire({ document, options, method });
|
||||
return true;
|
||||
}
|
||||
} else if (!_mrows->empty()) {
|
||||
if (_sel >= 0 && _sel < _mrows->size()) {
|
||||
_mentionChosen.fire({ _mrows->at(_sel).user, method });
|
||||
if (index < _mrows->size()) {
|
||||
_mentionChosen.fire({ _mrows->at(index).user, method });
|
||||
return true;
|
||||
}
|
||||
} else if (!_hrows->empty()) {
|
||||
if (_sel >= 0 && _sel < _hrows->size()) {
|
||||
_hashtagChosen.fire({ '#' + _hrows->at(_sel), method });
|
||||
if (index < _hrows->size()) {
|
||||
_hashtagChosen.fire({ '#' + _hrows->at(index), method });
|
||||
return true;
|
||||
}
|
||||
} else if (!_brows->empty()) {
|
||||
if (_sel >= 0 && _sel < _brows->size()) {
|
||||
const auto user = _brows->at(_sel).user;
|
||||
const auto command = _brows->at(_sel).command;
|
||||
if (index < _brows->size()) {
|
||||
const auto user = _brows->at(index).user;
|
||||
const auto command = _brows->at(index).command;
|
||||
const auto botStatus = _parent->chat()
|
||||
? _parent->chat()->botStatus
|
||||
: ((_parent->channel() && _parent->channel()->isMegagroup())
|
||||
@ -1003,6 +1017,29 @@ void FieldAutocompleteInner::mouseReleaseEvent(QMouseEvent *e) {
|
||||
chooseSelected(FieldAutocomplete::ChooseMethod::ByClick);
|
||||
}
|
||||
|
||||
void FieldAutocompleteInner::contextMenuEvent(QContextMenuEvent *e) {
|
||||
if (_sel < 0 || _srows->empty() || _down >= 0) {
|
||||
return;
|
||||
}
|
||||
const auto index = _sel;
|
||||
const auto type = SendMenuType::Scheduled;
|
||||
const auto method = FieldAutocomplete::ChooseMethod::ByClick;
|
||||
_menu = base::make_unique_q<Ui::PopupMenu>(this);
|
||||
|
||||
const auto send = [=](Api::SendOptions options) {
|
||||
chooseAtIndex(method, index, options);
|
||||
};
|
||||
FillSendMenu(
|
||||
_menu,
|
||||
[&] { return type; },
|
||||
DefaultSilentCallback(send),
|
||||
DefaultScheduleCallback(this, type, send));
|
||||
|
||||
if (!_menu->actions().empty()) {
|
||||
_menu->popup(QCursor::pos());
|
||||
}
|
||||
}
|
||||
|
||||
void FieldAutocompleteInner::enterEventHook(QEvent *e) {
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
@ -7,12 +7,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "api/api_common.h"
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "base/timer.h"
|
||||
#include "base/object_ptr.h"
|
||||
|
||||
namespace Ui {
|
||||
class PopupMenu;
|
||||
class ScrollArea;
|
||||
} // namespace Ui
|
||||
|
||||
@ -103,6 +105,7 @@ public:
|
||||
};
|
||||
struct StickerChosen {
|
||||
not_null<DocumentData*> sticker;
|
||||
Api::SendOptions options;
|
||||
ChooseMethod method;
|
||||
};
|
||||
|
||||
@ -210,6 +213,10 @@ public:
|
||||
void clearSel(bool hidden = false);
|
||||
bool moveSel(int key);
|
||||
bool chooseSelected(FieldAutocomplete::ChooseMethod method) const;
|
||||
bool chooseAtIndex(
|
||||
FieldAutocomplete::ChooseMethod method,
|
||||
int index,
|
||||
Api::SendOptions options = Api::SendOptions()) const;
|
||||
|
||||
void setRecentInlineBotsInRows(int32 bots);
|
||||
void rowsUpdated();
|
||||
@ -233,6 +240,7 @@ private:
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||
|
||||
void updateSelectedRow();
|
||||
void setSel(int sel, bool scroll = false);
|
||||
@ -252,6 +260,7 @@ private:
|
||||
const not_null<StickerRows*> _srows;
|
||||
rpl::lifetime _stickersLifetime;
|
||||
std::weak_ptr<Lottie::FrameRenderer> _lottieRenderer;
|
||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||
int _stickersPerRow = 1;
|
||||
int _recentInlineBotsInRows = 0;
|
||||
int _sel = -1;
|
||||
|
@ -400,7 +400,7 @@ HistoryWidget::HistoryWidget(
|
||||
|
||||
_fieldAutocomplete->stickerChosen(
|
||||
) | rpl::start_with_next([=](FieldAutocomplete::StickerChosen data) {
|
||||
sendExistingDocument(data.sticker, Api::SendOptions());
|
||||
sendExistingDocument(data.sticker, data.options);
|
||||
}, lifetime());
|
||||
|
||||
_fieldAutocomplete->setModerateKeyActivateCallback([=](int key) {
|
||||
|
Loading…
Reference in New Issue
Block a user