diff --git a/Telegram/Resources/tl/api.tl b/Telegram/Resources/tl/api.tl index 31df0a50d..742f02e12 100644 --- a/Telegram/Resources/tl/api.tl +++ b/Telegram/Resources/tl/api.tl @@ -1734,7 +1734,7 @@ messages.getOldFeaturedStickers#7ed094a1 offset:int limit:int hash:long = messag messages.getReplies#22ddd30c peer:InputPeer msg_id:int offset_id:int offset_date:int add_offset:int limit:int max_id:int min_id:int hash:long = messages.Messages; messages.getDiscussionMessage#446972fd peer:InputPeer msg_id:int = messages.DiscussionMessage; messages.readDiscussion#f731a9f4 peer:InputPeer msg_id:int read_max_id:int = Bool; -messages.unpinAllMessages#f025bc8b peer:InputPeer = messages.AffectedHistory; +messages.unpinAllMessages#ee22b9a8 flags:# peer:InputPeer top_msg_id:flags.0?int = messages.AffectedHistory; messages.deleteChat#5bd0ee50 chat_id:long = Bool; messages.deletePhoneCallHistory#f9cbe409 flags:# revoke:flags.0?true = messages.AffectedFoundMessages; messages.checkHistoryImport#43fe19f3 import_head:string = messages.HistoryImportParsed; diff --git a/Telegram/SourceFiles/data/data_shared_media.cpp b/Telegram/SourceFiles/data/data_shared_media.cpp index 4d32427e8..e2a69482e 100644 --- a/Telegram/SourceFiles/data/data_shared_media.cpp +++ b/Telegram/SourceFiles/data/data_shared_media.cpp @@ -149,6 +149,8 @@ rpl::producer SharedMediaViewer( session->storage().sharedMediaAllRemoved( ) | rpl::filter([=](const AllRemoved &update) { return (update.peerId == key.peerId) + && (!update.topicRootId + || update.topicRootId == key.topicRootId) && update.types.test(key.type); }) | rpl::filter([=] { return builder->removeAll(); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 16b18f87a..51f4c6def 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -550,13 +550,25 @@ void History::unpinMessagesFor(MsgId topicRootId) { topic->setHasPinnedMessages(false); }); } - for (const auto &message : _messages) { - if (message->isPinned()) { - message->setIsPinned(false); + for (const auto &item : _messages) { + if (item->isPinned()) { + item->setIsPinned(false); } } } else { - // #TODO forum pinned + session().storage().remove( + Storage::SharedMediaRemoveAll( + peer->id, + topicRootId, + Storage::SharedMediaType::Pinned)); + if (const auto topic = peer->forumTopicFor(topicRootId)) { + topic->setHasPinnedMessages(false); + } + for (const auto &item : _messages) { + if (item->isPinned() && item->topicRootId() == topicRootId) { + item->setIsPinned(false); + } + } } } diff --git a/Telegram/SourceFiles/storage/storage_shared_media.cpp b/Telegram/SourceFiles/storage/storage_shared_media.cpp index a27d0cba2..816cbd61e 100644 --- a/Telegram/SourceFiles/storage/storage_shared_media.cpp +++ b/Telegram/SourceFiles/storage/storage_shared_media.cpp @@ -85,8 +85,11 @@ void SharedMedia::remove(SharedMediaRemoveOne &&query) { } void SharedMedia::remove(SharedMediaRemoveAll &&query) { - auto peerIt = _lists.lower_bound({ query.peerId, MsgId(0) }); - while (peerIt != end(_lists) && peerIt->first.peerId == query.peerId) { + auto peerIt = _lists.lower_bound({ query.peerId, query.topicRootId }); + while (peerIt != end(_lists) + && peerIt->first.peerId == query.peerId + && (!query.topicRootId + || peerIt->first.topicRootId == query.topicRootId)) { for (auto index = 0; index != kSharedMediaTypeCount; ++index) { auto type = static_cast(index); if (query.types.test(type)) { diff --git a/Telegram/SourceFiles/storage/storage_shared_media.h b/Telegram/SourceFiles/storage/storage_shared_media.h index cf285a6df..6489714b3 100644 --- a/Telegram/SourceFiles/storage/storage_shared_media.h +++ b/Telegram/SourceFiles/storage/storage_shared_media.h @@ -124,8 +124,17 @@ struct SharedMediaRemoveAll { : peerId(peerId) , types(types) { } + SharedMediaRemoveAll( + PeerId peerId, + MsgId topicRootId, + SharedMediaTypesMask types = SharedMediaTypesMask::All()) + : peerId(peerId) + , topicRootId(topicRootId) + , types(types) { + } PeerId peerId = 0; + MsgId topicRootId = 0; SharedMediaTypesMask types; }; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index b92700c45..6cce6d8c5 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1757,15 +1757,18 @@ void UnpinAllMessages( const auto callback = crl::guard(navigation, [=](Fn &&close) { close(); const auto strong = weak.get(); - if (!strong || !strong->asHistory()) { // #TODO forum pinned + if (!strong) { return; } const auto api = &strong->session().api(); const auto sendRequest = [=](auto self) -> void { const auto history = strong->owningHistory(); const auto topicRootId = strong->topicRootId(); + using Flag = MTPmessages_UnpinAllMessages::Flag; api->request(MTPmessages_UnpinAllMessages( - history->peer->input + MTP_flags(topicRootId ? Flag::f_top_msg_id : Flag()), + history->peer->input, + MTP_int(topicRootId.bare) )).done([=](const MTPmessages_AffectedHistory &result) { const auto peer = history->peer; const auto offset = api->applyAffectedHistory(peer, result);