diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 097cfdfa83e2d3..af69678bf70a81 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -1489,6 +1489,16 @@ void PeerData::setStoriesState(StoriesState state) { } } +void PeerData::setEncryption(bool encryption) { + const auto status = encryption + ? EncryptionStatus::Enabled + : EncryptionStatus::Disabled; + if (_encryptionStatus != status) { + _encryptionStatus = status; + //todo add here openssl handshake + } +} + void PeerData::setIsBlocked(bool is) { const auto status = is ? BlockStatus::Blocked diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index f88d801cea846b..edb3aea6670f7c 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -417,6 +417,17 @@ class PeerData { Blocked, NotBlocked, }; + enum class EncryptionStatus : char { + Disabled, + Enabled, + }; + [[nodiscard]] EncryptionStatus encryptionStatus() const { + return _encryptionStatus; + } + [[nodiscard]] bool isEcnrypted() const { + return encryptionStatus() == EncryptionStatus::Enabled; + } + void setEncryption(bool encryption); [[nodiscard]] BlockStatus blockStatus() const { return _blockStatus; } @@ -524,6 +535,7 @@ class PeerData { BarSettings _barSettings = PeerBarSettings(PeerBarSetting::Unknown); std::unique_ptr _barDetails; + EncryptionStatus _encryptionStatus = EncryptionStatus::Disabled; BlockStatus _blockStatus = BlockStatus::Unknown; LoadedStatus _loadedStatus = LoadedStatus::Not; TranslationFlag _translationFlag = TranslationFlag::Unknown; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 1164b150c1037b..7f783fc2737053 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -305,6 +305,7 @@ class Filler { void addVideoChat(); void addViewStatistics(); void addBoostChat(); + void addEncryptButton(); not_null _controller; Dialogs::EntryState _request; @@ -1082,6 +1083,24 @@ void Filler::addBoostChat() { } } +void Filler::addEncryptButton() { + const auto user = _peer->asUser(); + if (!user || user->isBot()) { + return; + } + if (!_peer->isEcnrypted()) { + _addAction({ + .text = "Enable encrypt", + .handler = [=] {_peer->setEncryption(true); }, + .icon = &st::menuIconDrugs,}); + } else { + _addAction({ + .text = "Disable encrypt", + .handler = [=] {_peer->setEncryption(false);}, + .icon = &st::menuIconDrugs,}); + } +} + void Filler::addViewStatistics() { if (const auto channel = _peer->asChannel()) { const auto controller = _controller; @@ -1410,6 +1429,7 @@ void Filler::fillContextMenuActions() { void Filler::fillHistoryActions() { addToggleMuteSubmenu(true); addInfo(); + addEncryptButton(); addViewAsTopics(); addStoryArchive(); addSupportInfo();