Moved out swipe-to-reply setup to inner method in HistoryInner.

This commit is contained in:
23rd 2024-09-03 17:16:51 +03:00 committed by John Preston
parent f8c820f319
commit 1648c31a22
2 changed files with 63 additions and 58 deletions

View File

@ -383,64 +383,6 @@ HistoryInner::HistoryInner(
_migrated->delegateMixin()->setCurrent(this);
_migrated->translateTo(_history->translatedTo());
}
HistoryView::SetupSwipeHandler(this, _scroll, [=, history = _history](
HistoryView::ChatPaintGestureHorizontalData data) {
_gestureHorizontal = data;
const auto item = history->peer->owner().message(
history->peer->id,
MsgId{ data.msgBareId });
if (item) {
repaintItem(item);
}
}, [=, show = controller->uiShow()](int cursorTop) {
auto result = HistoryView::SwipeHandlerFinishData();
if (inSelectionMode()) {
return result;
}
enumerateItems<EnumItemsDirection::BottomToTop>([&](
not_null<Element*> view,
int itemtop,
int itembottom) {
if ((cursorTop < itemtop)
|| (cursorTop > itembottom)
|| !view->data()->isRegular()
|| view->data()->isService()) {
return true;
}
const auto item = view->data();
const auto canSendReply = CanSendReply(item);
const auto canReply = (canSendReply || item->allowsForward());
if (!canReply) {
return true;
}
result.msgBareId = item->fullId().msg.bare;
result.callback = [=, itemId = item->fullId()] {
const auto still = show->session().data().message(itemId);
const auto selected = selectedQuote(still);
const auto replyToItemId = (selected.item
? selected.item
: still)->fullId();
if (canSendReply) {
_widget->replyToMessage({
.messageId = replyToItemId,
.quote = selected.text,
.quoteOffset = selected.offset,
});
if (!selected.text.empty()) {
_widget->clearSelected();
}
} else {
HistoryView::Controls::ShowReplyToChatBox(show, {
.messageId = replyToItemId,
.quote = selected.text,
.quoteOffset = selected.offset,
});
}
};
return false;
});
return result;
});
Window::ChatThemeValueFromPeer(
controller,
@ -553,6 +495,7 @@ HistoryInner::HistoryInner(
}, _scroll->lifetime());
setupSharingDisallowed();
setupSwipeReply();
}
void HistoryInner::reactionChosen(const ChosenReaction &reaction) {
@ -635,6 +578,67 @@ void HistoryInner::setupSharingDisallowed() {
}, lifetime());
}
void HistoryInner::setupSwipeReply() {
HistoryView::SetupSwipeHandler(this, _scroll, [=, history = _history](
HistoryView::ChatPaintGestureHorizontalData data) {
_gestureHorizontal = data;
const auto item = history->peer->owner().message(
history->peer->id,
MsgId{ data.msgBareId });
if (item) {
repaintItem(item);
}
}, [=, show = _controller->uiShow()](int cursorTop) {
auto result = HistoryView::SwipeHandlerFinishData();
if (inSelectionMode()) {
return result;
}
enumerateItems<EnumItemsDirection::BottomToTop>([&](
not_null<Element*> view,
int itemtop,
int itembottom) {
if ((cursorTop < itemtop)
|| (cursorTop > itembottom)
|| !view->data()->isRegular()
|| view->data()->isService()) {
return true;
}
const auto item = view->data();
const auto canSendReply = CanSendReply(item);
const auto canReply = (canSendReply || item->allowsForward());
if (!canReply) {
return true;
}
result.msgBareId = item->fullId().msg.bare;
result.callback = [=, itemId = item->fullId()] {
const auto still = show->session().data().message(itemId);
const auto selected = selectedQuote(still);
const auto replyToItemId = (selected.item
? selected.item
: still)->fullId();
if (canSendReply) {
_widget->replyToMessage({
.messageId = replyToItemId,
.quote = selected.text,
.quoteOffset = selected.offset,
});
if (!selected.text.empty()) {
_widget->clearSelected();
}
} else {
HistoryView::Controls::ShowReplyToChatBox(show, {
.messageId = replyToItemId,
.quote = selected.text,
.quoteOffset = selected.offset,
});
}
};
return false;
});
return result;
});
}
bool HistoryInner::hasSelectRestriction() const {
if (!_sharingDisallowed.current()) {
return false;

View File

@ -420,6 +420,7 @@ private:
void reactionChosen(const ChosenReaction &reaction);
void setupSharingDisallowed();
void setupSwipeReply();
[[nodiscard]] bool hasCopyRestriction(HistoryItem *item = nullptr) const;
[[nodiscard]] bool hasCopyMediaRestriction(
not_null<HistoryItem*> item) const;