diff --git a/Telegram/SourceFiles/data/data_changes.cpp b/Telegram/SourceFiles/data/data_changes.cpp index 16b3fde77..9f28a7af0 100644 --- a/Telegram/SourceFiles/data/data_changes.cpp +++ b/Telegram/SourceFiles/data/data_changes.cpp @@ -76,6 +76,11 @@ rpl::producer Changes::Manager::flagsValue( ) | rpl::then(updates(data, flags)); } +template +void Changes::Manager::drop(not_null data) { + _updates.remove(data); +} + template void Changes::Manager::sendNotifications() { for (const auto &[data, flags] : base::take(_updates)) { @@ -166,8 +171,11 @@ rpl::producer Changes::realtimeHistoryUpdates( void Changes::topicUpdated( not_null topic, TopicUpdate::Flags flags) { - _topicChanges.updated(topic, flags); - scheduleNotifications(); + const auto drop = (flags & TopicUpdate::Flag::Destroyed); + _topicChanges.updated(topic, flags, drop); + if (!drop) { + scheduleNotifications(); + } } rpl::producer Changes::topicUpdates( @@ -192,6 +200,10 @@ rpl::producer Changes::realtimeTopicUpdates( return _topicChanges.realtimeUpdates(flag); } +void Changes::topicRemoved(not_null topic) { + _topicChanges.drop(topic); +} + void Changes::messageUpdated( not_null item, MessageUpdate::Flags flags) { @@ -227,8 +239,11 @@ rpl::producer Changes::realtimeMessageUpdates( void Changes::entryUpdated( not_null entry, EntryUpdate::Flags flags) { - _entryChanges.updated(entry, flags); - scheduleNotifications(); + const auto drop = (flags & EntryUpdate::Flag::Destroyed); + _entryChanges.updated(entry, flags, drop); + if (!drop) { + scheduleNotifications(); + } } rpl::producer Changes::entryUpdates( @@ -253,6 +268,10 @@ rpl::producer Changes::realtimeEntryUpdates( return _entryChanges.realtimeUpdates(flag); } +void Changes::entryRemoved(not_null entry) { + _entryChanges.drop(entry); +} + void Changes::scheduleNotifications() { if (!_notify) { _notify = true; diff --git a/Telegram/SourceFiles/data/data_changes.h b/Telegram/SourceFiles/data/data_changes.h index c4075abc1..e4e2f8209 100644 --- a/Telegram/SourceFiles/data/data_changes.h +++ b/Telegram/SourceFiles/data/data_changes.h @@ -153,8 +153,9 @@ struct TopicUpdate { CloudDraft = (1U << 8), Closed = (1U << 9), Creator = (1U << 10), + Destroyed = (1U << 11), - LastUsedBit = (1U << 10), + LastUsedBit = (1U << 11), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; } @@ -198,8 +199,9 @@ struct EntryUpdate { ForwardDraft = (1U << 2), LocalDraftSet = (1U << 3), Height = (1U << 4), + Destroyed = (1U << 5), - LastUsedBit = (1U << 4), + LastUsedBit = (1U << 5), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; } @@ -261,6 +263,7 @@ public: TopicUpdate::Flags flags) const; [[nodiscard]] rpl::producer realtimeTopicUpdates( TopicUpdate::Flag flag) const; + void topicRemoved(not_null topic); void messageUpdated( not_null item, @@ -289,6 +292,7 @@ public: EntryUpdate::Flags flags) const; [[nodiscard]] rpl::producer realtimeEntryUpdates( EntryUpdate::Flag flag) const; + void entryRemoved(not_null entry); void sendNotifications(); @@ -313,6 +317,8 @@ private: [[nodiscard]] rpl::producer realtimeUpdates( Flag flag) const; + void drop(not_null data); + void sendNotifications(); private: diff --git a/Telegram/SourceFiles/data/data_forum.cpp b/Telegram/SourceFiles/data/data_forum.cpp index 2ae50874e..507f54478 100644 --- a/Telegram/SourceFiles/data/data_forum.cpp +++ b/Telegram/SourceFiles/data/data_forum.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_histories.h" +#include "data/data_changes.h" #include "data/data_session.h" #include "data/data_forum_icons.h" #include "data/data_forum_topic.h" @@ -68,12 +69,16 @@ Forum::~Forum() { if (_requestId) { session().api().request(_requestId).cancel(); } + auto &storage = session().storage(); + auto &changes = session().changes(); const auto peerId = _history->peer->id; for (const auto &[rootId, topic] : _topics) { - session().storage().unload(Storage::SharedMediaUnloadThread( - peerId, - rootId)); + storage.unload(Storage::SharedMediaUnloadThread(peerId, rootId)); _history->setForwardDraft(rootId, {}); + + const auto raw = topic.get(); + changes.topicRemoved(raw); + changes.entryRemoved(raw); } } @@ -181,6 +186,12 @@ void Forum::applyTopicDeleted(MsgId rootId) { } _topicDestroyed.fire(raw); + session().changes().topicUpdated( + raw, + Data::TopicUpdate::Flag::Destroyed); + session().changes().entryUpdated( + raw, + Data::EntryUpdate::Flag::Destroyed); _topics.erase(i); _history->destroyMessagesByTopic(rootId); diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp index e143d1439..f2d5ebcd4 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp @@ -333,7 +333,7 @@ not_null Entry::addToChatList( void Entry::removeFromChatList( FilterId filterId, not_null list) { - if (!asTopic() && isPinnedDialog(filterId)) { + if (isPinnedDialog(filterId)) { owner().setChatPinned(this, filterId, false); } diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index ac2ab7b30..98d946cd5 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -1223,13 +1223,11 @@ void Element::drawRightAction( int outerWidth) const { } -ClickHandlerPtr Element::rightActionLink() const { +ClickHandlerPtr Element::rightActionLink( + std::optional pressPoint) const { return ClickHandlerPtr(); } -void Element::applyRightActionLastPoint(QPoint p) const { -} - TimeId Element::displayedEditDate() const { return TimeId(0); } diff --git a/Telegram/SourceFiles/history/view/history_view_element.h b/Telegram/SourceFiles/history/view/history_view_element.h index 60e612d52..8e9e19a26 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.h +++ b/Telegram/SourceFiles/history/view/history_view_element.h @@ -403,8 +403,8 @@ public: int left, int top, int outerWidth) const; - [[nodiscard]] virtual ClickHandlerPtr rightActionLink() const; - virtual void applyRightActionLastPoint(QPoint p) const; + [[nodiscard]] virtual ClickHandlerPtr rightActionLink( + std::optional pressPoint) const; [[nodiscard]] virtual TimeId displayedEditDate() const; [[nodiscard]] virtual bool hasVisibleText() const; [[nodiscard]] virtual HistoryMessageReply *displayedReply() const; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 35be56ae3..c467ed3c1 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1963,10 +1963,9 @@ TextState Message::textState( size->width(), size->height() ).contains(point)) { - result.link = rightActionLink(); + result.link = rightActionLink(point + - QPoint(fastShareLeft, fastShareTop)); } - applyRightActionLastPoint(point - - QPoint(fastShareLeft, fastShareTop)); } } else if (media && media->isDisplayed()) { result = media->textState(point - g.topLeft(), request); @@ -2715,7 +2714,7 @@ auto Message::verticalRepaintRange() const -> VerticalRepaintRange { void Message::refreshDataIdHook() { if (_rightAction && base::take(_rightAction->link)) { - _rightAction->link = rightActionLink(); + _rightAction->link = rightActionLink(_rightAction->lastPoint); } if (base::take(_fastReplyLink)) { _fastReplyLink = fastReplyLink(); @@ -2989,11 +2988,6 @@ std::optional Message::rightActionSize() const { : std::optional(); } -void Message::applyRightActionLastPoint(QPoint p) const { - ensureRightAction(); - _rightAction->lastPoint = std::move(p); -} - bool Message::displayFastShare() const { const auto item = message(); const auto peer = item->history()->peer; @@ -3100,11 +3094,15 @@ void Message::drawRightAction( } } -ClickHandlerPtr Message::rightActionLink() const { +ClickHandlerPtr Message::rightActionLink( + std::optional pressPoint) const { ensureRightAction(); if (!_rightAction->link) { _rightAction->link = prepareRightActionLink(); } + if (pressPoint) { + _rightAction->lastPoint = *pressPoint; + } return _rightAction->link; } diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index b81bac754..16b76f0d3 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -130,14 +130,14 @@ public: bool displayFastReply() const override; bool displayRightActionComments() const; std::optional rightActionSize() const override; - void applyRightActionLastPoint(QPoint p) const override; void drawRightAction( Painter &p, const PaintContext &context, int left, int top, int outerWidth) const override; - [[nodiscard]] ClickHandlerPtr rightActionLink() const override; + [[nodiscard]] ClickHandlerPtr rightActionLink( + std::optional pressPoint) const override; [[nodiscard]] TimeId displayedEditDate() const override; [[nodiscard]] HistoryMessageReply *displayedReply() const override; [[nodiscard]] bool toggleSelectionByHandlerClick( diff --git a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp index 063c1833e..697573c51 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_extended_preview.cpp @@ -393,8 +393,7 @@ TextState ExtendedPreview::textState(QPoint point, StateRequest request) const { auto fastShareLeft = (fullRight + st::historyFastShareLeft); auto fastShareTop = (fullBottom - st::historyFastShareBottom - size->height()); if (QRect(fastShareLeft, fastShareTop, size->width(), size->height()).contains(point)) { - result.link = _parent->rightActionLink(); - _parent->applyRightActionLastPoint(point + result.link = _parent->rightActionLink(point - QPoint(fastShareLeft, fastShareTop)); } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index e77cf2f79..597e3a1fc 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -1032,8 +1032,7 @@ TextState Gif::textState(QPoint point, StateRequest request) const { + st::msgDateImgPadding.y(); } if (QRect(QPoint(fastShareLeft, fastShareTop), *size).contains(point)) { - result.link = _parent->rightActionLink(); - _parent->applyRightActionLastPoint(point + result.link = _parent->rightActionLink(point - QPoint(fastShareLeft, fastShareTop)); } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_location.cpp b/Telegram/SourceFiles/history/view/media/history_view_location.cpp index 93b1f8e93..ab75f2051 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_location.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_location.cpp @@ -334,8 +334,7 @@ TextState Location::textState(QPoint point, StateRequest request) const { auto fastShareLeft = (fullRight + st::historyFastShareLeft); auto fastShareTop = (fullBottom - st::historyFastShareBottom - size->height()); if (QRect(fastShareLeft, fastShareTop, size->width(), size->height()).contains(point)) { - result.link = _parent->rightActionLink(); - _parent->applyRightActionLastPoint(point + result.link = _parent->rightActionLink(point - QPoint(fastShareLeft, fastShareTop)); } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp index 526809037..09d2df63e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_grouped.cpp @@ -461,8 +461,7 @@ TextState GroupedMedia::textState(QPoint point, StateRequest request) const { auto fastShareLeft = (fullRight + st::historyFastShareLeft); auto fastShareTop = (fullBottom - st::historyFastShareBottom - size->height()); if (QRect(fastShareLeft, fastShareTop, size->width(), size->height()).contains(point)) { - result.link = _parent->rightActionLink(); - _parent->applyRightActionLastPoint(point + result.link = _parent->rightActionLink(point - QPoint(fastShareLeft, fastShareTop)); } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp index c922e4fe7..9dba4f249 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_unwrapped.cpp @@ -485,8 +485,7 @@ TextState UnwrappedMedia::textState(QPoint point, StateRequest request) const { fullRight, *rightActionSize); if (QRect(position.x(), position.y(), rightActionSize->width(), rightActionSize->height()).contains(point)) { - result.link = _parent->rightActionLink(); - _parent->applyRightActionLastPoint(point - position); + result.link = _parent->rightActionLink(point - position); return result; } } diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index 11a1a8e0f..eeb21548b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -563,8 +563,7 @@ TextState Photo::textState(QPoint point, StateRequest request) const { auto fastShareLeft = (fullRight + st::historyFastShareLeft); auto fastShareTop = (fullBottom - st::historyFastShareBottom - size->height()); if (QRect(fastShareLeft, fastShareTop, size->width(), size->height()).contains(point)) { - result.link = _parent->rightActionLink(); - _parent->applyRightActionLastPoint(point + result.link = _parent->rightActionLink(point - QPoint(fastShareLeft, fastShareTop)); } }