Several crashes fixed.

This commit is contained in:
John Preston 2016-04-14 22:24:42 +03:00
parent d6070c37d1
commit bb70a76b9c
22 changed files with 195 additions and 166 deletions

View File

@ -1768,22 +1768,22 @@ namespace {
void historyItemDetached(HistoryItem *item) {
if (::hoveredItem == item) {
hoveredItem(0);
hoveredItem(nullptr);
}
if (::pressedItem == item) {
pressedItem(0);
pressedItem(nullptr);
}
if (::hoveredLinkItem == item) {
hoveredLinkItem(0);
hoveredLinkItem(nullptr);
}
if (::pressedLinkItem == item) {
pressedLinkItem(0);
pressedLinkItem(nullptr);
}
if (::contextItem == item) {
contextItem(0);
contextItem(nullptr);
}
if (::mousedItem == item) {
mousedItem(0);
mousedItem(nullptr);
}
if (App::wnd()) {
App::wnd()->notifyItemRemoved(item);

View File

@ -90,14 +90,7 @@ namespace {
AppClass *AppObject = 0;
Application::Application(int &argc, char **argv) : QApplication(argc, argv)
, _secondInstance(false)
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
, _updateReply(0)
, _updateThread(0)
, _updateChecker(0)
#endif
{
Application::Application(int &argc, char **argv) : QApplication(argc, argv) {
QByteArray d(QFile::encodeName(QDir(cWorkingDir()).absolutePath()));
char h[33] = { 0 };
hashMd5Hex(d.constData(), d.size(), h);
@ -905,6 +898,12 @@ void AppClass::call_handleHistoryUpdate() {
Notify::handlePendingHistoryUpdate();
}
void AppClass::call_handleUnreadCounterUpdate() {
if (auto w = App::wnd()) {
w->updateUnreadCounter();
}
}
void AppClass::killDownloadSessions() {
uint64 ms = getms(), left = MTPAckSendWaiting + MTPKillFileSessionTimeout;
for (QMap<int32, uint64>::iterator i = killDownloadSessionTimes.begin(); i != killDownloadSessionTimes.end(); ) {

View File

@ -56,7 +56,7 @@ private:
QLocalServer _localServer;
QLocalSocket _localSocket;
LocalClients _localClients;
bool _secondInstance;
bool _secondInstance = false;
void singleInstanceChecked();
@ -98,10 +98,10 @@ public slots:
private:
SingleTimer _updateCheckTimer;
QNetworkReply *_updateReply;
QNetworkReply *_updateReply = nullptr;
QNetworkAccessManager _updateManager;
QThread *_updateThread;
UpdateChecker *_updateChecker;
QThread *_updateThread = nullptr;
UpdateChecker *_updateChecker = nullptr;
#endif
};
@ -202,6 +202,7 @@ public slots:
void onAppStateChanged(Qt::ApplicationState state);
void call_handleHistoryUpdate();
void call_handleUnreadCounterUpdate();
private:

View File

@ -124,8 +124,14 @@ void HashtagClickHandler::onClick(Qt::MouseButton button) const {
void BotCommandClickHandler::onClick(Qt::MouseButton button) const {
if (button == Qt::LeftButton || button == Qt::MiddleButton) {
if (PeerData *peer = Ui::getPeerForMouseAction()) {
UserData *bot = peer->isUser() ? peer->asUser() : nullptr;
if (auto item = App::hoveredLinkItem()) {
if (!bot) {
bot = item->fromOriginal()->asUser(); // may return nullptr
}
}
Ui::showPeerHistory(peer, ShowAtTheEndMsgId);
App::sendBotCommand(peer, _cmd);
App::sendBotCommand(peer, bot, _cmd);
} else {
App::insertBotCommand(_cmd);
}

View File

@ -132,10 +132,10 @@ QImage colorizeCircleHalf(int size, int half, int xoffset, style::color color) {
int a = color->c.alpha() + 1;
int fg_r = color->c.red() * a, fg_g = color->c.green() * a, fg_b = color->c.blue() * a, fg_a = 255 * a;
QImage result(size, size, QImage::Format_ARGB32_Premultiplied);
QImage result(half, size, QImage::Format_ARGB32_Premultiplied);
uchar *bits = result.bits(), *maskbits = unreadBadgeStyle->circle.bits();
int bpl = result.bytesPerLine(), maskbpl = unreadBadgeStyle->circle.bytesPerLine();
for (int x = 0; x < size; ++x) {
for (int x = 0; x < half; ++x) {
for (int y = 0; y < size; ++y) {
int s = y * bpl + (x * 4);
int o = maskbits[y * maskbpl + x + xoffset] + 1;

View File

@ -1028,7 +1028,7 @@ void DialogsInner::dialogsReceived(const QVector<MTPDialog> &added) {
}
}
if (App::wnd()) App::wnd()->updateCounter();
Notify::unreadCounterUpdated();
if (!_sel && !shownDialogs()->isEmpty()) {
_sel = *shownDialogs()->cbegin();
_importantSwitchSel = false;
@ -1936,7 +1936,7 @@ void DialogsWidget::unreadCountsReceived(const QVector<MTPDialog> &dialogs) {
if (History *h = App::historyLoaded(peerFromMTP(d.vpeer))) {
App::main()->applyNotifySetting(MTP_notifyPeer(d.vpeer), d.vnotify_settings, h);
if (d.vunread_count.v >= h->unreadCount()) {
h->setUnreadCount(d.vunread_count.v, false);
h->setUnreadCount(d.vunread_count.v);
h->inboxReadBefore = d.vread_inbox_max_id.v + 1;
}
}
@ -1954,14 +1954,13 @@ void DialogsWidget::unreadCountsReceived(const QVector<MTPDialog> &dialogs) {
App::main()->applyNotifySetting(MTP_notifyPeer(d.vpeer), d.vnotify_settings, h);
int32 unreadCount = h->isMegagroup() ? d.vunread_count.v : d.vunread_important_count.v;
if (unreadCount >= h->unreadCount()) {
h->setUnreadCount(unreadCount, false);
h->setUnreadCount(unreadCount);
h->inboxReadBefore = d.vread_inbox_max_id.v + 1;
}
}
} break;
}
}
if (App::wnd()) App::wnd()->updateCounter();
}
void DialogsWidget::dialogsReceived(const MTPmessages_Dialogs &dialogs, mtpRequestId req) {

View File

@ -33,12 +33,16 @@ Q_DECLARE_METATYPE(Qt::MouseButton);
namespace App {
void sendBotCommand(PeerData *peer, const QString &cmd, MsgId replyTo) {
if (MainWidget *m = main()) m->sendBotCommand(peer, cmd, replyTo);
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) {
if (auto m = main()) {
m->sendBotCommand(peer, bot, cmd, replyTo);
}
}
bool insertBotCommand(const QString &cmd, bool specialGif) {
if (MainWidget *m = main()) return m->insertBotCommand(cmd, specialGif);
if (auto m = main()) {
return m->insertBotCommand(cmd, specialGif);
}
return false;
}
@ -59,7 +63,7 @@ void activateBotCommand(const HistoryItem *msg, int row, int col) {
// Copy string before passing it to the sending method
// because the original button can be destroyed inside.
MsgId replyTo = (msg->id > 0) ? msg->id : 0;
sendBotCommand(msg->history()->peer, QString(button->text), replyTo);
sendBotCommand(msg->history()->peer, msg->fromOriginal()->asUser(), QString(button->text), replyTo);
} break;
case HistoryMessageReplyMarkup::Button::Callback: {
@ -326,6 +330,10 @@ void handlePendingHistoryUpdate() {
Global::RefPendingRepaintItems().clear();
}
void unreadCounterUpdated() {
Global::RefHandleUnreadCounterUpdate().call();
}
} // namespace Notify
#define DefineReadOnlyVar(Namespace, Type, Name) const Type &Name() { \
@ -479,6 +487,7 @@ namespace internal {
struct Data {
uint64 LaunchId = 0;
SingleDelayedCall HandleHistoryUpdate = { App::app(), "call_handleHistoryUpdate" };
SingleDelayedCall HandleUnreadCounterUpdate = { App::app(), "call_handleUnreadCounterUpdate" };
Adaptive::Layout AdaptiveLayout = Adaptive::NormalLayout;
bool AdaptiveForWide = true;
@ -541,6 +550,7 @@ void finish() {
DefineReadOnlyVar(Global, uint64, LaunchId);
DefineRefVar(Global, SingleDelayedCall, HandleHistoryUpdate);
DefineRefVar(Global, SingleDelayedCall, HandleUnreadCounterUpdate);
DefineVar(Global, Adaptive::Layout, AdaptiveLayout);
DefineVar(Global, bool, AdaptiveForWide);

View File

@ -24,7 +24,7 @@ class LayeredWidget;
namespace App {
void sendBotCommand(PeerData *peer, const QString &cmd, MsgId replyTo = 0);
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo = 0);
bool insertBotCommand(const QString &cmd, bool specialGif = false);
void activateBotCommand(const HistoryItem *msg, int row, int col);
void searchByHashtag(const QString &tag, PeerData *inPeer);
@ -116,6 +116,7 @@ void historyMuteUpdated(History *history);
// handle pending resize() / paint() on history items
void handlePendingHistoryUpdate();
void unreadCounterUpdated();
} // namespace Notify
@ -184,6 +185,7 @@ void finish();
DeclareReadOnlyVar(uint64, LaunchId);
DeclareRefVar(SingleDelayedCall, HandleHistoryUpdate);
DeclareRefVar(SingleDelayedCall, HandleUnreadCounterUpdate);
DeclareVar(Adaptive::Layout, AdaptiveLayout);
DeclareVar(bool, AdaptiveForWide);

View File

@ -325,9 +325,7 @@ void ChannelHistory::insertCollapseItem(MsgId wasMinId) {
HistoryItem *item = block->items.at(itemIndex);
if (insertAfter || item->id > wasMinId || (item->id == wasMinId && !item->isImportant())) {
_collapseMessage = HistoryCollapse::create((History*)this, wasMinId, item->date);
if (!addNewInTheMiddle(_collapseMessage, blockIndex, itemIndex)) {
_collapseMessage = 0;
}
addNewInTheMiddle(_collapseMessage, blockIndex, itemIndex);
return;
} else if (item->id == wasMinId && item->isImportant()) {
insertAfter = true;
@ -663,16 +661,19 @@ void ChannelHistory::switchMode() {
checkJoinedMessage();
}
void ChannelHistory::cleared() {
_collapseMessage = 0;
_joinedMessage = 0;
void ChannelHistory::cleared(bool leaveItems) {
_collapseMessage = nullptr;
_joinedMessage = nullptr;
if (!leaveItems) {
_otherList.clear();
}
}
HistoryGroup *ChannelHistory::findGroup(MsgId msgId) const { // find message group using binary search
if (!_onlyImportant) return findGroupInOther(msgId);
HistoryBlock *block = findGroupBlock(msgId);
if (!block) return 0;
if (!block) return nullptr;
int32 itemIndex = 0;
if (block->items.size() > 1) for (int32 minItem = 0, maxItem = block->items.size();;) {
@ -698,10 +699,14 @@ HistoryGroup *ChannelHistory::findGroup(MsgId msgId) const { // find message gro
}
}
HistoryItem *item = block->items.at(itemIndex);
if (item->type() != HistoryItemGroup) return 0;
HistoryGroup *result = static_cast<HistoryGroup*>(item);
return (result->minId() < msgId && result->maxId() > msgId) ? result : 0;
auto item = block->items.at(itemIndex);
if (item->type() == HistoryItemGroup) {
auto result = static_cast<HistoryGroup*>(item);
if (result->minId() < msgId && result->maxId() > msgId) {
return result;
}
}
return nullptr;
}
HistoryBlock *ChannelHistory::findGroupBlock(MsgId msgId) const { // find block with message group using binary search
@ -838,7 +843,7 @@ History *Histories::findOrInsert(const PeerId &peerId, int32 unreadCount, int32
Map::const_iterator i = map.constFind(peerId);
if (i == map.cend()) {
i = map.insert(peerId, peerIsChannel(peerId) ? static_cast<History*>(new ChannelHistory(peerId)) : (new History(peerId)));
i.value()->setUnreadCount(unreadCount, false);
i.value()->setUnreadCount(unreadCount);
i.value()->inboxReadBefore = maxInboxRead + 1;
}
return i.value();
@ -846,18 +851,17 @@ History *Histories::findOrInsert(const PeerId &peerId, int32 unreadCount, int32
void Histories::clear() {
App::historyClearMsgs();
for (Map::const_iterator i = map.cbegin(), e = map.cend(); i != e; ++i) {
delete i.value();
Map temp;
std::swap(temp, map);
for_const (auto history, temp) {
delete history;
}
Global::RefPendingRepaintItems().clear();
_unreadFull = _unreadMuted = 0;
if (App::wnd()) {
App::wnd()->updateCounter();
}
Notify::unreadCounterUpdated();
App::historyClearItems();
typing.clear();
map.clear();
}
void Histories::regSendAction(History *history, UserData *user, const MTPSendMessageAction &action) {
@ -1742,7 +1746,7 @@ HistoryItem *History::lastImportantMessage() const {
return nullptr;
}
void History::setUnreadCount(int newUnreadCount, bool psUpdate) {
void History::setUnreadCount(int newUnreadCount) {
if (_unreadCount != newUnreadCount) {
if (newUnreadCount == 1) {
if (loadedAtBottom()) showFrom = lastImportantMessage();
@ -1753,8 +1757,8 @@ void History::setUnreadCount(int newUnreadCount, bool psUpdate) {
}
if (inChatList(Dialogs::Mode::All)) {
App::histories().unreadIncrement(newUnreadCount - _unreadCount, mute());
if (psUpdate && (!mute() || cIncludeMuted()) && App::wnd()) {
App::wnd()->updateCounter();
if (!mute() || cIncludeMuted()) {
Notify::unreadCounterUpdated();
}
}
_unreadCount = newUnreadCount;
@ -1780,7 +1784,7 @@ void History::setUnreadCount(int newUnreadCount, bool psUpdate) {
if (inChatList(Dialogs::Mode::All)) {
if (_unreadCount) {
App::histories().unreadMuteChanged(_unreadCount, newMute);
if (App::wnd()) App::wnd()->updateCounter();
Notify::unreadCounterUpdated();
}
Notify::historyMuteUpdated(this);
}
@ -2179,6 +2183,15 @@ void History::clear(bool leaveItems) {
}
if (!leaveItems) {
setLastMessage(nullptr);
notifies.clear();
auto &pending = Global::RefPendingRepaintItems();
for (auto i = pending.begin(); i != pending.end();) {
if ((*i)->history() == this) {
i = pending.erase(i);
} else {
++i;
}
}
}
for (int32 i = 0; i < OverviewCount; ++i) {
if (!overview[i].isEmpty() || !overviewIds[i].isEmpty()) {
@ -2199,6 +2212,10 @@ void History::clear(bool leaveItems) {
lastKeyboardInited = false;
} else {
setUnreadCount(0);
if (peer->isMegagroup()) {
peer->asChannel()->mgInfo->pinnedMsgId = 0;
}
clearLastKeyboard();
}
setPendingResize();
@ -2209,7 +2226,7 @@ void History::clear(bool leaveItems) {
peer->asChat()->lastAuthors.clear();
peer->asChat()->markupSenders.clear();
} else if (isChannel()) {
asChannelHistory()->cleared();
asChannelHistory()->cleared(leaveItems);
if (isMegagroup()) {
peer->asChannel()->mgInfo->markupSenders.clear();
}
@ -2251,7 +2268,7 @@ Dialogs::Row *History::addToChatList(Dialogs::Mode list, Dialogs::IndexedList *i
chatListLinks(list) = indexed->addToEnd(this);
if (list == Dialogs::Mode::All && unreadCount()) {
App::histories().unreadIncrement(unreadCount(), mute());
if (App::wnd()) App::wnd()->updateCounter();
Notify::unreadCounterUpdated();
}
}
return mainChatListLink(list);
@ -2264,7 +2281,7 @@ void History::removeFromChatList(Dialogs::Mode list, Dialogs::IndexedList *index
chatListLinks(list).clear();
if (list == Dialogs::Mode::All && unreadCount()) {
App::histories().unreadIncrement(-unreadCount(), mute());
if (App::wnd()) App::wnd()->updateCounter();
Notify::unreadCounterUpdated();
}
}
}
@ -2994,6 +3011,7 @@ void HistoryItem::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pres
}
void HistoryItem::destroy() {
// All this must be done for all items manually in History::clear(false)!
bool wasAtBottom = history()->loadedAtBottom();
_history->removeNotification(this);
detach();

View File

@ -255,7 +255,7 @@ public:
int unreadCount() const {
return _unreadCount;
}
void setUnreadCount(int newUnreadCount, bool psUpdate = true);
void setUnreadCount(int newUnreadCount);
bool mute() const {
return _mute;
}
@ -642,7 +642,7 @@ private:
HistoryItem *findPrevItem(HistoryItem *item) const;
void switchMode();
void cleared();
void cleared(bool leaveItems);
bool _onlyImportant;
@ -2637,7 +2637,7 @@ public:
HistoryItem::clickHandlerActiveChanged(p, active);
}
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override {
if (_media) _media->clickHandlerActiveChanged(p, pressed);
if (_media) _media->clickHandlerPressedChanged(p, pressed);
HistoryItem::clickHandlerPressedChanged(p, pressed);
}

View File

@ -2260,8 +2260,7 @@ void BotKeyboard::enterEvent(QEvent *e) {
}
void BotKeyboard::leaveEvent(QEvent *e) {
_lastMousePos = QPoint(-1, -1);
updateSelected();
clearSelection();
}
void BotKeyboard::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
@ -2275,44 +2274,43 @@ void BotKeyboard::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pres
}
bool BotKeyboard::updateMarkup(HistoryItem *to, bool force) {
if (to && to->definesReplyKeyboard()) {
if (_wasForMsgId == FullMsgId(to->channelId(), to->id) && !force) {
return false;
if (!to || !to->definesReplyKeyboard()) {
if (_wasForMsgId.msg) {
_maximizeSize = _singleUse = _forceReply = false;
_wasForMsgId = FullMsgId();
_impl = nullptr;
return true;
}
_wasForMsgId = FullMsgId(to->channelId(), to->id);
clearSelection();
auto markupFlags = to->replyKeyboardFlags();
_forceReply = markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
_maximizeSize = !(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_resize);
_singleUse = _forceReply || (markupFlags & MTPDreplyKeyboardMarkup::Flag::f_single_use);
_impl = nullptr;
if (auto markup = to->Get<HistoryMessageReplyMarkup>()) {
if (!markup->rows.isEmpty()) {
_impl.reset(new ReplyKeyboard(to, std_::make_unique<Style>(this, *_st)));
}
}
updateStyle();
_height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0);
if (_maximizeSize) _height = qMax(_height, _maxOuterHeight);
if (height() != _height) {
resize(width(), _height);
} else {
resizeEvent(0);
}
return true;
return false;
}
if (_wasForMsgId.msg) {
_maximizeSize = _singleUse = _forceReply = false;
_wasForMsgId = FullMsgId();
clearSelection();
_impl = nullptr;
return true;
if (_wasForMsgId == FullMsgId(to->channelId(), to->id) && !force) {
return false;
}
return false;
_wasForMsgId = FullMsgId(to->channelId(), to->id);
auto markupFlags = to->replyKeyboardFlags();
_forceReply = markupFlags & MTPDreplyKeyboardMarkup_ClientFlag::f_force_reply;
_maximizeSize = !(markupFlags & MTPDreplyKeyboardMarkup::Flag::f_resize);
_singleUse = _forceReply || (markupFlags & MTPDreplyKeyboardMarkup::Flag::f_single_use);
_impl = nullptr;
if (auto markup = to->Get<HistoryMessageReplyMarkup>()) {
if (!markup->rows.isEmpty()) {
_impl.reset(new ReplyKeyboard(to, std_::make_unique<Style>(this, *_st)));
}
}
updateStyle();
_height = st::botKbScroll.deltat + st::botKbScroll.deltab + (_impl ? _impl->naturalHeight() : 0);
if (_maximizeSize) _height = qMax(_height, _maxOuterHeight);
if (height() != _height) {
resize(width(), _height);
} else {
resizeEvent(nullptr);
}
return true;
}
bool BotKeyboard::hasMarkup() const {
@ -2351,7 +2349,10 @@ void BotKeyboard::updateStyle(int32 w) {
void BotKeyboard::clearSelection() {
if (_impl) {
_impl->clearSelection();
if (ClickHandler::setActive(ClickHandlerPtr(), this)) {
PopupTooltip::Hide();
setCursor(style::cur_default);
}
}
}
@ -2908,7 +2909,7 @@ void HistoryWidget::onStickersUpdated() {
void HistoryWidget::onMentionHashtagOrBotCommandInsert(QString str) {
if (str.at(0) == '/') { // bot command
App::sendBotCommand(_peer, str);
App::sendBotCommand(_peer, nullptr, str);
setFieldText(_field.getLastText().mid(_field.textCursor().position()));
} else {
_field.onMentionHashtagOrBotCommandInsert(str);
@ -4852,7 +4853,7 @@ void HistoryWidget::onBotStart() {
QString token = _peer->asUser()->botInfo->startToken;
if (token.isEmpty()) {
sendBotCommand(_peer, qsl("/start"), 0);
sendBotCommand(_peer, _peer->asUser(), qsl("/start"), 0);
} else {
uint64 randomId = rand_value<uint64>();
MTP::send(MTPmessages_StartBot(_peer->asUser()->inputUser, MTP_inputPeerEmpty(), MTP_long(randomId), MTP_string(token)), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::addParticipantFail, _peer->asUser()));
@ -5286,14 +5287,15 @@ void HistoryWidget::stopRecording(bool send) {
_a_record.start();
}
void HistoryWidget::sendBotCommand(PeerData *peer, const QString &cmd, MsgId replyTo) { // replyTo != 0 from ReplyKeyboardMarkup, == 0 from cmd links
void HistoryWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) { // replyTo != 0 from ReplyKeyboardMarkup, == 0 from cmd links
if (!_peer || _peer != peer) return;
bool lastKeyboardUsed = (_keyboard.forMsgId() == FullMsgId(_channel, _history->lastKeyboardId)) && (_keyboard.forMsgId() == FullMsgId(_channel, replyTo));
QString toSend = cmd;
PeerData *bot = _peer->isUser() ? _peer : (App::hoveredLinkItem() ? App::hoveredLinkItem()->fromOriginal() : 0);
if (bot && (!bot->isUser() || !bot->asUser()->botInfo)) bot = 0;
if (bot && (!bot->isUser() || !bot->asUser()->botInfo)) {
bot = nullptr;
}
QString username = bot ? bot->asUser()->username : QString();
int32 botStatus = _peer->isChat() ? _peer->asChat()->botStatus : (_peer->isMegagroup() ? _peer->asChannel()->mgInfo->botStatus : -1);
if (!replyTo && toSend.indexOf('@') < 2 && !username.isEmpty() && (botStatus == 0 || botStatus == 2)) {

View File

@ -622,7 +622,7 @@ public:
void onListEscapePressed();
void sendBotCommand(PeerData *peer, const QString &cmd, MsgId replyTo);
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo);
bool insertBotCommand(const QString &cmd, bool specialGif);
bool eventFilter(QObject *obj, QEvent *e) override;

View File

@ -35,45 +35,18 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "application.h"
#include "ui/text/text.h"
namespace {
IntroWidget *signalEmitOn = 0;
QString countryForReg;
void gotNearestDC(const MTPNearestDc &result) {
const auto &nearest(result.c_nearestDc());
DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3").arg(nearest.vcountry.c_string().v.c_str()).arg(nearest.vnearest_dc.v).arg(nearest.vthis_dc.v));
MTP::setdc(result.c_nearestDc().vnearest_dc.v, true);
if (countryForReg != nearest.vcountry.c_string().v.c_str()) {
countryForReg = nearest.vcountry.c_string().v.c_str();
emit signalEmitOn->countryChanged();
}
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
Sandbox::startUpdateCheck();
#endif
}
}
IntroWidget::IntroWidget(QWidget *parent) : TWidget(parent)
, _langChangeTo(0)
, _a_stage(animation(this, &IntroWidget::step_stage))
, _cacheHideIndex(0)
, _cacheShowIndex(0)
, _a_show(animation(this, &IntroWidget::step_show))
, _callStatus({ CallDisabled, 0 })
, _registered(false)
, _hasRecovery(false)
, _codeByTelegram(false)
, _back(this, st::setClose)
, _backFrom(0)
, _backTo(0) {
, _back(this, st::setClose) {
setGeometry(QRect(0, st::titleHeight, App::wnd()->width(), App::wnd()->height() - st::titleHeight));
connect(&_back, SIGNAL(clicked()), this, SLOT(onBack()));
_back.hide();
countryForReg = psCurrentCountry();
_countryForReg = psCurrentCountry();
MTP::send(MTPhelp_GetNearestDc(), rpcDone(gotNearestDC));
signalEmitOn = this;
MTP::send(MTPhelp_GetNearestDc(), rpcDone(&IntroWidget::gotNearestDC));
_stepHistory.push_back(new IntroStart(this));
_back.raise();
@ -86,6 +59,10 @@ IntroWidget::IntroWidget(QWidget *parent) : TWidget(parent)
cSetPasswordRecovered(false);
_back.move(st::setClosePos.x(), st::setClosePos.y());
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
Sandbox::startUpdateCheck();
#endif
}
void IntroWidget::langChangeTo(int32 langId) {
@ -173,6 +150,16 @@ void IntroWidget::pushStep(IntroStep *step, MoveType type) {
historyMove(type);
}
void IntroWidget::gotNearestDC(const MTPNearestDc &result) {
const auto &nearest(result.c_nearestDc());
DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3").arg(nearest.vcountry.c_string().v.c_str()).arg(nearest.vnearest_dc.v).arg(nearest.vthis_dc.v));
MTP::setdc(result.c_nearestDc().vnearest_dc.v, true);
if (_countryForReg != nearest.vcountry.c_string().v.c_str()) {
_countryForReg = nearest.vcountry.c_string().v.c_str();
emit countryChanged();
}
}
QPixmap IntroWidget::grabStep(int skip) {
return myGrab(step(skip), QRect(st::introSlideShift, 0, st::introSize.width(), st::introSize.height()));
}
@ -297,7 +284,7 @@ QRect IntroWidget::innerRect() const {
}
QString IntroWidget::currentCountry() const {
return countryForReg;
return _countryForReg;
}
void IntroWidget::setPhone(const QString &phone, const QString &phone_hash, bool registered) {

View File

@ -20,8 +20,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/
#pragma once
#include "mtproto/rpc_sender.h"
class IntroStep;
class IntroWidget final : public TWidget {
class IntroWidget : public TWidget, public RPCSender {
Q_OBJECT
public:
@ -99,11 +101,12 @@ private:
QPixmap grabStep(int skip = 0);
int _langChangeTo;
int _langChangeTo = 0;
Animation _a_stage;
QPixmap _cacheHide, _cacheShow;
int _cacheHideIndex, _cacheShowIndex;
int _cacheHideIndex = 0;
int _cacheShowIndex = 0;
anim::ivalue a_coordHide, a_coordShow;
anim::fvalue a_opacityHide, a_opacityShow;
@ -125,20 +128,26 @@ private:
void historyMove(MoveType type);
void pushStep(IntroStep *step, MoveType type);
void gotNearestDC(const MTPNearestDc &dc);
QString _countryForReg;
QString _phone, _phone_hash;
CallStatus _callStatus;
bool _registered;
CallStatus _callStatus = { CallDisabled, 0 };
bool _registered = false;
QString _code;
QByteArray _pwdSalt;
bool _hasRecovery, _codeByTelegram;
bool _hasRecovery = false;
bool _codeByTelegram = false;
QString _pwdHint;
QString _firstname, _lastname;
IconedButton _back;
float64 _backFrom, _backTo;
float64 _backFrom = 0.;
float64 _backTo = 0.;
};

View File

@ -113,6 +113,10 @@ MainWidget::MainWidget(MainWindow *window) : TWidget(window)
setFocus();
_api->init();
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
Sandbox::startUpdateCheck();
#endif
}
bool MainWidget::onForward(const PeerId &peer, ForwardWhatMessages what) {
@ -1205,8 +1209,8 @@ void MainWidget::stopAnimActive() {
_history->stopAnimActive();
}
void MainWidget::sendBotCommand(PeerData *peer, const QString &cmd, MsgId replyTo) {
_history->sendBotCommand(peer, cmd, replyTo);
void MainWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) {
_history->sendBotCommand(peer, bot, cmd, replyTo);
}
void MainWidget::app_sendBotCallback(const HistoryMessageReplyMarkup::Button *button, const HistoryItem *msg, int row, int col) {
@ -2781,7 +2785,7 @@ void MainWidget::gotChannelDifference(ChannelData *channel, const MTPupdates_Cha
}
int32 unreadCount = h->isMegagroup() ? d.vunread_count.v : d.vunread_important_count.v;
if (unreadCount >= h->unreadCount()) {
h->setUnreadCount(unreadCount, false);
h->setUnreadCount(unreadCount);
h->inboxReadBefore = d.vread_inbox_max_id.v + 1;
}
if (d.vunread_count.v >= h->asChannelHistory()->unreadCountAll) {
@ -3212,9 +3216,6 @@ void MainWidget::start(const MTPUser &user) {
cSetOtherOnline(0);
App::feedUsers(MTP_vector<MTPUser>(1, user));
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
Sandbox::startUpdateCheck();
#endif
MTP::send(MTPupdates_GetState(), rpcDone(&MainWidget::gotState));
update();
if (!cStartUrl().isEmpty()) {

View File

@ -289,7 +289,7 @@ public:
uint64 animActiveTimeStart(const HistoryItem *msg) const;
void stopAnimActive();
void sendBotCommand(PeerData *peer, const QString &cmd, MsgId replyTo);
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo);
bool insertBotCommand(const QString &cmd, bool specialGif);
void searchMessages(const QString &query, PeerData *inPeer);

View File

@ -673,11 +673,11 @@ void MainWindow::setupMain(bool anim, const MTPUser *self) {
_mediaView = new MediaView();
}
void MainWindow::updateCounter() {
void MainWindow::updateUnreadCounter() {
if (!Global::started() || App::quitting()) return;
psUpdateCounter();
title->updateCounter();
psUpdateCounter();
}
void MainWindow::showSettings() {
@ -1180,11 +1180,7 @@ void MainWindow::onLogout() {
}
void MainWindow::onLogoutSure() {
if (MTP::authedId()) {
App::logOut();
} else {
setupIntro(true);
}
App::logOut();
}
void MainWindow::updateGlobalMenu() {
@ -1254,7 +1250,7 @@ void MainWindow::showFromTray(QSystemTrayIcon::ActivationReason reason) {
QTimer::singleShot(1, this, SLOT(updateTrayMenu()));
QTimer::singleShot(1, this, SLOT(updateGlobalMenu()));
activate();
updateCounter();
Notify::unreadCounterUpdated();
}
}

View File

@ -228,6 +228,8 @@ public:
bool isActive(bool cached = true) const;
void hideMediaview();
void updateUnreadCounter();
bool contentOverlapped(const QRect &globalRect);
bool contentOverlapped(QWidget *w, QPaintEvent *e) {
return contentOverlapped(QRect(w->mapToGlobal(e->rect().topLeft()), e->rect().size()));
@ -250,7 +252,6 @@ public slots:
void stateChanged(Qt::WindowState state);
void checkHistoryActivation();
void updateCounter();
void checkAutoLock();

View File

@ -575,7 +575,7 @@ void ProfileInner::onBotSettings() {
QString cmd = _peerUser->botInfo->commands.at(i).command;
if (!cmd.compare(qsl("settings"), Qt::CaseInsensitive)) {
Ui::showPeerHistory(_peer, ShowAtTheEndMsgId);
App::sendBotCommand(_peerUser, '/' + cmd);
App::sendBotCommand(_peerUser, _peerUser, '/' + cmd);
return;
}
}
@ -589,7 +589,7 @@ void ProfileInner::onBotHelp() {
QString cmd = _peerUser->botInfo->commands.at(i).command;
if (!cmd.compare(qsl("help"), Qt::CaseInsensitive)) {
Ui::showPeerHistory(_peer, ShowAtTheEndMsgId);
App::sendBotCommand(_peerUser, '/' + cmd);
App::sendBotCommand(_peerUser, _peerUser, '/' + cmd);
return;
}
}

View File

@ -57,9 +57,7 @@ void MacPrivate::activeSpaceChanged() {
}
void MacPrivate::darkModeChanged() {
if (App::wnd()) {
App::wnd()->updateCounter();
}
Notify::unreadCounterUpdated();
}
void MacPrivate::notifyClicked(unsigned long long peer, int msgid) {

View File

@ -1515,7 +1515,7 @@ void SettingsInner::onSoundNotify() {
void SettingsInner::onIncludeMuted() {
cSetIncludeMuted(_includeMuted.checked());
if (App::wnd()) App::wnd()->updateCounter();
Notify::unreadCounterUpdated();
Local::writeUserSettings();
}

View File

@ -155,9 +155,9 @@ public:
return getState(rtl() ? (outerw - x - width) : x, y, width, request);
}
struct StateRequestElided : public StateRequest {
StateRequestElided() {
}
StateRequestElided(const StateRequest &other) : StateRequest(other) {
StateRequestElided() {
}
StateRequestElided(const StateRequest &other) : StateRequest(other) {
}
int lines = 1;
int removeFromEnd = 0;