From 1247bd19b60935d3992d694a60ffba1c8b1c1ce4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 29 Sep 2016 19:15:44 +0300 Subject: [PATCH] No confirmations for verified game bots. Disabled Game media edition. Also inline bot requests are sent after "@...bot" even without space. --- .../SourceFiles/core/click_handler_types.cpp | 2 +- .../history/history_media_types.cpp | 2 +- .../SourceFiles/history/history_message.cpp | 5 ++- Telegram/SourceFiles/historywidget.cpp | 4 +- Telegram/SourceFiles/ui/flattextarea.cpp | 42 +++++++++++++------ Telegram/SourceFiles/ui/flattextarea.h | 6 +-- 6 files changed, 40 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 36b25a67a..45f331df3 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -117,7 +117,7 @@ void BotGameUrlClickHandler::onClick(Qt::MouseButton button) const { if (u.startsWith(qstr("tg://"))) { App::openLocalUrl(u); - } else if (!_bot || Local::isBotTrusted(_bot)) { + } else if (!_bot || _bot->isVerified() || Local::isBotTrusted(_bot)) { doOpen(u); } else { Ui::showLayer(new ConfirmBotGameBox(_bot, u)); diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 813ff67f1..5d775c83c 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -1094,7 +1094,7 @@ void HistoryDocument::draw(Painter &p, const QRect &r, TextSelection selection, auto inWebPage = (_parent->getMedia() != this); auto roundRadius = inWebPage ? ImageRoundRadius::Small : ImageRoundRadius::Large; QRect rthumb(rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, _width)); - QPixmap thumb = loaded ? _data->thumb->pixSingle(roundRadius, thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize) : _data->thumb->pixBlurredSingle(ImageRoundRadius::Small, thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize); + QPixmap thumb = loaded ? _data->thumb->pixSingle(roundRadius, thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize) : _data->thumb->pixBlurredSingle(roundRadius, thumbed->_thumbw, 0, st::msgFileThumbSize, st::msgFileThumbSize); p.drawPixmap(rthumb.topLeft(), thumb); if (selected) { auto overlayCorners = inWebPage ? SelectedOverlaySmallCorners : SelectedOverlayLargeCorners; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index f47b7e1ff..0190a3ec3 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -968,6 +968,9 @@ void HistoryMessage::setMedia(const MTPMessageMedia *media) { bool mediaRemovedSkipBlock = false; if (_media) { + // Don't update Game media because we loose the consumed text of the message. + if (_media->type() == MediaTypeGame) return; + mediaRemovedSkipBlock = _media->isDisplayed() && _media->isBubbleBottom(); _media.clear(); } @@ -2180,7 +2183,7 @@ HistoryTextState HistoryService::getState(int x, int y, HistoryStateRequest requ result = _text.getState(x - trect.x(), y - trect.y(), trect.width(), textRequest); textstyleRestore(); if (auto gamescore = Get()) { - if (!result.link && outer.contains(x, y)) { + if (!result.link && result.cursor == HistoryInTextCursorState && outer.contains(x, y)) { result.link = gamescore->lnk; } } diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 86d604a88..8e0ce3af9 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -6027,7 +6027,7 @@ void HistoryWidget::inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result) UserData *bot = nullptr; QString inlineBotUsername; - QString query = _field.getInlineBotQuery(&bot, &inlineBotUsername); + auto query = _field.getInlineBotQuery(&bot, &inlineBotUsername); if (inlineBotUsername == _inlineBotUsername) { if (bot == LookingUpInlineBot) { bot = resolvedBot; @@ -6567,7 +6567,7 @@ void HistoryWidget::uploadImage(const QImage &img, PrepareMediaType type, FileLo if (!_history) return; App::wnd()->activateWindow(); - FileLoadTask *task = new FileLoadTask(img, type, FileLoadTo(_peer->id, _silent.checked(), replyToId()), confirm, source); + auto task = new FileLoadTask(img, type, FileLoadTo(_peer->id, _silent.checked(), replyToId()), confirm, source); if (withText) { _confirmWithTextId = task->fileid(); } diff --git a/Telegram/SourceFiles/ui/flattextarea.cpp b/Telegram/SourceFiles/ui/flattextarea.cpp index ed62bf939..1aae73771 100644 --- a/Telegram/SourceFiles/ui/flattextarea.cpp +++ b/Telegram/SourceFiles/ui/flattextarea.cpp @@ -286,7 +286,7 @@ void FlatTextarea::paintEvent(QPaintEvent *e) { p.setFont(_st.font); p.setPen(a_phColor.current()); if (_st.phAlign == style::al_topleft && _phAfter > 0) { - int skipWidth = _st.font->width(getTextWithTags().text.mid(0, _phAfter)); + int skipWidth = placeholderSkipWidth(); p.drawText(_st.textMrg.left() - _fakeMargin + a_phLeft.current() + skipWidth, _st.textMrg.top() - _fakeMargin - st::lineWidth + _st.font->ascent, _ph); } else { QRect phRect(_st.textMrg.left() - _fakeMargin + _st.phPos.x() + a_phLeft.current(), _st.textMrg.top() - _fakeMargin + _st.phPos.y(), width() - _st.textMrg.left() - _st.textMrg.right(), height() - _st.textMrg.top() - _st.textMrg.bottom()); @@ -298,6 +298,18 @@ void FlatTextarea::paintEvent(QPaintEvent *e) { QTextEdit::paintEvent(e); } +int FlatTextarea::placeholderSkipWidth() const { + if (!_phAfter) { + return 0; + } + auto text = getTextWithTags().text; + auto result = _st.font->width(text.mid(0, _phAfter)); + if (_phAfter > text.size()) { + result += _st.font->spacew; + } + return result; +} + void FlatTextarea::focusInEvent(QFocusEvent *e) { a_phColor.start(_st.phFocusColor->c); _a_appearance.start(); @@ -339,11 +351,12 @@ QString FlatTextarea::getInlineBotQuery(UserData **outInlineBot, QString *outInl t_assert(outInlineBotUsername != nullptr); auto &text = getTextWithTags().text; + auto textLength = text.size(); - int32 inlineUsernameStart = 1, inlineUsernameLength = 0, size = text.size(); - if (size > 2 && text.at(0) == '@' && text.at(1).isLetter()) { + int inlineUsernameStart = 1, inlineUsernameLength = 0; + if (textLength > 2 && text.at(0) == '@' && text.at(1).isLetter()) { inlineUsernameLength = 1; - for (int32 i = inlineUsernameStart + 1, l = text.size(); i < l; ++i) { + for (int i = inlineUsernameStart + 1; i != textLength; ++i) { if (text.at(i).isLetterOrNumber() || text.at(i).unicode() == '_') { ++inlineUsernameLength; continue; @@ -353,11 +366,19 @@ QString FlatTextarea::getInlineBotQuery(UserData **outInlineBot, QString *outInl } break; } - if (inlineUsernameLength && inlineUsernameStart + inlineUsernameLength < text.size() && text.at(inlineUsernameStart + inlineUsernameLength).isSpace()) { - QStringRef username = text.midRef(inlineUsernameStart, inlineUsernameLength); + auto inlineUsernameEnd = inlineUsernameStart + inlineUsernameLength; + auto inlineUsernameEqualsText = (inlineUsernameEnd == textLength); + auto validInlineUsername = false; + if (inlineUsernameEqualsText) { + validInlineUsername = text.endsWith(qstr("bot")); + } else if (inlineUsernameEnd < textLength && inlineUsernameLength) { + validInlineUsername = text.at(inlineUsernameEnd).isSpace(); + } + if (validInlineUsername) { + auto username = text.midRef(inlineUsernameStart, inlineUsernameLength); if (username != *outInlineBotUsername) { *outInlineBotUsername = username.toString(); - PeerData *peer = App::peerByName(*outInlineBotUsername); + auto peer = App::peerByName(*outInlineBotUsername); if (peer) { if (peer->isUser()) { *outInlineBot = peer->asUser(); @@ -373,7 +394,7 @@ QString FlatTextarea::getInlineBotQuery(UserData **outInlineBot, QString *outInl if (*outInlineBot && (!(*outInlineBot)->botInfo || (*outInlineBot)->botInfo->inlinePlaceholder.isEmpty())) { *outInlineBot = nullptr; } else { - return text.mid(inlineUsernameStart + inlineUsernameLength + 1); + return inlineUsernameEqualsText ? QString() : text.mid(inlineUsernameEnd + 1); } } else { inlineUsernameLength = 0; @@ -1265,10 +1286,7 @@ void FlatTextarea::setPlaceholder(const QString &ph, int32 afterSymbols) { _phAfter = afterSymbols; updatePlaceholder(); } - int skipWidth = 0; - if (_phAfter) { - skipWidth = _st.font->width(getTextWithTags().text.mid(0, _phAfter)); - } + int skipWidth = placeholderSkipWidth(); _phelided = _st.font->elided(_ph, width() - _st.textMrg.left() - _st.textMrg.right() - _st.phPos.x() - 1 - skipWidth); if (_phVisible) update(); } diff --git a/Telegram/SourceFiles/ui/flattextarea.h b/Telegram/SourceFiles/ui/flattextarea.h index 3dccd2743..a29687e1e 100644 --- a/Telegram/SourceFiles/ui/flattextarea.h +++ b/Telegram/SourceFiles/ui/flattextarea.h @@ -30,7 +30,6 @@ class FlatTextarea : public QTextEdit { T_WIDGET public: - struct Tag { int offset, length; QString id; @@ -122,7 +121,6 @@ public: void setTagMimeProcessor(std_::unique_ptr &&processor); public slots: - void onTouchTimer(); void onDocumentContentsChange(int position, int charsRemoved, int charsAdded); @@ -132,7 +130,6 @@ public slots: void onRedoAvailable(bool avail); signals: - void resized(); void changed(); void submitted(bool ctrlShiftEnter); @@ -170,7 +167,6 @@ protected: void checkContentHeight(); private: - // "start" and "end" are in coordinates of text where emoji are replaced // by ObjectReplacementCharacter. If "end" = -1 means get text till the end. QString getTextPart(int start, int end, TagList *outTagsList, bool *outTagsChanged = nullptr) const; @@ -188,6 +184,8 @@ private: bool heightAutoupdated(); + int placeholderSkipWidth() const; + int _minHeight = -1; // < 0 - no autosize int _maxHeight = -1; int _maxLength = -1;