mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix viewing gifts from list of saved.
This commit is contained in:
parent
8287d717f8
commit
7756cce123
4 changed files with 53 additions and 50 deletions
|
@ -850,7 +850,7 @@ std::optional<Data::SavedStarGift> FromTL(
|
||||||
using Id = Data::SavedStarGiftId;
|
using Id = Data::SavedStarGiftId;
|
||||||
return Data::SavedStarGift{
|
return Data::SavedStarGift{
|
||||||
.info = std::move(*parsed),
|
.info = std::move(*parsed),
|
||||||
.id = (to->isUser()
|
.manageId = (to->isUser()
|
||||||
? Id::User(data.vmsg_id().value_or_empty())
|
? Id::User(data.vmsg_id().value_or_empty())
|
||||||
: Id::Chat(to, data.vsaved_id().value_or_empty())),
|
: Id::Chat(to, data.vsaved_id().value_or_empty())),
|
||||||
.message = (data.vmessage()
|
.message = (data.vmessage()
|
||||||
|
|
|
@ -124,7 +124,7 @@ private:
|
||||||
|
|
||||||
struct SavedStarGift {
|
struct SavedStarGift {
|
||||||
StarGift info;
|
StarGift info;
|
||||||
SavedStarGiftId id;
|
SavedStarGiftId manageId;
|
||||||
TextWithEntities message;
|
TextWithEntities message;
|
||||||
int64 starsConverted = 0;
|
int64 starsConverted = 0;
|
||||||
int64 starsUpgradedBySender = 0;
|
int64 starsUpgradedBySender = 0;
|
||||||
|
|
|
@ -84,7 +84,8 @@ private:
|
||||||
};
|
};
|
||||||
struct View {
|
struct View {
|
||||||
std::unique_ptr<GiftButton> button;
|
std::unique_ptr<GiftButton> button;
|
||||||
Data::SavedStarGiftId id;
|
Data::SavedStarGiftId manageId;
|
||||||
|
uint64 giftId = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ private:
|
||||||
void loadMore();
|
void loadMore();
|
||||||
void refreshButtons();
|
void refreshButtons();
|
||||||
void validateButtons();
|
void validateButtons();
|
||||||
void showGift(Data::SavedStarGiftId id);
|
void showGift(int index);
|
||||||
void refreshAbout();
|
void refreshAbout();
|
||||||
|
|
||||||
int resizeGetHeight(int width) override;
|
int resizeGetHeight(int width) override;
|
||||||
|
@ -164,7 +165,7 @@ void InnerWidget::subscribeToUpdates() {
|
||||||
_peer->owner().giftUpdates(
|
_peer->owner().giftUpdates(
|
||||||
) | rpl::start_with_next([=](const Data::GiftUpdate &update) {
|
) | rpl::start_with_next([=](const Data::GiftUpdate &update) {
|
||||||
const auto savedId = [](const Entry &entry) {
|
const auto savedId = [](const Entry &entry) {
|
||||||
return entry.gift.id;
|
return entry.gift.manageId;
|
||||||
};
|
};
|
||||||
const auto i = ranges::find(_entries, update.id, savedId);
|
const auto i = ranges::find(_entries, update.id, savedId);
|
||||||
if (i == end(_entries)) {
|
if (i == end(_entries)) {
|
||||||
|
@ -194,7 +195,7 @@ void InnerWidget::subscribeToUpdates() {
|
||||||
for (auto &view : _views) {
|
for (auto &view : _views) {
|
||||||
if (view.index == index) {
|
if (view.index == index) {
|
||||||
view.index = -1;
|
view.index = -1;
|
||||||
view.id = {};
|
view.manageId = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -321,56 +322,59 @@ void InnerWidget::validateButtons() {
|
||||||
auto y = vskip + fromRow * oneh;
|
auto y = vskip + fromRow * oneh;
|
||||||
auto views = std::vector<View>();
|
auto views = std::vector<View>();
|
||||||
views.reserve((tillRow - fromRow) * _perRow);
|
views.reserve((tillRow - fromRow) * _perRow);
|
||||||
const auto idUsed = [&](const Data::SavedStarGiftId &id) {
|
const auto idUsed = [&](uint64 giftId, int column, int row) {
|
||||||
for (auto j = fromRow; j != tillRow; ++j) {
|
for (auto j = row; j != tillRow; ++j) {
|
||||||
for (auto i = 0; i != _perRow; ++i) {
|
for (auto i = column; i != _perRow; ++i) {
|
||||||
const auto index = j * _perRow + i;
|
const auto index = j * _perRow + i;
|
||||||
if (index >= _entries.size()) {
|
if (index >= _entries.size()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (_entries[index].gift.id == id) {
|
} else if (_entries[index].gift.info.id == giftId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
column = 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
const auto add = [&](int index) {
|
const auto add = [&](int column, int row) {
|
||||||
const auto id = _entries[index].gift.id;
|
const auto index = row * _perRow + column;
|
||||||
const auto already = ranges::find(_views, id, &View::id);
|
if (index >= _entries.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto giftId = _entries[index].gift.info.id;
|
||||||
|
const auto manageId = _entries[index].gift.manageId;
|
||||||
|
const auto already = ranges::find(_views, giftId, &View::giftId);
|
||||||
if (already != end(_views)) {
|
if (already != end(_views)) {
|
||||||
views.push_back(base::take(*already));
|
views.push_back(base::take(*already));
|
||||||
views.back().index = index;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const auto &descriptor = _entries[index].descriptor;
|
|
||||||
const auto callback = [=] {
|
|
||||||
showGift(id);
|
|
||||||
};
|
|
||||||
const auto unused = ranges::find_if(_views, [&](const View &v) {
|
|
||||||
return v.button && !idUsed(v.id);
|
|
||||||
});
|
|
||||||
if (unused != end(_views)) {
|
|
||||||
views.push_back(base::take(*unused));
|
|
||||||
views.back().index = index;
|
|
||||||
} else {
|
} else {
|
||||||
auto button = std::make_unique<GiftButton>(this, &_delegate);
|
const auto &descriptor = _entries[index].descriptor;
|
||||||
button->show();
|
const auto unused = ranges::find_if(_views, [&](const View &v) {
|
||||||
views.push_back({
|
return v.button && !idUsed(v.giftId, column, row);
|
||||||
.button = std::move(button),
|
|
||||||
.id = id,
|
|
||||||
.index = index,
|
|
||||||
});
|
});
|
||||||
|
if (unused != end(_views)) {
|
||||||
|
views.push_back(base::take(*unused));
|
||||||
|
} else {
|
||||||
|
auto button = std::make_unique<GiftButton>(this, &_delegate);
|
||||||
|
button->show();
|
||||||
|
views.push_back({ .button = std::move(button) });
|
||||||
|
}
|
||||||
|
auto &view = views.back();
|
||||||
|
const auto callback = [=] {
|
||||||
|
showGift(index);
|
||||||
|
};
|
||||||
|
view.index = index;
|
||||||
|
view.manageId = manageId;
|
||||||
|
view.giftId = giftId;
|
||||||
|
view.button->setDescriptor(descriptor, mode);
|
||||||
|
view.button->setClickedCallback(callback);
|
||||||
}
|
}
|
||||||
views.back().button->setDescriptor(descriptor, mode);
|
return true;
|
||||||
views.back().button->setClickedCallback(callback);
|
};
|
||||||
};
|
|
||||||
for (auto j = fromRow; j != tillRow; ++j) {
|
for (auto j = fromRow; j != tillRow; ++j) {
|
||||||
for (auto i = 0; i != _perRow; ++i) {
|
for (auto i = 0; i != _perRow; ++i) {
|
||||||
const auto index = j * _perRow + i;
|
if (!add(i, j)) {
|
||||||
if (index >= _entries.size()) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
add(index);
|
|
||||||
views.back().button->setGeometry(
|
views.back().button->setGeometry(
|
||||||
QRect(QPoint(x, y), _single),
|
QRect(QPoint(x, y), _single),
|
||||||
_delegate.buttonExtend());
|
_delegate.buttonExtend());
|
||||||
|
@ -382,15 +386,14 @@ void InnerWidget::validateButtons() {
|
||||||
std::swap(_views, views);
|
std::swap(_views, views);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::showGift(Data::SavedStarGiftId id) {
|
void InnerWidget::showGift(int index) {
|
||||||
const auto savedId = [](const Entry &entry) {
|
Expects(index >= 0 && index < _entries.size());
|
||||||
return entry.gift.id;
|
|
||||||
};
|
_window->show(Box(
|
||||||
const auto i = ranges::find(_entries, id, savedId);
|
::Settings::SavedStarGiftBox,
|
||||||
if (i != end(_entries)) {
|
_window,
|
||||||
using namespace ::Settings;
|
_peer,
|
||||||
_window->show(Box(SavedStarGiftBox, _window, _peer, i->gift));
|
_entries[index].gift));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::refreshAbout() {
|
void InnerWidget::refreshAbout() {
|
||||||
|
|
|
@ -1869,7 +1869,7 @@ void SavedStarGiftBox(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
not_null<PeerData*> owner,
|
not_null<PeerData*> owner,
|
||||||
const Data::SavedStarGift &data) {
|
const Data::SavedStarGift &data) {
|
||||||
const auto chatGiftPeer = data.id.chat();
|
const auto chatGiftPeer = data.manageId.chat();
|
||||||
Settings::ReceiptCreditsBox(
|
Settings::ReceiptCreditsBox(
|
||||||
box,
|
box,
|
||||||
controller,
|
controller,
|
||||||
|
@ -1877,13 +1877,13 @@ void SavedStarGiftBox(
|
||||||
.description = data.message,
|
.description = data.message,
|
||||||
.date = base::unixtime::parse(data.date),
|
.date = base::unixtime::parse(data.date),
|
||||||
.credits = StarsAmount(data.info.stars),
|
.credits = StarsAmount(data.info.stars),
|
||||||
.bareMsgId = uint64(data.id.userMessageId().bare),
|
.bareMsgId = uint64(data.manageId.userMessageId().bare),
|
||||||
.barePeerId = data.fromId.value,
|
.barePeerId = data.fromId.value,
|
||||||
.bareGiftStickerId = data.info.document->id,
|
.bareGiftStickerId = data.info.document->id,
|
||||||
.bareGiftOwnerId = owner->id.value,
|
.bareGiftOwnerId = owner->id.value,
|
||||||
.bareActorId = data.fromId.value,
|
.bareActorId = data.fromId.value,
|
||||||
.bareGiftListPeerId = chatGiftPeer ? chatGiftPeer->id.value : 0,
|
.bareGiftListPeerId = chatGiftPeer ? chatGiftPeer->id.value : 0,
|
||||||
.giftSavedId = data.id.chatSavedId(),
|
.giftSavedId = data.manageId.chatSavedId(),
|
||||||
.stargiftId = data.info.id,
|
.stargiftId = data.info.id,
|
||||||
.uniqueGift = data.info.unique,
|
.uniqueGift = data.info.unique,
|
||||||
.peerType = Data::CreditsHistoryEntry::PeerType::Peer,
|
.peerType = Data::CreditsHistoryEntry::PeerType::Peer,
|
||||||
|
|
Loading…
Add table
Reference in a new issue