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