From 44c6050bf23a493f418afd64bc9981017604ebba Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 26 Jun 2018 21:15:29 +0100 Subject: [PATCH] Fix field autocomplete in empty chat. --- .../chat_helpers/field_autocomplete.cpp | 11 ++++--- .../chat_helpers/field_autocomplete.h | 5 +++- .../SourceFiles/history/history_widget.cpp | 29 +++++++++++-------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 2f52431cc..315997ee4 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -57,7 +57,10 @@ void FieldAutocomplete::paintEvent(QPaintEvent *e) { p.fillRect(rect(), st::mentionBg); } -void FieldAutocomplete::showFiltered(PeerData *peer, QString query, bool addInlineBots) { +void FieldAutocomplete::showFiltered( + not_null peer, + QString query, + bool addInlineBots) { _chat = peer->asChat(); _user = peer->asUser(); _channel = peer->asChannel(); @@ -105,9 +108,9 @@ void FieldAutocomplete::showStickers(EmojiPtr emoji) { return; } - _chat = 0; - _user = 0; - _channel = 0; + _chat = nullptr; + _user = nullptr; + _channel = nullptr; updateFiltered(resetScroll); } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index 1d5cf64df..fe4d5d43d 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -32,7 +32,10 @@ public: FieldAutocomplete(QWidget *parent); bool clearFilteredBotCommands(); - void showFiltered(PeerData *peer, QString query, bool addInlineBots); + void showFiltered( + not_null peer, + QString query, + bool addInlineBots); void showStickers(EmojiPtr emoji); void setBoundings(QRect boundings); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 6810c9ebc..9a5097a4f 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1034,6 +1034,9 @@ void HistoryWidget::onHashtagOrBotCommandInsert( } void HistoryWidget::updateInlineBotQuery() { + if (!_history) { + return; + } const auto query = ParseInlineBotQuery(_field); if (_inlineBotUsername != query.username) { _inlineBotUsername = query.username; @@ -1131,20 +1134,22 @@ void HistoryWidget::setReportSpamStatus(DBIPeerReportSpamStatus status) { } void HistoryWidget::updateStickersByEmoji() { - int len = 0; - if (!_editMsgId) { - auto &text = _field->getTextWithTags().text; - if (auto emoji = Ui::Emoji::Find(text, &len)) { - if (text.size() > len) { - len = 0; - } else { - _fieldAutocomplete->showStickers(emoji); + if (!_history) { + return; + } + const auto emoji = [&] { + if (!_editMsgId) { + const auto &text = _field->getTextWithTags().text; + auto length = 0; + if (const auto emoji = Ui::Emoji::Find(text, &length)) { + if (text.size() <= length) { + return emoji; + } } } - } - if (!len) { - _fieldAutocomplete->showStickers(nullptr); - } + return EmojiPtr(nullptr); + }(); + _fieldAutocomplete->showStickers(emoji); } void HistoryWidget::onTextChange() {