From b629e0c43a27161889f40be93f40f1130bf0f17b Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 27 Jun 2020 18:53:30 +0300 Subject: [PATCH] Replaced Notify::replyMarkupUpdated with Data::MessageUpdate. --- Telegram/SourceFiles/data/data_changes.h | 3 ++- Telegram/SourceFiles/facades.cpp | 6 ------ Telegram/SourceFiles/facades.h | 1 - Telegram/SourceFiles/history/history_item.cpp | 2 +- Telegram/SourceFiles/history/history_message.cpp | 16 +++++++++------- Telegram/SourceFiles/history/history_widget.cpp | 14 ++++++++------ Telegram/SourceFiles/history/history_widget.h | 2 -- Telegram/SourceFiles/mainwidget.cpp | 4 ---- Telegram/SourceFiles/mainwidget.h | 1 - 9 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Telegram/SourceFiles/data/data_changes.h b/Telegram/SourceFiles/data/data_changes.h index db5230ab5e..930df35d5a 100644 --- a/Telegram/SourceFiles/data/data_changes.h +++ b/Telegram/SourceFiles/data/data_changes.h @@ -133,8 +133,9 @@ struct MessageUpdate { DialogRowRepaint = (1 << 2), DialogRowRefresh = (1 << 3), CallAdded = (1 << 4), + ReplyMarkup = (1 << 5), - LastUsedBit = (1 << 4), + LastUsedBit = (1 << 5), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; } diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index a95a506662..a73bd093cb 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -289,12 +289,6 @@ bool skipPaintEvent(QWidget *widget, QPaintEvent *event) { namespace Notify { -void replyMarkupUpdated(not_null item) { - if (const auto m = CheckMainWidget(&item->history()->session())) { - m->notify_replyMarkupUpdated(item); - } -} - void inlineKeyboardMoved( not_null item, int oldKeyboardTop, diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index cf456a4cf5..4dd0e4deb6 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -76,7 +76,6 @@ enum ClipStopperType { namespace Notify { -void replyMarkupUpdated(not_null item); void inlineKeyboardMoved( not_null item, int oldKeyboardTop, diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index df0659649b..78f4cc86b7 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -485,7 +485,7 @@ void HistoryItem::setRealId(MsgId newId) { } _history->owner().notifyItemIdChange({ this, oldId }); - // We don't call Notify::replyMarkupUpdated(this) and update keyboard + // We don't fire MessageUpdate::Flag::ReplyMarkup and update keyboard // in history widget, because it can't exist for an outgoing message. // Only inline keyboards can be in outgoing messages. if (const auto markup = inlineReplyMarkup()) { diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index b2b2562766..36d62baca3 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -41,7 +41,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_user.h" #include "data/data_histories.h" -#include "facades.h" // Notify::replyMarkupUpdated #include "app.h" #include "styles/style_dialogs.h" #include "styles/style_widgets.h" @@ -1279,14 +1278,19 @@ void HistoryMessage::checkIsolatedEmoji() { } void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) { + const auto requestUpdate = [&] { + history()->owner().requestItemResize(this); + history()->session().changes().messageUpdated( + this, + Data::MessageUpdate::Flag::ReplyMarkup); + }; if (!markup) { if (_flags & MTPDmessage::Flag::f_reply_markup) { _flags &= ~MTPDmessage::Flag::f_reply_markup; if (Has()) { RemoveComponents(HistoryMessageReplyMarkup::Bit()); } - history()->owner().requestItemResize(this); - Notify::replyMarkupUpdated(this); + requestUpdate(); } return; } @@ -1304,8 +1308,7 @@ void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) { changed = true; } if (changed) { - history()->owner().requestItemResize(this); - Notify::replyMarkupUpdated(this); + requestUpdate(); } } else { if (!(_flags & MTPDmessage::Flag::f_reply_markup)) { @@ -1315,8 +1318,7 @@ void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) { AddComponents(HistoryMessageReplyMarkup::Bit()); } Get()->create(*markup); - history()->owner().requestItemResize(this); - Notify::replyMarkupUpdated(this); + requestUpdate(); } } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 6b5822206f..d54a27e883 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -602,6 +602,14 @@ HistoryWidget::HistoryWidget( itemEdited(update.item); }, lifetime()); + session().changes().messageUpdates( + Data::MessageUpdate::Flag::ReplyMarkup + ) | rpl::start_with_next([=](const Data::MessageUpdate &update) { + if (_keyboard->forMsgId() == update.item->fullId()) { + updateBotKeyboard(update.item->history(), true); + } + }, lifetime()); + subscribe(Media::Player::instance()->switchToNextNotifier(), [this](const Media::Player::Instance::Switch &pair) { if (pair.from.type() == AudioMsgId::Type::Voice) { scrollToCurrentVoiceMessage(pair.from.contextId(), pair.to); @@ -1516,12 +1524,6 @@ void HistoryWidget::onRecordUpdate(quint16 level, qint32 samples) { } } -void HistoryWidget::notify_replyMarkupUpdated(not_null item) { - if (_keyboard->forMsgId() == item->fullId()) { - updateBotKeyboard(item->history(), true); - } -} - void HistoryWidget::notify_inlineKeyboardMoved(not_null item, int oldKeyboardTop, int newKeyboardTop) { if (_history == item->history() || _migrated == item->history()) { if (const auto move = _list->moveScrollFollowingInlineKeyboard(item, oldKeyboardTop, newKeyboardTop)) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index fd299a56a6..5e70426687 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -275,8 +275,6 @@ public: PeerData *ui_getPeerForMouseAction(); - void notify_inlineBotRequesting(bool requesting); - void notify_replyMarkupUpdated(not_null item); void notify_inlineKeyboardMoved(not_null item, int oldKeyboardTop, int newKeyboardTop); bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index dc3303a3f0..f69d55efd2 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -604,10 +604,6 @@ void MainWidget::onFilesOrForwardDrop( } } -void MainWidget::notify_replyMarkupUpdated(not_null item) { - _history->notify_replyMarkupUpdated(item); -} - void MainWidget::notify_inlineKeyboardMoved(not_null item, int oldKeyboardTop, int newKeyboardTop) { _history->notify_inlineKeyboardMoved(item, oldKeyboardTop, newKeyboardTop); } diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 4b0239c24f..d33942f21b 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -230,7 +230,6 @@ public: MsgId msgId); PeerData *ui_getPeerForMouseAction(); - void notify_replyMarkupUpdated(not_null item); void notify_inlineKeyboardMoved(not_null item, int oldKeyboardTop, int newKeyboardTop); bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo);