From 605b18aa270ccbbc9bfd6bec97e51809b7affff6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 3 Oct 2015 14:33:51 +0300 Subject: [PATCH] added some checks --- Telegram/SourceFiles/app.cpp | 4 ++-- Telegram/SourceFiles/boxes/aboutbox.cpp | 3 +++ Telegram/SourceFiles/boxes/aboutbox.h | 3 +++ Telegram/SourceFiles/boxes/addcontactbox.cpp | 4 ++-- Telegram/SourceFiles/dialogswidget.cpp | 2 +- Telegram/SourceFiles/dropdown.cpp | 10 +++++----- Telegram/SourceFiles/history.cpp | 6 +++--- Telegram/SourceFiles/historywidget.cpp | 16 +++++++++------- Telegram/SourceFiles/localstorage.cpp | 2 +- Telegram/SourceFiles/mainwidget.cpp | 4 ++-- Telegram/SourceFiles/profilewidget.cpp | 6 +++--- Telegram/SourceFiles/structs.cpp | 8 +++++--- 12 files changed, 39 insertions(+), 29 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 86a0ec74d4..52b90ac81b 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -626,7 +626,7 @@ namespace App { } else { if (i.key()->botInfo) { botStatus = (botStatus > 0/* || i.key()->botInfo->readsAllHistory*/) ? 2 : 1; - if (requestBotInfos && !i.key()->botInfo->inited) App::api()->requestFullPeer(i.key()); + if (requestBotInfos && !i.key()->botInfo->inited && App::api()) App::api()->requestFullPeer(i.key()); } if (!found && i.key()->id == h->lastKeyboardFrom) { found = true; @@ -676,7 +676,7 @@ namespace App { chat->count++; if (user->botInfo) { chat->botStatus = (chat->botStatus > 0/* || !user->botInfo->readsAllHistory*/) ? 2 : 1; - if (!user->botInfo->inited) App::api()->requestFullPeer(user); + if (!user->botInfo->inited && App::api()) App::api()->requestFullPeer(user); } } } else { diff --git a/Telegram/SourceFiles/boxes/aboutbox.cpp b/Telegram/SourceFiles/boxes/aboutbox.cpp index a9eca94287..1a7a2b8490 100644 --- a/Telegram/SourceFiles/boxes/aboutbox.cpp +++ b/Telegram/SourceFiles/boxes/aboutbox.cpp @@ -12,6 +12,9 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014 John Preston, https://desktop.telegram.org */ diff --git a/Telegram/SourceFiles/boxes/aboutbox.h b/Telegram/SourceFiles/boxes/aboutbox.h index 35d3dd2105..cfc1d3352b 100644 --- a/Telegram/SourceFiles/boxes/aboutbox.h +++ b/Telegram/SourceFiles/boxes/aboutbox.h @@ -12,6 +12,9 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014 John Preston, https://desktop.telegram.org */ diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index 758b084586..3b5a3636a4 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -577,7 +577,7 @@ bool EditChannelBox::onSaveFail(const RPCError &error, mtpRequestId req) { _saveDescriptionRequestId = 0; if (err == qstr("CHAT_ABOUT_NOT_MODIFIED")) { _channel->about = _sentDescription; - emit App::api()->fullPeerUpdated(_channel); + if (App::api()) emit App::api()->fullPeerUpdated(_channel); onClose(); } else { _description.setFocus(); @@ -595,6 +595,6 @@ void EditChannelBox::onSaveTitleDone(const MTPUpdates &updates) { void EditChannelBox::onSaveDescriptionDone(const MTPBool &result) { _saveDescriptionRequestId = 0; _channel->about = _sentDescription; - emit App::api()->fullPeerUpdated(_channel); + if (App::api()) emit App::api()->fullPeerUpdated(_channel); onClose(); } diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 04b16b533c..df2d4d79ef 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -796,7 +796,7 @@ void DialogsInner::dialogsReceived(const QVector &added) { history->peer->asChannel()->ptsReceived(d.vpts.v); if (!history->peer->asChannel()->amCreator()) { if (HistoryItem *top = App::histItemById(history->channelId(), d.vtop_important_message.v)) { - if (top->date <= date(history->peer->asChannel()->date)) { + if (top->date <= date(history->peer->asChannel()->date) && App::api()) { App::api()->requestSelfParticipant(history->peer->asChannel()); } } diff --git a/Telegram/SourceFiles/dropdown.cpp b/Telegram/SourceFiles/dropdown.cpp index 87d6a0034e..3b71add492 100644 --- a/Telegram/SourceFiles/dropdown.cpp +++ b/Telegram/SourceFiles/dropdown.cpp @@ -2976,7 +2976,7 @@ void MentionsDropdown::updateFiltered(bool toDown) { QMultiMap ordered; rows.reserve(_chat->participants.isEmpty() ? _chat->lastAuthors.size() : _chat->participants.size()); if (_chat->participants.isEmpty()) { - if (_chat->count > 0) { + if (_chat->count > 0 && App::api()) { App::api()->requestFullPeer(_chat); } } else { @@ -3015,7 +3015,7 @@ void MentionsDropdown::updateFiltered(bool toDown) { int32 cnt = 0; if (_chat) { if (_chat->participants.isEmpty()) { - if (_chat->count > 0) { + if (_chat->count > 0 && App::api()) { App::api()->requestFullPeer(_chat); } } else { @@ -3023,14 +3023,14 @@ void MentionsDropdown::updateFiltered(bool toDown) { for (ChatData::Participants::const_iterator i = _chat->participants.cbegin(), e = _chat->participants.cend(); i != e; ++i) { UserData *user = i.key(); if (!user->botInfo) continue; - if (!user->botInfo->inited) App::api()->requestFullPeer(user); + if (!user->botInfo->inited && App::api()) App::api()->requestFullPeer(user); if (user->botInfo->commands.isEmpty()) continue; bots.insert(user, true); cnt += user->botInfo->commands.size(); } } } else if (_user && _user->botInfo) { - if (!_user->botInfo->inited) App::api()->requestFullPeer(_user); + if (!_user->botInfo->inited && App::api()) App::api()->requestFullPeer(_user); cnt = _user->botInfo->commands.size(); bots.insert(_user, true); } @@ -3042,7 +3042,7 @@ void MentionsDropdown::updateFiltered(bool toDown) { UserData *user = *i; if (!user->botInfo) continue; if (!bots.contains(user)) continue; - if (!user->botInfo->inited) App::api()->requestFullPeer(user); + if (!user->botInfo->inited && App::api()) App::api()->requestFullPeer(user); if (user->botInfo->commands.isEmpty()) continue; bots.remove(user); for (int32 j = 0, l = user->botInfo->commands.size(); j < l; ++j) { diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index dbc3cce8bd..2bda94d12a 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -6963,7 +6963,7 @@ HistoryReply::HistoryReply(History *history, HistoryBlock *block, const MTPDmess , replyToVersion(0) , _maxReplyWidth(0) { - if (!updateReplyTo()) { + if (!updateReplyTo() && App::api()) { App::api()->requestReplyTo(this, history->peer->asChannel(), replyToMsgId); } } @@ -6974,7 +6974,7 @@ HistoryReply::HistoryReply(History *history, HistoryBlock *block, MsgId msgId, i , replyToVersion(0) , _maxReplyWidth(0) { - if (!updateReplyTo()) { + if (!updateReplyTo() && App::api()) { App::api()->requestReplyTo(this, history->peer->asChannel(), replyToMsgId); } } @@ -7285,7 +7285,7 @@ void HistoryReply::getSymbol(uint16 &symbol, bool &after, bool &upon, int32 x, i HistoryReply::~HistoryReply() { if (replyToMsg) { App::historyUnregReply(this, replyToMsg); - } else if (replyToMsgId) { + } else if (replyToMsgId && App::api()) { App::api()->itemRemoved(this); } } diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 3b65aa854e..98ce73bd8d 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -75,7 +75,7 @@ HistoryInner::HistoryInner(HistoryWidget *historyWidget, ScrollArea *scroll, His _trippleClickTimer.setSingleShot(true); - if (botInfo && !botInfo->inited) { + if (botInfo && !botInfo->inited && App::api()) { App::api()->requestFullPeer(hist->peer); } @@ -2746,7 +2746,7 @@ void HistoryWidget::stickersGot(const MTPmessages_AllStickers &stickers) { } } - if (!setsToRequest.isEmpty()) { + if (!setsToRequest.isEmpty() && App::api()) { for (QMap::const_iterator i = setsToRequest.cbegin(), e = setsToRequest.cend(); i != e; ++i) { App::api()->scheduleStickerSetRequest(i.key(), i.value()); } @@ -3018,7 +3018,7 @@ void HistoryWidget::showPeerHistory(const PeerId &peerId, MsgId showAtMsgId) { } if (_replyToId) { updateReplyTo(); - if (!_replyTo) App::api()->requestReplyTo(0, _peer->asChannel(), _replyToId); + if (!_replyTo && App::api()) App::api()->requestReplyTo(0, _peer->asChannel(), _replyToId); } resizeEvent(0); if (!_previewCancelled) { @@ -5914,10 +5914,12 @@ void HistoryWidget::peerUpdated(PeerData *data) { if (data && data == _peer) { updateListSize(); if (_peer->isChannel()) updateReportSpamStatus(); - if (data->isChat() && data->asChat()->count > 0 && data->asChat()->participants.isEmpty()) { - App::api()->requestFullPeer(data); - } else if (data->isUser() && data->asUser()->blocked == UserBlockUnknown) { - App::api()->requestFullPeer(data); + if (App::api()) { + if (data->isChat() && data->asChat()->count > 0 && data->asChat()->participants.isEmpty()) { + App::api()->requestFullPeer(data); + } else if (data->isUser() && data->asUser()->blocked == UserBlockUnknown) { + App::api()->requestFullPeer(data); + } } if (!_showAnim.animating()) { bool resize = (_unblock.isHidden() == isBlocked() || (!isBlocked() && _joinChannel.isHidden() == isJoinChannel())); diff --git a/Telegram/SourceFiles/localstorage.cpp b/Telegram/SourceFiles/localstorage.cpp index ab33cec92b..8d528ea484 100644 --- a/Telegram/SourceFiles/localstorage.cpp +++ b/Telegram/SourceFiles/localstorage.cpp @@ -3112,7 +3112,7 @@ namespace Local { peers.push_back(peer); } App::emitPeerUpdated(); - App::api()->requestPeers(peers); + if (App::api()) App::api()->requestPeers(peers); } void addSavedPeer(PeerData *peer, const QDateTime &position) { diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e5db85d195..676324548a 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -4109,7 +4109,7 @@ void MainWidget::feedUpdates(const MTPUpdates &updates, uint64 randomId) { bool noFrom = !App::userLoaded(d.vfrom_id.v); if (!App::chatLoaded(d.vchat_id.v) || noFrom || (d.has_fwd_from_id() && !App::peerLoaded(peerFromMTP(d.vfwd_from_id)))) { MTP_LOG(0, ("getDifference { good - getting user for updateShortChatMessage }%1").arg(cTestMode() ? " TESTMODE" : "")); - if (noFrom) App::api()->requestFullPeer(App::chatLoaded(d.vchat_id.v)); + if (noFrom && App::api()) App::api()->requestFullPeer(App::chatLoaded(d.vchat_id.v)); return getDifference(); } @@ -4524,7 +4524,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { deleteConversation(channel, false); } else if (!channel->amCreator() && App::history(channel->id)) { // create history _updatedChannels.insert(channel, true); - App::api()->requestSelfParticipant(channel); + if (App::api()) App::api()->requestSelfParticipant(channel); } } } break; diff --git a/Telegram/SourceFiles/profilewidget.cpp b/Telegram/SourceFiles/profilewidget.cpp index df035b73b8..513b46885c 100644 --- a/Telegram/SourceFiles/profilewidget.cpp +++ b/Telegram/SourceFiles/profilewidget.cpp @@ -93,7 +93,7 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, const Pee _photoLink = TextLinkPtr(new PhotoLink(userPhoto, _peer)); } if ((_peerUser->botInfo && !_peerUser->botInfo->inited) || (_peerUser->photoId == UnknownPeerPhotoId) || (_peerUser->photoId && !userPhoto->date) || (_peerUser->blocked == UserBlockUnknown)) { - App::api()->requestFullPeer(_peer); + if (App::api()) App::api()->requestFullPeer(_peer); } } else if (_peerChat) { PhotoData *chatPhoto = (_peerChat->photoId && _peerChat->photoId != UnknownPeerPhotoId) ? App::photo(_peerChat->photoId) : 0; @@ -101,7 +101,7 @@ ProfileInner::ProfileInner(ProfileWidget *profile, ScrollArea *scroll, const Pee _photoLink = TextLinkPtr(new PhotoLink(chatPhoto, _peer)); } if (_peerChat->photoId == UnknownPeerPhotoId) { - App::api()->requestFullPeer(_peer); + if (App::api()) App::api()->requestFullPeer(_peer); } } else if (_peerChannel) { PhotoData *chatPhoto = (_peerChannel->photoId && _peerChannel->photoId != UnknownPeerPhotoId) ? App::photo(_peerChannel->photoId) : 0; @@ -607,7 +607,7 @@ void ProfileInner::reorderParticipants() { } } if (_peerChat->count > 0 && _participants.isEmpty()) { - App::api()->requestFullPeer(_peer); + if (App::api()) App::api()->requestFullPeer(_peer); if (_onlineText.isEmpty()) _onlineText = lng_chat_status_members(lt_count, _peerChat->count); } else if (onlineCount && !onlyMe) { _onlineText = lng_chat_status_members_online(lt_count, _participants.size(), lt_count_online, onlineCount); diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 7be6904b82..73b482941e 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -385,7 +385,7 @@ void ChannelData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see photoId = newPhotoId; photo = newPhoto; photoLoc = newPhotoLoc; - emit App::main()->peerPhotoChanged(this); + if (App::main()) emit App::main()->peerPhotoChanged(this); } } @@ -397,8 +397,10 @@ void ChannelData::setName(const QString &newName, const QString &usern) { void ChannelData::updateFull(bool force) { if (!_lastFullUpdate || force || getms(true) > _lastFullUpdate + UpdateFullChannelTimeout) { - App::api()->requestFullPeer(this); - if (!amCreator() && !inviter) App::api()->requestSelfParticipant(this); + if (App::api()) { + App::api()->requestFullPeer(this); + if (!amCreator() && !inviter) App::api()->requestSelfParticipant(this); + } } }