From 6d62673e9ea4e7cabe1cd74427cb17cd1361ce29 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 9 Dec 2017 22:20:10 +0400 Subject: [PATCH] Fix crash in HistoryWidget. --- .../SourceFiles/history/history_widget.cpp | 17 ++++++++----- Telegram/SourceFiles/history/history_widget.h | 24 +++++++++---------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 1d782c9d0..556817298 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -92,6 +92,7 @@ constexpr auto kSkipRepaintWhileScrollMs = 100; constexpr auto kShowMembersDropdownTimeoutMs = 300; constexpr auto kDisplayEditTimeWarningMs = 300 * 1000; constexpr auto kFullDayInMs = 86400 * 1000; +constexpr auto kCancelTypingActionTimeout = TimeMs(5000); ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() { return [](ChannelData *channel, MsgId msgId) { @@ -448,6 +449,7 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null cont , _attachDragDocument(this) , _attachDragPhoto(this) , _fileLoader(this, FileLoaderQueueStopTimeout) +, _sendActionStopTimer([this] { cancelTypingAction(); }) , _topShadow(this) { setAcceptDrops(true); @@ -475,7 +477,6 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null cont connect(_tabbedSelector, SIGNAL(stickerSelected(DocumentData*)), this, SLOT(onStickerSend(DocumentData*))); connect(_tabbedSelector, SIGNAL(photoSelected(PhotoData*)), this, SLOT(onPhotoSend(PhotoData*))); connect(_tabbedSelector, SIGNAL(inlineResultSelected(InlineBots::Result*,UserData*)), this, SLOT(onInlineResultSend(InlineBots::Result*,UserData*))); - connect(&_sendActionStopTimer, SIGNAL(timeout()), this, SLOT(onCancelSendAction())); connect(&_previewTimer, SIGNAL(timeout()), this, SLOT(onPreviewTimeout())); connect(Media::Capture::instance(), SIGNAL(error()), this, SLOT(onRecordError())); connect(Media::Capture::instance(), SIGNAL(updated(quint16,qint32)), this, SLOT(onRecordUpdate(quint16,qint32))); @@ -490,8 +491,6 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null cont _scrollTimer.setSingleShot(false); - _sendActionStopTimer.setSingleShot(true); - _highlightTimer.setCallback([this] { updateHighlightedMessage(); }); _membersDropdownShowTimer.setSingleShot(true); @@ -1191,8 +1190,11 @@ void HistoryWidget::cancelSendAction( } } -void HistoryWidget::onCancelSendAction() { - cancelSendAction(_history, SendAction::Type::Typing); +void HistoryWidget::cancelTypingAction() { + if (_history) { + cancelSendAction(_history, SendAction::Type::Typing); + } + _sendActionStopTimer.cancel(); } void HistoryWidget::updateSendAction( @@ -1231,7 +1233,9 @@ void HistoryWidget::updateSendAction( action), rpcDone(&HistoryWidget::sendActionDone)); _sendActionRequests.insert(key, requestId); - if (type == Type::Typing) _sendActionStopTimer.start(5000); + if (type == Type::Typing) { + _sendActionStopTimer.callOnce(kCancelTypingActionTimeout); + } } } } @@ -1627,6 +1631,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re return; } updateSendAction(_history, SendAction::Type::Typing, -1); + cancelTypingAction(); } if (!cAutoPlayGif()) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index a0de55790..843f19d7c 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -29,6 +29,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "ui/widgets/input_fields.h" #include "ui/rp_widget.h" #include "base/flags.h" +#include "base/timer.h" namespace InlineBots { namespace Layout { @@ -206,16 +207,7 @@ public: void pushInfoToThirdSection( const Window::SectionShow ¶ms); - void updateSendAction( - not_null history, - SendAction::Type type, - int32 progress = 0); - void cancelSendAction( - not_null history, - SendAction::Type type); - void updateRecentStickers(); - void sendActionDone(const MTPBool &result, mtpRequestId req); void destroyData(); @@ -383,8 +375,6 @@ public slots: void onCopyPostLink(); void onFieldBarCancel(); - void onCancelSendAction(); - void onPreviewParse(); void onPreviewCheck(); void onPreviewTimeout(); @@ -493,6 +483,16 @@ private: void clearHighlightMessages(); void stopMessageHighlight(); + void updateSendAction( + not_null history, + SendAction::Type type, + int32 progress = 0); + void cancelSendAction( + not_null history, + SendAction::Type type); + void cancelTypingAction(); + void sendActionDone(const MTPBool &result, mtpRequestId req); + void animationCallback(); void updateOverStates(QPoint pos); void recordStartCallback(); @@ -852,7 +852,7 @@ private: TimeMs _highlightStart = 0; QMap, SendAction::Type>, mtpRequestId> _sendActionRequests; - QTimer _sendActionStopTimer; + base::Timer _sendActionStopTimer; TimeMs _saveDraftStart = 0; bool _saveDraftText = false;