Skip to content

Commit

Permalink
add button for encrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
astrophysik committed Nov 7, 2024
1 parent 520de60 commit 7e03bcb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Telegram/SourceFiles/data/data_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Telegram/SourceFiles/data/data_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -524,6 +535,7 @@ class PeerData {
BarSettings _barSettings = PeerBarSettings(PeerBarSetting::Unknown);
std::unique_ptr<PeerBarDetails> _barDetails;

EncryptionStatus _encryptionStatus = EncryptionStatus::Disabled;
BlockStatus _blockStatus = BlockStatus::Unknown;
LoadedStatus _loadedStatus = LoadedStatus::Not;
TranslationFlag _translationFlag = TranslationFlag::Unknown;
Expand Down
20 changes: 20 additions & 0 deletions Telegram/SourceFiles/window/window_peer_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class Filler {
void addVideoChat();
void addViewStatistics();
void addBoostChat();
void addEncryptButton();

not_null<SessionController*> _controller;
Dialogs::EntryState _request;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1410,6 +1429,7 @@ void Filler::fillContextMenuActions() {
void Filler::fillHistoryActions() {
addToggleMuteSubmenu(true);
addInfo();
addEncryptButton();
addViewAsTopics();
addStoryArchive();
addSupportInfo();
Expand Down

0 comments on commit 7e03bcb

Please sign in to comment.