Ability to restore previously hidden pinned message

This commit is contained in:
Eric Kotato 2019-09-29 20:21:43 +03:00
parent e4fbc383af
commit bb143a26f2
4 changed files with 54 additions and 0 deletions

View file

@ -5643,6 +5643,32 @@ void HistoryWidget::updatePinnedBar(bool force) {
}
}
bool HistoryWidget::hasHiddenPinnedMessage(not_null<PeerData*> 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<PeerData*> 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();

View file

@ -137,6 +137,8 @@ public:
void sendFileConfirmed(const std::shared_ptr<FileLoadResult> &file,
const std::optional<FullMsgId> &oldId = std::nullopt);
static bool hasHiddenPinnedMessage(not_null<PeerData*> peer);
static bool unhidePinnedMessage(not_null<PeerData*> peer);
void updateControlsVisibility();
void updateControlsGeometry();

View file

@ -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<UserData*> 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<ChatData*> 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<ChannelData*> 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<PeerData*> peer) {
auto unhidden = HistoryWidget::unhidePinnedMessage(peer);
if (unhidden) {
Notify::peerUpdatedDelayed(
peer,
Notify::PeerUpdate::Flag::PinnedMessageChanged);
}
}
void PeerMenuExportChat(not_null<PeerData*> peer) {
peer->owner().startExport(peer);
}

View file

@ -48,6 +48,7 @@ void PeerMenuAddMuteAction(
not_null<PeerData*> peer,
const PeerMenuCallback &addAction);
void PeerMenuUnhidePinnedMessage(not_null<PeerData*> peer);
void PeerMenuExportChat(not_null<PeerData*> peer);
void PeerMenuDeleteContact(not_null<UserData*> user);
void PeerMenuShareContactBox(