Allow hiding PSA from the chats list.

This commit is contained in:
John Preston 2020-04-29 14:42:24 +04:00
parent b6e184d0c8
commit 44e71dfa03
3 changed files with 30 additions and 4 deletions

View File

@ -1404,6 +1404,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_context_view_group" = "View group info"; "lng_context_view_group" = "View group info";
"lng_context_view_channel" = "View channel info"; "lng_context_view_channel" = "View channel info";
//"lng_context_view_feed_info" = "View feed info"; //"lng_context_view_feed_info" = "View feed info";
"lng_context_hide_psa" = "Hide this announcement";
"lng_context_pin_to_top" = "Pin to top"; "lng_context_pin_to_top" = "Pin to top";
"lng_context_unpin_from_top" = "Unpin from top"; "lng_context_unpin_from_top" = "Unpin from top";
"lng_context_mark_unread" = "Mark as unread"; "lng_context_mark_unread" = "Mark as unread";

View File

@ -342,7 +342,7 @@ void ApiWrap::topPromotionDone(const MTPhelp_PromoData &proxy) {
_topPromotionNextRequestTime); _topPromotionNextRequestTime);
proxy.match([&](const MTPDhelp_promoDataEmpty &data) { proxy.match([&](const MTPDhelp_promoDataEmpty &data) {
_session->data().setTopPromoted(nullptr, false, QString()); _session->data().setTopPromoted(nullptr, QString(), QString());
}, [&](const MTPDhelp_promoData &data) { }, [&](const MTPDhelp_promoData &data) {
_session->data().processChats(data.vchats()); _session->data().processChats(data.vchats());
_session->data().processUsers(data.vusers()); _session->data().processUsers(data.vusers());

View File

@ -72,9 +72,11 @@ public:
void fill(); void fill();
private: private:
bool showInfo(); [[nodiscard]] bool showInfo();
bool showToggleArchived(); [[nodiscard]] bool showHidePromotion();
bool showTogglePin(); [[nodiscard]] bool showToggleArchived();
[[nodiscard]] bool showTogglePin();
void addHidePromotion();
void addTogglePin(); void addTogglePin();
void addInfo(); void addInfo();
//void addSearch(); //void addSearch();
@ -248,6 +250,16 @@ bool Filler::showInfo() {
return false; return false;
} }
bool Filler::showHidePromotion() {
if (_source != PeerMenuSource::ChatsList) {
return false;
}
const auto history = _peer->owner().historyLoaded(_peer);
return history
&& history->useTopPromotion()
&& !history->topPromotionType().isEmpty();
}
bool Filler::showToggleArchived() { bool Filler::showToggleArchived() {
if (_source != PeerMenuSource::ChatsList) { if (_source != PeerMenuSource::ChatsList) {
return false; return false;
@ -269,6 +281,16 @@ bool Filler::showTogglePin() {
return history && !history->fixedOnTopIndex(); return history && !history->fixedOnTopIndex();
} }
void Filler::addHidePromotion() {
const auto history = _peer->owner().history(_peer);
_addAction(tr::lng_context_hide_psa(tr::now), [=] {
history->cacheTopPromotion(false, QString(), QString());
history->session().api().request(MTPhelp_HidePromoData(
history->peer->input
)).send();
});
}
void Filler::addTogglePin() { void Filler::addTogglePin() {
const auto filterId = _filterId; const auto filterId = _filterId;
const auto peer = _peer; const auto peer = _peer;
@ -571,6 +593,9 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
} }
void Filler::fill() { void Filler::fill() {
if (showHidePromotion()) {
addHidePromotion();
}
if (showToggleArchived()) { if (showToggleArchived()) {
addToggleArchive(); addToggleArchive();
} }