mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added api support to reorder stickers from sticker set box.
This commit is contained in:
parent
54214ff2ad
commit
358e586801
1 changed files with 46 additions and 3 deletions
|
@ -342,6 +342,8 @@ private:
|
||||||
|
|
||||||
void installDone(const MTPmessages_StickerSetInstallResult &result);
|
void installDone(const MTPmessages_StickerSetInstallResult &result);
|
||||||
|
|
||||||
|
void requestReorder(not_null<DocumentData*> document, int index);
|
||||||
|
|
||||||
void chosen(
|
void chosen(
|
||||||
int index,
|
int index,
|
||||||
not_null<DocumentData*> sticker,
|
not_null<DocumentData*> sticker,
|
||||||
|
@ -394,6 +396,8 @@ private:
|
||||||
int lastSelected = -1;
|
int lastSelected = -1;
|
||||||
QPoint point;
|
QPoint point;
|
||||||
} _dragging;
|
} _dragging;
|
||||||
|
std::deque<Fn<void()>> _reorderRequests;
|
||||||
|
std::optional<MTP::Sender> _apiReorder;
|
||||||
|
|
||||||
struct ShiftAnimation final {
|
struct ShiftAnimation final {
|
||||||
Ui::Animations::Simple animation;
|
Ui::Animations::Simple animation;
|
||||||
|
@ -1222,13 +1226,52 @@ void StickerSetBox::Inner::leaveEventHook(QEvent *e) {
|
||||||
setSelected(-1);
|
setSelected(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StickerSetBox::Inner::requestReorder(
|
||||||
|
not_null<DocumentData*> document,
|
||||||
|
int index) {
|
||||||
|
if (!_apiReorder) {
|
||||||
|
_apiReorder.emplace(&_session->mtp());
|
||||||
|
}
|
||||||
|
_reorderRequests.emplace_back([document, index, this] {
|
||||||
|
_apiReorder->request(
|
||||||
|
MTPstickers_ChangeStickerPosition(
|
||||||
|
document->mtpInput(),
|
||||||
|
MTP_int(index))
|
||||||
|
).done([this, document](const TLStickerSet &result) {
|
||||||
|
result.match([&](const MTPDmessages_stickerSet &d) {
|
||||||
|
document->owner().stickers().feedSetFull(d);
|
||||||
|
document->owner().stickers().notifyUpdated(
|
||||||
|
Data::StickersType::Stickers);
|
||||||
|
}, [](const auto &) {
|
||||||
|
});
|
||||||
|
if (!_reorderRequests.empty()) {
|
||||||
|
_reorderRequests.pop_front();
|
||||||
|
}
|
||||||
|
if (_reorderRequests.empty()) {
|
||||||
|
// applySet(result); // Causes stickers blink.
|
||||||
|
} else {
|
||||||
|
_reorderRequests.front()();
|
||||||
|
}
|
||||||
|
}).fail([show = _show](const MTP::Error &error) {
|
||||||
|
show->showToast(error.type());
|
||||||
|
}).send();
|
||||||
|
});
|
||||||
|
if (_reorderRequests.size() == 1) {
|
||||||
|
_reorderRequests.front()();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void StickerSetBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
void StickerSetBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
if (_dragging.index >= 0 && !isDraggedAnimating()) {
|
if (_dragging.index >= 0 && !isDraggedAnimating()) {
|
||||||
const auto fromPos = mapFromGlobal(e->globalPos()) - _dragging.point;
|
const auto fromPos = mapFromGlobal(e->globalPos()) - _dragging.point;
|
||||||
const auto toPos = posFromIndex(_dragging.lastSelected);
|
const auto toPos = posFromIndex(_dragging.lastSelected);
|
||||||
const auto finish = [=] {
|
const auto document = _pack[_dragging.index];
|
||||||
base::reorder(_pack, _dragging.index, _dragging.lastSelected);
|
const auto wasPosition = _dragging.index;
|
||||||
base::reorder(_elements, _dragging.index, _dragging.lastSelected);
|
const auto nowPosition = _dragging.lastSelected;
|
||||||
|
const auto finish = [=, this] {
|
||||||
|
requestReorder(document, nowPosition);
|
||||||
|
base::reorder(_pack, wasPosition, nowPosition);
|
||||||
|
base::reorder(_elements, wasPosition, nowPosition);
|
||||||
_dragging = {};
|
_dragging = {};
|
||||||
_dragging.enabled = true;
|
_dragging.enabled = true;
|
||||||
_shiftAnimations.clear();
|
_shiftAnimations.clear();
|
||||||
|
|
Loading…
Add table
Reference in a new issue