mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-10 00:29:31 +00:00
checking inline bot query on text change, not on cursor position change
This commit is contained in:
parent
d8b1df875e
commit
6fe380ff9f
@ -270,11 +270,9 @@ EmojiPtr FlatTextarea::getSingleEmoji() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString FlatTextarea::getMentionHashtagBotCommandPart(bool &start, UserData *&inlineBot, QString &inlineBotUsername) const {
|
||||
start = false;
|
||||
|
||||
// check inline bot query
|
||||
QString FlatTextarea::getInlineBotQuery(UserData *&inlineBot, QString &inlineBotUsername) const {
|
||||
const QString &text(getLastText());
|
||||
|
||||
int32 inlineUsernameStart = 1, inlineUsernameLength = 0, size = text.size();
|
||||
if (size > 2 && text.at(0) == '@' && text.at(1).isLetter()) {
|
||||
inlineUsernameLength = 1;
|
||||
@ -318,6 +316,11 @@ QString FlatTextarea::getMentionHashtagBotCommandPart(bool &start, UserData *&in
|
||||
inlineBot = 0;
|
||||
inlineBotUsername = QString();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString FlatTextarea::getMentionHashtagBotCommandPart(bool &start) const {
|
||||
start = false;
|
||||
|
||||
int32 pos = textCursor().position();
|
||||
if (textCursor().anchor() != pos) return QString();
|
||||
|
@ -64,7 +64,8 @@ public:
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
EmojiPtr getSingleEmoji() const;
|
||||
QString getMentionHashtagBotCommandPart(bool &start, UserData *&contextBot, QString &contextBotUsername) const;
|
||||
QString getMentionHashtagBotCommandPart(bool &start) const;
|
||||
QString getInlineBotQuery(UserData *&contextBot, QString &contextBotUsername) const;
|
||||
void removeSingleEmoji();
|
||||
bool hasText() const;
|
||||
|
||||
|
@ -2820,9 +2820,53 @@ void HistoryWidget::onMentionHashtagOrBotCommandInsert(QString str) {
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::updateInlineBotQuery() {
|
||||
UserData *bot = _inlineBot;
|
||||
bool start = false;
|
||||
QString inlineBotUsername(_inlineBotUsername);
|
||||
QString query = _field.getInlineBotQuery(_inlineBot, _inlineBotUsername);
|
||||
if (inlineBotUsername != _inlineBotUsername) {
|
||||
if (_inlineBotResolveRequestId) {
|
||||
Notify::inlineBotRequesting(false);
|
||||
MTP::cancel(_inlineBotResolveRequestId);
|
||||
_inlineBotResolveRequestId = 0;
|
||||
}
|
||||
if (_inlineBot == InlineBotLookingUpData) {
|
||||
Notify::inlineBotRequesting(true);
|
||||
_inlineBotResolveRequestId = MTP::send(MTPcontacts_ResolveUsername(MTP_string(_inlineBotUsername)), rpcDone(&HistoryWidget::inlineBotResolveDone), rpcFail(&HistoryWidget::inlineBotResolveFail, _inlineBotUsername));
|
||||
return;
|
||||
}
|
||||
} else if (_inlineBot == InlineBotLookingUpData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inlineBot) {
|
||||
if (_inlineBot != bot) {
|
||||
updateFieldPlaceholder();
|
||||
}
|
||||
if (_inlineBot->username == (cTestMode() ? qstr("contextbot") : qstr("gif")) && query.isEmpty()) {
|
||||
_emojiPan.clearInlineBot();
|
||||
} else {
|
||||
_emojiPan.queryInlineBot(_inlineBot, query);
|
||||
}
|
||||
if (!_attachMention.isHidden()) {
|
||||
_attachMention.hideStart();
|
||||
}
|
||||
} else {
|
||||
if (_inlineBot != bot) {
|
||||
updateFieldPlaceholder();
|
||||
_field.finishPlaceholder();
|
||||
}
|
||||
_emojiPan.clearInlineBot();
|
||||
onCheckMentionDropdown();
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryWidget::onTextChange() {
|
||||
updateInlineBotQuery();
|
||||
|
||||
if (_peer && (!_peer->isChannel() || _peer->isMegagroup() || !_peer->asChannel()->canPublish() || (!_peer->asChannel()->isBroadcast() && !_broadcast.checked()))) {
|
||||
if (!_inlineBot && !_inlineBotResolveRequestId && (_textUpdateEventsFlags & TextUpdateEventsSendTyping)) {
|
||||
if (!_inlineBot && (_textUpdateEventsFlags & TextUpdateEventsSendTyping)) {
|
||||
updateSendAction(_history, SendActionTyping);
|
||||
}
|
||||
}
|
||||
@ -5347,52 +5391,16 @@ void HistoryWidget::onFieldFocused() {
|
||||
}
|
||||
|
||||
void HistoryWidget::onCheckMentionDropdown() {
|
||||
if (!_history || _a_show.animating()) return;
|
||||
if (!_history || _a_show.animating() || _inlineBot) return;
|
||||
|
||||
UserData *bot = _inlineBot;
|
||||
bool start = false;
|
||||
QString inlineBotUsername(_inlineBotUsername);
|
||||
QString query = _field.getMentionHashtagBotCommandPart(start, _inlineBot, _inlineBotUsername);
|
||||
if (inlineBotUsername != _inlineBotUsername) {
|
||||
if (_inlineBotResolveRequestId) {
|
||||
Notify::inlineBotRequesting(false);
|
||||
MTP::cancel(_inlineBotResolveRequestId);
|
||||
_inlineBotResolveRequestId = 0;
|
||||
}
|
||||
if (_inlineBot == InlineBotLookingUpData) {
|
||||
Notify::inlineBotRequesting(true);
|
||||
_inlineBotResolveRequestId = MTP::send(MTPcontacts_ResolveUsername(MTP_string(_inlineBotUsername)), rpcDone(&HistoryWidget::inlineBotResolveDone), rpcFail(&HistoryWidget::inlineBotResolveFail, _inlineBotUsername));
|
||||
return;
|
||||
}
|
||||
} else if (_inlineBot == InlineBotLookingUpData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_inlineBot) {
|
||||
if (_inlineBot != bot) {
|
||||
updateFieldPlaceholder();
|
||||
}
|
||||
if (_inlineBot->username == (cTestMode() ? qstr("contextbot") : qstr("gif")) && query.isEmpty()) {
|
||||
_emojiPan.clearInlineBot();
|
||||
} else {
|
||||
_emojiPan.queryInlineBot(_inlineBot, query);
|
||||
}
|
||||
if (!_attachMention.isHidden()) {
|
||||
_attachMention.hideStart();
|
||||
}
|
||||
} else {
|
||||
if (_inlineBot != bot) {
|
||||
updateFieldPlaceholder();
|
||||
_field.finishPlaceholder();
|
||||
}
|
||||
_emojiPan.clearInlineBot();
|
||||
if (!query.isEmpty()) {
|
||||
if (query.at(0) == '#' && cRecentWriteHashtags().isEmpty() && cRecentSearchHashtags().isEmpty()) Local::readRecentHashtagsAndBots();
|
||||
if (query.at(0) == '@' && cRecentInlineBots().isEmpty()) Local::readRecentHashtagsAndBots();
|
||||
if (query.at(0) == '/' && _peer->isUser() && !_peer->asUser()->botInfo) return;
|
||||
}
|
||||
_attachMention.showFiltered(_peer, query, start);
|
||||
QString query = _field.getMentionHashtagBotCommandPart(start);
|
||||
if (!query.isEmpty()) {
|
||||
if (query.at(0) == '#' && cRecentWriteHashtags().isEmpty() && cRecentSearchHashtags().isEmpty()) Local::readRecentHashtagsAndBots();
|
||||
if (query.at(0) == '@' && cRecentInlineBots().isEmpty()) Local::readRecentHashtagsAndBots();
|
||||
if (query.at(0) == '/' && _peer->isUser() && !_peer->asUser()->botInfo) return;
|
||||
}
|
||||
_attachMention.showFiltered(_peer, query, start);
|
||||
}
|
||||
|
||||
void HistoryWidget::updateFieldPlaceholder() {
|
||||
|
@ -451,6 +451,7 @@ public:
|
||||
void destroyData();
|
||||
|
||||
void updateFieldPlaceholder();
|
||||
void updateInlineBotQuery();
|
||||
|
||||
void uploadImage(const QImage &img, PrepareMediaType type, FileLoadForceConfirmType confirm = FileLoadNoForceConfirm, const QString &source = QString(), bool withText = false);
|
||||
void uploadFile(const QString &file, PrepareMediaType type, FileLoadForceConfirmType confirm = FileLoadNoForceConfirm, bool withText = false); // with confirmation
|
||||
|
@ -1364,7 +1364,11 @@ void DocumentOpenLink::doOpen(DocumentData *data, ActionOnLoad action) {
|
||||
}
|
||||
} else if (location.accessEnable()) {
|
||||
if ((App::hoveredLinkItem() || App::contextItem()) && (data->isAnimation() || QImageReader(location.name()).canRead())) {
|
||||
App::wnd()->showDocument(data, item);
|
||||
if (action == ActionOnLoadPlayInline) {
|
||||
item->getMedia()->playInline(item);
|
||||
} else {
|
||||
App::wnd()->showDocument(data, item);
|
||||
}
|
||||
} else {
|
||||
psOpenFile(location.name());
|
||||
}
|
||||
@ -1634,7 +1638,11 @@ void DocumentData::performActionOnLoad() {
|
||||
} else if (_actionOnLoad == ActionOnLoadOpen || _actionOnLoad == ActionOnLoadPlayInline) {
|
||||
if (loc.accessEnable()) {
|
||||
if (showImage && QImageReader(loc.name()).canRead()) {
|
||||
App::wnd()->showDocument(this, item);
|
||||
if (_actionOnLoad == ActionOnLoadPlayInline) {
|
||||
item->getMedia()->playInline(item);
|
||||
} else {
|
||||
App::wnd()->showDocument(this, item);
|
||||
}
|
||||
} else {
|
||||
psOpenFile(already);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user