From bb143a26f26882a1c5c2f602ac89344a4381f594 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sun, 29 Sep 2019 20:21:43 +0300 Subject: [PATCH] Ability to restore previously hidden pinned message --- .../SourceFiles/history/history_widget.cpp | 26 +++++++++++++++++++ Telegram/SourceFiles/history/history_widget.h | 2 ++ .../SourceFiles/window/window_peer_menu.cpp | 25 ++++++++++++++++++ .../SourceFiles/window/window_peer_menu.h | 1 + 4 files changed, 54 insertions(+) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 4cf333dab..a6e9cc187 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -5643,6 +5643,32 @@ void HistoryWidget::updatePinnedBar(bool force) { } } +bool HistoryWidget::hasHiddenPinnedMessage(not_null peer) { + auto result = false; + auto pinnedId = peer->pinnedMessageId(); + if (pinnedId) { + auto it = Global::HiddenPinnedMessages().constFind(peer->id); + if (it != Global::HiddenPinnedMessages().cend()) { + result = true; + } + } + return result; +} + +bool HistoryWidget::unhidePinnedMessage(not_null peer) { + auto result = false; + auto pinnedId = peer->pinnedMessageId(); + if (pinnedId) { + auto it = Global::HiddenPinnedMessages().constFind(peer->id); + if (it != Global::HiddenPinnedMessages().cend()) { + Global::RefHiddenPinnedMessages().remove(peer->id); + Local::writeUserSettings(); + result = true; + } + } + return result; +} + bool HistoryWidget::pinnedMsgVisibilityUpdated() { auto result = false; auto pinnedId = _peer->pinnedMessageId(); diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index bd28252e7..3feb7e782 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -137,6 +137,8 @@ public: void sendFileConfirmed(const std::shared_ptr &file, const std::optional &oldId = std::nullopt); + static bool hasHiddenPinnedMessage(not_null peer); + static bool unhidePinnedMessage(not_null peer); void updateControlsVisibility(); void updateControlsGeometry(); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index f43b63c77..9a6a47e2e 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "history/history_message.h" // GetErrorTextForSending. +#include "history/history_widget.h" #include "window/window_session_controller.h" #include "window/window_controller.h" #include "support/support_helper.h" @@ -387,6 +388,11 @@ void Filler::addUserActions(not_null user) { user->session().supportHelper().editInfo(user); }); } + if (user->isSelf() && HistoryWidget::hasHiddenPinnedMessage(user)) { + _addAction( + tr::lng_pinned_message(tr::now), + [=] { PeerMenuUnhidePinnedMessage(user); }); + } if (!user->isContact() && !user->isSelf() && !user->isBot()) { _addAction( tr::lng_info_add_as_contact(tr::now), @@ -439,6 +445,11 @@ void Filler::addChatActions(not_null chat) { controller->showEditPeerBox(chat); }); } + if (HistoryWidget::hasHiddenPinnedMessage(chat)) { + _addAction( + tr::lng_pinned_message(tr::now), + [=] { PeerMenuUnhidePinnedMessage(chat); }); + } if (chat->canAddMembers()) { _addAction( tr::lng_profile_add_participant(tr::now), @@ -485,6 +496,11 @@ void Filler::addChannelActions(not_null channel) { controller->showEditPeerBox(channel); }); } + if (HistoryWidget::hasHiddenPinnedMessage(channel)) { + _addAction( + tr::lng_pinned_message(tr::now), + [=] { PeerMenuUnhidePinnedMessage(channel); }); + } if (channel->canAddMembers()) { _addAction( tr::lng_channel_add_members(tr::now), @@ -637,6 +653,15 @@ void FolderFiller::addTogglesForArchive() { } // namespace +void PeerMenuUnhidePinnedMessage(not_null peer) { + auto unhidden = HistoryWidget::unhidePinnedMessage(peer); + if (unhidden) { + Notify::peerUpdatedDelayed( + peer, + Notify::PeerUpdate::Flag::PinnedMessageChanged); + } +} + void PeerMenuExportChat(not_null peer) { peer->owner().startExport(peer); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index b376a4499..8f671a556 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -48,6 +48,7 @@ void PeerMenuAddMuteAction( not_null peer, const PeerMenuCallback &addAction); +void PeerMenuUnhidePinnedMessage(not_null peer); void PeerMenuExportChat(not_null peer); void PeerMenuDeleteContact(not_null user); void PeerMenuShareContactBox(