2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-02 15:45:12 +00:00

Updated TDesktop sources to 2.3.2+d34eabd

This commit is contained in:
RadRussianRus
2020-08-28 19:30:52 +03:00
210 changed files with 6138 additions and 2505 deletions

View File

@@ -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" // SendMenu::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"
@@ -45,8 +47,10 @@ FieldAutocomplete::FieldAutocomplete(
, _scroll(this, st::mentionScroll) {
_scroll->setGeometry(rect());
using Inner = internal::FieldAutocompleteInner;
_inner = _scroll->setOwnedWidget(
object_ptr<internal::FieldAutocompleteInner>(
object_ptr<Inner>(
_controller,
this,
&_mrows,
@@ -55,18 +59,41 @@ FieldAutocomplete::FieldAutocomplete(
&_srows));
_inner->setGeometry(rect());
connect(_inner, SIGNAL(mentionChosen(not_null<UserData*>,FieldAutocomplete::ChooseMethod)), this, SIGNAL(mentionChosen(not_null<UserData*>,FieldAutocomplete::ChooseMethod)));
connect(_inner, SIGNAL(hashtagChosen(QString,FieldAutocomplete::ChooseMethod)), this, SIGNAL(hashtagChosen(QString,FieldAutocomplete::ChooseMethod)));
connect(_inner, SIGNAL(botCommandChosen(QString,FieldAutocomplete::ChooseMethod)), this, SIGNAL(botCommandChosen(QString,FieldAutocomplete::ChooseMethod)));
connect(_inner, SIGNAL(stickerChosen(not_null<DocumentData*>,FieldAutocomplete::ChooseMethod)), this, SIGNAL(stickerChosen(not_null<DocumentData*>,FieldAutocomplete::ChooseMethod)));
connect(_inner, SIGNAL(mustScrollTo(int, int)), _scroll, SLOT(scrollToY(int, int)));
_inner->scrollToRequested(
) | rpl::start_with_next([=](Inner::ScrollTo data) {
_scroll->scrollToY(data.top, data.bottom);
}, lifetime());
_scroll->show();
_inner->show();
hide();
connect(_scroll, SIGNAL(geometryChanged()), _inner, SLOT(onParentGeometryChanged()));
connect(
_scroll,
&Ui::ScrollArea::geometryChanged,
_inner,
&Inner::onParentGeometryChanged);
}
auto FieldAutocomplete::mentionChosen() const
-> rpl::producer<FieldAutocomplete::MentionChosen> {
return _inner->mentionChosen();
}
auto FieldAutocomplete::hashtagChosen() const
-> rpl::producer<FieldAutocomplete::HashtagChosen> {
return _inner->hashtagChosen();
}
auto FieldAutocomplete::botCommandChosen() const
-> rpl::producer<FieldAutocomplete::BotCommandChosen> {
return _inner->botCommandChosen();
}
auto FieldAutocomplete::stickerChosen() const
-> rpl::producer<FieldAutocomplete::StickerChosen> {
return _inner->stickerChosen();
}
FieldAutocomplete::~FieldAutocomplete() = default;
@@ -583,9 +610,10 @@ bool FieldAutocomplete::eventFilter(QObject *obj, QEvent *e) {
&& ((key >= Qt::Key_1 && key <= Qt::Key_9)
|| key == Qt::Key_Q
|| key == Qt::Key_W)) {
bool handled = false;
emit moderateKeyActivate(key, &handled);
return handled;
return _moderateKeyActivateCallback
? _moderateKeyActivateCallback(key)
: false;
}
} else if (ev->modifiers() & Qt::ControlModifier) {
if (ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return) {
@@ -879,32 +907,52 @@ 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()) {
emit stickerChosen((*_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()) {
emit mentionChosen(_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()) {
emit hashtagChosen('#' + _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;
int32 botStatus = _parent->chat() ? _parent->chat()->botStatus : ((_parent->channel() && _parent->channel()->isMegagroup()) ? _parent->channel()->mgInfo->botStatus : -1);
if (botStatus == 0 || botStatus == 2 || _parent->filter().indexOf('@') > 0) {
emit botCommandChosen('/' + command->command + '@' + user->username, method);
} else {
emit botCommandChosen('/' + command->command, method);
}
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())
? _parent->channel()->mgInfo->botStatus
: -1);
const auto insertUsername = (botStatus == 0
|| botStatus == 2
|| _parent->filter().indexOf('@') > 0);
const auto commandString = QString("/%1%2")
.arg(command->command)
.arg(insertUsername ? ('@' + user->username) : QString());
_botCommandChosen.fire({ commandString, method });
return true;
}
}
@@ -989,6 +1037,29 @@ void FieldAutocompleteInner::mouseReleaseEvent(QMouseEvent *e) {
}
}
void FieldAutocompleteInner::contextMenuEvent(QContextMenuEvent *e) {
if (_sel < 0 || _srows->empty() || _down >= 0) {
return;
}
const auto index = _sel;
const auto type = SendMenu::Type::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);
};
SendMenu::FillSendMenu(
_menu,
[&] { return type; },
SendMenu::DefaultSilentCallback(send),
SendMenu::DefaultScheduleCallback(this, type, send));
if (!_menu->actions().empty()) {
_menu->popup(QCursor::pos());
}
}
void FieldAutocompleteInner::enterEventHook(QEvent *e) {
setMouseTracking(true);
}
@@ -1020,10 +1091,15 @@ void FieldAutocompleteInner::setSel(int sel, bool scroll) {
if (scroll && _sel >= 0) {
if (_srows->empty()) {
emit mustScrollTo(_sel * st::mentionHeight, (_sel + 1) * st::mentionHeight);
_scrollToRequested.fire({
_sel * st::mentionHeight,
(_sel + 1) * st::mentionHeight });
} else {
int32 row = _sel / _stickersPerRow;
emit mustScrollTo(st::stickerPanPadding + row * st::stickerPanSize.height(), st::stickerPanPadding + (row + 1) * st::stickerPanSize.height());
const auto padding = st::stickerPanPadding;
_scrollToRequested.fire({
padding + row * st::stickerPanSize.height(),
padding + (row + 1) * st::stickerPanSize.height() });
}
}
}
@@ -1151,4 +1227,29 @@ void FieldAutocompleteInner::showPreview() {
}
}
auto FieldAutocompleteInner::mentionChosen() const
-> rpl::producer<FieldAutocomplete::MentionChosen> {
return _mentionChosen.events();
}
auto FieldAutocompleteInner::hashtagChosen() const
-> rpl::producer<FieldAutocomplete::HashtagChosen> {
return _hashtagChosen.events();
}
auto FieldAutocompleteInner::botCommandChosen() const
-> rpl::producer<FieldAutocomplete::BotCommandChosen> {
return _botCommandChosen.events();
}
auto FieldAutocompleteInner::stickerChosen() const
-> rpl::producer<FieldAutocomplete::StickerChosen> {
return _stickerChosen.events();
}
auto FieldAutocompleteInner::scrollToRequested() const
-> rpl::producer<ScrollTo> {
return _scrollToRequested.events();
}
} // namespace internal