Fix some possible crashes.

This commit is contained in:
John Preston 2018-06-04 22:48:17 +03:00
parent 31998406dd
commit a52392241d
4 changed files with 21 additions and 12 deletions

View File

@ -678,7 +678,7 @@ namespace App {
auto h = App::historyLoaded(chat->id);
bool found = !h || !h->lastKeyboardFrom;
auto botStatus = -1;
for (auto i = chat->participants.begin(), e = chat->participants.end(); i != e;) {
for (auto i = chat->participants.begin(); i != chat->participants.end();) {
auto [user, version] = *i;
if (version < pversion) {
i = chat->participants.erase(i);

View File

@ -932,7 +932,7 @@ void StickersListWidget::refreshSearchRows() {
}
void StickersListWidget::refreshSearchRows(
const std::vector<Stickers::Set*> *cloudSets) {
const std::vector<uint64> *cloudSets) {
clearSelection();
_searchSets.clear();
@ -997,9 +997,12 @@ void StickersListWidget::fillLocalSearchRows(const QString &query) {
}
void StickersListWidget::fillCloudSearchRows(
const std::vector<Stickers::Set*> &sets) {
for (const auto set : sets) {
addSearchRow(set);
const std::vector<uint64> &cloudSets) {
const auto &sets = Auth().data().stickerSets();
for (const auto setId : cloudSets) {
if (const auto it = sets.find(setId); it != sets.end()) {
addSearchRow(&*it);
}
}
}
@ -1049,7 +1052,7 @@ void StickersListWidget::searchResultsDone(
if (it == _searchCache.cend()) {
it = _searchCache.emplace(
_searchQuery,
std::vector<Stickers::Set*>()).first;
std::vector<uint64>()).first;
}
auto &d = result.c_messages_foundStickerSets();
for_const (const auto &stickerSet, d.vsets.v) {
@ -1084,7 +1087,7 @@ void StickersListWidget::searchResultsDone(
if (set->stickers.empty() && set->covers.empty()) {
continue;
}
it->second.push_back(set);
it->second.push_back(set->id);
}
}
showSearchResults();

View File

@ -243,9 +243,9 @@ private:
void showSearchResults();
void searchResultsDone(const MTPmessages_FoundStickerSets &result);
void refreshSearchRows();
void refreshSearchRows(const std::vector<Stickers::Set*> *cloudSets);
void refreshSearchRows(const std::vector<uint64> *cloudSets);
void fillLocalSearchRows(const QString &query);
void fillCloudSearchRows(const std::vector<Stickers::Set*> &sets);
void fillCloudSearchRows(const std::vector<uint64> &cloudSets);
void addSearchRow(not_null<const Stickers::Set*> set);
ChannelData *_megagroupSet = nullptr;
@ -284,7 +284,7 @@ private:
QTimer _previewTimer;
bool _previewShown = false;
std::map<QString, std::vector<Stickers::Set*>> _searchCache;
std::map<QString, std::vector<uint64>> _searchCache;
std::vector<std::pair<uint64, QStringList>> _searchIndex;
base::Timer _searchRequestTimer;
QString _searchQuery, _searchNextQuery;

View File

@ -1261,11 +1261,17 @@ void ConnectionPrivate::markConnectionOld() {
void ConnectionPrivate::sendPingByTimer() {
if (_pingId) {
if (_pingSendAt + kPingSendAfterForce - kPingSendAfter - TimeMs(1000) < getms(true)) {
// _pingSendAt: when to send next ping (lastPingAt + kPingSendAfter)
// could be equal to zero.
const auto now = getms(true);
const auto mustSendTill = _pingSendAt
+ kPingSendAfterForce
- kPingSendAfter;
if (mustSendTill < now + 1000) {
LOG(("Could not send ping for some seconds, restarting..."));
return restart();
} else {
_pingSender.callOnce(_pingSendAt + kPingSendAfterForce - kPingSendAfter - getms(true));
_pingSender.callOnce(mustSendTill - now);
}
} else {
emit needToSendAsync();