2017-04-08 13:27:53 +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-04-08 13:27:53 +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-04-08 13:27:53 +00:00
|
|
|
*/
|
|
|
|
#include "history/history_inner_widget.h"
|
|
|
|
|
|
|
|
#include "core/file_utilities.h"
|
2018-01-29 12:07:16 +00:00
|
|
|
#include "core/crash_reports.h"
|
2020-11-10 16:38:21 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2017-06-22 15:11:41 +00:00
|
|
|
#include "history/history_message.h"
|
2019-08-02 13:21:09 +00:00
|
|
|
#include "history/view/media/history_view_media.h"
|
|
|
|
#include "history/view/media/history_view_sticker.h"
|
|
|
|
#include "history/view/media/history_view_web_page.h"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "history/history_item_components.h"
|
2018-01-26 15:40:11 +00:00
|
|
|
#include "history/history_item_text.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "history/view/history_view_message.h"
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/view/history_view_service_message.h"
|
2018-01-27 13:59:24 +00:00
|
|
|
#include "history/view/history_view_cursor_state.h"
|
2018-12-19 11:20:04 +00:00
|
|
|
#include "history/view/history_view_context_menu.h"
|
2021-09-15 14:49:06 +00:00
|
|
|
#include "history/view/history_view_emoji_interactions.h"
|
2021-09-02 22:08:57 +00:00
|
|
|
#include "ui/chat/chat_style.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2019-03-15 15:15:56 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2021-07-02 15:29:13 +00:00
|
|
|
#include "ui/effects/path_shift_gradient.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/text/text_options.h"
|
2021-02-15 17:37:22 +00:00
|
|
|
#include "ui/boxes/report_box.h"
|
|
|
|
#include "ui/layers/generic_box.h"
|
2021-02-11 16:10:15 +00:00
|
|
|
#include "ui/controls/delete_message_context_action.h"
|
2021-09-07 15:44:01 +00:00
|
|
|
#include "ui/controls/who_read_context_action.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2020-10-13 15:11:53 +00:00
|
|
|
#include "ui/cached_round_corners.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "ui/inactive_press.h"
|
2021-05-26 21:06:39 +00:00
|
|
|
#include "window/window_adaptive.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-12-15 18:36:28 +00:00
|
|
|
#include "window/window_peer_menu.h"
|
2020-01-14 11:55:18 +00:00
|
|
|
#include "window/window_controller.h"
|
2020-02-11 11:23:51 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2021-10-07 00:06:39 +00:00
|
|
|
#include "boxes/about_sponsored_box.h"
|
2021-10-18 20:55:58 +00:00
|
|
|
#include "boxes/delete_messages_box.h"
|
2018-11-26 11:55:02 +00:00
|
|
|
#include "boxes/sticker_set_box.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "chat_helpers/message_field.h"
|
2021-09-14 20:42:34 +00:00
|
|
|
#include "chat_helpers/emoji_interactions.h"
|
2017-06-29 10:27:09 +00:00
|
|
|
#include "history/history_widget.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "mainwindow.h"
|
2021-07-26 03:59:25 +00:00
|
|
|
#include "layout/layout_selection.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"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
#include "apiwrap.h"
|
2020-10-29 23:43:35 +00:00
|
|
|
#include "api/api_attached_stickers.h"
|
2020-08-17 12:29:27 +00:00
|
|
|
#include "api/api_toggling_media.h"
|
2021-09-07 15:44:01 +00:00
|
|
|
#include "api/api_who_read.h"
|
2021-09-28 21:23:58 +00:00
|
|
|
#include "api/api_views.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "data/data_media_types.h"
|
2018-12-18 10:45:06 +00:00
|
|
|
#include "data/data_document.h"
|
2020-10-01 10:38:36 +00:00
|
|
|
#include "data/data_channel.h"
|
2018-12-19 11:20:04 +00:00
|
|
|
#include "data/data_poll.h"
|
2018-12-18 10:45:06 +00:00
|
|
|
#include "data/data_photo.h"
|
2020-05-25 14:16:04 +00:00
|
|
|
#include "data/data_photo_media.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2021-06-17 23:28:09 +00:00
|
|
|
#include "data/data_file_click_handler.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2020-02-19 15:35:26 +00:00
|
|
|
#include "data/data_histories.h"
|
2020-06-12 14:09:04 +00:00
|
|
|
#include "data/data_changes.h"
|
2020-06-08 17:24:36 +00:00
|
|
|
#include "data/stickers/data_stickers.h"
|
2021-11-02 17:54:15 +00:00
|
|
|
#include "data/data_sponsored_messages.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2020-04-29 12:36:51 +00:00
|
|
|
#include "styles/style_window.h" // st::windowMinWidth
|
2021-10-19 13:00:21 +00:00
|
|
|
#include "base/qt_adapters.h"
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
#include <QtCore/QMimeData>
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kScrollDateHideTimeout = 1000;
|
2020-03-27 11:40:50 +00:00
|
|
|
constexpr auto kUnloadHeavyPartsPages = 2;
|
2020-05-28 14:32:10 +00:00
|
|
|
constexpr auto kClearUserpicsAfter = 50;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Helper binary search for an item in a list that is not completely
|
|
|
|
// above the given top of the visible area or below the given bottom of the visible area
|
|
|
|
// is applied once for blocks list in a history and once for items list in the found block.
|
|
|
|
template <bool TopToBottom, typename T>
|
|
|
|
int BinarySearchBlocksOrItems(const T &list, int edge) {
|
|
|
|
// static_cast to work around GCC bug #78693
|
|
|
|
auto start = 0, end = static_cast<int>(list.size());
|
|
|
|
while (end - start > 1) {
|
|
|
|
auto middle = (start + end) / 2;
|
|
|
|
auto top = list[middle]->y();
|
|
|
|
auto chooseLeft = (TopToBottom ? (top <= edge) : (top < edge));
|
|
|
|
if (chooseLeft) {
|
|
|
|
start = middle;
|
|
|
|
} else {
|
|
|
|
end = middle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// flick scroll taken from http://qt-project.org/doc/qt-4.8/demos-embedded-anomaly-src-flickcharm-cpp.html
|
|
|
|
|
2019-05-14 09:50:44 +00:00
|
|
|
HistoryInner *HistoryInner::Instance = nullptr;
|
|
|
|
|
2017-12-16 15:00:20 +00:00
|
|
|
class HistoryInner::BotAbout : public ClickHandlerHost {
|
|
|
|
public:
|
|
|
|
BotAbout(not_null<HistoryInner*> parent, not_null<BotInfo*> info);
|
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override;
|
|
|
|
|
|
|
|
not_null<BotInfo*> info;
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
QRect rect;
|
|
|
|
|
|
|
|
private:
|
|
|
|
not_null<HistoryInner*> _parent;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
HistoryInner::BotAbout::BotAbout(
|
|
|
|
not_null<HistoryInner*> parent,
|
|
|
|
not_null<BotInfo*> info)
|
|
|
|
: info(info)
|
|
|
|
, _parent(parent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::BotAbout::clickHandlerActiveChanged(
|
|
|
|
const ClickHandlerPtr &p,
|
|
|
|
bool active) {
|
|
|
|
_parent->update(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::BotAbout::clickHandlerPressedChanged(
|
|
|
|
const ClickHandlerPtr &p,
|
|
|
|
bool pressed) {
|
|
|
|
_parent->update(rect);
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
HistoryInner::HistoryInner(
|
2017-12-06 14:15:41 +00:00
|
|
|
not_null<HistoryWidget*> historyWidget,
|
2020-04-30 09:16:42 +00:00
|
|
|
not_null<Ui::ScrollArea*> scroll,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2017-12-06 14:15:41 +00:00
|
|
|
not_null<History*> history)
|
2017-10-05 15:35:52 +00:00
|
|
|
: RpWidget(nullptr)
|
2020-04-30 09:16:42 +00:00
|
|
|
, _widget(historyWidget)
|
|
|
|
, _scroll(scroll)
|
2017-04-08 13:27:53 +00:00
|
|
|
, _controller(controller)
|
|
|
|
, _peer(history->peer)
|
|
|
|
, _history(history)
|
2021-09-15 14:49:06 +00:00
|
|
|
, _emojiInteractions(std::make_unique<HistoryView::EmojiInteractions>(
|
|
|
|
&controller->session()))
|
2018-01-11 13:07:29 +00:00
|
|
|
, _migrated(history->migrateFrom())
|
2021-09-03 10:17:07 +00:00
|
|
|
, _pathGradient(
|
|
|
|
HistoryView::MakePathShiftGradient(
|
|
|
|
controller->chatStyle(),
|
|
|
|
[=] { update(); }))
|
2021-09-29 00:00:11 +00:00
|
|
|
, _touchSelectTimer([=] { onTouchSelect(); })
|
|
|
|
, _touchScrollTimer([=] { onTouchScrollTimer(); })
|
2018-01-27 13:59:24 +00:00
|
|
|
, _scrollDateCheck([this] { scrollDateCheck(); })
|
|
|
|
, _scrollDateHideTimer([this] { scrollDateHideByTimer(); }) {
|
2019-05-14 09:50:44 +00:00
|
|
|
Instance = this;
|
|
|
|
|
2021-08-27 20:44:47 +00:00
|
|
|
Window::ChatThemeValueFromPeer(
|
|
|
|
controller,
|
|
|
|
_peer
|
|
|
|
) | rpl::start_with_next([=](std::shared_ptr<Ui::ChatTheme> &&theme) {
|
|
|
|
_theme = std::move(theme);
|
|
|
|
controller->setChatStyleTheme(_theme);
|
|
|
|
}, lifetime());
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
setAttribute(Qt::WA_AcceptTouchEvents);
|
|
|
|
|
|
|
|
notifyIsBotChanged();
|
|
|
|
|
|
|
|
setMouseTracking(true);
|
2021-05-25 10:35:38 +00:00
|
|
|
_controller->gifPauseLevelChanged(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (!_controller->isGifPausedAtLeastFor(
|
|
|
|
Window::GifPauseReason::Any)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
update();
|
|
|
|
}
|
2021-05-25 10:35:38 +00:00
|
|
|
}, lifetime());
|
2021-09-15 14:49:06 +00:00
|
|
|
|
|
|
|
using PlayRequest = ChatHelpers::EmojiInteractionPlayRequest;
|
|
|
|
_controller->emojiInteractions().playRequests(
|
|
|
|
) | rpl::filter([=](const PlayRequest &request) {
|
2021-09-19 12:12:37 +00:00
|
|
|
return (request.item->history() == _history)
|
|
|
|
&& _controller->widget()->isActive();
|
2021-09-15 15:30:29 +00:00
|
|
|
}) | rpl::start_with_next([=](PlayRequest &&request) {
|
2021-09-15 14:49:06 +00:00
|
|
|
if (const auto view = request.item->mainView()) {
|
2021-09-15 15:30:29 +00:00
|
|
|
_emojiInteractions->play(std::move(request), view);
|
2021-09-15 14:49:06 +00:00
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
_emojiInteractions->updateRequests(
|
|
|
|
) | rpl::start_with_next([=](QRect rect) {
|
|
|
|
update(rect.translated(0, _historyPaddingTop));
|
|
|
|
}, lifetime());
|
2021-09-16 16:30:41 +00:00
|
|
|
_emojiInteractions->playStarted(
|
|
|
|
) | rpl::start_with_next([=](QString &&emoji) {
|
|
|
|
_controller->emojiInteractions().playStarted(_peer, std::move(emoji));
|
|
|
|
}, lifetime());
|
2021-09-15 14:49:06 +00:00
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().itemRemoved(
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::start_with_next(
|
|
|
|
[this](auto item) { itemRemoved(item); },
|
|
|
|
lifetime());
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().viewRemoved(
|
2018-03-09 11:44:42 +00:00
|
|
|
) | rpl::start_with_next(
|
|
|
|
[this](auto view) { viewRemoved(view); },
|
|
|
|
lifetime());
|
2017-10-30 19:24:20 +00:00
|
|
|
rpl::merge(
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().historyUnloaded(),
|
|
|
|
session().data().historyCleared()
|
2017-12-22 07:05:20 +00:00
|
|
|
) | rpl::filter([this](not_null<const History*> history) {
|
|
|
|
return (_history == history);
|
|
|
|
}) | rpl::start_with_next([this] {
|
|
|
|
mouseActionCancel();
|
|
|
|
}, lifetime());
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().viewRepaintRequest(
|
2018-01-27 13:59:24 +00:00
|
|
|
) | rpl::start_with_next([this](not_null<const Element*> view) {
|
|
|
|
repaintItem(view);
|
|
|
|
}, lifetime());
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().viewLayoutChanged(
|
2018-01-27 13:59:24 +00:00
|
|
|
) | rpl::filter([](not_null<const Element*> view) {
|
|
|
|
return (view == view->data()->mainView()) && view->isUnderCursor();
|
|
|
|
}) | rpl::start_with_next([this](not_null<const Element*> view) {
|
|
|
|
mouseActionUpdate();
|
|
|
|
}, lifetime());
|
2020-06-12 14:09:04 +00:00
|
|
|
session().changes().historyUpdates(
|
|
|
|
_history,
|
|
|
|
Data::HistoryUpdate::Flag::OutboxRead
|
|
|
|
) | rpl::start_with_next([=] {
|
2020-06-11 09:41:03 +00:00
|
|
|
update();
|
|
|
|
}, lifetime());
|
2021-05-27 00:44:12 +00:00
|
|
|
|
|
|
|
controller->adaptive().chatWideValue(
|
|
|
|
) | rpl::start_with_next([=](bool wide) {
|
|
|
|
_isChatWide = wide;
|
|
|
|
}, lifetime());
|
2021-10-30 06:11:27 +00:00
|
|
|
|
|
|
|
_selectScroll.scrolls(
|
|
|
|
) | rpl::start_with_next([=](int d) {
|
|
|
|
_scroll->scrollToY(_scroll->scrollTop() + d);
|
|
|
|
}, _scroll->lifetime());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session &HistoryInner::session() const {
|
2019-07-24 11:13:51 +00:00
|
|
|
return _controller->session();
|
|
|
|
}
|
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
void HistoryInner::messagesReceived(
|
|
|
|
PeerData *peer,
|
|
|
|
const QVector<MTPMessage> &messages) {
|
2019-01-18 08:11:15 +00:00
|
|
|
if (_history->peer == peer) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_history->addOlderSlice(messages);
|
|
|
|
} else if (_migrated && _migrated->peer == peer) {
|
2018-01-31 17:10:29 +00:00
|
|
|
const auto newLoaded = _migrated
|
|
|
|
&& _migrated->isEmpty()
|
|
|
|
&& !_history->isEmpty();
|
2017-04-08 13:27:53 +00:00
|
|
|
_migrated->addOlderSlice(messages);
|
|
|
|
if (newLoaded) {
|
|
|
|
_migrated->addNewerSlice(QVector<MTPMessage>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::messagesReceivedDown(PeerData *peer, const QVector<MTPMessage> &messages) {
|
2019-01-18 08:11:15 +00:00
|
|
|
if (_history->peer == peer) {
|
2018-02-05 14:37:22 +00:00
|
|
|
const auto oldLoaded = _migrated
|
|
|
|
&& _history->isEmpty()
|
|
|
|
&& !_migrated->isEmpty();
|
2017-04-08 13:27:53 +00:00
|
|
|
_history->addNewerSlice(messages);
|
|
|
|
if (oldLoaded) {
|
|
|
|
_history->addOlderSlice(QVector<MTPMessage>());
|
|
|
|
}
|
|
|
|
} else if (_migrated && _migrated->peer == peer) {
|
|
|
|
_migrated->addNewerSlice(messages);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::repaintItem(const HistoryItem *item) {
|
2018-01-18 11:46:45 +00:00
|
|
|
if (!item) {
|
|
|
|
return;
|
2018-01-11 13:07:29 +00:00
|
|
|
}
|
2018-01-18 11:46:45 +00:00
|
|
|
repaintItem(item->mainView());
|
2018-01-11 13:07:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void HistoryInner::repaintItem(const Element *view) {
|
2018-01-18 11:46:45 +00:00
|
|
|
if (_widget->skipItemRepaint()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto top = itemTop(view);
|
|
|
|
if (top >= 0) {
|
2020-01-24 09:50:20 +00:00
|
|
|
const auto range = view->verticalRepaintRange();
|
|
|
|
update(0, top + range.top, width(), range.height);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <bool TopToBottom, typename Method>
|
|
|
|
void HistoryInner::enumerateItemsInHistory(History *history, int historytop, Method method) {
|
2017-06-22 01:31:02 +00:00
|
|
|
// No displayed messages in this history.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (historytop < 0 || history->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-21 19:21:08 +00:00
|
|
|
if (_visibleAreaBottom <= historytop || historytop + history->height() <= _visibleAreaTop) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto searchEdge = TopToBottom ? _visibleAreaTop : _visibleAreaBottom;
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Binary search for blockIndex of the first block that is not completely below the visible area.
|
|
|
|
auto blockIndex = BinarySearchBlocksOrItems<TopToBottom>(history->blocks, searchEdge - historytop);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Binary search for itemIndex of the first item that is not completely below the visible area.
|
2018-01-10 13:13:33 +00:00
|
|
|
auto block = history->blocks[blockIndex].get();
|
2017-05-12 13:53:08 +00:00
|
|
|
auto blocktop = historytop + block->y();
|
|
|
|
auto blockbottom = blocktop + block->height();
|
2018-01-10 13:13:33 +00:00
|
|
|
auto itemIndex = BinarySearchBlocksOrItems<TopToBottom>(block->messages, searchEdge - blocktop);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
while (true) {
|
2018-01-10 13:13:33 +00:00
|
|
|
auto view = block->messages[itemIndex].get();
|
|
|
|
auto itemtop = blocktop + view->y();
|
2018-01-13 12:45:11 +00:00
|
|
|
auto itembottom = itemtop + view->height();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Binary search should've skipped all the items that are above / below the visible area.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (TopToBottom) {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(itembottom > _visibleAreaTop);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2017-08-17 09:06:26 +00:00
|
|
|
Assert(itemtop < _visibleAreaBottom);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
if (!method(view, itemtop, itembottom)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Skip all the items that are below / above the visible area.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (TopToBottom) {
|
|
|
|
if (itembottom >= _visibleAreaBottom) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (itemtop <= _visibleAreaTop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TopToBottom) {
|
2018-01-10 13:13:33 +00:00
|
|
|
if (++itemIndex >= block->messages.size()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (--itemIndex < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Skip all the rest blocks that are below / above the visible area.
|
2017-04-08 13:27:53 +00:00
|
|
|
if (TopToBottom) {
|
|
|
|
if (blockbottom >= _visibleAreaBottom) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (blocktop <= _visibleAreaTop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TopToBottom) {
|
|
|
|
if (++blockIndex >= history->blocks.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (--blockIndex < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 13:13:33 +00:00
|
|
|
block = history->blocks[blockIndex].get();
|
2017-05-12 13:53:08 +00:00
|
|
|
blocktop = historytop + block->y();
|
|
|
|
blockbottom = blocktop + block->height();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (TopToBottom) {
|
|
|
|
itemIndex = 0;
|
|
|
|
} else {
|
2018-01-10 13:13:33 +00:00
|
|
|
itemIndex = block->messages.size() - 1;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 19:21:08 +00:00
|
|
|
bool HistoryInner::canHaveFromUserpics() const {
|
2020-09-11 15:33:26 +00:00
|
|
|
if (_peer->isUser()
|
|
|
|
&& !_peer->isSelf()
|
|
|
|
&& !_peer->isRepliesChat()
|
2021-05-27 00:44:12 +00:00
|
|
|
&& !_isChatWide) {
|
2018-01-21 19:21:08 +00:00
|
|
|
return false;
|
|
|
|
} else if (_peer->isChannel() && !_peer->isMegagroup()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
template <typename Method>
|
|
|
|
void HistoryInner::enumerateUserpics(Method method) {
|
2018-01-21 19:21:08 +00:00
|
|
|
if (!canHaveFromUserpics()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Find and remember the top of an attached messages pack
|
|
|
|
// -1 means we didn't find an attached to next message yet.
|
2017-04-08 13:27:53 +00:00
|
|
|
int lowestAttachedItemTop = -1;
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
auto userpicCallback = [&](not_null<Element*> view, int itemtop, int itembottom) {
|
2017-06-22 01:31:02 +00:00
|
|
|
// Skip all service messages.
|
2018-01-10 13:13:33 +00:00
|
|
|
const auto item = view->data();
|
2021-11-07 08:06:00 +00:00
|
|
|
if (view->isHidden() || item->isService()) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
if (lowestAttachedItemTop < 0 && view->isAttachedToNext()) {
|
|
|
|
lowestAttachedItemTop = itemtop + view->marginTop();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Call method on a userpic for all messages that have it and for those who are not showing it
|
|
|
|
// because of their attachment to the next message if they are bottom-most visible.
|
2018-01-13 12:45:11 +00:00
|
|
|
if (view->displayFromPhoto() || (view->hasFromPhoto() && itembottom >= _visibleAreaBottom)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (lowestAttachedItemTop < 0) {
|
2018-01-13 12:45:11 +00:00
|
|
|
lowestAttachedItemTop = itemtop + view->marginTop();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-06-22 01:31:02 +00:00
|
|
|
// Attach userpic to the bottom of the visible area with the same margin as the last message.
|
2017-04-08 13:27:53 +00:00
|
|
|
auto userpicMinBottomSkip = st::historyPaddingBottom + st::msgMargin.bottom();
|
2018-01-13 12:45:11 +00:00
|
|
|
auto userpicBottom = qMin(itembottom - view->marginBottom(), _visibleAreaBottom - userpicMinBottomSkip);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Do not let the userpic go above the attached messages pack top line.
|
2017-04-08 13:27:53 +00:00
|
|
|
userpicBottom = qMax(userpicBottom, lowestAttachedItemTop + st::msgPhotoSize);
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Call the template callback function that was passed
|
|
|
|
// and return if it finished everything it needed.
|
2018-01-11 15:51:59 +00:00
|
|
|
if (!method(view, userpicBottom - st::msgPhotoSize)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Forget the found top of the pack, search for the next one from scratch.
|
2018-01-13 12:45:11 +00:00
|
|
|
if (!view->isAttachedToNext()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
lowestAttachedItemTop = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
enumerateItems<EnumItemsDirection::TopToBottom>(userpicCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Method>
|
|
|
|
void HistoryInner::enumerateDates(Method method) {
|
2017-06-22 01:31:02 +00:00
|
|
|
auto drawtop = historyDrawTop();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Find and remember the bottom of an single-day messages pack
|
|
|
|
// -1 means we didn't find a same-day with previous message yet.
|
|
|
|
auto lowestInOneDayItemBottom = -1;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
auto dateCallback = [&](not_null<Element*> view, int itemtop, int itembottom) {
|
2018-01-10 13:13:33 +00:00
|
|
|
const auto item = view->data();
|
2018-01-23 11:47:38 +00:00
|
|
|
if (lowestInOneDayItemBottom < 0 && view->isInOneDayWithPrevious()) {
|
2018-01-13 12:45:11 +00:00
|
|
|
lowestInOneDayItemBottom = itembottom - view->marginBottom();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Call method on a date for all messages that have it and for those who are not showing it
|
|
|
|
// because they are in a one day together with the previous message if they are top-most visible.
|
2018-01-23 11:47:38 +00:00
|
|
|
if (view->displayDate() || (!item->isEmpty() && itemtop <= _visibleAreaTop)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// skip the date of history migrate item if it will be in migrated
|
|
|
|
if (itemtop < drawtop && item->history() == _history) {
|
|
|
|
if (itemtop > _visibleAreaTop) {
|
2017-06-22 01:31:02 +00:00
|
|
|
// Previous item (from the _migrated history) is drawing date now.
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lowestInOneDayItemBottom < 0) {
|
2018-01-13 12:45:11 +00:00
|
|
|
lowestInOneDayItemBottom = itembottom - view->marginBottom();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-06-22 01:31:02 +00:00
|
|
|
// Attach date to the top of the visible area with the same margin as it has in service message.
|
2017-04-08 13:27:53 +00:00
|
|
|
int dateTop = qMax(itemtop, _visibleAreaTop) + st::msgServiceMargin.top();
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Do not let the date go below the single-day messages pack bottom line.
|
2017-04-08 13:27:53 +00:00
|
|
|
int dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top();
|
|
|
|
dateTop = qMin(dateTop, lowestInOneDayItemBottom - dateHeight);
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Call the template callback function that was passed
|
|
|
|
// and return if it finished everything it needed.
|
2018-01-11 15:51:59 +00:00
|
|
|
if (!method(view, itemtop, dateTop)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:31:02 +00:00
|
|
|
// Forget the found bottom of the pack, search for the next one from scratch.
|
2018-01-23 11:47:38 +00:00
|
|
|
if (!view->isInOneDayWithPrevious()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
lowestInOneDayItemBottom = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
enumerateItems<EnumItemsDirection::BottomToTop>(dateCallback);
|
|
|
|
}
|
|
|
|
|
2017-12-16 15:00:20 +00:00
|
|
|
TextSelection HistoryInner::computeRenderSelection(
|
|
|
|
not_null<const SelectedItems*> selected,
|
2018-01-14 16:02:25 +00:00
|
|
|
not_null<Element*> view) const {
|
2018-01-27 13:59:24 +00:00
|
|
|
if (view->isHiddenByGroup()) {
|
|
|
|
return TextSelection();
|
|
|
|
}
|
|
|
|
const auto item = view->data();
|
2017-12-16 15:00:20 +00:00
|
|
|
const auto itemSelection = [&](not_null<HistoryItem*> item) {
|
|
|
|
auto i = selected->find(item);
|
|
|
|
if (i != selected->end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return TextSelection();
|
|
|
|
};
|
2018-01-27 13:59:24 +00:00
|
|
|
const auto result = itemSelection(item);
|
|
|
|
if (result != TextSelection() && result != FullSelection) {
|
|
|
|
return result;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto group = session().data().groups().find(item)) {
|
2018-01-27 13:59:24 +00:00
|
|
|
auto parts = TextSelection();
|
|
|
|
auto allFullSelected = true;
|
|
|
|
const auto count = int(group->items.size());
|
|
|
|
for (auto i = 0; i != count; ++i) {
|
|
|
|
const auto part = group->items[i];
|
|
|
|
const auto selection = itemSelection(part);
|
|
|
|
if (part == item
|
|
|
|
&& selection != FullSelection
|
|
|
|
&& selection != TextSelection()) {
|
|
|
|
return selection;
|
|
|
|
} else if (selection == FullSelection) {
|
|
|
|
parts = AddGroupItemSelection(parts, i);
|
|
|
|
} else {
|
|
|
|
allFullSelected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return allFullSelected ? FullSelection : parts;
|
|
|
|
}
|
|
|
|
return itemSelection(item);
|
2017-12-16 15:00:20 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
TextSelection HistoryInner::itemRenderSelection(
|
2018-01-11 19:33:26 +00:00
|
|
|
not_null<Element*> view,
|
2017-12-15 16:25:47 +00:00
|
|
|
int selfromy,
|
|
|
|
int seltoy) const {
|
2018-01-10 13:13:33 +00:00
|
|
|
const auto item = view->data();
|
2018-01-11 13:07:29 +00:00
|
|
|
const auto y = view->block()->y() + view->y();
|
2017-12-15 16:25:47 +00:00
|
|
|
if (y >= selfromy && y < seltoy) {
|
2021-11-07 08:06:00 +00:00
|
|
|
if (_dragSelecting && !item->isService() && item->isRegular()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return FullSelection;
|
|
|
|
}
|
|
|
|
} else if (!_selected.empty()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return computeRenderSelection(&_selected, view);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
return TextSelection();
|
|
|
|
}
|
|
|
|
|
2021-09-03 10:17:07 +00:00
|
|
|
void HistoryInner::paintEmpty(
|
|
|
|
Painter &p,
|
|
|
|
not_null<const Ui::ChatStyle*> st,
|
|
|
|
int width,
|
|
|
|
int height) {
|
2019-01-18 08:11:15 +00:00
|
|
|
if (!_emptyPainter) {
|
|
|
|
_emptyPainter = std::make_unique<HistoryView::EmptyPainter>(
|
|
|
|
_history);
|
|
|
|
}
|
2021-09-03 10:17:07 +00:00
|
|
|
_emptyPainter->paint(p, st, width, height);
|
2019-01-18 08:11:15 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::paintEvent(QPaintEvent *e) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (Ui::skipPaintEvent(this, e)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hasPendingResizedItems()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
const auto guard = gsl::finally([&] {
|
|
|
|
_userpicsCache.clear();
|
|
|
|
});
|
|
|
|
|
2021-09-03 10:17:07 +00:00
|
|
|
Painter p(this);
|
|
|
|
auto clip = e->rect();
|
|
|
|
|
|
|
|
const auto visibleAreaTopGlobal = mapToGlobal(
|
|
|
|
QPoint(0, _visibleAreaTop)).y();
|
|
|
|
auto context = _controller->preparePaintContext({
|
|
|
|
.theme = _theme.get(),
|
|
|
|
.visibleAreaTop = _visibleAreaTop,
|
|
|
|
.visibleAreaTopGlobal = visibleAreaTopGlobal,
|
2021-09-06 10:18:14 +00:00
|
|
|
.visibleAreaWidth = width(),
|
2021-09-03 10:17:07 +00:00
|
|
|
.clip = clip,
|
|
|
|
});
|
2021-07-02 15:29:13 +00:00
|
|
|
_pathGradient->startFrame(
|
|
|
|
0,
|
|
|
|
width(),
|
|
|
|
std::min(st::msgMaxWidth / 2, width() / 2));
|
|
|
|
|
2019-01-22 07:50:21 +00:00
|
|
|
const auto historyDisplayedEmpty = _history->isDisplayedEmpty()
|
|
|
|
&& (!_migrated || _migrated->isDisplayedEmpty());
|
2021-09-26 10:17:24 +00:00
|
|
|
bool noHistoryDisplayed = historyDisplayedEmpty;
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) {
|
2021-09-03 10:17:07 +00:00
|
|
|
const auto st = context.st;
|
|
|
|
const auto stm = &st->messageStyle(false, false);
|
2017-06-21 21:38:31 +00:00
|
|
|
if (clip.y() < _botAbout->rect.y() + _botAbout->rect.height() && clip.y() + clip.height() > _botAbout->rect.y()) {
|
2021-09-03 10:17:07 +00:00
|
|
|
p.setTextPalette(stm->textPalette);
|
2021-09-03 14:45:21 +00:00
|
|
|
Ui::FillRoundRect(p, _botAbout->rect, stm->msgBg, stm->msgBgCorners, &stm->msgShadow);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2020-10-01 08:05:47 +00:00
|
|
|
auto top = _botAbout->rect.top() + st::msgPadding.top();
|
|
|
|
if (!_history->peer->isRepliesChat()) {
|
|
|
|
p.setFont(st::msgNameFont);
|
2021-09-03 10:17:07 +00:00
|
|
|
p.setPen(st->dialogsNameFg());
|
2020-10-01 08:05:47 +00:00
|
|
|
p.drawText(_botAbout->rect.left() + st::msgPadding.left(), top + st::msgNameFont->ascent, tr::lng_bot_description(tr::now));
|
|
|
|
top += +st::msgNameFont->height + st::botDescSkip;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2021-09-03 10:17:07 +00:00
|
|
|
p.setPen(stm->historyTextFg);
|
2020-10-01 08:05:47 +00:00
|
|
|
_botAbout->info->text.draw(p, _botAbout->rect.left() + st::msgPadding.left(), top, _botAbout->width);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
p.restoreTextPalette();
|
|
|
|
}
|
2019-01-15 14:13:20 +00:00
|
|
|
} else if (historyDisplayedEmpty) {
|
2021-09-03 10:17:07 +00:00
|
|
|
paintEmpty(p, context.st, width(), height());
|
2019-01-22 07:50:21 +00:00
|
|
|
} else {
|
|
|
|
_emptyPainter = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (!noHistoryDisplayed) {
|
2017-12-07 13:02:24 +00:00
|
|
|
auto readMentions = base::flat_set<not_null<HistoryItem*>>();
|
2017-08-11 07:16:07 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
adjustCurrent(clip.top());
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
auto drawToY = clip.y() + clip.height();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
auto selfromy = itemTop(_dragSelFrom);
|
|
|
|
auto seltoy = itemTop(_dragSelTo);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selfromy < 0 || seltoy < 0) {
|
|
|
|
selfromy = seltoy = -1;
|
|
|
|
} else {
|
2018-01-13 12:45:11 +00:00
|
|
|
seltoy += _dragSelTo->height();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:53:08 +00:00
|
|
|
auto mtop = migratedTop();
|
|
|
|
auto htop = historyTop();
|
|
|
|
auto hdrawtop = historyDrawTop();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (mtop >= 0) {
|
2017-05-12 13:53:08 +00:00
|
|
|
auto iBlock = (_curHistory == _migrated ? _curBlock : (_migrated->blocks.size() - 1));
|
2018-01-10 13:13:33 +00:00
|
|
|
auto block = _migrated->blocks[iBlock].get();
|
|
|
|
auto iItem = (_curHistory == _migrated ? _curItem : (block->messages.size() - 1));
|
|
|
|
auto view = block->messages[iItem].get();
|
|
|
|
auto item = view->data();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2021-08-19 14:22:12 +00:00
|
|
|
auto top = mtop + block->y() + view->y();
|
2021-09-03 10:17:07 +00:00
|
|
|
context.translate(0, -top);
|
2021-08-19 14:22:12 +00:00
|
|
|
p.translate(0, top);
|
|
|
|
if (context.clip.y() < view->height()) while (top < drawToY) {
|
2021-09-02 22:08:57 +00:00
|
|
|
context.outbg = view->hasOutLayout();
|
2021-08-19 14:22:12 +00:00
|
|
|
context.selection = itemRenderSelection(
|
2018-01-10 13:13:33 +00:00
|
|
|
view,
|
2017-12-15 16:25:47 +00:00
|
|
|
selfromy - mtop,
|
|
|
|
seltoy - mtop);
|
2021-08-19 14:22:12 +00:00
|
|
|
view->draw(p, context);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2021-11-03 11:49:48 +00:00
|
|
|
const auto height = view->height();
|
|
|
|
const auto middle = top + height / 2;
|
|
|
|
if (_visibleAreaBottom >= middle
|
|
|
|
&& _visibleAreaTop <= middle) {
|
|
|
|
if (item->hasViews()) {
|
|
|
|
session().api().views().scheduleIncrement(item);
|
|
|
|
}
|
|
|
|
if (item->isUnreadMention() && !item->isUnreadMedia()) {
|
|
|
|
readMentions.insert(item);
|
|
|
|
_widget->enqueueMessageHighlight(view);
|
|
|
|
}
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2021-08-19 14:22:12 +00:00
|
|
|
top += height;
|
2021-08-20 10:12:07 +00:00
|
|
|
context.translate(0, -height);
|
2021-08-19 14:22:12 +00:00
|
|
|
p.translate(0, height);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
++iItem;
|
2018-01-10 13:13:33 +00:00
|
|
|
if (iItem == block->messages.size()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
iItem = 0;
|
|
|
|
++iBlock;
|
|
|
|
if (iBlock == _migrated->blocks.size()) {
|
|
|
|
break;
|
|
|
|
}
|
2018-01-10 13:13:33 +00:00
|
|
|
block = _migrated->blocks[iBlock].get();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2018-01-10 13:13:33 +00:00
|
|
|
view = block->messages[iItem].get();
|
|
|
|
item = view->data();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2021-08-19 14:22:12 +00:00
|
|
|
p.translate(0, -top);
|
2021-09-03 10:17:07 +00:00
|
|
|
context.translate(0, top);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (htop >= 0) {
|
2017-05-12 13:53:08 +00:00
|
|
|
auto iBlock = (_curHistory == _history ? _curBlock : 0);
|
2018-01-10 13:13:33 +00:00
|
|
|
auto block = _history->blocks[iBlock].get();
|
2017-05-12 13:53:08 +00:00
|
|
|
auto iItem = (_curHistory == _history ? _curItem : 0);
|
2018-01-10 13:13:33 +00:00
|
|
|
auto view = block->messages[iItem].get();
|
|
|
|
auto item = view->data();
|
2020-02-11 11:23:51 +00:00
|
|
|
auto readTill = (HistoryItem*)nullptr;
|
2021-08-19 14:22:12 +00:00
|
|
|
auto top = htop + block->y() + view->y();
|
2021-09-03 10:17:07 +00:00
|
|
|
context.clip = clip.intersected(
|
|
|
|
QRect(0, hdrawtop, width(), clip.top() + clip.height()));
|
|
|
|
context.translate(0, -top);
|
2021-08-19 14:22:12 +00:00
|
|
|
p.translate(0, top);
|
|
|
|
while (top < drawToY) {
|
|
|
|
const auto height = view->height();
|
|
|
|
if (context.clip.y() < height && hdrawtop < top + height) {
|
2021-09-02 22:08:57 +00:00
|
|
|
context.outbg = view->hasOutLayout();
|
2021-08-19 14:22:12 +00:00
|
|
|
context.selection = itemRenderSelection(
|
2018-01-10 13:13:33 +00:00
|
|
|
view,
|
2017-12-15 16:25:47 +00:00
|
|
|
selfromy - htop,
|
|
|
|
seltoy - htop);
|
2021-08-19 14:22:12 +00:00
|
|
|
view->draw(p, context);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2021-08-19 14:22:12 +00:00
|
|
|
const auto middle = top + height / 2;
|
|
|
|
const auto bottom = top + height;
|
2020-02-11 11:23:51 +00:00
|
|
|
if (_visibleAreaBottom >= bottom) {
|
2020-02-19 16:54:19 +00:00
|
|
|
const auto item = view->data();
|
|
|
|
if (!item->out() && item->unread()) {
|
|
|
|
readTill = item;
|
|
|
|
}
|
2021-11-03 11:49:48 +00:00
|
|
|
if (item->isSponsored()) {
|
|
|
|
session().data().sponsoredMessages().view(
|
|
|
|
item->fullId());
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2020-02-11 11:23:51 +00:00
|
|
|
if (_visibleAreaBottom >= middle
|
|
|
|
&& _visibleAreaTop <= middle) {
|
|
|
|
if (item->hasViews()) {
|
2021-09-28 21:23:58 +00:00
|
|
|
session().api().views().scheduleIncrement(item);
|
2020-02-11 11:23:51 +00:00
|
|
|
}
|
|
|
|
if (item->isUnreadMention() && !item->isUnreadMedia()) {
|
|
|
|
readMentions.insert(item);
|
|
|
|
_widget->enqueueMessageHighlight(view);
|
|
|
|
}
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2021-08-19 14:22:12 +00:00
|
|
|
top += height;
|
2021-08-20 10:12:07 +00:00
|
|
|
context.translate(0, -height);
|
2021-08-19 14:22:12 +00:00
|
|
|
p.translate(0, height);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
++iItem;
|
2018-01-10 13:13:33 +00:00
|
|
|
if (iItem == block->messages.size()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
iItem = 0;
|
|
|
|
++iBlock;
|
|
|
|
if (iBlock == _history->blocks.size()) {
|
|
|
|
break;
|
|
|
|
}
|
2018-01-10 13:13:33 +00:00
|
|
|
block = _history->blocks[iBlock].get();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2018-01-10 13:13:33 +00:00
|
|
|
view = block->messages[iItem].get();
|
|
|
|
item = view->data();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2021-08-19 14:22:12 +00:00
|
|
|
p.translate(0, -top);
|
2020-02-11 11:23:51 +00:00
|
|
|
|
2020-02-19 16:54:19 +00:00
|
|
|
if (readTill && _widget->doWeReadServerHistory()) {
|
2020-02-19 15:35:26 +00:00
|
|
|
session().data().histories().readInboxTill(readTill);
|
2020-02-11 11:23:51 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 11:23:51 +00:00
|
|
|
if (!readMentions.empty() && _widget->doWeReadMentions()) {
|
2019-07-24 11:13:51 +00:00
|
|
|
session().api().markMediaRead(readMentions);
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
if (mtop >= 0 || htop >= 0) {
|
2018-01-11 19:33:26 +00:00
|
|
|
enumerateUserpics([&](not_null<Element*> view, int userpicTop) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// stop the enumeration if the userpic is below the painted rect
|
2017-06-21 21:38:31 +00:00
|
|
|
if (userpicTop >= clip.top() + clip.height()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// paint the userpic if it intersects the painted rect
|
2017-06-21 21:38:31 +00:00
|
|
|
if (userpicTop + st::msgPhotoSize > clip.top()) {
|
2021-11-07 08:06:00 +00:00
|
|
|
if (const auto from = view->data()->displayFrom()) {
|
2019-03-15 15:15:56 +00:00
|
|
|
from->paintUserpicLeft(
|
|
|
|
p,
|
2020-05-28 14:32:10 +00:00
|
|
|
_userpics[from],
|
2019-03-15 15:15:56 +00:00
|
|
|
st::historyPhotoLeft,
|
|
|
|
userpicTop,
|
|
|
|
width(),
|
|
|
|
st::msgPhotoSize);
|
2021-11-07 08:06:00 +00:00
|
|
|
} else if (const auto info = view->data()->hiddenForwardedInfo()) {
|
2019-03-15 15:15:56 +00:00
|
|
|
info->userpic.paint(
|
|
|
|
p,
|
|
|
|
st::historyPhotoLeft,
|
|
|
|
userpicTop,
|
|
|
|
width(),
|
|
|
|
st::msgPhotoSize);
|
|
|
|
} else {
|
|
|
|
Unexpected("Corrupt forwarded information in message.");
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
int dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top();
|
|
|
|
//QDate lastDate;
|
|
|
|
//if (!_history->isEmpty()) {
|
2018-01-10 13:13:33 +00:00
|
|
|
// lastDate = _history->blocks.back()->messages.back()->data()->date.date();
|
2017-04-08 13:27:53 +00:00
|
|
|
//}
|
|
|
|
|
|
|
|
//// if item top is before this value always show date as a floating date
|
|
|
|
//int showFloatingBefore = height() - 2 * (_visibleAreaBottom - _visibleAreaTop) - dateHeight;
|
|
|
|
|
2018-01-21 19:21:08 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
auto scrollDateOpacity = _scrollDateOpacity.value(_scrollDateShown ? 1. : 0.);
|
2018-01-11 19:33:26 +00:00
|
|
|
enumerateDates([&](not_null<Element*> view, int itemtop, int dateTop) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// stop the enumeration if the date is above the painted rect
|
2017-06-21 21:38:31 +00:00
|
|
|
if (dateTop + dateHeight <= clip.top()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-23 11:47:38 +00:00
|
|
|
const auto displayDate = view->displayDate();
|
2018-01-11 15:51:59 +00:00
|
|
|
auto dateInPlace = displayDate;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dateInPlace) {
|
2018-01-11 15:51:59 +00:00
|
|
|
const auto correctDateTop = itemtop + st::msgServiceMargin.top();
|
2017-04-08 13:27:53 +00:00
|
|
|
dateInPlace = (dateTop < correctDateTop + dateHeight);
|
|
|
|
}
|
|
|
|
//bool noFloatingDate = (item->date.date() == lastDate && displayDate);
|
|
|
|
//if (noFloatingDate) {
|
|
|
|
// if (itemtop < showFloatingBefore) {
|
|
|
|
// noFloatingDate = false;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
// paint the date if it intersects the painted rect
|
2017-06-21 21:38:31 +00:00
|
|
|
if (dateTop < clip.top() + clip.height()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
auto opacity = (dateInPlace/* || noFloatingDate*/) ? 1. : scrollDateOpacity;
|
|
|
|
if (opacity > 0.) {
|
|
|
|
p.setOpacity(opacity);
|
2018-01-21 19:21:08 +00:00
|
|
|
const auto dateY = false // noFloatingDate
|
|
|
|
? itemtop
|
|
|
|
: (dateTop - st::msgServiceMargin.top());
|
2018-01-23 11:47:38 +00:00
|
|
|
if (const auto date = view->Get<HistoryView::DateBadge>()) {
|
2021-09-03 10:17:07 +00:00
|
|
|
date->paint(p, context.st, dateY, _contentWidth, _isChatWide);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2021-09-03 10:17:07 +00:00
|
|
|
HistoryView::ServiceMessagePainter::PaintDate(
|
2018-01-09 17:08:31 +00:00
|
|
|
p,
|
2021-09-03 10:17:07 +00:00
|
|
|
context.st,
|
2018-02-03 19:52:35 +00:00
|
|
|
view->dateTime(),
|
2018-01-09 17:08:31 +00:00
|
|
|
dateY,
|
2021-05-27 00:44:12 +00:00
|
|
|
_contentWidth,
|
|
|
|
_isChatWide);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2021-09-15 14:49:06 +00:00
|
|
|
p.setOpacity(1.);
|
|
|
|
p.translate(0, _historyPaddingTop);
|
|
|
|
_emojiInteractions->paint(p);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
bool HistoryInner::eventHook(QEvent *e) {
|
|
|
|
if (e->type() == QEvent::TouchBegin
|
|
|
|
|| e->type() == QEvent::TouchUpdate
|
|
|
|
|| e->type() == QEvent::TouchEnd
|
|
|
|
|| e->type() == QEvent::TouchCancel) {
|
2017-04-08 13:27:53 +00:00
|
|
|
QTouchEvent *ev = static_cast<QTouchEvent*>(e);
|
2021-10-19 13:00:21 +00:00
|
|
|
if (ev->device()->type() == base::TouchDevice::TouchScreen) {
|
2017-04-08 13:27:53 +00:00
|
|
|
touchEvent(ev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
return RpWidget::eventHook(e);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onTouchScrollTimer() {
|
2019-02-19 06:57:53 +00:00
|
|
|
auto nowTime = crl::now();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Acceleration && _touchWaitingAcceleration && (nowTime - _touchAccelerationTime) > 40) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
|
|
|
touchResetSpeed();
|
|
|
|
} else if (_touchScrollState == Ui::TouchScrollState::Auto || _touchScrollState == Ui::TouchScrollState::Acceleration) {
|
|
|
|
int32 elapsed = int32(nowTime - _touchTime);
|
|
|
|
QPoint delta = _touchSpeed * elapsed / 1000;
|
|
|
|
bool hasScrolled = _widget->touchScroll(delta);
|
|
|
|
|
|
|
|
if (_touchSpeed.isNull() || !hasScrolled) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
|
|
|
_touchScroll = false;
|
2021-09-29 00:00:11 +00:00
|
|
|
_touchScrollTimer.cancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
_touchTime = nowTime;
|
|
|
|
}
|
|
|
|
touchDeaccelerate(elapsed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchUpdateSpeed() {
|
2019-02-19 06:57:53 +00:00
|
|
|
const auto nowTime = crl::now();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_touchPrevPosValid) {
|
|
|
|
const int elapsed = nowTime - _touchSpeedTime;
|
|
|
|
if (elapsed) {
|
|
|
|
const QPoint newPixelDiff = (_touchPos - _touchPrevPos);
|
|
|
|
const QPoint pixelsPerSecond = newPixelDiff * (1000 / elapsed);
|
|
|
|
|
|
|
|
// fingers are inacurates, we ignore small changes to avoid stopping the autoscroll because
|
|
|
|
// of a small horizontal offset when scrolling vertically
|
2019-09-16 11:14:06 +00:00
|
|
|
const int newSpeedY = (qAbs(pixelsPerSecond.y()) > Ui::kFingerAccuracyThreshold) ? pixelsPerSecond.y() : 0;
|
|
|
|
const int newSpeedX = (qAbs(pixelsPerSecond.x()) > Ui::kFingerAccuracyThreshold) ? pixelsPerSecond.x() : 0;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Auto) {
|
|
|
|
const int oldSpeedY = _touchSpeed.y();
|
|
|
|
const int oldSpeedX = _touchSpeed.x();
|
|
|
|
if ((oldSpeedY <= 0 && newSpeedY <= 0) || ((oldSpeedY >= 0 && newSpeedY >= 0)
|
|
|
|
&& (oldSpeedX <= 0 && newSpeedX <= 0)) || (oldSpeedX >= 0 && newSpeedX >= 0)) {
|
2021-01-23 03:29:50 +00:00
|
|
|
_touchSpeed.setY(std::clamp(
|
|
|
|
(oldSpeedY + (newSpeedY / 4)),
|
|
|
|
-Ui::kMaxScrollAccelerated,
|
|
|
|
+Ui::kMaxScrollAccelerated));
|
|
|
|
_touchSpeed.setX(std::clamp(
|
|
|
|
(oldSpeedX + (newSpeedX / 4)),
|
|
|
|
-Ui::kMaxScrollAccelerated,
|
|
|
|
+Ui::kMaxScrollAccelerated));
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
_touchSpeed = QPoint();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we average the speed to avoid strange effects with the last delta
|
|
|
|
if (!_touchSpeed.isNull()) {
|
2021-01-23 03:29:50 +00:00
|
|
|
_touchSpeed.setX(std::clamp(
|
|
|
|
(_touchSpeed.x() / 4) + (newSpeedX * 3 / 4),
|
|
|
|
-Ui::kMaxScrollFlick,
|
|
|
|
+Ui::kMaxScrollFlick));
|
|
|
|
_touchSpeed.setY(std::clamp(
|
|
|
|
(_touchSpeed.y() / 4) + (newSpeedY * 3 / 4),
|
|
|
|
-Ui::kMaxScrollFlick,
|
|
|
|
+Ui::kMaxScrollFlick));
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
_touchSpeed = QPoint(newSpeedX, newSpeedY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_touchPrevPosValid = true;
|
|
|
|
}
|
|
|
|
_touchSpeedTime = nowTime;
|
|
|
|
_touchPrevPos = _touchPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchResetSpeed() {
|
|
|
|
_touchSpeed = QPoint();
|
|
|
|
_touchPrevPosValid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchDeaccelerate(int32 elapsed) {
|
|
|
|
int32 x = _touchSpeed.x();
|
|
|
|
int32 y = _touchSpeed.y();
|
|
|
|
_touchSpeed.setX((x == 0) ? x : (x > 0) ? qMax(0, x - elapsed) : qMin(0, x + elapsed));
|
|
|
|
_touchSpeed.setY((y == 0) ? y : (y > 0) ? qMax(0, y - elapsed) : qMin(0, y + elapsed));
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchEvent(QTouchEvent *e) {
|
|
|
|
if (e->type() == QEvent::TouchCancel) { // cancel
|
|
|
|
if (!_touchInProgress) return;
|
|
|
|
_touchInProgress = false;
|
2021-09-29 00:00:11 +00:00
|
|
|
_touchSelectTimer.cancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
_touchScroll = _touchSelect = false;
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionCancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e->touchPoints().isEmpty()) {
|
|
|
|
_touchPrevPos = _touchPos;
|
|
|
|
_touchPos = e->touchPoints().cbegin()->screenPos().toPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (e->type()) {
|
2017-11-30 18:18:39 +00:00
|
|
|
case QEvent::TouchBegin: {
|
|
|
|
if (_menu) {
|
|
|
|
e->accept();
|
|
|
|
return; // ignore mouse press, that was hiding context menu
|
|
|
|
}
|
|
|
|
if (_touchInProgress) return;
|
|
|
|
if (e->touchPoints().isEmpty()) return;
|
|
|
|
|
|
|
|
_touchInProgress = true;
|
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Auto) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Acceleration;
|
|
|
|
_touchWaitingAcceleration = true;
|
2019-02-19 06:57:53 +00:00
|
|
|
_touchAccelerationTime = crl::now();
|
2017-11-30 18:18:39 +00:00
|
|
|
touchUpdateSpeed();
|
|
|
|
_touchStart = _touchPos;
|
|
|
|
} else {
|
|
|
|
_touchScroll = false;
|
2021-09-29 00:00:11 +00:00
|
|
|
_touchSelectTimer.callOnce(QApplication::startDragTime());
|
2017-11-30 18:18:39 +00:00
|
|
|
}
|
|
|
|
_touchSelect = false;
|
|
|
|
_touchStart = _touchPrevPos = _touchPos;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::TouchUpdate: {
|
|
|
|
if (!_touchInProgress) return;
|
|
|
|
if (_touchSelect) {
|
|
|
|
mouseActionUpdate(_touchPos);
|
|
|
|
} else if (!_touchScroll && (_touchPos - _touchStart).manhattanLength() >= QApplication::startDragDistance()) {
|
2021-09-29 00:00:11 +00:00
|
|
|
_touchSelectTimer.cancel();
|
2017-11-30 18:18:39 +00:00
|
|
|
_touchScroll = true;
|
|
|
|
touchUpdateSpeed();
|
|
|
|
}
|
|
|
|
if (_touchScroll) {
|
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Manual) {
|
|
|
|
touchScrollUpdated(_touchPos);
|
|
|
|
} else if (_touchScrollState == Ui::TouchScrollState::Acceleration) {
|
|
|
|
touchUpdateSpeed();
|
2019-02-19 06:57:53 +00:00
|
|
|
_touchAccelerationTime = crl::now();
|
2017-11-30 18:18:39 +00:00
|
|
|
if (_touchSpeed.isNull()) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-30 18:18:39 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::TouchEnd: {
|
|
|
|
if (!_touchInProgress) return;
|
|
|
|
_touchInProgress = false;
|
2019-09-13 12:22:54 +00:00
|
|
|
auto weak = Ui::MakeWeak(this);
|
2017-11-30 18:18:39 +00:00
|
|
|
if (_touchSelect) {
|
|
|
|
mouseActionFinish(_touchPos, Qt::RightButton);
|
|
|
|
QContextMenuEvent contextMenu(QContextMenuEvent::Mouse, mapFromGlobal(_touchPos), _touchPos);
|
|
|
|
showContextMenu(&contextMenu, true);
|
2017-04-08 13:27:53 +00:00
|
|
|
_touchScroll = false;
|
2017-11-30 18:18:39 +00:00
|
|
|
} else if (_touchScroll) {
|
|
|
|
if (_touchScrollState == Ui::TouchScrollState::Manual) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Auto;
|
|
|
|
_touchPrevPosValid = false;
|
2021-09-29 00:00:11 +00:00
|
|
|
_touchScrollTimer.callEach(15);
|
2019-02-19 06:57:53 +00:00
|
|
|
_touchTime = crl::now();
|
2017-11-30 18:18:39 +00:00
|
|
|
} else if (_touchScrollState == Ui::TouchScrollState::Auto) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Manual;
|
|
|
|
_touchScroll = false;
|
|
|
|
touchResetSpeed();
|
|
|
|
} else if (_touchScrollState == Ui::TouchScrollState::Acceleration) {
|
|
|
|
_touchScrollState = Ui::TouchScrollState::Auto;
|
|
|
|
_touchWaitingAcceleration = false;
|
|
|
|
_touchPrevPosValid = false;
|
|
|
|
}
|
|
|
|
} else { // One short tap is like left mouse click.
|
|
|
|
mouseActionStart(_touchPos, Qt::LeftButton);
|
|
|
|
mouseActionFinish(_touchPos, Qt::LeftButton);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-11-30 18:18:39 +00:00
|
|
|
if (weak) {
|
2021-09-29 00:00:11 +00:00
|
|
|
_touchSelectTimer.cancel();
|
2017-11-30 18:18:39 +00:00
|
|
|
_touchSelect = false;
|
|
|
|
}
|
|
|
|
} break;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::mouseMoveEvent(QMouseEvent *e) {
|
2017-05-16 13:41:47 +00:00
|
|
|
static auto lastGlobalPosition = e->globalPos();
|
|
|
|
auto reallyMoved = (lastGlobalPosition != e->globalPos());
|
2017-04-08 13:27:53 +00:00
|
|
|
auto buttonsPressed = (e->buttons() & (Qt::LeftButton | Qt::MiddleButton));
|
2017-06-21 21:38:31 +00:00
|
|
|
if (!buttonsPressed && _mouseAction != MouseAction::None) {
|
2017-04-08 13:27:53 +00:00
|
|
|
mouseReleaseEvent(e);
|
|
|
|
}
|
2017-05-16 13:41:47 +00:00
|
|
|
if (reallyMoved) {
|
|
|
|
lastGlobalPosition = e->globalPos();
|
|
|
|
if (!buttonsPressed || (_scrollDateLink && ClickHandler::getPressed() == _scrollDateLink)) {
|
|
|
|
keepScrollDateForNow();
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(e->globalPos());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void HistoryInner::mouseActionUpdate(const QPoint &screenPos) {
|
|
|
|
_mousePosition = screenPos;
|
2018-01-27 13:59:24 +00:00
|
|
|
mouseActionUpdate();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::touchScrollUpdated(const QPoint &screenPos) {
|
|
|
|
_touchPos = screenPos;
|
|
|
|
_widget->touchScroll(_touchPos - _touchPrevPos);
|
|
|
|
touchUpdateSpeed();
|
|
|
|
}
|
|
|
|
|
2018-12-24 10:12:45 +00:00
|
|
|
QPoint HistoryInner::mapPointToItem(QPoint p, const Element *view) const {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (view) {
|
|
|
|
const auto top = itemTop(view);
|
|
|
|
p.setY(p.y() - top);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return QPoint();
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-12-24 10:12:45 +00:00
|
|
|
QPoint HistoryInner::mapPointToItem(
|
|
|
|
QPoint p,
|
|
|
|
const HistoryItem *item) const {
|
2018-01-11 13:07:29 +00:00
|
|
|
return item ? mapPointToItem(p, item->mainView()) : QPoint();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (_menu) {
|
|
|
|
e->accept();
|
|
|
|
return; // ignore mouse press, that was hiding context menu
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionStart(e->globalPos(), e->button());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void HistoryInner::mouseActionStart(const QPoint &screenPos, Qt::MouseButton button) {
|
|
|
|
mouseActionUpdate(screenPos);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (button != Qt::LeftButton) return;
|
|
|
|
|
|
|
|
ClickHandler::pressed();
|
|
|
|
if (App::pressedItem() != App::hoveredItem()) {
|
|
|
|
repaintItem(App::pressedItem());
|
|
|
|
App::pressedItem(App::hoveredItem());
|
|
|
|
repaintItem(App::pressedItem());
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto mouseActionView = App::mousedItem();
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::None;
|
2018-01-13 12:45:11 +00:00
|
|
|
_mouseActionItem = mouseActionView
|
|
|
|
? mouseActionView->data().get()
|
2018-01-11 13:07:29 +00:00
|
|
|
: nullptr;
|
2018-01-13 12:45:11 +00:00
|
|
|
_dragStartPosition = mapPointToItem(mapFromGlobal(screenPos), mouseActionView);
|
2019-09-16 11:14:06 +00:00
|
|
|
_pressWasInactive = Ui::WasInactivePress(_controller->widget());
|
|
|
|
if (_pressWasInactive) {
|
|
|
|
Ui::MarkInactivePress(_controller->widget(), false);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
if (ClickHandler::getPressed()) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::PrepareDrag;
|
2021-02-15 17:37:22 +00:00
|
|
|
} else if (inSelectionMode()) {
|
|
|
|
if (_dragStateItem
|
|
|
|
&& _selected.find(_dragStateItem) != _selected.cend()
|
|
|
|
&& App::hoveredItem()) {
|
|
|
|
_mouseAction = MouseAction::PrepareDrag; // start items drag
|
|
|
|
} else if (!_pressWasInactive) {
|
|
|
|
_mouseAction = MouseAction::PrepareSelect; // start items select
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
if (_mouseAction == MouseAction::None && mouseActionView) {
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState dragState;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_trippleClickTimer.isActive() && (screenPos - _trippleClickPoint).manhattanLength() < QApplication::startDragDistance()) {
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request;
|
2019-06-12 13:26:04 +00:00
|
|
|
request.flags = Ui::Text::StateRequest::Flag::LookupSymbol;
|
2018-01-27 13:59:24 +00:00
|
|
|
dragState = mouseActionView->textState(_dragStartPosition, request);
|
|
|
|
if (dragState.cursor == CursorState::Text) {
|
2017-04-08 13:27:53 +00:00
|
|
|
TextSelection selStatus = { dragState.symbol, dragState.symbol };
|
2017-10-05 15:35:52 +00:00
|
|
|
if (selStatus != FullSelection && (_selected.empty() || _selected.cbegin()->second != FullSelection)) {
|
|
|
|
if (!_selected.empty()) {
|
|
|
|
repaintItem(_selected.cbegin()->first);
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
_selected.emplace(_mouseActionItem, selStatus);
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseTextSymbol = dragState.symbol;
|
|
|
|
_mouseAction = MouseAction::Selecting;
|
|
|
|
_mouseSelectType = TextSelectType::Paragraphs;
|
|
|
|
mouseActionUpdate(_mousePosition);
|
2021-09-29 00:00:11 +00:00
|
|
|
_trippleClickTimer.callOnce(
|
|
|
|
QApplication::doubleClickInterval());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (App::pressedItem()) {
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request;
|
2019-06-12 13:26:04 +00:00
|
|
|
request.flags = Ui::Text::StateRequest::Flag::LookupSymbol;
|
2018-01-27 13:59:24 +00:00
|
|
|
dragState = mouseActionView->textState(_dragStartPosition, request);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseSelectType != TextSelectType::Paragraphs) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (App::pressedItem()) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseTextSymbol = dragState.symbol;
|
2018-01-27 13:59:24 +00:00
|
|
|
bool uponSelected = (dragState.cursor == CursorState::Text);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (uponSelected) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.empty()
|
|
|
|
|| _selected.cbegin()->second == FullSelection
|
|
|
|
|| _selected.cbegin()->first != _mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
uponSelected = false;
|
|
|
|
} else {
|
2017-10-05 15:35:52 +00:00
|
|
|
uint16 selFrom = _selected.cbegin()->second.from, selTo = _selected.cbegin()->second.to;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseTextSymbol < selFrom || _mouseTextSymbol >= selTo) {
|
2017-04-08 13:27:53 +00:00
|
|
|
uponSelected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (uponSelected) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::PrepareDrag; // start text drag
|
|
|
|
} else if (!_pressWasInactive) {
|
2019-08-02 15:06:44 +00:00
|
|
|
const auto media = App::pressedItem()->media();
|
|
|
|
if ((media && media->dragItem())
|
2018-01-27 13:59:24 +00:00
|
|
|
|| _mouseCursorState == CursorState::Date) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::PrepareDrag; // start sticker drag or by-date drag
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (dragState.afterSymbol) ++_mouseTextSymbol;
|
|
|
|
TextSelection selStatus = { _mouseTextSymbol, _mouseTextSymbol };
|
2017-10-05 15:35:52 +00:00
|
|
|
if (selStatus != FullSelection && (_selected.empty() || _selected.cbegin()->second != FullSelection)) {
|
|
|
|
if (!_selected.empty()) {
|
|
|
|
repaintItem(_selected.cbegin()->first);
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
_selected.emplace(_mouseActionItem, selStatus);
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::Selecting;
|
|
|
|
repaintItem(_mouseActionItem);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::PrepareSelect;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (!_pressWasInactive) {
|
|
|
|
_mouseAction = MouseAction::PrepareSelect; // start items select
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (!_mouseActionItem) {
|
|
|
|
_mouseAction = MouseAction::None;
|
|
|
|
} else if (_mouseAction == MouseAction::None) {
|
|
|
|
_mouseActionItem = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void HistoryInner::mouseActionCancel() {
|
|
|
|
_mouseActionItem = nullptr;
|
2017-12-15 16:25:47 +00:00
|
|
|
_dragStateItem = nullptr;
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::None;
|
|
|
|
_dragStartPosition = QPoint(0, 0);
|
|
|
|
_dragSelFrom = _dragSelTo = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
_wasSelectedText = false;
|
2021-10-30 06:11:27 +00:00
|
|
|
_selectScroll.cancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 19:21:41 +00:00
|
|
|
std::unique_ptr<QMimeData> HistoryInner::prepareDrag() {
|
|
|
|
if (_mouseAction != MouseAction::Dragging) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto pressedHandler = ClickHandler::getPressed();
|
|
|
|
if (dynamic_cast<VoiceSeekClickHandler*>(pressedHandler.get())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
const auto mouseActionView = _mouseActionItem
|
|
|
|
? _mouseActionItem->mainView()
|
|
|
|
: nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
bool uponSelected = false;
|
2018-01-13 12:45:11 +00:00
|
|
|
if (mouseActionView) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty() && _selected.cbegin()->second == FullSelection) {
|
2017-12-15 16:25:47 +00:00
|
|
|
uponSelected = _dragStateItem
|
|
|
|
&& (_selected.find(_dragStateItem) != _selected.cend());
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request;
|
2019-06-12 13:26:04 +00:00
|
|
|
request.flags |= Ui::Text::StateRequest::Flag::LookupSymbol;
|
2018-01-27 13:59:24 +00:00
|
|
|
auto dragState = mouseActionView->textState(_dragStartPosition, request);
|
|
|
|
uponSelected = (dragState.cursor == CursorState::Text);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (uponSelected) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.empty()
|
|
|
|
|| _selected.cbegin()->second == FullSelection
|
|
|
|
|| _selected.cbegin()->first != _mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
uponSelected = false;
|
|
|
|
} else {
|
2017-10-05 15:35:52 +00:00
|
|
|
uint16 selFrom = _selected.cbegin()->second.from, selTo = _selected.cbegin()->second.to;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dragState.symbol < selFrom || dragState.symbol >= selTo) {
|
|
|
|
uponSelected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
auto urls = QList<QUrl>();
|
|
|
|
const auto selectedText = [&] {
|
|
|
|
if (uponSelected) {
|
|
|
|
return getSelectedText();
|
|
|
|
} else if (pressedHandler) {
|
|
|
|
//if (!sel.isEmpty() && sel.at(0) != '/' && sel.at(0) != '@' && sel.at(0) != '#') {
|
|
|
|
// urls.push_back(QUrl::fromEncoded(sel.toUtf8())); // Google Chrome crashes in Mac OS X O_o
|
|
|
|
//}
|
|
|
|
return TextForMimeData::Simple(pressedHandler->dragText());
|
|
|
|
}
|
|
|
|
return TextForMimeData();
|
|
|
|
}();
|
2019-09-16 11:14:06 +00:00
|
|
|
if (auto mimeData = TextUtilities::MimeDataFromText(selectedText)) {
|
2019-04-04 10:02:22 +00:00
|
|
|
updateDragSelection(nullptr, nullptr, false);
|
2021-10-30 06:11:27 +00:00
|
|
|
_selectScroll.cancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
if (!urls.isEmpty()) mimeData->setUrls(urls);
|
2021-05-26 21:06:39 +00:00
|
|
|
if (uponSelected && !_controller->adaptive().isOneColumn()) {
|
2017-04-27 21:17:00 +00:00
|
|
|
auto selectedState = getSelectionState();
|
|
|
|
if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) {
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().setMimeForwardIds(getSelectedItems());
|
2018-01-11 15:51:59 +00:00
|
|
|
mimeData->setData(qsl("application/x-td-forward"), "1");
|
2017-04-27 21:17:00 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2018-01-27 19:21:41 +00:00
|
|
|
return mimeData;
|
|
|
|
} else if (_dragStateItem) {
|
|
|
|
const auto view = _dragStateItem->mainView();
|
|
|
|
if (!view) {
|
|
|
|
return nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2018-01-27 19:21:41 +00:00
|
|
|
auto forwardIds = MessageIdsList();
|
|
|
|
if (_mouseCursorState == CursorState::Date) {
|
2019-07-24 11:13:51 +00:00
|
|
|
forwardIds = session().data().itemOrItsGroup(_dragStateItem);
|
2018-01-27 19:21:41 +00:00
|
|
|
} else if (view->isHiddenByGroup() && pressedHandler) {
|
|
|
|
forwardIds = MessageIdsList(1, _dragStateItem->fullId());
|
|
|
|
} else if (const auto media = view->media()) {
|
|
|
|
if (media->dragItemByHandler(pressedHandler)
|
|
|
|
|| media->dragItem()) {
|
|
|
|
forwardIds = MessageIdsList(1, _dragStateItem->fullId());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-27 19:21:41 +00:00
|
|
|
if (forwardIds.empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().setMimeForwardIds(std::move(forwardIds));
|
2018-01-27 19:21:41 +00:00
|
|
|
auto result = std::make_unique<QMimeData>();
|
|
|
|
result->setData(qsl("application/x-td-forward"), "1");
|
|
|
|
if (const auto media = view->media()) {
|
|
|
|
if (const auto document = media->getDocument()) {
|
2020-04-09 14:02:09 +00:00
|
|
|
const auto filepath = document->filepath(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!filepath.isEmpty()) {
|
|
|
|
QList<QUrl> urls;
|
|
|
|
urls.push_back(QUrl::fromLocalFile(filepath));
|
2018-01-27 19:21:41 +00:00
|
|
|
result->setUrls(urls);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-27 19:21:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::performDrag() {
|
|
|
|
if (auto mimeData = prepareDrag()) {
|
|
|
|
// This call enters event loop and can destroy any QObject.
|
2021-05-25 12:42:26 +00:00
|
|
|
_controller->widget()->launchDrag(
|
|
|
|
std::move(mimeData),
|
|
|
|
crl::guard(this, [=] { mouseActionUpdate(QCursor::pos()); }));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
void HistoryInner::itemRemoved(not_null<const HistoryItem*> item) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_history != item->history() && _migrated != item->history()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-01 12:55:14 +00:00
|
|
|
_animatedStickersPlayed.remove(item);
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
auto i = _selected.find(item);
|
|
|
|
if (i != _selected.cend()) {
|
|
|
|
_selected.erase(i);
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseActionItem == item) {
|
|
|
|
mouseActionCancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
if (_dragStateItem == item) {
|
|
|
|
_dragStateItem = nullptr;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-01-25 14:19:14 +00:00
|
|
|
if ((_dragSelFrom && _dragSelFrom->data() == item)
|
|
|
|
|| (_dragSelTo && _dragSelTo->data() == item)) {
|
2018-01-11 13:07:29 +00:00
|
|
|
_dragSelFrom = nullptr;
|
|
|
|
_dragSelTo = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
update();
|
|
|
|
}
|
2018-03-08 10:47:31 +00:00
|
|
|
if (_scrollDateLastItem && _scrollDateLastItem->data() == item) {
|
|
|
|
_scrollDateLastItem = nullptr;
|
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
mouseActionUpdate();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 11:44:42 +00:00
|
|
|
void HistoryInner::viewRemoved(not_null<const Element*> view) {
|
2020-07-02 09:35:07 +00:00
|
|
|
const auto refresh = [&](auto &saved) {
|
|
|
|
if (saved == view) {
|
|
|
|
const auto now = view->data()->mainView();
|
|
|
|
saved = (now && now != view) ? now : nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
refresh(_dragSelFrom);
|
|
|
|
refresh(_dragSelTo);
|
|
|
|
refresh(_scrollDateLastItem);
|
2018-03-08 10:47:31 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
void HistoryInner::mouseActionFinish(
|
|
|
|
const QPoint &screenPos,
|
|
|
|
Qt::MouseButton button) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(screenPos);
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-10-13 19:07:04 +00:00
|
|
|
auto activated = ClickHandler::unpressed();
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Dragging) {
|
2017-12-18 09:07:18 +00:00
|
|
|
activated = nullptr;
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if (_mouseActionItem) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// if we are in selecting items mode perhaps we want to
|
|
|
|
// toggle selection instead of activating the pressed link
|
2021-02-15 17:37:22 +00:00
|
|
|
if (_mouseAction == MouseAction::PrepareDrag
|
|
|
|
&& !_pressWasInactive
|
|
|
|
&& inSelectionMode()
|
|
|
|
&& button != Qt::RightButton) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto view = _mouseActionItem->mainView()) {
|
2021-02-16 13:50:41 +00:00
|
|
|
if (view->toggleSelectionByHandlerClick(activated)) {
|
|
|
|
activated = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 18:13:48 +00:00
|
|
|
const auto pressedItemView = App::pressedItem();
|
|
|
|
if (pressedItemView) {
|
|
|
|
repaintItem(pressedItemView);
|
2017-04-08 13:27:53 +00:00
|
|
|
App::pressedItem(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
_wasSelectedText = false;
|
|
|
|
|
|
|
|
if (activated) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionCancel();
|
2018-07-09 18:13:48 +00:00
|
|
|
const auto pressedItemId = pressedItemView
|
|
|
|
? pressedItemView->data()->fullId()
|
|
|
|
: FullMsgId();
|
2019-09-16 11:14:06 +00:00
|
|
|
ActivateClickHandler(window(), activated, {
|
2018-07-09 18:13:48 +00:00
|
|
|
button,
|
2020-11-10 16:38:21 +00:00
|
|
|
QVariant::fromValue(ClickHandlerContext{
|
|
|
|
.itemId = pressedItemId,
|
|
|
|
.elementDelegate = [weak = Ui::MakeWeak(this)] {
|
|
|
|
return weak
|
|
|
|
? HistoryInner::ElementDelegate().get()
|
|
|
|
: nullptr;
|
|
|
|
},
|
2021-02-25 15:12:51 +00:00
|
|
|
.sessionWindow = base::make_weak(_controller.get()),
|
2020-11-10 16:38:21 +00:00
|
|
|
})
|
2018-07-09 18:13:48 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
if ((_mouseAction == MouseAction::PrepareSelect)
|
|
|
|
&& !_pressWasInactive
|
2021-02-15 17:37:22 +00:00
|
|
|
&& inSelectionMode()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelectionAsGroup(
|
2017-12-15 16:25:47 +00:00
|
|
|
&_selected,
|
|
|
|
_mouseActionItem,
|
|
|
|
SelectAction::Invert);
|
2017-06-21 21:38:31 +00:00
|
|
|
repaintItem(_mouseActionItem);
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if ((_mouseAction == MouseAction::PrepareDrag)
|
|
|
|
&& !_pressWasInactive
|
|
|
|
&& _dragStateItem
|
|
|
|
&& (button != Qt::RightButton)) {
|
|
|
|
auto i = _selected.find(_dragStateItem);
|
2017-10-05 15:35:52 +00:00
|
|
|
if (i != _selected.cend() && i->second == FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.erase(i);
|
2017-06-21 21:38:31 +00:00
|
|
|
repaintItem(_mouseActionItem);
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if ((i == _selected.cend())
|
2021-11-07 08:06:00 +00:00
|
|
|
&& !_dragStateItem->isService()
|
|
|
|
&& _dragStateItem->isRegular()
|
2021-02-15 17:37:22 +00:00
|
|
|
&& inSelectionMode()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_selected.size() < MaxSelectedItems) {
|
2017-12-15 16:25:47 +00:00
|
|
|
_selected.emplace(_dragStateItem, FullSelection);
|
2017-06-21 21:38:31 +00:00
|
|
|
repaintItem(_mouseActionItem);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_selected.clear();
|
|
|
|
update();
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (_mouseAction == MouseAction::Selecting) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_dragSelFrom && _dragSelTo) {
|
|
|
|
applyDragSelection();
|
2018-01-11 13:07:29 +00:00
|
|
|
_dragSelFrom = _dragSelTo = nullptr;
|
2017-10-05 15:35:52 +00:00
|
|
|
} else if (!_selected.empty() && !_pressWasInactive) {
|
|
|
|
auto sel = _selected.cbegin()->second;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (sel != FullSelection && sel.from == sel.to) {
|
|
|
|
_selected.clear();
|
2021-02-03 03:31:11 +00:00
|
|
|
_controller->widget()->setInnerFocus();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::None;
|
|
|
|
_mouseActionItem = nullptr;
|
|
|
|
_mouseSelectType = TextSelectType::Letters;
|
2021-10-30 06:11:27 +00:00
|
|
|
_selectScroll.cancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
|
2020-11-06 05:12:18 +00:00
|
|
|
if (QGuiApplication::clipboard()->supportsSelection()
|
|
|
|
&& !_selected.empty()
|
|
|
|
&& _selected.cbegin()->second != FullSelection) {
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto [item, selection] = *_selected.cbegin();
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto view = item->mainView()) {
|
2019-09-16 11:14:06 +00:00
|
|
|
TextUtilities::SetClipboardText(
|
2018-01-14 16:02:25 +00:00
|
|
|
view->selectedText(selection),
|
|
|
|
QClipboard::Selection);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::mouseReleaseEvent(QMouseEvent *e) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionFinish(e->globalPos(), e->button());
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!rect().contains(e->pos())) {
|
|
|
|
leaveEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::mouseDoubleClickEvent(QMouseEvent *e) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionStart(e->globalPos(), e->button());
|
2018-01-13 12:45:11 +00:00
|
|
|
|
|
|
|
const auto mouseActionView = _mouseActionItem
|
|
|
|
? _mouseActionItem->mainView()
|
|
|
|
: nullptr;
|
|
|
|
if (_mouseSelectType == TextSelectType::Letters
|
|
|
|
&& mouseActionView
|
|
|
|
&& ((_mouseAction == MouseAction::Selecting
|
|
|
|
&& !_selected.empty()
|
|
|
|
&& _selected.cbegin()->second != FullSelection)
|
|
|
|
|| (_mouseAction == MouseAction::None
|
|
|
|
&& (_selected.empty()
|
|
|
|
|| _selected.cbegin()->second != FullSelection)))) {
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request;
|
2019-06-12 13:26:04 +00:00
|
|
|
request.flags |= Ui::Text::StateRequest::Flag::LookupSymbol;
|
2018-01-27 13:59:24 +00:00
|
|
|
auto dragState = mouseActionView->textState(_dragStartPosition, request);
|
|
|
|
if (dragState.cursor == CursorState::Text) {
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseTextSymbol = dragState.symbol;
|
|
|
|
_mouseSelectType = TextSelectType::Words;
|
|
|
|
if (_mouseAction == MouseAction::None) {
|
|
|
|
_mouseAction = MouseAction::Selecting;
|
2017-04-08 13:27:53 +00:00
|
|
|
TextSelection selStatus = { dragState.symbol, dragState.symbol };
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty()) {
|
|
|
|
repaintItem(_selected.cbegin()->first);
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
_selected.emplace(_mouseActionItem, selStatus);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
mouseMoveEvent(e);
|
|
|
|
|
|
|
|
_trippleClickPoint = e->globalPos();
|
2021-09-29 00:00:11 +00:00
|
|
|
_trippleClickTimer.callOnce(QApplication::doubleClickInterval());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-28 12:07:15 +00:00
|
|
|
if (!ClickHandler::getActive()
|
|
|
|
&& !ClickHandler::getPressed()
|
2018-03-09 18:20:56 +00:00
|
|
|
&& (_mouseCursorState == CursorState::None
|
|
|
|
|| _mouseCursorState == CursorState::Date)
|
2019-07-04 09:37:05 +00:00
|
|
|
&& !inSelectionMode()
|
|
|
|
&& !_emptyPainter) {
|
2018-02-28 12:07:15 +00:00
|
|
|
if (const auto item = _mouseActionItem) {
|
|
|
|
mouseActionCancel();
|
|
|
|
_widget->replyToMessage(item);
|
|
|
|
}
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 21:05:57 +00:00
|
|
|
void HistoryInner::contextMenuEvent(QContextMenuEvent *e) {
|
|
|
|
showContextMenu(e);
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
|
|
|
if (e->reason() == QContextMenuEvent::Mouse) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(e->globalPos());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-04-27 21:17:00 +00:00
|
|
|
auto selectedState = getSelectionState();
|
2017-12-06 14:15:41 +00:00
|
|
|
auto canSendMessages = _peer->canWrite();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
// -2 - has full selected items, but not over, -1 - has selection, but no over, 0 - no selection, 1 - over text, 2 - over full selected items
|
2017-06-24 10:11:29 +00:00
|
|
|
auto isUponSelected = 0;
|
2018-01-26 15:40:11 +00:00
|
|
|
auto hasSelected = 0;
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
isUponSelected = -1;
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.cbegin()->second == FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
hasSelected = 2;
|
2017-12-15 18:36:28 +00:00
|
|
|
if (_dragStateItem && _selected.find(_dragStateItem) != _selected.cend()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
isUponSelected = 2;
|
|
|
|
} else {
|
|
|
|
isUponSelected = -2;
|
|
|
|
}
|
2021-10-15 12:42:09 +00:00
|
|
|
} else if (App::mousedItem()
|
|
|
|
&& App::mousedItem() == App::hoveredItem()
|
|
|
|
&& _selected.cbegin()->first == App::mousedItem()->data()) {
|
2017-10-05 15:35:52 +00:00
|
|
|
uint16 selFrom = _selected.cbegin()->second.from, selTo = _selected.cbegin()->second.to;
|
2017-04-08 13:27:53 +00:00
|
|
|
hasSelected = (selTo > selFrom) ? 1 : 0;
|
2021-10-15 12:42:09 +00:00
|
|
|
auto mousePos = mapPointToItem(mapFromGlobal(_mousePosition), App::mousedItem());
|
|
|
|
StateRequest request;
|
|
|
|
request.flags |= Ui::Text::StateRequest::Flag::LookupSymbol;
|
|
|
|
auto dragState = App::mousedItem()->textState(mousePos, request);
|
|
|
|
if (dragState.cursor == CursorState::Text
|
|
|
|
&& dragState.symbol >= selFrom
|
|
|
|
&& dragState.symbol < selTo) {
|
|
|
|
isUponSelected = 1;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showFromTouch && hasSelected && isUponSelected < hasSelected) {
|
|
|
|
isUponSelected = hasSelected;
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:47:02 +00:00
|
|
|
const auto hasWhoReadItem = _dragStateItem
|
|
|
|
&& Api::WhoReadExists(_dragStateItem);
|
|
|
|
_menu = base::make_unique_q<Ui::PopupMenu>(
|
|
|
|
this,
|
|
|
|
hasWhoReadItem ? st::whoReadMenu : st::defaultPopupMenu);
|
2020-06-09 09:36:40 +00:00
|
|
|
const auto session = &this->session();
|
2020-06-23 17:21:58 +00:00
|
|
|
const auto controller = _controller;
|
2020-10-26 09:33:19 +00:00
|
|
|
const auto groupLeaderOrSelf = [](HistoryItem *item) -> HistoryItem* {
|
|
|
|
if (!item) {
|
|
|
|
return nullptr;
|
|
|
|
} else if (const auto group = item->history()->owner().groups().find(item)) {
|
|
|
|
return group->items.front();
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
};
|
2020-10-29 15:21:16 +00:00
|
|
|
const auto addItemActions = [&](
|
|
|
|
HistoryItem *item,
|
|
|
|
HistoryItem *albumPartItem) {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (!item
|
2021-11-07 08:06:00 +00:00
|
|
|
|| !item->isRegular()
|
2018-01-11 13:07:29 +00:00
|
|
|
|| isUponSelected == 2
|
|
|
|
|| isUponSelected == -2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto itemId = item->fullId();
|
|
|
|
if (canSendMessages) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_reply_msg(tr::now), [=] {
|
2018-01-11 13:07:29 +00:00
|
|
|
_widget->replyToMessage(itemId);
|
|
|
|
});
|
|
|
|
}
|
2020-09-03 08:42:25 +00:00
|
|
|
const auto repliesCount = item->repliesCount();
|
2021-11-07 08:06:00 +00:00
|
|
|
const auto withReplies = (repliesCount > 0);
|
2020-10-21 07:58:46 +00:00
|
|
|
if (withReplies && item->history()->peer->isMegagroup()) {
|
2020-09-03 08:42:25 +00:00
|
|
|
const auto rootId = repliesCount ? item->id : item->replyToTop();
|
2020-09-03 11:53:54 +00:00
|
|
|
const auto phrase = (repliesCount > 0)
|
|
|
|
? tr::lng_replies_view(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
repliesCount)
|
|
|
|
: tr::lng_replies_view_thread(tr::now);
|
2020-09-03 08:42:25 +00:00
|
|
|
_menu->addAction(phrase, [=] {
|
|
|
|
controller->showRepliesForMessage(_history, rootId);
|
2020-08-28 10:01:55 +00:00
|
|
|
});
|
|
|
|
}
|
2020-10-29 15:21:16 +00:00
|
|
|
const auto t = base::unixtime::now();
|
|
|
|
const auto editItem = (albumPartItem && albumPartItem->allowsEdit(t))
|
|
|
|
? albumPartItem
|
|
|
|
: item->allowsEdit(t)
|
|
|
|
? item
|
|
|
|
: nullptr;
|
|
|
|
if (editItem) {
|
|
|
|
const auto editItemId = editItem->fullId();
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_edit_msg(tr::now), [=] {
|
2020-10-29 15:21:16 +00:00
|
|
|
_widget->editMessage(editItemId);
|
2018-01-11 13:07:29 +00:00
|
|
|
});
|
|
|
|
}
|
2020-10-26 09:33:19 +00:00
|
|
|
const auto pinItem = (item->canPin() && item->isPinned())
|
|
|
|
? item
|
|
|
|
: groupLeaderOrSelf(item);
|
|
|
|
if (pinItem->canPin()) {
|
|
|
|
const auto isPinned = pinItem->isPinned();
|
|
|
|
const auto pinItemId = pinItem->fullId();
|
2020-10-21 14:41:13 +00:00
|
|
|
const auto controller = _controller;
|
|
|
|
_menu->addAction(isPinned ? tr::lng_context_unpin_msg(tr::now) : tr::lng_context_pin_msg(tr::now), crl::guard(controller, [=] {
|
2020-10-26 09:33:19 +00:00
|
|
|
Window::ToggleMessagePinned(controller, pinItemId, !isPinned);
|
2020-10-21 14:41:13 +00:00
|
|
|
}));
|
2018-01-11 13:07:29 +00:00
|
|
|
}
|
|
|
|
};
|
2019-01-29 16:26:19 +00:00
|
|
|
const auto addPhotoActions = [&](not_null<PhotoData*> photo) {
|
2021-02-04 15:26:49 +00:00
|
|
|
const auto media = photo->activeMediaView();
|
|
|
|
if (!photo->isNull() && media && media->loaded()) {
|
|
|
|
_menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
|
|
|
|
savePhotoToFile(photo);
|
|
|
|
}));
|
|
|
|
_menu->addAction(tr::lng_context_copy_image(tr::now), [=] {
|
|
|
|
copyContextImage(photo);
|
|
|
|
});
|
|
|
|
}
|
2020-10-30 00:07:59 +00:00
|
|
|
if (photo->hasAttachedStickers()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] {
|
2020-10-29 23:43:35 +00:00
|
|
|
session->api().attachedStickers().requestAttachedStickerSets(
|
|
|
|
controller,
|
|
|
|
photo);
|
2019-03-10 12:55:24 +00:00
|
|
|
});
|
|
|
|
}
|
2019-01-29 16:26:19 +00:00
|
|
|
};
|
|
|
|
const auto addDocumentActions = [&](not_null<DocumentData*> document) {
|
|
|
|
if (document->loading()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_cancel_download(tr::now), [=] {
|
2019-01-29 16:26:19 +00:00
|
|
|
cancelContextDownload(document);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto item = _dragStateItem;
|
|
|
|
const auto itemId = item ? item->fullId() : FullMsgId();
|
|
|
|
const auto lnkIsVideo = document->isVideoFile();
|
|
|
|
const auto lnkIsVoice = document->isVoiceMessage();
|
|
|
|
const auto lnkIsAudio = document->isAudioFile();
|
2019-12-24 10:09:04 +00:00
|
|
|
if (document->isGifv()) {
|
|
|
|
const auto notAutoplayedGif = [&] {
|
|
|
|
return item
|
|
|
|
&& document->isGifv()
|
2019-12-30 10:38:02 +00:00
|
|
|
&& !Data::AutoDownload::ShouldAutoPlay(
|
2020-06-09 09:36:40 +00:00
|
|
|
session->settings().autoDownload(),
|
2019-12-24 10:09:04 +00:00
|
|
|
item->history()->peer,
|
|
|
|
document);
|
|
|
|
}();
|
|
|
|
if (notAutoplayedGif) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_open_gif(tr::now), [=] {
|
2019-01-29 16:26:19 +00:00
|
|
|
openContextGif(itemId);
|
|
|
|
});
|
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_save_gif(tr::now), [=] {
|
2019-01-29 16:26:19 +00:00
|
|
|
saveContextGif(itemId);
|
|
|
|
});
|
|
|
|
}
|
2020-04-09 14:02:09 +00:00
|
|
|
if (!document->filepath(true).isEmpty()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] {
|
2019-01-29 16:26:19 +00:00
|
|
|
showContextInFolder(document);
|
|
|
|
});
|
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(lnkIsVideo ? tr::lng_context_save_video(tr::now) : (lnkIsVoice ? tr::lng_context_save_audio(tr::now) : (lnkIsAudio ? tr::lng_context_save_audio_file(tr::now) : tr::lng_context_save_file(tr::now))), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
|
2019-01-29 16:26:19 +00:00
|
|
|
saveDocumentToFile(itemId, document);
|
|
|
|
}));
|
2020-10-30 01:07:04 +00:00
|
|
|
if (document->hasAttachedStickers()) {
|
|
|
|
_menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] {
|
|
|
|
session->api().attachedStickers().requestAttachedStickerSets(
|
|
|
|
controller,
|
|
|
|
document);
|
|
|
|
});
|
|
|
|
}
|
2019-01-29 16:26:19 +00:00
|
|
|
};
|
2021-09-30 11:36:14 +00:00
|
|
|
|
|
|
|
if (hasWhoReadItem) {
|
|
|
|
const auto participantChosen = [=](uint64 id) {
|
|
|
|
controller->showPeerInfo(PeerId(id));
|
|
|
|
};
|
|
|
|
_menu->addAction(Ui::WhoReadContextAction(
|
|
|
|
_menu.get(),
|
|
|
|
Api::WhoRead(_dragStateItem, this, st::defaultWhoRead),
|
|
|
|
participantChosen));
|
|
|
|
_menu->addSeparator();
|
|
|
|
}
|
|
|
|
|
2018-01-25 10:10:52 +00:00
|
|
|
const auto link = ClickHandler::getActive();
|
|
|
|
auto lnkPhoto = dynamic_cast<PhotoClickHandler*>(link.get());
|
|
|
|
auto lnkDocument = dynamic_cast<DocumentClickHandler*>(link.get());
|
2017-04-08 13:27:53 +00:00
|
|
|
if (lnkPhoto || lnkDocument) {
|
2017-12-16 12:13:08 +00:00
|
|
|
const auto item = _dragStateItem;
|
2018-01-11 13:07:29 +00:00
|
|
|
const auto itemId = item ? item->fullId() : FullMsgId();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (isUponSelected > 0) {
|
2018-01-27 13:59:24 +00:00
|
|
|
_menu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
(isUponSelected > 1
|
|
|
|
? tr::lng_context_copy_selected_items(tr::now)
|
|
|
|
: tr::lng_context_copy_selected(tr::now)),
|
2018-01-27 13:59:24 +00:00
|
|
|
[=] { copySelectedText(); });
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2020-10-29 15:21:16 +00:00
|
|
|
addItemActions(item, item);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (lnkPhoto) {
|
2019-01-29 16:26:19 +00:00
|
|
|
addPhotoActions(lnkPhoto->photo());
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2019-01-29 16:26:19 +00:00
|
|
|
addDocumentActions(lnkDocument->document());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
|
2020-12-22 15:11:52 +00:00
|
|
|
_menu->addAction(item->history()->peer->isMegagroup() ? tr::lng_context_copy_message_link(tr::now) : tr::lng_context_copy_post_link(tr::now), [=] {
|
2020-09-22 15:28:49 +00:00
|
|
|
HistoryView::CopyPostLink(session, itemId, HistoryView::Context::History);
|
2018-01-11 13:07:29 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (isUponSelected > 1) {
|
2017-04-27 21:17:00 +00:00
|
|
|
if (selectedState.count > 0 && selectedState.canForwardCount == selectedState.count) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_forward_selected(tr::now), [=] {
|
2018-01-26 15:40:11 +00:00
|
|
|
_widget->forwardSelected();
|
|
|
|
});
|
2017-04-27 21:17:00 +00:00
|
|
|
}
|
|
|
|
if (selectedState.count > 0 && selectedState.canDeleteCount == selectedState.count) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_delete_selected(tr::now), [=] {
|
2018-01-26 15:40:11 +00:00
|
|
|
_widget->confirmDeleteSelected();
|
2018-01-11 13:07:29 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_clear_selection(tr::now), [=] {
|
2018-01-26 15:40:11 +00:00
|
|
|
_widget->clearSelected();
|
|
|
|
});
|
2017-12-16 12:13:08 +00:00
|
|
|
} else if (item) {
|
2018-01-11 13:07:29 +00:00
|
|
|
const auto itemId = item->fullId();
|
2020-09-17 13:26:53 +00:00
|
|
|
const auto blockSender = item->history()->peer->isRepliesChat();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (isUponSelected != -2) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (item->allowsForward()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_forward_msg(tr::now), [=] {
|
2018-01-11 13:07:29 +00:00
|
|
|
forwardItem(itemId);
|
2018-01-25 10:10:52 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-12-16 12:13:08 +00:00
|
|
|
if (item->canDelete()) {
|
2021-02-11 16:10:15 +00:00
|
|
|
_menu->addAction(Ui::DeleteMessageContextAction(
|
|
|
|
_menu->menu(),
|
|
|
|
[=] { deleteItem(itemId); },
|
|
|
|
item->ttlDestroyAt(),
|
|
|
|
[=] { _menu = nullptr; }));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2020-09-17 13:26:53 +00:00
|
|
|
if (!blockSender && item->suggestReport()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_report_msg(tr::now), [=] {
|
2018-05-10 14:15:16 +00:00
|
|
|
reportItem(itemId);
|
|
|
|
});
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2021-11-07 08:06:00 +00:00
|
|
|
if (item->isRegular() && !item->isService()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_select_msg(tr::now), [=] {
|
2020-06-09 09:36:40 +00:00
|
|
|
if (const auto item = session->data().message(itemId)) {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (const auto view = item->mainView()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelection(&_selected, item, SelectAction::Select);
|
|
|
|
repaintItem(item);
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
}
|
|
|
|
}
|
2018-01-25 10:10:52 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2020-09-17 13:26:53 +00:00
|
|
|
if (isUponSelected != -2 && blockSender) {
|
|
|
|
_menu->addAction(tr::lng_profile_block_user(tr::now), [=] {
|
|
|
|
blockSenderItem(itemId);
|
|
|
|
});
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else { // maybe cursor on some text history item?
|
2020-10-29 15:21:16 +00:00
|
|
|
const auto albumPartItem = _dragStateItem;
|
|
|
|
const auto item = [&] {
|
2020-10-26 09:33:19 +00:00
|
|
|
const auto result = App::hoveredItem()
|
2018-01-11 13:07:29 +00:00
|
|
|
? App::hoveredItem()->data().get()
|
|
|
|
: App::hoveredLinkItem()
|
|
|
|
? App::hoveredLinkItem()->data().get()
|
2020-10-26 09:33:19 +00:00
|
|
|
: nullptr;
|
|
|
|
return result ? groupLeaderOrSelf(result) : nullptr;
|
2018-01-11 13:07:29 +00:00
|
|
|
}();
|
|
|
|
const auto itemId = item ? item->fullId() : FullMsgId();
|
2017-12-17 07:25:02 +00:00
|
|
|
const auto canDelete = item
|
|
|
|
&& item->canDelete()
|
2021-11-07 08:06:00 +00:00
|
|
|
&& (item->isRegular() || !item->isService());
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto canForward = item && item->allowsForward();
|
2018-05-10 14:15:16 +00:00
|
|
|
const auto canReport = item && item->suggestReport();
|
2020-09-17 13:26:53 +00:00
|
|
|
const auto canBlockSender = item && item->history()->peer->isRepliesChat();
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto view = item ? item->mainView() : nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
if (isUponSelected > 0) {
|
2018-01-27 13:59:24 +00:00
|
|
|
_menu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
((isUponSelected > 1)
|
|
|
|
? tr::lng_context_copy_selected_items(tr::now)
|
|
|
|
: tr::lng_context_copy_selected(tr::now)),
|
2018-01-27 13:59:24 +00:00
|
|
|
[=] { copySelectedText(); });
|
2020-10-29 15:21:16 +00:00
|
|
|
addItemActions(item, item);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2020-10-29 15:21:16 +00:00
|
|
|
addItemActions(item, albumPartItem);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (item && !isUponSelected) {
|
2018-12-18 11:06:57 +00:00
|
|
|
const auto media = (view ? view->media() : nullptr);
|
|
|
|
const auto mediaHasTextForCopy = media && media->hasTextForCopy();
|
|
|
|
if (const auto document = media ? media->getDocument() : nullptr) {
|
2019-08-02 18:19:14 +00:00
|
|
|
if (!item->isIsolatedEmoji() && document->sticker()) {
|
2021-07-08 16:42:57 +00:00
|
|
|
if (document->sticker()->set) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(document->isStickerSetInstalled() ? tr::lng_context_pack_info(tr::now) : tr::lng_context_pack_add(tr::now), [=] {
|
2019-01-02 08:19:14 +00:00
|
|
|
showStickerPackInfo(document);
|
|
|
|
});
|
2020-06-09 09:36:40 +00:00
|
|
|
_menu->addAction(session->data().stickers().isFaved(document) ? tr::lng_faved_stickers_remove(tr::now) : tr::lng_faved_stickers_add(tr::now), [=] {
|
2020-08-17 12:29:27 +00:00
|
|
|
Api::ToggleFavedSticker(document, itemId);
|
2019-01-02 08:19:14 +00:00
|
|
|
});
|
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
|
2018-12-18 11:06:57 +00:00
|
|
|
saveDocumentToFile(itemId, document);
|
|
|
|
}));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-19 11:20:04 +00:00
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto poll = media->poll()) {
|
2021-01-02 14:36:14 +00:00
|
|
|
HistoryView::AddPollActions(
|
|
|
|
_menu,
|
|
|
|
poll,
|
|
|
|
item,
|
|
|
|
HistoryView::Context::History);
|
2019-07-04 08:36:48 +00:00
|
|
|
} else if (const auto contact = media->sharedContact()) {
|
|
|
|
const auto phone = contact->phoneNumber;
|
|
|
|
_menu->addAction(tr::lng_profile_copy_phone(tr::now), [=] {
|
2019-09-04 07:19:15 +00:00
|
|
|
QGuiApplication::clipboard()->setText(phone);
|
2019-07-04 08:36:48 +00:00
|
|
|
});
|
2018-12-19 11:20:04 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 08:06:00 +00:00
|
|
|
if (item->isSponsored()) {
|
|
|
|
_menu->addAction(tr::lng_sponsored_title({}), [=] {
|
|
|
|
_controller->show(Box(Ui::AboutSponsoredBox));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (!item->isService()
|
|
|
|
&& view
|
|
|
|
&& !link
|
|
|
|
&& (view->hasVisibleText() || mediaHasTextForCopy)) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_copy_text(tr::now), [=] {
|
2018-01-11 13:07:29 +00:00
|
|
|
copyContextText(itemId);
|
2018-01-25 10:10:52 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-25 10:10:52 +00:00
|
|
|
const auto actionText = link
|
|
|
|
? link->copyToClipboardContextItemText()
|
|
|
|
: QString();
|
|
|
|
if (!actionText.isEmpty()) {
|
|
|
|
_menu->addAction(
|
|
|
|
actionText,
|
|
|
|
[text = link->copyToClipboardText()] {
|
2019-09-04 07:19:15 +00:00
|
|
|
QGuiApplication::clipboard()->setText(text);
|
2018-01-11 13:07:29 +00:00
|
|
|
});
|
2018-01-25 10:10:52 +00:00
|
|
|
} else if (item && item->hasDirectLink() && isUponSelected != 2 && isUponSelected != -2) {
|
2020-12-22 15:11:52 +00:00
|
|
|
_menu->addAction(item->history()->peer->isMegagroup() ? tr::lng_context_copy_message_link(tr::now) : tr::lng_context_copy_post_link(tr::now), [=] {
|
2020-09-22 15:28:49 +00:00
|
|
|
HistoryView::CopyPostLink(session, itemId, HistoryView::Context::History);
|
2018-01-25 10:10:52 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (isUponSelected > 1) {
|
2017-04-27 21:17:00 +00:00
|
|
|
if (selectedState.count > 0 && selectedState.count == selectedState.canForwardCount) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_forward_selected(tr::now), [=] {
|
2018-01-26 15:40:11 +00:00
|
|
|
_widget->forwardSelected();
|
|
|
|
});
|
2017-04-27 21:17:00 +00:00
|
|
|
}
|
|
|
|
if (selectedState.count > 0 && selectedState.count == selectedState.canDeleteCount) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_delete_selected(tr::now), [=] {
|
2018-01-26 15:40:11 +00:00
|
|
|
_widget->confirmDeleteSelected();
|
2018-01-11 13:07:29 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_clear_selection(tr::now), [=] {
|
2018-01-26 15:40:11 +00:00
|
|
|
_widget->clearSelected();
|
|
|
|
});
|
2021-11-07 08:06:00 +00:00
|
|
|
} else if (item && ((isUponSelected != -2 && (canForward || canDelete)) || item->isRegular())) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (isUponSelected != -2) {
|
|
|
|
if (canForward) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_forward_msg(tr::now), [=] {
|
2018-01-11 13:07:29 +00:00
|
|
|
forwardAsGroup(itemId);
|
2018-01-25 10:10:52 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (canDelete) {
|
2021-02-11 16:10:15 +00:00
|
|
|
const auto callback = [=] {
|
2018-01-11 13:07:29 +00:00
|
|
|
deleteAsGroup(itemId);
|
2021-02-11 16:10:15 +00:00
|
|
|
};
|
2021-11-07 08:06:00 +00:00
|
|
|
if (item->isUploading()) {
|
2021-02-11 16:10:15 +00:00
|
|
|
_menu->addAction(tr::lng_context_cancel_upload(tr::now), callback);
|
|
|
|
} else {
|
|
|
|
_menu->addAction(Ui::DeleteMessageContextAction(
|
|
|
|
_menu->menu(),
|
|
|
|
callback,
|
|
|
|
item->ttlDestroyAt(),
|
|
|
|
[=] { _menu = nullptr; }));
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2020-09-17 13:26:53 +00:00
|
|
|
if (!canBlockSender && canReport) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_report_msg(tr::now), [=] {
|
2018-05-10 14:15:16 +00:00
|
|
|
reportAsGroup(itemId);
|
|
|
|
});
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2021-11-07 08:06:00 +00:00
|
|
|
if (item->isRegular() && !item->isService()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_select_msg(tr::now), [=] {
|
2020-06-09 09:36:40 +00:00
|
|
|
if (const auto item = session->data().message(itemId)) {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (const auto view = item->mainView()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelectionAsGroup(&_selected, item, SelectAction::Select);
|
2018-01-11 13:07:29 +00:00
|
|
|
repaintItem(view);
|
2017-12-15 18:36:28 +00:00
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
}
|
|
|
|
}
|
2018-01-25 10:10:52 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2020-09-17 13:26:53 +00:00
|
|
|
if (isUponSelected != -2 && canBlockSender) {
|
|
|
|
_menu->addAction(tr::lng_profile_block_user(tr::now), [=] {
|
|
|
|
blockSenderAsGroup(itemId);
|
|
|
|
});
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (App::mousedItem()
|
2021-11-07 08:06:00 +00:00
|
|
|
&& App::mousedItem()->data()->isRegular()
|
|
|
|
&& !App::mousedItem()->data()->isService()) {
|
2018-01-11 13:07:29 +00:00
|
|
|
const auto itemId = App::mousedItem()->data()->fullId();
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_context_select_msg(tr::now), [=] {
|
2020-06-09 09:36:40 +00:00
|
|
|
if (const auto item = session->data().message(itemId)) {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (const auto view = item->mainView()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelectionAsGroup(&_selected, item, SelectAction::Select);
|
|
|
|
repaintItem(item);
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
}
|
|
|
|
}
|
2018-01-25 10:10:52 +00:00
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-13 01:10:25 +00:00
|
|
|
if (_menu->empty()) {
|
2018-01-11 13:07:29 +00:00
|
|
|
_menu = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
_menu->popup(e->globalPos());
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::copySelectedText() {
|
2019-09-16 11:14:06 +00:00
|
|
|
TextUtilities::SetClipboardText(getSelectedText());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::savePhotoToFile(not_null<PhotoData*> photo) {
|
2020-05-25 14:16:04 +00:00
|
|
|
const auto media = photo->activeMediaView();
|
|
|
|
if (photo->isNull() || !media || !media->loaded()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
const auto image = media->image(Data::PhotoSize::Large)->original();
|
2017-04-08 13:27:53 +00:00
|
|
|
auto filter = qsl("JPEG Image (*.jpg);;") + FileDialog::AllFilesFilter();
|
2018-02-03 19:52:35 +00:00
|
|
|
FileDialog::GetWritePath(
|
2018-04-17 15:19:34 +00:00
|
|
|
this,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_save_photo(tr::now),
|
2018-02-03 19:52:35 +00:00
|
|
|
filter,
|
|
|
|
filedialogDefaultName(
|
|
|
|
qsl("photo"),
|
|
|
|
qsl(".jpg")),
|
2018-06-04 15:35:11 +00:00
|
|
|
crl::guard(this, [=](const QString &result) {
|
2018-02-03 19:52:35 +00:00
|
|
|
if (!result.isEmpty()) {
|
2020-05-25 14:16:04 +00:00
|
|
|
image.save(result, "JPG");
|
2018-02-03 19:52:35 +00:00
|
|
|
}
|
|
|
|
}));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::copyContextImage(not_null<PhotoData*> photo) {
|
2020-05-25 14:16:04 +00:00
|
|
|
const auto media = photo->activeMediaView();
|
|
|
|
if (photo->isNull() || !media || !media->loaded()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
const auto image = media->image(Data::PhotoSize::Large)->original();
|
2020-12-11 08:00:52 +00:00
|
|
|
QGuiApplication::clipboard()->setImage(image);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::showStickerPackInfo(not_null<DocumentData*> document) {
|
2019-06-24 15:09:37 +00:00
|
|
|
StickerSetBox::Show(_controller, document);
|
2017-06-24 10:11:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::cancelContextDownload(not_null<DocumentData*> document) {
|
|
|
|
document->cancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::showContextInFolder(not_null<DocumentData*> document) {
|
2020-04-09 14:02:09 +00:00
|
|
|
const auto filepath = document->filepath(true);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!filepath.isEmpty()) {
|
|
|
|
File::ShowInFolder(filepath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
void HistoryInner::saveDocumentToFile(
|
|
|
|
FullMsgId contextId,
|
|
|
|
not_null<DocumentData*> document) {
|
2019-02-27 11:36:19 +00:00
|
|
|
DocumentSaveClickHandler::Save(
|
|
|
|
contextId,
|
|
|
|
document,
|
2019-03-11 14:35:11 +00:00
|
|
|
DocumentSaveClickHandler::Mode::ToNewFile);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::openContextGif(FullMsgId itemId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = session().data().message(itemId)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto document = media->document()) {
|
2021-06-16 21:33:51 +00:00
|
|
|
_controller->openDocument(document, itemId, true);
|
2017-05-18 13:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::saveContextGif(FullMsgId itemId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = session().data().message(itemId)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto document = media->document()) {
|
2020-08-17 12:29:27 +00:00
|
|
|
Api::ToggleSavedGif(document, item->fullId(), true);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::copyContextText(FullMsgId itemId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = session().data().message(itemId)) {
|
|
|
|
if (const auto group = session().data().groups().find(item)) {
|
2019-09-16 11:14:06 +00:00
|
|
|
TextUtilities::SetClipboardText(HistoryGroupText(group));
|
2018-01-27 19:21:41 +00:00
|
|
|
} else {
|
2019-09-16 11:14:06 +00:00
|
|
|
TextUtilities::SetClipboardText(HistoryItemText(item));
|
2018-01-27 19:21:41 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::resizeEvent(QResizeEvent *e) {
|
2018-01-27 13:59:24 +00:00
|
|
|
mouseActionUpdate();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextForMimeData HistoryInner::getSelectedText() const {
|
2017-12-15 16:25:47 +00:00
|
|
|
auto selected = _selected;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Selecting && _dragSelFrom && _dragSelTo) {
|
2017-12-15 16:25:47 +00:00
|
|
|
applyDragSelection(&selected);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
if (selected.empty()) {
|
2019-04-08 15:10:06 +00:00
|
|
|
return TextForMimeData();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
if (selected.cbegin()->second != FullSelection) {
|
|
|
|
const auto [item, selection] = *selected.cbegin();
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto view = item->mainView()) {
|
|
|
|
return view->selectedText(selection);
|
|
|
|
}
|
2019-04-08 15:10:06 +00:00
|
|
|
return TextForMimeData();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-10-07 05:37:42 +00:00
|
|
|
const auto timeFormat = QString(", [%1 %2]\n")
|
|
|
|
.arg(cDateFormat())
|
|
|
|
.arg(cTimeFormat());
|
2018-01-27 17:26:24 +00:00
|
|
|
auto groups = base::flat_set<not_null<const Data::Group*>>();
|
2017-12-16 15:00:20 +00:00
|
|
|
auto fullSize = 0;
|
2019-04-08 15:10:06 +00:00
|
|
|
auto texts = base::flat_map<Data::MessagePosition, TextForMimeData>();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-01-27 17:26:24 +00:00
|
|
|
const auto wrapItem = [&](
|
|
|
|
not_null<HistoryItem*> item,
|
2019-04-08 15:10:06 +00:00
|
|
|
TextForMimeData &&unwrapped) {
|
2018-02-03 19:52:35 +00:00
|
|
|
auto time = ItemDateTime(item).toString(timeFormat);
|
2019-04-08 15:10:06 +00:00
|
|
|
auto part = TextForMimeData();
|
2017-12-16 15:00:20 +00:00
|
|
|
auto size = item->author()->name.size()
|
|
|
|
+ time.size()
|
2019-04-08 15:10:06 +00:00
|
|
|
+ unwrapped.expanded.size();
|
|
|
|
part.reserve(size);
|
|
|
|
part.append(item->author()->name).append(time);
|
|
|
|
part.append(std::move(unwrapped));
|
2018-01-27 17:26:24 +00:00
|
|
|
texts.emplace(item->position(), part);
|
|
|
|
fullSize += size;
|
|
|
|
};
|
|
|
|
const auto addItem = [&](not_null<HistoryItem*> item) {
|
|
|
|
wrapItem(item, HistoryItemText(item));
|
|
|
|
};
|
|
|
|
const auto addGroup = [&](not_null<const Data::Group*> group) {
|
|
|
|
Expects(!group->items.empty());
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-01-27 17:26:24 +00:00
|
|
|
wrapItem(group->items.back(), HistoryGroupText(group));
|
2017-12-16 15:00:20 +00:00
|
|
|
};
|
|
|
|
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &[item, selection] : selected) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto group = session().data().groups().find(item)) {
|
2018-01-27 17:26:24 +00:00
|
|
|
if (groups.contains(group)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isSelectedGroup(&selected, group)) {
|
|
|
|
groups.emplace(group);
|
|
|
|
addGroup(group);
|
|
|
|
} else {
|
|
|
|
addItem(item);
|
|
|
|
}
|
2017-12-16 15:00:20 +00:00
|
|
|
} else {
|
2018-01-27 17:26:24 +00:00
|
|
|
addItem(item);
|
2017-12-16 15:00:20 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
auto result = TextForMimeData();
|
|
|
|
const auto sep = qstr("\n\n");
|
|
|
|
result.reserve(fullSize + (texts.size() - 1) * sep.size());
|
2017-12-16 15:00:20 +00:00
|
|
|
for (auto i = texts.begin(), e = texts.end(); i != e;) {
|
2019-04-08 15:10:06 +00:00
|
|
|
result.append(std::move(i->second));
|
2017-12-16 15:00:20 +00:00
|
|
|
if (++i != e) {
|
2019-04-08 15:10:06 +00:00
|
|
|
result.append(sep);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
2019-05-01 12:09:16 +00:00
|
|
|
_widget->escape();
|
2017-10-05 15:35:52 +00:00
|
|
|
} else if (e == QKeySequence::Copy && !_selected.empty()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
copySelectedText();
|
|
|
|
#ifdef Q_OS_MAC
|
2018-01-25 10:10:52 +00:00
|
|
|
} else if (e->key() == Qt::Key_E
|
|
|
|
&& e->modifiers().testFlag(Qt::ControlModifier)) {
|
2019-09-16 11:14:06 +00:00
|
|
|
TextUtilities::SetClipboardText(getSelectedText(), QClipboard::FindBuffer);
|
2017-04-08 13:27:53 +00:00
|
|
|
#endif // Q_OS_MAC
|
|
|
|
} else if (e == QKeySequence::Delete) {
|
2017-04-27 21:17:00 +00:00
|
|
|
auto selectedState = getSelectionState();
|
2018-01-25 10:10:52 +00:00
|
|
|
if (selectedState.count > 0
|
|
|
|
&& selectedState.canDeleteCount == selectedState.count) {
|
2018-01-26 15:40:11 +00:00
|
|
|
_widget->confirmDeleteSelected();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
e->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 11:23:51 +00:00
|
|
|
void HistoryInner::checkHistoryActivation() {
|
|
|
|
if (!_widget->doWeReadServerHistory()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
adjustCurrent(_visibleAreaBottom);
|
|
|
|
if (_history->loadedAtBottom() && _visibleAreaBottom >= height()) {
|
|
|
|
// Clear possible scheduled messages notifications.
|
2020-06-19 12:59:31 +00:00
|
|
|
Core::App().notifications().clearFromHistory(_history);
|
2020-02-11 11:23:51 +00:00
|
|
|
}
|
|
|
|
if (_curHistory != _history || _history->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto block = _history->blocks[_curBlock].get();
|
|
|
|
auto view = block->messages[_curItem].get();
|
|
|
|
while (_curBlock > 0 || _curItem > 0) {
|
|
|
|
const auto bottom = itemTop(view) + view->height();
|
|
|
|
if (_visibleAreaBottom >= bottom) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (_curItem > 0) {
|
|
|
|
view = block->messages[--_curItem].get();
|
|
|
|
} else {
|
|
|
|
while (_curBlock > 0) {
|
|
|
|
block = _history->blocks[--_curBlock].get();
|
|
|
|
_curItem = block->messages.size();
|
|
|
|
if (_curItem > 0) {
|
|
|
|
view = block->messages[--_curItem].get();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 15:35:26 +00:00
|
|
|
session().data().histories().readInboxTill(view->data());
|
2020-02-11 11:23:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 12:39:59 +00:00
|
|
|
void HistoryInner::recountHistoryGeometry() {
|
2018-01-21 19:21:08 +00:00
|
|
|
_contentWidth = _scroll->width();
|
|
|
|
|
|
|
|
const auto visibleHeight = _scroll->height();
|
2017-04-08 13:27:53 +00:00
|
|
|
int oldHistoryPaddingTop = qMax(visibleHeight - historyHeight() - st::historyPaddingBottom, 0);
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
|
|
|
accumulate_max(oldHistoryPaddingTop, st::msgMargin.top() + st::msgMargin.bottom() + st::msgPadding.top() + st::msgPadding.bottom() + st::msgNameFont->height + st::botDescSkip + _botAbout->height);
|
|
|
|
}
|
|
|
|
|
2018-01-21 19:21:08 +00:00
|
|
|
_history->resizeToWidth(_contentWidth);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_migrated) {
|
2018-01-21 19:21:08 +00:00
|
|
|
_migrated->resizeToWidth(_contentWidth);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 11:57:45 +00:00
|
|
|
// With migrated history we perhaps do not need to display
|
|
|
|
// the first _history message date (just skip it by height).
|
2017-04-08 13:27:53 +00:00
|
|
|
_historySkipHeight = 0;
|
2019-01-15 11:57:45 +00:00
|
|
|
if (_migrated
|
|
|
|
&& _migrated->loadedAtBottom()
|
|
|
|
&& _history->loadedAtTop()) {
|
|
|
|
if (const auto first = _history->findFirstNonEmpty()) {
|
|
|
|
if (const auto last = _migrated->findLastNonEmpty()) {
|
|
|
|
if (first->dateTime().date() == last->dateTime().date()) {
|
|
|
|
const auto dateHeight = first->displayedDateHeight();
|
|
|
|
if (_migrated->height() > dateHeight) {
|
|
|
|
_historySkipHeight += dateHeight;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateBotInfo(false);
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
|
|
|
int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right();
|
|
|
|
if (tw > st::msgMaxWidth) tw = st::msgMaxWidth;
|
|
|
|
tw -= st::msgPadding.left() + st::msgPadding.right();
|
2020-10-01 08:05:47 +00:00
|
|
|
const auto descriptionWidth = _history->peer->isRepliesChat()
|
|
|
|
? 0
|
|
|
|
: st::msgNameFont->width(tr::lng_bot_description(tr::now));
|
|
|
|
int32 mw = qMax(_botAbout->info->text.maxWidth(), descriptionWidth);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (tw > mw) tw = mw;
|
|
|
|
|
|
|
|
_botAbout->width = tw;
|
|
|
|
_botAbout->height = _botAbout->info->text.countHeight(_botAbout->width);
|
|
|
|
|
2020-10-01 08:05:47 +00:00
|
|
|
const auto descriptionHeight = _history->peer->isRepliesChat()
|
|
|
|
? 0
|
|
|
|
: (st::msgNameFont->height + st::botDescSkip);
|
|
|
|
int32 descH = st::msgMargin.top() + st::msgPadding.top() + descriptionHeight + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
|
2017-04-08 13:27:53 +00:00
|
|
|
int32 descMaxWidth = _scroll->width();
|
2021-05-27 00:44:12 +00:00
|
|
|
if (_isChatWide) {
|
2017-04-08 13:27:53 +00:00
|
|
|
descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
|
|
|
|
}
|
|
|
|
int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
|
|
|
|
int32 descAtY = qMin(_historyPaddingTop - descH, qMax(0, (_scroll->height() - descH) / 2)) + st::msgMargin.top();
|
|
|
|
|
|
|
|
_botAbout->rect = QRect(descAtX, descAtY, _botAbout->width + st::msgPadding.left() + st::msgPadding.right(), descH - st::msgMargin.top() - st::msgMargin.bottom());
|
|
|
|
} else if (_botAbout) {
|
|
|
|
_botAbout->width = _botAbout->height = 0;
|
|
|
|
_botAbout->rect = QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
int newHistoryPaddingTop = qMax(visibleHeight - historyHeight() - st::historyPaddingBottom, 0);
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
|
|
|
accumulate_max(newHistoryPaddingTop, st::msgMargin.top() + st::msgMargin.bottom() + st::msgPadding.top() + st::msgPadding.bottom() + st::msgNameFont->height + st::botDescSkip + _botAbout->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto historyPaddingTopDelta = (newHistoryPaddingTop - oldHistoryPaddingTop);
|
|
|
|
if (historyPaddingTopDelta != 0) {
|
|
|
|
if (_history->scrollTopItem) {
|
|
|
|
_history->scrollTopOffset += historyPaddingTopDelta;
|
|
|
|
} else if (_migrated && _migrated->scrollTopItem) {
|
|
|
|
_migrated->scrollTopOffset += historyPaddingTopDelta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::updateBotInfo(bool recount) {
|
|
|
|
int newh = 0;
|
|
|
|
if (_botAbout && !_botAbout->info->description.isEmpty()) {
|
|
|
|
if (_botAbout->info->text.isEmpty()) {
|
2017-12-28 13:06:06 +00:00
|
|
|
_botAbout->info->text.setText(
|
|
|
|
st::messageTextStyle,
|
|
|
|
_botAbout->info->description,
|
|
|
|
Ui::ItemTextBotNoMonoOptions());
|
2017-04-08 13:27:53 +00:00
|
|
|
if (recount) {
|
|
|
|
int32 tw = _scroll->width() - st::msgMargin.left() - st::msgMargin.right();
|
|
|
|
if (tw > st::msgMaxWidth) tw = st::msgMaxWidth;
|
|
|
|
tw -= st::msgPadding.left() + st::msgPadding.right();
|
2020-10-01 08:05:47 +00:00
|
|
|
const auto descriptionWidth = _history->peer->isRepliesChat()
|
|
|
|
? 0
|
|
|
|
: st::msgNameFont->width(tr::lng_bot_description(tr::now));
|
|
|
|
int32 mw = qMax(_botAbout->info->text.maxWidth(), descriptionWidth);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (tw > mw) tw = mw;
|
|
|
|
|
|
|
|
_botAbout->width = tw;
|
|
|
|
newh = _botAbout->info->text.countHeight(_botAbout->width);
|
|
|
|
}
|
|
|
|
} else if (recount) {
|
|
|
|
newh = _botAbout->height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (recount && _botAbout) {
|
|
|
|
if (_botAbout->height != newh) {
|
|
|
|
_botAbout->height = newh;
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
if (_botAbout->height > 0) {
|
2020-10-01 08:05:47 +00:00
|
|
|
const auto descriptionHeight = _history->peer->isRepliesChat()
|
|
|
|
? 0
|
|
|
|
: (st::msgNameFont->height + st::botDescSkip);
|
|
|
|
int32 descH = st::msgMargin.top() + st::msgPadding.top() + descriptionHeight + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
|
2017-04-08 13:27:53 +00:00
|
|
|
int32 descAtX = (_scroll->width() - _botAbout->width) / 2 - st::msgPadding.left();
|
|
|
|
int32 descAtY = qMin(_historyPaddingTop - descH, (_scroll->height() - descH) / 2) + st::msgMargin.top();
|
|
|
|
|
|
|
|
_botAbout->rect = QRect(descAtX, descAtY, _botAbout->width + st::msgPadding.left() + st::msgPadding.right(), descH - st::msgMargin.top() - st::msgMargin.bottom());
|
|
|
|
} else {
|
|
|
|
_botAbout->width = 0;
|
|
|
|
_botAbout->rect = QRect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::wasSelectedText() const {
|
|
|
|
return _wasSelectedText;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::visibleAreaUpdated(int top, int bottom) {
|
2017-05-16 13:41:47 +00:00
|
|
|
auto scrolledUp = (top < _visibleAreaTop);
|
2017-04-08 13:27:53 +00:00
|
|
|
_visibleAreaTop = top;
|
|
|
|
_visibleAreaBottom = bottom;
|
2019-05-14 09:50:44 +00:00
|
|
|
const auto visibleAreaHeight = bottom - top;
|
2017-04-08 13:27:53 +00:00
|
|
|
|
|
|
|
// if history has pending resize events we should not update scrollTopItem
|
|
|
|
if (hasPendingResizedItems()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bottom >= _historyPaddingTop + historyHeight() + st::historyPaddingBottom) {
|
|
|
|
_history->forgetScrollState();
|
|
|
|
if (_migrated) {
|
|
|
|
_migrated->forgetScrollState();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int htop = historyTop(), mtop = migratedTop();
|
|
|
|
if ((htop >= 0 && top >= htop) || mtop < 0) {
|
|
|
|
_history->countScrollState(top - htop);
|
|
|
|
if (_migrated) {
|
|
|
|
_migrated->forgetScrollState();
|
|
|
|
}
|
|
|
|
} else if (mtop >= 0 && top >= mtop) {
|
|
|
|
_history->forgetScrollState();
|
|
|
|
_migrated->countScrollState(top - mtop);
|
|
|
|
} else {
|
|
|
|
_history->countScrollState(top - htop);
|
|
|
|
if (_migrated) {
|
|
|
|
_migrated->forgetScrollState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-16 13:41:47 +00:00
|
|
|
if (scrolledUp) {
|
|
|
|
_scrollDateCheck.call();
|
|
|
|
} else {
|
2018-01-27 13:59:24 +00:00
|
|
|
scrollDateHideByTimer();
|
2017-05-16 13:41:47 +00:00
|
|
|
}
|
2019-05-14 09:50:44 +00:00
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
// Unload userpics.
|
|
|
|
if (_userpics.size() > kClearUserpicsAfter) {
|
|
|
|
_userpicsCache = std::move(_userpics);
|
|
|
|
}
|
|
|
|
|
2019-05-14 09:50:44 +00:00
|
|
|
// Unload lottie animations.
|
|
|
|
const auto pages = kUnloadHeavyPartsPages;
|
|
|
|
const auto from = _visibleAreaTop - pages * visibleAreaHeight;
|
|
|
|
const auto till = _visibleAreaBottom + pages * visibleAreaHeight;
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().unloadHeavyViewParts(ElementDelegate(), from, till);
|
2020-02-11 11:23:51 +00:00
|
|
|
checkHistoryActivation();
|
2021-09-15 14:49:06 +00:00
|
|
|
|
|
|
|
_emojiInteractions->visibleAreaUpdated(
|
|
|
|
_visibleAreaTop - _historyPaddingTop,
|
|
|
|
_visibleAreaBottom - _historyPaddingTop);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::displayScrollDate() const {
|
|
|
|
return (_visibleAreaTop <= height() - 2 * (_visibleAreaBottom - _visibleAreaTop));
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
void HistoryInner::scrollDateCheck() {
|
2017-04-08 13:27:53 +00:00
|
|
|
auto newScrollDateItem = _history->scrollTopItem ? _history->scrollTopItem : (_migrated ? _migrated->scrollTopItem : nullptr);
|
|
|
|
auto newScrollDateItemTop = _history->scrollTopItem ? _history->scrollTopOffset : (_migrated ? _migrated->scrollTopOffset : 0);
|
|
|
|
//if (newScrollDateItem && !displayScrollDate()) {
|
2018-01-10 13:13:33 +00:00
|
|
|
// if (!_history->isEmpty() && newScrollDateItem->date.date() == _history->blocks.back()->messages.back()->data()->date.date()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// newScrollDateItem = nullptr;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
if (!newScrollDateItem) {
|
|
|
|
_scrollDateLastItem = nullptr;
|
|
|
|
_scrollDateLastItemTop = 0;
|
|
|
|
scrollDateHide();
|
|
|
|
} else if (newScrollDateItem != _scrollDateLastItem || newScrollDateItemTop != _scrollDateLastItemTop) {
|
|
|
|
// Show scroll date only if it is not the initial onScroll() event (with empty _scrollDateLastItem).
|
|
|
|
if (_scrollDateLastItem && !_scrollDateShown) {
|
|
|
|
toggleScrollDateShown();
|
|
|
|
}
|
|
|
|
_scrollDateLastItem = newScrollDateItem;
|
|
|
|
_scrollDateLastItemTop = newScrollDateItemTop;
|
2018-01-27 13:59:24 +00:00
|
|
|
_scrollDateHideTimer.callOnce(kScrollDateHideTimeout);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
void HistoryInner::scrollDateHideByTimer() {
|
|
|
|
_scrollDateHideTimer.cancel();
|
2017-05-16 13:41:47 +00:00
|
|
|
if (!_scrollDateLink || ClickHandler::getPressed() != _scrollDateLink) {
|
2017-04-08 13:27:53 +00:00
|
|
|
scrollDateHide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::scrollDateHide() {
|
|
|
|
if (_scrollDateShown) {
|
|
|
|
toggleScrollDateShown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::keepScrollDateForNow() {
|
|
|
|
if (!_scrollDateShown && _scrollDateLastItem && _scrollDateOpacity.animating()) {
|
|
|
|
toggleScrollDateShown();
|
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
_scrollDateHideTimer.callOnce(kScrollDateHideTimeout);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::toggleScrollDateShown() {
|
|
|
|
_scrollDateShown = !_scrollDateShown;
|
|
|
|
auto from = _scrollDateShown ? 0. : 1.;
|
|
|
|
auto to = _scrollDateShown ? 1. : 0.;
|
|
|
|
_scrollDateOpacity.start([this] { repaintScrollDateCallback(); }, from, to, st::historyDateFadeDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::repaintScrollDateCallback() {
|
|
|
|
int updateTop = _visibleAreaTop;
|
|
|
|
int updateHeight = st::msgServiceMargin.top() + st::msgServicePadding.top() + st::msgServiceFont->height + st::msgServicePadding.bottom();
|
|
|
|
update(0, updateTop, width(), updateHeight);
|
|
|
|
}
|
|
|
|
|
2021-07-19 10:02:36 +00:00
|
|
|
void HistoryInner::setItemsRevealHeight(int revealHeight) {
|
|
|
|
_revealHeight = revealHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::changeItemsRevealHeight(int revealHeight) {
|
|
|
|
if (_revealHeight == revealHeight) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-20 09:13:32 +00:00
|
|
|
_revealHeight = revealHeight;
|
|
|
|
updateSize();
|
2021-07-19 10:02:36 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::updateSize() {
|
2021-07-20 09:13:32 +00:00
|
|
|
const auto visibleHeight = _scroll->height();
|
|
|
|
const auto itemsHeight = historyHeight() - _revealHeight;
|
|
|
|
int newHistoryPaddingTop = qMax(visibleHeight - itemsHeight - st::historyPaddingBottom, 0);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty()) {
|
|
|
|
accumulate_max(newHistoryPaddingTop, st::msgMargin.top() + st::msgMargin.bottom() + st::msgPadding.top() + st::msgPadding.bottom() + st::msgNameFont->height + st::botDescSkip + _botAbout->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_botAbout && _botAbout->height > 0) {
|
2020-10-01 08:05:47 +00:00
|
|
|
const auto descriptionHeight = _history->peer->isRepliesChat()
|
|
|
|
? 0
|
|
|
|
: (st::msgNameFont->height + st::botDescSkip);
|
|
|
|
int32 descH = st::msgMargin.top() + st::msgPadding.top() + descriptionHeight + _botAbout->height + st::msgPadding.bottom() + st::msgMargin.bottom();
|
2017-04-08 13:27:53 +00:00
|
|
|
int32 descMaxWidth = _scroll->width();
|
2021-05-27 00:44:12 +00:00
|
|
|
if (_isChatWide) {
|
2017-04-08 13:27:53 +00:00
|
|
|
descMaxWidth = qMin(descMaxWidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
|
|
|
|
}
|
|
|
|
int32 descAtX = (descMaxWidth - _botAbout->width) / 2 - st::msgPadding.left();
|
|
|
|
int32 descAtY = qMin(newHistoryPaddingTop - descH, qMax(0, (_scroll->height() - descH) / 2)) + st::msgMargin.top();
|
|
|
|
|
|
|
|
_botAbout->rect = QRect(descAtX, descAtY, _botAbout->width + st::msgPadding.left() + st::msgPadding.right(), descH - st::msgMargin.top() - st::msgMargin.bottom());
|
|
|
|
}
|
|
|
|
|
2021-09-15 14:49:06 +00:00
|
|
|
if (_historyPaddingTop != newHistoryPaddingTop) {
|
|
|
|
_historyPaddingTop = newHistoryPaddingTop;
|
|
|
|
_emojiInteractions->visibleAreaUpdated(
|
|
|
|
_visibleAreaTop - _historyPaddingTop,
|
|
|
|
_visibleAreaBottom - _historyPaddingTop);
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2021-07-20 09:13:32 +00:00
|
|
|
int newHeight = _historyPaddingTop + itemsHeight + st::historyPaddingBottom;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (width() != _scroll->width() || height() != newHeight) {
|
|
|
|
resize(_scroll->width(), newHeight);
|
|
|
|
|
2021-07-19 10:02:36 +00:00
|
|
|
if (!_revealHeight) {
|
|
|
|
mouseActionUpdate(QCursor::pos());
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:00:21 +00:00
|
|
|
void HistoryInner::enterEventHook(QEnterEvent *e) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(QCursor::pos());
|
2017-04-08 13:27:53 +00:00
|
|
|
return TWidget::enterEventHook(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::leaveEventHook(QEvent *e) {
|
|
|
|
if (auto item = App::hoveredItem()) {
|
|
|
|
repaintItem(item);
|
|
|
|
App::hoveredItem(nullptr);
|
|
|
|
}
|
|
|
|
ClickHandler::clearActive();
|
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
if (!ClickHandler::getPressed() && _cursor != style::cur_default) {
|
|
|
|
_cursor = style::cur_default;
|
|
|
|
setCursor(_cursor);
|
|
|
|
}
|
|
|
|
return TWidget::leaveEventHook(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryInner::~HistoryInner() {
|
2019-08-01 12:55:14 +00:00
|
|
|
for (const auto &item : _animatedStickersPlayed) {
|
|
|
|
if (const auto view = item->mainView()) {
|
|
|
|
if (const auto media = view->media()) {
|
2020-06-16 16:53:44 +00:00
|
|
|
media->stickerClearLoopPlayed();
|
2019-08-01 12:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-14 09:50:44 +00:00
|
|
|
if (Instance == this) {
|
|
|
|
Instance = nullptr;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
delete _menu;
|
2017-06-21 21:38:31 +00:00
|
|
|
_mouseAction = MouseAction::None;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::focusNextPrevChild(bool next) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.empty()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return TWidget::focusNextPrevChild(next);
|
|
|
|
} else {
|
2018-01-26 15:40:11 +00:00
|
|
|
clearSelected();
|
2017-04-08 13:27:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::adjustCurrent(int32 y) const {
|
|
|
|
int32 htop = historyTop(), hdrawtop = historyDrawTop(), mtop = migratedTop();
|
2019-04-04 10:02:22 +00:00
|
|
|
_curHistory = nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (mtop >= 0) {
|
|
|
|
adjustCurrent(y - mtop, _migrated);
|
|
|
|
}
|
|
|
|
if (htop >= 0 && hdrawtop >= 0 && (mtop < 0 || y >= hdrawtop)) {
|
|
|
|
adjustCurrent(y - htop, _history);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::adjustCurrent(int32 y, History *history) const {
|
2020-02-11 11:23:51 +00:00
|
|
|
Expects(!history->isEmpty());
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
_curHistory = history;
|
|
|
|
if (_curBlock >= history->blocks.size()) {
|
|
|
|
_curBlock = history->blocks.size() - 1;
|
|
|
|
_curItem = 0;
|
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
while (history->blocks[_curBlock]->y() > y && _curBlock > 0) {
|
2017-04-08 13:27:53 +00:00
|
|
|
--_curBlock;
|
|
|
|
_curItem = 0;
|
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
while (history->blocks[_curBlock]->y() + history->blocks[_curBlock]->height() <= y && _curBlock + 1 < history->blocks.size()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
++_curBlock;
|
|
|
|
_curItem = 0;
|
|
|
|
}
|
2018-01-10 13:13:33 +00:00
|
|
|
auto block = history->blocks[_curBlock].get();
|
|
|
|
if (_curItem >= block->messages.size()) {
|
|
|
|
_curItem = block->messages.size() - 1;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2017-05-12 13:53:08 +00:00
|
|
|
auto by = block->y();
|
2018-01-10 13:13:33 +00:00
|
|
|
while (block->messages[_curItem]->y() + by > y && _curItem > 0) {
|
2017-04-08 13:27:53 +00:00
|
|
|
--_curItem;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
while (block->messages[_curItem]->y() + block->messages[_curItem]->height() + by <= y && _curItem + 1 < block->messages.size()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
++_curItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
auto HistoryInner::prevItem(Element *view) -> Element* {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (!view) {
|
2018-01-10 13:13:33 +00:00
|
|
|
return nullptr;
|
2020-09-16 11:28:35 +00:00
|
|
|
} else if (const auto result = view->previousDisplayedInBlocks()) {
|
2018-01-11 13:07:29 +00:00
|
|
|
return result;
|
|
|
|
} else if (view->data()->history() == _history
|
|
|
|
&& _migrated
|
|
|
|
&& _history->loadedAtTop()
|
|
|
|
&& !_migrated->isEmpty()
|
|
|
|
&& _migrated->loadedAtBottom()) {
|
2020-09-16 11:28:35 +00:00
|
|
|
return _migrated->findLastDisplayed();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
auto HistoryInner::nextItem(Element *view) -> Element* {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (!view) {
|
|
|
|
return nullptr;
|
2020-09-16 11:28:35 +00:00
|
|
|
} else if (const auto result = view->nextDisplayedInBlocks()) {
|
2018-01-11 13:07:29 +00:00
|
|
|
return result;
|
|
|
|
} else if (view->data()->history() == _migrated
|
|
|
|
&& _migrated->loadedAtBottom()
|
|
|
|
&& _history->loadedAtTop()
|
|
|
|
&& !_history->isEmpty()) {
|
2020-09-16 11:28:35 +00:00
|
|
|
return _history->findFirstDisplayed();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::canCopySelected() const {
|
2017-10-05 15:35:52 +00:00
|
|
|
return !_selected.empty();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::canDeleteSelected() const {
|
2017-04-27 21:17:00 +00:00
|
|
|
auto selectedState = getSelectionState();
|
|
|
|
return (selectedState.count > 0) && (selectedState.count == selectedState.canDeleteCount);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 21:21:27 +00:00
|
|
|
bool HistoryInner::inSelectionMode() const {
|
|
|
|
if (!_selected.empty()
|
|
|
|
&& (_selected.begin()->second == FullSelection)) {
|
|
|
|
return true;
|
|
|
|
} else if (_mouseAction == MouseAction::Selecting
|
|
|
|
&& _dragSelFrom
|
|
|
|
&& _dragSelTo) {
|
|
|
|
return true;
|
2021-02-15 17:37:22 +00:00
|
|
|
} else if (_chooseForReportReason.has_value()) {
|
|
|
|
return true;
|
2018-03-08 21:21:27 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-14 09:50:44 +00:00
|
|
|
bool HistoryInner::elementIntersectsRange(
|
|
|
|
not_null<const Element*> view,
|
|
|
|
int from,
|
|
|
|
int till) const {
|
|
|
|
const auto top = itemTop(view);
|
|
|
|
if (top < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto bottom = top + view->height();
|
|
|
|
return (top < till && bottom > from);
|
|
|
|
}
|
|
|
|
|
2019-08-01 12:55:14 +00:00
|
|
|
void HistoryInner::elementStartStickerLoop(
|
|
|
|
not_null<const Element*> view) {
|
|
|
|
_animatedStickersPlayed.emplace(view->data());
|
2019-08-01 11:42:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-30 08:55:11 +00:00
|
|
|
crl::time HistoryInner::elementHighlightTime(
|
|
|
|
not_null<const HistoryItem*> item) {
|
2021-09-28 23:32:23 +00:00
|
|
|
const auto fullAnimMs = _widget->highlightStartTime(item);
|
2020-06-10 18:08:17 +00:00
|
|
|
if (fullAnimMs > 0) {
|
|
|
|
const auto now = crl::now();
|
|
|
|
if (fullAnimMs < now) {
|
|
|
|
return now - fullAnimMs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-14 11:55:18 +00:00
|
|
|
void HistoryInner::elementShowPollResults(
|
2020-05-04 10:42:06 +00:00
|
|
|
not_null<PollData*> poll,
|
|
|
|
FullMsgId context) {
|
|
|
|
_controller->showPollResults(poll, context);
|
2020-01-14 11:55:18 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 20:24:35 +00:00
|
|
|
void HistoryInner::elementOpenPhoto(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
FullMsgId context) {
|
|
|
|
_controller->openPhoto(photo, context);
|
|
|
|
}
|
|
|
|
|
2021-06-16 21:31:15 +00:00
|
|
|
void HistoryInner::elementOpenDocument(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
FullMsgId context,
|
|
|
|
bool showInMediaView) {
|
|
|
|
_controller->openDocument(document, context, showInMediaView);
|
|
|
|
}
|
|
|
|
|
2021-06-18 06:20:49 +00:00
|
|
|
void HistoryInner::elementCancelUpload(const FullMsgId &context) {
|
|
|
|
if (const auto item = session().data().message(context)) {
|
2021-06-18 06:39:10 +00:00
|
|
|
_controller->cancelUploadLayer(item);
|
2021-06-18 06:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 10:11:05 +00:00
|
|
|
void HistoryInner::elementShowTooltip(
|
|
|
|
const TextWithEntities &text,
|
|
|
|
Fn<void()> hiddenCallback) {
|
2020-04-30 11:20:50 +00:00
|
|
|
_widget->showInfoTooltip(text, std::move(hiddenCallback));
|
2020-04-29 12:36:51 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 17:21:58 +00:00
|
|
|
bool HistoryInner::elementIsGifPaused() {
|
|
|
|
return _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any);
|
|
|
|
}
|
|
|
|
|
2020-11-10 16:38:21 +00:00
|
|
|
void HistoryInner::elementSendBotCommand(
|
|
|
|
const QString &command,
|
|
|
|
const FullMsgId &context) {
|
2021-07-26 23:18:11 +00:00
|
|
|
_widget->sendBotCommand({ _history->peer, command, context });
|
2020-11-10 16:38:21 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 18:51:20 +00:00
|
|
|
void HistoryInner::elementHandleViaClick(not_null<UserData*> bot) {
|
|
|
|
App::insertBotCommand('@' + bot->username);
|
|
|
|
}
|
|
|
|
|
2021-05-27 00:44:12 +00:00
|
|
|
bool HistoryInner::elementIsChatWide() {
|
|
|
|
return _isChatWide;
|
|
|
|
}
|
|
|
|
|
2021-07-02 15:29:13 +00:00
|
|
|
not_null<Ui::PathShiftGradient*> HistoryInner::elementPathShiftGradient() {
|
|
|
|
return _pathGradient.get();
|
|
|
|
}
|
|
|
|
|
2021-07-26 14:37:19 +00:00
|
|
|
void HistoryInner::elementReplyTo(const FullMsgId &to) {
|
|
|
|
return _widget->replyToMessage(to);
|
|
|
|
}
|
|
|
|
|
2021-09-14 16:55:35 +00:00
|
|
|
void HistoryInner::elementStartInteraction(not_null<const Element*> view) {
|
2021-09-16 11:20:25 +00:00
|
|
|
_controller->emojiInteractions().startOutgoing(view);
|
2021-09-14 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
auto HistoryInner::getSelectionState() const
|
|
|
|
-> HistoryView::TopBarWidget::SelectedState {
|
|
|
|
auto result = HistoryView::TopBarWidget::SelectedState {};
|
2017-10-05 15:35:52 +00:00
|
|
|
for (auto &selected : _selected) {
|
|
|
|
if (selected.second == FullSelection) {
|
2017-04-27 21:17:00 +00:00
|
|
|
++result.count;
|
2017-10-05 15:35:52 +00:00
|
|
|
if (selected.first->canDelete()) {
|
2017-04-27 21:17:00 +00:00
|
|
|
++result.canDeleteCount;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
if (selected.first->allowsForward()) {
|
2017-04-27 21:17:00 +00:00
|
|
|
++result.canForwardCount;
|
|
|
|
}
|
2018-03-08 13:03:59 +00:00
|
|
|
} else if (selected.second.from != selected.second.to) {
|
2017-04-27 21:17:00 +00:00
|
|
|
result.textSelected = true;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-27 21:17:00 +00:00
|
|
|
return result;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
void HistoryInner::clearSelected(bool onlyTextSelection) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty() && (!onlyTextSelection || _selected.cbegin()->second != FullSelection)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
_widget->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
MessageIdsList HistoryInner::getSelectedItems() const {
|
|
|
|
using namespace ranges;
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
if (_selected.empty() || _selected.cbegin()->second != FullSelection) {
|
2017-12-06 10:13:38 +00:00
|
|
|
return {};
|
2017-06-16 20:33:35 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2019-10-02 09:54:29 +00:00
|
|
|
auto result = ranges::make_subrange(
|
2017-12-06 10:13:38 +00:00
|
|
|
_selected.begin(),
|
|
|
|
_selected.end()
|
2021-03-13 18:07:29 +00:00
|
|
|
) | views::filter([](const auto &selected) {
|
2017-12-06 10:13:38 +00:00
|
|
|
const auto item = selected.first;
|
2021-11-07 08:06:00 +00:00
|
|
|
return item && !item->isService() && item->isRegular();
|
2021-03-13 18:07:29 +00:00
|
|
|
}) | views::transform([](const auto &selected) {
|
2017-12-06 10:13:38 +00:00
|
|
|
return selected.first->fullId();
|
|
|
|
}) | to_vector;
|
|
|
|
|
2021-07-11 20:16:28 +00:00
|
|
|
result |= actions::sort(less{}, [](const FullMsgId &msgId) {
|
2017-12-06 10:13:38 +00:00
|
|
|
return msgId.channel ? msgId.msg : (msgId.msg - ServerMaxMsgId);
|
|
|
|
});
|
2017-06-16 20:33:35 +00:00
|
|
|
return result;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
void HistoryInner::selectItem(not_null<HistoryItem*> item) {
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!_selected.empty() && _selected.cbegin()->second != FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
_selected.clear();
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if (_selected.size() == MaxSelectedItems
|
|
|
|
&& _selected.find(item) == _selected.cend()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-05 15:35:52 +00:00
|
|
|
_selected.emplace(item, FullSelection);
|
2017-04-08 13:27:53 +00:00
|
|
|
_widget->updateTopBarSelection();
|
|
|
|
_widget->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::onTouchSelect() {
|
|
|
|
_touchSelect = true;
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionStart(_touchPos, Qt::LeftButton);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
void HistoryInner::mouseActionUpdate() {
|
2019-01-18 08:11:15 +00:00
|
|
|
if (hasPendingResizedItems()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
auto mousePos = mapFromGlobal(_mousePosition);
|
2017-04-08 13:27:53 +00:00
|
|
|
auto point = _widget->clampMousePosition(mousePos);
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
auto block = (HistoryBlock*)nullptr;
|
|
|
|
auto item = (HistoryItem*)nullptr;
|
2018-01-11 19:33:26 +00:00
|
|
|
auto view = (Element*)nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
QPoint m;
|
|
|
|
|
|
|
|
adjustCurrent(point.y());
|
|
|
|
if (_curHistory && !_curHistory->isEmpty()) {
|
2018-01-10 13:13:33 +00:00
|
|
|
block = _curHistory->blocks[_curBlock].get();
|
2018-01-11 13:07:29 +00:00
|
|
|
view = block->messages[_curItem].get();
|
|
|
|
item = view->data();
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
App::mousedItem(view);
|
|
|
|
m = mapPointToItem(point, view);
|
2018-01-27 13:59:24 +00:00
|
|
|
if (view->pointState(m) != PointState::Outside) {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (App::hoveredItem() != view) {
|
2017-04-08 13:27:53 +00:00
|
|
|
repaintItem(App::hoveredItem());
|
2018-01-11 13:07:29 +00:00
|
|
|
App::hoveredItem(view);
|
2017-04-08 13:27:53 +00:00
|
|
|
repaintItem(App::hoveredItem());
|
|
|
|
}
|
|
|
|
} else if (App::hoveredItem()) {
|
|
|
|
repaintItem(App::hoveredItem());
|
2018-01-11 13:07:29 +00:00
|
|
|
App::hoveredItem(nullptr);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-11 13:07:29 +00:00
|
|
|
if (_mouseActionItem && !_mouseActionItem->mainView()) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionCancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState dragState;
|
2017-04-08 13:27:53 +00:00
|
|
|
ClickHandlerHost *lnkhost = nullptr;
|
2017-12-15 16:25:47 +00:00
|
|
|
auto selectingText = (item == _mouseActionItem)
|
2018-01-11 13:07:29 +00:00
|
|
|
&& (view == App::hoveredItem())
|
2017-12-15 16:25:47 +00:00
|
|
|
&& !_selected.empty()
|
|
|
|
&& (_selected.cbegin()->second != FullSelection);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (point.y() < _historyPaddingTop) {
|
|
|
|
if (_botAbout && !_botAbout->info->text.isEmpty() && _botAbout->height > 0) {
|
2018-01-27 13:59:24 +00:00
|
|
|
dragState = TextState(nullptr, _botAbout->info->text.getState(
|
2017-12-15 16:25:47 +00:00
|
|
|
point - _botAbout->rect.topLeft() - QPoint(st::msgPadding.left(), st::msgPadding.top() + st::botDescSkip + st::msgNameFont->height),
|
|
|
|
_botAbout->width));
|
2019-07-24 11:13:51 +00:00
|
|
|
_dragStateItem = session().data().message(dragState.itemId);
|
2017-04-08 13:27:53 +00:00
|
|
|
lnkhost = _botAbout.get();
|
|
|
|
}
|
|
|
|
} else if (item) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (item != _mouseActionItem || (m - _dragStartPosition).manhattanLength() >= QApplication::startDragDistance()) {
|
|
|
|
if (_mouseAction == MouseAction::PrepareDrag) {
|
|
|
|
_mouseAction = MouseAction::Dragging;
|
2018-01-27 19:21:41 +00:00
|
|
|
crl::on_main(this, [=] { performDrag(); });
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (_mouseAction == MouseAction::PrepareSelect) {
|
|
|
|
_mouseAction = MouseAction::Selecting;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto dateHeight = st::msgServicePadding.bottom() + st::msgServiceFont->height + st::msgServicePadding.top();
|
2019-04-02 09:13:30 +00:00
|
|
|
auto scrollDateOpacity = _scrollDateOpacity.value(_scrollDateShown ? 1. : 0.);
|
2018-01-11 19:33:26 +00:00
|
|
|
enumerateDates([&](not_null<Element*> view, int itemtop, int dateTop) {
|
2017-04-08 13:27:53 +00:00
|
|
|
// stop enumeration if the date is above our point
|
|
|
|
if (dateTop + dateHeight <= point.y()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-23 11:47:38 +00:00
|
|
|
const auto displayDate = view->displayDate();
|
2018-01-11 15:51:59 +00:00
|
|
|
auto dateInPlace = displayDate;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dateInPlace) {
|
2018-01-11 15:51:59 +00:00
|
|
|
const auto correctDateTop = itemtop + st::msgServiceMargin.top();
|
2017-04-08 13:27:53 +00:00
|
|
|
dateInPlace = (dateTop < correctDateTop + dateHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop enumeration if we've found a date under the cursor
|
|
|
|
if (dateTop <= point.y()) {
|
|
|
|
auto opacity = (dateInPlace/* || noFloatingDate*/) ? 1. : scrollDateOpacity;
|
|
|
|
if (opacity > 0.) {
|
2018-01-23 11:47:38 +00:00
|
|
|
const auto item = view->data();
|
2017-04-08 13:27:53 +00:00
|
|
|
auto dateWidth = 0;
|
2018-01-23 11:47:38 +00:00
|
|
|
if (const auto date = view->Get<HistoryView::DateBadge>()) {
|
|
|
|
dateWidth = date->width;
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2018-02-03 19:52:35 +00:00
|
|
|
dateWidth = st::msgServiceFont->width(langDayOfMonthFull(view->dateTime().date()));
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
dateWidth += st::msgServicePadding.left() + st::msgServicePadding.right();
|
|
|
|
auto dateLeft = st::msgServiceMargin.left();
|
2018-01-21 19:21:08 +00:00
|
|
|
auto maxwidth = _contentWidth;
|
2021-05-27 00:44:12 +00:00
|
|
|
if (_isChatWide) {
|
2017-04-08 13:27:53 +00:00
|
|
|
maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left()));
|
|
|
|
}
|
|
|
|
auto widthForDate = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left();
|
|
|
|
|
|
|
|
dateLeft += (widthForDate - dateWidth) / 2;
|
|
|
|
|
|
|
|
if (point.x() >= dateLeft && point.x() < dateLeft + dateWidth) {
|
|
|
|
if (!_scrollDateLink) {
|
2018-02-21 21:17:36 +00:00
|
|
|
_scrollDateLink = std::make_shared<Window::DateClickHandler>(item->history(), view->dateTime().date());
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2018-02-21 21:17:36 +00:00
|
|
|
static_cast<Window::DateClickHandler*>(_scrollDateLink.get())->setDate(view->dateTime().date());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
dragState = TextState(
|
2017-12-15 16:25:47 +00:00
|
|
|
nullptr,
|
|
|
|
_scrollDateLink);
|
2019-07-24 11:13:51 +00:00
|
|
|
_dragStateItem = session().data().message(dragState.itemId);
|
2018-01-11 15:51:59 +00:00
|
|
|
lnkhost = view;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
if (!dragState.link) {
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Selecting) {
|
2019-06-12 13:26:04 +00:00
|
|
|
request.flags |= Ui::Text::StateRequest::Flag::LookupSymbol;
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
selectingText = false;
|
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
dragState = view->textState(m, request);
|
2019-07-24 11:13:51 +00:00
|
|
|
_dragStateItem = session().data().message(dragState.itemId);
|
2018-01-11 15:51:59 +00:00
|
|
|
lnkhost = view;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!dragState.link && m.x() >= st::historyPhotoLeft && m.x() < st::historyPhotoLeft + st::msgPhotoSize) {
|
2021-11-07 08:06:00 +00:00
|
|
|
if (!item->isService() && view->hasFromPhoto()) {
|
|
|
|
enumerateUserpics([&](not_null<Element*> view, int userpicTop) -> bool {
|
|
|
|
// stop enumeration if the userpic is below our point
|
|
|
|
if (userpicTop > point.y()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-11 15:51:59 +00:00
|
|
|
|
2021-11-07 08:06:00 +00:00
|
|
|
// stop enumeration if we've found a userpic under the cursor
|
|
|
|
if (point.y() >= userpicTop && point.y() < userpicTop + st::msgPhotoSize) {
|
|
|
|
dragState = TextState(nullptr, view->fromPhotoLink());
|
|
|
|
_dragStateItem = nullptr;
|
|
|
|
lnkhost = view;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto lnkChanged = ClickHandler::setActive(dragState.link, lnkhost);
|
2017-06-21 21:38:31 +00:00
|
|
|
if (lnkChanged || dragState.cursor != _mouseCursorState) {
|
2017-04-08 13:27:53 +00:00
|
|
|
Ui::Tooltip::Hide();
|
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
if (dragState.link
|
|
|
|
|| dragState.cursor == CursorState::Date
|
2018-12-24 10:12:45 +00:00
|
|
|
|| dragState.cursor == CursorState::Forwarded
|
|
|
|
|| dragState.customTooltip) {
|
2017-04-08 13:27:53 +00:00
|
|
|
Ui::Tooltip::Show(1000, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::CursorShape cur = style::cur_default;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::None) {
|
|
|
|
_mouseCursorState = dragState.cursor;
|
2017-04-08 13:27:53 +00:00
|
|
|
if (dragState.link) {
|
|
|
|
cur = style::cur_pointer;
|
2018-01-27 13:59:24 +00:00
|
|
|
} else if (_mouseCursorState == CursorState::Text && (_selected.empty() || _selected.cbegin()->second != FullSelection)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
cur = style::cur_text;
|
2018-01-27 13:59:24 +00:00
|
|
|
} else if (_mouseCursorState == CursorState::Date) {
|
2017-12-15 16:25:47 +00:00
|
|
|
//cur = style::cur_cross;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else if (item) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Selecting) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selectingText) {
|
|
|
|
uint16 second = dragState.symbol;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (dragState.afterSymbol && _mouseSelectType == TextSelectType::Letters) {
|
2017-04-08 13:27:53 +00:00
|
|
|
++second;
|
|
|
|
}
|
2017-06-23 19:28:42 +00:00
|
|
|
auto selState = TextSelection { qMin(second, _mouseTextSymbol), qMax(second, _mouseTextSymbol) };
|
|
|
|
if (_mouseSelectType != TextSelectType::Letters) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto view = _mouseActionItem->mainView()) {
|
|
|
|
selState = view->adjustSelection(selState, _mouseSelectType);
|
|
|
|
}
|
2017-06-23 19:28:42 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_selected[_mouseActionItem] != selState) {
|
|
|
|
_selected[_mouseActionItem] = selState;
|
|
|
|
repaintItem(_mouseActionItem);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (!_wasSelectedText && (selState == FullSelection || selState.from != selState.to)) {
|
|
|
|
_wasSelectedText = true;
|
|
|
|
setFocus();
|
|
|
|
}
|
2019-01-18 08:11:15 +00:00
|
|
|
updateDragSelection(nullptr, nullptr, false);
|
|
|
|
} else {
|
2017-06-21 21:38:31 +00:00
|
|
|
auto selectingDown = (itemTop(_mouseActionItem) < itemTop(item)) || (_mouseActionItem == item && _dragStartPosition.y() < m.y());
|
2018-01-11 13:07:29 +00:00
|
|
|
auto dragSelFrom = _mouseActionItem->mainView();
|
|
|
|
auto dragSelTo = view;
|
2018-01-27 13:59:24 +00:00
|
|
|
// Maybe exclude dragSelFrom.
|
|
|
|
if (dragSelFrom->pointState(_dragStartPosition) == PointState::Outside) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selectingDown) {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (_dragStartPosition.y() >= dragSelFrom->height() - dragSelFrom->marginBottom() || ((view == dragSelFrom) && (m.y() < _dragStartPosition.y() + QApplication::startDragDistance() || m.y() < dragSelFrom->marginTop()))) {
|
2018-01-11 13:07:29 +00:00
|
|
|
dragSelFrom = (dragSelFrom != dragSelTo)
|
|
|
|
? nextItem(dragSelFrom)
|
|
|
|
: nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (_dragStartPosition.y() < dragSelFrom->marginTop() || ((view == dragSelFrom) && (m.y() >= _dragStartPosition.y() - QApplication::startDragDistance() || m.y() >= dragSelFrom->height() - dragSelFrom->marginBottom()))) {
|
2018-01-11 13:07:29 +00:00
|
|
|
dragSelFrom = (dragSelFrom != dragSelTo)
|
|
|
|
? prevItem(dragSelFrom)
|
|
|
|
: nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseActionItem != item) { // maybe exclude dragSelTo
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selectingDown) {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (m.y() < dragSelTo->marginTop()) {
|
2018-01-11 13:07:29 +00:00
|
|
|
dragSelTo = (dragSelFrom != dragSelTo)
|
2018-03-08 21:21:27 +00:00
|
|
|
? prevItem(dragSelTo)
|
2018-01-11 13:07:29 +00:00
|
|
|
: nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (m.y() >= dragSelTo->height() - dragSelTo->marginBottom()) {
|
2018-01-11 13:07:29 +00:00
|
|
|
dragSelTo = (dragSelFrom != dragSelTo)
|
2018-03-08 21:21:27 +00:00
|
|
|
? nextItem(dragSelTo)
|
2018-01-11 13:07:29 +00:00
|
|
|
: nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto dragSelecting = false;
|
|
|
|
auto dragFirstAffected = dragSelFrom;
|
2021-11-07 08:06:00 +00:00
|
|
|
while (dragFirstAffected
|
|
|
|
&& (!dragFirstAffected->data()->isRegular()
|
|
|
|
|| dragFirstAffected->data()->isService())) {
|
2018-01-11 13:07:29 +00:00
|
|
|
dragFirstAffected = (dragFirstAffected != dragSelTo)
|
|
|
|
? (selectingDown
|
|
|
|
? nextItem(dragFirstAffected)
|
|
|
|
: prevItem(dragFirstAffected))
|
|
|
|
: nullptr;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (dragFirstAffected) {
|
2018-01-11 13:07:29 +00:00
|
|
|
auto i = _selected.find(dragFirstAffected->data());
|
2017-10-05 15:35:52 +00:00
|
|
|
dragSelecting = (i == _selected.cend() || i->second != FullSelection);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
updateDragSelection(dragSelFrom, dragSelTo, dragSelecting);
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
} else if (_mouseAction == MouseAction::Dragging) {
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ClickHandler::getPressed()) {
|
|
|
|
cur = style::cur_pointer;
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if ((_mouseAction == MouseAction::Selecting)
|
|
|
|
&& !_selected.empty()
|
|
|
|
&& (_selected.cbegin()->second != FullSelection)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (!_dragSelFrom || !_dragSelTo) {
|
|
|
|
cur = style::cur_text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Voice message seek support.
|
2017-12-15 16:25:47 +00:00
|
|
|
if (const auto pressedItem = _dragStateItem) {
|
2018-01-13 12:45:11 +00:00
|
|
|
if (const auto pressedView = pressedItem->mainView()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (pressedItem->history() == _history || pressedItem->history() == _migrated) {
|
2018-01-13 12:45:11 +00:00
|
|
|
auto adjustedPoint = mapPointToItem(point, pressedView);
|
|
|
|
pressedView->updatePressed(adjustedPoint);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::Selecting) {
|
2021-10-30 06:11:27 +00:00
|
|
|
_selectScroll.checkDeltaScroll(
|
|
|
|
mousePos,
|
|
|
|
_scroll->scrollTop(),
|
|
|
|
_scroll->scrollTop() + _scroll->height());
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2019-04-04 10:02:22 +00:00
|
|
|
updateDragSelection(nullptr, nullptr, false);
|
2021-10-30 06:11:27 +00:00
|
|
|
_selectScroll.cancel();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_mouseAction == MouseAction::None && (lnkChanged || cur != _cursor)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
setCursor(_cursor = cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void HistoryInner::updateDragSelection(Element *dragSelFrom, Element *dragSelTo, bool dragSelecting) {
|
2017-10-13 19:07:04 +00:00
|
|
|
if (_dragSelFrom == dragSelFrom && _dragSelTo == dragSelTo && _dragSelecting == dragSelecting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_dragSelFrom = dragSelFrom;
|
|
|
|
_dragSelTo = dragSelTo;
|
|
|
|
int32 fromy = itemTop(_dragSelFrom), toy = itemTop(_dragSelTo);
|
|
|
|
if (fromy >= 0 && toy >= 0 && fromy > toy) {
|
2018-01-11 13:07:29 +00:00
|
|
|
std::swap(_dragSelFrom, _dragSelTo);
|
2017-10-13 19:07:04 +00:00
|
|
|
}
|
|
|
|
_dragSelecting = dragSelecting;
|
|
|
|
if (!_wasSelectedText && _dragSelFrom && _dragSelTo && _dragSelecting) {
|
|
|
|
_wasSelectedText = true;
|
|
|
|
setFocus();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::historyHeight() const {
|
|
|
|
int result = 0;
|
2019-01-18 08:11:15 +00:00
|
|
|
if (_history->isEmpty()) {
|
2018-01-21 19:21:08 +00:00
|
|
|
result += _migrated ? _migrated->height() : 0;
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2018-01-21 19:21:08 +00:00
|
|
|
result += _history->height() - _historySkipHeight + (_migrated ? _migrated->height() : 0);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::historyScrollTop() const {
|
2017-05-12 13:53:08 +00:00
|
|
|
auto htop = historyTop();
|
|
|
|
auto mtop = migratedTop();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (htop >= 0 && _history->scrollTopItem) {
|
2018-01-11 13:07:29 +00:00
|
|
|
return htop + _history->scrollTopItem->block()->y() + _history->scrollTopItem->y() + _history->scrollTopOffset;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (mtop >= 0 && _migrated->scrollTopItem) {
|
2018-01-11 13:07:29 +00:00
|
|
|
return mtop + _migrated->scrollTopItem->block()->y() + _migrated->scrollTopItem->y() + _migrated->scrollTopOffset;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
return ScrollMax;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::migratedTop() const {
|
|
|
|
return (_migrated && !_migrated->isEmpty()) ? _historyPaddingTop : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::historyTop() const {
|
|
|
|
int mig = migratedTop();
|
2019-01-18 08:11:15 +00:00
|
|
|
return !_history->isEmpty()
|
|
|
|
? (mig >= 0
|
|
|
|
? (mig + _migrated->height() - _historySkipHeight)
|
|
|
|
: _historyPaddingTop)
|
|
|
|
: -1;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int HistoryInner::historyDrawTop() const {
|
2017-05-21 16:06:33 +00:00
|
|
|
auto top = historyTop();
|
|
|
|
return (top >= 0) ? (top + _historySkipHeight) : -1;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2021-02-15 17:37:22 +00:00
|
|
|
void HistoryInner::setChooseReportReason(Ui::ReportReason reason) {
|
|
|
|
_chooseForReportReason = reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::clearChooseReportReason() {
|
|
|
|
_chooseForReportReason = std::nullopt;
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
// -1 if should not be visible, -2 if bad history()
|
|
|
|
int HistoryInner::itemTop(const HistoryItem *item) const {
|
|
|
|
if (!item) {
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
return itemTop(item->mainView());
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
int HistoryInner::itemTop(const Element *view) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (!view || view->data()->mainView() != view) {
|
2018-01-11 13:07:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
auto top = (view->data()->history() == _history)
|
|
|
|
? historyTop()
|
|
|
|
: (view->data()->history() == _migrated
|
|
|
|
? migratedTop()
|
|
|
|
: -2);
|
|
|
|
return (top < 0) ? top : (top + view->y() + view->block()->y());
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 12:40:33 +00:00
|
|
|
auto HistoryInner::findViewForPinnedTracking(int top) const
|
|
|
|
-> std::pair<Element*, int> {
|
|
|
|
const auto normalTop = historyTop();
|
|
|
|
const auto oldTop = migratedTop();
|
|
|
|
const auto fromHistory = [&](not_null<History*> history, int historyTop)
|
|
|
|
-> std::pair<Element*, int> {
|
|
|
|
auto [view, offset] = history->findItemAndOffset(top - historyTop);
|
2021-11-07 08:06:00 +00:00
|
|
|
while (view && !view->data()->isRegular()) {
|
2020-10-22 12:40:33 +00:00
|
|
|
offset -= view->height();
|
|
|
|
view = view->nextInBlocks();
|
|
|
|
}
|
|
|
|
return { view, offset };
|
|
|
|
};
|
|
|
|
if (normalTop >= 0 && (oldTop < 0 || top >= normalTop)) {
|
|
|
|
return fromHistory(_history, normalTop);
|
|
|
|
} else if (oldTop >= 0) {
|
|
|
|
auto [view, offset] = fromHistory(_migrated, oldTop);
|
|
|
|
if (!view && normalTop >= 0) {
|
|
|
|
return fromHistory(_history, normalTop);
|
|
|
|
}
|
|
|
|
return { view, offset };
|
|
|
|
}
|
|
|
|
return { nullptr, 0 };
|
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::notifyIsBotChanged() {
|
2019-01-18 08:11:15 +00:00
|
|
|
const auto newinfo = _peer->isUser()
|
2019-01-08 13:57:22 +00:00
|
|
|
? _peer->asUser()->botInfo.get()
|
2017-12-16 15:00:20 +00:00
|
|
|
: nullptr;
|
|
|
|
if ((!newinfo && !_botAbout)
|
|
|
|
|| (newinfo && _botAbout && _botAbout->info == newinfo)) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newinfo) {
|
2017-12-16 15:00:20 +00:00
|
|
|
_botAbout = std::make_unique<BotAbout>(this, newinfo);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (newinfo && !newinfo->inited) {
|
2019-07-24 11:13:51 +00:00
|
|
|
session().api().requestFullPeer(_peer);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_botAbout = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::notifyMigrateUpdated() {
|
2017-08-31 17:53:03 +00:00
|
|
|
_migrated = _history->migrateFrom();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::applyDragSelection() {
|
|
|
|
applyDragSelection(&_selected);
|
|
|
|
}
|
|
|
|
|
2017-12-15 18:36:28 +00:00
|
|
|
bool HistoryInner::isSelected(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item) const {
|
|
|
|
const auto i = toItems->find(item);
|
|
|
|
return (i != toItems->cend()) && (i->second == FullSelection);
|
|
|
|
}
|
|
|
|
|
2018-01-27 17:26:24 +00:00
|
|
|
bool HistoryInner::isSelectedGroup(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<const Data::Group*> group) const {
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &other : group->items) {
|
2018-01-27 17:26:24 +00:00
|
|
|
if (!isSelected(toItems, other)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-15 18:36:28 +00:00
|
|
|
bool HistoryInner::isSelectedAsGroup(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item) const {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto group = session().data().groups().find(item)) {
|
2018-01-27 17:26:24 +00:00
|
|
|
return isSelectedGroup(toItems, group);
|
2017-12-15 18:36:28 +00:00
|
|
|
}
|
|
|
|
return isSelected(toItems, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryInner::goodForSelection(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
int &totalCount) const {
|
2021-11-07 08:06:00 +00:00
|
|
|
if (!item->isRegular() || item->isService()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return false;
|
2021-11-07 08:06:00 +00:00
|
|
|
} else if (toItems->find(item) == toItems->end()) {
|
2017-12-15 18:36:28 +00:00
|
|
|
++totalCount;
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-15 18:36:28 +00:00
|
|
|
void HistoryInner::addToSelection(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item) const {
|
|
|
|
const auto i = toItems->find(item);
|
|
|
|
if (i == toItems->cend()) {
|
2021-08-18 11:52:49 +00:00
|
|
|
if (toItems->size() == 1
|
|
|
|
&& toItems->begin()->second != FullSelection) {
|
|
|
|
toItems->clear();
|
|
|
|
}
|
2017-12-15 18:36:28 +00:00
|
|
|
toItems->emplace(item, FullSelection);
|
|
|
|
} else if (i->second != FullSelection) {
|
|
|
|
i->second = FullSelection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::removeFromSelection(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item) const {
|
|
|
|
const auto i = toItems->find(item);
|
|
|
|
if (i != toItems->cend()) {
|
|
|
|
toItems->erase(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::changeSelection(
|
2017-12-15 16:25:47 +00:00
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
SelectAction action) const {
|
|
|
|
if (action == SelectAction::Invert) {
|
2017-12-15 18:36:28 +00:00
|
|
|
action = isSelected(toItems, item)
|
2017-12-15 16:25:47 +00:00
|
|
|
? SelectAction::Deselect
|
|
|
|
: SelectAction::Select;
|
|
|
|
}
|
2017-12-15 18:36:28 +00:00
|
|
|
auto total = int(toItems->size());
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto add = (action == SelectAction::Select);
|
2017-12-15 18:36:28 +00:00
|
|
|
if (add
|
|
|
|
&& goodForSelection(toItems, item, total)
|
|
|
|
&& total <= MaxSelectedItems) {
|
|
|
|
addToSelection(toItems, item);
|
|
|
|
} else {
|
|
|
|
removeFromSelection(toItems, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::changeSelectionAsGroup(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
SelectAction action) const {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto group = session().data().groups().find(item);
|
2017-12-15 18:36:28 +00:00
|
|
|
if (!group) {
|
|
|
|
return changeSelection(toItems, item, action);
|
|
|
|
}
|
|
|
|
if (action == SelectAction::Invert) {
|
|
|
|
action = isSelectedAsGroup(toItems, item)
|
|
|
|
? SelectAction::Deselect
|
|
|
|
: SelectAction::Select;
|
|
|
|
}
|
|
|
|
auto total = int(toItems->size());
|
2018-01-27 13:59:24 +00:00
|
|
|
const auto canSelect = [&] {
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &other : group->items) {
|
2017-12-15 18:36:28 +00:00
|
|
|
if (!goodForSelection(toItems, other, total)) {
|
|
|
|
return false;
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-15 18:36:28 +00:00
|
|
|
return (total <= MaxSelectedItems);
|
2017-12-15 16:25:47 +00:00
|
|
|
}();
|
2018-01-27 13:59:24 +00:00
|
|
|
if (action == SelectAction::Select && canSelect) {
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &other : group->items) {
|
2017-12-15 18:36:28 +00:00
|
|
|
addToSelection(toItems, other);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &other : group->items) {
|
2017-12-15 18:36:28 +00:00
|
|
|
removeFromSelection(toItems, other);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::forwardItem(FullMsgId itemId) {
|
2019-07-25 18:55:11 +00:00
|
|
|
Window::ShowForwardMessagesBox(_controller, { 1, itemId });
|
2017-12-15 18:36:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::forwardAsGroup(FullMsgId itemId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = session().data().message(itemId)) {
|
2019-07-25 18:55:11 +00:00
|
|
|
Window::ShowForwardMessagesBox(
|
|
|
|
_controller,
|
|
|
|
session().data().itemOrItsGroup(item));
|
2018-01-11 13:07:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::deleteItem(FullMsgId itemId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = session().data().message(itemId)) {
|
2018-01-11 13:07:29 +00:00
|
|
|
deleteItem(item);
|
2017-12-15 18:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::deleteItem(not_null<HistoryItem*> item) {
|
2021-11-07 08:06:00 +00:00
|
|
|
if (item->isUploading()) {
|
|
|
|
_controller->cancelUploadLayer(item);
|
|
|
|
return;
|
2017-12-15 18:36:28 +00:00
|
|
|
}
|
|
|
|
const auto suggestModerateActions = true;
|
2021-06-13 07:37:52 +00:00
|
|
|
_controller->show(Box<DeleteMessagesBox>(item, suggestModerateActions));
|
2017-12-15 18:36:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
bool HistoryInner::hasPendingResizedItems() const {
|
2019-01-18 08:11:15 +00:00
|
|
|
return _history->hasPendingResizedItems()
|
2018-01-13 12:45:11 +00:00
|
|
|
|| (_migrated && _migrated->hasPendingResizedItems());
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryInner::deleteAsGroup(FullMsgId itemId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = session().data().message(itemId)) {
|
|
|
|
const auto group = session().data().groups().find(item);
|
2018-01-21 09:05:30 +00:00
|
|
|
if (!group) {
|
2018-01-11 13:07:29 +00:00
|
|
|
return deleteItem(item);
|
|
|
|
}
|
2021-06-13 07:37:52 +00:00
|
|
|
_controller->show(Box<DeleteMessagesBox>(
|
2019-07-24 14:00:30 +00:00
|
|
|
&session(),
|
2019-07-24 11:13:51 +00:00
|
|
|
session().data().itemsToIds(group->items)));
|
2017-12-15 18:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-10 14:15:16 +00:00
|
|
|
void HistoryInner::reportItem(FullMsgId itemId) {
|
2021-02-15 17:37:22 +00:00
|
|
|
HistoryView::ShowReportItemsBox(_peer, { 1, itemId });
|
2018-05-10 14:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::reportAsGroup(FullMsgId itemId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = session().data().message(itemId)) {
|
|
|
|
const auto group = session().data().groups().find(item);
|
2021-02-15 17:37:22 +00:00
|
|
|
HistoryView::ShowReportItemsBox(
|
2018-05-10 14:15:16 +00:00
|
|
|
_peer,
|
2021-02-15 17:37:22 +00:00
|
|
|
(group
|
|
|
|
? session().data().itemsToIds(group->items)
|
|
|
|
: MessageIdsList{ 1, itemId }));
|
2018-05-10 14:15:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-17 13:26:53 +00:00
|
|
|
void HistoryInner::blockSenderItem(FullMsgId itemId) {
|
|
|
|
if (const auto item = session().data().message(itemId)) {
|
2021-06-13 07:37:52 +00:00
|
|
|
_controller->show(Box(
|
2021-02-15 17:37:22 +00:00
|
|
|
Window::BlockSenderFromRepliesBox,
|
2020-09-17 13:26:53 +00:00
|
|
|
_controller,
|
2020-09-25 12:31:36 +00:00
|
|
|
itemId));
|
2020-09-17 13:26:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryInner::blockSenderAsGroup(FullMsgId itemId) {
|
2020-09-25 12:31:36 +00:00
|
|
|
blockSenderItem(itemId);
|
2020-09-17 13:26:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
void HistoryInner::addSelectionRange(
|
|
|
|
not_null<SelectedItems*> toItems,
|
|
|
|
not_null<History*> history,
|
|
|
|
int fromblock,
|
|
|
|
int fromitem,
|
|
|
|
int toblock,
|
|
|
|
int toitem) const {
|
2017-04-08 13:27:53 +00:00
|
|
|
if (fromblock >= 0 && fromitem >= 0 && toblock >= 0 && toitem >= 0) {
|
|
|
|
for (; fromblock <= toblock; ++fromblock) {
|
2018-01-10 13:13:33 +00:00
|
|
|
auto block = history->blocks[fromblock].get();
|
|
|
|
for (int cnt = (fromblock < toblock) ? block->messages.size() : (toitem + 1); fromitem < cnt; ++fromitem) {
|
|
|
|
auto item = block->messages[fromitem]->data();
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelectionAsGroup(toItems, item, SelectAction::Select);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
if (toItems->size() >= MaxSelectedItems) break;
|
|
|
|
fromitem = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
void HistoryInner::applyDragSelection(
|
|
|
|
not_null<SelectedItems*> toItems) const {
|
|
|
|
const auto selfromy = itemTop(_dragSelFrom);
|
|
|
|
const auto seltoy = [&] {
|
|
|
|
auto result = itemTop(_dragSelTo);
|
2018-01-13 12:45:11 +00:00
|
|
|
return (result < 0) ? result : (result + _dragSelTo->height());
|
2017-12-15 16:25:47 +00:00
|
|
|
}();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (selfromy < 0 || seltoy < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-05 15:35:52 +00:00
|
|
|
if (!toItems->empty() && toItems->cbegin()->second != FullSelection) {
|
2017-04-08 13:27:53 +00:00
|
|
|
toItems->clear();
|
|
|
|
}
|
|
|
|
if (_dragSelecting) {
|
2017-12-15 16:25:47 +00:00
|
|
|
auto fromblock = _dragSelFrom->block()->indexInHistory();
|
|
|
|
auto fromitem = _dragSelFrom->indexInBlock();
|
|
|
|
auto toblock = _dragSelTo->block()->indexInHistory();
|
|
|
|
auto toitem = _dragSelTo->indexInBlock();
|
2017-04-08 13:27:53 +00:00
|
|
|
if (_migrated) {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (_dragSelFrom->data()->history() == _migrated) {
|
|
|
|
if (_dragSelTo->data()->history() == _migrated) {
|
2017-12-15 16:25:47 +00:00
|
|
|
addSelectionRange(toItems, _migrated, fromblock, fromitem, toblock, toitem);
|
2017-04-08 13:27:53 +00:00
|
|
|
toblock = -1;
|
|
|
|
toitem = -1;
|
|
|
|
} else {
|
2018-01-10 13:13:33 +00:00
|
|
|
addSelectionRange(toItems, _migrated, fromblock, fromitem, _migrated->blocks.size() - 1, _migrated->blocks.back()->messages.size() - 1);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
fromblock = 0;
|
|
|
|
fromitem = 0;
|
2018-01-11 13:07:29 +00:00
|
|
|
} else if (_dragSelTo->data()->history() == _migrated) { // wtf
|
2017-04-08 13:27:53 +00:00
|
|
|
toblock = -1;
|
|
|
|
toitem = -1;
|
|
|
|
}
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
addSelectionRange(toItems, _history, fromblock, fromitem, toblock, toitem);
|
2017-04-08 13:27:53 +00:00
|
|
|
} else {
|
2017-12-15 16:25:47 +00:00
|
|
|
auto toRemove = std::vector<not_null<HistoryItem*>>();
|
2019-01-18 08:11:15 +00:00
|
|
|
for (const auto &item : *toItems) {
|
|
|
|
auto iy = itemTop(item.first);
|
2017-12-15 16:25:47 +00:00
|
|
|
if (iy < -1) {
|
2019-01-18 08:11:15 +00:00
|
|
|
toRemove.emplace_back(item.first);
|
2017-12-15 16:25:47 +00:00
|
|
|
} else if (iy >= 0 && iy >= selfromy && iy < seltoy) {
|
2019-01-18 08:11:15 +00:00
|
|
|
toRemove.emplace_back(item.first);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
for (const auto item : toRemove) {
|
2017-12-15 18:36:28 +00:00
|
|
|
changeSelectionAsGroup(toItems, item, SelectAction::Deselect);
|
2017-12-15 16:25:47 +00:00
|
|
|
}
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HistoryInner::tooltipText() const {
|
2018-01-27 13:59:24 +00:00
|
|
|
if (_mouseCursorState == CursorState::Date
|
|
|
|
&& _mouseAction == MouseAction::None) {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (const auto view = App::hoveredItem()) {
|
2021-01-22 02:05:24 +00:00
|
|
|
return HistoryView::DateTooltipText(view);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
2018-01-27 13:59:24 +00:00
|
|
|
} else if (_mouseCursorState == CursorState::Forwarded
|
|
|
|
&& _mouseAction == MouseAction::None) {
|
2020-03-06 07:53:59 +00:00
|
|
|
if (const auto view = App::mousedItem()) {
|
2018-01-11 13:07:29 +00:00
|
|
|
if (const auto forwarded = view->data()->Get<HistoryMessageForwarded>()) {
|
2019-04-08 11:53:08 +00:00
|
|
|
return forwarded->text.toString();
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-24 10:12:45 +00:00
|
|
|
} else if (const auto lnk = ClickHandler::getActive()) {
|
2017-04-08 13:27:53 +00:00
|
|
|
return lnk->tooltip();
|
2018-12-24 10:12:45 +00:00
|
|
|
} else if (const auto view = App::mousedItem()) {
|
|
|
|
StateRequest request;
|
|
|
|
const auto local = mapFromGlobal(_mousePosition);
|
|
|
|
const auto point = _widget->clampMousePosition(local);
|
2019-06-12 13:26:04 +00:00
|
|
|
request.flags |= Ui::Text::StateRequest::Flag::LookupCustomTooltip;
|
2018-12-24 10:12:45 +00:00
|
|
|
const auto state = view->textState(
|
|
|
|
mapPointToItem(point, view),
|
|
|
|
request);
|
|
|
|
return state.customTooltipText;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint HistoryInner::tooltipPos() const {
|
2017-06-21 21:38:31 +00:00
|
|
|
return _mousePosition;
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
bool HistoryInner::tooltipWindowActive() const {
|
2019-12-31 13:48:44 +00:00
|
|
|
return Ui::AppInFocus() && Ui::InFocusChain(window());
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 13:27:53 +00:00
|
|
|
void HistoryInner::onParentGeometryChanged() {
|
|
|
|
auto mousePos = QCursor::pos();
|
|
|
|
auto mouseOver = _widget->rect().contains(_widget->mapFromGlobal(mousePos));
|
2017-06-21 21:38:31 +00:00
|
|
|
auto needToUpdate = (_mouseAction != MouseAction::None || _touchScroll || mouseOver);
|
2017-04-08 13:27:53 +00:00
|
|
|
if (needToUpdate) {
|
2017-06-21 21:38:31 +00:00
|
|
|
mouseActionUpdate(mousePos);
|
2017-04-08 13:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
|
|
|
|
not_null<HistoryView::ElementDelegate*> HistoryInner::ElementDelegate() {
|
2021-07-02 15:29:13 +00:00
|
|
|
class Result final : public HistoryView::ElementDelegate {
|
2018-01-17 16:21:01 +00:00
|
|
|
public:
|
2018-01-19 17:10:58 +00:00
|
|
|
HistoryView::Context elementContext() override {
|
|
|
|
return HistoryView::Context::History;
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
std::unique_ptr<HistoryView::Element> elementCreate(
|
2020-06-16 16:53:44 +00:00
|
|
|
not_null<HistoryMessage*> message,
|
|
|
|
Element *replacing = nullptr) override {
|
|
|
|
return std::make_unique<HistoryView::Message>(
|
|
|
|
this,
|
|
|
|
message,
|
|
|
|
replacing);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
std::unique_ptr<HistoryView::Element> elementCreate(
|
2020-06-16 16:53:44 +00:00
|
|
|
not_null<HistoryService*> message,
|
|
|
|
Element *replacing = nullptr) override {
|
|
|
|
return std::make_unique<HistoryView::Service>(
|
|
|
|
this,
|
|
|
|
message,
|
|
|
|
replacing);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
2018-01-26 15:40:11 +00:00
|
|
|
bool elementUnderCursor(
|
2020-06-10 18:08:17 +00:00
|
|
|
not_null<const Element*> view) override {
|
2018-01-26 15:40:11 +00:00
|
|
|
return (App::hoveredItem() == view);
|
|
|
|
}
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time elementHighlightTime(
|
2020-12-30 08:55:11 +00:00
|
|
|
not_null<const HistoryItem*> item) override {
|
|
|
|
return Instance ? Instance->elementHighlightTime(item) : 0;
|
2018-02-16 17:59:35 +00:00
|
|
|
}
|
2018-03-08 21:21:27 +00:00
|
|
|
bool elementInSelectionMode() override {
|
2019-05-14 09:50:44 +00:00
|
|
|
return Instance ? Instance->inSelectionMode() : false;
|
|
|
|
}
|
|
|
|
bool elementIntersectsRange(
|
|
|
|
not_null<const Element*> view,
|
|
|
|
int from,
|
|
|
|
int till) override {
|
|
|
|
return Instance
|
|
|
|
? Instance->elementIntersectsRange(view, from, till)
|
|
|
|
: false;
|
2018-03-08 21:21:27 +00:00
|
|
|
}
|
2019-08-01 12:55:14 +00:00
|
|
|
void elementStartStickerLoop(
|
2019-08-01 11:42:24 +00:00
|
|
|
not_null<const Element*> view) override {
|
|
|
|
if (Instance) {
|
2019-08-01 12:55:14 +00:00
|
|
|
Instance->elementStartStickerLoop(view);
|
2019-08-01 11:42:24 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-14 11:55:18 +00:00
|
|
|
void elementShowPollResults(
|
|
|
|
not_null<PollData*> poll,
|
|
|
|
FullMsgId context) override {
|
|
|
|
if (Instance) {
|
|
|
|
Instance->elementShowPollResults(poll, context);
|
|
|
|
}
|
|
|
|
}
|
2021-06-16 20:24:35 +00:00
|
|
|
void elementOpenPhoto(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
FullMsgId context) override {
|
|
|
|
if (Instance) {
|
|
|
|
Instance->elementOpenPhoto(photo, context);
|
|
|
|
}
|
|
|
|
}
|
2021-06-16 21:31:15 +00:00
|
|
|
void elementOpenDocument(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
FullMsgId context,
|
|
|
|
bool showInMediaView = false) override {
|
|
|
|
if (Instance) {
|
|
|
|
Instance->elementOpenDocument(
|
|
|
|
document,
|
|
|
|
context,
|
|
|
|
showInMediaView);
|
|
|
|
}
|
|
|
|
}
|
2021-06-18 06:20:49 +00:00
|
|
|
void elementCancelUpload(const FullMsgId &context) override {
|
|
|
|
if (Instance) {
|
|
|
|
Instance->elementCancelUpload(context);
|
|
|
|
}
|
|
|
|
}
|
2020-04-30 10:11:05 +00:00
|
|
|
void elementShowTooltip(
|
|
|
|
const TextWithEntities &text,
|
|
|
|
Fn<void()> hiddenCallback) override {
|
2020-04-29 12:36:51 +00:00
|
|
|
if (Instance) {
|
2020-04-30 10:11:05 +00:00
|
|
|
Instance->elementShowTooltip(text, hiddenCallback);
|
2020-04-29 12:36:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-23 17:21:58 +00:00
|
|
|
bool elementIsGifPaused() override {
|
|
|
|
return Instance ? Instance->elementIsGifPaused() : false;
|
|
|
|
}
|
2020-08-28 12:48:54 +00:00
|
|
|
bool elementHideReply(not_null<const Element*> view) override {
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-22 11:30:15 +00:00
|
|
|
bool elementShownUnread(not_null<const Element*> view) override {
|
|
|
|
return view->data()->unread();
|
|
|
|
}
|
2020-11-10 16:38:21 +00:00
|
|
|
void elementSendBotCommand(
|
|
|
|
const QString &command,
|
2020-11-10 18:51:20 +00:00
|
|
|
const FullMsgId &context) override {
|
2020-11-10 16:38:21 +00:00
|
|
|
if (Instance) {
|
|
|
|
Instance->elementSendBotCommand(command, context);
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 18:51:20 +00:00
|
|
|
void elementHandleViaClick(not_null<UserData*> bot) override {
|
|
|
|
if (Instance) {
|
|
|
|
Instance->elementHandleViaClick(bot);
|
|
|
|
}
|
|
|
|
}
|
2021-05-27 00:44:12 +00:00
|
|
|
bool elementIsChatWide() override {
|
|
|
|
return Instance
|
|
|
|
? Instance->elementIsChatWide()
|
|
|
|
: false;
|
|
|
|
}
|
2021-07-02 15:29:13 +00:00
|
|
|
not_null<Ui::PathShiftGradient*> elementPathShiftGradient() override {
|
|
|
|
Expects(Instance != nullptr);
|
|
|
|
|
|
|
|
return Instance->elementPathShiftGradient();
|
|
|
|
}
|
2021-07-26 14:37:19 +00:00
|
|
|
void elementReplyTo(const FullMsgId &to) override {
|
|
|
|
if (Instance) {
|
|
|
|
Instance->elementReplyTo(to);
|
|
|
|
}
|
|
|
|
}
|
2021-09-14 16:55:35 +00:00
|
|
|
void elementStartInteraction(not_null<const Element*> view) override {
|
|
|
|
if (Instance) {
|
|
|
|
Instance->elementStartInteraction(view);
|
|
|
|
}
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
};
|
2018-01-19 17:10:58 +00:00
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
static Result result;
|
|
|
|
return &result;
|
|
|
|
}
|