Fix pinning between topics.

This commit is contained in:
John Preston 2022-11-07 15:12:47 +04:00
parent 9a54473e03
commit 0737034ea6
3 changed files with 13 additions and 4 deletions

View File

@ -741,6 +741,7 @@ void HistoryItem::indexAsNewItem() {
if (const auto types = sharedMediaTypes()) { if (const auto types = sharedMediaTypes()) {
_history->session().storage().add(Storage::SharedMediaAddNew( _history->session().storage().add(Storage::SharedMediaAddNew(
_history->peer->id, _history->peer->id,
topicRootId(),
types, types,
id)); id));
if (types.test(Storage::SharedMediaType::Pinned)) { if (types.test(Storage::SharedMediaType::Pinned)) {

View File

@ -35,15 +35,20 @@ auto SharedMedia::enforceLists(Key key)
} }
void SharedMedia::add(SharedMediaAddNew &&query) { void SharedMedia::add(SharedMediaAddNew &&query) {
auto peerIt = enforceLists({ query.peerId, MsgId(0) }); const auto addByIt = [&](const auto i) {
while (peerIt != end(_lists) && peerIt->first.peerId == query.peerId) {
for (auto index = 0; index != kSharedMediaTypeCount; ++index) { for (auto index = 0; index != kSharedMediaTypeCount; ++index) {
auto type = static_cast<SharedMediaType>(index); auto type = static_cast<SharedMediaType>(index);
if (query.types.test(type)) { 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);
} }
} }

View File

@ -41,14 +41,17 @@ using SharedMediaTypesMask = base::enum_mask<SharedMediaType>;
struct SharedMediaAddNew { struct SharedMediaAddNew {
SharedMediaAddNew( SharedMediaAddNew(
PeerId peerId, PeerId peerId,
MsgId topicRootId,
SharedMediaTypesMask types, SharedMediaTypesMask types,
MsgId messageId) MsgId messageId)
: peerId(peerId) : peerId(peerId)
, topicRootId(topicRootId)
, messageId(messageId) , messageId(messageId)
, types(types) { , types(types) {
} }
PeerId peerId = 0; PeerId peerId = 0;
MsgId topicRootId = 0;
MsgId messageId = 0; MsgId messageId = 0;
SharedMediaTypesMask types; SharedMediaTypesMask types;