Skip to content

Commit

Permalink
No confirmations for verified game bots. Disabled Game media edition.
Browse files Browse the repository at this point in the history
Also inline bot requests are sent after "@...bot" even without space.
  • Loading branch information
john-preston committed Sep 29, 2016
1 parent 01a5aa3 commit 1247bd1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/core/click_handler_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/history/history_media_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/history/history_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<HistoryServiceGameScore>()) {
if (!result.link && outer.contains(x, y)) {
if (!result.link && result.cursor == HistoryInTextCursorState && outer.contains(x, y)) {
result.link = gamescore->lnk;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/historywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
42 changes: 30 additions & 12 deletions Telegram/SourceFiles/ui/flattextarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 2 additions & 4 deletions Telegram/SourceFiles/ui/flattextarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class FlatTextarea : public QTextEdit {
T_WIDGET

public:

struct Tag {
int offset, length;
QString id;
Expand Down Expand Up @@ -122,7 +121,6 @@ class FlatTextarea : public QTextEdit {
void setTagMimeProcessor(std_::unique_ptr<TagMimeProcessor> &&processor);

public slots:

void onTouchTimer();

void onDocumentContentsChange(int position, int charsRemoved, int charsAdded);
Expand All @@ -132,7 +130,6 @@ public slots:
void onRedoAvailable(bool avail);

signals:

void resized();
void changed();
void submitted(bool ctrlShiftEnter);
Expand Down Expand Up @@ -170,7 +167,6 @@ public slots:
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;
Expand All @@ -188,6 +184,8 @@ public slots:

bool heightAutoupdated();

int placeholderSkipWidth() const;

int _minHeight = -1; // < 0 - no autosize
int _maxHeight = -1;
int _maxLength = -1;
Expand Down

0 comments on commit 1247bd1

Please sign in to comment.