mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Moved out swipe-to-reply setup to inner method in HistoryInner.
This commit is contained in:
parent
f8c820f319
commit
1648c31a22
2 changed files with 63 additions and 58 deletions
|
@ -383,64 +383,6 @@ HistoryInner::HistoryInner(
|
||||||
_migrated->delegateMixin()->setCurrent(this);
|
_migrated->delegateMixin()->setCurrent(this);
|
||||||
_migrated->translateTo(_history->translatedTo());
|
_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(
|
Window::ChatThemeValueFromPeer(
|
||||||
controller,
|
controller,
|
||||||
|
@ -553,6 +495,7 @@ HistoryInner::HistoryInner(
|
||||||
}, _scroll->lifetime());
|
}, _scroll->lifetime());
|
||||||
|
|
||||||
setupSharingDisallowed();
|
setupSharingDisallowed();
|
||||||
|
setupSwipeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryInner::reactionChosen(const ChosenReaction &reaction) {
|
void HistoryInner::reactionChosen(const ChosenReaction &reaction) {
|
||||||
|
@ -635,6 +578,67 @@ void HistoryInner::setupSharingDisallowed() {
|
||||||
}, lifetime());
|
}, 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 {
|
bool HistoryInner::hasSelectRestriction() const {
|
||||||
if (!_sharingDisallowed.current()) {
|
if (!_sharingDisallowed.current()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -420,6 +420,7 @@ private:
|
||||||
void reactionChosen(const ChosenReaction &reaction);
|
void reactionChosen(const ChosenReaction &reaction);
|
||||||
|
|
||||||
void setupSharingDisallowed();
|
void setupSharingDisallowed();
|
||||||
|
void setupSwipeReply();
|
||||||
[[nodiscard]] bool hasCopyRestriction(HistoryItem *item = nullptr) const;
|
[[nodiscard]] bool hasCopyRestriction(HistoryItem *item = nullptr) const;
|
||||||
[[nodiscard]] bool hasCopyMediaRestriction(
|
[[nodiscard]] bool hasCopyMediaRestriction(
|
||||||
not_null<HistoryItem*> item) const;
|
not_null<HistoryItem*> item) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue