Fix crash in HistoryWidget.

This commit is contained in:
John Preston 2017-12-09 22:20:10 +04:00
parent 677dbd5d6e
commit 6d62673e9e
2 changed files with 23 additions and 18 deletions

View File

@ -92,6 +92,7 @@ constexpr auto kSkipRepaintWhileScrollMs = 100;
constexpr auto kShowMembersDropdownTimeoutMs = 300; constexpr auto kShowMembersDropdownTimeoutMs = 300;
constexpr auto kDisplayEditTimeWarningMs = 300 * 1000; constexpr auto kDisplayEditTimeWarningMs = 300 * 1000;
constexpr auto kFullDayInMs = 86400 * 1000; constexpr auto kFullDayInMs = 86400 * 1000;
constexpr auto kCancelTypingActionTimeout = TimeMs(5000);
ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() { ApiWrap::RequestMessageDataCallback replyEditMessageDataCallback() {
return [](ChannelData *channel, MsgId msgId) { return [](ChannelData *channel, MsgId msgId) {
@ -448,6 +449,7 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
, _attachDragDocument(this) , _attachDragDocument(this)
, _attachDragPhoto(this) , _attachDragPhoto(this)
, _fileLoader(this, FileLoaderQueueStopTimeout) , _fileLoader(this, FileLoaderQueueStopTimeout)
, _sendActionStopTimer([this] { cancelTypingAction(); })
, _topShadow(this) { , _topShadow(this) {
setAcceptDrops(true); setAcceptDrops(true);
@ -475,7 +477,6 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
connect(_tabbedSelector, SIGNAL(stickerSelected(DocumentData*)), this, SLOT(onStickerSend(DocumentData*))); connect(_tabbedSelector, SIGNAL(stickerSelected(DocumentData*)), this, SLOT(onStickerSend(DocumentData*)));
connect(_tabbedSelector, SIGNAL(photoSelected(PhotoData*)), this, SLOT(onPhotoSend(PhotoData*))); connect(_tabbedSelector, SIGNAL(photoSelected(PhotoData*)), this, SLOT(onPhotoSend(PhotoData*)));
connect(_tabbedSelector, SIGNAL(inlineResultSelected(InlineBots::Result*,UserData*)), this, SLOT(onInlineResultSend(InlineBots::Result*,UserData*))); 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(&_previewTimer, SIGNAL(timeout()), this, SLOT(onPreviewTimeout()));
connect(Media::Capture::instance(), SIGNAL(error()), this, SLOT(onRecordError())); connect(Media::Capture::instance(), SIGNAL(error()), this, SLOT(onRecordError()));
connect(Media::Capture::instance(), SIGNAL(updated(quint16,qint32)), this, SLOT(onRecordUpdate(quint16,qint32))); connect(Media::Capture::instance(), SIGNAL(updated(quint16,qint32)), this, SLOT(onRecordUpdate(quint16,qint32)));
@ -490,8 +491,6 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
_scrollTimer.setSingleShot(false); _scrollTimer.setSingleShot(false);
_sendActionStopTimer.setSingleShot(true);
_highlightTimer.setCallback([this] { updateHighlightedMessage(); }); _highlightTimer.setCallback([this] { updateHighlightedMessage(); });
_membersDropdownShowTimer.setSingleShot(true); _membersDropdownShowTimer.setSingleShot(true);
@ -1191,8 +1190,11 @@ void HistoryWidget::cancelSendAction(
} }
} }
void HistoryWidget::onCancelSendAction() { void HistoryWidget::cancelTypingAction() {
cancelSendAction(_history, SendAction::Type::Typing); if (_history) {
cancelSendAction(_history, SendAction::Type::Typing);
}
_sendActionStopTimer.cancel();
} }
void HistoryWidget::updateSendAction( void HistoryWidget::updateSendAction(
@ -1231,7 +1233,9 @@ void HistoryWidget::updateSendAction(
action), action),
rpcDone(&HistoryWidget::sendActionDone)); rpcDone(&HistoryWidget::sendActionDone));
_sendActionRequests.insert(key, requestId); _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; return;
} }
updateSendAction(_history, SendAction::Type::Typing, -1); updateSendAction(_history, SendAction::Type::Typing, -1);
cancelTypingAction();
} }
if (!cAutoPlayGif()) { if (!cAutoPlayGif()) {

View File

@ -29,6 +29,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
#include "base/flags.h" #include "base/flags.h"
#include "base/timer.h"
namespace InlineBots { namespace InlineBots {
namespace Layout { namespace Layout {
@ -206,16 +207,7 @@ public:
void pushInfoToThirdSection( void pushInfoToThirdSection(
const Window::SectionShow &params); const Window::SectionShow &params);
void updateSendAction(
not_null<History*> history,
SendAction::Type type,
int32 progress = 0);
void cancelSendAction(
not_null<History*> history,
SendAction::Type type);
void updateRecentStickers(); void updateRecentStickers();
void sendActionDone(const MTPBool &result, mtpRequestId req);
void destroyData(); void destroyData();
@ -383,8 +375,6 @@ public slots:
void onCopyPostLink(); void onCopyPostLink();
void onFieldBarCancel(); void onFieldBarCancel();
void onCancelSendAction();
void onPreviewParse(); void onPreviewParse();
void onPreviewCheck(); void onPreviewCheck();
void onPreviewTimeout(); void onPreviewTimeout();
@ -493,6 +483,16 @@ private:
void clearHighlightMessages(); void clearHighlightMessages();
void stopMessageHighlight(); void stopMessageHighlight();
void updateSendAction(
not_null<History*> history,
SendAction::Type type,
int32 progress = 0);
void cancelSendAction(
not_null<History*> history,
SendAction::Type type);
void cancelTypingAction();
void sendActionDone(const MTPBool &result, mtpRequestId req);
void animationCallback(); void animationCallback();
void updateOverStates(QPoint pos); void updateOverStates(QPoint pos);
void recordStartCallback(); void recordStartCallback();
@ -852,7 +852,7 @@ private:
TimeMs _highlightStart = 0; TimeMs _highlightStart = 0;
QMap<QPair<not_null<History*>, SendAction::Type>, mtpRequestId> _sendActionRequests; QMap<QPair<not_null<History*>, SendAction::Type>, mtpRequestId> _sendActionRequests;
QTimer _sendActionStopTimer; base::Timer _sendActionStopTimer;
TimeMs _saveDraftStart = 0; TimeMs _saveDraftStart = 0;
bool _saveDraftText = false; bool _saveDraftText = false;