not sending typing status when working with inline bots

This commit is contained in:
John Preston 2016-01-02 08:58:43 +08:00
parent 4426e2dd78
commit d8b1df875e
5 changed files with 33 additions and 23 deletions

View File

@ -88,16 +88,16 @@ FlatTextarea::FlatTextarea(QWidget *parent, const style::flatTextarea &st, const
}
}
void FlatTextarea::setTextFast(const QString &text, bool withUndo) {
if (withUndo) {
void FlatTextarea::setTextFast(const QString &text, bool clearUndoHistory) {
if (clearUndoHistory) {
setPlainText(text);
} else {
QTextCursor c(document()->docHandle(), 0);
c.joinPreviousEditBlock();
c.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
c.insertText(text);
c.movePosition(QTextCursor::End);
c.endEditBlock();
} else {
setPlainText(text);
}
finishPlaceholder();
}

View File

@ -79,7 +79,7 @@ public:
QMimeData *createMimeDataFromSelection() const;
void setCtrlEnterSubmit(bool ctrlEnterSubmit);
void setTextFast(const QString &text, bool withUndo = false);
void setTextFast(const QString &text, bool clearUndoHistory = true);
public slots:

View File

@ -2668,7 +2668,7 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent)
, _attachDragDocument(this)
, _attachDragPhoto(this)
, _fileLoader(this, FileLoaderQueueStopTimeout)
, _synthedTextUpdate(false)
, _textUpdateEventsFlags(TextUpdateEventsSaveDraft | TextUpdateEventsSendTyping)
, _serviceImageCacheSize(0)
, _confirmWithTextId(0)
, _titlePeerTextWidth(0)
@ -2822,7 +2822,9 @@ void HistoryWidget::onMentionHashtagOrBotCommandInsert(QString str) {
void HistoryWidget::onTextChange() {
if (_peer && (!_peer->isChannel() || _peer->isMegagroup() || !_peer->asChannel()->canPublish() || (!_peer->asChannel()->isBroadcast() && !_broadcast.checked()))) {
updateSendAction(_history, SendActionTyping);
if (!_inlineBot && !_inlineBotResolveRequestId && (_textUpdateEventsFlags & TextUpdateEventsSendTyping)) {
updateSendAction(_history, SendActionTyping);
}
}
if (cHasAudioCapture()) {
@ -2846,13 +2848,13 @@ void HistoryWidget::onTextChange() {
update();
}
if (!_peer || _synthedTextUpdate) return;
if (!_peer || !(_textUpdateEventsFlags & TextUpdateEventsSaveDraft)) return;
_saveDraftText = true;
onDraftSave(true);
}
void HistoryWidget::onDraftSaveDelayed() {
if (!_peer || _synthedTextUpdate) return;
if (!_peer || !(_textUpdateEventsFlags & TextUpdateEventsSaveDraft)) return;
if (!_field.textCursor().anchor() && !_field.textCursor().position() && !_field.verticalScrollBar()->value()) {
if (!Local::hasDraftPositions(_peer->id)) return;
}
@ -2908,7 +2910,6 @@ void HistoryWidget::onCancelSendAction() {
void HistoryWidget::updateSendAction(History *history, SendActionType type, int32 progress) {
if (!history) return;
if (type == SendActionTyping && _synthedTextUpdate) return;
bool doing = (progress >= 0);
@ -3301,7 +3302,9 @@ void HistoryWidget::applyDraft(bool parseLinks) {
if (!_history) return;
setFieldText(_history->draft);
_field.setFocus();
_history->draftCursor.applyTo(_field, &_synthedTextUpdate);
_textUpdateEventsFlags = 0;
_history->draftCursor.applyTo(_field);
_textUpdateEventsFlags = TextUpdateEventsSaveDraft | TextUpdateEventsSendTyping;
_previewCancelled = _history->draftPreviewCancelled;
if (parseLinks) {
onPreviewParse();
@ -3494,7 +3497,9 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
_field.setFocus();
if (!draft.text.isEmpty()) {
MessageCursor cur = Local::readDraftPositions(fromMigrated ? _migrated->peer->id : _peer->id);
cur.applyTo(_field, &_synthedTextUpdate);
_textUpdateEventsFlags = 0;
cur.applyTo(_field);
_textUpdateEventsFlags = TextUpdateEventsSaveDraft | TextUpdateEventsSendTyping;
}
_replyToId = readyToForward() ? 0 : draft.replyTo;
_previewCancelled = draft.previewCancelled;
@ -4861,7 +4866,7 @@ bool HistoryWidget::insertBotCommand(const QString &cmd, bool specialGif) {
QString text = _field.getLastText();
if (specialGif) {
if (text.trimmed() == (cTestMode() ? qstr("@contextbot") : qstr("@gif")) && text.at(0) == '@') {
_field.setTextFast(QString(), true);
setFieldText(QString(), TextUpdateEventsSaveDraft, false);
}
} else {
QRegularExpressionMatch m = QRegularExpression(qsl("^/[A-Za-z_0-9]{0,64}(@[A-Za-z_0-9]{0,32})?(\\s|$)")).match(text);
@ -4878,7 +4883,7 @@ bool HistoryWidget::insertBotCommand(const QString &cmd, bool specialGif) {
}
} else {
if (!specialGif || _field.getLastText().isEmpty()) {
_field.setTextFast(toInsert, true);
setFieldText(toInsert, TextUpdateEventsSaveDraft, false);
_field.setFocus();
return true;
}
@ -4980,6 +4985,7 @@ bool HistoryWidget::hasBroadcastToggle() const {
}
void HistoryWidget::inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result) {
_inlineBotResolveRequestId = 0;
Notify::inlineBotRequesting(false);
_inlineBotUsername = QString();
if (result.type() == mtpc_contacts_resolvedPeer) {
@ -4993,6 +4999,7 @@ void HistoryWidget::inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result)
bool HistoryWidget::inlineBotResolveFail(QString name, const RPCError &error) {
if (mtpIsFlood(error)) return false;
_inlineBotResolveRequestId = 0;
Notify::inlineBotRequesting(false);
if (name == _inlineBotUsername) {
_inlineBot = 0;
@ -6528,10 +6535,10 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption,
_field.setFocus();
}
void HistoryWidget::setFieldText(const QString &text) {
_synthedTextUpdate = true;
_field.setTextFast(text);
_synthedTextUpdate = false;
void HistoryWidget::setFieldText(const QString &text, int32 textUpdateEventsFlags, bool clearUndoHistory) {
_textUpdateEventsFlags = textUpdateEventsFlags;
_field.setTextFast(text, clearUndoHistory);
_textUpdateEventsFlags = TextUpdateEventsSaveDraft | TextUpdateEventsSendTyping;
_previewCancelled = false;
_previewData = 0;

View File

@ -389,6 +389,11 @@ public:
};
enum TextUpdateEventsFlags {
TextUpdateEventsSaveDraft = 0x01,
TextUpdateEventsSendTyping = 0x02,
};
class HistoryWidget : public TWidget, public RPCSender {
Q_OBJECT
@ -738,7 +743,7 @@ private:
bool savedGifsFailed(const RPCError &error);
void writeDraft(MsgId *replyTo = 0, const QString *text = 0, const MessageCursor *cursor = 0, bool *previewCancelled = 0);
void setFieldText(const QString &text);
void setFieldText(const QString &text, int32 textUpdateEventsFlags = 0, bool clearUndoHistory = true);
QStringList getMediasFromMime(const QMimeData *d);
@ -814,7 +819,7 @@ private:
int32 _selCount; // < 0 - text selected, focus list, not _field
TaskQueue _fileLoader;
bool _synthedTextUpdate;
int32 _textUpdateEventsFlags;
int64 _serviceImageCacheSize;
QString _confirmSource;

View File

@ -1355,15 +1355,13 @@ struct MessageCursor {
QScrollBar *s = edit.verticalScrollBar();
scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX;
}
void applyTo(QTextEdit &edit, bool *lock = 0) {
if (lock) *lock = true;
void applyTo(QTextEdit &edit) {
QTextCursor c = edit.textCursor();
c.setPosition(anchor, QTextCursor::MoveAnchor);
c.setPosition(position, QTextCursor::KeepAnchor);
edit.setTextCursor(c);
QScrollBar *s = edit.verticalScrollBar();
if (s) s->setValue(scroll);
if (lock) *lock = false;
}
int position, anchor, scroll;
};