Fix getting list of archived sticker sets.

GitOrigin-RevId: d73147d8e6ff0e7c0db2319793feb73c7a1755e1
This commit is contained in:
levlam 2019-06-05 02:32:10 +03:00
parent 71d6963e50
commit 6d2842d0b4
2 changed files with 27 additions and 13 deletions

View File

@ -114,6 +114,7 @@ class SearchStickersQuery : public Td::ResultHandler {
class GetArchivedStickerSetsQuery : public Td::ResultHandler { class GetArchivedStickerSetsQuery : public Td::ResultHandler {
Promise<Unit> promise_; Promise<Unit> promise_;
int64 offset_sticker_set_id_;
bool is_masks_; bool is_masks_;
public: public:
@ -121,6 +122,7 @@ class GetArchivedStickerSetsQuery : public Td::ResultHandler {
} }
void send(bool is_masks, int64 offset_sticker_set_id, int32 limit) { void send(bool is_masks, int64 offset_sticker_set_id, int32 limit) {
offset_sticker_set_id_ = offset_sticker_set_id;
is_masks_ = is_masks; is_masks_ = is_masks;
LOG(INFO) << "Get archived " << (is_masks ? "mask" : "sticker") << " sets from " << offset_sticker_set_id LOG(INFO) << "Get archived " << (is_masks ? "mask" : "sticker") << " sets from " << offset_sticker_set_id
<< " with limit " << limit; << " with limit " << limit;
@ -143,7 +145,8 @@ class GetArchivedStickerSetsQuery : public Td::ResultHandler {
auto ptr = result_ptr.move_as_ok(); auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetArchivedStickerSetsQuery " << to_string(ptr); LOG(INFO) << "Receive result for GetArchivedStickerSetsQuery " << to_string(ptr);
td->stickers_manager_->on_get_archived_sticker_sets(is_masks_, std::move(ptr->sets_), ptr->count_); td->stickers_manager_->on_get_archived_sticker_sets(is_masks_, offset_sticker_set_id_, std::move(ptr->sets_),
ptr->count_);
promise_.set_value(Unit()); promise_.set_value(Unit());
} }
@ -2463,10 +2466,16 @@ void StickersManager::on_update_sticker_set(StickerSet *sticker_set, bool is_ins
} }
if (is_archived) { if (is_archived) {
if (std::find(sticker_set_ids.begin(), sticker_set_ids.end(), sticker_set->id) == sticker_set_ids.end()) {
total_count++; total_count++;
sticker_set_ids.insert(sticker_set_ids.begin(), sticker_set->id); sticker_set_ids.insert(sticker_set_ids.begin(), sticker_set->id);
}
} else { } else {
total_count--; total_count--;
if (total_count < 0) {
LOG(ERROR) << "Total count of archived sticker sets became negative";
total_count = 0;
}
sticker_set_ids.erase(std::remove(sticker_set_ids.begin(), sticker_set_ids.end(), sticker_set->id), sticker_set_ids.erase(std::remove(sticker_set_ids.begin(), sticker_set_ids.end(), sticker_set->id),
sticker_set_ids.end()); sticker_set_ids.end());
} }
@ -2841,11 +2850,7 @@ std::pair<int32, vector<int64>> StickersManager::get_archived_sticker_sets(bool
vector<int64> &sticker_set_ids = archived_sticker_set_ids_[is_masks]; vector<int64> &sticker_set_ids = archived_sticker_set_ids_[is_masks];
int32 total_count = total_archived_sticker_set_count_[is_masks]; int32 total_count = total_archived_sticker_set_count_[is_masks];
if (total_count < 0) { if (total_count >= 0) {
total_count = 0;
}
if (!sticker_set_ids.empty()) {
auto offset_it = sticker_set_ids.begin(); auto offset_it = sticker_set_ids.begin();
if (offset_sticker_set_id != 0) { if (offset_sticker_set_id != 0) {
offset_it = std::find(sticker_set_ids.begin(), sticker_set_ids.end(), offset_sticker_set_id); offset_it = std::find(sticker_set_ids.begin(), sticker_set_ids.end(), offset_sticker_set_id);
@ -2878,11 +2883,20 @@ std::pair<int32, vector<int64>> StickersManager::get_archived_sticker_sets(bool
} }
void StickersManager::on_get_archived_sticker_sets( void StickersManager::on_get_archived_sticker_sets(
bool is_masks, vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets, int32 total_count) { bool is_masks, int64 offset_sticker_set_id, vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets,
int32 total_count) {
vector<int64> &sticker_set_ids = archived_sticker_set_ids_[is_masks]; vector<int64> &sticker_set_ids = archived_sticker_set_ids_[is_masks];
if (!sticker_set_ids.empty() && sticker_set_ids.back() == 0) { if (!sticker_set_ids.empty() && sticker_set_ids.back() == 0) {
return; return;
} }
if (total_count < 0) {
LOG(ERROR) << "Receive " << total_count << " as total count of archived sticker sets";
}
// if 0 sticker sets are received then set offset_sticker_set_id was found and there is no stickers after it
// or it wasn't found and there is no archived sets at all
bool is_last =
sticker_sets.empty() && (offset_sticker_set_id == 0 || offset_sticker_set_id == sticker_set_ids.back());
total_archived_sticker_set_count_[is_masks] = total_count; total_archived_sticker_set_count_[is_masks] = total_count;
for (auto &sticker_set_covered : sticker_sets) { for (auto &sticker_set_covered : sticker_sets) {
@ -2897,9 +2911,9 @@ void StickersManager::on_get_archived_sticker_sets(
} }
} }
} }
if (sticker_set_ids.size() >= static_cast<size_t>(total_count)) { if (sticker_set_ids.size() >= static_cast<size_t>(total_count) || is_last) {
if (sticker_set_ids.size() > static_cast<size_t>(total_count)) { if (sticker_set_ids.size() != static_cast<size_t>(total_count)) {
LOG(ERROR) << "Expected total of " << total_count << " archived sticker sets, but only " << sticker_set_ids.size() LOG(ERROR) << "Expected total of " << total_count << " archived sticker sets, but " << sticker_set_ids.size()
<< " found"; << " found";
total_archived_sticker_set_count_[is_masks] = static_cast<int32>(sticker_set_ids.size()); total_archived_sticker_set_count_[is_masks] = static_cast<int32>(sticker_set_ids.size());
} }

View File

@ -115,7 +115,7 @@ class StickersManager : public Actor {
std::pair<int32, vector<int64>> get_archived_sticker_sets(bool is_masks, int64 offset_sticker_set_id, int32 limit, std::pair<int32, vector<int64>> get_archived_sticker_sets(bool is_masks, int64 offset_sticker_set_id, int32 limit,
bool force, Promise<Unit> &&promise); bool force, Promise<Unit> &&promise);
void on_get_archived_sticker_sets(bool is_masks, void on_get_archived_sticker_sets(bool is_masks, int64 offset_sticker_set_id,
vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets, vector<tl_object_ptr<telegram_api::StickerSetCovered>> &&sticker_sets,
int32 total_count); int32 total_count);