From 1953cc2f8a356663b43766e0855bc8cfd979bb34 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 3 Nov 2022 14:13:36 +0400 Subject: [PATCH] Fix "Topic Author" badge for the new topics. --- Telegram/SourceFiles/data/data_changes.h | 3 ++- Telegram/SourceFiles/data/data_forum.cpp | 9 ++++--- .../SourceFiles/data/data_forum_topic.cpp | 9 ++++++- Telegram/SourceFiles/data/data_forum_topic.h | 1 + .../SourceFiles/data/data_replies_list.cpp | 27 +++++++++++++++++++ Telegram/SourceFiles/data/data_replies_list.h | 3 +++ Telegram/SourceFiles/data/data_session.cpp | 6 +++++ .../view/history_view_replies_section.cpp | 4 +++ 8 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/data/data_changes.h b/Telegram/SourceFiles/data/data_changes.h index eae1003c61..9ff9333ae5 100644 --- a/Telegram/SourceFiles/data/data_changes.h +++ b/Telegram/SourceFiles/data/data_changes.h @@ -152,8 +152,9 @@ struct TopicUpdate { ColorId = (1U << 7), CloudDraft = (1U << 8), Closed = (1U << 9), + Creator = (1U << 10), - LastUsedBit = (1U << 9), + LastUsedBit = (1U << 10), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; } diff --git a/Telegram/SourceFiles/data/data_forum.cpp b/Telegram/SourceFiles/data/data_forum.cpp index bcf5988871..53183dd267 100644 --- a/Telegram/SourceFiles/data/data_forum.cpp +++ b/Telegram/SourceFiles/data/data_forum.cpp @@ -333,6 +333,7 @@ ForumTopic *Forum::applyTopicAdded( raw->applyColorId(colorId); raw->applyIconId(iconId); if (!creating(rootId)) { + requestTopic(rootId); raw->addToChatList(FilterId(), topicsList()); _chatsListChanges.fire({}); } @@ -345,7 +346,9 @@ MsgId Forum::reserveCreatingId( DocumentId iconId) { const auto result = owner().nextLocalMessageId(); _creatingRootIds.emplace(result); - applyTopicAdded(result, title, colorId, iconId); + const auto topic = applyTopicAdded(result, title, colorId, iconId); + // Perhaps it will be created from some public channel name. + //topic->applyCreator(session().userPeerId()); return result; } @@ -416,9 +419,7 @@ ForumTopic *Forum::enforceTopicFor(MsgId rootId) { if (i != end(_topics)) { return i->second.get(); } - const auto result = applyTopicAdded(rootId, {}, {}, {}); - requestTopic(rootId); - return result; + return applyTopicAdded(rootId, {}, {}, {}); } bool Forum::topicDeleted(MsgId rootId) const { diff --git a/Telegram/SourceFiles/data/data_forum_topic.cpp b/Telegram/SourceFiles/data/data_forum_topic.cpp index c8a10c98d7..1b6ca44874 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.cpp +++ b/Telegram/SourceFiles/data/data_forum_topic.cpp @@ -285,7 +285,7 @@ void ForumTopic::readTillEnd() { void ForumTopic::applyTopic(const MTPDforumTopic &data) { Expects(_rootId == data.vid().v); - _creatorId = peerFromMTP(data.vfrom_id()); + applyCreator(peerFromMTP(data.vfrom_id())); _creationDate = data.vdate().v; applyTitle(qs(data.vtitle())); @@ -328,6 +328,13 @@ void ForumTopic::applyTopic(const MTPDforumTopic &data) { unreadReactions().setCount(data.vunread_reactions_count().v); } +void ForumTopic::applyCreator(PeerId creatorId) { + if (_creatorId != creatorId) { + _creatorId = creatorId; + session().changes().topicUpdated(this, UpdateFlag::Creator); + } +} + bool ForumTopic::closed() const { return _flags & Flag::Closed; } diff --git a/Telegram/SourceFiles/data/data_forum_topic.h b/Telegram/SourceFiles/data/data_forum_topic.h index 4be29cdc55..8d55661ee5 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.h +++ b/Telegram/SourceFiles/data/data_forum_topic.h @@ -116,6 +116,7 @@ public: void applyIconId(DocumentId iconId); [[nodiscard]] int32 colorId() const; void applyColorId(int32 colorId); + void applyCreator(PeerId creatorId); void applyItemAdded(not_null item); void applyItemRemoved(MsgId id); void maybeSetLastMessage(not_null item); diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index d9a242155a..28d489e68b 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -109,6 +109,12 @@ void RepliesList::subscribeToUpdates() { apply(update); }, _lifetime); + _history->session().changes().topicUpdates( + TopicUpdate::Flag::Creator + ) | rpl::start_with_next([=](const TopicUpdate &update) { + apply(update); + }, _lifetime); + _history->owner().channelDifferenceTooLong( ) | rpl::start_with_next([=](not_null channel) { if (channel == _history->peer) { @@ -133,6 +139,27 @@ void RepliesList::apply(const MessageUpdate &update) { } } +void RepliesList::apply(const TopicUpdate &update) { + if (update.topic->history() == _history + && update.topic->rootId() == _rootId) { + if (update.flags & TopicUpdate::Flag::Creator) { + applyTopicCreator(update.topic->creatorId()); + } + } +} + +void RepliesList::applyTopicCreator(PeerId creatorId) { + const auto owner = &_history->owner(); + const auto peerId = _history->peer->id; + for (const auto &id : _list) { + if (const auto item = owner->message(peerId, id)) { + if (item->from()->id == creatorId) { + owner->requestItemResize(item); + } + } + } +} + rpl::producer RepliesList::source( MessagePosition aroundId, int limitBefore, diff --git a/Telegram/SourceFiles/data/data_replies_list.h b/Telegram/SourceFiles/data/data_replies_list.h index 7d982a4b6b..6b4107c8cc 100644 --- a/Telegram/SourceFiles/data/data_replies_list.h +++ b/Telegram/SourceFiles/data/data_replies_list.h @@ -20,6 +20,7 @@ class Histories; struct MessagePosition; struct MessagesSlice; struct MessageUpdate; +struct TopicUpdate; struct RepliesReadTillUpdate; class RepliesList final : public base::has_weak_ptr { @@ -32,6 +33,7 @@ public: void apply(const RepliesReadTillUpdate &update); void apply(const MessageUpdate &update); + void apply(const TopicUpdate &update); void applyDifferenceTooLong(); [[nodiscard]] rpl::producer source( @@ -87,6 +89,7 @@ private: not_null viewer, not_null item); [[nodiscard]] bool applyUpdate(const MessageUpdate &update); + void applyTopicCreator(PeerId creatorId); void injectRootMessageAndReverse(not_null viewer); void injectRootMessage(not_null viewer); void injectRootDivider( diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 150c7cef02..440faa9d66 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -331,6 +331,12 @@ void Session::subscribeForTopicRepliesLists() { } }, _lifetime); + session().changes().topicUpdates( + TopicUpdate::Flag::Creator + ) | rpl::start_with_next([=](const TopicUpdate &update) { + update.topic->replies()->apply(update); + }, _lifetime); + channelDifferenceTooLong( ) | rpl::start_with_next([=](not_null channel) { if (const auto forum = channel->forum()) { diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 91cfe522f9..2a78f8d17c 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -537,6 +537,10 @@ void RepliesWidget::subscribeToTopic() { if (!_topic->creating()) { subscribeToPinnedMessages(); + + if (!_topic->creatorId()) { + _topic->forum()->requestTopic(_topic->rootId()); + } } _cornerButtons.updateUnreadThingsVisibility();