mirror of https://github.com/procxx/kepka.git
not sending typing status when working with inline bots
This commit is contained in:
parent
4426e2dd78
commit
d8b1df875e
|
@ -88,16 +88,16 @@ FlatTextarea::FlatTextarea(QWidget *parent, const style::flatTextarea &st, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatTextarea::setTextFast(const QString &text, bool withUndo) {
|
void FlatTextarea::setTextFast(const QString &text, bool clearUndoHistory) {
|
||||||
if (withUndo) {
|
if (clearUndoHistory) {
|
||||||
|
setPlainText(text);
|
||||||
|
} else {
|
||||||
QTextCursor c(document()->docHandle(), 0);
|
QTextCursor c(document()->docHandle(), 0);
|
||||||
c.joinPreviousEditBlock();
|
c.joinPreviousEditBlock();
|
||||||
c.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
c.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
||||||
c.insertText(text);
|
c.insertText(text);
|
||||||
c.movePosition(QTextCursor::End);
|
c.movePosition(QTextCursor::End);
|
||||||
c.endEditBlock();
|
c.endEditBlock();
|
||||||
} else {
|
|
||||||
setPlainText(text);
|
|
||||||
}
|
}
|
||||||
finishPlaceholder();
|
finishPlaceholder();
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
QMimeData *createMimeDataFromSelection() const;
|
QMimeData *createMimeDataFromSelection() const;
|
||||||
void setCtrlEnterSubmit(bool ctrlEnterSubmit);
|
void setCtrlEnterSubmit(bool ctrlEnterSubmit);
|
||||||
|
|
||||||
void setTextFast(const QString &text, bool withUndo = false);
|
void setTextFast(const QString &text, bool clearUndoHistory = true);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|
|
@ -2668,7 +2668,7 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent)
|
||||||
, _attachDragDocument(this)
|
, _attachDragDocument(this)
|
||||||
, _attachDragPhoto(this)
|
, _attachDragPhoto(this)
|
||||||
, _fileLoader(this, FileLoaderQueueStopTimeout)
|
, _fileLoader(this, FileLoaderQueueStopTimeout)
|
||||||
, _synthedTextUpdate(false)
|
, _textUpdateEventsFlags(TextUpdateEventsSaveDraft | TextUpdateEventsSendTyping)
|
||||||
, _serviceImageCacheSize(0)
|
, _serviceImageCacheSize(0)
|
||||||
, _confirmWithTextId(0)
|
, _confirmWithTextId(0)
|
||||||
, _titlePeerTextWidth(0)
|
, _titlePeerTextWidth(0)
|
||||||
|
@ -2822,8 +2822,10 @@ void HistoryWidget::onMentionHashtagOrBotCommandInsert(QString str) {
|
||||||
|
|
||||||
void HistoryWidget::onTextChange() {
|
void HistoryWidget::onTextChange() {
|
||||||
if (_peer && (!_peer->isChannel() || _peer->isMegagroup() || !_peer->asChannel()->canPublish() || (!_peer->asChannel()->isBroadcast() && !_broadcast.checked()))) {
|
if (_peer && (!_peer->isChannel() || _peer->isMegagroup() || !_peer->asChannel()->canPublish() || (!_peer->asChannel()->isBroadcast() && !_broadcast.checked()))) {
|
||||||
|
if (!_inlineBot && !_inlineBotResolveRequestId && (_textUpdateEventsFlags & TextUpdateEventsSendTyping)) {
|
||||||
updateSendAction(_history, SendActionTyping);
|
updateSendAction(_history, SendActionTyping);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cHasAudioCapture()) {
|
if (cHasAudioCapture()) {
|
||||||
if (!_field.hasSendText() && !readyToForward()) {
|
if (!_field.hasSendText() && !readyToForward()) {
|
||||||
|
@ -2846,13 +2848,13 @@ void HistoryWidget::onTextChange() {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_peer || _synthedTextUpdate) return;
|
if (!_peer || !(_textUpdateEventsFlags & TextUpdateEventsSaveDraft)) return;
|
||||||
_saveDraftText = true;
|
_saveDraftText = true;
|
||||||
onDraftSave(true);
|
onDraftSave(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::onDraftSaveDelayed() {
|
void HistoryWidget::onDraftSaveDelayed() {
|
||||||
if (!_peer || _synthedTextUpdate) return;
|
if (!_peer || !(_textUpdateEventsFlags & TextUpdateEventsSaveDraft)) return;
|
||||||
if (!_field.textCursor().anchor() && !_field.textCursor().position() && !_field.verticalScrollBar()->value()) {
|
if (!_field.textCursor().anchor() && !_field.textCursor().position() && !_field.verticalScrollBar()->value()) {
|
||||||
if (!Local::hasDraftPositions(_peer->id)) return;
|
if (!Local::hasDraftPositions(_peer->id)) return;
|
||||||
}
|
}
|
||||||
|
@ -2908,7 +2910,6 @@ void HistoryWidget::onCancelSendAction() {
|
||||||
|
|
||||||
void HistoryWidget::updateSendAction(History *history, SendActionType type, int32 progress) {
|
void HistoryWidget::updateSendAction(History *history, SendActionType type, int32 progress) {
|
||||||
if (!history) return;
|
if (!history) return;
|
||||||
if (type == SendActionTyping && _synthedTextUpdate) return;
|
|
||||||
|
|
||||||
bool doing = (progress >= 0);
|
bool doing = (progress >= 0);
|
||||||
|
|
||||||
|
@ -3301,7 +3302,9 @@ void HistoryWidget::applyDraft(bool parseLinks) {
|
||||||
if (!_history) return;
|
if (!_history) return;
|
||||||
setFieldText(_history->draft);
|
setFieldText(_history->draft);
|
||||||
_field.setFocus();
|
_field.setFocus();
|
||||||
_history->draftCursor.applyTo(_field, &_synthedTextUpdate);
|
_textUpdateEventsFlags = 0;
|
||||||
|
_history->draftCursor.applyTo(_field);
|
||||||
|
_textUpdateEventsFlags = TextUpdateEventsSaveDraft | TextUpdateEventsSendTyping;
|
||||||
_previewCancelled = _history->draftPreviewCancelled;
|
_previewCancelled = _history->draftPreviewCancelled;
|
||||||
if (parseLinks) {
|
if (parseLinks) {
|
||||||
onPreviewParse();
|
onPreviewParse();
|
||||||
|
@ -3494,7 +3497,9 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re
|
||||||
_field.setFocus();
|
_field.setFocus();
|
||||||
if (!draft.text.isEmpty()) {
|
if (!draft.text.isEmpty()) {
|
||||||
MessageCursor cur = Local::readDraftPositions(fromMigrated ? _migrated->peer->id : _peer->id);
|
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;
|
_replyToId = readyToForward() ? 0 : draft.replyTo;
|
||||||
_previewCancelled = draft.previewCancelled;
|
_previewCancelled = draft.previewCancelled;
|
||||||
|
@ -4861,7 +4866,7 @@ bool HistoryWidget::insertBotCommand(const QString &cmd, bool specialGif) {
|
||||||
QString text = _field.getLastText();
|
QString text = _field.getLastText();
|
||||||
if (specialGif) {
|
if (specialGif) {
|
||||||
if (text.trimmed() == (cTestMode() ? qstr("@contextbot") : qstr("@gif")) && text.at(0) == '@') {
|
if (text.trimmed() == (cTestMode() ? qstr("@contextbot") : qstr("@gif")) && text.at(0) == '@') {
|
||||||
_field.setTextFast(QString(), true);
|
setFieldText(QString(), TextUpdateEventsSaveDraft, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QRegularExpressionMatch m = QRegularExpression(qsl("^/[A-Za-z_0-9]{0,64}(@[A-Za-z_0-9]{0,32})?(\\s|$)")).match(text);
|
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 {
|
} else {
|
||||||
if (!specialGif || _field.getLastText().isEmpty()) {
|
if (!specialGif || _field.getLastText().isEmpty()) {
|
||||||
_field.setTextFast(toInsert, true);
|
setFieldText(toInsert, TextUpdateEventsSaveDraft, false);
|
||||||
_field.setFocus();
|
_field.setFocus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4980,6 +4985,7 @@ bool HistoryWidget::hasBroadcastToggle() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result) {
|
void HistoryWidget::inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result) {
|
||||||
|
_inlineBotResolveRequestId = 0;
|
||||||
Notify::inlineBotRequesting(false);
|
Notify::inlineBotRequesting(false);
|
||||||
_inlineBotUsername = QString();
|
_inlineBotUsername = QString();
|
||||||
if (result.type() == mtpc_contacts_resolvedPeer) {
|
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) {
|
bool HistoryWidget::inlineBotResolveFail(QString name, const RPCError &error) {
|
||||||
if (mtpIsFlood(error)) return false;
|
if (mtpIsFlood(error)) return false;
|
||||||
|
|
||||||
|
_inlineBotResolveRequestId = 0;
|
||||||
Notify::inlineBotRequesting(false);
|
Notify::inlineBotRequesting(false);
|
||||||
if (name == _inlineBotUsername) {
|
if (name == _inlineBotUsername) {
|
||||||
_inlineBot = 0;
|
_inlineBot = 0;
|
||||||
|
@ -6528,10 +6535,10 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption,
|
||||||
_field.setFocus();
|
_field.setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::setFieldText(const QString &text) {
|
void HistoryWidget::setFieldText(const QString &text, int32 textUpdateEventsFlags, bool clearUndoHistory) {
|
||||||
_synthedTextUpdate = true;
|
_textUpdateEventsFlags = textUpdateEventsFlags;
|
||||||
_field.setTextFast(text);
|
_field.setTextFast(text, clearUndoHistory);
|
||||||
_synthedTextUpdate = false;
|
_textUpdateEventsFlags = TextUpdateEventsSaveDraft | TextUpdateEventsSendTyping;
|
||||||
|
|
||||||
_previewCancelled = false;
|
_previewCancelled = false;
|
||||||
_previewData = 0;
|
_previewData = 0;
|
||||||
|
|
|
@ -389,6 +389,11 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum TextUpdateEventsFlags {
|
||||||
|
TextUpdateEventsSaveDraft = 0x01,
|
||||||
|
TextUpdateEventsSendTyping = 0x02,
|
||||||
|
};
|
||||||
|
|
||||||
class HistoryWidget : public TWidget, public RPCSender {
|
class HistoryWidget : public TWidget, public RPCSender {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -738,7 +743,7 @@ private:
|
||||||
bool savedGifsFailed(const RPCError &error);
|
bool savedGifsFailed(const RPCError &error);
|
||||||
|
|
||||||
void writeDraft(MsgId *replyTo = 0, const QString *text = 0, const MessageCursor *cursor = 0, bool *previewCancelled = 0);
|
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);
|
QStringList getMediasFromMime(const QMimeData *d);
|
||||||
|
|
||||||
|
@ -814,7 +819,7 @@ private:
|
||||||
int32 _selCount; // < 0 - text selected, focus list, not _field
|
int32 _selCount; // < 0 - text selected, focus list, not _field
|
||||||
|
|
||||||
TaskQueue _fileLoader;
|
TaskQueue _fileLoader;
|
||||||
bool _synthedTextUpdate;
|
int32 _textUpdateEventsFlags;
|
||||||
|
|
||||||
int64 _serviceImageCacheSize;
|
int64 _serviceImageCacheSize;
|
||||||
QString _confirmSource;
|
QString _confirmSource;
|
||||||
|
|
|
@ -1355,15 +1355,13 @@ struct MessageCursor {
|
||||||
QScrollBar *s = edit.verticalScrollBar();
|
QScrollBar *s = edit.verticalScrollBar();
|
||||||
scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX;
|
scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX;
|
||||||
}
|
}
|
||||||
void applyTo(QTextEdit &edit, bool *lock = 0) {
|
void applyTo(QTextEdit &edit) {
|
||||||
if (lock) *lock = true;
|
|
||||||
QTextCursor c = edit.textCursor();
|
QTextCursor c = edit.textCursor();
|
||||||
c.setPosition(anchor, QTextCursor::MoveAnchor);
|
c.setPosition(anchor, QTextCursor::MoveAnchor);
|
||||||
c.setPosition(position, QTextCursor::KeepAnchor);
|
c.setPosition(position, QTextCursor::KeepAnchor);
|
||||||
edit.setTextCursor(c);
|
edit.setTextCursor(c);
|
||||||
QScrollBar *s = edit.verticalScrollBar();
|
QScrollBar *s = edit.verticalScrollBar();
|
||||||
if (s) s->setValue(scroll);
|
if (s) s->setValue(scroll);
|
||||||
if (lock) *lock = false;
|
|
||||||
}
|
}
|
||||||
int position, anchor, scroll;
|
int position, anchor, scroll;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue