diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index c04a26d47..c23740922 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -442,6 +442,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_proxy_credentials_optional" = "Credentials (optional)"; "lng_proxy_credentials" = "Credentials"; "lng_proxy_description" = "Your saved proxy list will be here."; +"lng_proxy_sponsor" = "Proxy sponsor"; +"lng_proxy_sponsor_about" = "This channel is shown by your proxy server.\nTo remove this channel from your chats list,\ndisable the proxy in Telegram Settings."; "lng_settings_blocked_users" = "Blocked users"; "lng_settings_last_seen_privacy" = "Last seen privacy"; diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index a2e881565..6c580cb5b 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -288,6 +288,8 @@ AuthSession::AuthSession(UserId userId) subscribe(Global::RefConnectionTypeChanged(), [=] { _api->refreshProxyPromotion(); }); + _api->refreshProxyPromotion(); + Window::Theme::Background()->start(); } diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index ff11e6d8b..8486fcde7 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1601,13 +1601,21 @@ void Session::setProxyPromoted(PeerData *promoted) { if (const auto history = App::historyLoaded(_proxyPromoted)) { history->cacheProxyPromoted(false); } - _proxyPromoted = promoted; + const auto old = std::exchange(_proxyPromoted, promoted); if (_proxyPromoted) { const auto history = App::history(_proxyPromoted); history->cacheProxyPromoted(true); if (!history->lastMessageKnown()) { _session->api().requestDialogEntry(history); } + Notify::peerUpdatedDelayed( + _proxyPromoted, + Notify::PeerUpdate::Flag::ChannelPromotedChanged); + } + if (old) { + Notify::peerUpdatedDelayed( + old, + Notify::PeerUpdate::Flag::ChannelPromotedChanged); } } } diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp index 5d4a774e9..f417175a9 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp @@ -58,6 +58,9 @@ void Entry::cacheProxyPromoted(bool promoted) { _isProxyPromoted = promoted; updateChatListSortPosition(); updateChatListEntry(); + if (!_isProxyPromoted) { + updateChatListExistence(); + } } } diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index b86bde560..1d1bd883b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -138,7 +138,7 @@ void paintRow( const auto promoted = chat.entry()->useProxyPromotion(); if (promoted) { - const auto text = QString("Proxy sponsor"); + const auto text = lang(lng_proxy_sponsor); paintRowTopRight(p, text, rectForName, active, selected); } else if (from && !(flags & Flag::FeedSearchResult)) { if (const auto chatTypeIcon = ChatTypeIcon(from, active, selected)) { diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style index 27703ad24..e98609e1a 100644 --- a/Telegram/SourceFiles/history/history.style +++ b/Telegram/SourceFiles/history/history.style @@ -456,3 +456,9 @@ historyGroupWidthMin: minPhotoSize; historyGroupSkip: 4px; historyGroupRadialSize: 44px; historyGroupRadialLine: 3px; + +historyAboutProxy: FlatLabel(defaultFlatLabel) { + align: align(top); + textFg: windowSubTextFg; +} +historyAboutProxyPadding: margins(20px, 10px, 20px, 10px); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 8de17d589..e7bb87c85 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -617,7 +617,8 @@ HistoryWidget::HistoryWidget( | UpdateFlag::MembersChanged | UpdateFlag::UserOnlineChanged | UpdateFlag::NotificationsEnabled - | UpdateFlag::ChannelAmIn; + | UpdateFlag::ChannelAmIn + | UpdateFlag::ChannelPromotedChanged; subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) { if (update.peer == _peer) { if (update.flags & UpdateFlag::ChannelRightsChanged) { @@ -652,6 +653,13 @@ HistoryWidget::HistoryWidget( this->update(); } } + if (update.flags & UpdateFlag::ChannelPromotedChanged) { + refreshAboutProxyPromotion(); + updateHistoryGeometry(); + updateControlsVisibility(); + updateControlsGeometry(); + this->update(); + } if (update.flags & (UpdateFlag::UserIsBlocked | UpdateFlag::AdminsChanged | UpdateFlag::MembersChanged @@ -2085,6 +2093,7 @@ void HistoryWidget::updateControlsVisibility() { if (_reportSpamPanel) { _reportSpamPanel->show(); } + refreshAboutProxyPromotion(); if (!editingMessage() && (isBlocked() || isJoinChannel() || isMuteUnmute() || isBotStart())) { if (isBlocked()) { _joinChannel->hide(); @@ -2246,6 +2255,24 @@ void HistoryWidget::updateControlsVisibility() { updateMouseTracking(); } +void HistoryWidget::refreshAboutProxyPromotion() { + if (_history->useProxyPromotion()) { + if (!_aboutProxyPromotion) { + _aboutProxyPromotion = object_ptr>( + this, + object_ptr( + this, + lang(lng_proxy_sponsor_about), + Ui::FlatLabel::InitType::Simple, + st::historyAboutProxy), + st::historyAboutProxyPadding); + } + _aboutProxyPromotion->show(); + } else { + _aboutProxyPromotion.destroy(); + } +} + void HistoryWidget::updateMouseTracking() { bool trackMouse = !_fieldBarCancel->isHidden() || _pinnedBar; setMouseTracking(trackMouse); @@ -3911,6 +3938,12 @@ void HistoryWidget::moveFieldControls() { _unblock->setGeometry(fullWidthButtonRect); _joinChannel->setGeometry(fullWidthButtonRect); _muteUnmute->setGeometry(fullWidthButtonRect); + + if (_aboutProxyPromotion) { + _aboutProxyPromotion->moveToLeft( + 0, + fullWidthButtonRect.y() - _aboutProxyPromotion->height()); + } } void HistoryWidget::updateTabbedSelectorToggleTooltipGeometry() { @@ -4729,6 +4762,10 @@ void HistoryWidget::updateHistoryGeometry(bool initial, bool loadedDown, const S auto newScrollHeight = height() - _topBar->height(); if (!editingMessage() && (isBlocked() || isBotStart() || isJoinChannel() || isMuteUnmute())) { newScrollHeight -= _unblock->height(); + if (_aboutProxyPromotion) { + _aboutProxyPromotion->resizeToWidth(width()); + newScrollHeight -= _aboutProxyPromotion->height(); + } } else { if (editingMessage() || _canSendMessages) { newScrollHeight -= (_field->height() + 2 * st::historySendPadding); @@ -6663,6 +6700,9 @@ void HistoryWidget::paintEvent(QPaintEvent *e) { } else if (isRestrictedWrite()) { drawRestrictedWrite(p); } + if (_aboutProxyPromotion) { + p.fillRect(_aboutProxyPromotion->geometry(), st::historyReplyBg); + } if (_pinnedBar && !_pinnedBar->cancel->isHidden()) { drawPinnedBar(p); } diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index a5941c9c4..48be1db79 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -461,6 +461,7 @@ private: void setMembersShowAreaActive(bool active); void forwardItems(MessageIdsList &&items); void handleHistoryChange(not_null history); + void refreshAboutProxyPromotion(); void highlightMessage(MsgId universalMessageId); void adjustHighlightedMessageToMigrated(); @@ -783,6 +784,7 @@ private: object_ptr _botStart; object_ptr _joinChannel; object_ptr _muteUnmute; + object_ptr _aboutProxyPromotion = { nullptr }; mtpRequestId _unblockRequest = 0; mtpRequestId _reportSpamRequest = 0; object_ptr _attachToggle; diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index 8fed8c5b0..c6ea649e2 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -64,6 +64,7 @@ struct PeerUpdate { ChannelRightsChanged = (1 << 17), ChannelStickersChanged = (1 << 18), ChannelPinnedChanged = (1 << 19), + ChannelPromotedChanged = (1 << 20), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; }