diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index a2751a6e28..542ebbaedd 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -741,6 +741,7 @@ void HistoryItem::indexAsNewItem() { if (const auto types = sharedMediaTypes()) { _history->session().storage().add(Storage::SharedMediaAddNew( _history->peer->id, + topicRootId(), types, id)); if (types.test(Storage::SharedMediaType::Pinned)) { diff --git a/Telegram/SourceFiles/storage/storage_shared_media.cpp b/Telegram/SourceFiles/storage/storage_shared_media.cpp index 816cbd61e6..0326ad3566 100644 --- a/Telegram/SourceFiles/storage/storage_shared_media.cpp +++ b/Telegram/SourceFiles/storage/storage_shared_media.cpp @@ -35,15 +35,20 @@ auto SharedMedia::enforceLists(Key key) } void SharedMedia::add(SharedMediaAddNew &&query) { - auto peerIt = enforceLists({ query.peerId, MsgId(0) }); - while (peerIt != end(_lists) && peerIt->first.peerId == query.peerId) { + const auto addByIt = [&](const auto i) { for (auto index = 0; index != kSharedMediaTypeCount; ++index) { auto type = static_cast(index); if (query.types.test(type)) { - peerIt->second[index].addNew(query.messageId); + i->second[index].addNew(query.messageId); } } - ++peerIt; + }; + addByIt(enforceLists({ query.peerId, MsgId(0) })); + const auto topicIt = query.topicRootId + ? _lists.find({ query.peerId, query.topicRootId }) + : end(_lists); + if (topicIt != end(_lists)) { + addByIt(topicIt); } } diff --git a/Telegram/SourceFiles/storage/storage_shared_media.h b/Telegram/SourceFiles/storage/storage_shared_media.h index 6489714b3c..697bd284c3 100644 --- a/Telegram/SourceFiles/storage/storage_shared_media.h +++ b/Telegram/SourceFiles/storage/storage_shared_media.h @@ -41,14 +41,17 @@ using SharedMediaTypesMask = base::enum_mask; struct SharedMediaAddNew { SharedMediaAddNew( PeerId peerId, + MsgId topicRootId, SharedMediaTypesMask types, MsgId messageId) : peerId(peerId) + , topicRootId(topicRootId) , messageId(messageId) , types(types) { } PeerId peerId = 0; + MsgId topicRootId = 0; MsgId messageId = 0; SharedMediaTypesMask types;