Skip to content

Commit

Permalink
Allow hiding PSA from the chats list.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Apr 30, 2020
1 parent b6e184d commit 44e71df
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_context_view_group" = "View group info";
"lng_context_view_channel" = "View channel 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_unpin_from_top" = "Unpin from top";
"lng_context_mark_unread" = "Mark as unread";
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/apiwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void ApiWrap::topPromotionDone(const MTPhelp_PromoData &proxy) {
_topPromotionNextRequestTime);

proxy.match([&](const MTPDhelp_promoDataEmpty &data) {
_session->data().setTopPromoted(nullptr, false, QString());
_session->data().setTopPromoted(nullptr, QString(), QString());
}, [&](const MTPDhelp_promoData &data) {
_session->data().processChats(data.vchats());
_session->data().processUsers(data.vusers());
Expand Down
31 changes: 28 additions & 3 deletions Telegram/SourceFiles/window/window_peer_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ class Filler {
void fill();

private:
bool showInfo();
bool showToggleArchived();
bool showTogglePin();
[[nodiscard]] bool showInfo();
[[nodiscard]] bool showHidePromotion();
[[nodiscard]] bool showToggleArchived();
[[nodiscard]] bool showTogglePin();
void addHidePromotion();
void addTogglePin();
void addInfo();
//void addSearch();
Expand Down Expand Up @@ -248,6 +250,16 @@ bool Filler::showInfo() {
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() {
if (_source != PeerMenuSource::ChatsList) {
return false;
Expand All @@ -269,6 +281,16 @@ bool Filler::showTogglePin() {
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() {
const auto filterId = _filterId;
const auto peer = _peer;
Expand Down Expand Up @@ -571,6 +593,9 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
}

void Filler::fill() {
if (showHidePromotion()) {
addHidePromotion();
}
if (showToggleArchived()) {
addToggleArchive();
}
Expand Down

0 comments on commit 44e71df

Please sign in to comment.