From 35d5089f48970bd838f889f131bbc0b84cb741dc Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 8 Apr 2016 13:20:10 +0400 Subject: [PATCH] Scroll following the inline bot keyboard when message is edited. --- Telegram/SourceFiles/app.cpp | 8 +- Telegram/SourceFiles/facades.cpp | 6 + Telegram/SourceFiles/facades.h | 1 + Telegram/SourceFiles/history.cpp | 219 ++++++++++++++----------- Telegram/SourceFiles/history.h | 6 +- Telegram/SourceFiles/historywidget.cpp | 40 ++++- Telegram/SourceFiles/historywidget.h | 10 +- Telegram/SourceFiles/layout.cpp | 22 +-- Telegram/SourceFiles/mainwidget.cpp | 34 +--- Telegram/SourceFiles/mainwidget.h | 55 ++++--- Telegram/SourceFiles/structs.cpp | 4 +- Telegram/SourceFiles/structs.h | 4 +- 12 files changed, 232 insertions(+), 177 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 901fc71c8..1e11d8a5a 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1614,7 +1614,7 @@ namespace { return i.value(); } - WebPageData *webPageSet(const WebPageId &webPage, WebPageData *convert, const QString &type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill) { + WebPageData *webPageSet(const WebPageId &webPage, WebPageData *convert, const QString &type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *document, int32 duration, const QString &author, int32 pendingTill) { if (convert) { if (convert->id != webPage) { WebPagesData::iterator i = webPagesData.find(convert->id); @@ -1631,7 +1631,7 @@ namespace { convert->title = title; convert->description = description; convert->photo = photo; - convert->doc = doc; + convert->document = document; convert->duration = duration; convert->author = author; if (convert->pendingTill > 0 && pendingTill <= 0 && api()) api()->clearWebPageRequest(convert); @@ -1645,7 +1645,7 @@ namespace { if (convert) { result = convert; } else { - result = new WebPageData(webPage, toWebPageType(type), url, displayUrl, siteName, title, description, photo, doc, duration, author, (pendingTill >= -1) ? pendingTill : -1); + result = new WebPageData(webPage, toWebPageType(type), url, displayUrl, siteName, title, description, document, photo, duration, author, (pendingTill >= -1) ? pendingTill : -1); if (pendingTill > 0 && api()) { api()->requestWebPageDelayed(result); } @@ -1662,7 +1662,7 @@ namespace { result->title = title; result->description = description; result->photo = photo; - result->doc = doc; + result->document = document; result->duration = duration; result->author = author; if (result->pendingTill > 0 && pendingTill <= 0 && api()) api()->clearWebPageRequest(result); diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index fb2bf04e5..268b64d39 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -260,6 +260,12 @@ namespace Notify { } } + void inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { + if (MainWidget *m = App::main()) { + m->notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop); + } + } + void migrateUpdated(PeerData *peer) { if (MainWidget *m = App::main()) m->notify_migrateUpdated(peer); } diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 8adec8d7f..f6a83571d 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -102,6 +102,7 @@ namespace Notify { void inlineBotRequesting(bool requesting); void replyMarkupUpdated(const HistoryItem *item); + void inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop); void migrateUpdated(PeerData *peer); diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index b0ba36dd5..cdb061ff5 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -2373,7 +2373,7 @@ MsgId History::msgIdForRead() const { } int History::resizeGetHeight(int newWidth) { - bool resizeAllItems = (_flags | Flag::f_pending_resize) || (width != newWidth); + bool resizeAllItems = (_flags & Flag::f_pending_resize) || (width != newWidth); if (!resizeAllItems && !hasPendingResizedItems()) { return height; @@ -2758,7 +2758,7 @@ public: // Note: it is possible that we will point to the different button // than the one was used when constructing the handler, but not a big deal. const HistoryMessageReplyMarkup::Button *getButton() const { - if (auto *markup = _item->Get()) { + if (auto markup = _item->Get()) { if (_row < markup->rows.size()) { const HistoryMessageReplyMarkup::ButtonRow &row(markup->rows.at(_row)); if (_col < row.size()) { @@ -2793,7 +2793,7 @@ ReplyKeyboard::ReplyKeyboard(const HistoryItem *item, StylePtr &&s) : _item(item) , _a_selected(animation(this, &ReplyKeyboard::step_selected)) , _st(std_::forward(s)) { - if (auto *markup = item->Get()) { + if (auto markup = item->Get()) { _rows.reserve(markup->rows.size()); for (int i = 0, l = markup->rows.size(); i != l; ++i) { const HistoryMessageReplyMarkup::ButtonRow &row(markup->rows.at(i)); @@ -2815,7 +2815,7 @@ ReplyKeyboard::ReplyKeyboard(const HistoryItem *item, StylePtr &&s) void ReplyKeyboard::resize(int width, int height) { _width = width; - auto *markup = _item->Get(); + auto markup = _item->Get(); float64 y = 0, buttonHeight = _rows.isEmpty() ? _st->buttonHeight() : (float64(height + _st->buttonSkip()) / _rows.size()); for (ButtonRow &row : _rows) { int s = row.size(); @@ -2868,7 +2868,7 @@ void ReplyKeyboard::setStyle(StylePtr &&st) { int ReplyKeyboard::naturalWidth() const { int result = 0; - auto *markup = _item->Get(); + auto markup = _item->Get(); for_const (const ButtonRow &row, _rows) { int rowSize = row.size(); int rowWidth = (rowSize - 1) * _st->buttonSkip() + rowSize * 2 * _st->buttonPadding(); @@ -3177,7 +3177,7 @@ void HistoryItem::finishCreate() { } void HistoryItem::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) { - if (auto *markup = Get()) { + if (auto markup = Get()) { if (markup->inlineKeyboard) { markup->inlineKeyboard->clickHandlerActiveChanged(p, active); } @@ -3187,7 +3187,7 @@ void HistoryItem::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool activ } void HistoryItem::clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) { - if (auto *markup = Get()) { + if (auto markup = Get()) { if (markup->inlineKeyboard) { markup->inlineKeyboard->clickHandlerPressedChanged(p, pressed); } @@ -3337,7 +3337,7 @@ void HistoryItem::setUnreadBarCount(int count) { } void HistoryItem::setUnreadBarFreezed() { - if (auto *bar = Get()) { + if (auto bar = Get()) { bar->_freezed = true; } } @@ -4204,7 +4204,7 @@ HistoryDocument::HistoryDocument(DocumentData *document, const QString &caption, , _parent(nullptr) , _data(document) { createComponents(!caption.isEmpty()); - if (auto *named = Get()) { + if (auto named = Get()) { named->_name = documentName(_data); named->_namew = st::semiboldFont->width(named->_name); } @@ -4213,7 +4213,7 @@ HistoryDocument::HistoryDocument(DocumentData *document, const QString &caption, setStatusSize(FileStatusSizeReady); - if (auto *captioned = Get()) { + if (auto captioned = Get()) { captioned->_caption.setText(st::msgFont, caption + parent->skipBlock(), itemTextNoMonoOptions(parent)); } } @@ -4222,10 +4222,10 @@ HistoryDocument::HistoryDocument(const HistoryDocument &other) : HistoryFileMedi , Composer() , _parent(nullptr) , _data(other._data) { - auto *captioned = other.Get(); + auto captioned = other.Get(); createComponents(captioned != 0); - if (auto *named = Get()) { - if (auto *othernamed = other.Get()) { + if (auto named = Get()) { + if (auto othernamed = other.Get()) { named->_name = othernamed->_name; named->_namew = othernamed->_namew; } else { @@ -4257,7 +4257,7 @@ void HistoryDocument::createComponents(bool caption) { mask |= HistoryDocumentCaptioned::Bit(); } UpdateComponents(mask); - if (auto *thumbed = Get()) { + if (auto thumbed = Get()) { thumbed->_linksavel.reset(new DocumentSaveClickHandler(_data)); thumbed->_linkcancell.reset(new DocumentCancelClickHandler(_data)); } @@ -4266,12 +4266,12 @@ void HistoryDocument::createComponents(bool caption) { void HistoryDocument::initDimensions(const HistoryItem *parent) { _parent = parent; - auto *captioned = Get(); + auto captioned = Get(); if (captioned && captioned->_caption.hasSkipBlock()) { captioned->_caption.setSkipBlock(parent->skipBlockWidth(), parent->skipBlockHeight()); } - auto *thumbed = Get(); + auto thumbed = Get(); if (thumbed) { _data->thumb->load(); int32 tw = convertScale(_data->thumb->width()), th = convertScale(_data->thumb->height()); @@ -4296,7 +4296,7 @@ void HistoryDocument::initDimensions(const HistoryItem *parent) { _maxw = qMax(_maxw, tleft + documentMaxStatusWidth(_data) + unread + parent->skipBlockWidth() + st::msgPadding.right()); } - if (auto *named = Get()) { + if (auto named = Get()) { _maxw = qMax(tleft + named->_namew + tright, _maxw); _maxw = qMin(_maxw, int(st::msgMaxWidth)); } @@ -4318,7 +4318,7 @@ void HistoryDocument::initDimensions(const HistoryItem *parent) { } int HistoryDocument::resizeGetHeight(int width, const HistoryItem *parent) { - auto *captioned = Get(); + auto captioned = Get(); if (!captioned) { return HistoryFileMedia::resizeGetHeight(width, parent); } @@ -4354,7 +4354,7 @@ void HistoryDocument::draw(Painter &p, const HistoryItem *parent, const QRect &r bool radial = isRadialAnimation(ms); int nameleft = 0, nametop = 0, nameright = 0, statustop = 0, linktop = 0, bottom = 0; - if (auto *thumbed = Get()) { + if (auto thumbed = Get()) { nameleft = st::msgFileThumbPadding.left() + st::msgFileThumbSize + st::msgFileThumbPadding.right(); nametop = st::msgFileThumbNameTop; nameright = st::msgFileThumbPadding.left(); @@ -4462,7 +4462,7 @@ void HistoryDocument::draw(Painter &p, const HistoryItem *parent, const QRect &r } int32 namewidth = _width - nameleft - nameright; - if (auto *voice = Get()) { + if (auto voice = Get()) { const VoiceWaveform *wf = 0; uchar norm_value = 0; if (_data->voice()) { @@ -4521,7 +4521,7 @@ void HistoryDocument::draw(Painter &p, const HistoryItem *parent, const QRect &r sum_i += bar_count; } } - } else if (auto *named = Get()) { + } else if (auto named = Get()) { p.setFont(st::semiboldFont); p.setPen(st::black); if (namewidth < named->_namew) { @@ -4548,7 +4548,7 @@ void HistoryDocument::draw(Painter &p, const HistoryItem *parent, const QRect &r } } - if (auto *captioned = Get()) { + if (auto captioned = Get()) { p.setPen(st::black); captioned->_caption.draw(p, st::msgPadding.left(), bottom, captionw); } @@ -4563,7 +4563,7 @@ void HistoryDocument::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, bool showPause = updateStatusText(parent); int32 nameleft = 0, nametop = 0, nameright = 0, statustop = 0, linktop = 0, bottom = 0; - if (auto *thumbed = Get()) { + if (auto thumbed = Get()) { nameleft = st::msgFileThumbPadding.left() + st::msgFileThumbSize + st::msgFileThumbPadding.right(); linktop = st::msgFileThumbLinkTop; bottom = st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom(); @@ -4592,7 +4592,7 @@ void HistoryDocument::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, } int32 height = _height; - if (auto *captioned = Get()) { + if (auto captioned = Get()) { if (y >= bottom) { bool inText = false; captioned->_caption.getState(lnk, inText, x - st::msgPadding.left(), y - bottom, _width - st::msgPadding.left() - st::msgPadding.right()); @@ -4614,10 +4614,10 @@ const QString HistoryDocument::inDialogsText() const { } else if (_data->song()) { result = lang(lng_in_dlg_audio_file); } else { - auto *named = Get(); + auto named = Get(); result = (!named || named->_name.isEmpty()) ? lang(lng_in_dlg_file) : named->_name; } - if (auto *captioned = Get()) { + if (auto captioned = Get()) { if (!captioned->_caption.isEmpty()) { result.append(' ').append(captioned->_caption.original(0, 0xFFFF, Text::ExpandLinksNone)); } @@ -4634,12 +4634,12 @@ const QString HistoryDocument::inHistoryText() const { } else { result = lang(lng_in_dlg_file); } - if (auto *named = Get()) { + if (auto named = Get()) { if (!named->_name.isEmpty()) { result.append(qsl(" : ")).append(named->_name); } } - if (auto *captioned = Get()) { + if (auto captioned = Get()) { if (!captioned->_caption.isEmpty()) { result.append(qsl(", ")).append(captioned->_caption.original(0, 0xFFFF, Text::ExpandLinksAll)); } @@ -4650,7 +4650,7 @@ const QString HistoryDocument::inHistoryText() const { void HistoryDocument::setStatusSize(int32 newSize, qint64 realDuration) const { int32 duration = _data->song() ? _data->song()->duration : (_data->voice() ? _data->voice()->duration : -1); HistoryFileMedia::setStatusSize(newSize, _data->size, duration, realDuration); - if (auto *thumbed = Get()) { + if (auto thumbed = Get()) { if (_statusSize == FileStatusSizeReady) { thumbed->_link = lang(lng_media_download).toUpper(); } else if (_statusSize == FileStatusSizeLoaded) { @@ -4686,7 +4686,7 @@ bool HistoryDocument::updateStatusText(const HistoryItem *parent) const { } if (playing.msgId == parent->fullId() && !(playingState & AudioPlayerStoppedMask) && playingState != AudioPlayerFinishing) { - if (auto *voice = Get()) { + if (auto voice = Get()) { bool was = voice->_playback; voice->ensurePlayback(this); if (!was || playingPosition != voice->_playback->_position) { @@ -4706,7 +4706,7 @@ bool HistoryDocument::updateStatusText(const HistoryItem *parent) const { showPause = (playingState == AudioPlayerPlaying || playingState == AudioPlayerResuming || playingState == AudioPlayerStarting); } else { statusSize = FileStatusSizeLoaded; - if (auto *voice = Get()) { + if (auto voice = Get()) { voice->checkPlaybackFinished(); } } @@ -4742,7 +4742,7 @@ bool HistoryDocument::updateStatusText(const HistoryItem *parent) const { } void HistoryDocument::step_voiceProgress(float64 ms, bool timer) { - if (auto *voice = Get()) { + if (auto voice = Get()) { if (voice->_playback) { float64 dt = ms / (2 * AudioVoiceMsgUpdateView); if (dt >= 1) { @@ -5232,8 +5232,8 @@ void HistorySticker::initDimensions(const HistoryItem *parent) { int HistorySticker::resizeGetHeight(int width, const HistoryItem *parent) { // return new height _width = qMin(width, _maxw); if (parent->getMedia() == this) { - auto *via = parent->Get(); - auto *reply = parent->Get(); + auto via = parent->Get(); + auto reply = parent->Get(); if (via || reply) { int usew = _maxw - additionalWidth(via, reply); int availw = _width - usew - st::msgReplyPadding.left() - st::msgReplyPadding.left() - st::msgReplyPadding.left(); @@ -5257,8 +5257,8 @@ void HistorySticker::draw(Painter &p, const HistoryItem *parent, const QRect &r, bool out = parent->out(), isPost = parent->isPost(), childmedia = (parent->getMedia() != this); int usew = _maxw, usex = 0; - auto *via = childmedia ? nullptr : parent->Get(); - auto *reply = childmedia ? nullptr : parent->Get(); + auto via = childmedia ? nullptr : parent->Get(); + auto reply = childmedia ? nullptr : parent->Get(); if (via || reply) { usew -= additionalWidth(via, reply); if (isPost) { @@ -5326,8 +5326,8 @@ void HistorySticker::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, i bool out = parent->out(), isPost = parent->isPost(), childmedia = (parent->getMedia() != this); int usew = _maxw, usex = 0; - auto *via = childmedia ? nullptr : parent->Get(); - auto *reply = childmedia ? nullptr : parent->Get(); + auto via = childmedia ? nullptr : parent->Get(); + auto reply = childmedia ? nullptr : parent->Get(); if (via || reply) { usew -= additionalWidth(via, reply); if (isPost) { @@ -5657,7 +5657,7 @@ void HistoryWebPage::initDimensions(const HistoryItem *parent) { if (!_data->description.isEmpty() && title.isEmpty() && _data->siteName.isEmpty() && !_data->url.isEmpty()) { _data->siteName = siteNameFromUrl(_data->url); } - if (!_data->doc && _data->photo && _data->type != WebPagePhoto && _data->type != WebPageVideo) { + if (!_data->document && _data->photo && _data->type != WebPagePhoto && _data->type != WebPageVideo) { if (_data->type == WebPageProfile) { _asArticle = true; } else if (_data->siteName == qstr("Twitter") || _data->siteName == qstr("Facebook")) { @@ -5674,15 +5674,15 @@ void HistoryWebPage::initDimensions(const HistoryItem *parent) { // init attach if (!_asArticle && !_attach) { - if (_data->doc) { - if (_data->doc->sticker()) { - _attach = new HistorySticker(_data->doc); - } else if (_data->doc->isAnimation()) { - _attach = new HistoryGif(_data->doc, QString(), parent); - } else if (_data->doc->isVideo()) { - _attach = new HistoryVideo(_data->doc, QString(), parent); + if (_data->document) { + if (_data->document->sticker()) { + _attach = new HistorySticker(_data->document); + } else if (_data->document->isAnimation()) { + _attach = new HistoryGif(_data->document, QString(), parent); + } else if (_data->document->isVideo()) { + _attach = new HistoryVideo(_data->document, QString(), parent); } else { - _attach = new HistoryDocument(_data->doc, QString(), parent); + _attach = new HistoryDocument(_data->document, QString(), parent); } } else if (_data->photo) { _attach = new HistoryPhoto(_data->photo, QString(), parent); @@ -6012,7 +6012,7 @@ void HistoryWebPage::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, i int32 attachLeft = lshift - bubble.left(), attachTop = tshift - bubble.top(); if (rtl()) attachLeft = _width - attachLeft - _attach->currentWidth(); _attach->getState(lnk, state, x - attachLeft, y - attachTop, parent); - if (lnk && !_data->doc && _data->photo) { + if (lnk && !_data->document && _data->photo) { if (_data->type == WebPageProfile || _data->type == WebPageVideo) { lnk = _openl; } else if (_data->type == WebPagePhoto || _data->siteName == qstr("Twitter") || _data->siteName == qstr("Facebook")) { @@ -6833,27 +6833,27 @@ void HistoryMessage::createComponents(const CreateConfig &config) { } } UpdateComponents(mask); - if (auto *reply = Get()) { + if (auto reply = Get()) { reply->replyToMsgId = config.replyTo; if (!reply->updateData(this) && App::api()) { App::api()->requestMessageData(history()->peer->asChannel(), reply->replyToMsgId, new HistoryDependentItemCallback(fullId())); } } - if (auto *via = Get()) { + if (auto via = Get()) { via->create(config.viaBotId); } - if (auto *views = Get()) { + if (auto views = Get()) { views->_views = config.viewsCount; } - if (auto *msgsigned = Get()) { + if (auto msgsigned = Get()) { msgsigned->create(_from->asUser(), date); } - if (auto *fwd = Get()) { + if (auto fwd = Get()) { fwd->_authorOriginal = App::peer(config.authorIdOriginal); fwd->_fromOriginal = App::peer(config.fromIdOriginal); fwd->_originalId = config.originalId; } - if (auto *markup = Get()) { + if (auto markup = Get()) { markup->create(*config.markup); } initTime(); @@ -6879,13 +6879,13 @@ QString formatViewsCount(int32 views) { } void HistoryMessage::initTime() { - if (auto *msgsigned = Get()) { + if (auto msgsigned = Get()) { _timeWidth = msgsigned->maxWidth(); } else { _timeText = date.toString(cTimeFormat()); _timeWidth = st::msgDateFont->width(_timeText); } - if (auto *views = Get()) { + if (auto views = Get()) { views->_viewsText = (views->_views >= 0) ? formatViewsCount(views->_views) : QString(); views->_viewsWidth = views->_viewsText.isEmpty() ? 0 : st::msgDateFont->width(views->_viewsText); } @@ -7011,7 +7011,7 @@ void HistoryMessage::initDimensions() { _maxw = _media->maxWidth(); _minh = _media->minHeight(); } - if (auto *reply = Get()) { + if (auto reply = Get()) { reply->updateName(); if (!_text.isEmpty()) { int replyw = st::msgPadding.left() + reply->_maxReplyWidth - st::msgReplyPadding.left() - st::msgReplyPadding.right() + st::msgPadding.right(); @@ -7059,13 +7059,21 @@ void HistoryMessage::countPositionAndSize(int32 &left, int32 &width) const { void HistoryMessage::fromNameUpdated(int32 width) const { _authorNameVersion = author()->nameVersion; if (!Has()) { - if (auto *via = Get()) { + if (auto via = Get()) { via->resize(width - st::msgPadding.left() - st::msgPadding.right() - author()->nameText.maxWidth() - st::msgServiceFont->spacew); } } } void HistoryMessage::applyEdition(const MTPDmessage &message) { + int keyboardTop = -1; + if (!pendingResize()) { + if (auto keyboard = inlineReplyKeyboard()) { + int h = st::msgBotKbButton.margin + keyboard->naturalHeight(); + keyboardTop = _height - h + st::msgBotKbButton.margin - marginBottom(); + } + } + EntitiesInText entities; if (message.has_entities()) { entities = entitiesFromMTP(message.ventities.c_vector().v); @@ -7084,6 +7092,12 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) { if (history()->textCachedFor == this) { history()->textCachedFor = nullptr; } + + if (keyboardTop >= 0) { + if (auto keyboard = Get()) { + keyboard->oldTop = keyboardTop; + } + } } void HistoryMessage::updateMedia(const MTPMessageMedia *media) { @@ -7141,7 +7155,7 @@ QString HistoryMessage::selectedText(uint32 selection) const { uint16 selectedTo = (selection == FullSelection) ? 0xFFFF : (selection & 0xFFFF); result = _text.original(selectedFrom, selectedTo, Text::ExpandLinksAll); } - if (auto *fwd = Get()) { + if (auto fwd = Get()) { if (selection == FullSelection) { QString fwdinfo = fwd->_text.original(0, 0xFFFF, Text::ExpandLinksAll), wrapped; wrapped.reserve(fwdinfo.size() + 4 + result.size()); @@ -7149,7 +7163,7 @@ QString HistoryMessage::selectedText(uint32 selection) const { result = wrapped; } } - if (auto *reply = Get()) { + if (auto reply = Get()) { if (selection == FullSelection && reply->replyToMsg) { QString wrapped; wrapped.reserve(lang(lng_in_reply_to).size() + reply->replyToMsg->author()->name.size() + 4 + result.size()); @@ -7281,7 +7295,7 @@ void HistoryMessage::drawInfo(Painter &p, int32 right, int32 bottom, int32 width } dateX += HistoryMessage::timeLeft(); - if (auto *msgsigned = Get()) { + if (auto msgsigned = Get()) { msgsigned->_signature.drawElided(p, dateX, dateY, _timeWidth); } else { p.drawText(dateX, dateY + st::msgDateFont->ascent, _timeText); @@ -7289,7 +7303,7 @@ void HistoryMessage::drawInfo(Painter &p, int32 right, int32 bottom, int32 width QPoint iconPos; const QRect *iconRect = 0; - if (auto *views = Get()) { + if (auto views = Get()) { iconPos = QPoint(infoRight - infoW + st::msgViewsPos.x(), infoBottom - st::msgViewsImg.pxHeight() + st::msgViewsPos.y()); if (id > 0) { if (outbg) { @@ -7328,7 +7342,7 @@ void HistoryMessage::drawInfo(Painter &p, int32 right, int32 bottom, int32 width } void HistoryMessage::setViewsCount(int32 count) { - auto *views = Get(); + auto views = Get(); if (!views || views->_views == count || (count >= 0 && views->_views > count)) return; int32 was = views->_viewsWidth; @@ -7370,11 +7384,11 @@ void HistoryMessage::draw(Painter &p, const QRect &r, uint32 selection, uint64 m if (width < 1) return; int dateh = 0, unreadbarh = 0; - if (auto *date = Get()) { + if (auto date = Get()) { dateh = date->height(); date->paint(p, 0, _history->width); } - if (auto *unreadbar = Get()) { + if (auto unreadbar = Get()) { unreadbarh = unreadbar->height(); p.translate(0, dateh); unreadbar->paint(p, 0, _history->width); @@ -7408,14 +7422,14 @@ void HistoryMessage::draw(Painter &p, const QRect &r, uint32 selection, uint64 m p.translate(-left, -top); } - auto *reply = Get(); + auto reply = Get(); if (reply) { reply->checkNameUpdate(); } if (bubble) { - auto *fwd = Get(); - auto *via = Get(); + auto fwd = Get(); + auto via = Get(); if (displayFromName() && author()->nameVersion > _authorNameVersion) { fromNameUpdated(width); } @@ -7483,7 +7497,7 @@ void HistoryMessage::paintForwardedInfo(Painter &p, QRect &trect, bool selected) p.setPen(selected ? (hasOutLayout() ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (hasOutLayout() ? st::msgOutServiceFg : st::msgInServiceFg)); p.setFont(serviceFont); - auto *fwd = Get(); + auto fwd = Get(); bool breakEverywhere = (fwd->_text.countHeight(trect.width()) > 2 * serviceFont->height); textstyleSet(&(selected ? (hasOutLayout() ? st::outFwdTextStyleSelected : st::inFwdTextStyleSelected) : (hasOutLayout() ? st::outFwdTextStyle : st::inFwdTextStyle))); fwd->_text.drawElided(p, trect.x(), trect.y(), trect.width(), 2, style::al_left, 0, -1, 0, breakEverywhere); @@ -7494,7 +7508,7 @@ void HistoryMessage::paintForwardedInfo(Painter &p, QRect &trect, bool selected) } void HistoryMessage::paintReplyInfo(Painter &p, QRect &trect, bool selected) const { - if (auto *reply = Get()) { + if (auto reply = Get()) { int32 h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); HistoryMessageReply::PaintFlags flags = HistoryMessageReply::PaintInBubble; @@ -7509,7 +7523,7 @@ void HistoryMessage::paintReplyInfo(Painter &p, QRect &trect, bool selected) con void HistoryMessage::paintViaBotIdInfo(Painter &p, QRect &trect, bool selected) const { if (!displayFromName() && !Has()) { - if (auto *via = Get()) { + if (auto via = Get()) { p.setFont(st::msgServiceNameFont); p.setPen(selected ? (hasOutLayout() ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (hasOutLayout() ? st::msgOutServiceFg : st::msgInServiceFg)); p.drawTextLeft(trect.left(), trect.top(), _history->width, via->_text); @@ -7519,7 +7533,7 @@ void HistoryMessage::paintViaBotIdInfo(Painter &p, QRect &trect, bool selected) } void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) { - if (auto *reply = Get()) { + if (auto reply = Get()) { reply->itemRemoved(this, dependency); } } @@ -7530,6 +7544,27 @@ void HistoryMessage::destroy() { } int HistoryMessage::resizeGetHeight_(int width) { + int result = performResizeGetHeight(width); + + auto keyboard = inlineReplyKeyboard(); + if (auto markup = Get()) { + int oldTop = markup->oldTop; + if (oldTop >= 0) { + markup->oldTop = -1; + if (keyboard) { + int h = st::msgBotKbButton.margin + keyboard->naturalHeight(); + int keyboardTop = _height - h + st::msgBotKbButton.margin - marginBottom(); + if (keyboardTop != oldTop) { + Notify::inlineKeyboardMoved(this, oldTop, keyboardTop); + } + } + } + } + + return result; +} + +int HistoryMessage::performResizeGetHeight(int width) { if (width < st::msgMinWidth) return _height; width -= st::msgMargin.left() + st::msgMargin.right(); @@ -7539,9 +7574,9 @@ int HistoryMessage::resizeGetHeight_(int width) { width = st::msgMaxWidth; } if (drawBubble()) { - auto *fwd = Get(); - auto *reply = Get(); - auto *via = Get(); + auto fwd = Get(); + auto reply = Get(); + auto via = Get(); bool media = (_media && _media->isDisplayed()); if (width >= _maxw) { @@ -7606,7 +7641,7 @@ int HistoryMessage::resizeGetHeight_(int width) { } else { _height = _media->resizeGetHeight(width, this); } - if (ReplyKeyboard *keyboard = inlineReplyKeyboard()) { + if (auto keyboard = inlineReplyKeyboard()) { int32 l = 0, w = 0; countPositionAndSize(l, w); @@ -7669,9 +7704,9 @@ void HistoryMessage::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, i } if (drawBubble()) { - auto *fwd = Get(); - auto *via = Get(); - auto *reply = Get(); + auto fwd = Get(); + auto via = Get(); + auto reply = Get(); int top = marginTop(); QRect r(left, top, width, height - top - marginBottom()); @@ -7765,9 +7800,9 @@ void HistoryMessage::getSymbol(uint16 &symbol, bool &after, bool &upon, int32 x, countPositionAndSize(left, width); if (width < 1) return; - auto *fwd = Get(); - auto *via = Get(); - auto *reply = Get(); + auto fwd = Get(); + auto via = Get(); + auto reply = Get(); int top = marginTop(); QRect r(left, top, width, height - top - marginBottom()); @@ -7837,7 +7872,7 @@ bool HistoryMessage::hasFromPhoto() const { HistoryMessage::~HistoryMessage() { _media.clear(this); - if (auto *reply = Get()) { + if (auto reply = Get()) { reply->clearData(this); } } @@ -7968,7 +8003,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { case mtpc_messageActionPinMessage: { if (updatePinnedText(&from, &text)) { - auto *pinned = Get(); + auto pinned = Get(); t_assert(pinned != nullptr); links.push_back(pinned->lnk); @@ -7990,7 +8025,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { } bool HistoryService::updatePinned(bool force) { - auto *pinned = Get(); + auto pinned = Get(); t_assert(pinned != nullptr); if (!force) { @@ -8038,7 +8073,7 @@ bool HistoryService::updatePinnedText(const QString *pfrom, QString *ptext) { } ClickHandlerPtr second; - auto *pinned = Get(); + auto pinned = Get(); if (pinned && pinned->msg) { HistoryMedia *media = pinned->msg->getMedia(); QString mediaText; @@ -8160,13 +8195,13 @@ void HistoryService::draw(Painter &p, const QRect &r, uint32 selection, uint64 m if (width < 1) return; int dateh = 0, unreadbarh = 0; - if (auto *date = Get()) { + if (auto date = Get()) { dateh = date->height(); date->paint(p, 0, _history->width); p.translate(0, dateh); height -= dateh; } - if (auto *unreadbar = Get()) { + if (auto unreadbar = Get()) { unreadbarh = unreadbar->height(); unreadbar->paint(p, 0, _history->width); p.translate(0, unreadbarh); @@ -8248,7 +8283,7 @@ int32 HistoryService::resizeGetHeight_(int32 width) { _height += st::msgServiceMargin.top() + _media->resizeGetHeight(_media->currentWidth(), this); } _height += displayedDateHeight(); - if (auto *unreadbar = Get()) { + if (auto unreadbar = Get()) { _height += unreadbar->height(); } return _height; @@ -8263,7 +8298,7 @@ bool HistoryService::hasPoint(int32 x, int32 y) const { y -= dateh; height -= dateh; } - if (auto *unreadbar = Get()) { + if (auto unreadbar = Get()) { int unreadbarh = unreadbar->height(); y -= unreadbarh; height -= unreadbarh; @@ -8287,7 +8322,7 @@ void HistoryService::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, i y -= dateh; height -= dateh; } - if (auto *unreadbar = Get()) { + if (auto unreadbar = Get()) { int unreadbarh = unreadbar->height(); y -= unreadbarh; height -= unreadbarh; @@ -8321,7 +8356,7 @@ void HistoryService::getSymbol(uint16 &symbol, bool &after, bool &upon, int32 x, y -= dateh; height -= dateh; } - if (auto *unreadbar = Get()) { + if (auto unreadbar = Get()) { int unreadbarh = unreadbar->height(); y -= unreadbarh; height -= unreadbarh; diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 82ed36eac..d197d24b6 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -1118,6 +1118,9 @@ struct HistoryMessageReplyMarkup : public BaseComponent inlineKeyboard; + // If >= 0 it holds the y coord of the inlineKeyboard before the last edition. + int oldTop = -1; + private: void createFromButtonRows(const QVector &v); @@ -2586,7 +2589,7 @@ public: void detachFromItem(HistoryItem *item) override; bool hasReplyPreview() const override { - return (_data->photo && !_data->photo->thumb->isNull()) || (_data->doc && !_data->doc->thumb->isNull()); + return (_data->photo && !_data->photo->thumb->isNull()) || (_data->document && !_data->document->thumb->isNull()); } ImagePtr replyPreview() override; @@ -2883,6 +2886,7 @@ private: void initDimensions() override; int resizeGetHeight_(int width) override; + int performResizeGetHeight(int width); bool displayForwardedFrom() const { if (const HistoryMessageForwarded *fwd = Get()) { diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 31ca53fb0..ce9d6f835 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -1908,6 +1908,16 @@ void HistoryInner::notifyMigrateUpdated() { _migrated = _peer->migrateFrom() ? App::history(_peer->migrateFrom()->id) : 0; } +int HistoryInner::moveScrollFollowingInlineKeyboard(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { + if (item == App::mousedItem()) { + int top = itemTop(item); + if (top >= oldKeyboardTop) { + return newKeyboardTop - oldKeyboardTop; + } + } + return 0; +} + void HistoryInner::applyDragSelection() { applyDragSelection(&_selected); } @@ -3183,6 +3193,14 @@ void HistoryWidget::notify_replyMarkupUpdated(const HistoryItem *item) { } } +void HistoryWidget::notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { + if (_history == item->history() || _migrated == item->history()) { + if (int move = _list->moveScrollFollowingInlineKeyboard(item, oldKeyboardTop, newKeyboardTop)) { + _addToScroll = move; + } + } +} + void HistoryWidget::notify_userIsBotChanged(UserData *user) { if (_peer && _peer == user) { _list->notifyIsBotChanged(); @@ -3577,6 +3595,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re updateBotKeyboard(); } + _addToScroll = 0; _editMsgId = 0; _saveEditMsgRequestId = 0; _replyToId = 0; @@ -6418,6 +6437,9 @@ void HistoryWidget::updateListSize(bool initial, bool loadedDown, const ScrollCh toY += change.value; } else if (change.type == ScrollChangeNoJumpToBottom) { toY = wasScrollTop; + } else if (_addToScroll) { + toY += _addToScroll; + _addToScroll = 0; } if (toY > _scroll.scrollTopMax()) { toY = _scroll.scrollTopMax(); @@ -7425,24 +7447,24 @@ void HistoryWidget::updatePreview() { if (_previewData->title.isEmpty()) { if (_previewData->description.isEmpty()) { title = _previewData->author; - desc = ((_previewData->doc && !_previewData->doc->name.isEmpty()) ? _previewData->doc->name : _previewData->url); + desc = ((_previewData->document && !_previewData->document->name.isEmpty()) ? _previewData->document->name : _previewData->url); } else { title = _previewData->description; - desc = _previewData->author.isEmpty() ? ((_previewData->doc && !_previewData->doc->name.isEmpty()) ? _previewData->doc->name : _previewData->url) : _previewData->author; + desc = _previewData->author.isEmpty() ? ((_previewData->document && !_previewData->document->name.isEmpty()) ? _previewData->document->name : _previewData->url) : _previewData->author; } } else { title = _previewData->title; - desc = _previewData->description.isEmpty() ? (_previewData->author.isEmpty() ? ((_previewData->doc && !_previewData->doc->name.isEmpty()) ? _previewData->doc->name : _previewData->url) : _previewData->author) : _previewData->description; + desc = _previewData->description.isEmpty() ? (_previewData->author.isEmpty() ? ((_previewData->document && !_previewData->document->name.isEmpty()) ? _previewData->document->name : _previewData->url) : _previewData->author) : _previewData->description; } } else { title = _previewData->siteName; - desc = _previewData->title.isEmpty() ? (_previewData->description.isEmpty() ? (_previewData->author.isEmpty() ? ((_previewData->doc && !_previewData->doc->name.isEmpty()) ? _previewData->doc->name : _previewData->url) : _previewData->author) : _previewData->description) : _previewData->title; + desc = _previewData->title.isEmpty() ? (_previewData->description.isEmpty() ? (_previewData->author.isEmpty() ? ((_previewData->document && !_previewData->document->name.isEmpty()) ? _previewData->document->name : _previewData->url) : _previewData->author) : _previewData->description) : _previewData->title; } if (title.isEmpty()) { - if (_previewData->photo) { - title = lang(lng_attach_photo); - } else if (_previewData->doc) { + if (_previewData->document) { title = lang(lng_attach_file); + } else if (_previewData->photo) { + title = lang(lng_attach_photo); } } _previewTitle.setText(st::msgServiceNameFont, title, _textNameOptions); @@ -7802,8 +7824,8 @@ void HistoryWidget::drawField(Painter &p) { if (drawPreview) { int32 previewLeft = st::replySkip + st::webPageLeft; p.fillRect(st::replySkip, backy + st::msgReplyPadding.top(), st::webPageBar, st::msgReplyBarSize.height(), st::msgInReplyBarColor->b); - if ((_previewData->photo && !_previewData->photo->thumb->isNull()) || (_previewData->doc && !_previewData->doc->thumb->isNull())) { - ImagePtr replyPreview = _previewData->photo ? _previewData->photo->makeReplyPreview() : _previewData->doc->makeReplyPreview(); + if ((_previewData->photo && !_previewData->photo->thumb->isNull()) || (_previewData->document && !_previewData->document->thumb->isNull())) { + ImagePtr replyPreview = _previewData->photo ? _previewData->photo->makeReplyPreview() : _previewData->document->makeReplyPreview(); if (!replyPreview->isNull()) { QRect to(previewLeft, backy + st::msgReplyPadding.top(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height()); if (replyPreview->width() == replyPreview->height()) { diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index 6bd8659f3..6a9ce10ae 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -101,6 +101,10 @@ public: void notifyIsBotChanged(); void notifyMigrateUpdated(); + // When inline keyboard has moved because of the edition of its item we want + // to move scroll position so that mouse points to the same button row. + int moveScrollFollowingInlineKeyboard(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop); + // AbstractTooltipShower interface QString tooltipText() const override; QPoint tooltipPos() const override; @@ -680,6 +684,7 @@ public: void notify_botCommandsChanged(UserData *user); void notify_inlineBotRequesting(bool requesting); void notify_replyMarkupUpdated(const HistoryItem *item); + void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop); void notify_userIsBotChanged(UserData *user); void notify_migrateUpdated(PeerData *peer); void notify_clipStopperHidden(ClipStopperType type); @@ -977,10 +982,11 @@ private: History *_migrated = nullptr; History *_history = nullptr; bool _histInited = false; // initial updateListSize() called + int _addToScroll = 0; - int32 _lastScroll = 0; + int _lastScroll = 0;// gifs optimization uint64 _lastScrolled = 0; - QTimer _updateHistoryItems; // gifs optimization + QTimer _updateHistoryItems; IconedButton _toHistoryEnd; CollapseButton _collapseComments; diff --git a/Telegram/SourceFiles/layout.cpp b/Telegram/SourceFiles/layout.cpp index e844bfa01..bd0c72e27 100644 --- a/Telegram/SourceFiles/layout.cpp +++ b/Telegram/SourceFiles/layout.cpp @@ -1105,8 +1105,8 @@ LayoutOverviewLink::LayoutOverviewLink(HistoryMedia *media, HistoryItem *parent) _page = (media && media->type() == MediaTypeWebPage) ? static_cast(media)->webpage() : 0; if (_page) { - if (_page->doc) { - _photol.reset(new DocumentOpenClickHandler(_page->doc)); + if (_page->document) { + _photol.reset(new DocumentOpenClickHandler(_page->document)); } else if (_page->photo) { if (_page->type == WebPageProfile || _page->type == WebPageVideo) { _photol = MakeShared(_page->url); @@ -1136,11 +1136,11 @@ LayoutOverviewLink::LayoutOverviewLink(HistoryMedia *media, HistoryItem *parent) tw = convertScale(_page->photo->thumb->width()); th = convertScale(_page->photo->thumb->height()); - } else if (_page && _page->doc) { - if (!_page->doc->thumb->loaded()) _page->doc->thumb->load(false, false); + } else if (_page && _page->document) { + if (!_page->document->thumb->loaded()) _page->document->thumb->load(false, false); - tw = convertScale(_page->doc->thumb->width()); - th = convertScale(_page->doc->thumb->height()); + tw = convertScale(_page->document->thumb->width()); + th = convertScale(_page->document->thumb->height()); } if (tw > st::dlgPhotoSize) { if (th > tw) { @@ -1214,16 +1214,16 @@ void LayoutOverviewLink::paint(Painter &p, const QRect &clip, uint32 selection, if (clip.intersects(rtlrect(0, top, st::dlgPhotoSize, st::dlgPhotoSize, _width))) { if (_page && _page->photo) { QPixmap pix; - if (_page->photo->loaded()) { - pix = _page->photo->full->pixSingle(_pixw, _pixh, st::dlgPhotoSize, st::dlgPhotoSize); - } else if (_page->photo->medium->loaded()) { + if (_page->photo->medium->loaded()) { pix = _page->photo->medium->pixSingle(_pixw, _pixh, st::dlgPhotoSize, st::dlgPhotoSize); + } else if (_page->photo->loaded()) { + pix = _page->photo->full->pixSingle(_pixw, _pixh, st::dlgPhotoSize, st::dlgPhotoSize); } else { pix = _page->photo->thumb->pixSingle(_pixw, _pixh, st::dlgPhotoSize, st::dlgPhotoSize); } p.drawPixmapLeft(0, top, _width, pix); - } else if (_page && _page->doc && !_page->doc->thumb->isNull()) { - p.drawPixmapLeft(0, top, _width, _page->doc->thumb->pixSingle(_pixw, _pixh, st::dlgPhotoSize, st::dlgPhotoSize)); + } else if (_page && _page->document && !_page->document->thumb->isNull()) { + p.drawPixmapLeft(0, top, _width, _page->document->thumb->pixSingle(_pixw, _pixh, st::dlgPhotoSize, st::dlgPhotoSize)); } else { int32 index = _letter.isEmpty() ? 0 : (_letter.at(0).unicode() % 4); switch (index) { diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index d5a7e8b2e..b06bea167 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -399,40 +399,12 @@ MainWidget *TopBarWidget::main() { } MainWidget::MainWidget(Window *window) : TWidget(window) -, _started(0) -, failedObjId(0) -, _toForwardNameVersion(0) , _a_show(animation(this, &MainWidget::step_show)) -, _dialogsWidth(st::dlgMinWidth) , dialogs(this) , history(this) -, profile(0) -, overview(0) , _player(this) , _topBar(this) -, _forwardConfirm(0) -, _hider(0) -, _peerInStack(0) -, _msgIdInStack(0) -, _playerHeight(0) -, _contentScrollAddToY(0) , _mediaType(this) -, _mediaTypeMask(0) -, updDate(0) -, updQts(-1) -, updSeq(0) -, _getDifferenceTimeByPts(0) -, _getDifferenceTimeAfterFail(0) -, _onlineRequest(0) -, _lastWasOnline(false) -, _lastSetOnline(0) -, _isIdle(false) -, _failDifferenceTimeout(1) -, _lastUpdateTime(0) -, _handlingChannelDifference(false) -, _cachedX(0) -, _cachedY(0) -, _background(0) , _api(new ApiWrap(this)) { setGeometry(QRect(0, st::titleHeight, App::wnd()->width(), App::wnd()->height() - st::titleHeight)); @@ -776,6 +748,10 @@ void MainWidget::notify_replyMarkupUpdated(const HistoryItem *item) { history.notify_replyMarkupUpdated(item); } +void MainWidget::notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop) { + history.notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop); +} + void MainWidget::notify_userIsBotChanged(UserData *bot) { history.notify_userIsBotChanged(bot); } @@ -2890,7 +2866,7 @@ void MainWidget::resizeEvent(QResizeEvent *e) { _contentScrollAddToY = 0; } -int32 MainWidget::contentScrollAddToY() const { +int MainWidget::contentScrollAddToY() const { return _contentScrollAddToY; } diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 5ecfa80af..b277eb909 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -223,7 +223,7 @@ public: TopBarWidget *topBar(); PlayerWidget *player(); - int32 contentScrollAddToY() const; + int contentScrollAddToY() const; void animShow(const QPixmap &bgAnimCache, bool back = false); void step_show(float64 ms, bool timer); @@ -453,6 +453,7 @@ public: void notify_botCommandsChanged(UserData *bot); void notify_inlineBotRequesting(bool requesting); void notify_replyMarkupUpdated(const HistoryItem *item); + void notify_inlineKeyboardMoved(const HistoryItem *item, int oldKeyboardTop, int newKeyboardTop); void notify_userIsBotChanged(UserData *bot); void notify_userIsContactChanged(UserData *user, bool fromThisApp); void notify_migrateUpdated(PeerData *peer); @@ -548,15 +549,15 @@ private: void messagesAffected(PeerData *peer, const MTPmessages_AffectedMessages &result); void overviewLoaded(History *history, const MTPmessages_Messages &result, mtpRequestId req); - bool _started; + bool _started = false; - uint64 failedObjId; + uint64 failedObjId = 0; QString failedFileName; void loadFailed(mtpFileLoader *loader, bool started, const char *retrySlot); SelectedItemSet _toForward; Text _toForwardFrom, _toForwardText; - int32 _toForwardNameVersion; + int32 _toForwardNameVersion = 0; QMap _webPagesUpdated; QTimer _webPageUpdater; @@ -611,27 +612,29 @@ private: anim::ivalue a_coordUnder, a_coordOver; anim::fvalue a_shadow; - int32 _dialogsWidth; + int _dialogsWidth = st::dlgMinWidth; DialogsWidget dialogs; HistoryWidget history; - ProfileWidget *profile; - OverviewWidget *overview; + ProfileWidget *profile = nullptr; + OverviewWidget *overview = nullptr; PlayerWidget _player; TopBarWidget _topBar; - ConfirmBox *_forwardConfirm; // for narrow mode - HistoryHider *_hider; + ConfirmBox *_forwardConfirm = nullptr; // for single column layout + HistoryHider *_hider = nullptr; StackItems _stack; - PeerData *_peerInStack; - MsgId _msgIdInStack; + PeerData *_peerInStack = nullptr; + MsgId _msgIdInStack = 0; - int32 _playerHeight; - int32 _contentScrollAddToY; + int _playerHeight = 0; + int _contentScrollAddToY = 0; Dropdown _mediaType; - int32 _mediaTypeMask; + int32 _mediaTypeMask = 0; - int32 updDate, updQts, updSeq; + int32 updDate = 0; + int32 updQts = -1; + int32 updSeq = 0; SingleTimer noUpdatesTimer; bool ptsUpdated(int32 pts, int32 ptsCount); @@ -642,7 +645,8 @@ private: typedef QMap ChannelGetDifferenceTime; ChannelGetDifferenceTime _channelGetDifferenceTimeByPts, _channelGetDifferenceTimeAfterFail; - uint64 _getDifferenceTimeByPts, _getDifferenceTimeAfterFail; + uint64 _getDifferenceTimeByPts = 0; + uint64 _getDifferenceTimeAfterFail = 0; bool getDifferenceTimeChanged(ChannelData *channel, int32 ms, ChannelGetDifferenceTime &channelCurTime, uint64 &curTime); @@ -653,11 +657,11 @@ private: SingleTimer _byMinChannelTimer; - mtpRequestId _onlineRequest; + mtpRequestId _onlineRequest = 0; SingleTimer _onlineTimer, _onlineUpdater, _idleFinishTimer; - bool _lastWasOnline; - uint64 _lastSetOnline; - bool _isIdle; + bool _lastWasOnline = false; + uint64 _lastSetOnline = 0; + bool _isIdle = false; QSet updateNotifySettingPeers; SingleTimer updateNotifySettingTimer; @@ -670,17 +674,18 @@ private: typedef QMap OverviewsPreload; OverviewsPreload _overviewPreload[OverviewCount], _overviewLoad[OverviewCount]; - int32 _failDifferenceTimeout; // growing timeout for getDifference calls, if it fails + int32 _failDifferenceTimeout = 1; // growing timeout for getDifference calls, if it fails typedef QMap ChannelFailDifferenceTimeout; ChannelFailDifferenceTimeout _channelFailDifferenceTimeout; // growing timeout for getChannelDifference calls, if it fails SingleTimer _failDifferenceTimer; - uint64 _lastUpdateTime; - bool _handlingChannelDifference; + uint64 _lastUpdateTime = 0; + bool _handlingChannelDifference = false; QPixmap _cachedBackground; QRect _cachedFor, _willCacheFor; - int _cachedX, _cachedY; + int _cachedX = 0; + int _cachedY = 0; SingleTimer _cacheBackgroundTimer; typedef QMap UpdatedChannels; @@ -697,7 +702,7 @@ private: void viewsIncrementDone(QVector ids, const MTPVector &result, mtpRequestId req); bool viewsIncrementFail(const RPCError &error, mtpRequestId req); - App::WallPaper *_background; + App::WallPaper *_background = nullptr; ApiWrap *_api; diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index 01e545146..148c8c5a7 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -1428,7 +1428,7 @@ DocumentData::~DocumentData() { } } -WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill) : id(id) +WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, DocumentData *document, PhotoData *photo, int32 duration, const QString &author, int32 pendingTill) : id(id) , type(type) , url(url) , displayUrl(displayUrl) @@ -1438,7 +1438,7 @@ WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &u , duration(duration) , author(author) , photo(photo) -, doc(doc) +, document(document) , pendingTill(pendingTill) { } diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index b5706e24f..fa5201200 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -1228,7 +1228,7 @@ inline WebPageType toWebPageType(const QString &type) { } struct WebPageData { - WebPageData(const WebPageId &id, WebPageType type = WebPageArticle, const QString &url = QString(), const QString &displayUrl = QString(), const QString &siteName = QString(), const QString &title = QString(), const QString &description = QString(), PhotoData *photo = 0, DocumentData *doc = 0, int32 duration = 0, const QString &author = QString(), int32 pendingTill = -1); + WebPageData(const WebPageId &id, WebPageType type = WebPageArticle, const QString &url = QString(), const QString &displayUrl = QString(), const QString &siteName = QString(), const QString &title = QString(), const QString &description = QString(), DocumentData *doc = nullptr, PhotoData *photo = nullptr, int32 duration = 0, const QString &author = QString(), int32 pendingTill = -1); void forget() { if (photo) photo->forget(); @@ -1240,7 +1240,7 @@ struct WebPageData { int32 duration; QString author; PhotoData *photo; - DocumentData *doc; + DocumentData *document; int32 pendingTill; };