From eb47b9468ce69fa5c3dd99636c82763eeeacd064 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 7 Oct 2016 10:58:34 +0300 Subject: [PATCH] Various fixes. Copy inline keyboard when forwarding messages with a game. Don't show "Deleted Message" in service message with scores. Improved tiny web page previews. Ignore right button in emoji panel. --- Telegram/Resources/langs/lang.strings | 2 + Telegram/SourceFiles/history/history_item.cpp | 25 ++++++-- Telegram/SourceFiles/history/history_item.h | 19 +++--- .../history/history_media_types.cpp | 6 +- .../SourceFiles/history/history_message.cpp | 64 ++++++++++++++----- .../SourceFiles/history/history_message.h | 9 ++- Telegram/SourceFiles/localstorage.cpp | 4 ++ .../settings/settings_general_widget.cpp | 3 + Telegram/SourceFiles/stickers/emoji_pan.cpp | 10 ++- 9 files changed, 104 insertions(+), 38 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index c8384625e1..38dfc25080 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -590,6 +590,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org "lng_action_pinned_media_game" = "the game «{game}»"; "lng_action_game_score" = "{from} scored {count:#|#|#} in {game}"; "lng_action_game_you_scored" = "You scored {count:#|#|#} in {game}"; +"lng_action_game_score_no_game" = "{from} scored {count:#|#|#}"; +"lng_action_game_you_scored_no_game" = "You scored {count:#|#|#}"; "lng_profile_migrate_reached" = "{count:_not_used_|# member|# members} limit reached"; "lng_profile_migrate_body" = "To get over this limit, you can upgrade your group to a supergroup."; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index f792eafd6f..c4d8c2978d 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -359,7 +359,7 @@ void HistoryMessageReplyMarkup::createFromButtonRows(const QVector()) { + if (auto fwd = Get()) { return fwd->_fromOriginal; } return from(); } PeerData *authorOriginal() const { - if (const HistoryMessageForwarded *fwd = Get()) { + if (auto fwd = Get()) { return fwd->_authorOriginal; } return author(); @@ -898,6 +899,12 @@ protected: void recountAttachToPrevious(); const HistoryMessageReplyMarkup *inlineReplyMarkup() const { + return const_cast(this)->inlineReplyMarkup(); + } + const ReplyKeyboard *inlineReplyKeyboard() const { + return const_cast(this)->inlineReplyKeyboard(); + } + HistoryMessageReplyMarkup *inlineReplyMarkup() { if (auto markup = Get()) { if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) { return markup; @@ -905,18 +912,12 @@ protected: } return nullptr; } - const ReplyKeyboard *inlineReplyKeyboard() const { + ReplyKeyboard *inlineReplyKeyboard() { if (auto markup = inlineReplyMarkup()) { return markup->inlineKeyboard.get(); } return nullptr; } - HistoryMessageReplyMarkup *inlineReplyMarkup() { - return const_cast(static_cast(this)->inlineReplyMarkup()); - } - ReplyKeyboard *inlineReplyKeyboard() { - return const_cast(static_cast(this)->inlineReplyKeyboard()); - } TextSelection toMediaSelection(TextSelection selection) const { return internal::unshiftSelection(selection, _text); diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 3505b01f55..934e43bc68 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -2562,7 +2562,7 @@ int HistoryWebPage::resizeGetHeight(int width) { return _height; } - _width = width = qMin(width, _maxw); + _width = width/* = qMin(width, _maxw)*/; width -= st::msgPadding.left() + st::webPageLeft + st::msgPadding.right(); int32 linesMax = 5; @@ -2686,9 +2686,9 @@ void HistoryWebPage::draw(Painter &p, const QRect &r, TextSelection selection, u } else { pix = _data->photo->thumb->pixBlurredSingle(ImageRoundRadius::Small, pixw, pixh, pw, ph); } - p.drawPixmapLeft(padding.left() + width - pw, 0, _width, pix); + p.drawPixmapLeft(padding.left() + width - pw, tshift, _width, pix); if (selected) { - App::roundRect(p, rtlrect(padding.left() + width - pw, 0, pw, _pixh, _width), textstyleCurrent()->selectOverlay, SelectedOverlaySmallCorners); + App::roundRect(p, rtlrect(padding.left() + width - pw, tshift, pw, _pixh, _width), textstyleCurrent()->selectOverlay, SelectedOverlaySmallCorners); } width -= pw + st::webPagePhotoDelta; } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 50d10940a1..7e7779f0d0 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -366,7 +366,7 @@ HistoryMessage::HistoryMessage(History *history, const MTPDmessage &msg) CreateConfig config; if (msg.has_fwd_from() && msg.vfwd_from.type() == mtpc_messageFwdHeader) { - const auto &f(msg.vfwd_from.c_messageFwdHeader()); + auto &f = msg.vfwd_from.c_messageFwdHeader(); if (f.has_from_id() || f.has_channel_id()) { config.authorIdOriginal = f.has_channel_id() ? peerFromChannel(f.vchannel_id) : peerFromUser(f.vfrom_id); config.fromIdOriginal = f.has_from_id() ? peerFromUser(f.vfrom_id) : peerFromChannel(f.vchannel_id); @@ -376,7 +376,7 @@ HistoryMessage::HistoryMessage(History *history, const MTPDmessage &msg) if (msg.has_reply_to_msg_id()) config.replyTo = msg.vreply_to_msg_id.v; if (msg.has_via_bot_id()) config.viaBotId = msg.vvia_bot_id.v; if (msg.has_views()) config.viewsCount = msg.vviews.v; - if (msg.has_reply_markup()) config.markup = &msg.vreply_markup; + if (msg.has_reply_markup()) config.mtpMarkup = &msg.vreply_markup; if (msg.has_edit_date()) config.editDate = ::date(msg.vedit_date); createComponents(config); @@ -435,9 +435,15 @@ HistoryMessage::HistoryMessage(History *history, MsgId id, MTPDmessage::Flags fl config.viewsCount = 1; } + // Copy inline keyboard when forwarding messages with a game. + auto mediaOriginal = fwd->getMedia(); + if (mediaOriginal && mediaOriginal->type() == MediaTypeGame) { + config.inlineMarkup = fwd->inlineReplyMarkup(); + } + createComponents(config); - if (HistoryMedia *mediaOriginal = fwd->getMedia()) { + if (mediaOriginal) { _media.reset(mediaOriginal->clone(this)); } setText(fwd->originalText()); @@ -479,7 +485,7 @@ void HistoryMessage::createComponentsHelper(MTPDmessage::Flags flags, MsgId repl if (flags & MTPDmessage::Flag::f_via_bot_id) config.viaBotId = viaBotId; if (flags & MTPDmessage::Flag::f_reply_to_msg_id) config.replyTo = replyTo; - if (flags & MTPDmessage::Flag::f_reply_markup) config.markup = &markup; + if (flags & MTPDmessage::Flag::f_reply_markup) config.mtpMarkup = &markup; if (isPost()) config.viewsCount = 1; createComponents(config); @@ -518,8 +524,10 @@ void HistoryMessage::updateMediaInBubbleState() { _media->setInBubbleState(computeState()); } -bool HistoryMessage::displayEditedBadge(bool hasViaBot) const { - if (!(_flags & MTPDmessage::Flag::f_edit_date)) { +bool HistoryMessage::displayEditedBadge(bool hasViaBotOrInlineMarkup) const { + if (hasViaBotOrInlineMarkup) { + return false; + } else if (!(_flags & MTPDmessage::Flag::f_edit_date)) { return false; } if (auto fromUser = from()->asUser()) { @@ -527,9 +535,6 @@ bool HistoryMessage::displayEditedBadge(bool hasViaBot) const { return false; } } - if (hasViaBot) { - return false; - } return true; } @@ -548,20 +553,31 @@ void HistoryMessage::createComponents(const CreateConfig &config) { if (isPost() && _from->isUser()) { mask |= HistoryMessageSigned::Bit(); } - if (displayEditedBadge(config.viaBotId != 0)) { + auto hasViaBot = (config.viaBotId != 0); + auto hasInlineMarkup = [&config] { + if (config.mtpMarkup) { + return (config.mtpMarkup->type() == mtpc_replyInlineMarkup); + } + return (config.inlineMarkup != nullptr); + }; + if (displayEditedBadge(hasViaBot || hasInlineMarkup())) { mask |= HistoryMessageEdited::Bit(); } if (config.authorIdOriginal && config.fromIdOriginal) { mask |= HistoryMessageForwarded::Bit(); } - if (config.markup) { + if (config.mtpMarkup) { // optimization: don't create markup component for the case // MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag - if (config.markup->type() != mtpc_replyKeyboardHide || config.markup->c_replyKeyboardHide().vflags.v != 0) { + if (config.mtpMarkup->type() != mtpc_replyKeyboardHide || config.mtpMarkup->c_replyKeyboardHide().vflags.v != 0) { mask |= HistoryMessageReplyMarkup::Bit(); } + } else if (config.inlineMarkup) { + mask |= HistoryMessageReplyMarkup::Bit(); } + UpdateComponents(mask); + if (auto reply = Get()) { reply->replyToMsgId = config.replyTo; if (!reply->updateData(this) && App::api()) { @@ -586,7 +602,11 @@ void HistoryMessage::createComponents(const CreateConfig &config) { fwd->_originalId = config.originalId; } if (auto markup = Get()) { - markup->create(*config.markup); + if (config.mtpMarkup) { + markup->create(*config.mtpMarkup); + } else if (config.inlineMarkup) { + markup->create(*config.inlineMarkup); + } if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button) { _flags |= MTPDmessage_ClientFlag::f_has_switch_inline_button; } @@ -829,7 +849,9 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) { if (message.has_edit_date()) { _flags |= MTPDmessage::Flag::f_edit_date; - if (displayEditedBadge(Has())) { + auto hasViaBotId = Has(); + auto hasInlineMarkup = (inlineReplyMarkup() != nullptr); + if (displayEditedBadge(hasViaBotId || hasInlineMarkup)) { if (!Has()) { AddComponents(HistoryMessageEdited::Bit()); } @@ -2009,13 +2031,21 @@ bool HistoryService::prepareGameScoreText(const QString &from, QString *outText, gameTitle = lang(lng_contacts_loading); result = true; } else { - gameTitle = lang(lng_deleted_message); + gameTitle = QString(); } auto scoreNumber = gamescore ? gamescore->score : 0; if (_from->isSelf()) { - *outText = lng_action_game_you_scored(lt_count, scoreNumber, lt_game, gameTitle); + if (gameTitle.isEmpty()) { + *outText = lng_action_game_you_scored_no_game(lt_count, scoreNumber); + } else { + *outText = lng_action_game_you_scored(lt_count, scoreNumber, lt_game, gameTitle); + } } else { - *outText = lng_action_game_score(lt_from, from, lt_count, scoreNumber, lt_game, gameTitle); + if (gameTitle.isEmpty()) { + *outText = lng_action_game_score_no_game(lt_from, from, lt_count, scoreNumber); + } else { + *outText = lng_action_game_score(lt_from, from, lt_count, scoreNumber, lt_game, gameTitle); + } } if (second) { outLinks->push_back(second); diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index c52e6490c5..0a1408c9b3 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -63,7 +63,7 @@ public: return (!emptyText() || !_media || !_media->isDisplayed() || Has() || Has() || viaBot() || !_media->hideFromName()); } - bool displayEditedBadge(bool hasViaBot) const; + bool displayEditedBadge(bool hasViaBotOrInlineMarkup) const; bool uploading() const { return _media && _media->uploading(); } @@ -191,7 +191,12 @@ private: PeerId fromIdOriginal = 0; MsgId originalId = 0; QDateTime editDate; - const MTPReplyMarkup *markup = nullptr; + + // For messages created from MTP structs. + const MTPReplyMarkup *mtpMarkup = nullptr; + + // For messages created from existing messages (forwarded). + const HistoryMessageReplyMarkup *inlineMarkup = nullptr; }; void createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, int32 viaBotId, const MTPReplyMarkup &markup); void createComponents(const CreateConfig &config); diff --git a/Telegram/SourceFiles/localstorage.cpp b/Telegram/SourceFiles/localstorage.cpp index 9f43d60f49..bc71589ec9 100644 --- a/Telegram/SourceFiles/localstorage.cpp +++ b/Telegram/SourceFiles/localstorage.cpp @@ -31,6 +31,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwidget.h" #include "mainwindow.h" #include "lang.h" +#include "application.h" #include "playerwidget.h" #include "apiwrap.h" @@ -1078,6 +1079,9 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version) { if (!_checkStreamStatus(stream)) return false; cSetAutoUpdate(v == 1); + if (!cAutoUpdate()) { + Sandbox::stopUpdate(); + } } break; case dbiLastUpdateCheck: { diff --git a/Telegram/SourceFiles/settings/settings_general_widget.cpp b/Telegram/SourceFiles/settings/settings_general_widget.cpp index 4945dd5c8c..9c5e66c59f 100644 --- a/Telegram/SourceFiles/settings/settings_general_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_general_widget.cpp @@ -193,6 +193,9 @@ void GeneralWidget::refreshControls() { style::margins marginLink(st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip); addChildRow(_updateRow, marginLink, slidedPadding); connect(_updateRow->entity(), SIGNAL(restart()), this, SLOT(onRestart())); + if (!cAutoUpdate()) { + _updateRow->hideFast(); + } #endif // TDESKTOP_DISABLE_AUTOUPDATE if (cPlatform() == dbipWindows || cSupportTray()) { diff --git a/Telegram/SourceFiles/stickers/emoji_pan.cpp b/Telegram/SourceFiles/stickers/emoji_pan.cpp index 900ea04dab..63850ba287 100644 --- a/Telegram/SourceFiles/stickers/emoji_pan.cpp +++ b/Telegram/SourceFiles/stickers/emoji_pan.cpp @@ -116,6 +116,9 @@ void EmojiColorPicker::leaveEvent(QEvent *e) { } void EmojiColorPicker::mousePressEvent(QMouseEvent *e) { + if (e->button() != Qt::LeftButton) { + return; + } _lastMousePos = e->globalPos(); updateSelected(); _pressedSel = _selected; @@ -411,7 +414,7 @@ bool EmojiPanInner::checkPickerHide() { void EmojiPanInner::mousePressEvent(QMouseEvent *e) { _lastMousePos = e->globalPos(); updateSelected(); - if (checkPickerHide()) { + if (checkPickerHide() || e->button() != Qt::LeftButton) { return; } _pressedSel = _selected; @@ -1160,6 +1163,9 @@ QRect StickerPanInner::featuredAddRect(int index) const { } void StickerPanInner::mousePressEvent(QMouseEvent *e) { + if (e->button() != Qt::LeftButton) { + return; + } _lastMousePos = e->globalPos(); updateSelected(); @@ -2895,7 +2901,7 @@ void EmojiPan::otherLeave() { } void EmojiPan::mousePressEvent(QMouseEvent *e) { - if (!_stickersShown) return; + if (!_stickersShown || e->button() != Qt::LeftButton) return; _iconsMousePos = e ? e->globalPos() : QCursor::pos(); updateSelected();