Added initial swipe-to-reply to section for replies.

This commit is contained in:
23rd 2024-09-03 18:04:55 +03:00 committed by John Preston
parent 1648c31a22
commit 71e3cd227c
3 changed files with 80 additions and 0 deletions

View file

@ -2305,6 +2305,11 @@ void ListWidget::paintUserpics(
// paint the userpic if it intersects the painted rect
if (userpicTop + st::msgPhotoSize > clip.top()) {
const auto item = view->data();
const auto hasTranslation = context.gestureHorizontal.ratio
&& (context.gestureHorizontal.msgBareId == item->fullId().msg.bare);
if (hasTranslation) {
p.translate(context.gestureHorizontal.translation, 0);
}
if (const auto from = item->displayFrom()) {
from->paintUserpicLeft(
p,
@ -2337,6 +2342,9 @@ void ListWidget::paintUserpics(
} else {
Unexpected("Corrupt forwarded information in message.");
}
if (hasTranslation) {
p.translate(-context.gestureHorizontal.translation, 0);
}
}
return true;
});

View file

@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_drag_area.h"
#include "history/history_item_components.h"
#include "history/history_item_helpers.h" // GetErrorTextForSending.
#include "history/history_view_swipe.h"
#include "ui/chat/pinned_bar.h"
#include "ui/chat/chat_style.h"
#include "ui/widgets/buttons.h"
@ -399,6 +400,7 @@ RepliesWidget::RepliesWidget(
setupTopicViewer();
setupComposeControls();
setupSwipeReply();
orderWidgets();
if (_pinnedBar) {
@ -865,6 +867,62 @@ void RepliesWidget::setupComposeControls() {
}
}
void RepliesWidget::setupSwipeReply() {
const auto can = [=](not_null<HistoryItem*> still) {
const auto canSendReply = _topic
? Data::CanSendAnything(_topic)
: Data::CanSendAnything(_history->peer);
const auto allowInAnotherChat = still && still->allowsForward();
if (allowInAnotherChat && (_joinGroup || !canSendReply)) {
return true;
} else if (!_joinGroup && canSendReply) {
return true;
}
return false;
};
HistoryView::SetupSwipeHandler(_inner, _scroll.get(), [=](
HistoryView::ChatPaintGestureHorizontalData data) {
_gestureHorizontal = data;
const auto item = _history->peer->owner().message(
_history->peer->id,
MsgId{ data.msgBareId });
if (item) {
_inner->update();
// repaintItem(item);
}
}, [=, show = controller()->uiShow()](int cursorTop) {
auto result = HistoryView::SwipeHandlerFinishData();
if (_inner->elementInSelectionMode()) {
return result;
}
const auto view = _inner->lookupItemByY(cursorTop);
if (!view->data()->isRegular()
|| view->data()->isService()) {
return result;
}
if (!can(view->data())) {
return result;
}
result.msgBareId = view->data()->fullId().msg.bare;
result.callback = [=, itemId = view->data()->fullId()] {
const auto still = show->session().data().message(itemId);
const auto view = _inner->viewByPosition(still->position());
const auto selected = view->selectedQuote(
_inner->getSelectedTextRange(still));
const auto replyToItemId = (selected.item
? selected.item
: still)->fullId();
_inner->replyToMessageRequestNotify({
.messageId = replyToItemId,
.quote = selected.text,
.quoteOffset = selected.offset,
});
};
return result;
});
}
void RepliesWidget::chooseAttach(
std::optional<bool> overrideSendImagesAsPhotos) {
_choosingAttach = false;
@ -2631,6 +2689,14 @@ void RepliesWidget::listAddTranslatedItems(
}
}
Ui::ChatPaintContext RepliesWidget::listPreparePaintContext(
Ui::ChatPaintContextArgs &&args) {
auto context = WindowListDelegate::listPreparePaintContext(
std::move(args));
context.gestureHorizontal = _gestureHorizontal;
return context;
}
void RepliesWidget::setupEmptyPainter() {
Expects(_topic != nullptr);

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/section_memento.h"
#include "history/view/history_view_corner_buttons.h"
#include "history/view/history_view_list_widget.h"
#include "history/history_view_swipe_data.h"
#include "data/data_messages.h"
#include "base/timer.h"
@ -180,6 +181,8 @@ public:
History *listTranslateHistory() override;
void listAddTranslatedItems(
not_null<TranslateTracker*> tracker) override;
Ui::ChatPaintContext listPreparePaintContext(
Ui::ChatPaintContextArgs &&args) override;
// CornerButtonsDelegate delegate.
void cornerButtonsShowAtPosition(
@ -221,6 +224,7 @@ private:
void finishSending();
void setupComposeControls();
void setupSwipeReply();
void setupRoot();
void setupRootView();
@ -369,6 +373,8 @@ private:
HistoryView::CornerButtons _cornerButtons;
rpl::lifetime _topicLifetime;
HistoryView::ChatPaintGestureHorizontalData _gestureHorizontal;
int _lastScrollTop = 0;
int _topicReopenBarHeight = 0;
int _scrollTopDelta = 0;