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()) {
_history->session().storage().add(Storage::SharedMediaAddNew(
_history->peer->id,
topicRootId(),
types,
id));
if (types.test(Storage::SharedMediaType::Pinned)) {

View File

@ -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<SharedMediaType>(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);
}
}

View File

@ -41,14 +41,17 @@ using SharedMediaTypesMask = base::enum_mask<SharedMediaType>;
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;