2017-08-01 12:01:42 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-08-01 12:01:42 +00:00
|
|
|
*/
|
|
|
|
#include "dialogs/dialogs_widget.h"
|
|
|
|
|
|
|
|
#include "dialogs/dialogs_inner_widget.h"
|
2017-08-01 15:55:51 +00:00
|
|
|
#include "dialogs/dialogs_search_from_controllers.h"
|
2018-01-04 19:54:35 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "dialogs/dialogs_entry.h"
|
|
|
|
#include "history/history.h"
|
2019-04-24 14:12:35 +00:00
|
|
|
#include "history/view/history_view_top_bar_widget.h"
|
2017-08-01 12:01:42 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2017-10-03 13:05:58 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2018-11-09 13:54:34 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
2022-02-22 13:58:55 +00:00
|
|
|
#include "ui/controls/download_bar.h"
|
2022-09-16 20:23:27 +00:00
|
|
|
#include "ui/painter.h"
|
2021-05-07 14:33:53 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2017-08-01 12:01:42 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "mainwidget.h"
|
2021-05-25 20:38:01 +00:00
|
|
|
#include "main/main_domain.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session_settings.h"
|
2018-01-03 17:06:43 +00:00
|
|
|
#include "apiwrap.h"
|
2019-09-19 09:28:36 +00:00
|
|
|
#include "base/event_filter.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2019-04-05 08:28:07 +00:00
|
|
|
#include "core/update_checker.h"
|
2017-08-01 15:55:51 +00:00
|
|
|
#include "boxes/peer_list_box.h"
|
2019-01-10 06:26:08 +00:00
|
|
|
#include "boxes/peers/edit_participants_box.h"
|
2021-05-26 21:00:12 +00:00
|
|
|
#include "window/window_adaptive.h"
|
2022-01-04 11:18:13 +00:00
|
|
|
#include "window/window_controller.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-10-03 13:05:58 +00:00
|
|
|
#include "window/window_slide_animation.h"
|
2018-05-07 17:44:33 +00:00
|
|
|
#include "window/window_connecting_widget.h"
|
2020-07-24 05:41:51 +00:00
|
|
|
#include "window/window_main_menu.h"
|
2017-12-19 16:57:42 +00:00
|
|
|
#include "storage/storage_media_prepare.h"
|
2020-06-09 16:57:05 +00:00
|
|
|
#include "storage/storage_account.h"
|
2021-05-25 20:38:01 +00:00
|
|
|
#include "storage/storage_domain.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_user.h"
|
2019-04-18 09:31:16 +00:00
|
|
|
#include "data/data_folder.h"
|
2022-09-20 18:12:30 +00:00
|
|
|
#include "data/data_forum.h"
|
|
|
|
#include "data/data_forum_topic.h"
|
2020-02-21 12:57:06 +00:00
|
|
|
#include "data/data_histories.h"
|
2020-06-12 14:09:04 +00:00
|
|
|
#include "data/data_changes.h"
|
2022-02-22 13:58:55 +00:00
|
|
|
#include "data/data_download_manager.h"
|
2022-09-14 05:13:28 +00:00
|
|
|
#include "data/data_chat_filters.h"
|
2022-02-24 15:12:55 +00:00
|
|
|
#include "info/downloads/info_downloads_widget.h"
|
|
|
|
#include "info/info_memento.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
2018-01-04 17:15:04 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2019-04-26 14:07:44 +00:00
|
|
|
#include "styles/style_info.h"
|
2018-01-04 17:15:04 +00:00
|
|
|
#include "styles/style_window.h"
|
2022-01-24 16:33:30 +00:00
|
|
|
#include "base/qt/qt_common_adapters.h"
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtCore/QMimeData>
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
namespace Dialogs {
|
2017-08-06 17:32:05 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
QString SwitchToChooseFromQuery() {
|
|
|
|
return qsl("from:");
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
class Widget::BottomButton : public Ui::RippleButton {
|
2017-08-01 12:01:42 +00:00
|
|
|
public:
|
2018-11-09 13:54:34 +00:00
|
|
|
BottomButton(
|
|
|
|
QWidget *parent,
|
|
|
|
const QString &text,
|
|
|
|
const style::FlatButton &st,
|
|
|
|
const style::icon &icon,
|
|
|
|
const style::icon &iconOver);
|
|
|
|
|
|
|
|
void setText(const QString &text);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
|
|
|
|
|
|
|
private:
|
2019-04-01 17:44:54 +00:00
|
|
|
void radialAnimationCallback();
|
2018-11-09 13:54:34 +00:00
|
|
|
|
2017-08-01 12:01:42 +00:00
|
|
|
QString _text;
|
|
|
|
const style::FlatButton &_st;
|
2018-11-09 13:54:34 +00:00
|
|
|
const style::icon &_icon;
|
|
|
|
const style::icon &_iconOver;
|
|
|
|
std::unique_ptr<Ui::InfiniteRadialAnimation> _loading;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
Widget::BottomButton::BottomButton(
|
2018-11-09 13:54:34 +00:00
|
|
|
QWidget *parent,
|
|
|
|
const QString &text,
|
|
|
|
const style::FlatButton &st,
|
|
|
|
const style::icon &icon,
|
|
|
|
const style::icon &iconOver)
|
|
|
|
: RippleButton(parent, st.ripple)
|
|
|
|
, _text(text.toUpper())
|
|
|
|
, _st(st)
|
|
|
|
, _icon(icon)
|
|
|
|
, _iconOver(iconOver) {
|
2017-11-12 16:50:58 +00:00
|
|
|
resize(st::columnMinimalWidthLeft, _st.height);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::BottomButton::setText(const QString &text) {
|
2018-11-09 13:54:34 +00:00
|
|
|
_text = text.toUpper();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::BottomButton::radialAnimationCallback() {
|
2019-04-01 17:44:54 +00:00
|
|
|
if (!anim::Disabled() && width() < st::columnMinimalWidthLeft) {
|
2018-11-09 13:54:34 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::BottomButton::onStateChanged(State was, StateChangeSource source) {
|
2017-08-01 12:01:42 +00:00
|
|
|
RippleButton::onStateChanged(was, source);
|
2018-11-09 13:54:34 +00:00
|
|
|
if ((was & StateFlag::Disabled) != (state() & StateFlag::Disabled)) {
|
|
|
|
_loading = isDisabled()
|
|
|
|
? std::make_unique<Ui::InfiniteRadialAnimation>(
|
2019-04-01 17:44:54 +00:00
|
|
|
[=] { radialAnimationCallback(); },
|
2018-11-09 13:54:34 +00:00
|
|
|
st::dialogsLoadMoreLoading)
|
|
|
|
: nullptr;
|
|
|
|
if (_loading) {
|
|
|
|
_loading->start();
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::BottomButton::paintEvent(QPaintEvent *e) {
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(this);
|
2018-11-09 13:54:34 +00:00
|
|
|
|
|
|
|
const auto over = isOver() && !isDisabled();
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
QRect r(0, height() - _st.height, width(), _st.height);
|
2018-11-09 13:54:34 +00:00
|
|
|
p.fillRect(r, over ? _st.overBgColor : _st.bgColor);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2018-11-09 13:54:34 +00:00
|
|
|
if (!isDisabled()) {
|
2019-04-02 09:13:30 +00:00
|
|
|
paintRipple(p, 0, 0);
|
2018-11-09 13:54:34 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2018-11-09 13:54:34 +00:00
|
|
|
p.setFont(over ? _st.overFont : _st.font);
|
2017-08-01 12:01:42 +00:00
|
|
|
p.setRenderHint(QPainter::TextAntialiasing);
|
2018-11-09 13:54:34 +00:00
|
|
|
p.setPen(over ? _st.overColor : _st.color);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2017-11-12 16:50:58 +00:00
|
|
|
if (width() >= st::columnMinimalWidthLeft) {
|
2017-08-01 12:01:42 +00:00
|
|
|
r.setTop(_st.textTop);
|
|
|
|
p.drawText(r, _text, style::al_top);
|
2018-11-09 13:54:34 +00:00
|
|
|
} else if (isDisabled() && _loading) {
|
|
|
|
_loading->draw(
|
|
|
|
p,
|
|
|
|
QPoint(
|
|
|
|
(width() - st::dialogsLoadMoreLoading.size.width()) / 2,
|
|
|
|
(height() - st::dialogsLoadMoreLoading.size.height()) / 2),
|
|
|
|
width());
|
2017-08-01 12:01:42 +00:00
|
|
|
} else {
|
2018-11-09 13:54:34 +00:00
|
|
|
(over ? _iconOver : _icon).paintInCenter(p, r);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
2021-08-26 13:25:48 +00:00
|
|
|
: Window::AbstractSectionWidget(parent, controller, nullptr)
|
2020-07-02 07:13:50 +00:00
|
|
|
, _api(&controller->session().mtp())
|
2022-03-14 15:48:39 +00:00
|
|
|
, _chooseByDragTimer([=] { _inner->chooseRow(); })
|
2019-04-24 10:15:10 +00:00
|
|
|
, _searchControls(this)
|
|
|
|
, _mainMenuToggle(_searchControls, st::dialogsMenuToggle)
|
2020-03-18 12:14:45 +00:00
|
|
|
, _searchForNarrowFilters(_searchControls, st::dialogsSearchForNarrowFilters)
|
2019-06-18 14:07:45 +00:00
|
|
|
, _filter(_searchControls, st::dialogsFilter, tr::lng_dlg_filter())
|
2017-09-30 18:26:45 +00:00
|
|
|
, _chooseFromUser(
|
2019-04-24 10:15:10 +00:00
|
|
|
_searchControls,
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::IconButton>(this, st::dialogsSearchFrom))
|
|
|
|
, _jumpToDate(
|
2019-04-24 10:15:10 +00:00
|
|
|
_searchControls,
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<Ui::IconButton>(this, st::dialogsCalendar))
|
2019-04-24 10:15:10 +00:00
|
|
|
, _cancelSearch(_searchControls, st::dialogsCancelSearch)
|
|
|
|
, _lockUnlock(_searchControls, st::dialogsLock)
|
2021-04-23 11:07:12 +00:00
|
|
|
, _scroll(this)
|
2019-08-06 14:43:26 +00:00
|
|
|
, _scrollToTop(_scroll, st::dialogsToUp)
|
2022-03-14 15:48:39 +00:00
|
|
|
, _searchTimer([=] { searchMessages(); })
|
2019-08-06 14:43:26 +00:00
|
|
|
, _singleMessageSearch(&controller->session()) {
|
2019-04-24 10:15:10 +00:00
|
|
|
_inner = _scroll->setOwnedWidget(object_ptr<InnerWidget>(this, controller));
|
2019-04-16 16:28:41 +00:00
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
_inner->updated(
|
|
|
|
) | rpl::start_with_next([=] {
|
2022-03-14 15:48:39 +00:00
|
|
|
listScrollUpdated();
|
2020-06-12 12:12:34 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2019-04-16 16:28:41 +00:00
|
|
|
rpl::combine(
|
|
|
|
session().api().dialogsLoadMayBlockByDate(),
|
|
|
|
session().api().dialogsLoadBlockedByDate()
|
|
|
|
) | rpl::start_with_next([=](bool mayBlock, bool isBlocked) {
|
|
|
|
refreshLoadMoreButton(mayBlock, isBlocked);
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-06-12 14:09:04 +00:00
|
|
|
session().changes().historyUpdates(
|
|
|
|
Data::HistoryUpdate::Flag::MessageSent
|
2020-06-12 12:12:34 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
jumpToTop();
|
|
|
|
}, lifetime());
|
|
|
|
|
2019-06-17 13:29:07 +00:00
|
|
|
fullSearchRefreshOn(session().settings().skipArchiveInSearchChanges(
|
2020-06-21 16:25:29 +00:00
|
|
|
) | rpl::to_empty);
|
2019-06-17 13:29:07 +00:00
|
|
|
|
2022-03-14 15:18:10 +00:00
|
|
|
_inner->scrollByDeltaRequests(
|
|
|
|
) | rpl::start_with_next([=](int delta) {
|
|
|
|
if (_scroll) {
|
|
|
|
_scroll->scrollToY(_scroll->scrollTop() + delta);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
2022-03-14 12:02:57 +00:00
|
|
|
_inner->mustScrollTo(
|
|
|
|
) | rpl::start_with_next([=](const Ui::ScrollToRequest &data) {
|
2021-10-02 13:03:26 +00:00
|
|
|
if (_scroll) {
|
2022-03-14 12:02:57 +00:00
|
|
|
_scroll->scrollToY(data.ymin, data.ymax);
|
2021-10-02 13:03:26 +00:00
|
|
|
}
|
2022-03-14 12:02:57 +00:00
|
|
|
}, lifetime());
|
|
|
|
_inner->dialogMoved(
|
|
|
|
) | rpl::start_with_next([=](const Ui::ScrollToRequest &data) {
|
|
|
|
const auto movedFrom = data.ymin;
|
|
|
|
const auto movedTo = data.ymax;
|
|
|
|
const auto st = int32(_scroll->scrollTop());
|
|
|
|
if (st > movedTo && st < movedFrom) {
|
|
|
|
_scroll->scrollToY(st + st::dialogsRowHeight);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
_inner->searchMessages(
|
|
|
|
) | rpl::start_with_next([=] {
|
2022-03-14 15:48:39 +00:00
|
|
|
needSearchMessages();
|
2022-03-14 12:02:57 +00:00
|
|
|
}, lifetime());
|
|
|
|
_inner->cancelSearchInChatRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
2022-03-14 15:48:39 +00:00
|
|
|
cancelSearchInChat();
|
2022-03-14 12:02:57 +00:00
|
|
|
}, lifetime());
|
|
|
|
_inner->completeHashtagRequests(
|
|
|
|
) | rpl::start_with_next([=](const QString &tag) {
|
2022-03-14 15:48:39 +00:00
|
|
|
completeHashtag(tag);
|
2022-03-14 12:02:57 +00:00
|
|
|
}, lifetime());
|
|
|
|
_inner->refreshHashtagsRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
2022-03-14 15:48:39 +00:00
|
|
|
filterCursorMoved();
|
2022-03-14 12:02:57 +00:00
|
|
|
}, lifetime());
|
2021-05-25 10:44:30 +00:00
|
|
|
_inner->cancelSearchFromUserRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
setSearchInChat(_searchInChat, nullptr);
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate(true);
|
2021-05-25 10:44:30 +00:00
|
|
|
}, lifetime());
|
2019-04-24 10:15:10 +00:00
|
|
|
_inner->chosenRow(
|
|
|
|
) | rpl::start_with_next([=](const ChosenRow &row) {
|
2022-09-26 13:37:32 +00:00
|
|
|
chosenRow(row);
|
2019-04-24 10:15:10 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2021-09-29 16:01:12 +00:00
|
|
|
_scroll->geometryChanged(
|
|
|
|
) | rpl::start_with_next(crl::guard(_inner, [=] {
|
2022-03-14 12:02:57 +00:00
|
|
|
_inner->parentGeometryChanged();
|
2021-09-29 16:01:12 +00:00
|
|
|
}), lifetime());
|
2021-10-02 13:03:26 +00:00
|
|
|
_scroll->scrolls(
|
|
|
|
) | rpl::start_with_next([=] {
|
2022-03-14 15:48:39 +00:00
|
|
|
listScrollUpdated();
|
2021-10-02 13:03:26 +00:00
|
|
|
}, lifetime());
|
2019-04-18 11:31:30 +00:00
|
|
|
|
2019-04-18 08:28:43 +00:00
|
|
|
session().data().chatsListChanges(
|
|
|
|
) | rpl::filter([=](Data::Folder *folder) {
|
|
|
|
return (folder == _inner->shownFolder());
|
|
|
|
}) | rpl::start_with_next([=] {
|
2022-03-14 15:48:39 +00:00
|
|
|
Ui::PostponeCall(this, [=] { listScrollUpdated(); });
|
2019-04-18 08:28:43 +00:00
|
|
|
}, lifetime());
|
2019-04-18 11:31:30 +00:00
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
QObject::connect(_filter, &Ui::FlatInput::cancelled, [=] {
|
2019-05-01 12:09:16 +00:00
|
|
|
escape();
|
2018-12-29 08:11:54 +00:00
|
|
|
});
|
2022-03-14 15:48:39 +00:00
|
|
|
QObject::connect(_filter, &Ui::FlatInput::changed, [=] {
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate();
|
|
|
|
});
|
2022-03-14 15:48:39 +00:00
|
|
|
QObject::connect(
|
2018-12-29 08:11:54 +00:00
|
|
|
_filter,
|
|
|
|
&Ui::FlatInput::cursorPositionChanged,
|
2022-03-14 15:48:39 +00:00
|
|
|
[=](int from, int to) { filterCursorMoved(from, to); });
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2018-07-11 22:14:44 +00:00
|
|
|
if (!Core::UpdaterDisabled()) {
|
|
|
|
Core::UpdateChecker checker;
|
|
|
|
rpl::merge(
|
2022-03-11 05:55:21 +00:00
|
|
|
rpl::single(rpl::empty),
|
2018-07-11 22:14:44 +00:00
|
|
|
checker.isLatest(),
|
|
|
|
checker.failed(),
|
|
|
|
checker.ready()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
checkUpdateStatus();
|
|
|
|
}, lifetime());
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2021-06-24 05:33:52 +00:00
|
|
|
controller->adaptive().changes(
|
2021-05-26 21:00:12 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateForwardBar();
|
|
|
|
}, lifetime());
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
_cancelSearch->setClickedCallback([this] { cancelSearch(); });
|
2021-11-16 07:26:35 +00:00
|
|
|
_jumpToDate->entity()->setClickedCallback([this] { showCalendar(); });
|
2017-08-01 15:55:51 +00:00
|
|
|
_chooseFromUser->entity()->setClickedCallback([this] { showSearchFrom(); });
|
2022-03-11 05:55:21 +00:00
|
|
|
rpl::single(rpl::empty) | rpl::then(
|
2021-05-25 20:38:01 +00:00
|
|
|
session().domain().local().localPasscodeChanged()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateLockUnlockVisibility();
|
|
|
|
}, lifetime());
|
2017-08-01 12:01:42 +00:00
|
|
|
_lockUnlock->setClickedCallback([this] {
|
|
|
|
_lockUnlock->setIconOverride(&st::dialogsUnlockIcon, &st::dialogsUnlockIconOver);
|
2019-01-21 13:42:21 +00:00
|
|
|
Core::App().lockByPasscode();
|
2017-08-01 12:01:42 +00:00
|
|
|
_lockUnlock->setIconOverride(nullptr);
|
|
|
|
});
|
2020-07-24 05:41:51 +00:00
|
|
|
|
|
|
|
setupMainMenuToggle();
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
_searchForNarrowFilters->setClickedCallback([=] { Ui::showChatsList(&session()); });
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
setAcceptDrops(true);
|
|
|
|
|
2019-04-16 16:28:41 +00:00
|
|
|
_inner->setLoadMoreCallback([=] {
|
2018-01-07 12:04:34 +00:00
|
|
|
const auto state = _inner->state();
|
2019-04-24 10:15:10 +00:00
|
|
|
if (state == WidgetState::Filtered
|
2019-04-16 16:28:41 +00:00
|
|
|
&& (!_inner->waitingForSearch()
|
|
|
|
|| (_searchInMigrated
|
|
|
|
&& _searchFull
|
|
|
|
&& !_searchFullMigrated))) {
|
2022-03-14 15:48:39 +00:00
|
|
|
searchMore();
|
2022-09-20 18:12:30 +00:00
|
|
|
} else if (_openedForum) {
|
|
|
|
_openedForum->forum()->requestTopics();
|
2017-08-01 12:01:42 +00:00
|
|
|
} else {
|
2019-04-19 08:47:49 +00:00
|
|
|
const auto folder = _inner->shownFolder();
|
2020-03-16 10:20:18 +00:00
|
|
|
if (!folder || !folder->chatsList()->loaded()) {
|
2019-04-22 14:22:39 +00:00
|
|
|
session().api().requestDialogs(folder);
|
2019-04-19 08:47:49 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
});
|
2018-12-29 13:09:45 +00:00
|
|
|
_inner->listBottomReached(
|
|
|
|
) | rpl::start_with_next([=] {
|
2019-04-16 16:28:41 +00:00
|
|
|
loadMoreBlockedByDate();
|
2018-12-29 13:09:45 +00:00
|
|
|
}, lifetime());
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
_filter->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
_filter->customUpDown(true);
|
|
|
|
|
|
|
|
updateJumpToDateVisibility(true);
|
2017-08-01 15:55:51 +00:00
|
|
|
updateSearchFromVisibility(true);
|
2018-05-07 17:44:33 +00:00
|
|
|
setupConnectingWidget();
|
2018-12-30 08:40:25 +00:00
|
|
|
setupSupportMode();
|
2019-04-05 08:28:07 +00:00
|
|
|
setupScrollUpButton();
|
2019-04-24 10:15:10 +00:00
|
|
|
|
|
|
|
changeOpenedFolder(
|
|
|
|
controller->openedFolder().current(),
|
|
|
|
anim::type::instant);
|
|
|
|
|
|
|
|
controller->openedFolder().changes(
|
|
|
|
) | rpl::start_with_next([=](Data::Folder *folder) {
|
|
|
|
changeOpenedFolder(folder, anim::type::normal);
|
|
|
|
}, lifetime());
|
2022-02-22 13:58:55 +00:00
|
|
|
|
2022-09-20 09:35:47 +00:00
|
|
|
changeOpenedForum(
|
|
|
|
controller->openedForum().current(),
|
|
|
|
anim::type::instant);
|
|
|
|
|
|
|
|
controller->openedForum().changes(
|
|
|
|
) | rpl::start_with_next([=](ChannelData *forum) {
|
|
|
|
changeOpenedForum(forum, anim::type::normal);
|
|
|
|
}, lifetime());
|
|
|
|
|
2022-02-22 13:58:55 +00:00
|
|
|
setupDownloadBar();
|
2019-04-05 08:28:07 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 13:37:32 +00:00
|
|
|
void Widget::chosenRow(const ChosenRow &row) {
|
|
|
|
const auto openSearchResult = !controller()->selectingPeer()
|
|
|
|
&& row.filteredRow;
|
|
|
|
const auto history = row.key.history();
|
|
|
|
if (const auto topic = row.key.topic()) {
|
|
|
|
controller()->showRepliesForMessage(
|
2022-09-27 16:52:35 +00:00
|
|
|
topic->history(),
|
2022-09-27 12:05:47 +00:00
|
|
|
topic->rootId(),
|
|
|
|
ShowAtUnreadMsgId,
|
|
|
|
Window::SectionShow::Way::ClearStack);
|
2022-09-26 13:37:32 +00:00
|
|
|
} else if (history && history->peer->isForum()) {
|
|
|
|
controller()->openForum(history->peer->asChannel());
|
|
|
|
} else if (history) {
|
|
|
|
const auto peer = history->peer;
|
|
|
|
const auto showAtMsgId = controller()->uniqueChatsInSearchResults()
|
|
|
|
? ShowAtUnreadMsgId
|
|
|
|
: row.message.fullId.msg;
|
|
|
|
if (row.newWindow && controller()->canShowSeparateWindow(peer)) {
|
|
|
|
const auto active = controller()->activeChatCurrent();
|
|
|
|
const auto fromActive = active.history()
|
|
|
|
? (active.history()->peer == peer)
|
|
|
|
: false;
|
|
|
|
const auto toSeparate = [=] {
|
|
|
|
Core::App().ensureSeparateWindowForPeer(
|
|
|
|
peer,
|
|
|
|
showAtMsgId);
|
|
|
|
};
|
|
|
|
if (fromActive) {
|
|
|
|
controller()->window().preventOrInvoke([=] {
|
|
|
|
controller()->content()->ui_showPeerHistory(
|
|
|
|
0,
|
|
|
|
Window::SectionShow::Way::ClearStack,
|
|
|
|
0);
|
|
|
|
toSeparate();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
toSeparate();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
controller()->content()->choosePeer(peer->id, showAtMsgId);
|
|
|
|
}
|
|
|
|
} else if (const auto folder = row.key.folder()) {
|
|
|
|
controller()->openFolder(folder);
|
|
|
|
}
|
|
|
|
if (openSearchResult && !session().supportMode()) {
|
|
|
|
escape();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 09:41:03 +00:00
|
|
|
void Widget::setGeometryWithTopMoved(
|
|
|
|
const QRect &newGeometry,
|
|
|
|
int topDelta) {
|
|
|
|
_topDelta = topDelta;
|
|
|
|
bool willBeResized = (size() != newGeometry.size());
|
|
|
|
if (geometry() != newGeometry) {
|
|
|
|
auto weak = Ui::MakeWeak(this);
|
|
|
|
setGeometry(newGeometry);
|
|
|
|
if (!weak) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!willBeResized) {
|
|
|
|
resizeEvent(nullptr);
|
|
|
|
}
|
|
|
|
_topDelta = 0;
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::setupScrollUpButton() {
|
2019-04-05 08:28:07 +00:00
|
|
|
_scrollToTop->setClickedCallback([=] {
|
|
|
|
if (_scrollToAnimation.animating()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
scrollToTop();
|
|
|
|
});
|
2019-09-19 09:28:36 +00:00
|
|
|
base::install_event_filter(_scrollToTop, [=](not_null<QEvent*> event) {
|
2019-09-05 10:51:36 +00:00
|
|
|
if (event->type() != QEvent::Wheel) {
|
2019-09-19 09:28:36 +00:00
|
|
|
return base::EventFilterResult::Continue;
|
2019-04-05 08:28:07 +00:00
|
|
|
}
|
2019-09-05 10:51:36 +00:00
|
|
|
return _scroll->viewportEvent(event)
|
2019-09-19 09:28:36 +00:00
|
|
|
? base::EventFilterResult::Cancel
|
|
|
|
: base::EventFilterResult::Continue;
|
2019-04-05 08:28:07 +00:00
|
|
|
});
|
|
|
|
updateScrollUpVisibility();
|
|
|
|
}
|
|
|
|
|
2022-02-22 13:58:55 +00:00
|
|
|
void Widget::setupDownloadBar() {
|
|
|
|
Data::MakeDownloadBarContent(
|
|
|
|
) | rpl::start_with_next([=](Ui::DownloadBarContent &&content) {
|
|
|
|
const auto create = (content.count && !_downloadBar);
|
|
|
|
if (create) {
|
|
|
|
_downloadBar = std::make_unique<Ui::DownloadBar>(
|
|
|
|
this,
|
|
|
|
Data::MakeDownloadBarProgress());
|
|
|
|
}
|
|
|
|
if (_downloadBar) {
|
|
|
|
_downloadBar->show(std::move(content));
|
|
|
|
}
|
|
|
|
if (create) {
|
|
|
|
_downloadBar->heightValue(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}, _downloadBar->lifetime());
|
|
|
|
|
|
|
|
_downloadBar->shownValue(
|
|
|
|
) | rpl::filter(
|
|
|
|
!rpl::mappers::_1
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_downloadBar = nullptr;
|
2022-03-04 11:37:50 +00:00
|
|
|
updateControlsGeometry();
|
2022-02-22 13:58:55 +00:00
|
|
|
}, _downloadBar->lifetime());
|
|
|
|
|
|
|
|
_downloadBar->clicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto &&list = Core::App().downloadManager().loadingList();
|
2022-02-27 11:27:19 +00:00
|
|
|
const auto guard = gsl::finally([] {
|
|
|
|
Core::App().downloadManager().clearIfFinished();
|
|
|
|
});
|
2022-02-24 15:12:55 +00:00
|
|
|
auto first = (HistoryItem*)nullptr;
|
2022-02-26 11:51:54 +00:00
|
|
|
for (const auto id : list) {
|
2022-02-24 15:12:55 +00:00
|
|
|
if (!first) {
|
2022-02-26 11:51:54 +00:00
|
|
|
first = id->object.item;
|
2022-02-24 15:12:55 +00:00
|
|
|
} else {
|
|
|
|
controller()->showSection(
|
|
|
|
Info::Downloads::Make(
|
|
|
|
controller()->session().user()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (first) {
|
|
|
|
controller()->showPeerHistoryAtItem(first);
|
2022-02-22 13:58:55 +00:00
|
|
|
}
|
|
|
|
}, _downloadBar->lifetime());
|
|
|
|
|
|
|
|
if (_connecting) {
|
|
|
|
_connecting->raise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateScrollUpVisibility() {
|
2019-04-05 08:28:07 +00:00
|
|
|
if (_scrollToAnimation.animating()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
startScrollUpButtonAnimation(
|
2019-12-15 23:07:22 +00:00
|
|
|
(_scroll->scrollTop() > st::historyToDownShownAfter)
|
|
|
|
&& (_scroll->scrollTop() < _scroll->scrollTopMax()));
|
2019-04-05 08:28:07 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::startScrollUpButtonAnimation(bool shown) {
|
2019-04-05 20:42:10 +00:00
|
|
|
const auto smallColumn = (width() < st::columnMinimalWidthLeft);
|
|
|
|
shown &= !smallColumn;
|
2019-04-05 08:28:07 +00:00
|
|
|
if (_scrollToTopIsShown == shown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_scrollToTopIsShown = shown;
|
|
|
|
_scrollToTopShown.start(
|
|
|
|
[=] { updateScrollUpPosition(); },
|
|
|
|
_scrollToTopIsShown ? 0. : 1.,
|
|
|
|
_scrollToTopIsShown ? 1. : 0.,
|
2019-04-05 20:42:10 +00:00
|
|
|
smallColumn ? 0 : st::historyToDownDuration);
|
2019-04-05 08:28:07 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateScrollUpPosition() {
|
2019-04-05 08:28:07 +00:00
|
|
|
// _scrollToTop is a child widget of _scroll, not me.
|
|
|
|
auto top = anim::interpolate(
|
|
|
|
0,
|
2019-04-05 21:24:56 +00:00
|
|
|
_scrollToTop->height() + st::connectingMargin.top(),
|
2019-04-05 08:28:07 +00:00
|
|
|
_scrollToTopShown.value(_scrollToTopIsShown ? 1. : 0.));
|
|
|
|
_scrollToTop->moveToRight(
|
|
|
|
st::historyToDownPosition.x(),
|
|
|
|
_scroll->height() - top);
|
|
|
|
const auto shouldBeHidden =
|
|
|
|
!_scrollToTopIsShown && !_scrollToTopShown.animating();
|
|
|
|
if (shouldBeHidden != _scrollToTop->isHidden()) {
|
|
|
|
_scrollToTop->setVisible(!shouldBeHidden);
|
|
|
|
}
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::setupConnectingWidget() {
|
2019-02-10 16:29:55 +00:00
|
|
|
_connecting = std::make_unique<Window::ConnectionState>(
|
2018-05-07 17:44:33 +00:00
|
|
|
this,
|
2020-06-10 14:52:44 +00:00
|
|
|
&session().account(),
|
2021-05-26 21:00:12 +00:00
|
|
|
controller()->adaptive().oneColumnValue());
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::setupSupportMode() {
|
2019-04-16 14:05:56 +00:00
|
|
|
if (!session().supportMode()) {
|
2018-11-09 13:54:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-30 08:40:25 +00:00
|
|
|
|
2019-06-17 13:29:07 +00:00
|
|
|
fullSearchRefreshOn(session().settings().supportAllSearchResultsValue(
|
2020-06-21 16:25:29 +00:00
|
|
|
) | rpl::to_empty);
|
2019-06-17 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 05:41:51 +00:00
|
|
|
void Widget::setupMainMenuToggle() {
|
|
|
|
_mainMenuToggle->setClickedCallback([=] { showMainMenu(); });
|
|
|
|
|
2022-03-11 05:55:21 +00:00
|
|
|
rpl::single(rpl::empty) | rpl::then(
|
2020-07-24 05:41:51 +00:00
|
|
|
controller()->filtersMenuChanged()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto filtersHidden = !controller()->filtersWidth();
|
|
|
|
_mainMenuToggle->setVisible(filtersHidden);
|
|
|
|
_searchForNarrowFilters->setVisible(!filtersHidden);
|
|
|
|
updateControlsGeometry();
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
Window::OtherAccountsUnreadState(
|
|
|
|
) | rpl::start_with_next([=](const Window::OthersUnreadState &state) {
|
|
|
|
const auto icon = !state.count
|
|
|
|
? nullptr
|
|
|
|
: !state.allMuted
|
|
|
|
? &st::dialogsMenuToggleUnread
|
|
|
|
: &st::dialogsMenuToggleUnreadMuted;
|
|
|
|
_mainMenuToggle->setIconOverride(icon, icon);
|
|
|
|
}, _mainMenuToggle->lifetime());
|
|
|
|
}
|
|
|
|
|
2019-06-17 13:29:07 +00:00
|
|
|
void Widget::fullSearchRefreshOn(rpl::producer<> events) {
|
|
|
|
std::move(
|
|
|
|
events
|
2018-12-30 08:40:25 +00:00
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !_searchQuery.isEmpty();
|
|
|
|
}) | rpl::start_with_next([=] {
|
2022-03-14 15:48:39 +00:00
|
|
|
_searchTimer.cancel();
|
2018-12-30 08:40:25 +00:00
|
|
|
_searchCache.clear();
|
2019-08-06 14:43:26 +00:00
|
|
|
_singleMessageSearch.clear();
|
2020-07-02 07:13:50 +00:00
|
|
|
for (const auto &[requestId, query] : base::take(_searchQueries)) {
|
|
|
|
session().api().request(requestId).cancel();
|
|
|
|
}
|
2018-12-30 08:40:25 +00:00
|
|
|
_searchQuery = QString();
|
|
|
|
_scroll->scrollToY(0);
|
2020-02-21 12:57:06 +00:00
|
|
|
cancelSearchRequest();
|
2022-03-14 15:48:39 +00:00
|
|
|
searchMessages();
|
2018-12-30 08:40:25 +00:00
|
|
|
}, lifetime());
|
2018-11-09 13:54:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateControlsVisibility(bool fast) {
|
|
|
|
updateLoadMoreChatsVisibility();
|
|
|
|
_scroll->show();
|
|
|
|
if (_forwardCancel) {
|
|
|
|
_forwardCancel->show();
|
|
|
|
}
|
2022-09-20 09:35:47 +00:00
|
|
|
if ((_openedFolder || _openedForum) && _filter->hasFocus()) {
|
2019-04-24 10:15:10 +00:00
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
if (_updateTelegram) {
|
|
|
|
_updateTelegram->show();
|
|
|
|
}
|
2022-09-20 09:35:47 +00:00
|
|
|
_searchControls->setVisible(!_openedFolder && !_openedForum);
|
|
|
|
if (_openedFolder || _openedForum) {
|
2019-04-24 14:12:35 +00:00
|
|
|
_folderTopBar->show();
|
|
|
|
} else {
|
2019-04-24 10:15:10 +00:00
|
|
|
if (hasFocus()) {
|
|
|
|
_filter->setFocus();
|
|
|
|
_filter->finishAnimations();
|
|
|
|
}
|
|
|
|
updateLockUnlockVisibility();
|
|
|
|
updateJumpToDateVisibility(fast);
|
|
|
|
updateSearchFromVisibility(fast);
|
|
|
|
}
|
|
|
|
_connecting->setForceHidden(false);
|
|
|
|
}
|
|
|
|
|
2022-09-20 09:35:47 +00:00
|
|
|
void Widget::changeOpenedSubsection(
|
|
|
|
FnMut<void()> change,
|
|
|
|
bool fromRight,
|
|
|
|
anim::type animated) {
|
2019-04-24 10:15:10 +00:00
|
|
|
_a_show.stop();
|
2020-06-03 08:31:15 +00:00
|
|
|
|
|
|
|
if (isHidden()) {
|
|
|
|
animated = anim::type::instant;
|
|
|
|
}
|
2019-04-24 10:15:10 +00:00
|
|
|
if (animated == anim::type::normal) {
|
2022-09-20 09:35:47 +00:00
|
|
|
_showDirection = fromRight
|
2019-04-24 10:15:10 +00:00
|
|
|
? Window::SlideDirection::FromRight
|
|
|
|
: Window::SlideDirection::FromLeft;
|
|
|
|
_showAnimationType = ShowAnimation::Internal;
|
|
|
|
_connecting->setForceHidden(true);
|
|
|
|
_cacheUnder = grabForFolderSlideAnimation();
|
|
|
|
}
|
2022-09-20 09:35:47 +00:00
|
|
|
change();
|
2019-04-24 14:12:35 +00:00
|
|
|
refreshFolderTopBar();
|
2019-04-24 10:15:10 +00:00
|
|
|
updateControlsVisibility(true);
|
|
|
|
if (animated == anim::type::normal) {
|
|
|
|
_connecting->setForceHidden(true);
|
|
|
|
_cacheOver = grabForFolderSlideAnimation();
|
|
|
|
_connecting->setForceHidden(false);
|
|
|
|
startSlideAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-20 09:35:47 +00:00
|
|
|
void Widget::changeOpenedFolder(Data::Folder *folder, anim::type animated) {
|
|
|
|
changeOpenedSubsection([&] {
|
|
|
|
_openedFolder = folder;
|
|
|
|
_inner->changeOpenedFolder(folder);
|
|
|
|
}, (folder != nullptr), animated);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::changeOpenedForum(ChannelData *forum, anim::type animated) {
|
|
|
|
changeOpenedSubsection([&] {
|
|
|
|
_openedForum = forum;
|
|
|
|
_inner->changeOpenedForum(forum);
|
|
|
|
}, (forum != nullptr), animated);
|
|
|
|
}
|
|
|
|
|
2019-04-24 14:12:35 +00:00
|
|
|
void Widget::refreshFolderTopBar() {
|
2022-09-20 09:35:47 +00:00
|
|
|
if (_openedFolder || _openedForum) {
|
2019-04-24 14:12:35 +00:00
|
|
|
if (!_folderTopBar) {
|
|
|
|
_folderTopBar.create(this, controller());
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
2019-08-09 12:15:57 +00:00
|
|
|
_folderTopBar->setActiveChat(
|
2020-11-11 20:47:40 +00:00
|
|
|
HistoryView::TopBarWidget::ActiveChat{
|
2022-09-20 09:35:47 +00:00
|
|
|
.key = (_openedFolder
|
|
|
|
? Dialogs::Key(_openedFolder)
|
|
|
|
: Dialogs::Key(session().data().history(_openedForum))),
|
2020-11-12 15:46:17 +00:00
|
|
|
.section = Dialogs::EntryState::Section::ChatsList,
|
2020-11-11 20:47:40 +00:00
|
|
|
},
|
2020-09-29 08:36:30 +00:00
|
|
|
nullptr);
|
2019-04-24 14:12:35 +00:00
|
|
|
} else {
|
|
|
|
_folderTopBar.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
QPixmap Widget::grabForFolderSlideAnimation() {
|
|
|
|
const auto hidden = _scrollToTop->isHidden();
|
|
|
|
if (!hidden) {
|
|
|
|
_scrollToTop->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto top = _forwardCancel ? _forwardCancel->height() : 0;
|
|
|
|
const auto rect = QRect(
|
|
|
|
0,
|
|
|
|
top,
|
|
|
|
width(),
|
|
|
|
(_updateTelegram ? _updateTelegram->y() : height()) - top);
|
|
|
|
auto result = Ui::GrabWidget(this, rect);
|
|
|
|
|
|
|
|
if (!hidden) {
|
|
|
|
_scrollToTop->show();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::checkUpdateStatus() {
|
2018-07-11 22:14:44 +00:00
|
|
|
Expects(!Core::UpdaterDisabled());
|
|
|
|
|
2018-04-26 16:14:21 +00:00
|
|
|
using Checker = Core::UpdateChecker;
|
|
|
|
if (Checker().state() == Checker::State::Ready) {
|
2022-01-19 15:59:43 +00:00
|
|
|
if (_updateTelegram) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-09 13:54:34 +00:00
|
|
|
_updateTelegram.create(
|
|
|
|
this,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_update_telegram(tr::now),
|
2018-11-09 13:54:34 +00:00
|
|
|
st::dialogsUpdateButton,
|
|
|
|
st::dialogsInstallUpdate,
|
|
|
|
st::dialogsInstallUpdateOver);
|
2017-08-01 12:01:42 +00:00
|
|
|
_updateTelegram->show();
|
|
|
|
_updateTelegram->setClickedCallback([] {
|
2018-04-26 16:14:21 +00:00
|
|
|
Core::checkReadyUpdate();
|
2022-01-27 12:48:51 +00:00
|
|
|
Core::Restart();
|
2017-08-01 12:01:42 +00:00
|
|
|
});
|
2022-01-19 15:59:43 +00:00
|
|
|
if (_connecting) {
|
|
|
|
_connecting->raise();
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
} else {
|
2022-01-19 15:59:43 +00:00
|
|
|
if (!_updateTelegram) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
_updateTelegram.destroy();
|
|
|
|
}
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2019-04-24 14:12:35 +00:00
|
|
|
void Widget::setInnerFocus() {
|
2022-09-20 09:35:47 +00:00
|
|
|
if (_openedFolder || _openedForum) {
|
2019-04-24 10:15:10 +00:00
|
|
|
setFocus();
|
|
|
|
} else {
|
|
|
|
_filter->setFocus();
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::jumpToTop() {
|
2019-04-16 14:05:56 +00:00
|
|
|
if (session().supportMode()) {
|
2018-10-07 19:27:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-05 08:28:07 +00:00
|
|
|
if ((_filter->getLastText().trimmed().isEmpty() && !_searchInChat)) {
|
2019-04-11 09:08:23 +00:00
|
|
|
_scrollToAnimation.stop();
|
|
|
|
_scroll->scrollToY(0);
|
2019-04-05 08:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-24 17:19:16 +00:00
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::scrollToTop() {
|
2019-04-05 08:28:07 +00:00
|
|
|
_scrollToAnimation.stop();
|
|
|
|
auto scrollTop = _scroll->scrollTop();
|
|
|
|
const auto scrollTo = 0;
|
|
|
|
const auto maxAnimatedDelta = _scroll->height();
|
|
|
|
if (scrollTo + maxAnimatedDelta < scrollTop) {
|
|
|
|
scrollTop = scrollTo + maxAnimatedDelta;
|
|
|
|
_scroll->scrollToY(scrollTop);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2019-04-05 08:28:07 +00:00
|
|
|
|
|
|
|
startScrollUpButtonAnimation(false);
|
|
|
|
|
|
|
|
const auto scroll = [=] {
|
|
|
|
_scroll->scrollToY(qRound(_scrollToAnimation.value(scrollTo)));
|
|
|
|
};
|
|
|
|
|
|
|
|
_scrollToAnimation.start(
|
|
|
|
scroll,
|
|
|
|
scrollTop,
|
|
|
|
scrollTo,
|
|
|
|
st::slideDuration,
|
|
|
|
anim::sineInOut);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::startWidthAnimation() {
|
2017-08-01 12:01:42 +00:00
|
|
|
if (!_widthAnimationCache.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto scrollGeometry = _scroll->geometry();
|
2017-11-12 16:50:58 +00:00
|
|
|
auto grabGeometry = QRect(
|
|
|
|
scrollGeometry.x(),
|
|
|
|
scrollGeometry.y(),
|
|
|
|
st::columnMinimalWidthLeft,
|
|
|
|
scrollGeometry.height());
|
2017-08-01 12:01:42 +00:00
|
|
|
_scroll->setGeometry(grabGeometry);
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(_scroll);
|
2017-11-12 16:50:58 +00:00
|
|
|
auto image = QImage(
|
|
|
|
grabGeometry.size() * cIntRetinaFactor(),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
2017-08-01 12:01:42 +00:00
|
|
|
image.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
image.fill(Qt::transparent);
|
2019-04-26 09:43:57 +00:00
|
|
|
{
|
|
|
|
QPainter p(&image);
|
|
|
|
Ui::RenderWidget(p, _scroll);
|
|
|
|
}
|
2021-05-07 14:33:53 +00:00
|
|
|
_widthAnimationCache = Ui::PixmapFromImage(std::move(image));
|
2017-08-01 12:01:42 +00:00
|
|
|
_scroll->setGeometry(scrollGeometry);
|
|
|
|
_scroll->hide();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::stopWidthAnimation() {
|
2017-08-01 12:01:42 +00:00
|
|
|
_widthAnimationCache = QPixmap();
|
|
|
|
if (!_a_show.animating()) {
|
|
|
|
_scroll->show();
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::showFast() {
|
2019-04-24 14:12:35 +00:00
|
|
|
if (isHidden()) {
|
|
|
|
_inner->clearSelection();
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
show();
|
|
|
|
updateForwardBar();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::showAnimated(Window::SlideDirection direction, const Window::SectionSlideParams ¶ms) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_showDirection = direction;
|
2019-04-24 10:15:10 +00:00
|
|
|
_showAnimationType = ShowAnimation::External;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_show.stop();
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
_cacheUnder = params.oldContentCache;
|
2019-04-24 14:12:35 +00:00
|
|
|
showFast();
|
2020-06-10 18:08:17 +00:00
|
|
|
_cacheOver = controller()->content()->grabForShowAnimation(params);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
if (_updateTelegram) {
|
|
|
|
_updateTelegram->hide();
|
|
|
|
}
|
2018-05-07 17:44:33 +00:00
|
|
|
_connecting->setForceHidden(true);
|
2019-04-24 10:15:10 +00:00
|
|
|
startSlideAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::startSlideAnimation() {
|
|
|
|
_scroll->hide();
|
|
|
|
if (_forwardCancel) {
|
|
|
|
_forwardCancel->hide();
|
|
|
|
}
|
|
|
|
_searchControls->hide();
|
2019-04-24 14:12:35 +00:00
|
|
|
if (_folderTopBar) {
|
|
|
|
_folderTopBar->hide();
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
if (_showDirection == Window::SlideDirection::FromLeft) {
|
|
|
|
std::swap(_cacheUnder, _cacheOver);
|
|
|
|
}
|
2019-04-24 10:15:10 +00:00
|
|
|
_a_show.start([=] { animationCallback(); }, 0., 1., st::slideDuration, Window::SlideAnimation::transition());
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 14:17:37 +00:00
|
|
|
bool Widget::floatPlayerHandleWheelEvent(QEvent *e) {
|
2017-08-01 12:01:42 +00:00
|
|
|
return _scroll->viewportEvent(e);
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:17:37 +00:00
|
|
|
QRect Widget::floatPlayerAvailableRect() {
|
2017-08-01 12:01:42 +00:00
|
|
|
return mapToGlobal(_scroll->geometry());
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::animationCallback() {
|
2017-08-01 12:01:42 +00:00
|
|
|
update();
|
|
|
|
if (!_a_show.animating()) {
|
|
|
|
_cacheUnder = _cacheOver = QPixmap();
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
updateControlsVisibility(true);
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-05-26 12:49:12 +00:00
|
|
|
if (!_filter->hasFocus()) {
|
2021-02-03 03:31:11 +00:00
|
|
|
controller()->widget()->setInnerFocus();
|
2019-05-26 12:49:12 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-01 12:09:16 +00:00
|
|
|
void Widget::escape() {
|
2019-04-24 10:15:10 +00:00
|
|
|
if (controller()->openedFolder().current()) {
|
|
|
|
controller()->closeFolder();
|
2022-09-20 09:35:47 +00:00
|
|
|
} else if (controller()->openedForum().current()) {
|
|
|
|
controller()->closeForum();
|
2022-03-14 15:48:39 +00:00
|
|
|
} else if (!cancelSearch()) {
|
2020-03-23 10:08:54 +00:00
|
|
|
if (controller()->activeChatEntryCurrent().key) {
|
2022-01-04 13:13:00 +00:00
|
|
|
controller()->content()->dialogsCancelled();
|
2022-09-14 05:13:28 +00:00
|
|
|
} else {
|
|
|
|
const auto filters = &session().data().chatsFilters();
|
|
|
|
const auto &list = filters->list();
|
|
|
|
const auto first = list.empty() ? FilterId() : list.front().id();
|
|
|
|
if (controller()->activeChatsFilterCurrent() != first) {
|
|
|
|
controller()->setActiveChatsFilter(first);
|
|
|
|
}
|
2020-03-23 10:08:54 +00:00
|
|
|
}
|
2020-06-30 15:05:12 +00:00
|
|
|
} else if (!_searchInChat && !controller()->selectingPeer()) {
|
2020-03-27 08:39:47 +00:00
|
|
|
if (controller()->activeChatEntryCurrent().key) {
|
2022-01-04 13:13:00 +00:00
|
|
|
controller()->content()->dialogsCancelled();
|
2020-03-27 08:39:47 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::refreshLoadMoreButton(bool mayBlock, bool isBlocked) {
|
2019-04-16 16:28:41 +00:00
|
|
|
if (!mayBlock) {
|
2020-06-11 09:41:03 +00:00
|
|
|
if (_loadMoreChats) {
|
|
|
|
_loadMoreChats.destroy();
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
2018-11-09 13:54:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_loadMoreChats) {
|
|
|
|
_loadMoreChats.create(
|
|
|
|
this,
|
|
|
|
"Load more",
|
|
|
|
st::dialogsLoadMoreButton,
|
|
|
|
st::dialogsLoadMore,
|
|
|
|
st::dialogsLoadMore);
|
2019-04-30 10:21:56 +00:00
|
|
|
_loadMoreChats->show();
|
2018-11-09 13:54:34 +00:00
|
|
|
_loadMoreChats->addClickHandler([=] {
|
2019-04-16 16:28:41 +00:00
|
|
|
loadMoreBlockedByDate();
|
2018-11-09 13:54:34 +00:00
|
|
|
});
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
2019-04-16 16:28:41 +00:00
|
|
|
const auto loading = !isBlocked;
|
2018-11-09 13:54:34 +00:00
|
|
|
_loadMoreChats->setDisabled(loading);
|
|
|
|
_loadMoreChats->setText(loading ? "Loading..." : "Load more");
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::loadMoreBlockedByDate() {
|
2018-12-30 07:34:17 +00:00
|
|
|
if (!_loadMoreChats
|
|
|
|
|| _loadMoreChats->isDisabled()
|
|
|
|
|| _loadMoreChats->isHidden()) {
|
2018-12-29 13:09:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-16 16:28:41 +00:00
|
|
|
session().api().requestMoreBlockedByDateDialogs();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
bool Widget::searchMessages(bool searchCache) {
|
2018-03-08 13:15:56 +00:00
|
|
|
auto result = false;
|
2017-08-01 15:55:51 +00:00
|
|
|
auto q = _filter->getLastText().trimmed();
|
2020-10-06 12:58:16 +00:00
|
|
|
if (q.isEmpty() && !_searchFromAuthor) {
|
2020-02-21 12:57:06 +00:00
|
|
|
cancelSearchRequest();
|
2020-07-02 07:13:50 +00:00
|
|
|
_api.request(base::take(_peerSearchRequest)).cancel();
|
2017-08-01 12:01:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (searchCache) {
|
2019-08-06 14:43:26 +00:00
|
|
|
const auto success = _singleMessageSearch.lookup(q, [=] {
|
2022-03-14 15:48:39 +00:00
|
|
|
needSearchMessages();
|
2019-08-06 14:43:26 +00:00
|
|
|
});
|
|
|
|
if (!success) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-02 07:13:50 +00:00
|
|
|
const auto i = _searchCache.find(q);
|
|
|
|
if (i != _searchCache.end()) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_searchQuery = q;
|
2020-10-06 12:58:16 +00:00
|
|
|
_searchQueryFrom = _searchFromAuthor;
|
2019-05-20 19:04:24 +00:00
|
|
|
_searchNextRate = 0;
|
2017-08-01 12:01:42 +00:00
|
|
|
_searchFull = _searchFullMigrated = false;
|
2020-02-21 12:57:06 +00:00
|
|
|
cancelSearchRequest();
|
2018-01-22 10:58:11 +00:00
|
|
|
searchReceived(
|
2018-02-14 19:38:01 +00:00
|
|
|
_searchInChat
|
2019-04-24 10:15:10 +00:00
|
|
|
? SearchRequestType::PeerFromStart
|
|
|
|
: SearchRequestType::FromStart,
|
2020-07-02 07:13:50 +00:00
|
|
|
i->second,
|
2018-01-22 10:58:11 +00:00
|
|
|
0);
|
2018-03-08 13:15:56 +00:00
|
|
|
result = true;
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-10-06 12:58:16 +00:00
|
|
|
} else if (_searchQuery != q || _searchQueryFrom != _searchFromAuthor) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_searchQuery = q;
|
2020-10-06 12:58:16 +00:00
|
|
|
_searchQueryFrom = _searchFromAuthor;
|
2019-05-20 19:04:24 +00:00
|
|
|
_searchNextRate = 0;
|
2017-08-01 12:01:42 +00:00
|
|
|
_searchFull = _searchFullMigrated = false;
|
2020-02-21 12:57:06 +00:00
|
|
|
cancelSearchRequest();
|
2018-02-14 19:38:01 +00:00
|
|
|
if (const auto peer = _searchInChat.peer()) {
|
2020-02-21 12:57:06 +00:00
|
|
|
auto &histories = session().data().histories();
|
|
|
|
const auto type = Data::Histories::RequestType::History;
|
|
|
|
const auto history = session().data().history(peer);
|
|
|
|
_searchInHistoryRequest = histories.sendRequest(history, type, [=](Fn<void()> finish) {
|
|
|
|
const auto type = SearchRequestType::PeerFromStart;
|
|
|
|
const auto flags = _searchQueryFrom
|
|
|
|
? MTP_flags(MTPmessages_Search::Flag::f_from_id)
|
|
|
|
: MTP_flags(0);
|
|
|
|
_searchRequest = session().api().request(MTPmessages_Search(
|
2018-01-18 11:04:50 +00:00
|
|
|
flags,
|
2018-02-14 19:38:01 +00:00
|
|
|
peer->input,
|
2018-01-18 11:04:50 +00:00
|
|
|
MTP_string(_searchQuery),
|
2020-02-21 12:57:06 +00:00
|
|
|
(_searchQueryFrom
|
2020-10-06 12:58:16 +00:00
|
|
|
? _searchQueryFrom->input
|
|
|
|
: MTP_inputPeerEmpty()),
|
2020-09-01 06:44:18 +00:00
|
|
|
MTPint(), // top_msg_id
|
2018-01-18 11:04:50 +00:00
|
|
|
MTP_inputMessagesFilterEmpty(),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_int(0), // min_date
|
|
|
|
MTP_int(0), // max_date
|
|
|
|
MTP_int(0), // offset_id
|
|
|
|
MTP_int(0), // add_offset
|
2018-01-18 11:04:50 +00:00
|
|
|
MTP_int(SearchPerPage),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_int(0), // max_id
|
|
|
|
MTP_int(0), // min_id
|
|
|
|
MTP_long(0) // hash
|
2020-02-21 12:57:06 +00:00
|
|
|
)).done([=](const MTPmessages_Messages &result) {
|
2020-02-24 09:14:29 +00:00
|
|
|
_searchInHistoryRequest = 0;
|
2020-11-25 11:51:34 +00:00
|
|
|
searchReceived(type, result, _searchRequest);
|
2020-02-21 12:57:06 +00:00
|
|
|
finish();
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-02-24 09:14:29 +00:00
|
|
|
_searchInHistoryRequest = 0;
|
2020-11-25 11:51:34 +00:00
|
|
|
searchFailed(type, error, _searchRequest);
|
2020-02-21 12:57:06 +00:00
|
|
|
finish();
|
|
|
|
}).send();
|
2020-07-02 07:13:50 +00:00
|
|
|
_searchQueries.emplace(_searchRequest, _searchQuery);
|
2020-02-21 12:57:06 +00:00
|
|
|
return _searchRequest;
|
|
|
|
});
|
2017-08-01 12:01:42 +00:00
|
|
|
} else {
|
2020-06-11 16:09:46 +00:00
|
|
|
const auto type = SearchRequestType::FromStart;
|
2019-06-17 13:29:07 +00:00
|
|
|
const auto flags = session().settings().skipArchiveInSearch()
|
|
|
|
? MTPmessages_SearchGlobal::Flag::f_folder_id
|
|
|
|
: MTPmessages_SearchGlobal::Flag(0);
|
|
|
|
const auto folderId = 0;
|
2020-06-11 16:09:46 +00:00
|
|
|
_searchRequest = session().api().request(MTPmessages_SearchGlobal(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(folderId),
|
|
|
|
MTP_string(_searchQuery),
|
2020-09-01 06:44:18 +00:00
|
|
|
MTP_inputMessagesFilterEmpty(),
|
|
|
|
MTP_int(0), // min_date
|
|
|
|
MTP_int(0), // max_date
|
2020-06-11 16:09:46 +00:00
|
|
|
MTP_int(0),
|
|
|
|
MTP_inputPeerEmpty(),
|
|
|
|
MTP_int(0),
|
|
|
|
MTP_int(SearchPerPage)
|
|
|
|
)).done([=](const MTPmessages_Messages &result) {
|
|
|
|
searchReceived(type, result, _searchRequest);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-06-11 16:09:46 +00:00
|
|
|
searchFailed(type, error, _searchRequest);
|
|
|
|
}).send();
|
2020-07-02 07:13:50 +00:00
|
|
|
_searchQueries.emplace(_searchRequest, _searchQuery);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-06 14:54:44 +00:00
|
|
|
const auto query = Api::ConvertPeerSearchQuery(q);
|
|
|
|
if (searchForPeersRequired(query)) {
|
2017-08-01 12:01:42 +00:00
|
|
|
if (searchCache) {
|
2020-07-02 07:13:50 +00:00
|
|
|
auto i = _peerSearchCache.find(query);
|
|
|
|
if (i != _peerSearchCache.end()) {
|
2019-08-06 14:54:44 +00:00
|
|
|
_peerSearchQuery = query;
|
2017-08-01 12:01:42 +00:00
|
|
|
_peerSearchRequest = 0;
|
2020-07-02 07:13:50 +00:00
|
|
|
peerSearchReceived(i->second, 0);
|
2018-03-08 13:15:56 +00:00
|
|
|
result = true;
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2019-08-06 14:54:44 +00:00
|
|
|
} else if (_peerSearchQuery != query) {
|
|
|
|
_peerSearchQuery = query;
|
2017-08-01 12:01:42 +00:00
|
|
|
_peerSearchFull = false;
|
2020-07-02 07:13:50 +00:00
|
|
|
_peerSearchRequest = _api.request(MTPcontacts_Search(
|
2020-06-11 16:09:46 +00:00
|
|
|
MTP_string(_peerSearchQuery),
|
|
|
|
MTP_int(SearchPeopleLimit)
|
|
|
|
)).done([=](const MTPcontacts_Found &result, mtpRequestId requestId) {
|
|
|
|
peerSearchReceived(result, requestId);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error, mtpRequestId requestId) {
|
2020-06-11 16:09:46 +00:00
|
|
|
peopleFailed(error, requestId);
|
|
|
|
}).send();
|
2020-07-02 07:13:50 +00:00
|
|
|
_peerSearchQueries.emplace(_peerSearchRequest, _peerSearchQuery);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2018-03-08 13:15:56 +00:00
|
|
|
} else {
|
2019-08-06 14:54:44 +00:00
|
|
|
_peerSearchQuery = query;
|
2018-03-08 13:15:56 +00:00
|
|
|
_peerSearchFull = true;
|
|
|
|
peerSearchReceived(
|
|
|
|
MTP_contacts_found(
|
|
|
|
MTP_vector<MTPPeer>(0),
|
|
|
|
MTP_vector<MTPPeer>(0),
|
|
|
|
MTP_vector<MTPChat>(0),
|
|
|
|
MTP_vector<MTPUser>(0)),
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
bool Widget::searchForPeersRequired(const QString &query) const {
|
2018-03-08 13:15:56 +00:00
|
|
|
if (_searchInChat || query.isEmpty()) {
|
|
|
|
return false;
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2018-03-08 13:15:56 +00:00
|
|
|
return (query[0] != '#');
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
void Widget::needSearchMessages() {
|
|
|
|
if (!searchMessages(true)) {
|
|
|
|
_searchTimer.callOnce(AutoSearchTimeout);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::showMainMenu() {
|
2021-02-03 03:31:11 +00:00
|
|
|
controller()->widget()->showMainMenu();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::searchMessages(
|
2018-02-14 19:38:01 +00:00
|
|
|
const QString &query,
|
2019-04-24 10:15:10 +00:00
|
|
|
Key inChat) {
|
2018-02-14 19:38:01 +00:00
|
|
|
auto inChatChanged = [&] {
|
|
|
|
if (inChat == _searchInChat) {
|
|
|
|
return false;
|
|
|
|
} else if (const auto inPeer = inChat.peer()) {
|
|
|
|
if (inPeer->migrateTo() == _searchInChat.peer()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}();
|
|
|
|
if ((_filter->getLastText() != query) || inChatChanged) {
|
|
|
|
if (inChat) {
|
2022-03-14 15:48:39 +00:00
|
|
|
cancelSearch();
|
2018-02-14 19:38:01 +00:00
|
|
|
setSearchInChat(inChat);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
_filter->setText(query);
|
|
|
|
_filter->updatePlaceholder();
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate(true);
|
2022-03-14 15:48:39 +00:00
|
|
|
_searchTimer.cancel();
|
|
|
|
searchMessages();
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2020-06-09 16:57:05 +00:00
|
|
|
session().local().saveRecentSearchHashtags(query);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
void Widget::searchMore() {
|
2020-02-21 12:57:06 +00:00
|
|
|
if (_searchRequest || _searchInHistoryRequest) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_searchFull) {
|
|
|
|
auto offsetPeer = _inner->lastSearchPeer();
|
|
|
|
auto offsetId = _inner->lastSearchId();
|
|
|
|
if (const auto peer = _searchInChat.peer()) {
|
|
|
|
auto &histories = session().data().histories();
|
|
|
|
const auto type = Data::Histories::RequestType::History;
|
|
|
|
const auto history = session().data().history(peer);
|
|
|
|
_searchInHistoryRequest = histories.sendRequest(history, type, [=](Fn<void()> finish) {
|
|
|
|
const auto type = offsetId
|
|
|
|
? SearchRequestType::PeerFromOffset
|
|
|
|
: SearchRequestType::PeerFromStart;
|
2018-02-14 19:38:01 +00:00
|
|
|
auto flags = _searchQueryFrom
|
|
|
|
? MTP_flags(MTPmessages_Search::Flag::f_from_id)
|
|
|
|
: MTP_flags(0);
|
2020-02-21 12:57:06 +00:00
|
|
|
_searchRequest = session().api().request(MTPmessages_Search(
|
2018-01-18 11:04:50 +00:00
|
|
|
flags,
|
2020-02-21 12:57:06 +00:00
|
|
|
peer->input,
|
2018-01-18 11:04:50 +00:00
|
|
|
MTP_string(_searchQuery),
|
2020-02-21 12:57:06 +00:00
|
|
|
(_searchQueryFrom
|
2020-10-06 12:58:16 +00:00
|
|
|
? _searchQueryFrom->input
|
|
|
|
: MTP_inputPeerEmpty()),
|
2020-09-01 06:44:18 +00:00
|
|
|
MTPint(), // top_msg_id
|
2018-01-18 11:04:50 +00:00
|
|
|
MTP_inputMessagesFilterEmpty(),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_int(0), // min_date
|
|
|
|
MTP_int(0), // max_date
|
2020-02-21 12:57:06 +00:00
|
|
|
MTP_int(offsetId),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_int(0), // add_offset
|
2018-01-18 11:04:50 +00:00
|
|
|
MTP_int(SearchPerPage),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_int(0), // max_id
|
|
|
|
MTP_int(0), // min_id
|
|
|
|
MTP_long(0) // hash
|
2020-02-21 12:57:06 +00:00
|
|
|
)).done([=](const MTPmessages_Messages &result) {
|
|
|
|
searchReceived(type, result, _searchRequest);
|
2020-02-24 09:14:29 +00:00
|
|
|
_searchInHistoryRequest = 0;
|
|
|
|
finish();
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-02-21 12:57:06 +00:00
|
|
|
searchFailed(type, error, _searchRequest);
|
2020-02-24 09:14:29 +00:00
|
|
|
_searchInHistoryRequest = 0;
|
|
|
|
finish();
|
2020-02-21 12:57:06 +00:00
|
|
|
}).send();
|
|
|
|
if (!offsetId) {
|
2020-07-02 07:13:50 +00:00
|
|
|
_searchQueries.emplace(_searchRequest, _searchQuery);
|
2020-02-21 12:57:06 +00:00
|
|
|
}
|
|
|
|
return _searchRequest;
|
|
|
|
});
|
|
|
|
} else {
|
2020-06-11 16:09:46 +00:00
|
|
|
const auto type = offsetId
|
|
|
|
? SearchRequestType::FromOffset
|
|
|
|
: SearchRequestType::FromStart;
|
2020-02-21 12:57:06 +00:00
|
|
|
const auto flags = session().settings().skipArchiveInSearch()
|
|
|
|
? MTPmessages_SearchGlobal::Flag::f_folder_id
|
|
|
|
: MTPmessages_SearchGlobal::Flag(0);
|
|
|
|
const auto folderId = 0;
|
2020-06-11 16:09:46 +00:00
|
|
|
_searchRequest = session().api().request(MTPmessages_SearchGlobal(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(folderId),
|
|
|
|
MTP_string(_searchQuery),
|
2020-09-01 06:44:18 +00:00
|
|
|
MTP_inputMessagesFilterEmpty(),
|
|
|
|
MTP_int(0), // min_date
|
|
|
|
MTP_int(0), // max_date
|
2020-06-11 16:09:46 +00:00
|
|
|
MTP_int(_searchNextRate),
|
|
|
|
offsetPeer
|
|
|
|
? offsetPeer->input
|
|
|
|
: MTP_inputPeerEmpty(),
|
|
|
|
MTP_int(offsetId),
|
|
|
|
MTP_int(SearchPerPage)
|
|
|
|
)).done([=](const MTPmessages_Messages &result) {
|
|
|
|
searchReceived(type, result, _searchRequest);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-06-11 16:09:46 +00:00
|
|
|
searchFailed(type, error, _searchRequest);
|
|
|
|
}).send();
|
2020-02-21 12:57:06 +00:00
|
|
|
if (!offsetId) {
|
2020-07-02 07:13:50 +00:00
|
|
|
_searchQueries.emplace(_searchRequest, _searchQuery);
|
2020-02-21 12:57:06 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-02-21 12:57:06 +00:00
|
|
|
} else if (_searchInMigrated && !_searchFullMigrated) {
|
|
|
|
auto offsetMigratedId = _inner->lastSearchMigratedId();
|
|
|
|
auto &histories = session().data().histories();
|
|
|
|
const auto type = Data::Histories::RequestType::History;
|
|
|
|
const auto history = _searchInMigrated;
|
|
|
|
_searchInHistoryRequest = histories.sendRequest(history, type, [=](Fn<void()> finish) {
|
|
|
|
const auto type = offsetMigratedId
|
|
|
|
? SearchRequestType::MigratedFromOffset
|
|
|
|
: SearchRequestType::MigratedFromStart;
|
|
|
|
const auto flags = _searchQueryFrom
|
|
|
|
? MTP_flags(MTPmessages_Search::Flag::f_from_id)
|
|
|
|
: MTP_flags(0);
|
|
|
|
_searchRequest = session().api().request(MTPmessages_Search(
|
|
|
|
flags,
|
|
|
|
_searchInMigrated->peer->input,
|
|
|
|
MTP_string(_searchQuery),
|
|
|
|
(_searchQueryFrom
|
2020-10-06 12:58:16 +00:00
|
|
|
? _searchQueryFrom->input
|
|
|
|
: MTP_inputPeerEmpty()),
|
2020-09-01 06:44:18 +00:00
|
|
|
MTPint(), // top_msg_id
|
2020-02-21 12:57:06 +00:00
|
|
|
MTP_inputMessagesFilterEmpty(),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_int(0), // min_date
|
|
|
|
MTP_int(0), // max_date
|
2020-02-21 12:57:06 +00:00
|
|
|
MTP_int(offsetMigratedId),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_int(0), // add_offset
|
2020-02-21 12:57:06 +00:00
|
|
|
MTP_int(SearchPerPage),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_int(0), // max_id
|
|
|
|
MTP_int(0), // min_id
|
|
|
|
MTP_long(0) // hash
|
2020-02-21 12:57:06 +00:00
|
|
|
)).done([=](const MTPmessages_Messages &result) {
|
|
|
|
searchReceived(type, result, _searchRequest);
|
2020-02-24 09:14:29 +00:00
|
|
|
_searchInHistoryRequest = 0;
|
|
|
|
finish();
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2020-02-21 12:57:06 +00:00
|
|
|
searchFailed(type, error, _searchRequest);
|
2020-02-24 09:14:29 +00:00
|
|
|
_searchInHistoryRequest = 0;
|
|
|
|
finish();
|
2020-02-21 12:57:06 +00:00
|
|
|
}).send();
|
|
|
|
return _searchRequest;
|
|
|
|
});
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::searchReceived(
|
|
|
|
SearchRequestType type,
|
2018-01-22 10:58:11 +00:00
|
|
|
const MTPmessages_Messages &result,
|
|
|
|
mtpRequestId requestId) {
|
2018-01-07 12:04:34 +00:00
|
|
|
const auto state = _inner->state();
|
2019-04-24 10:15:10 +00:00
|
|
|
if (state == WidgetState::Filtered) {
|
|
|
|
if (type == SearchRequestType::FromStart || type == SearchRequestType::PeerFromStart) {
|
2018-01-22 10:58:11 +00:00
|
|
|
auto i = _searchQueries.find(requestId);
|
2020-07-02 07:13:50 +00:00
|
|
|
if (i != _searchQueries.end()) {
|
|
|
|
_searchCache[i->second] = result;
|
2017-08-01 12:01:42 +00:00
|
|
|
_searchQueries.erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 14:43:26 +00:00
|
|
|
const auto inject = (type == SearchRequestType::FromStart
|
|
|
|
|| type == SearchRequestType::PeerFromStart)
|
|
|
|
? *_singleMessageSearch.lookup(_searchQuery)
|
|
|
|
: nullptr;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2020-02-21 11:51:37 +00:00
|
|
|
if (_searchRequest != requestId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_messages_messages: {
|
|
|
|
auto &d = result.c_messages_messages();
|
|
|
|
if (_searchRequest != 0) {
|
|
|
|
// Don't apply cached data!
|
|
|
|
session().data().processUsers(d.vusers());
|
|
|
|
session().data().processChats(d.vchats());
|
|
|
|
}
|
|
|
|
auto &msgs = d.vmessages().v;
|
|
|
|
_inner->searchReceived(msgs, inject, type, msgs.size());
|
|
|
|
if (type == SearchRequestType::MigratedFromStart || type == SearchRequestType::MigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_messages_messagesSlice: {
|
|
|
|
auto &d = result.c_messages_messagesSlice();
|
|
|
|
if (_searchRequest != 0) {
|
|
|
|
// Don't apply cached data!
|
|
|
|
session().data().processUsers(d.vusers());
|
|
|
|
session().data().processChats(d.vchats());
|
|
|
|
}
|
|
|
|
auto &msgs = d.vmessages().v;
|
|
|
|
const auto someAdded = _inner->searchReceived(msgs, inject, type, d.vcount().v);
|
|
|
|
const auto nextRate = d.vnext_rate();
|
|
|
|
const auto rateUpdated = nextRate && (nextRate->v != _searchNextRate);
|
|
|
|
const auto finished = (type == SearchRequestType::FromStart || type == SearchRequestType::FromOffset)
|
|
|
|
? !rateUpdated
|
|
|
|
: !someAdded;
|
|
|
|
if (rateUpdated) {
|
|
|
|
_searchNextRate = nextRate->v;
|
|
|
|
}
|
|
|
|
if (finished) {
|
2019-05-20 19:04:24 +00:00
|
|
|
if (type == SearchRequestType::MigratedFromStart || type == SearchRequestType::MigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-02-21 11:51:37 +00:00
|
|
|
}
|
|
|
|
} break;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2020-02-21 11:51:37 +00:00
|
|
|
case mtpc_messages_channelMessages: {
|
|
|
|
auto &d = result.c_messages_channelMessages();
|
|
|
|
if (const auto peer = _searchInChat.peer()) {
|
|
|
|
if (const auto channel = peer->asChannel()) {
|
|
|
|
channel->ptsReceived(d.vpts().v);
|
2017-08-01 12:01:42 +00:00
|
|
|
} else {
|
2018-02-14 19:38:01 +00:00
|
|
|
LOG(("API Error: "
|
|
|
|
"received messages.channelMessages when no channel "
|
2019-04-24 10:15:10 +00:00
|
|
|
"was passed! (Widget::searchReceived)"));
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-02-21 11:51:37 +00:00
|
|
|
} else {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"received messages.channelMessages when no channel "
|
|
|
|
"was passed! (Widget::searchReceived)"));
|
|
|
|
}
|
|
|
|
if (_searchRequest != 0) {
|
|
|
|
// Don't apply cached data!
|
|
|
|
session().data().processUsers(d.vusers());
|
|
|
|
session().data().processChats(d.vchats());
|
|
|
|
}
|
|
|
|
auto &msgs = d.vmessages().v;
|
|
|
|
if (!_inner->searchReceived(msgs, inject, type, d.vcount().v)) {
|
2019-04-24 10:15:10 +00:00
|
|
|
if (type == SearchRequestType::MigratedFromStart || type == SearchRequestType::MigratedFromOffset) {
|
2017-11-20 19:54:05 +00:00
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-02-21 11:51:37 +00:00
|
|
|
} break;
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2020-02-21 11:51:37 +00:00
|
|
|
case mtpc_messages_messagesNotModified: {
|
|
|
|
LOG(("API Error: received messages.messagesNotModified! (Widget::searchReceived)"));
|
|
|
|
if (type == SearchRequestType::MigratedFromStart || type == SearchRequestType::MigratedFromOffset) {
|
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
|
|
|
} break;
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-02-21 11:51:37 +00:00
|
|
|
|
|
|
|
_searchRequest = 0;
|
2022-03-14 15:48:39 +00:00
|
|
|
listScrollUpdated();
|
2020-02-21 11:51:37 +00:00
|
|
|
update();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::peerSearchReceived(
|
2018-01-22 10:58:11 +00:00
|
|
|
const MTPcontacts_Found &result,
|
|
|
|
mtpRequestId requestId) {
|
2018-01-07 12:04:34 +00:00
|
|
|
const auto state = _inner->state();
|
2017-08-01 12:01:42 +00:00
|
|
|
auto q = _peerSearchQuery;
|
2019-04-24 10:15:10 +00:00
|
|
|
if (state == WidgetState::Filtered) {
|
2018-01-22 10:58:11 +00:00
|
|
|
auto i = _peerSearchQueries.find(requestId);
|
2020-07-02 07:13:50 +00:00
|
|
|
if (i != _peerSearchQueries.end()) {
|
|
|
|
_peerSearchCache[i->second] = result;
|
2017-08-01 12:01:42 +00:00
|
|
|
_peerSearchQueries.erase(i);
|
|
|
|
}
|
|
|
|
}
|
2018-01-22 10:58:11 +00:00
|
|
|
if (_peerSearchRequest == requestId) {
|
2017-08-01 12:01:42 +00:00
|
|
|
switch (result.type()) {
|
|
|
|
case mtpc_contacts_found: {
|
|
|
|
auto &d = result.c_contacts_found();
|
2019-07-05 13:38:38 +00:00
|
|
|
session().data().processUsers(d.vusers());
|
|
|
|
session().data().processChats(d.vchats());
|
|
|
|
_inner->peerSearchReceived(q, d.vmy_results().v, d.vresults().v);
|
2017-08-01 12:01:42 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_peerSearchRequest = 0;
|
2022-03-14 15:48:39 +00:00
|
|
|
listScrollUpdated();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
void Widget::searchFailed(
|
2019-04-24 10:15:10 +00:00
|
|
|
SearchRequestType type,
|
2021-03-12 12:48:00 +00:00
|
|
|
const MTP::Error &error,
|
2018-01-22 10:58:11 +00:00
|
|
|
mtpRequestId requestId) {
|
2020-11-25 11:51:34 +00:00
|
|
|
if (error.type() == qstr("SEARCH_QUERY_EMPTY")) {
|
|
|
|
searchReceived(
|
|
|
|
type,
|
|
|
|
MTP_messages_messages(
|
|
|
|
MTP_vector<MTPMessage>(),
|
|
|
|
MTP_vector<MTPChat>(),
|
|
|
|
MTP_vector<MTPUser>()),
|
|
|
|
requestId);
|
|
|
|
} else if (_searchRequest == requestId) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_searchRequest = 0;
|
2019-04-24 10:15:10 +00:00
|
|
|
if (type == SearchRequestType::MigratedFromStart || type == SearchRequestType::MigratedFromOffset) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_searchFullMigrated = true;
|
|
|
|
} else {
|
|
|
|
_searchFull = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void Widget::peopleFailed(const MTP::Error &error, mtpRequestId requestId) {
|
2020-06-11 16:09:46 +00:00
|
|
|
if (_peerSearchRequest == requestId) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_peerSearchRequest = 0;
|
|
|
|
_peerSearchFull = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::dragEnterEvent(QDragEnterEvent *e) {
|
2017-12-19 16:57:42 +00:00
|
|
|
using namespace Storage;
|
|
|
|
|
2020-06-30 15:05:12 +00:00
|
|
|
if (controller()->selectingPeer()) {
|
2020-06-10 18:08:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2017-12-19 16:57:42 +00:00
|
|
|
const auto data = e->mimeData();
|
2017-08-01 12:01:42 +00:00
|
|
|
_dragInScroll = false;
|
2021-05-26 21:00:12 +00:00
|
|
|
_dragForward = controller()->adaptive().isOneColumn()
|
2017-12-19 16:57:42 +00:00
|
|
|
? false
|
2018-01-11 15:51:59 +00:00
|
|
|
: data->hasFormat(qsl("application/x-td-forward"));
|
2017-08-01 12:01:42 +00:00
|
|
|
if (_dragForward) {
|
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
e->accept();
|
|
|
|
updateDragInScroll(_scroll->geometry().contains(e->pos()));
|
2017-12-19 16:57:42 +00:00
|
|
|
} else if (ComputeMimeDataState(data) != MimeDataState::None) {
|
2017-08-01 12:01:42 +00:00
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
e->accept();
|
|
|
|
}
|
2022-03-14 15:48:39 +00:00
|
|
|
_chooseByDragTimer.cancel();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::dragMoveEvent(QDragMoveEvent *e) {
|
2017-08-01 12:01:42 +00:00
|
|
|
if (_scroll->geometry().contains(e->pos())) {
|
|
|
|
if (_dragForward) {
|
|
|
|
updateDragInScroll(true);
|
|
|
|
} else {
|
2022-03-14 15:48:39 +00:00
|
|
|
_chooseByDragTimer.callOnce(ChoosePeerByDragTimeout);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2018-01-05 15:57:18 +00:00
|
|
|
if (_inner->updateFromParentDrag(mapToGlobal(e->pos()))) {
|
2017-08-01 12:01:42 +00:00
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
} else {
|
|
|
|
e->setDropAction(Qt::IgnoreAction);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_dragForward) updateDragInScroll(false);
|
|
|
|
_inner->dragLeft();
|
|
|
|
e->setDropAction(Qt::IgnoreAction);
|
|
|
|
}
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::dragLeaveEvent(QDragLeaveEvent *e) {
|
2017-08-01 12:01:42 +00:00
|
|
|
if (_dragForward) {
|
|
|
|
updateDragInScroll(false);
|
|
|
|
} else {
|
2022-03-14 15:48:39 +00:00
|
|
|
_chooseByDragTimer.cancel();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
_inner->dragLeft();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateDragInScroll(bool inScroll) {
|
2017-08-01 12:01:42 +00:00
|
|
|
if (_dragInScroll != inScroll) {
|
|
|
|
_dragInScroll = inScroll;
|
|
|
|
if (_dragInScroll) {
|
2020-06-10 18:08:17 +00:00
|
|
|
controller()->content()->showForwardLayer({});
|
2017-08-01 12:01:42 +00:00
|
|
|
} else {
|
2020-06-10 18:08:17 +00:00
|
|
|
controller()->content()->dialogsCancelled();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::dropEvent(QDropEvent *e) {
|
2022-03-14 15:48:39 +00:00
|
|
|
_chooseByDragTimer.cancel();
|
2017-08-01 12:01:42 +00:00
|
|
|
if (_scroll->geometry().contains(e->pos())) {
|
|
|
|
if (auto peer = _inner->updateFromParentDrag(mapToGlobal(e->pos()))) {
|
|
|
|
e->acceptProposedAction();
|
2020-06-10 18:08:17 +00:00
|
|
|
controller()->content()->onFilesOrForwardDrop(
|
|
|
|
peer->id,
|
|
|
|
e->mimeData());
|
2021-06-07 07:25:19 +00:00
|
|
|
controller()->widget()->raise();
|
2019-09-03 15:24:51 +00:00
|
|
|
controller()->widget()->activateWindow();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
void Widget::listScrollUpdated() {
|
2019-04-18 09:31:16 +00:00
|
|
|
const auto scrollTop = _scroll->scrollTop();
|
2017-08-01 12:01:42 +00:00
|
|
|
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
2019-04-05 08:28:07 +00:00
|
|
|
updateScrollUpVisibility();
|
2019-04-05 15:52:45 +00:00
|
|
|
|
|
|
|
// Fix button rendering glitch, Qt bug with WA_OpaquePaintEvent widgets.
|
|
|
|
_scrollToTop->update();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::applyFilterUpdate(bool force) {
|
2018-12-30 07:34:17 +00:00
|
|
|
if (_a_show.animating() && !force) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
auto filterText = _filter->getLastText();
|
2018-12-29 08:11:54 +00:00
|
|
|
_inner->applyFilterUpdate(filterText, force);
|
2020-10-06 12:58:16 +00:00
|
|
|
if (filterText.isEmpty() && !_searchFromAuthor) {
|
2017-08-01 15:55:51 +00:00
|
|
|
clearSearchCache();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2017-11-27 11:43:57 +00:00
|
|
|
_cancelSearch->toggle(!filterText.isEmpty(), anim::type::normal);
|
2019-04-24 10:15:10 +00:00
|
|
|
updateLoadMoreChatsVisibility();
|
2017-08-01 12:01:42 +00:00
|
|
|
updateJumpToDateVisibility();
|
|
|
|
|
2018-01-22 10:58:11 +00:00
|
|
|
if (filterText.isEmpty()) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_peerSearchCache.clear();
|
2020-07-02 07:13:50 +00:00
|
|
|
for (const auto &[requestId, query] : base::take(_peerSearchQueries)) {
|
|
|
|
_api.request(requestId).cancel();
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
_peerSearchQuery = QString();
|
|
|
|
}
|
2017-08-06 17:32:05 +00:00
|
|
|
|
2020-10-06 12:58:16 +00:00
|
|
|
if (_chooseFromUser->toggled() || _searchFromAuthor) {
|
2017-08-06 17:32:05 +00:00
|
|
|
auto switchToChooseFrom = SwitchToChooseFromQuery();
|
|
|
|
if (_lastFilterText != switchToChooseFrom
|
|
|
|
&& switchToChooseFrom.startsWith(_lastFilterText)
|
|
|
|
&& filterText == switchToChooseFrom) {
|
|
|
|
showSearchFrom();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_lastFilterText = filterText;
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::searchInChat(Key chat) {
|
2022-03-14 15:48:39 +00:00
|
|
|
cancelSearch();
|
2018-02-14 19:38:01 +00:00
|
|
|
setSearchInChat(chat);
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate(true);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 12:58:16 +00:00
|
|
|
void Widget::setSearchInChat(Key chat, PeerData *from) {
|
2019-05-26 12:49:12 +00:00
|
|
|
if (chat.folder()) {
|
|
|
|
chat = Key();
|
|
|
|
}
|
2018-02-14 19:38:01 +00:00
|
|
|
_searchInMigrated = nullptr;
|
|
|
|
if (const auto peer = chat.peer()) {
|
|
|
|
if (const auto migrateTo = peer->migrateTo()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
return setSearchInChat(peer->owner().history(migrateTo), from);
|
2018-02-14 19:38:01 +00:00
|
|
|
} else if (const auto migrateFrom = peer->migrateFrom()) {
|
2019-01-18 12:27:37 +00:00
|
|
|
_searchInMigrated = peer->owner().history(migrateFrom);
|
2018-02-14 19:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto searchInPeerUpdated = (_searchInChat != chat);
|
2017-08-01 15:55:51 +00:00
|
|
|
if (searchInPeerUpdated) {
|
2018-02-14 19:38:01 +00:00
|
|
|
_searchInChat = chat;
|
2017-08-01 15:55:51 +00:00
|
|
|
from = nullptr;
|
2018-02-14 19:38:01 +00:00
|
|
|
controller()->searchInChat = _searchInChat;
|
2017-08-01 12:01:42 +00:00
|
|
|
updateJumpToDateVisibility();
|
2018-02-14 19:38:01 +00:00
|
|
|
} else if (!_searchInChat) {
|
2017-08-01 15:55:51 +00:00
|
|
|
from = nullptr;
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-10-06 12:58:16 +00:00
|
|
|
if (_searchFromAuthor != from || searchInPeerUpdated) {
|
|
|
|
_searchFromAuthor = from;
|
2017-08-01 15:55:51 +00:00
|
|
|
updateSearchFromVisibility();
|
|
|
|
clearSearchCache();
|
|
|
|
}
|
2020-10-06 12:58:16 +00:00
|
|
|
_inner->searchInChat(_searchInChat, _searchFromAuthor);
|
|
|
|
if (_searchFromAuthor && _lastFilterText == SwitchToChooseFromQuery()) {
|
2022-03-14 15:48:39 +00:00
|
|
|
cancelSearch();
|
2017-08-06 17:32:05 +00:00
|
|
|
}
|
|
|
|
_filter->setFocus();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::clearSearchCache() {
|
2017-08-01 15:55:51 +00:00
|
|
|
_searchCache.clear();
|
2019-08-06 14:43:26 +00:00
|
|
|
_singleMessageSearch.clear();
|
2020-07-02 07:13:50 +00:00
|
|
|
for (const auto &[requestId, query] : base::take(_searchQueries)) {
|
|
|
|
session().api().request(requestId).cancel();
|
|
|
|
}
|
2017-08-01 15:55:51 +00:00
|
|
|
_searchQuery = QString();
|
|
|
|
_searchQueryFrom = nullptr;
|
2020-02-21 12:57:06 +00:00
|
|
|
cancelSearchRequest();
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2021-11-16 07:26:35 +00:00
|
|
|
void Widget::showCalendar() {
|
2018-02-21 21:17:36 +00:00
|
|
|
if (_searchInChat) {
|
2021-11-16 07:26:35 +00:00
|
|
|
controller()->showCalendar(_searchInChat, QDate());
|
2018-02-21 21:17:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::showSearchFrom() {
|
2018-02-14 19:38:01 +00:00
|
|
|
if (const auto peer = _searchInChat.peer()) {
|
|
|
|
const auto chat = _searchInChat;
|
2022-03-21 12:44:37 +00:00
|
|
|
auto box = SearchFromBox(
|
2018-02-14 19:38:01 +00:00
|
|
|
peer,
|
2020-10-06 12:58:16 +00:00
|
|
|
crl::guard(this, [=](not_null<PeerData*> from) {
|
2018-02-14 19:38:01 +00:00
|
|
|
Ui::hideLayer();
|
2020-10-06 12:58:16 +00:00
|
|
|
setSearchInChat(chat, from);
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate(true);
|
2018-02-14 19:38:01 +00:00
|
|
|
}),
|
2018-11-26 11:00:31 +00:00
|
|
|
crl::guard(this, [=] { _filter->setFocus(); }));
|
2022-03-21 12:44:37 +00:00
|
|
|
if (box) {
|
|
|
|
Window::Show(controller()).showBox(std::move(box));
|
|
|
|
}
|
2017-10-03 13:05:58 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
void Widget::filterCursorMoved(int from, int to) {
|
2017-08-01 12:01:42 +00:00
|
|
|
if (to < 0) to = _filter->cursorPosition();
|
|
|
|
QString t = _filter->getLastText();
|
2021-10-19 13:00:21 +00:00
|
|
|
QStringView r;
|
2017-08-01 12:01:42 +00:00
|
|
|
for (int start = to; start > 0;) {
|
|
|
|
--start;
|
|
|
|
if (t.size() <= start) break;
|
|
|
|
if (t.at(start) == '#') {
|
2021-10-19 13:00:21 +00:00
|
|
|
r = base::StringViewMid(t, start, to - start);
|
2017-08-01 12:01:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!t.at(start).isLetterOrNumber() && t.at(start) != '_') break;
|
|
|
|
}
|
|
|
|
_inner->onHashtagFilterUpdate(r);
|
|
|
|
}
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
void Widget::completeHashtag(QString tag) {
|
2017-08-01 12:01:42 +00:00
|
|
|
QString t = _filter->getLastText(), r;
|
|
|
|
int cur = _filter->cursorPosition();
|
|
|
|
for (int start = cur; start > 0;) {
|
|
|
|
--start;
|
|
|
|
if (t.size() <= start) break;
|
|
|
|
if (t.at(start) == '#') {
|
2021-10-19 13:00:21 +00:00
|
|
|
if (cur == start + 1
|
|
|
|
|| base::StringViewMid(t, start + 1, cur - start - 1)
|
|
|
|
== base::StringViewMid(tag, 0, cur - start - 1)) {
|
2017-08-01 12:01:42 +00:00
|
|
|
for (; cur < t.size() && cur - start - 1 < tag.size(); ++cur) {
|
|
|
|
if (t.at(cur) != tag.at(cur - start - 1)) break;
|
|
|
|
}
|
|
|
|
if (cur - start - 1 == tag.size() && cur < t.size() && t.at(cur) == ' ') ++cur;
|
|
|
|
r = t.mid(0, start + 1) + tag + ' ' + t.mid(cur);
|
|
|
|
_filter->setText(r);
|
|
|
|
_filter->setCursorPosition(start + 1 + tag.size() + 1);
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate(true);
|
2017-08-01 12:01:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!t.at(start).isLetterOrNumber() && t.at(start) != '_') break;
|
|
|
|
}
|
|
|
|
_filter->setText(t.mid(0, cur) + '#' + tag + ' ' + t.mid(cur));
|
|
|
|
_filter->setCursorPosition(cur + 1 + tag.size() + 1);
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate(true);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::resizeEvent(QResizeEvent *e) {
|
2017-08-01 12:01:42 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateLockUnlockVisibility() {
|
|
|
|
if (_a_show.animating()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-25 20:38:01 +00:00
|
|
|
const auto hidden = !session().domain().local().hasLocalPasscode();
|
2019-04-24 10:15:10 +00:00
|
|
|
if (_lockUnlock->isHidden() != hidden) {
|
|
|
|
_lockUnlock->setVisible(!hidden);
|
|
|
|
updateControlsGeometry();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateLoadMoreChatsVisibility() {
|
|
|
|
if (_a_show.animating() || !_loadMoreChats) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto hidden = (_openedFolder != nullptr)
|
2022-09-20 09:35:47 +00:00
|
|
|
|| (_openedForum != nullptr)
|
2019-04-24 10:15:10 +00:00
|
|
|
|| !_filter->getLastText().isEmpty();
|
|
|
|
if (_loadMoreChats->isHidden() != hidden) {
|
|
|
|
_loadMoreChats->setVisible(!hidden);
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateJumpToDateVisibility(bool fast) {
|
2017-08-01 12:01:42 +00:00
|
|
|
if (_a_show.animating()) return;
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
_jumpToDate->toggle(
|
2018-02-14 19:38:01 +00:00
|
|
|
(_searchInChat && _filter->getLastText().isEmpty()),
|
2017-09-30 19:20:40 +00:00
|
|
|
fast ? anim::type::instant : anim::type::normal);
|
2017-08-01 15:55:51 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateSearchFromVisibility(bool fast) {
|
2018-02-14 19:38:01 +00:00
|
|
|
auto visible = [&] {
|
|
|
|
if (const auto peer = _searchInChat.peer()) {
|
|
|
|
if (peer->isChat() || peer->isMegagroup()) {
|
2020-10-06 12:58:16 +00:00
|
|
|
return !_searchFromAuthor;
|
2018-02-14 19:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}();
|
2017-09-30 19:20:40 +00:00
|
|
|
auto changed = (visible == !_chooseFromUser->toggled());
|
|
|
|
_chooseFromUser->toggle(
|
|
|
|
visible,
|
|
|
|
fast ? anim::type::instant : anim::type::normal);
|
2017-08-06 17:11:22 +00:00
|
|
|
if (changed) {
|
|
|
|
auto margins = st::dialogsFilter.textMrg;
|
|
|
|
if (visible) {
|
|
|
|
margins.setRight(margins.right() + _chooseFromUser->width());
|
|
|
|
}
|
|
|
|
_filter->setTextMrg(margins);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateControlsGeometry() {
|
2017-08-01 12:01:42 +00:00
|
|
|
auto filterAreaTop = 0;
|
|
|
|
if (_forwardCancel) {
|
|
|
|
_forwardCancel->moveToLeft(0, filterAreaTop);
|
|
|
|
filterAreaTop += st::dialogsForwardHeight;
|
|
|
|
}
|
|
|
|
auto smallLayoutWidth = (st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPadding.x());
|
2017-11-12 16:50:58 +00:00
|
|
|
auto smallLayoutRatio = (width() < st::columnMinimalWidthLeft) ? (st::columnMinimalWidthLeft - width()) / float64(st::columnMinimalWidthLeft - smallLayoutWidth) : 0.;
|
2020-03-06 13:12:22 +00:00
|
|
|
auto filterLeft = (controller()->filtersWidth() ? st::dialogsFilterSkip : st::dialogsFilterPadding.x() + _mainMenuToggle->width()) + st::dialogsFilterPadding.x();
|
2021-06-18 18:22:38 +00:00
|
|
|
auto filterRight = (session().domain().local().hasLocalPasscode() ? (st::dialogsFilterPadding.x() + _lockUnlock->width()) : st::dialogsFilterSkip) + st::dialogsFilterPadding.x();
|
2017-11-12 16:50:58 +00:00
|
|
|
auto filterWidth = qMax(width(), st::columnMinimalWidthLeft) - filterLeft - filterRight;
|
2019-04-26 14:07:44 +00:00
|
|
|
auto filterAreaHeight = st::topBarHeight;
|
2019-04-24 10:15:10 +00:00
|
|
|
_searchControls->setGeometry(0, filterAreaTop, width(), filterAreaHeight);
|
2019-04-24 14:12:35 +00:00
|
|
|
if (_folderTopBar) {
|
|
|
|
_folderTopBar->setGeometry(_searchControls->geometry());
|
|
|
|
}
|
2019-04-24 10:15:10 +00:00
|
|
|
|
|
|
|
auto filterTop = (filterAreaHeight - _filter->height()) / 2;
|
2017-08-01 12:01:42 +00:00
|
|
|
filterLeft = anim::interpolate(filterLeft, smallLayoutWidth, smallLayoutRatio);
|
|
|
|
_filter->setGeometryToLeft(filterLeft, filterTop, filterWidth, _filter->height());
|
|
|
|
auto mainMenuLeft = anim::interpolate(st::dialogsFilterPadding.x(), (smallLayoutWidth - _mainMenuToggle->width()) / 2, smallLayoutRatio);
|
2019-04-24 10:15:10 +00:00
|
|
|
_mainMenuToggle->moveToLeft(mainMenuLeft, st::dialogsFilterPadding.y());
|
2020-03-18 12:14:45 +00:00
|
|
|
const auto searchLeft = anim::interpolate(
|
|
|
|
-_searchForNarrowFilters->width(),
|
|
|
|
(smallLayoutWidth - _searchForNarrowFilters->width()) / 2,
|
|
|
|
smallLayoutRatio);
|
|
|
|
_searchForNarrowFilters->moveToLeft(searchLeft, st::dialogsFilterPadding.y());
|
|
|
|
|
2017-08-01 15:55:51 +00:00
|
|
|
auto right = filterLeft + filterWidth;
|
2019-04-24 10:15:10 +00:00
|
|
|
_lockUnlock->moveToLeft(right + st::dialogsFilterPadding.x(), st::dialogsFilterPadding.y());
|
2017-08-01 15:55:51 +00:00
|
|
|
_cancelSearch->moveToLeft(right - _cancelSearch->width(), _filter->y());
|
|
|
|
right -= _jumpToDate->width(); _jumpToDate->moveToLeft(right, _filter->y());
|
|
|
|
right -= _chooseFromUser->width(); _chooseFromUser->moveToLeft(right, _filter->y());
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
auto scrollTop = filterAreaTop + filterAreaHeight;
|
2020-06-11 09:41:03 +00:00
|
|
|
auto newScrollTop = _scroll->scrollTop() + _topDelta;
|
2017-08-01 12:01:42 +00:00
|
|
|
auto scrollHeight = height() - scrollTop;
|
2022-02-22 13:58:55 +00:00
|
|
|
const auto putBottomButton = [&](auto &button) {
|
2018-12-30 07:34:17 +00:00
|
|
|
if (button && !button->isHidden()) {
|
2018-11-09 13:54:34 +00:00
|
|
|
const auto buttonHeight = button->height();
|
|
|
|
scrollHeight -= buttonHeight;
|
|
|
|
button->setGeometry(
|
|
|
|
0,
|
|
|
|
scrollTop + scrollHeight,
|
|
|
|
width(),
|
|
|
|
buttonHeight);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
putBottomButton(_updateTelegram);
|
2022-02-22 13:58:55 +00:00
|
|
|
putBottomButton(_downloadBar);
|
2018-11-09 13:54:34 +00:00
|
|
|
putBottomButton(_loadMoreChats);
|
2022-03-01 15:38:45 +00:00
|
|
|
const auto bottomSkip = (height() - scrollTop) - scrollHeight;
|
|
|
|
if (_connecting) {
|
|
|
|
_connecting->setBottomSkip(bottomSkip);
|
|
|
|
}
|
|
|
|
controller()->setConnectingBottomSkip(bottomSkip);
|
2017-08-01 12:01:42 +00:00
|
|
|
auto wasScrollHeight = _scroll->height();
|
|
|
|
_scroll->setGeometry(0, scrollTop, width(), scrollHeight);
|
2019-04-16 09:29:21 +00:00
|
|
|
_inner->resize(width(), _inner->height());
|
2017-08-01 12:01:42 +00:00
|
|
|
if (scrollHeight != wasScrollHeight) {
|
2020-06-25 14:17:37 +00:00
|
|
|
controller()->floatPlayerAreaUpdated();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-06-11 09:41:03 +00:00
|
|
|
if (_topDelta) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_scroll->scrollToY(newScrollTop);
|
|
|
|
} else {
|
2022-03-14 15:48:39 +00:00
|
|
|
listScrollUpdated();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2019-04-05 15:37:39 +00:00
|
|
|
if (_scrollToTopIsShown) {
|
|
|
|
updateScrollUpPosition();
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 16:22:46 +00:00
|
|
|
rpl::producer<> Widget::closeForwardBarRequests() const {
|
|
|
|
return _closeForwardBarRequests.events();
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::updateForwardBar() {
|
2020-06-30 15:05:12 +00:00
|
|
|
auto selecting = controller()->selectingPeer();
|
2021-05-26 21:00:12 +00:00
|
|
|
auto oneColumnSelecting = (controller()->adaptive().isOneColumn()
|
|
|
|
&& selecting);
|
2017-08-01 12:01:42 +00:00
|
|
|
if (!oneColumnSelecting == !_forwardCancel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oneColumnSelecting) {
|
|
|
|
_forwardCancel.create(this, st::dialogsForwardCancel);
|
2021-05-25 16:22:46 +00:00
|
|
|
_forwardCancel->setClickedCallback([=] {
|
|
|
|
_closeForwardBarRequests.fire({});
|
2020-06-10 18:08:17 +00:00
|
|
|
});
|
2017-08-01 12:01:42 +00:00
|
|
|
if (!_a_show.animating()) _forwardCancel->show();
|
|
|
|
} else {
|
|
|
|
_forwardCancel.destroyDelayed();
|
|
|
|
}
|
|
|
|
updateControlsGeometry();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2022-02-05 15:15:24 +00:00
|
|
|
RowDescriptor Widget::resolveChatNext(RowDescriptor from) const {
|
|
|
|
return _inner->resolveChatNext(from);
|
|
|
|
}
|
|
|
|
|
|
|
|
RowDescriptor Widget::resolveChatPrevious(RowDescriptor from) const {
|
|
|
|
return _inner->resolveChatPrevious(from);
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::keyPressEvent(QKeyEvent *e) {
|
2017-08-01 12:01:42 +00:00
|
|
|
if (e->key() == Qt::Key_Escape) {
|
2019-04-24 10:15:10 +00:00
|
|
|
if (_openedFolder) {
|
|
|
|
controller()->closeFolder();
|
2022-09-20 09:35:47 +00:00
|
|
|
} else if (_openedForum) {
|
|
|
|
controller()->closeForum();
|
2019-04-24 10:15:10 +00:00
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
|
2018-01-07 12:04:34 +00:00
|
|
|
if (!_inner->chooseRow()) {
|
|
|
|
const auto state = _inner->state();
|
2019-04-24 10:15:10 +00:00
|
|
|
if (state == WidgetState::Default
|
|
|
|
|| (state == WidgetState::Filtered
|
2018-01-07 12:04:34 +00:00
|
|
|
&& (!_inner->waitingForSearch() || _inner->hasFilteredResults()))) {
|
2017-08-01 12:01:42 +00:00
|
|
|
_inner->selectSkip(1);
|
2018-01-07 12:04:34 +00:00
|
|
|
_inner->chooseRow();
|
2017-08-01 12:01:42 +00:00
|
|
|
} else {
|
2022-03-14 15:48:39 +00:00
|
|
|
searchMessages();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (e->key() == Qt::Key_Down) {
|
|
|
|
_inner->selectSkip(1);
|
|
|
|
} else if (e->key() == Qt::Key_Up) {
|
|
|
|
_inner->selectSkip(-1);
|
|
|
|
} else if (e->key() == Qt::Key_PageDown) {
|
|
|
|
_inner->selectSkipPage(_scroll->height(), 1);
|
|
|
|
} else if (e->key() == Qt::Key_PageUp) {
|
|
|
|
_inner->selectSkipPage(_scroll->height(), -1);
|
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::paintEvent(QPaintEvent *e) {
|
2021-02-03 03:31:11 +00:00
|
|
|
if (controller()->widget()->contentOverlapped(this, e)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
|
|
|
|
Painter p(this);
|
|
|
|
QRect r(e->rect());
|
|
|
|
if (r != rect()) {
|
|
|
|
p.setClipRect(r);
|
|
|
|
}
|
|
|
|
if (_a_show.animating()) {
|
2019-04-24 14:12:35 +00:00
|
|
|
const auto progress = _a_show.value(1.);
|
2019-04-24 10:15:10 +00:00
|
|
|
const auto top = (_showAnimationType == ShowAnimation::Internal)
|
|
|
|
? (_forwardCancel ? _forwardCancel->height() : 0)
|
|
|
|
: 0;
|
2019-04-24 14:12:35 +00:00
|
|
|
const auto shift = std::min(st::slideShift, width() / 2);
|
|
|
|
const auto retina = cIntRetinaFactor();
|
|
|
|
const auto fromLeft = (_showDirection == Window::SlideDirection::FromLeft);
|
|
|
|
const auto coordUnder = fromLeft ? anim::interpolate(-shift, 0, progress) : anim::interpolate(0, -shift, progress);
|
|
|
|
const auto coordOver = fromLeft ? anim::interpolate(0, width(), progress) : anim::interpolate(width(), 0, progress);
|
|
|
|
const auto shadow = fromLeft ? (1. - progress) : progress;
|
2017-08-01 12:01:42 +00:00
|
|
|
if (coordOver > 0) {
|
2019-04-24 10:15:10 +00:00
|
|
|
p.drawPixmap(QRect(0, top, coordOver, _cacheUnder.height() / retina), _cacheUnder, QRect(-coordUnder * retina, 0, coordOver * retina, _cacheUnder.height()));
|
2017-08-01 12:01:42 +00:00
|
|
|
p.setOpacity(shadow);
|
2019-04-24 10:15:10 +00:00
|
|
|
p.fillRect(0, top, coordOver, _cacheUnder.height() / retina, st::slideFadeOutBg);
|
2017-08-01 12:01:42 +00:00
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
2019-04-24 10:15:10 +00:00
|
|
|
p.drawPixmap(QRect(coordOver, top, _cacheOver.width() / retina, _cacheOver.height() / retina), _cacheOver, QRect(0, 0, _cacheOver.width(), _cacheOver.height()));
|
2017-08-01 12:01:42 +00:00
|
|
|
p.setOpacity(shadow);
|
2019-04-24 10:15:10 +00:00
|
|
|
st::slideShadow.fill(p, QRect(coordOver - st::slideShadow.width(), top, st::slideShadow.width(), _cacheOver.height() / retina));
|
2017-08-01 12:01:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto aboveTop = 0;
|
|
|
|
if (_forwardCancel) {
|
|
|
|
p.fillRect(0, aboveTop, width(), st::dialogsForwardHeight, st::dialogsForwardBg);
|
|
|
|
p.setPen(st::dialogsForwardFg);
|
|
|
|
p.setFont(st::dialogsForwardFont);
|
2019-06-19 15:09:03 +00:00
|
|
|
p.drawTextLeft(st::dialogsForwardTextLeft, st::dialogsForwardTextTop, width(), tr::lng_forward_choose(tr::now));
|
2017-08-01 12:01:42 +00:00
|
|
|
aboveTop += st::dialogsForwardHeight;
|
|
|
|
}
|
|
|
|
auto above = QRect(0, aboveTop, width(), _scroll->y() - aboveTop);
|
|
|
|
if (above.intersects(r)) {
|
|
|
|
p.fillRect(above.intersected(r), st::dialogsBg);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto belowTop = _scroll->y() + qMin(_scroll->height(), _inner->height());
|
|
|
|
if (!_widthAnimationCache.isNull()) {
|
|
|
|
p.drawPixmapLeft(0, _scroll->y(), width(), _widthAnimationCache);
|
|
|
|
belowTop = _scroll->y() + (_widthAnimationCache.height() / cIntRetinaFactor());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto below = QRect(0, belowTop, width(), height() - belowTop);
|
|
|
|
if (below.intersects(r)) {
|
|
|
|
p.fillRect(below.intersected(r), st::dialogsBg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 10:15:10 +00:00
|
|
|
void Widget::scrollToEntry(const RowDescriptor &entry) {
|
2018-11-16 13:36:42 +00:00
|
|
|
_inner->scrollToEntry(entry);
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 12:57:06 +00:00
|
|
|
void Widget::cancelSearchRequest() {
|
2020-06-11 16:09:46 +00:00
|
|
|
session().api().request(base::take(_searchRequest)).cancel();
|
2020-07-02 07:13:50 +00:00
|
|
|
session().data().histories().cancelRequest(
|
|
|
|
base::take(_searchInHistoryRequest));
|
2020-02-21 12:57:06 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
bool Widget::cancelSearch() {
|
2020-02-21 12:57:06 +00:00
|
|
|
bool clearing = !_filter->getLastText().isEmpty();
|
|
|
|
cancelSearchRequest();
|
2018-02-14 19:38:01 +00:00
|
|
|
if (_searchInChat && !clearing) {
|
2021-05-26 21:00:12 +00:00
|
|
|
if (controller()->adaptive().isOneColumn()) {
|
2018-02-14 19:38:01 +00:00
|
|
|
if (const auto peer = _searchInChat.peer()) {
|
|
|
|
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
|
|
|
} else {
|
2022-03-14 15:48:39 +00:00
|
|
|
Unexpected("Empty key in cancelSearch().");
|
2018-02-14 19:38:01 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2019-04-24 10:15:10 +00:00
|
|
|
setSearchInChat(Key());
|
2017-08-01 12:01:42 +00:00
|
|
|
clearing = true;
|
|
|
|
}
|
|
|
|
_inner->clearFilter();
|
|
|
|
_filter->clear();
|
|
|
|
_filter->updatePlaceholder();
|
2018-12-29 08:11:54 +00:00
|
|
|
applyFilterUpdate();
|
2017-08-01 12:01:42 +00:00
|
|
|
return clearing;
|
|
|
|
}
|
|
|
|
|
2022-03-14 15:48:39 +00:00
|
|
|
void Widget::cancelSearchInChat() {
|
2020-02-21 12:57:06 +00:00
|
|
|
cancelSearchRequest();
|
2021-05-26 21:00:12 +00:00
|
|
|
const auto isOneColumn = controller()->adaptive().isOneColumn();
|
2018-02-14 19:38:01 +00:00
|
|
|
if (_searchInChat) {
|
2021-05-26 21:00:12 +00:00
|
|
|
if (isOneColumn
|
2020-11-09 09:41:59 +00:00
|
|
|
&& !controller()->selectingPeer()
|
|
|
|
&& _filter->getLastText().trimmed().isEmpty()) {
|
2018-02-14 19:38:01 +00:00
|
|
|
if (const auto peer = _searchInChat.peer()) {
|
|
|
|
Ui::showPeerHistory(peer, ShowAtUnreadMsgId);
|
|
|
|
} else {
|
2022-03-14 15:48:39 +00:00
|
|
|
Unexpected("Empty key in cancelSearchInPeer().");
|
2018-02-14 19:38:01 +00:00
|
|
|
}
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2019-04-24 10:15:10 +00:00
|
|
|
setSearchInChat(Key());
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
2020-11-05 11:02:27 +00:00
|
|
|
applyFilterUpdate(true);
|
2021-05-26 21:00:12 +00:00
|
|
|
if (!isOneColumn && !controller()->selectingPeer()) {
|
2022-01-04 13:13:00 +00:00
|
|
|
controller()->content()->dialogsCancelled();
|
2017-08-01 12:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-30 14:34:37 +00:00
|
|
|
Widget::~Widget() {
|
|
|
|
cancelSearchRequest();
|
2022-03-07 14:10:01 +00:00
|
|
|
|
|
|
|
// Destructor may hide the bar and attempt to double-destroy it.
|
|
|
|
base::take(_downloadBar);
|
2020-06-30 14:34:37 +00:00
|
|
|
}
|
2019-04-24 10:15:10 +00:00
|
|
|
|
|
|
|
} // namespace Dialogs
|