Skip to content

Commit

Permalink
Merge 9257702 into e2e9b8a
Browse files Browse the repository at this point in the history
  • Loading branch information
Randl committed Oct 21, 2018
2 parents e2e9b8a + 9257702 commit 2cc31e0
Show file tree
Hide file tree
Showing 63 changed files with 220 additions and 500 deletions.
20 changes: 10 additions & 10 deletions Telegram/SourceFiles/apiwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void ApiWrap::requestAppChangelogs() {

void ApiWrap::addLocalChangelogs(int oldAppVersion) {
auto addedSome = false;
auto addLocalChangelog = [this, &addedSome](const QString &text) {
auto addLocalChangelog = [&addedSome](const QString &text) {
auto textWithEntities = TextWithEntities{text};
TextUtilities::ParseEntities(textWithEntities, TextParseLinks);
App::wnd()->serviceNotification(textWithEntities, MTP_messageMediaEmpty(), unixtime());
Expand Down Expand Up @@ -542,7 +542,7 @@ void ApiWrap::requestPeers(const QList<PeerData *> &peers) {
channels.push_back((*i)->asChannel()->inputChannel);
}
}
auto handleChats = [this](const MTPmessages_Chats &result) {
auto handleChats = [](const MTPmessages_Chats &result) {
if (auto chats = Api::getChatsFromMessagesChats(result)) {
App::feedChats(*chats);
}
Expand All @@ -555,7 +555,7 @@ void ApiWrap::requestPeers(const QList<PeerData *> &peers) {
}
if (!users.isEmpty()) {
request(MTPusers_GetUsers(MTP_vector<MTPInputUser>(users)))
.done([this](const MTPVector<MTPUser> &result) { App::feedUsers(result); })
.done([](const MTPVector<MTPUser> &result) { App::feedUsers(result); })
.send();
}
}
Expand Down Expand Up @@ -1192,7 +1192,7 @@ void ApiWrap::handlePrivacyChange(mtpTypeId keyTypeId, const MTPVector<MTPPrivac
}

auto now = unixtime();
App::enumerateUsers([&userRules, contactsRule, everyoneRule, now](UserData *user) {
App::enumerateUsers([now](UserData *user) {
if (user->isSelf() || user->loadedStatus != PeerData::FullLoaded) {
return;
}
Expand Down Expand Up @@ -1460,7 +1460,7 @@ void ApiWrap::resolveWebPages() {
}

void ApiWrap::requestParticipantsCountDelayed(ChannelData *channel) {
_participantsCountRequestTimer.call(kReloadChannelMembersTimeout, [this, channel] { channel->updateFullForced(); });
_participantsCountRequestTimer.call(kReloadChannelMembersTimeout, [channel] { channel->updateFullForced(); });
}

void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs, mtpRequestId req) {
Expand Down Expand Up @@ -1587,7 +1587,7 @@ void ApiWrap::requestStickers(TimeId now) {
};
_stickersUpdateRequest = request(MTPmessages_GetAllStickers(MTP_int(Local::countStickersHash(true))))
.done(onDone)
.fail([this, onDone](const RPCError &error) {
.fail([onDone](const RPCError &error) {
LOG(("App Fail: Failed to get stickers!"));
onDone(MTP_messages_allStickersNotModified());
})
Expand Down Expand Up @@ -1619,7 +1619,7 @@ void ApiWrap::requestRecentStickers(TimeId now) {
_recentStickersUpdateRequest =
request(MTPmessages_GetRecentStickers(MTP_flags(0), MTP_int(Local::countRecentStickersHash())))
.done(onDone)
.fail([this, onDone](const RPCError &error) {
.fail([onDone](const RPCError &error) {
LOG(("App Fail: Failed to get recent stickers!"));
onDone(MTP_messages_recentStickersNotModified());
})
Expand Down Expand Up @@ -1650,7 +1650,7 @@ void ApiWrap::requestFavedStickers(TimeId now) {
};
_favedStickersUpdateRequest = request(MTPmessages_GetFavedStickers(MTP_int(Local::countFavedStickersHash())))
.done(onDone)
.fail([this, onDone](const RPCError &error) {
.fail([onDone](const RPCError &error) {
LOG(("App Fail: Failed to get faved stickers!"));
onDone(MTP_messages_favedStickersNotModified());
})
Expand Down Expand Up @@ -1682,7 +1682,7 @@ void ApiWrap::requestFeaturedStickers(TimeId now) {
_featuredStickersUpdateRequest =
request(MTPmessages_GetFeaturedStickers(MTP_int(Local::countFeaturedStickersHash())))
.done(onDone)
.fail([this, onDone](const RPCError &error) {
.fail([onDone](const RPCError &error) {
LOG(("App Fail: Failed to get featured stickers!"));
onDone(MTP_messages_featuredStickersNotModified());
})
Expand Down Expand Up @@ -1712,7 +1712,7 @@ void ApiWrap::requestSavedGifs(TimeId now) {
};
_savedGifsUpdateRequest = request(MTPmessages_GetSavedGifs(MTP_int(Local::countSavedGifsHash())))
.done(onDone)
.fail([this, onDone](const RPCError &error) {
.fail([onDone](const RPCError &error) {
LOG(("App Fail: Failed to get saved gifs!"));
onDone(MTP_messages_savedGifsNotModified());
})
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/auth_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ AuthSession::AuthSession(UserId userId)
, _uploader(std::make_unique<Storage::Uploader>())
, _notifications(std::make_unique<Window::Notifications::System>(this)) {
Expects(_userId != 0);
_saveDataTimer.setCallback([this] { Local::writeUserSettings(); });
_saveDataTimer.setCallback([] { Local::writeUserSettings(); });
subscribe(Messenger::Instance().passcodedChanged(), [this] {
_shouldLockAt = 0;
notifications().updateAll();
Expand Down
1 change: 0 additions & 1 deletion Telegram/SourceFiles/boxes/about_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ AboutBox::AboutBox(QWidget *parent)
, _text3(this, st::aboutLabel) {}

void AboutBox::prepare() {
constexpr auto test = std::is_convertible<const char *, QString>::value;
setTitle([] { return str_const_toString(AppName); });

addButton(langFactory(lng_close), [this] { closeBox(); });
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/boxes/confirm_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ ConfirmInviteBox::ConfirmInviteBox(QWidget *, const QString &title, bool isChann
}

void ConfirmInviteBox::prepare() {
addButton(langFactory(lng_group_invite_join), [this] {
addButton(langFactory(lng_group_invite_join), [] {
if (auto main = App::main()) {
main->onInviteImport();
}
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/boxes/edit_participant_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ void EditRestrictedBox::createUntilVariants() {
_untilVariants.back()->setDisabled(true);
}
};
auto addCustomVariant = [this, addVariant](TimeId until, TimeId from, TimeId to) {
auto addCustomVariant = [addVariant](TimeId until, TimeId from, TimeId to) {
if (!ChannelData::IsRestrictedForever(until) && until > from && until <= to) {
addVariant(until, lng_rights_chat_banned_custom_date(lt_date, langDayOfMonthFull(date(until).date())));
}
Expand Down
1 change: 0 additions & 1 deletion Telegram/SourceFiles/boxes/peer_list_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,6 @@ void PeerListBox::Inner::paintRow(Painter &p, TimeMs ms, RowIndex index) {
row->lazyInitialize();

auto peer = row->peer();
auto user = peer->asUser();
auto active = (_pressed.index.value >= 0) ? _pressed : _selected;
auto selected = (active.index == index);
auto actionSelected = (selected && active.action);
Expand Down
1 change: 0 additions & 1 deletion Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ void GifsListWidget::updateSelected() {
return;
}

auto newSelected = -1;
auto p = mapFromGlobal(_lastMousePos);

int sx = (rtl() ? width() - p.x() : p.x()) - (st::inlineResultsLeft - st::buttonRadius);
Expand Down
2 changes: 0 additions & 2 deletions Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ object_ptr<TabbedSelector::InnerFooter> StickersListWidget::createFooter() {
}

void StickersListWidget::setVisibleTopBottom(int visibleTop, int visibleBottom) {
auto top = getVisibleTop();
Inner::setVisibleTopBottom(visibleTop, visibleBottom);
if (_section == Section::Featured) {
readVisibleSets();
Expand Down Expand Up @@ -1501,7 +1500,6 @@ void StickersListWidget::updateSelected() {
newSelected = OverGroupAdd{};
}
} else {
auto special = ((set.flags & MTPDstickerSet::Flag::f_official) != 0);
int rowIndex = std::floor(yOffset / st::stickerPanSize.height());
int columnIndex = std::floor(sx / st::stickerPanSize.width());
auto index = rowIndex * kStickersPanelPerRow + columnIndex;
Expand Down
145 changes: 0 additions & 145 deletions Telegram/SourceFiles/codegen/lang/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,151 +346,6 @@ QString GetOriginalValue(LangKey key) {\n\
return source_->finalize();
}

template <typename ComputeResult>
void Generator::writeSetSearch(const std::set<QString, std::greater<QString>> &set, ComputeResult computeResult,
const QString &invalidResult) {
auto tabs = [](int size) { return QString(size, '\t'); };

enum class UsedCheckType {
Switch,
If,
UpcomingIf,
};
auto checkTypes = QVector<UsedCheckType>();
auto checkLengthHistory = QVector<int>(1, 0);
auto chars = QString();
auto tabsUsed = 1;

// Returns true if at least one check was finished.
auto finishChecksTillKey = [this, &chars, &checkTypes, &checkLengthHistory, &tabsUsed, tabs](const QString &key) {
auto result = false;
while (!chars.isEmpty() && key.midRef(0, chars.size()) != chars) {
result = true;

auto wasType = checkTypes.back();
chars.resize(chars.size() - 1);
checkTypes.pop_back();
checkLengthHistory.pop_back();
if (wasType == UsedCheckType::Switch || wasType == UsedCheckType::If) {
--tabsUsed;
if (wasType == UsedCheckType::Switch) {
source_->stream() << tabs(tabsUsed) << "break;\n";
}
if ((!chars.isEmpty() && key.midRef(0, chars.size()) != chars) || key == chars) {
source_->stream() << tabs(tabsUsed) << "}\n";
}
}
}
return result;
};

// Check if we can use "if" for a check on "charIndex" in "it" (otherwise only "switch")
auto canUseIfForCheck = [](auto it, auto end, int charIndex) {
auto key = *it;
auto i = it;
auto keyStart = key.mid(0, charIndex);
for (++i; i != end; ++i) {
auto nextKey = *i;
if (nextKey.mid(0, charIndex) != keyStart) {
return true;
} else if (nextKey.size() > charIndex && nextKey[charIndex] != key[charIndex]) {
return false;
}
}
return true;
};

auto countMinimalLength = [](auto it, auto end, int charIndex) {
auto key = *it;
auto i = it;
auto keyStart = key.mid(0, charIndex);
auto result = key.size();
for (++i; i != end; ++i) {
auto nextKey = *i;
if (nextKey.mid(0, charIndex) != keyStart) {
break;
} else if (nextKey.size() > charIndex && result > nextKey.size()) {
result = nextKey.size();
}
}
return result;
};

for (auto i = set.begin(), e = set.end(); i != e; ++i) {
// If we use just "auto" here and "name" becomes mutable,
// the operator[] will return QCharRef instead of QChar,
// and "auto ch = name[index]" will behave like "auto &ch =",
// if you assign something to "ch" after that you'll change "name" (!)
const auto name = *i;

auto weContinueOldSwitch = finishChecksTillKey(name);
while (chars.size() != name.size()) {
auto checking = chars.size();
auto partialKey = name.mid(0, checking);

auto keyChar = name[checking];
auto usedIfForCheckCount = 0;
auto minimalLengthCheck = countMinimalLength(i, e, checking);
for (; checking + usedIfForCheckCount != name.size(); ++usedIfForCheckCount) {
if (!canUseIfForCheck(i, e, checking + usedIfForCheckCount) ||
countMinimalLength(i, e, checking + usedIfForCheckCount) != minimalLengthCheck) {
break;
}
}
auto usedIfForCheck = !weContinueOldSwitch && (usedIfForCheckCount > 0);
auto checkLengthCondition = QString();
if (weContinueOldSwitch) {
weContinueOldSwitch = false;
} else {
checkLengthCondition = (minimalLengthCheck > checkLengthHistory.back()) ?
("size >= " + QString::number(minimalLengthCheck)) :
QString();
if (!usedIfForCheck) {
source_->stream() << tabs(tabsUsed)
<< (checkLengthCondition.isEmpty() ? QString() :
("if (" + checkLengthCondition + ") "))
<< "switch (data[" << checking << "]) {\n";
}
}
if (usedIfForCheck) {
auto conditions = QStringList();
if (usedIfForCheckCount > 1) {
conditions.push_back("!memcmp(data + " + QString::number(checking) + ", \"" +
name.mid(checking, usedIfForCheckCount) + "\", " +
QString::number(usedIfForCheckCount) + ")");
} else {
conditions.push_back("data[" + QString::number(checking) + "] == '" + keyChar + "'");
}
if (!checkLengthCondition.isEmpty()) {
conditions.push_front(checkLengthCondition);
}
source_->stream() << tabs(tabsUsed) << "if (" << conditions.join(" && ") << ") {\n";
checkTypes.push_back(UsedCheckType::If);
for (auto i = 1; i != usedIfForCheckCount; ++i) {
checkTypes.push_back(UsedCheckType::UpcomingIf);
chars.push_back(keyChar);
checkLengthHistory.push_back(std::max(minimalLengthCheck, checkLengthHistory.back()));
keyChar = name[checking + i];
}
} else {
source_->stream() << tabs(tabsUsed) << "case '" << keyChar << "':\n";
checkTypes.push_back(UsedCheckType::Switch);
}
++tabsUsed;
chars.push_back(keyChar);
checkLengthHistory.push_back(std::max(minimalLengthCheck, checkLengthHistory.back()));
}
source_->stream() << tabs(tabsUsed) << "return (size == " << chars.size() << ") ? " << computeResult(name)
<< " : " << invalidResult << ";\n";
}
finishChecksTillKey(QString());

source_->stream() << "\
\n\
return " << invalidResult
<< ";\n";
}

QString Generator::getFullKey(const LangPack::Entry &entry) {
if (!entry.keyBase.isEmpty() || entry.tags.empty()) {
return entry.key;
Expand Down
32 changes: 8 additions & 24 deletions Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2026,40 +2026,24 @@ void DialogsInner::loadPeerPhotos() {
_filterResults[from]->history()->peer->loadUserpic();
}
}

from = (yFrom > filteredOffset() + st::searchedBarHeight ?
((yFrom - filteredOffset() - st::searchedBarHeight) / qint32(st::dialogsRowHeight)) :
0) -
_filterResults.size();
auto offset = filteredOffset() + st::searchedBarHeight;
from = (yFrom > offset ? ((yFrom - offset) / qint32(st::dialogsRowHeight)) : 0) - _filterResults.size();
if (from < 0) from = 0;
if (from < _peerSearchResults.size()) {
qint32 to = (yTo > filteredOffset() + st::searchedBarHeight ?
((yTo - filteredOffset() - st::searchedBarHeight) / qint32(st::dialogsRowHeight)) :
0) -
_filterResults.size() + 1;
qint32 to =
(yTo > offset ? ((yTo - offset) / qint32(st::dialogsRowHeight)) : 0) - _filterResults.size() + 1;
if (to > _peerSearchResults.size()) to = _peerSearchResults.size();

for (; from < to; ++from) {
_peerSearchResults[from]->peer->loadUserpic();
}
}
from = (yFrom > filteredOffset() +
((_peerSearchResults.empty() ? 0 : st::searchedBarHeight) + st::searchedBarHeight) ?
((yFrom - filteredOffset() - (_peerSearchResults.empty() ? 0 : st::searchedBarHeight) -
st::searchedBarHeight) /
qint32(st::dialogsRowHeight)) :
0) -
_filterResults.size() - _peerSearchResults.size();
auto offset2 = offset + (_peerSearchResults.empty() ? 0 : st::searchedBarHeight);
auto results_size = _filterResults.size() + _peerSearchResults.size();
from = (yFrom > offset2 ? ((yFrom - offset2) / qint32(st::dialogsRowHeight)) : 0) - results_size;
if (from < 0) from = 0;
if (from < _searchResults.size()) {
qint32 to = (yTo > filteredOffset() + (_peerSearchResults.empty() ? 0 : st::searchedBarHeight) +
st::searchedBarHeight ?
((yTo - filteredOffset() - (_peerSearchResults.empty() ? 0 : st::searchedBarHeight) -
st::searchedBarHeight) /
qint32(st::dialogsRowHeight)) :
0) -
_filterResults.size() - _peerSearchResults.size() + 1,
w = width();
qint32 to = (yTo > offset2 ? ((yTo - offset2) / qint32(st::dialogsRowHeight)) : 0) - results_size + 1;
if (to > _searchResults.size()) to = _searchResults.size();

for (; from < to; ++from) {
Expand Down
1 change: 0 additions & 1 deletion Telegram/SourceFiles/dialogs/dialogs_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ void DialogsWidget::showAnimated(Window::SlideDirection direction, const Window:
_chooseFromUser->hideFast();
_lockUnlock->hide();

int delta = st::slideShift;
if (_showDirection == Window::SlideDirection::FromLeft) {
std::swap(_cacheUnder, _cacheOver);
}
Expand Down
Loading

0 comments on commit 2cc31e0

Please sign in to comment.