diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 4389c3c30..66f754cb8 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -763,7 +763,13 @@ PeerId ChannelData::groupCallDefaultJoinAs() const { void ChannelData::setAllowedReactions(std::vector list) { if (_allowedReactions != list) { + const auto toggled = (_allowedReactions.empty() != list.empty()); _allowedReactions = std::move(list); + if (toggled) { + owner().reactions().updateAllInHistory( + this, + !_allowedReactions.empty()); + } session().changes().peerUpdated(this, UpdateFlag::Reactions); } } diff --git a/Telegram/SourceFiles/data/data_chat.cpp b/Telegram/SourceFiles/data/data_chat.cpp index 022faaee7..16acd3694 100644 --- a/Telegram/SourceFiles/data/data_chat.cpp +++ b/Telegram/SourceFiles/data/data_chat.cpp @@ -289,7 +289,13 @@ void ChatData::setPendingRequestsCount( void ChatData::setAllowedReactions(std::vector list) { if (_allowedReactions != list) { + const auto toggled = (_allowedReactions.empty() != list.empty()); _allowedReactions = std::move(list); + if (toggled) { + owner().reactions().updateAllInHistory( + this, + !_allowedReactions.empty()); + } session().changes().peerUpdated(this, UpdateFlag::Reactions); } } diff --git a/Telegram/SourceFiles/data/data_message_reactions.cpp b/Telegram/SourceFiles/data/data_message_reactions.cpp index 18c534043..559f8d89d 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.cpp +++ b/Telegram/SourceFiles/data/data_message_reactions.cpp @@ -317,6 +317,12 @@ void Reactions::poll(not_null item, crl::time now) { } } +void Reactions::updateAllInHistory(not_null peer, bool enabled) { + if (const auto history = _owner->historyLoaded(peer)) { + history->reactionsEnabledChanged(enabled); + } +} + void Reactions::repaintCollected() { const auto now = crl::now(); auto closest = 0; @@ -407,7 +413,6 @@ void MessageReactions::remove() { void MessageReactions::set( const QVector &list, bool ignoreChosen) { - _lastRefreshTime = crl::now(); if (_item->history()->owner().reactions().sending(_item)) { // We'll apply non-stale data from the request response. return; @@ -458,10 +463,6 @@ bool MessageReactions::empty() const { return _list.empty(); } -crl::time MessageReactions::lastRefreshTime() const { - return _lastRefreshTime; -} - QString MessageReactions::chosen() const { return _chosen; } diff --git a/Telegram/SourceFiles/data/data_message_reactions.h b/Telegram/SourceFiles/data/data_message_reactions.h index 22eff5545..d6e7c1844 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.h +++ b/Telegram/SourceFiles/data/data_message_reactions.h @@ -63,6 +63,8 @@ public: void poll(not_null item, crl::time now); + void updateAllInHistory(not_null peer, bool enabled); + private: struct ImageSet { QImage bottomInfo; @@ -118,14 +120,12 @@ public: [[nodiscard]] const base::flat_map &list() const; [[nodiscard]] QString chosen() const; [[nodiscard]] bool empty() const; - [[nodiscard]] crl::time lastRefreshTime() const; private: const not_null _item; QString _chosen; base::flat_map _list; - crl::time _lastRefreshTime = 0; }; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index b3777dee5..b5aad44fe 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -273,7 +273,6 @@ Session::Session(not_null session) session->saveSettingsDelayed(); } }, _lifetime); - } void Session::clear() { diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 6c9dae37b..b951587ee 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2965,6 +2965,16 @@ void History::removeJoinedMessage() { } } +void History::reactionsEnabledChanged(bool enabled) { + if (!enabled) { + for (const auto &item : _messages) { + item->updateReactions(nullptr); + } + } else { + + } +} + bool History::isEmpty() const { return blocks.empty(); } diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index a5580159b..a3f4178c7 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -89,6 +89,8 @@ public: void checkLocalMessages(); void removeJoinedMessage(); + void reactionsEnabledChanged(bool enabled); + bool isEmpty() const; bool isDisplayedEmpty() const; Element *findFirstNonEmpty() const; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 4f8214c34..de34b82cf 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -381,6 +381,27 @@ void HistoryItem::setIsPinned(bool pinned) { } } +void HistoryItem::returnSavedMedia() { +} + +void HistoryItem::savePreviousMedia() { + Expects(_media != nullptr); + + using Data = SavedMediaData; + _savedLocalEditMediaData = std::make_unique(Data{ + .text = originalText(), + .media = _media->clone(this), + }); +} + +bool HistoryItem::isEditingMedia() const { + return _savedLocalEditMediaData != nullptr; +} + +void HistoryItem::clearSavedMedia() { + _savedLocalEditMediaData = nullptr; +} + bool HistoryItem::definesReplyKeyboard() const { if (const auto markup = Get()) { if (markup->data.flags & ReplyMarkupFlag::Inline) { @@ -774,6 +795,9 @@ void HistoryItem::toggleReaction(const QString &reaction) { } void HistoryItem::updateReactions(const MTPMessageReactions *reactions) { + if (reactions || _reactionsLastRefreshed) { + _reactionsLastRefreshed = crl::now(); + } if (!reactions) { _flags &= ~MessageFlag::CanViewReactions; if (_reactions) { @@ -801,6 +825,10 @@ void HistoryItem::updateReactions(const MTPMessageReactions *reactions) { }); } +void HistoryItem::updateReactionsUnknown() { + _reactionsLastRefreshed = 1; +} + const base::flat_map &HistoryItem::reactions() const { static const auto kEmpty = base::flat_map(); return _reactions ? _reactions->list() : kEmpty; @@ -817,7 +845,7 @@ QString HistoryItem::chosenReaction() const { } crl::time HistoryItem::lastReactionsRefreshTime() const { - return _reactions ? _reactions->lastRefreshTime() : 0; + return _reactionsLastRefreshed; } bool HistoryItem::hasDirectLink() const { diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index c7ece4b95..a6a4f2c30 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -146,19 +146,10 @@ public: void setIsPinned(bool isPinned); // For edit media in history_message. - virtual void returnSavedMedia() {}; - void savePreviousMedia() { - _savedLocalEditMediaData = { - originalText(), - _media->clone(this), - }; - } - [[nodiscard]] bool isEditingMedia() const { - return _savedLocalEditMediaData.media != nullptr; - } - void clearSavedMedia() { - _savedLocalEditMediaData = {}; - } + virtual void returnSavedMedia(); + void savePreviousMedia(); + [[nodiscard]] bool isEditingMedia() const; + void clearSavedMedia(); // Zero result means this message is not self-destructing right now. virtual crl::time getSelfDestructIn(crl::time now) { @@ -364,6 +355,7 @@ public: void addReaction(const QString &reaction); void toggleReaction(const QString &reaction); void updateReactions(const MTPMessageReactions *reactions); + void updateReactionsUnknown(); [[nodiscard]] const base::flat_map &reactions() const; [[nodiscard]] bool canViewReactions() const; [[nodiscard]] QString chosenReaction() const; @@ -467,9 +459,10 @@ protected: std::unique_ptr media; }; - SavedMediaData _savedLocalEditMediaData; + std::unique_ptr _savedLocalEditMediaData; std::unique_ptr _media; std::unique_ptr _reactions; + crl::time _reactionsLastRefreshed = 0; private: diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 41ea47a61..7840194be 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1222,8 +1222,8 @@ void HistoryMessage::returnSavedMedia() { return; } const auto wasGrouped = history()->owner().groups().isGrouped(this); - _media = std::move(_savedLocalEditMediaData.media); - setText(_savedLocalEditMediaData.text); + _media = std::move(_savedLocalEditMediaData->media); + setText(_savedLocalEditMediaData->text); clearSavedMedia(); if (wasGrouped) { history()->owner().groups().refreshMessage(this, true);