2020-08-28 10:01:55 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "history/view/history_view_replies_section.h"
|
|
|
|
|
2020-10-02 10:36:22 +00:00
|
|
|
#include "history/view/controls/history_view_compose_controls.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "history/view/history_view_top_bar_widget.h"
|
|
|
|
#include "history/view/history_view_list_widget.h"
|
|
|
|
#include "history/view/history_view_schedule_box.h"
|
2020-10-13 07:16:16 +00:00
|
|
|
#include "history/view/history_view_pinned_bar.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "history/history.h"
|
|
|
|
#include "history/history_drag_area.h"
|
2020-08-28 12:48:54 +00:00
|
|
|
#include "history/history_item_components.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "history/history_item.h"
|
|
|
|
#include "chat_helpers/send_context_menu.h" // SendMenu::Type.
|
2020-10-13 07:16:16 +00:00
|
|
|
#include "ui/chat/pinned_bar.h"
|
2021-09-06 19:45:38 +00:00
|
|
|
#include "ui/chat/chat_style.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "ui/widgets/shadow.h"
|
2020-09-15 18:19:06 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "ui/layers/generic_box.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/item_text_options.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2020-09-30 11:06:08 +00:00
|
|
|
#include "ui/text/format_values.h"
|
2020-10-13 07:16:16 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2020-10-13 12:07:53 +00:00
|
|
|
#include "ui/chat/attach/attach_prepare.h"
|
2020-10-15 14:27:16 +00:00
|
|
|
#include "ui/chat/attach/attach_send_files_way.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "ui/special_buttons.h"
|
|
|
|
#include "ui/ui_utility.h"
|
2020-09-30 07:51:17 +00:00
|
|
|
#include "ui/toasts/common_toasts.h"
|
2020-09-30 11:06:08 +00:00
|
|
|
#include "base/timer_rpl.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "api/api_common.h"
|
|
|
|
#include "api/api_editing.h"
|
|
|
|
#include "api/api_sending.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/edit_caption_box.h"
|
|
|
|
#include "boxes/send_files_box.h"
|
2021-05-26 21:04:18 +00:00
|
|
|
#include "window/window_adaptive.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "window/window_peer_menu.h"
|
|
|
|
#include "base/event_filter.h"
|
|
|
|
#include "base/call_delayed.h"
|
|
|
|
#include "core/file_utilities.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_user.h"
|
2020-11-10 16:38:21 +00:00
|
|
|
#include "data/data_chat.h"
|
2020-09-04 10:07:40 +00:00
|
|
|
#include "data/data_channel.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "data/data_replies_list.h"
|
2020-08-31 13:41:24 +00:00
|
|
|
#include "data/data_changes.h"
|
2021-08-30 19:35:16 +00:00
|
|
|
#include "data/data_send_action.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "storage/storage_media_prepare.h"
|
|
|
|
#include "storage/storage_account.h"
|
|
|
|
#include "inline_bots/inline_bot_result.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "facades.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2020-08-28 10:01:55 +00:00
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
|
|
|
|
#include <QtCore/QMimeData>
|
2020-08-31 13:41:24 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
namespace HistoryView {
|
|
|
|
namespace {
|
|
|
|
|
2020-09-08 11:19:44 +00:00
|
|
|
constexpr auto kReadRequestTimeout = 3 * crl::time(1000);
|
2020-09-30 11:06:08 +00:00
|
|
|
constexpr auto kRefreshSlowmodeLabelTimeout = crl::time(200);
|
2020-09-08 11:19:44 +00:00
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
bool CanSendFiles(not_null<const QMimeData*> data) {
|
|
|
|
if (data->hasImage()) {
|
|
|
|
return true;
|
|
|
|
} else if (const auto urls = data->urls(); !urls.empty()) {
|
|
|
|
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-13 07:16:16 +00:00
|
|
|
rpl::producer<Ui::MessageBarContent> RootViewContent(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId rootId) {
|
|
|
|
return MessageBarContentByItemId(
|
|
|
|
&history->session(),
|
|
|
|
FullMsgId{ history->channelId(), rootId }
|
|
|
|
) | rpl::map([=](Ui::MessageBarContent &&content) {
|
|
|
|
const auto item = history->owner().message(
|
|
|
|
history->channelId(),
|
|
|
|
rootId);
|
|
|
|
if (!item) {
|
|
|
|
content.text = Ui::Text::Link(tr::lng_deleted_message(tr::now));
|
|
|
|
}
|
|
|
|
const auto sender = (item && item->discussionPostOriginalSender())
|
|
|
|
? item->discussionPostOriginalSender()
|
|
|
|
: history->peer.get();
|
|
|
|
content.title = sender->name.isEmpty() ? "Message" : sender->name;
|
|
|
|
return std::move(content);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-09-17 17:57:06 +00:00
|
|
|
RepliesMemento::RepliesMemento(
|
|
|
|
not_null<HistoryItem*> commentsItem,
|
|
|
|
MsgId commentId)
|
|
|
|
: RepliesMemento(commentsItem->history(), commentsItem->id, commentId) {
|
|
|
|
if (commentId) {
|
|
|
|
_list.setAroundPosition({
|
2020-10-20 18:31:47 +00:00
|
|
|
.fullId = FullMsgId(
|
|
|
|
commentsItem->history()->channelId(),
|
|
|
|
commentId),
|
2020-10-09 12:56:33 +00:00
|
|
|
.date = TimeId(0),
|
2020-09-17 17:57:06 +00:00
|
|
|
});
|
2020-09-22 11:01:49 +00:00
|
|
|
} else if (commentsItem->computeRepliesInboxReadTillFull() == MsgId(1)) {
|
|
|
|
_list.setAroundPosition(Data::MinMessagePosition);
|
|
|
|
_list.setScrollTopState(ListMemento::ScrollTopState{
|
|
|
|
Data::MinMessagePosition
|
|
|
|
});
|
2020-09-08 11:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
object_ptr<Window::SectionWidget> RepliesMemento::createWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
Window::Column column,
|
|
|
|
const QRect &geometry) {
|
|
|
|
if (column == Window::Column::Third) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto result = object_ptr<RepliesWidget>(
|
|
|
|
parent,
|
|
|
|
controller,
|
|
|
|
_history,
|
|
|
|
_rootId);
|
|
|
|
result->setInternalState(geometry, this);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
RepliesWidget::RepliesWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId rootId)
|
2021-08-26 13:25:48 +00:00
|
|
|
: Window::SectionWidget(parent, controller, history->peer)
|
2020-08-28 10:01:55 +00:00
|
|
|
, _history(history)
|
|
|
|
, _rootId(rootId)
|
2020-09-03 07:19:02 +00:00
|
|
|
, _root(lookupRoot())
|
|
|
|
, _areComments(computeAreComments())
|
2021-08-30 19:35:16 +00:00
|
|
|
, _sendAction(history->owner().sendActionManager().repliesPainter(
|
|
|
|
history,
|
|
|
|
rootId))
|
2020-08-28 10:01:55 +00:00
|
|
|
, _topBar(this, controller)
|
|
|
|
, _topBarShadow(this)
|
|
|
|
, _composeControls(std::make_unique<ComposeControls>(
|
|
|
|
this,
|
|
|
|
controller,
|
2020-11-16 16:01:37 +00:00
|
|
|
ComposeControls::Mode::Normal,
|
|
|
|
SendMenu::Type::SilentOnly))
|
2021-09-06 19:45:38 +00:00
|
|
|
, _scroll(std::make_unique<Ui::ScrollArea>(
|
|
|
|
this,
|
|
|
|
controller->chatStyle()->value(lifetime(), st::historyScroll),
|
|
|
|
false))
|
|
|
|
, _scrollDown(
|
|
|
|
_scroll.get(),
|
|
|
|
controller->chatStyle()->value(lifetime(), st::historyToDown))
|
2020-09-08 11:19:44 +00:00
|
|
|
, _readRequestTimer([=] { sendReadTillRequest(); }) {
|
2021-09-06 19:45:38 +00:00
|
|
|
controller->chatStyle()->paletteChanged(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_scroll->updateBars();
|
|
|
|
}, _scroll->lifetime());
|
|
|
|
|
2021-08-27 20:44:47 +00:00
|
|
|
Window::ChatThemeValueFromPeer(
|
|
|
|
controller,
|
|
|
|
history->peer
|
|
|
|
) | rpl::start_with_next([=](std::shared_ptr<Ui::ChatTheme> &&theme) {
|
|
|
|
_theme = std::move(theme);
|
|
|
|
controller->setChatStyleTheme(_theme);
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
setupRoot();
|
2020-09-15 18:19:06 +00:00
|
|
|
setupRootView();
|
2020-09-03 07:19:02 +00:00
|
|
|
|
2020-09-30 11:06:08 +00:00
|
|
|
session().api().requestFullPeer(_history->peer);
|
|
|
|
|
2020-11-11 20:47:40 +00:00
|
|
|
refreshTopBarActiveChat();
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
_topBar->move(0, 0);
|
|
|
|
_topBar->resizeToWidth(width());
|
|
|
|
_topBar->show();
|
|
|
|
|
2020-09-15 18:19:06 +00:00
|
|
|
_rootView->move(0, _topBar->height());
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
_topBar->deleteSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
confirmDeleteSelected();
|
|
|
|
}, _topBar->lifetime());
|
2020-09-04 16:11:36 +00:00
|
|
|
_topBar->forwardSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
confirmForwardSelected();
|
|
|
|
}, _topBar->lifetime());
|
2020-08-28 10:01:55 +00:00
|
|
|
_topBar->clearSelectionRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
clearSelected();
|
|
|
|
}, _topBar->lifetime());
|
|
|
|
|
2020-09-16 19:48:56 +00:00
|
|
|
_rootView->raise();
|
|
|
|
_topBarShadow->raise();
|
2021-05-26 21:04:18 +00:00
|
|
|
|
2021-06-24 05:33:52 +00:00
|
|
|
controller->adaptive().value(
|
2021-05-26 21:04:18 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateAdaptiveLayout();
|
|
|
|
}, lifetime());
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
_inner = _scroll->setOwnedWidget(object_ptr<ListWidget>(
|
|
|
|
this,
|
|
|
|
controller,
|
|
|
|
static_cast<ListDelegate*>(this)));
|
2020-09-15 18:19:06 +00:00
|
|
|
_scroll->move(0, _topBar->height());
|
2020-08-28 10:01:55 +00:00
|
|
|
_scroll->show();
|
2021-09-29 16:01:12 +00:00
|
|
|
_scroll->scrolls(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
onScroll();
|
|
|
|
}, lifetime());
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
_inner->editMessageRequested(
|
|
|
|
) | rpl::start_with_next([=](auto fullId) {
|
|
|
|
if (const auto item = session().data().message(fullId)) {
|
|
|
|
const auto media = item->media();
|
|
|
|
if (media && !media->webpage()) {
|
|
|
|
if (media->allowsEditCaption()) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(Box<EditCaptionBox>(controller, item));
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_composeControls->editMessage(fullId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, _inner->lifetime());
|
|
|
|
|
2020-09-01 06:07:37 +00:00
|
|
|
_inner->replyToMessageRequested(
|
|
|
|
) | rpl::start_with_next([=](auto fullId) {
|
2020-11-11 20:47:40 +00:00
|
|
|
replyToMessage(fullId);
|
2020-09-01 06:07:37 +00:00
|
|
|
}, _inner->lifetime());
|
|
|
|
|
2021-01-31 20:49:25 +00:00
|
|
|
_inner->showMessageRequested(
|
|
|
|
) | rpl::start_with_next([=](auto fullId) {
|
|
|
|
if (const auto item = session().data().message(fullId)) {
|
|
|
|
showAtPosition(item->position());
|
|
|
|
}
|
|
|
|
}, _inner->lifetime());
|
|
|
|
|
2020-09-29 08:36:30 +00:00
|
|
|
_composeControls->sendActionUpdates(
|
2020-09-29 15:05:48 +00:00
|
|
|
) | rpl::start_with_next([=](ComposeControls::SendActionUpdate &&data) {
|
2021-08-30 15:05:07 +00:00
|
|
|
if (!data.cancel) {
|
|
|
|
session().sendProgressManager().update(
|
|
|
|
_history,
|
|
|
|
_rootId,
|
|
|
|
data.type,
|
|
|
|
data.progress);
|
|
|
|
} else {
|
|
|
|
session().sendProgressManager().cancel(
|
|
|
|
_history,
|
|
|
|
_rootId,
|
|
|
|
data.type);
|
|
|
|
}
|
2020-09-29 08:36:30 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2021-08-30 15:37:09 +00:00
|
|
|
using MessageUpdateFlag = Data::MessageUpdate::Flag;
|
2020-08-31 13:41:24 +00:00
|
|
|
_history->session().changes().messageUpdates(
|
2021-08-30 15:37:09 +00:00
|
|
|
MessageUpdateFlag::Destroyed
|
|
|
|
| MessageUpdateFlag::RepliesUnreadCount
|
2020-09-08 11:19:44 +00:00
|
|
|
) | rpl::start_with_next([=](const Data::MessageUpdate &update) {
|
2021-08-30 15:37:09 +00:00
|
|
|
if (update.flags & MessageUpdateFlag::Destroyed) {
|
|
|
|
if (update.item == _root) {
|
|
|
|
_root = nullptr;
|
|
|
|
updatePinnedVisibility();
|
|
|
|
controller->showBackFromStack();
|
|
|
|
}
|
|
|
|
while (update.item == _replyReturn) {
|
|
|
|
calculateNextReplyReturn();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if ((update.item == _root)
|
|
|
|
&& (update.flags & MessageUpdateFlag::RepliesUnreadCount)) {
|
|
|
|
refreshUnreadCountBadge();
|
2020-08-31 13:41:24 +00:00
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-09-22 11:30:15 +00:00
|
|
|
_history->session().changes().historyUpdates(
|
|
|
|
_history,
|
|
|
|
Data::HistoryUpdate::Flag::OutboxRead
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_inner->update();
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-08-30 16:22:16 +00:00
|
|
|
_history->session().data().unreadRepliesCountRequests(
|
|
|
|
) | rpl::filter([=](
|
|
|
|
const Data::Session::UnreadRepliesCountRequest &request) {
|
|
|
|
return (request.root.get() == _root);
|
|
|
|
}) | rpl::start_with_next([=](
|
|
|
|
const Data::Session::UnreadRepliesCountRequest &request) {
|
|
|
|
if (const auto result = computeUnreadCountLocally(request.afterId)) {
|
|
|
|
*request.result = result;
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
setupScrollDownButton();
|
|
|
|
setupComposeControls();
|
2020-11-10 14:10:08 +00:00
|
|
|
orderWidgets();
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
2020-09-08 11:19:44 +00:00
|
|
|
RepliesWidget::~RepliesWidget() {
|
|
|
|
if (_readRequestTimer.isActive()) {
|
|
|
|
sendReadTillRequest();
|
|
|
|
}
|
2020-09-29 08:36:30 +00:00
|
|
|
base::take(_sendAction);
|
2021-08-30 19:35:16 +00:00
|
|
|
_history->owner().sendActionManager().repliesPainterRemoved(
|
|
|
|
_history,
|
|
|
|
_rootId);
|
2020-09-08 11:19:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 14:10:08 +00:00
|
|
|
void RepliesWidget::orderWidgets() {
|
|
|
|
if (_topBar) {
|
|
|
|
_topBar->raise();
|
|
|
|
}
|
|
|
|
if (_rootView) {
|
|
|
|
_rootView->raise();
|
|
|
|
}
|
|
|
|
_topBarShadow->raise();
|
|
|
|
_composeControls->raisePanels();
|
|
|
|
}
|
|
|
|
|
2020-09-08 11:19:44 +00:00
|
|
|
void RepliesWidget::sendReadTillRequest() {
|
2020-09-22 11:01:49 +00:00
|
|
|
if (!_root) {
|
2020-09-15 11:47:26 +00:00
|
|
|
_readRequestPending = true;
|
2020-09-08 11:19:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_readRequestTimer.isActive()) {
|
|
|
|
_readRequestTimer.cancel();
|
|
|
|
}
|
2020-09-15 11:47:26 +00:00
|
|
|
_readRequestPending = false;
|
2020-09-08 11:19:44 +00:00
|
|
|
const auto api = &_history->session().api();
|
|
|
|
api->request(base::take(_readRequestId)).cancel();
|
2021-08-30 15:37:09 +00:00
|
|
|
|
2020-09-08 11:19:44 +00:00
|
|
|
_readRequestId = api->request(MTPmessages_ReadDiscussion(
|
2020-09-22 11:01:49 +00:00
|
|
|
_root->history()->peer->input,
|
|
|
|
MTP_int(_root->id),
|
|
|
|
MTP_int(_root->computeRepliesInboxReadTillFull())
|
2021-08-30 15:37:09 +00:00
|
|
|
)).done(crl::guard(this, [=](const MTPBool &) {
|
|
|
|
_readRequestId = 0;
|
|
|
|
reloadUnreadCountIfNeeded();
|
|
|
|
})).send();
|
2020-09-08 11:19:44 +00:00
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
void RepliesWidget::setupRoot() {
|
2020-10-13 07:16:16 +00:00
|
|
|
if (!_root) {
|
2020-09-03 07:19:02 +00:00
|
|
|
const auto channel = _history->peer->asChannel();
|
|
|
|
const auto done = crl::guard(this, [=](ChannelData*, MsgId) {
|
|
|
|
_root = lookupRoot();
|
|
|
|
if (_root) {
|
|
|
|
_areComments = computeAreComments();
|
2021-08-30 15:37:09 +00:00
|
|
|
refreshUnreadCountBadge();
|
2020-09-22 11:01:49 +00:00
|
|
|
if (_readRequestPending) {
|
|
|
|
sendReadTillRequest();
|
|
|
|
}
|
2020-09-22 11:30:15 +00:00
|
|
|
_inner->update();
|
2020-09-03 07:19:02 +00:00
|
|
|
}
|
2020-09-15 18:19:06 +00:00
|
|
|
updatePinnedVisibility();
|
2020-09-03 07:19:02 +00:00
|
|
|
});
|
|
|
|
_history->session().api().requestMessageData(channel, _rootId, done);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-15 18:19:06 +00:00
|
|
|
void RepliesWidget::setupRootView() {
|
2020-10-13 07:16:16 +00:00
|
|
|
auto content = rpl::combine(
|
|
|
|
RootViewContent(_history, _rootId),
|
|
|
|
_rootVisible.value()
|
|
|
|
) | rpl::map([=](Ui::MessageBarContent &&content, bool shown) {
|
|
|
|
return shown ? std::move(content) : Ui::MessageBarContent();
|
|
|
|
});
|
|
|
|
_rootView = std::make_unique<Ui::PinnedBar>(this, std::move(content));
|
|
|
|
|
2021-05-26 21:04:18 +00:00
|
|
|
controller()->adaptive().oneColumnValue(
|
|
|
|
) | rpl::start_with_next([=](bool one) {
|
2020-10-13 07:16:16 +00:00
|
|
|
_rootView->setShadowGeometryPostprocess([=](QRect geometry) {
|
|
|
|
if (!one) {
|
|
|
|
geometry.setLeft(geometry.left() + st::lineWidth);
|
2020-09-21 16:56:22 +00:00
|
|
|
}
|
2020-10-13 07:16:16 +00:00
|
|
|
return geometry;
|
|
|
|
});
|
2020-09-15 18:19:06 +00:00
|
|
|
}, _rootView->lifetime());
|
|
|
|
|
2020-10-13 07:16:16 +00:00
|
|
|
_rootView->barClicks(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
showAtStart();
|
|
|
|
}, lifetime());
|
2020-09-15 18:19:06 +00:00
|
|
|
|
2020-09-21 17:07:52 +00:00
|
|
|
_rootViewHeight = 0;
|
|
|
|
_rootView->heightValue(
|
|
|
|
) | rpl::start_with_next([=](int height) {
|
|
|
|
if (const auto delta = height - _rootViewHeight) {
|
|
|
|
_rootViewHeight = height;
|
|
|
|
setGeometryWithTopMoved(geometry(), delta);
|
|
|
|
}
|
|
|
|
}, _rootView->lifetime());
|
2020-09-15 18:19:06 +00:00
|
|
|
}
|
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
HistoryItem *RepliesWidget::lookupRoot() const {
|
|
|
|
return _history->owner().message(_history->channelId(), _rootId);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::computeAreComments() const {
|
|
|
|
return _root && _root->isDiscussionPost();
|
|
|
|
}
|
|
|
|
|
2021-08-30 15:37:09 +00:00
|
|
|
std::optional<int> RepliesWidget::computeUnreadCount() const {
|
|
|
|
if (!_root) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
const auto views = _root->Get<HistoryMessageViews>();
|
|
|
|
if (!views) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
return (views->repliesUnreadCount >= 0)
|
|
|
|
? std::make_optional(views->repliesUnreadCount)
|
|
|
|
: std::nullopt;
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::setupComposeControls() {
|
2020-09-30 11:06:08 +00:00
|
|
|
auto slowmodeSecondsLeft = session().changes().peerFlagsValue(
|
|
|
|
_history->peer,
|
|
|
|
Data::PeerUpdate::Flag::Slowmode
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return _history->peer->slowmodeSecondsLeft();
|
|
|
|
}) | rpl::map([=](int delay) -> rpl::producer<int> {
|
|
|
|
auto start = rpl::single(delay);
|
|
|
|
if (!delay) {
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
return std::move(
|
|
|
|
start
|
|
|
|
) | rpl::then(base::timer_each(
|
|
|
|
kRefreshSlowmodeLabelTimeout
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return _history->peer->slowmodeSecondsLeft();
|
|
|
|
}) | rpl::take_while([=](int delay) {
|
|
|
|
return delay > 0;
|
|
|
|
})) | rpl::then(rpl::single(0));
|
|
|
|
}) | rpl::flatten_latest();
|
|
|
|
|
|
|
|
const auto channel = _history->peer->asChannel();
|
|
|
|
Assert(channel != nullptr);
|
|
|
|
|
|
|
|
auto hasSendingMessage = session().changes().historyFlagsValue(
|
|
|
|
_history,
|
|
|
|
Data::HistoryUpdate::Flag::LocalMessages
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return _history->latestSendingMessage() != nullptr;
|
|
|
|
}) | rpl::distinct_until_changed();
|
|
|
|
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
auto sendDisabledBySlowmode = (!channel || channel->amCreator())
|
|
|
|
? (rpl::single(false) | rpl::type_erased())
|
|
|
|
: rpl::combine(
|
|
|
|
channel->slowmodeAppliedValue(),
|
|
|
|
std::move(hasSendingMessage),
|
|
|
|
_1 && _2);
|
|
|
|
|
2020-09-30 15:38:58 +00:00
|
|
|
auto writeRestriction = session().changes().peerFlagsValue(
|
|
|
|
_history->peer,
|
|
|
|
Data::PeerUpdate::Flag::Rights
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return Data::RestrictionError(
|
|
|
|
_history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendMessages);
|
2020-09-30 15:38:58 +00:00
|
|
|
});
|
|
|
|
|
2020-09-30 11:06:08 +00:00
|
|
|
_composeControls->setHistory({
|
|
|
|
.history = _history.get(),
|
|
|
|
.showSlowmodeError = [=] { return showSlowmodeError(); },
|
|
|
|
.slowmodeSecondsLeft = std::move(slowmodeSecondsLeft),
|
|
|
|
.sendDisabledBySlowmode = std::move(sendDisabledBySlowmode),
|
2020-09-30 15:38:58 +00:00
|
|
|
.writeRestriction = std::move(writeRestriction),
|
2020-09-30 11:06:08 +00:00
|
|
|
});
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
_composeControls->height(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto wasMax = (_scroll->scrollTopMax() == _scroll->scrollTop());
|
|
|
|
updateControlsGeometry();
|
|
|
|
if (wasMax) {
|
|
|
|
listScrollTo(_scroll->scrollTopMax());
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_composeControls->cancelRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
listCancelRequest();
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_composeControls->sendRequests(
|
2020-11-16 16:01:37 +00:00
|
|
|
) | rpl::start_with_next([=](Api::SendOptions options) {
|
|
|
|
send(options);
|
2020-08-28 10:01:55 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2020-09-29 15:05:48 +00:00
|
|
|
_composeControls->sendVoiceRequests(
|
|
|
|
) | rpl::start_with_next([=](ComposeControls::VoiceToSend &&data) {
|
2020-11-16 16:01:37 +00:00
|
|
|
sendVoice(std::move(data));
|
2020-09-29 15:05:48 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2020-11-10 14:10:08 +00:00
|
|
|
_composeControls->sendCommandRequests(
|
|
|
|
) | rpl::start_with_next([=](const QString &command) {
|
|
|
|
if (showSlowmodeError()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-10 16:38:21 +00:00
|
|
|
listSendBotCommand(command, FullMsgId());
|
2020-11-10 14:10:08 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
const auto saveEditMsgRequestId = lifetime().make_state<mtpRequestId>(0);
|
|
|
|
_composeControls->editRequests(
|
|
|
|
) | rpl::start_with_next([=](auto data) {
|
|
|
|
if (const auto item = session().data().message(data.fullId)) {
|
|
|
|
edit(item, data.options, saveEditMsgRequestId);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_composeControls->attachRequests(
|
|
|
|
) | rpl::filter([=] {
|
|
|
|
return !_choosingAttach;
|
|
|
|
}) | rpl::start_with_next([=] {
|
|
|
|
_choosingAttach = true;
|
|
|
|
base::call_delayed(
|
|
|
|
st::historyAttach.ripple.hideDuration,
|
|
|
|
this,
|
|
|
|
[=] { _choosingAttach = false; chooseAttach(); });
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
using Selector = ChatHelpers::TabbedSelector;
|
|
|
|
|
|
|
|
_composeControls->fileChosen(
|
|
|
|
) | rpl::start_with_next([=](Selector::FileChosen chosen) {
|
2020-11-16 18:09:53 +00:00
|
|
|
sendExistingDocument(chosen.document, chosen.options);
|
2020-08-28 10:01:55 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_composeControls->photoChosen(
|
|
|
|
) | rpl::start_with_next([=](Selector::PhotoChosen chosen) {
|
2020-11-16 18:09:53 +00:00
|
|
|
sendExistingPhoto(chosen.photo, chosen.options);
|
2020-08-28 10:01:55 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_composeControls->inlineResultChosen(
|
|
|
|
) | rpl::start_with_next([=](Selector::InlineChosen chosen) {
|
2020-11-16 18:09:53 +00:00
|
|
|
sendInlineResult(chosen.result, chosen.bot, chosen.options);
|
2020-08-28 10:01:55 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_composeControls->scrollRequests(
|
|
|
|
) | rpl::start_with_next([=](Data::MessagePosition pos) {
|
|
|
|
showAtPosition(pos);
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-01-31 03:22:54 +00:00
|
|
|
_composeControls->scrollKeyEvents(
|
|
|
|
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
|
|
|
_scroll->keyPressEvent(e);
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-01-31 04:22:46 +00:00
|
|
|
_composeControls->editLastMessageRequests(
|
2020-08-28 10:01:55 +00:00
|
|
|
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
|
2021-01-31 04:22:46 +00:00
|
|
|
if (!_inner->lastMessageEditRequestNotify()) {
|
|
|
|
_scroll->keyPressEvent(e);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
2021-01-31 20:49:25 +00:00
|
|
|
_composeControls->replyNextRequests(
|
|
|
|
) | rpl::start_with_next([=](ComposeControls::ReplyNextRequest &&data) {
|
|
|
|
using Direction = ComposeControls::ReplyNextRequest::Direction;
|
|
|
|
_inner->replyNextMessage(
|
|
|
|
data.replyId,
|
|
|
|
data.direction == Direction::Next);
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
_composeControls->setMimeDataHook([=](
|
|
|
|
not_null<const QMimeData*> data,
|
|
|
|
Ui::InputField::MimeAction action) {
|
|
|
|
if (action == Ui::InputField::MimeAction::Check) {
|
|
|
|
return CanSendFiles(data);
|
|
|
|
} else if (action == Ui::InputField::MimeAction::Insert) {
|
2020-10-15 14:27:16 +00:00
|
|
|
return confirmSendingFiles(data, std::nullopt, data->text());
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
Unexpected("action in MimeData hook.");
|
|
|
|
});
|
2020-09-30 11:06:08 +00:00
|
|
|
|
2020-10-11 18:35:09 +00:00
|
|
|
_composeControls->lockShowStarts(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateScrollDownVisibility();
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-11-22 01:11:52 +00:00
|
|
|
_composeControls->viewportEvents(
|
|
|
|
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
|
|
|
_scroll->viewportEvent(e);
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-09-30 11:06:08 +00:00
|
|
|
_composeControls->finishAnimating();
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::chooseAttach() {
|
|
|
|
if (const auto error = Data::RestrictionError(
|
|
|
|
_history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendMedia)) {
|
2020-09-30 07:51:17 +00:00
|
|
|
Ui::ShowMultilineToast({
|
|
|
|
.text = { *error },
|
|
|
|
});
|
2020-08-28 10:01:55 +00:00
|
|
|
return;
|
2020-09-30 11:06:08 +00:00
|
|
|
} else if (showSlowmodeError()) {
|
|
|
|
return;
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 10:00:35 +00:00
|
|
|
const auto filter = FileDialog::AllOrImagesFilter();
|
2020-08-28 10:01:55 +00:00
|
|
|
FileDialog::GetOpenPaths(this, tr::lng_choose_files(tr::now), filter, crl::guard(this, [=](
|
|
|
|
FileDialog::OpenResult &&result) {
|
|
|
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.remoteContent.isEmpty()) {
|
2021-08-11 15:40:17 +00:00
|
|
|
auto read = Images::Read({
|
|
|
|
.content = result.remoteContent,
|
|
|
|
});
|
|
|
|
if (!read.image.isNull() && !read.animated) {
|
2020-08-28 10:01:55 +00:00
|
|
|
confirmSendingFiles(
|
2021-08-11 15:40:17 +00:00
|
|
|
std::move(read.image),
|
2020-10-15 14:27:16 +00:00
|
|
|
std::move(result.remoteContent));
|
2020-08-28 10:01:55 +00:00
|
|
|
} else {
|
|
|
|
uploadFile(result.remoteContent, SendMediaType::File);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
auto list = Storage::PrepareMediaList(
|
|
|
|
result.paths,
|
|
|
|
st::sendMediaPreviewSize);
|
2020-10-15 14:27:16 +00:00
|
|
|
confirmSendingFiles(std::move(list));
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
}), nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::confirmSendingFiles(
|
|
|
|
not_null<const QMimeData*> data,
|
2020-10-15 14:27:16 +00:00
|
|
|
std::optional<bool> overrideSendImagesAsPhotos,
|
2020-08-28 10:01:55 +00:00
|
|
|
const QString &insertTextOnCancel) {
|
|
|
|
const auto hasImage = data->hasImage();
|
|
|
|
|
|
|
|
if (const auto urls = data->urls(); !urls.empty()) {
|
|
|
|
auto list = Storage::PrepareMediaList(
|
|
|
|
urls,
|
|
|
|
st::sendMediaPreviewSize);
|
2020-10-13 12:07:53 +00:00
|
|
|
if (list.error != Ui::PreparedList::Error::NonLocalUrl) {
|
|
|
|
if (list.error == Ui::PreparedList::Error::None
|
2020-08-28 10:01:55 +00:00
|
|
|
|| !hasImage) {
|
|
|
|
const auto emptyTextOnCancel = QString();
|
2020-10-15 14:27:16 +00:00
|
|
|
list.overrideSendImagesAsPhotos = overrideSendImagesAsPhotos;
|
|
|
|
confirmSendingFiles(std::move(list), emptyTextOnCancel);
|
2020-08-28 10:01:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasImage) {
|
2021-08-10 13:15:05 +00:00
|
|
|
auto image = qvariant_cast<QImage>(data->imageData());
|
2020-08-28 10:01:55 +00:00
|
|
|
if (!image.isNull()) {
|
|
|
|
confirmSendingFiles(
|
|
|
|
std::move(image),
|
|
|
|
QByteArray(),
|
2020-10-15 14:27:16 +00:00
|
|
|
overrideSendImagesAsPhotos,
|
2020-08-28 10:01:55 +00:00
|
|
|
insertTextOnCancel);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::confirmSendingFiles(
|
2020-10-13 12:07:53 +00:00
|
|
|
Ui::PreparedList &&list,
|
2020-08-28 10:01:55 +00:00
|
|
|
const QString &insertTextOnCancel) {
|
|
|
|
if (showSendingFilesError(list)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
using SendLimit = SendFilesBox::SendLimit;
|
|
|
|
auto box = Box<SendFilesBox>(
|
|
|
|
controller(),
|
|
|
|
std::move(list),
|
2021-02-11 18:58:25 +00:00
|
|
|
_composeControls->getTextWithAppliedMarkdown(),
|
2020-08-28 10:01:55 +00:00
|
|
|
_history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many,
|
2020-08-28 15:54:59 +00:00
|
|
|
Api::SendType::Normal,
|
2020-11-20 17:04:50 +00:00
|
|
|
SendMenu::Type::SilentOnly); // #TODO replies schedule
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
box->setConfirmedCallback(crl::guard(this, [=](
|
2020-10-13 12:07:53 +00:00
|
|
|
Ui::PreparedList &&list,
|
2020-10-13 15:11:53 +00:00
|
|
|
Ui::SendFilesWay way,
|
2020-08-28 10:01:55 +00:00
|
|
|
TextWithTags &&caption,
|
|
|
|
Api::SendOptions options,
|
|
|
|
bool ctrlShiftEnter) {
|
2020-10-17 09:51:55 +00:00
|
|
|
sendingFilesConfirmed(
|
2020-08-28 10:01:55 +00:00
|
|
|
std::move(list),
|
2020-10-17 09:51:55 +00:00
|
|
|
way,
|
2020-08-28 10:01:55 +00:00
|
|
|
std::move(caption),
|
|
|
|
options,
|
2020-10-17 09:51:55 +00:00
|
|
|
ctrlShiftEnter);
|
2020-09-01 13:10:10 +00:00
|
|
|
}));
|
2021-02-11 18:58:25 +00:00
|
|
|
box->setCancelledCallback(_composeControls->restoreTextCallback(
|
|
|
|
insertTextOnCancel));
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
//ActivateWindow(controller());
|
2021-06-13 07:37:52 +00:00
|
|
|
const auto shown = controller()->show(std::move(box));
|
2020-08-28 10:01:55 +00:00
|
|
|
shown->setCloseByOutsideClick(false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-17 09:51:55 +00:00
|
|
|
void RepliesWidget::sendingFilesConfirmed(
|
|
|
|
Ui::PreparedList &&list,
|
|
|
|
Ui::SendFilesWay way,
|
|
|
|
TextWithTags &&caption,
|
|
|
|
Api::SendOptions options,
|
|
|
|
bool ctrlShiftEnter) {
|
|
|
|
Expects(list.filesToProcess.empty());
|
|
|
|
|
|
|
|
if (showSendingFilesError(list)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto groups = DivideByGroups(
|
|
|
|
std::move(list),
|
|
|
|
way,
|
|
|
|
_history->peer->slowmodeApplied());
|
|
|
|
const auto replyTo = replyToId();
|
|
|
|
const auto type = way.sendImagesAsPhotos()
|
|
|
|
? SendMediaType::Photo
|
|
|
|
: SendMediaType::File;
|
|
|
|
auto action = Api::SendAction(_history);
|
|
|
|
action.replyTo = replyTo ? replyTo : _rootId;
|
|
|
|
action.options = options;
|
|
|
|
action.clearDraft = false;
|
2020-10-20 08:19:48 +00:00
|
|
|
if ((groups.size() != 1 || !groups.front().sentWithCaption())
|
|
|
|
&& !caption.text.isEmpty()) {
|
2020-10-17 09:51:55 +00:00
|
|
|
auto message = Api::MessageToSend(_history);
|
|
|
|
message.textWithTags = base::take(caption);
|
|
|
|
message.action = action;
|
|
|
|
session().api().sendMessage(std::move(message));
|
|
|
|
}
|
|
|
|
for (auto &group : groups) {
|
2020-10-20 08:19:48 +00:00
|
|
|
const auto album = (group.type != Ui::AlbumType::None)
|
2020-10-17 09:51:55 +00:00
|
|
|
? std::make_shared<SendingAlbum>()
|
|
|
|
: nullptr;
|
|
|
|
session().api().sendFiles(
|
|
|
|
std::move(group.list),
|
|
|
|
type,
|
|
|
|
base::take(caption),
|
|
|
|
album,
|
|
|
|
action);
|
2020-10-22 13:09:00 +00:00
|
|
|
}
|
2020-10-17 09:51:55 +00:00
|
|
|
if (_composeControls->replyingToMessage().msg == replyTo) {
|
|
|
|
_composeControls->cancelReplyMessage();
|
2020-11-11 20:47:40 +00:00
|
|
|
refreshTopBarActiveChat();
|
2020-10-17 09:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
bool RepliesWidget::confirmSendingFiles(
|
|
|
|
QImage &&image,
|
|
|
|
QByteArray &&content,
|
2020-10-15 14:27:16 +00:00
|
|
|
std::optional<bool> overrideSendImagesAsPhotos,
|
2020-08-28 10:01:55 +00:00
|
|
|
const QString &insertTextOnCancel) {
|
|
|
|
if (image.isNull()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto list = Storage::PrepareMediaFromImage(
|
|
|
|
std::move(image),
|
|
|
|
std::move(content),
|
|
|
|
st::sendMediaPreviewSize);
|
2020-10-15 14:27:16 +00:00
|
|
|
list.overrideSendImagesAsPhotos = overrideSendImagesAsPhotos;
|
|
|
|
return confirmSendingFiles(std::move(list), insertTextOnCancel);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 11:06:08 +00:00
|
|
|
bool RepliesWidget::showSlowmodeError() {
|
|
|
|
const auto text = [&] {
|
|
|
|
if (const auto left = _history->peer->slowmodeSecondsLeft()) {
|
|
|
|
return tr::lng_slowmode_enabled(
|
|
|
|
tr::now,
|
|
|
|
lt_left,
|
|
|
|
Ui::FormatDurationWords(left));
|
|
|
|
} else if (_history->peer->slowmodeApplied()) {
|
|
|
|
if (const auto item = _history->latestSendingMessage()) {
|
|
|
|
showAtPositionNow(item->position(), nullptr);
|
|
|
|
return tr::lng_slowmode_no_many(tr::now);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}();
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Ui::ShowMultilineToast({
|
|
|
|
.text = { text },
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:38:58 +00:00
|
|
|
std::optional<QString> RepliesWidget::writeRestriction() const {
|
|
|
|
return Data::RestrictionError(
|
|
|
|
_history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendMessages);
|
2020-09-30 15:38:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 13:41:24 +00:00
|
|
|
void RepliesWidget::pushReplyReturn(not_null<HistoryItem*> item) {
|
|
|
|
if (item->history() == _history && item->replyToTop() == _rootId) {
|
|
|
|
_replyReturns.push_back(item->id);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_replyReturn = item;
|
|
|
|
updateScrollDownVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::restoreReplyReturns(const std::vector<MsgId> &list) {
|
|
|
|
_replyReturns = list;
|
|
|
|
computeCurrentReplyReturn();
|
|
|
|
if (!_replyReturn) {
|
|
|
|
calculateNextReplyReturn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::computeCurrentReplyReturn() {
|
|
|
|
_replyReturn = _replyReturns.empty()
|
|
|
|
? nullptr
|
|
|
|
: _history->owner().message(
|
|
|
|
_history->channelId(),
|
|
|
|
_replyReturns.back());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::calculateNextReplyReturn() {
|
|
|
|
_replyReturn = nullptr;
|
|
|
|
while (!_replyReturns.empty() && !_replyReturn) {
|
|
|
|
_replyReturns.pop_back();
|
|
|
|
computeCurrentReplyReturn();
|
|
|
|
}
|
|
|
|
if (!_replyReturn) {
|
|
|
|
updateScrollDownVisibility();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::checkReplyReturns() {
|
|
|
|
const auto currentTop = _scroll->scrollTop();
|
|
|
|
for (; _replyReturn != nullptr; calculateNextReplyReturn()) {
|
|
|
|
const auto position = _replyReturn->position();
|
|
|
|
const auto scrollTop = _inner->scrollTopForPosition(position);
|
|
|
|
const auto scrolledBelow = scrollTop
|
|
|
|
? (currentTop >= std::min(*scrollTop, _scroll->scrollTopMax()))
|
|
|
|
: _inner->isBelowPosition(position);
|
|
|
|
if (!scrolledBelow) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::uploadFile(
|
|
|
|
const QByteArray &fileContent,
|
|
|
|
SendMediaType type) {
|
2020-08-28 15:54:59 +00:00
|
|
|
// #TODO replies schedule
|
|
|
|
auto action = Api::SendAction(_history);
|
2020-09-01 06:07:37 +00:00
|
|
|
action.replyTo = replyToId();
|
2020-08-28 15:54:59 +00:00
|
|
|
session().api().sendFile(fileContent, type, action);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::showSendingFilesError(
|
2020-10-13 12:07:53 +00:00
|
|
|
const Ui::PreparedList &list) const {
|
2020-08-28 10:01:55 +00:00
|
|
|
const auto text = [&] {
|
2020-10-16 07:52:55 +00:00
|
|
|
const auto peer = _history->peer;
|
2020-08-28 10:01:55 +00:00
|
|
|
const auto error = Data::RestrictionError(
|
2020-10-16 07:52:55 +00:00
|
|
|
peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendMedia);
|
2020-08-28 10:01:55 +00:00
|
|
|
if (error) {
|
|
|
|
return *error;
|
|
|
|
}
|
2020-10-16 07:52:55 +00:00
|
|
|
if (peer->slowmodeApplied() && !list.canBeSentInSlowmode()) {
|
2020-09-30 11:06:08 +00:00
|
|
|
return tr::lng_slowmode_no_many(tr::now);
|
|
|
|
} else if (const auto left = _history->peer->slowmodeSecondsLeft()) {
|
|
|
|
return tr::lng_slowmode_enabled(
|
|
|
|
tr::now,
|
|
|
|
lt_left,
|
|
|
|
Ui::FormatDurationWords(left));
|
|
|
|
}
|
2020-10-13 12:07:53 +00:00
|
|
|
using Error = Ui::PreparedList::Error;
|
2020-08-28 10:01:55 +00:00
|
|
|
switch (list.error) {
|
|
|
|
case Error::None: return QString();
|
|
|
|
case Error::EmptyFile:
|
|
|
|
case Error::Directory:
|
|
|
|
case Error::NonLocalUrl: return tr::lng_send_image_empty(
|
|
|
|
tr::now,
|
|
|
|
lt_name,
|
|
|
|
list.errorData);
|
|
|
|
case Error::TooLargeFile: return tr::lng_send_image_too_large(
|
|
|
|
tr::now,
|
|
|
|
lt_name,
|
|
|
|
list.errorData);
|
|
|
|
}
|
|
|
|
return tr::lng_forward_send_files_cant(tr::now);
|
|
|
|
}();
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-30 07:51:17 +00:00
|
|
|
Ui::ShowMultilineToast({
|
|
|
|
.text = { text },
|
|
|
|
});
|
2020-08-28 10:01:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::send() {
|
|
|
|
if (_composeControls->getTextWithAppliedMarkdown().text.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-28 15:54:59 +00:00
|
|
|
send(Api::SendOptions());
|
|
|
|
// #TODO replies schedule
|
|
|
|
//const auto callback = [=](Api::SendOptions options) { send(options); };
|
|
|
|
//Ui::show(
|
|
|
|
// PrepareScheduleBox(this, sendMenuType(), callback),
|
|
|
|
// Ui::LayerOption::KeepOther);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 16:01:37 +00:00
|
|
|
void RepliesWidget::sendVoice(ComposeControls::VoiceToSend &&data) {
|
2020-09-29 15:05:48 +00:00
|
|
|
auto action = Api::SendAction(_history);
|
|
|
|
action.replyTo = replyToId();
|
2020-11-16 16:01:37 +00:00
|
|
|
action.options = data.options;
|
|
|
|
session().api().sendVoiceMessage(
|
|
|
|
data.bytes,
|
|
|
|
data.waveform,
|
|
|
|
data.duration,
|
|
|
|
std::move(action));
|
2020-11-19 02:15:42 +00:00
|
|
|
|
|
|
|
_composeControls->cancelReplyMessage();
|
2020-11-19 15:11:09 +00:00
|
|
|
_composeControls->clearListenState();
|
2020-11-19 02:15:42 +00:00
|
|
|
finishSending();
|
2020-09-29 15:05:48 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::send(Api::SendOptions options) {
|
2020-09-30 11:06:08 +00:00
|
|
|
if (!options.scheduled && showSlowmodeError()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-29 11:27:17 +00:00
|
|
|
const auto webPageId = _composeControls->webPageId();
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
auto message = ApiWrap::MessageToSend(_history);
|
|
|
|
message.textWithTags = _composeControls->getTextWithAppliedMarkdown();
|
|
|
|
message.action.options = options;
|
2020-09-01 06:07:37 +00:00
|
|
|
message.action.replyTo = replyToId();
|
2020-08-28 10:01:55 +00:00
|
|
|
message.webPageId = webPageId;
|
|
|
|
|
|
|
|
//const auto error = GetErrorTextForSending(
|
|
|
|
// _peer,
|
|
|
|
// _toForward,
|
|
|
|
// message.textWithTags);
|
|
|
|
//if (!error.isEmpty()) {
|
2020-09-30 07:51:17 +00:00
|
|
|
// Ui::ShowMultilineToast({
|
|
|
|
// .text = { error },
|
|
|
|
// });
|
2020-08-28 10:01:55 +00:00
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
|
|
|
|
session().api().sendMessage(std::move(message));
|
|
|
|
|
|
|
|
_composeControls->clear();
|
2020-09-29 08:36:30 +00:00
|
|
|
session().sendProgressManager().update(
|
|
|
|
_history,
|
|
|
|
_rootId,
|
|
|
|
Api::SendProgressType::Typing,
|
|
|
|
-1);
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
//_saveDraftText = true;
|
|
|
|
//_saveDraftStart = crl::now();
|
|
|
|
//onDraftSave();
|
|
|
|
|
2020-09-11 11:24:57 +00:00
|
|
|
finishSending();
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::edit(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
Api::SendOptions options,
|
|
|
|
mtpRequestId *const saveEditMsgRequestId) {
|
|
|
|
if (*saveEditMsgRequestId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto textWithTags = _composeControls->getTextWithAppliedMarkdown();
|
|
|
|
const auto prepareFlags = Ui::ItemTextOptions(
|
|
|
|
_history,
|
|
|
|
session().user()).flags;
|
|
|
|
auto sending = TextWithEntities();
|
|
|
|
auto left = TextWithEntities {
|
|
|
|
textWithTags.text,
|
|
|
|
TextUtilities::ConvertTextTagsToEntities(textWithTags.tags) };
|
|
|
|
TextUtilities::PrepareForSending(left, prepareFlags);
|
|
|
|
|
|
|
|
if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) {
|
|
|
|
if (item) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller()->show(Box<DeleteMessagesBox>(item, false));
|
2020-08-28 10:01:55 +00:00
|
|
|
} else {
|
2020-09-29 15:05:48 +00:00
|
|
|
doSetInnerFocus();
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (!left.text.isEmpty()) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller()->show(Box<InformBox>(tr::lng_edit_too_long(tr::now)));
|
2020-08-28 10:01:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lifetime().add([=] {
|
|
|
|
if (!*saveEditMsgRequestId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
session().api().request(base::take(*saveEditMsgRequestId)).cancel();
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto done = [=](const MTPUpdates &result, mtpRequestId requestId) {
|
|
|
|
if (requestId == *saveEditMsgRequestId) {
|
|
|
|
*saveEditMsgRequestId = 0;
|
|
|
|
_composeControls->cancelEditMessage();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
const auto fail = [=](const MTP::Error &error, mtpRequestId requestId) {
|
2020-08-28 10:01:55 +00:00
|
|
|
if (requestId == *saveEditMsgRequestId) {
|
|
|
|
*saveEditMsgRequestId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &err = error.type();
|
|
|
|
if (ranges::contains(Api::kDefaultEditMessagesErrors, err)) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller()->show(Box<InformBox>(tr::lng_edit_error(tr::now)));
|
2020-08-28 10:01:55 +00:00
|
|
|
} else if (err == u"MESSAGE_NOT_MODIFIED"_q) {
|
|
|
|
_composeControls->cancelEditMessage();
|
|
|
|
} else if (err == u"MESSAGE_EMPTY"_q) {
|
2020-09-29 15:05:48 +00:00
|
|
|
doSetInnerFocus();
|
2020-08-28 10:01:55 +00:00
|
|
|
} else {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller()->show(Box<InformBox>(tr::lng_edit_error(tr::now)));
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
*saveEditMsgRequestId = Api::EditTextMessage(
|
|
|
|
item,
|
|
|
|
sending,
|
|
|
|
options,
|
|
|
|
crl::guard(this, done),
|
|
|
|
crl::guard(this, fail));
|
|
|
|
|
|
|
|
_composeControls->hidePanelsAnimated();
|
2020-09-29 15:05:48 +00:00
|
|
|
doSetInnerFocus();
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::sendExistingDocument(
|
|
|
|
not_null<DocumentData*> document) {
|
2020-08-28 15:54:59 +00:00
|
|
|
sendExistingDocument(document, Api::SendOptions());
|
|
|
|
// #TODO replies schedule
|
|
|
|
//const auto callback = [=](Api::SendOptions options) {
|
|
|
|
// sendExistingDocument(document, options);
|
|
|
|
//};
|
|
|
|
//Ui::show(
|
|
|
|
// PrepareScheduleBox(this, sendMenuType(), callback),
|
|
|
|
// Ui::LayerOption::KeepOther);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::sendExistingDocument(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
Api::SendOptions options) {
|
|
|
|
const auto error = Data::RestrictionError(
|
|
|
|
_history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendStickers);
|
2020-08-28 10:01:55 +00:00
|
|
|
if (error) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller()->show(
|
|
|
|
Box<InformBox>(*error),
|
|
|
|
Ui::LayerOption::KeepOther);
|
2020-08-28 10:01:55 +00:00
|
|
|
return false;
|
2020-09-30 11:06:08 +00:00
|
|
|
} else if (showSlowmodeError()) {
|
|
|
|
return false;
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto message = Api::MessageToSend(_history);
|
2020-09-01 06:07:37 +00:00
|
|
|
message.action.replyTo = replyToId();
|
2020-08-28 10:01:55 +00:00
|
|
|
message.action.options = options;
|
|
|
|
Api::SendExistingDocument(std::move(message), document);
|
|
|
|
|
2020-09-01 06:07:37 +00:00
|
|
|
_composeControls->cancelReplyMessage();
|
2020-09-11 11:24:57 +00:00
|
|
|
finishSending();
|
2020-08-28 10:01:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::sendExistingPhoto(not_null<PhotoData*> photo) {
|
2020-08-28 15:54:59 +00:00
|
|
|
sendExistingPhoto(photo, Api::SendOptions());
|
|
|
|
// #TODO replies schedule
|
|
|
|
//const auto callback = [=](Api::SendOptions options) {
|
|
|
|
// sendExistingPhoto(photo, options);
|
|
|
|
//};
|
|
|
|
//Ui::show(
|
|
|
|
// PrepareScheduleBox(this, sendMenuType(), callback),
|
|
|
|
// Ui::LayerOption::KeepOther);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::sendExistingPhoto(
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
Api::SendOptions options) {
|
|
|
|
const auto error = Data::RestrictionError(
|
|
|
|
_history->peer,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestriction::SendMedia);
|
2020-08-28 10:01:55 +00:00
|
|
|
if (error) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller()->show(
|
|
|
|
Box<InformBox>(*error),
|
|
|
|
Ui::LayerOption::KeepOther);
|
2020-08-28 10:01:55 +00:00
|
|
|
return false;
|
2020-09-30 11:06:08 +00:00
|
|
|
} else if (showSlowmodeError()) {
|
|
|
|
return false;
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto message = Api::MessageToSend(_history);
|
2020-09-01 06:07:37 +00:00
|
|
|
message.action.replyTo = replyToId();
|
2020-08-28 10:01:55 +00:00
|
|
|
message.action.options = options;
|
|
|
|
Api::SendExistingPhoto(std::move(message), photo);
|
|
|
|
|
2020-09-01 06:07:37 +00:00
|
|
|
_composeControls->cancelReplyMessage();
|
2020-09-11 11:24:57 +00:00
|
|
|
finishSending();
|
2020-08-28 10:01:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::sendInlineResult(
|
|
|
|
not_null<InlineBots::Result*> result,
|
|
|
|
not_null<UserData*> bot) {
|
|
|
|
const auto errorText = result->getErrorOnSend(_history);
|
|
|
|
if (!errorText.isEmpty()) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller()->show(Box<InformBox>(errorText));
|
2020-08-28 10:01:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-28 15:54:59 +00:00
|
|
|
sendInlineResult(result, bot, Api::SendOptions());
|
|
|
|
//const auto callback = [=](Api::SendOptions options) {
|
|
|
|
// sendInlineResult(result, bot, options);
|
|
|
|
//};
|
|
|
|
//Ui::show(
|
|
|
|
// PrepareScheduleBox(this, sendMenuType(), callback),
|
|
|
|
// Ui::LayerOption::KeepOther);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::sendInlineResult(
|
|
|
|
not_null<InlineBots::Result*> result,
|
|
|
|
not_null<UserData*> bot,
|
|
|
|
Api::SendOptions options) {
|
|
|
|
auto action = Api::SendAction(_history);
|
2020-09-01 06:07:37 +00:00
|
|
|
action.replyTo = replyToId();
|
2020-08-28 10:01:55 +00:00
|
|
|
action.options = options;
|
|
|
|
action.generateLocal = true;
|
|
|
|
session().api().sendInlineResult(bot, result, action);
|
|
|
|
|
|
|
|
_composeControls->clear();
|
|
|
|
//_saveDraftText = true;
|
|
|
|
//_saveDraftStart = crl::now();
|
|
|
|
//onDraftSave();
|
|
|
|
|
|
|
|
auto &bots = cRefRecentInlineBots();
|
|
|
|
const auto index = bots.indexOf(bot);
|
|
|
|
if (index) {
|
|
|
|
if (index > 0) {
|
|
|
|
bots.removeAt(index);
|
|
|
|
} else if (bots.size() >= RecentInlineBotsLimit) {
|
|
|
|
bots.resize(RecentInlineBotsLimit - 1);
|
|
|
|
}
|
|
|
|
bots.push_front(bot);
|
|
|
|
bot->session().local().writeRecentHashtagsAndBots();
|
|
|
|
}
|
2020-09-11 11:24:57 +00:00
|
|
|
finishSending();
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SendMenu::Type RepliesWidget::sendMenuType() const {
|
2020-08-28 15:54:59 +00:00
|
|
|
// #TODO replies schedule
|
2020-08-28 10:01:55 +00:00
|
|
|
return _history->peer->isSelf()
|
|
|
|
? SendMenu::Type::Reminder
|
|
|
|
: HistoryView::CanScheduleUntilOnline(_history->peer)
|
|
|
|
? SendMenu::Type::ScheduledToUser
|
|
|
|
: SendMenu::Type::Scheduled;
|
|
|
|
}
|
|
|
|
|
2020-11-11 20:47:40 +00:00
|
|
|
void RepliesWidget::refreshTopBarActiveChat() {
|
2020-11-12 15:46:17 +00:00
|
|
|
const auto state = Dialogs::EntryState{
|
|
|
|
.key = _history,
|
|
|
|
.section = Dialogs::EntryState::Section::Replies,
|
|
|
|
.rootId = _rootId,
|
2020-11-13 17:27:08 +00:00
|
|
|
.currentReplyToId = _composeControls->replyingToMessage().msg,
|
2020-11-12 15:46:17 +00:00
|
|
|
};
|
|
|
|
_topBar->setActiveChat(state, _sendAction.get());
|
|
|
|
_composeControls->setCurrentDialogsEntryState(state);
|
2020-11-11 20:47:40 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 06:07:37 +00:00
|
|
|
MsgId RepliesWidget::replyToId() const {
|
|
|
|
const auto custom = _composeControls->replyingToMessage().msg;
|
|
|
|
return custom ? custom : _rootId;
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::setupScrollDownButton() {
|
|
|
|
_scrollDown->setClickedCallback([=] {
|
|
|
|
scrollDownClicked();
|
|
|
|
});
|
2021-08-30 15:37:09 +00:00
|
|
|
refreshUnreadCountBadge();
|
2020-08-28 10:01:55 +00:00
|
|
|
base::install_event_filter(_scrollDown, [=](not_null<QEvent*> event) {
|
|
|
|
if (event->type() != QEvent::Wheel) {
|
|
|
|
return base::EventFilterResult::Continue;
|
|
|
|
}
|
|
|
|
return _scroll->viewportEvent(event)
|
|
|
|
? base::EventFilterResult::Cancel
|
|
|
|
: base::EventFilterResult::Continue;
|
|
|
|
});
|
|
|
|
updateScrollDownVisibility();
|
|
|
|
}
|
|
|
|
|
2021-08-30 15:37:09 +00:00
|
|
|
void RepliesWidget::refreshUnreadCountBadge() {
|
|
|
|
if (!_root) {
|
|
|
|
return;
|
|
|
|
} else if (const auto count = computeUnreadCount()) {
|
|
|
|
_scrollDown->setUnreadCount(*count);
|
|
|
|
} else if (!_readRequestPending
|
|
|
|
&& !_readRequestTimer.isActive()
|
|
|
|
&& !_readRequestId) {
|
|
|
|
reloadUnreadCountIfNeeded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::reloadUnreadCountIfNeeded() {
|
|
|
|
const auto views = _root ? _root->Get<HistoryMessageViews>() : nullptr;
|
|
|
|
if (!views || views->repliesUnreadCount >= 0) {
|
|
|
|
return;
|
|
|
|
} else if (views->repliesInboxReadTillId
|
|
|
|
< _root->computeRepliesInboxReadTillFull()) {
|
|
|
|
_readRequestTimer.callOnce(0);
|
|
|
|
} else if (!_reloadUnreadCountRequestId) {
|
|
|
|
const auto session = &_history->session();
|
|
|
|
const auto fullId = _root->fullId();
|
|
|
|
const auto apply = [session, fullId](int readTill, int unreadCount) {
|
|
|
|
if (const auto root = session->data().message(fullId)) {
|
|
|
|
root->setRepliesInboxReadTill(readTill, unreadCount);
|
|
|
|
if (const auto post = root->lookupDiscussionPostOriginal()) {
|
|
|
|
post->setRepliesInboxReadTill(readTill, unreadCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const auto weak = Ui::MakeWeak(this);
|
|
|
|
_reloadUnreadCountRequestId = session->api().request(
|
|
|
|
MTPmessages_GetDiscussionMessage(
|
|
|
|
_history->peer->input,
|
|
|
|
MTP_int(_rootId))
|
|
|
|
).done([=](const MTPmessages_DiscussionMessage &result) {
|
|
|
|
if (weak) {
|
|
|
|
_reloadUnreadCountRequestId = 0;
|
|
|
|
}
|
|
|
|
result.match([&](const MTPDmessages_discussionMessage &data) {
|
|
|
|
session->data().processUsers(data.vusers());
|
|
|
|
session->data().processChats(data.vchats());
|
|
|
|
apply(
|
|
|
|
data.vread_inbox_max_id().value_or_empty(),
|
|
|
|
data.vunread_count().v);
|
|
|
|
});
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::scrollDownClicked() {
|
2020-08-31 13:41:24 +00:00
|
|
|
if (QGuiApplication::keyboardModifiers() == Qt::ControlModifier) {
|
2020-09-11 11:24:57 +00:00
|
|
|
showAtEnd();
|
2020-08-31 13:41:24 +00:00
|
|
|
} else if (_replyReturn) {
|
|
|
|
showAtPosition(_replyReturn->position());
|
|
|
|
} else {
|
2020-09-11 11:24:57 +00:00
|
|
|
showAtEnd();
|
2020-08-31 13:41:24 +00:00
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 16:56:22 +00:00
|
|
|
void RepliesWidget::showAtStart() {
|
|
|
|
showAtPosition(Data::MinMessagePosition);
|
|
|
|
}
|
|
|
|
|
2020-09-11 11:24:57 +00:00
|
|
|
void RepliesWidget::showAtEnd() {
|
|
|
|
showAtPosition(Data::MaxMessagePosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::finishSending() {
|
|
|
|
_composeControls->hidePanelsAnimated();
|
|
|
|
//if (_previewData && _previewData->pendingTill) previewCancel();
|
2020-09-29 15:05:48 +00:00
|
|
|
doSetInnerFocus();
|
2020-09-11 11:24:57 +00:00
|
|
|
showAtEnd();
|
2020-11-11 20:47:40 +00:00
|
|
|
refreshTopBarActiveChat();
|
2020-09-11 11:24:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-31 13:41:24 +00:00
|
|
|
void RepliesWidget::showAtPosition(
|
|
|
|
Data::MessagePosition position,
|
|
|
|
HistoryItem *originItem) {
|
|
|
|
if (!showAtPositionNow(position, originItem)) {
|
2020-08-31 12:14:32 +00:00
|
|
|
_inner->showAroundPosition(position, [=] {
|
2020-08-31 13:41:24 +00:00
|
|
|
return showAtPositionNow(position, originItem);
|
2020-08-31 12:14:32 +00:00
|
|
|
});
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-31 13:41:24 +00:00
|
|
|
bool RepliesWidget::showAtPositionNow(
|
|
|
|
Data::MessagePosition position,
|
2020-10-21 12:31:15 +00:00
|
|
|
HistoryItem *originItem,
|
|
|
|
anim::type animated) {
|
|
|
|
using AnimatedScroll = HistoryView::ListWidget::AnimatedScroll;
|
2020-09-17 17:57:06 +00:00
|
|
|
const auto item = position.fullId
|
|
|
|
? _history->owner().message(position.fullId)
|
|
|
|
: nullptr;
|
|
|
|
const auto use = item ? item->position() : position;
|
|
|
|
if (const auto scrollTop = _inner->scrollTopForPosition(use)) {
|
|
|
|
while (_replyReturn && use.fullId.msg == _replyReturn->id) {
|
2020-08-31 13:41:24 +00:00
|
|
|
calculateNextReplyReturn();
|
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
const auto currentScrollTop = _scroll->scrollTop();
|
2021-01-23 03:29:50 +00:00
|
|
|
const auto wanted = std::clamp(
|
|
|
|
*scrollTop,
|
|
|
|
0,
|
|
|
|
_scroll->scrollTopMax());
|
2020-08-28 10:01:55 +00:00
|
|
|
const auto fullDelta = (wanted - currentScrollTop);
|
|
|
|
const auto limit = _scroll->height();
|
2021-01-23 03:29:50 +00:00
|
|
|
const auto scrollDelta = std::clamp(fullDelta, -limit, limit);
|
2020-10-21 12:31:15 +00:00
|
|
|
const auto type = (animated == anim::type::instant)
|
|
|
|
? AnimatedScroll::None
|
|
|
|
: (std::abs(fullDelta) > limit)
|
|
|
|
? AnimatedScroll::Part
|
|
|
|
: AnimatedScroll::Full;
|
|
|
|
_inner->scrollTo(
|
2020-08-28 10:01:55 +00:00
|
|
|
wanted,
|
2020-09-17 17:57:06 +00:00
|
|
|
use,
|
2020-08-28 10:01:55 +00:00
|
|
|
scrollDelta,
|
2020-10-21 12:31:15 +00:00
|
|
|
type);
|
2020-09-17 17:57:06 +00:00
|
|
|
if (use != Data::MaxMessagePosition
|
|
|
|
&& use != Data::UnreadMessagePosition) {
|
|
|
|
_inner->highlightMessage(use.fullId);
|
2020-08-31 13:41:24 +00:00
|
|
|
}
|
|
|
|
if (originItem) {
|
|
|
|
pushReplyReturn(originItem);
|
2020-08-31 12:14:32 +00:00
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::updateScrollDownVisibility() {
|
|
|
|
if (animating()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto scrollDownIsVisible = [&]() -> std::optional<bool> {
|
2020-10-11 18:35:09 +00:00
|
|
|
if (_composeControls->isLockPresent()) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
const auto top = _scroll->scrollTop() + st::historyToDownShownAfter;
|
2020-08-31 13:41:24 +00:00
|
|
|
if (top < _scroll->scrollTopMax() || _replyReturn) {
|
2020-08-28 10:01:55 +00:00
|
|
|
return true;
|
2020-08-31 13:41:24 +00:00
|
|
|
} else if (_inner->loadedAtBottomKnown()) {
|
2020-08-28 10:01:55 +00:00
|
|
|
return !_inner->loadedAtBottom();
|
|
|
|
}
|
|
|
|
return std::nullopt;
|
|
|
|
};
|
|
|
|
const auto scrollDownIsShown = scrollDownIsVisible();
|
|
|
|
if (!scrollDownIsShown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_scrollDownIsShown != *scrollDownIsShown) {
|
|
|
|
_scrollDownIsShown = *scrollDownIsShown;
|
|
|
|
_scrollDownShown.start(
|
|
|
|
[=] { updateScrollDownPosition(); },
|
|
|
|
_scrollDownIsShown ? 0. : 1.,
|
|
|
|
_scrollDownIsShown ? 1. : 0.,
|
|
|
|
st::historyToDownDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::updateScrollDownPosition() {
|
|
|
|
// _scrollDown is a child widget of _scroll, not me.
|
|
|
|
auto top = anim::interpolate(
|
|
|
|
0,
|
|
|
|
_scrollDown->height() + st::historyToDownPosition.y(),
|
|
|
|
_scrollDownShown.value(_scrollDownIsShown ? 1. : 0.));
|
|
|
|
_scrollDown->moveToRight(
|
|
|
|
st::historyToDownPosition.x(),
|
|
|
|
_scroll->height() - top);
|
|
|
|
auto shouldBeHidden = !_scrollDownIsShown && !_scrollDownShown.animating();
|
|
|
|
if (shouldBeHidden != _scrollDown->isHidden()) {
|
|
|
|
_scrollDown->setVisible(!shouldBeHidden);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::scrollDownAnimationFinish() {
|
|
|
|
_scrollDownShown.stop();
|
|
|
|
updateScrollDownPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::updateAdaptiveLayout() {
|
|
|
|
_topBarShadow->moveToLeft(
|
2021-05-26 21:04:18 +00:00
|
|
|
controller()->adaptive().isOneColumn() ? 0 : st::lineWidth,
|
2020-08-28 10:01:55 +00:00
|
|
|
_topBar->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<History*> RepliesWidget::history() const {
|
|
|
|
return _history;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dialogs::RowDescriptor RepliesWidget::activeChat() const {
|
|
|
|
return {
|
|
|
|
_history,
|
|
|
|
FullMsgId(_history->channelId(), ShowAtUnreadMsgId)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-21 23:18:58 +00:00
|
|
|
bool RepliesWidget::preventsClose(Fn<void()> &&continueCallback) const {
|
|
|
|
return _composeControls->preventsClose(std::move(continueCallback));
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
QPixmap RepliesWidget::grabForShowAnimation(const Window::SectionSlideParams ¶ms) {
|
|
|
|
_topBar->updateControlsVisibility();
|
|
|
|
if (params.withTopBarShadow) _topBarShadow->hide();
|
|
|
|
_composeControls->showForGrab();
|
|
|
|
auto result = Ui::GrabWidget(this);
|
|
|
|
if (params.withTopBarShadow) _topBarShadow->show();
|
2021-09-19 14:48:00 +00:00
|
|
|
_rootView->hide();
|
2020-08-28 10:01:55 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::doSetInnerFocus() {
|
2020-09-29 15:05:48 +00:00
|
|
|
if (!_inner->getSelectedText().rich.text.isEmpty()
|
|
|
|
|| !_inner->getSelectedItems().empty()
|
|
|
|
|| !_composeControls->focus()) {
|
|
|
|
_inner->setFocus();
|
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::showInternal(
|
|
|
|
not_null<Window::SectionMemento*> memento,
|
|
|
|
const Window::SectionShow ¶ms) {
|
|
|
|
if (auto logMemento = dynamic_cast<RepliesMemento*>(memento.get())) {
|
2020-09-22 15:05:07 +00:00
|
|
|
if (logMemento->getHistory() == history()
|
|
|
|
&& logMemento->getRootId() == _rootId) {
|
2020-08-28 10:01:55 +00:00
|
|
|
restoreState(logMemento);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<RepliesMemento*> memento) {
|
|
|
|
setGeometry(geometry);
|
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::pushTabbedSelectorToThirdSection(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const Window::SectionShow ¶ms) {
|
|
|
|
return _composeControls->pushTabbedSelectorToThirdSection(peer, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::returnTabbedSelector() {
|
|
|
|
return _composeControls->returnTabbedSelector();
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:48:10 +00:00
|
|
|
std::shared_ptr<Window::SectionMemento> RepliesWidget::createMemento() {
|
|
|
|
auto result = std::make_shared<RepliesMemento>(history(), _rootId);
|
2020-08-28 10:01:55 +00:00
|
|
|
saveState(result.get());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-08-31 11:17:02 +00:00
|
|
|
bool RepliesWidget::showMessage(
|
|
|
|
PeerId peerId,
|
|
|
|
const Window::SectionShow ¶ms,
|
|
|
|
MsgId messageId) {
|
|
|
|
if (peerId != _history->peer->id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto id = FullMsgId{
|
|
|
|
_history->channelId(),
|
|
|
|
messageId
|
|
|
|
};
|
|
|
|
const auto message = _history->owner().message(id);
|
|
|
|
if (!message || message->replyToTop() != _rootId) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-31 13:41:24 +00:00
|
|
|
|
|
|
|
const auto originItem = [&]() -> HistoryItem* {
|
|
|
|
using OriginMessage = Window::SectionShow::OriginMessage;
|
|
|
|
if (const auto origin = std::get_if<OriginMessage>(¶ms.origin)) {
|
|
|
|
if (const auto returnTo = session().data().message(origin->id)) {
|
|
|
|
if (returnTo->history() == _history
|
|
|
|
&& returnTo->replyToTop() == _rootId
|
|
|
|
&& _replyReturn != returnTo) {
|
|
|
|
return returnTo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}();
|
2020-10-09 12:56:33 +00:00
|
|
|
showAtPosition(
|
|
|
|
Data::MessagePosition{ .fullId = id, .date = message->date() },
|
|
|
|
originItem);
|
2020-08-31 11:17:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-26 23:18:11 +00:00
|
|
|
Window::SectionActionResult RepliesWidget::sendBotCommand(
|
|
|
|
Bot::SendCommandRequest request) {
|
|
|
|
if (request.peer != _history->peer) {
|
|
|
|
return Window::SectionActionResult::Ignore;
|
|
|
|
}
|
|
|
|
listSendBotCommand(request.command, request.context);
|
|
|
|
return Window::SectionActionResult::Handle;
|
|
|
|
}
|
|
|
|
|
2020-11-11 20:47:40 +00:00
|
|
|
void RepliesWidget::replyToMessage(FullMsgId itemId) {
|
2021-07-26 14:37:19 +00:00
|
|
|
// if (item->history() != _history || item->replyToTop() != _rootId) {
|
2020-11-11 20:47:40 +00:00
|
|
|
_composeControls->replyToMessage(itemId);
|
|
|
|
refreshTopBarActiveChat();
|
2020-11-10 17:54:43 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::saveState(not_null<RepliesMemento*> memento) {
|
|
|
|
memento->setReplies(_replies);
|
2020-08-31 13:41:24 +00:00
|
|
|
memento->setReplyReturns(_replyReturns);
|
2020-08-28 10:01:55 +00:00
|
|
|
_inner->saveState(memento->list());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::restoreState(not_null<RepliesMemento*> memento) {
|
|
|
|
const auto setReplies = [&](std::shared_ptr<Data::RepliesList> replies) {
|
|
|
|
_replies = std::move(replies);
|
2020-09-15 18:19:06 +00:00
|
|
|
|
2020-09-17 13:26:53 +00:00
|
|
|
rpl::combine(
|
|
|
|
rpl::single(0) | rpl::then(_replies->fullCount()),
|
|
|
|
_areComments.value()
|
|
|
|
) | rpl::map([=](int count, bool areComments) {
|
|
|
|
return count
|
|
|
|
? (areComments
|
|
|
|
? tr::lng_comments_header
|
|
|
|
: tr::lng_replies_header)(
|
2021-09-17 15:17:48 +00:00
|
|
|
lt_count_decimal,
|
2020-09-17 13:26:53 +00:00
|
|
|
rpl::single(count) | tr::to_count())
|
|
|
|
: (areComments
|
|
|
|
? tr::lng_comments_header_none
|
|
|
|
: tr::lng_replies_header_none)();
|
|
|
|
}) | rpl::flatten_latest(
|
|
|
|
) | rpl::start_with_next([=](const QString &text) {
|
|
|
|
_topBar->setCustomTitle(text);
|
|
|
|
}, lifetime());
|
2020-08-28 10:01:55 +00:00
|
|
|
};
|
|
|
|
if (auto replies = memento->getReplies()) {
|
|
|
|
setReplies(std::move(replies));
|
|
|
|
} else if (!_replies) {
|
|
|
|
setReplies(std::make_shared<Data::RepliesList>(_history, _rootId));
|
|
|
|
}
|
2020-08-31 13:41:24 +00:00
|
|
|
restoreReplyReturns(memento->replyReturns());
|
2020-08-28 10:01:55 +00:00
|
|
|
_inner->restoreState(memento->list());
|
2020-09-17 17:57:06 +00:00
|
|
|
if (const auto highlight = memento->getHighlightId()) {
|
|
|
|
const auto position = Data::MessagePosition{
|
2020-10-09 12:56:33 +00:00
|
|
|
.fullId = FullMsgId(_history->channelId(), highlight),
|
|
|
|
.date = TimeId(0),
|
2020-09-17 17:57:06 +00:00
|
|
|
};
|
|
|
|
_inner->showAroundPosition(position, [=] {
|
|
|
|
return showAtPositionNow(position, nullptr);
|
|
|
|
});
|
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
if (!width() || !height()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_composeControls->resizeToWidth(width());
|
2020-09-22 16:16:36 +00:00
|
|
|
recountChatWidth();
|
2020-08-28 10:01:55 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2020-09-22 16:16:36 +00:00
|
|
|
void RepliesWidget::recountChatWidth() {
|
|
|
|
auto layout = (width() < st::adaptiveChatWideWidth)
|
2021-05-27 13:54:24 +00:00
|
|
|
? Window::Adaptive::ChatLayout::Normal
|
|
|
|
: Window::Adaptive::ChatLayout::Wide;
|
2021-05-26 21:04:18 +00:00
|
|
|
controller()->adaptive().setChatLayout(layout);
|
2020-09-22 16:16:36 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::updateControlsGeometry() {
|
|
|
|
const auto contentWidth = width();
|
|
|
|
|
|
|
|
const auto newScrollTop = _scroll->isHidden()
|
|
|
|
? std::nullopt
|
|
|
|
: base::make_optional(_scroll->scrollTop() + topDelta());
|
|
|
|
_topBar->resizeToWidth(contentWidth);
|
|
|
|
_topBarShadow->resize(contentWidth, st::lineWidth);
|
2020-10-13 07:16:16 +00:00
|
|
|
if (_rootView) {
|
|
|
|
_rootView->resizeToWidth(contentWidth);
|
|
|
|
}
|
2020-09-15 18:19:06 +00:00
|
|
|
_rootView->resizeToWidth(contentWidth);
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
const auto bottom = height();
|
|
|
|
const auto controlsHeight = _composeControls->heightCurrent();
|
2020-10-02 16:26:04 +00:00
|
|
|
const auto scrollY = _topBar->height() + _rootViewHeight;
|
2020-09-21 17:07:52 +00:00
|
|
|
const auto scrollHeight = bottom - scrollY - controlsHeight;
|
2020-08-28 10:01:55 +00:00
|
|
|
const auto scrollSize = QSize(contentWidth, scrollHeight);
|
|
|
|
if (_scroll->size() != scrollSize) {
|
|
|
|
_skipScrollEvent = true;
|
|
|
|
_scroll->resize(scrollSize);
|
|
|
|
_inner->resizeToWidth(scrollSize.width(), _scroll->height());
|
|
|
|
_skipScrollEvent = false;
|
|
|
|
}
|
2020-09-21 17:07:52 +00:00
|
|
|
_scroll->move(0, scrollY);
|
2020-08-28 10:01:55 +00:00
|
|
|
if (!_scroll->isHidden()) {
|
|
|
|
if (newScrollTop) {
|
|
|
|
_scroll->scrollToY(*newScrollTop);
|
|
|
|
}
|
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
|
|
|
_composeControls->move(0, bottom - controlsHeight);
|
2020-11-10 14:10:08 +00:00
|
|
|
_composeControls->setAutocompleteBoundingRect(_scroll->geometry());
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
updateScrollDownPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
if (animating()) {
|
|
|
|
SectionWidget::paintEvent(e);
|
|
|
|
return;
|
2020-09-04 10:07:40 +00:00
|
|
|
} else if (Ui::skipPaintEvent(this, e)) {
|
2020-08-28 10:01:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-15 18:19:06 +00:00
|
|
|
const auto aboveHeight = _topBar->height();
|
2020-09-04 10:07:40 +00:00
|
|
|
const auto bg = e->rect().intersected(
|
|
|
|
QRect(0, aboveHeight, width(), height() - aboveHeight));
|
2021-08-27 20:44:47 +00:00
|
|
|
SectionWidget::PaintBackground(controller(), _theme.get(), this, bg);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::onScroll() {
|
|
|
|
if (_skipScrollEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::updateInnerVisibleArea() {
|
2020-08-31 13:41:24 +00:00
|
|
|
if (!_inner->animatedScrolling()) {
|
|
|
|
checkReplyReturns();
|
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
const auto scrollTop = _scroll->scrollTop();
|
|
|
|
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
2020-09-15 18:19:06 +00:00
|
|
|
updatePinnedVisibility();
|
2020-08-28 10:01:55 +00:00
|
|
|
updateScrollDownVisibility();
|
|
|
|
}
|
|
|
|
|
2020-09-15 18:19:06 +00:00
|
|
|
void RepliesWidget::updatePinnedVisibility() {
|
|
|
|
if (!_loaded) {
|
|
|
|
return;
|
|
|
|
} else if (!_root) {
|
|
|
|
setPinnedVisibility(true);
|
|
|
|
return;
|
|
|
|
}
|
2020-09-16 19:48:56 +00:00
|
|
|
const auto item = [&] {
|
|
|
|
if (const auto group = _history->owner().groups().find(_root)) {
|
|
|
|
return group->items.front().get();
|
|
|
|
}
|
|
|
|
return _root;
|
|
|
|
}();
|
|
|
|
const auto view = _inner->viewByPosition(item->position());
|
2020-10-02 16:26:04 +00:00
|
|
|
const auto visible = !view
|
|
|
|
|| (view->y() + view->height() <= _scroll->scrollTop());
|
|
|
|
setPinnedVisibility(visible);
|
2020-09-15 18:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::setPinnedVisibility(bool shown) {
|
|
|
|
if (!animating()) {
|
2020-10-02 16:26:04 +00:00
|
|
|
if (!_rootViewInited) {
|
|
|
|
const auto height = shown ? st::historyReplyHeight : 0;
|
|
|
|
if (const auto delta = height - _rootViewHeight) {
|
|
|
|
_rootViewHeight = height;
|
|
|
|
if (_scroll->scrollTop() == _scroll->scrollTopMax()) {
|
|
|
|
setGeometryWithTopMoved(geometry(), delta);
|
|
|
|
} else {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
}
|
2020-10-13 07:16:16 +00:00
|
|
|
if (shown) {
|
|
|
|
_rootView->show();
|
|
|
|
} else {
|
|
|
|
_rootView->hide();
|
|
|
|
}
|
|
|
|
_rootVisible = shown;
|
|
|
|
_rootView->finishAnimating();
|
2020-10-02 16:26:04 +00:00
|
|
|
_rootViewInited = true;
|
|
|
|
} else {
|
2020-10-13 07:16:16 +00:00
|
|
|
_rootVisible = shown;
|
2020-10-02 16:26:04 +00:00
|
|
|
}
|
2020-09-15 18:19:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::showAnimatedHook(
|
|
|
|
const Window::SectionSlideParams ¶ms) {
|
|
|
|
_topBar->setAnimatingMode(true);
|
|
|
|
if (params.withTopBarShadow) {
|
|
|
|
_topBarShadow->show();
|
|
|
|
}
|
|
|
|
_composeControls->showStarted();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::showFinishedHook() {
|
|
|
|
_topBar->setAnimatingMode(false);
|
|
|
|
_composeControls->showFinished();
|
2021-09-19 14:48:00 +00:00
|
|
|
_rootView->show();
|
2020-08-28 10:01:55 +00:00
|
|
|
|
|
|
|
// We should setup the drag area only after
|
|
|
|
// the section animation is finished,
|
|
|
|
// because after that the method showChildren() is called.
|
|
|
|
setupDragArea();
|
2020-09-15 18:19:06 +00:00
|
|
|
updatePinnedVisibility();
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::floatPlayerHandleWheelEvent(QEvent *e) {
|
|
|
|
return _scroll->viewportEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect RepliesWidget::floatPlayerAvailableRect() {
|
|
|
|
return mapToGlobal(_scroll->geometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
Context RepliesWidget::listContext() {
|
2020-09-15 12:30:30 +00:00
|
|
|
return Context::Replies;
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::listScrollTo(int top) {
|
|
|
|
if (_scroll->scrollTop() != top) {
|
|
|
|
_scroll->scrollToY(top);
|
|
|
|
} else {
|
|
|
|
updateInnerVisibleArea();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::listCancelRequest() {
|
|
|
|
if (_inner && !_inner->getSelectedItems().empty()) {
|
|
|
|
clearSelected();
|
|
|
|
return;
|
2020-11-10 14:10:08 +00:00
|
|
|
} else if (_composeControls->handleCancelRequest()) {
|
2020-11-11 20:47:40 +00:00
|
|
|
refreshTopBarActiveChat();
|
2020-09-01 06:07:37 +00:00
|
|
|
return;
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
controller()->showBackFromStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::listDeleteRequest() {
|
|
|
|
confirmDeleteSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<Data::MessagesSlice> RepliesWidget::listSource(
|
|
|
|
Data::MessagePosition aroundId,
|
|
|
|
int limitBefore,
|
|
|
|
int limitAfter) {
|
2020-10-01 13:29:09 +00:00
|
|
|
return _replies->source(
|
|
|
|
aroundId,
|
|
|
|
limitBefore,
|
|
|
|
limitAfter
|
|
|
|
) | rpl::before_next([=] { // after_next makes a copy of value.
|
|
|
|
if (!_loaded) {
|
|
|
|
_loaded = true;
|
|
|
|
crl::on_main(this, [=] {
|
|
|
|
updatePinnedVisibility();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::listAllowsMultiSelect() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::listIsItemGoodForSelection(
|
|
|
|
not_null<HistoryItem*> item) {
|
2020-10-26 08:54:59 +00:00
|
|
|
return IsServerMsgId(item->id);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RepliesWidget::listIsLessInOrder(
|
|
|
|
not_null<HistoryItem*> first,
|
|
|
|
not_null<HistoryItem*> second) {
|
|
|
|
return first->position() < second->position();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::listSelectionChanged(SelectedItems &&items) {
|
|
|
|
HistoryView::TopBarWidget::SelectedState state;
|
|
|
|
state.count = items.size();
|
2021-09-08 10:53:54 +00:00
|
|
|
for (const auto &item : items) {
|
2020-08-28 10:01:55 +00:00
|
|
|
if (item.canDelete) {
|
|
|
|
++state.canDeleteCount;
|
|
|
|
}
|
2020-09-01 06:07:37 +00:00
|
|
|
if (item.canForward) {
|
|
|
|
++state.canForwardCount;
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_topBar->showSelected(state);
|
|
|
|
}
|
|
|
|
|
2021-08-30 16:22:16 +00:00
|
|
|
std::optional<int> RepliesWidget::computeUnreadCountLocally(
|
|
|
|
MsgId afterId) const {
|
|
|
|
const auto views = _root ? _root->Get<HistoryMessageViews>() : nullptr;
|
|
|
|
if (!views) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
const auto wasReadTillId = views->repliesInboxReadTillId;
|
|
|
|
const auto wasUnreadCount = views->repliesUnreadCount;
|
|
|
|
return _replies->fullUnreadCountAfter(
|
|
|
|
afterId,
|
|
|
|
wasReadTillId,
|
|
|
|
wasUnreadCount);
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:30:34 +00:00
|
|
|
void RepliesWidget::readTill(not_null<HistoryItem*> item) {
|
2020-09-22 11:01:49 +00:00
|
|
|
if (!_root) {
|
2020-09-08 11:19:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-09-22 11:01:49 +00:00
|
|
|
const auto was = _root->computeRepliesInboxReadTillFull();
|
2020-09-15 15:30:34 +00:00
|
|
|
const auto now = item->id;
|
2021-08-30 15:37:09 +00:00
|
|
|
if (now < was) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-30 16:22:16 +00:00
|
|
|
const auto unreadCount = computeUnreadCountLocally(now);
|
2021-08-30 15:37:09 +00:00
|
|
|
const auto fast = item->out() || !unreadCount.has_value();
|
|
|
|
if (was < now || (fast && now == was)) {
|
|
|
|
_root->setRepliesInboxReadTill(now, unreadCount);
|
2020-09-22 11:01:49 +00:00
|
|
|
if (const auto post = _root->lookupDiscussionPostOriginal()) {
|
2021-08-30 15:37:09 +00:00
|
|
|
post->setRepliesInboxReadTill(now, unreadCount);
|
2020-09-22 11:01:49 +00:00
|
|
|
}
|
2020-09-08 11:19:44 +00:00
|
|
|
if (!_readRequestTimer.isActive()) {
|
2020-09-15 15:30:34 +00:00
|
|
|
_readRequestTimer.callOnce(fast ? 0 : kReadRequestTimeout);
|
|
|
|
} else if (fast && _readRequestTimer.remainingTime() > 0) {
|
|
|
|
_readRequestTimer.callOnce(0);
|
2020-09-08 11:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::listVisibleItemsChanged(HistoryItemsList &&items) {
|
2021-03-13 12:12:08 +00:00
|
|
|
const auto reversed = ranges::views::reverse(items);
|
2020-09-08 11:19:44 +00:00
|
|
|
const auto good = ranges::find_if(reversed, [](auto item) {
|
|
|
|
return IsServerMsgId(item->id);
|
|
|
|
});
|
|
|
|
if (good != end(reversed)) {
|
2020-09-15 15:30:34 +00:00
|
|
|
readTill(*good);
|
2020-09-08 11:19:44 +00:00
|
|
|
}
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 15:30:34 +00:00
|
|
|
MessagesBarData RepliesWidget::listMessagesBar(
|
2020-08-28 10:01:55 +00:00
|
|
|
const std::vector<not_null<Element*>> &elements) {
|
2020-09-22 11:01:49 +00:00
|
|
|
if (!_root || elements.empty()) {
|
2020-09-16 19:48:56 +00:00
|
|
|
return {};
|
2020-09-08 11:19:44 +00:00
|
|
|
}
|
2020-09-22 11:01:49 +00:00
|
|
|
const auto till = _root->computeRepliesInboxReadTillFull();
|
2021-08-30 08:27:08 +00:00
|
|
|
const auto hidden = (till < 2);
|
2020-09-08 11:19:44 +00:00
|
|
|
for (auto i = 0, count = int(elements.size()); i != count; ++i) {
|
|
|
|
const auto item = elements[i]->data();
|
2020-09-15 15:30:34 +00:00
|
|
|
if (IsServerMsgId(item->id) && item->id > till) {
|
2020-10-23 13:35:43 +00:00
|
|
|
if (item->out() || !item->replyToId()) {
|
2020-09-15 15:30:34 +00:00
|
|
|
readTill(item);
|
2020-09-08 11:19:44 +00:00
|
|
|
} else {
|
2021-08-30 08:27:08 +00:00
|
|
|
return {
|
|
|
|
.bar = {
|
2020-09-15 15:30:34 +00:00
|
|
|
.element = elements[i],
|
2021-08-30 08:27:08 +00:00
|
|
|
.hidden = hidden,
|
2020-09-15 15:30:34 +00:00
|
|
|
.focus = true,
|
|
|
|
},
|
2021-08-30 08:27:08 +00:00
|
|
|
.text = tr::lng_unread_bar_some(),
|
2020-09-15 15:30:34 +00:00
|
|
|
};
|
2020-09-08 11:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 19:48:56 +00:00
|
|
|
return {};
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::listContentRefreshed() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ClickHandlerPtr RepliesWidget::listDateLink(not_null<Element*> view) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-08-28 12:48:54 +00:00
|
|
|
bool RepliesWidget::listElementHideReply(not_null<const Element*> view) {
|
|
|
|
return (view->data()->replyToId() == _rootId);
|
|
|
|
}
|
|
|
|
|
2020-09-22 11:30:15 +00:00
|
|
|
bool RepliesWidget::listElementShownUnread(not_null<const Element*> view) {
|
|
|
|
if (!_root) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto item = view->data();
|
|
|
|
const auto till = item->out()
|
|
|
|
? _root->computeRepliesOutboxReadTillFull()
|
|
|
|
: _root->computeRepliesInboxReadTillFull();
|
|
|
|
return (item->id > till);
|
|
|
|
}
|
|
|
|
|
2020-09-04 16:11:36 +00:00
|
|
|
bool RepliesWidget::listIsGoodForAroundPosition(
|
|
|
|
not_null<const Element*> view) {
|
|
|
|
return IsServerMsgId(view->data()->id);
|
|
|
|
}
|
|
|
|
|
2020-11-10 16:38:21 +00:00
|
|
|
void RepliesWidget::listSendBotCommand(
|
|
|
|
const QString &command,
|
|
|
|
const FullMsgId &context) {
|
2021-07-26 20:06:14 +00:00
|
|
|
const auto text = Bot::WrapCommandInChat(
|
|
|
|
_history->peer,
|
|
|
|
command,
|
|
|
|
context);
|
2020-11-10 16:38:21 +00:00
|
|
|
auto message = ApiWrap::MessageToSend(_history);
|
|
|
|
message.textWithTags = { text };
|
|
|
|
message.action.replyTo = replyToId();
|
|
|
|
session().api().sendMessage(std::move(message));
|
|
|
|
finishSending();
|
|
|
|
}
|
|
|
|
|
2020-11-10 18:51:20 +00:00
|
|
|
void RepliesWidget::listHandleViaClick(not_null<UserData*> bot) {
|
|
|
|
_composeControls->setText({ '@' + bot->username + ' ' });
|
|
|
|
}
|
|
|
|
|
2021-08-27 20:44:47 +00:00
|
|
|
not_null<Ui::ChatTheme*> RepliesWidget::listChatTheme() {
|
|
|
|
return _theme.get();
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::confirmDeleteSelected() {
|
2020-10-26 08:54:59 +00:00
|
|
|
ConfirmDeleteSelectedItems(_inner);
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 16:11:36 +00:00
|
|
|
void RepliesWidget::confirmForwardSelected() {
|
2020-10-26 08:54:59 +00:00
|
|
|
ConfirmForwardSelectedItems(_inner);
|
2020-09-04 16:11:36 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 10:01:55 +00:00
|
|
|
void RepliesWidget::clearSelected() {
|
|
|
|
_inner->cancelSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RepliesWidget::setupDragArea() {
|
|
|
|
const auto areas = DragArea::SetupDragAreaToContainer(
|
|
|
|
this,
|
2020-10-12 11:45:48 +00:00
|
|
|
[=](auto d) { return _history && !_composeControls->isRecording(); },
|
2020-08-28 10:01:55 +00:00
|
|
|
nullptr,
|
|
|
|
[=] { updateControlsGeometry(); });
|
|
|
|
|
2020-10-15 14:27:16 +00:00
|
|
|
const auto droppedCallback = [=](bool overrideSendImagesAsPhotos) {
|
2020-08-28 10:01:55 +00:00
|
|
|
return [=](const QMimeData *data) {
|
2020-10-15 14:27:16 +00:00
|
|
|
confirmSendingFiles(data, overrideSendImagesAsPhotos);
|
2020-08-28 10:01:55 +00:00
|
|
|
Window::ActivateWindow(controller());
|
|
|
|
};
|
|
|
|
};
|
2020-10-15 14:27:16 +00:00
|
|
|
areas.document->setDroppedCallback(droppedCallback(false));
|
|
|
|
areas.photo->setDroppedCallback(droppedCallback(true));
|
2020-08-28 10:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace HistoryView
|