From 30d000e139a25a25f0e04d07d6a975b2d1f6d02a Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 28 Apr 2017 20:16:14 +0300 Subject: [PATCH] Toggle calls controls using config and user flags. Also use calls timeout values from config. Also request config each time when the auth session changes. --- Telegram/SourceFiles/apiwrap.cpp | 1 + Telegram/SourceFiles/calls/calls_call.cpp | 18 ++++---- Telegram/SourceFiles/calls/calls_call.h | 4 +- Telegram/SourceFiles/calls/calls_instance.cpp | 2 + Telegram/SourceFiles/facades.cpp | 12 ++++++ Telegram/SourceFiles/facades.h | 6 +++ Telegram/SourceFiles/historywidget.cpp | 4 +- Telegram/SourceFiles/mainwidget.cpp | 4 ++ Telegram/SourceFiles/messenger.cpp | 5 +++ Telegram/SourceFiles/mtproto/mtp_instance.cpp | 16 ++++++-- Telegram/SourceFiles/observer_peer.h | 1 + Telegram/SourceFiles/overviewwidget.cpp | 2 +- Telegram/SourceFiles/structs.cpp | 11 +++++ Telegram/SourceFiles/structs.h | 13 ++++++ .../SourceFiles/window/top_bar_widget.cpp | 35 ++++++++++------ Telegram/SourceFiles/window/top_bar_widget.h | 2 +- .../SourceFiles/window/window_main_menu.cpp | 41 ++++++++++++------- .../SourceFiles/window/window_main_menu.h | 1 + 18 files changed, 134 insertions(+), 44 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index c197fe857..83e139746 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -362,6 +362,7 @@ void ApiWrap::gotUserFull(UserData *user, const MTPUserFull &result, mtpRequestI user->setBotInfoVersion(-1); } user->setBlockStatus(d.is_blocked() ? UserData::BlockStatus::Blocked : UserData::BlockStatus::NotBlocked); + user->setCallsStatus(d.is_phone_calls_private() ? UserData::CallsStatus::Private : d.is_phone_calls_available() ? UserData::CallsStatus::Enabled : UserData::CallsStatus::Disabled); user->setAbout(d.has_about() ? qs(d.vabout) : QString()); user->setCommonChatsCount(d.vcommon_chats_count.v); diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 5c19916e2..c1d6e2f5e 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -44,9 +44,7 @@ namespace { constexpr auto kMinLayer = 65; constexpr auto kMaxLayer = 65; // MTP::CurrentLayer? -constexpr auto kHangupTimeoutMs = 5000; // TODO read from server config -constexpr auto kReceiveTimeoutMs = 5000; // TODO read from server config call_receive_timeout_ms -constexpr auto kRingTimeoutMs = 5000; // TODO read from server config call_ring_timeout_ms +constexpr auto kHangupTimeoutMs = 5000; using tgvoip::Endpoint; @@ -80,6 +78,7 @@ Call::Call(gsl::not_null delegate, gsl::not_null user, Typ , _type(type) { if (_type == Type::Outgoing) { setState(State::Requesting); + _discardByTimeoutTimer.setCallback([this] { hangup(); }); } } @@ -132,10 +131,12 @@ void Call::startOutgoing() { } setState(State::Waiting); + if (_finishAfterRequestingCall) { hangup(); return; } + _discardByTimeoutTimer.callOnce(Global::CallReceiveTimeoutMs()); auto &phoneCall = call.vphone_call.c_phoneCallWaiting(); _id = phoneCall.vid.v; @@ -228,7 +229,6 @@ bool Call::handleUpdate(const MTPPhoneCall &call) { LOG(("Call Error: Wrong call participant_id %1, expected %2.").arg(data.vparticipant_id.v).arg(AuthSession::CurrentUserId())); setState(State::Failed); return true; - } _id = data.vid.v; _accessHash = data.vaccess_hash.v; @@ -257,6 +257,7 @@ bool Call::handleUpdate(const MTPPhoneCall &call) { return false; } if (_state == State::Waiting && data.vreceive_date.v != 0) { + _discardByTimeoutTimer.callOnce(Global::CallRingTimeoutMs()); setState(State::Ringing); } } return true; @@ -362,6 +363,7 @@ void Call::startConfirmedCall(const MTPDphoneCall &call) { } void Call::createAndStartController(const MTPDphoneCall &call) { + _discardByTimeoutTimer.cancel(); if (!checkCallFields(call)) { return; } @@ -371,8 +373,8 @@ void Call::createAndStartController(const MTPDphoneCall &call) { config.enableAEC = true; config.enableNS = true; config.enableAGC = true; - config.init_timeout = 30; - config.recv_timeout = 10; + config.init_timeout = Global::CallConnectTimeoutMs() / 1000; + config.recv_timeout = Global::CallPacketTimeoutMs() / 1000; std::vector endpoints; ConvertEndpoint(endpoints, call.vconnection.c_phoneConnection()); @@ -492,7 +494,7 @@ void Call::setState(State state) { void Call::finish(const MTPPhoneCallDiscardReason &reason) { if (_state == State::Requesting) { - _hangupByTimeoutTimer.call(kHangupTimeoutMs, [this] { setState(State::Ended); }); + _finishByTimeoutTimer.call(kHangupTimeoutMs, [this] { setState(State::Ended); }); _finishAfterRequestingCall = true; return; } @@ -507,7 +509,7 @@ void Call::finish(const MTPPhoneCallDiscardReason &reason) { setState(State::HangingUp); auto duration = getDurationMs() / 1000; auto connectionId = _controller ? _controller->GetPreferredRelayID() : 0; - _hangupByTimeoutTimer.call(kHangupTimeoutMs, [this] { setState(State::Ended); }); + _finishByTimeoutTimer.call(kHangupTimeoutMs, [this] { setState(State::Ended); }); request(MTPphone_DiscardCall(MTP_inputPhoneCall(MTP_long(_id), MTP_long(_accessHash)), MTP_int(duration), reason, MTP_long(connectionId))).done([this](const MTPUpdates &result) { // This could be destroyed by updates, so we set Ended after // updates being handled, but in a guarded way. diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index 184d28776..8fa59b1d2 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -132,7 +132,9 @@ private: bool _finishAfterRequestingCall = false; base::Observable _stateChanged; TimeMs _startTime = 0; - base::DelayedCallTimer _hangupByTimeoutTimer; + base::DelayedCallTimer _finishByTimeoutTimer; + base::Timer _discardByTimeoutTimer; + bool _mute = false; base::Observable _muteChanged; diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 547ee78f8..9711db559 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -197,6 +197,8 @@ void Instance::handleCallUpdate(const MTPPhoneCall &call) { } if (_currentCall || !user || user->isSelf()) { request(MTPphone_DiscardCall(MTP_inputPhoneCall(phoneCall.vid, phoneCall.vaccess_hash), MTP_int(0), MTP_phoneCallDiscardReasonBusy(), MTP_long(0))).send(); + } else if (phoneCall.vdate.v + Global::CallRingTimeoutMs() / 1000 < unixtime()) { + LOG(("Ignoring too old call.")); } else { createCall(user, Call::Type::Incoming); _currentCall->handleUpdate(call); diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 9d7d6ddbc..3aae8222c 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -630,6 +630,12 @@ struct Data { int32 StickersRecentLimit = 30; int32 PinnedDialogsCountMax = 5; QString InternalLinksDomain = qsl("https://t.me/"); + int32 CallReceiveTimeoutMs = 20000; + int32 CallRingTimeoutMs = 90000; + int32 CallConnectTimeoutMs = 30000; + int32 CallPacketTimeoutMs = 10000; + bool PhoneCallsEnabled = true; + base::Observable PhoneCallsEnabledChanged; HiddenPinnedMessagesMap HiddenPinnedMessages; @@ -746,6 +752,12 @@ DefineVar(Global, int32, EditTimeLimit); DefineVar(Global, int32, StickersRecentLimit); DefineVar(Global, int32, PinnedDialogsCountMax); DefineVar(Global, QString, InternalLinksDomain); +DefineVar(Global, int32, CallReceiveTimeoutMs); +DefineVar(Global, int32, CallRingTimeoutMs); +DefineVar(Global, int32, CallConnectTimeoutMs); +DefineVar(Global, int32, CallPacketTimeoutMs); +DefineVar(Global, bool, PhoneCallsEnabled); +DefineRefVar(Global, base::Observable, PhoneCallsEnabledChanged); DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages); diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index c4735aedf..493d7efe4 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -336,6 +336,12 @@ DeclareVar(int32, EditTimeLimit); DeclareVar(int32, StickersRecentLimit); DeclareVar(int32, PinnedDialogsCountMax); DeclareVar(QString, InternalLinksDomain); +DeclareVar(int32, CallReceiveTimeoutMs); +DeclareVar(int32, CallRingTimeoutMs); +DeclareVar(int32, CallConnectTimeoutMs); +DeclareVar(int32, CallPacketTimeoutMs); +DeclareVar(bool, PhoneCallsEnabled); +DeclareRefVar(base::Observable, PhoneCallsEnabledChanged); typedef QMap HiddenPinnedMessagesMap; DeclareVar(HiddenPinnedMessagesMap, HiddenPinnedMessages); diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 3745f3adf..f145abd63 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -2916,7 +2916,7 @@ void HistoryWidget::showAnimated(Window::SlideDirection direction, const Window: _cacheUnder = params.oldContentCache; show(); - _topBar->showAll(); + _topBar->updateControlsVisibility(); historyDownAnimationFinish(); _topShadow->setVisible(params.withTopBarShadow ? false : true); _cacheOver = App::main()->grabForShowAnimation(params); @@ -5760,7 +5760,7 @@ void HistoryWidget::peerUpdated(PeerData *data) { if (App::api()) { if (data->isChat() && data->asChat()->noParticipantInfo()) { App::api()->requestFullPeer(data); - } else if (data->isUser() && data->asUser()->blockStatus() == UserData::BlockStatus::Unknown) { + } else if (data->isUser() && (data->asUser()->blockStatus() == UserData::BlockStatus::Unknown || data->asUser()->callsStatus() == UserData::CallsStatus::Unknown)) { App::api()->requestFullPeer(data); } else if (data->isMegagroup() && !data->asChannel()->mgInfo->botStatus) { App::api()->requestBots(data->asChannel()); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index da53c3d22..82fbb858b 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -4893,6 +4893,10 @@ void MainWidget::feedUpdate(const MTPUpdate &update) { Messenger::Instance().dcOptions()->addFromList(d.vdc_options); } break; + case mtpc_updateConfig: { + Messenger::Instance().mtp()->configLoadRequest(); + } break; + case mtpc_updateUserPhone: { auto &d = update.c_updateUserPhone(); if (auto user = App::userLoaded(d.vuser_id.v)) { diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index 252783009..5c6425b96 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -402,6 +402,11 @@ void Messenger::startLocalStorage() { } } }); + subscribe(authSessionChanged(), [this] { + if (_mtproto) { + _mtproto->configLoadRequest(); + } + }); } void Messenger::regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId) { diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index 59533b365..82947e6b1 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -575,14 +575,22 @@ void Instance::Private::configLoadDone(const MTPConfig &result) { Global::SetOnlineCloudTimeout(data.vonline_cloud_timeout_ms.v); Global::SetNotifyCloudDelay(data.vnotify_cloud_delay_ms.v); Global::SetNotifyDefaultDelay(data.vnotify_default_delay_ms.v); - Global::SetChatBigSize(data.vchat_big_size.v); // ? - Global::SetPushChatPeriod(data.vpush_chat_period_ms.v); // ? - Global::SetPushChatLimit(data.vpush_chat_limit.v); // ? + Global::SetChatBigSize(data.vchat_big_size.v); + Global::SetPushChatPeriod(data.vpush_chat_period_ms.v); + Global::SetPushChatLimit(data.vpush_chat_limit.v); Global::SetSavedGifsLimit(data.vsaved_gifs_limit.v); - Global::SetEditTimeLimit(data.vedit_time_limit.v); // ? + Global::SetEditTimeLimit(data.vedit_time_limit.v); Global::SetStickersRecentLimit(data.vstickers_recent_limit.v); Global::SetPinnedDialogsCountMax(data.vpinned_dialogs_count_max.v); Messenger::Instance().setInternalLinkDomain(qs(data.vme_url_prefix)); + Global::SetCallReceiveTimeoutMs(data.vcall_receive_timeout_ms.v); + Global::SetCallRingTimeoutMs(data.vcall_ring_timeout_ms.v); + Global::SetCallConnectTimeoutMs(data.vcall_connect_timeout_ms.v); + Global::SetCallPacketTimeoutMs(data.vcall_packet_timeout_ms.v); + if (Global::PhoneCallsEnabled() != data.is_phonecalls_enabled()) { + Global::SetPhoneCallsEnabled(data.is_phonecalls_enabled()); + Global::RefPhoneCallsEnabledChanged().notify(); + } Local::writeSettings(); diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index da84ed809..0ac021aff 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -59,6 +59,7 @@ struct PeerUpdate { UserOnlineChanged = 0x00200000U, BotCanAddToGroups = 0x00400000U, UserCommonChatsChanged = 0x00800000U, + UserHasCalls = 0x01000000U, // For chats ChatCanEdit = 0x00010000U, diff --git a/Telegram/SourceFiles/overviewwidget.cpp b/Telegram/SourceFiles/overviewwidget.cpp index d6a43a529..70a13e7dc 100644 --- a/Telegram/SourceFiles/overviewwidget.cpp +++ b/Telegram/SourceFiles/overviewwidget.cpp @@ -2149,7 +2149,7 @@ void OverviewWidget::showAnimated(Window::SlideDirection direction, const Window _cacheUnder = params.oldContentCache; show(); - _topBar->showAll(); + _topBar->updateControlsVisibility(); _topShadow->setVisible(params.withTopBarShadow ? false : true); _cacheOver = App::main()->grabForShowAnimation(params); _topShadow->setVisible(params.withTopBarShadow ? true : false); diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index c7c3678ed..7ea004c36 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -578,6 +578,17 @@ void UserData::setBlockStatus(BlockStatus blockStatus) { } } +void UserData::setCallsStatus(CallsStatus callsStatus) { + if (callsStatus != _callsStatus) { + _callsStatus = callsStatus; + Notify::peerUpdatedDelayed(this, UpdateFlag::UserHasCalls); + } +} + +bool UserData::hasCalls() const { + return (callsStatus() != CallsStatus::Disabled) && (callsStatus() != CallsStatus::Unknown); +} + void ChatData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Local::readPeer as well PhotoId newPhotoId = photoId; ImagePtr newPhoto = _userpic; diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index 50d55f446..e899e012a 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -508,6 +508,18 @@ public: } void setBlockStatus(BlockStatus blockStatus); + enum class CallsStatus { + Unknown, + Enabled, + Disabled, + Private, + }; + CallsStatus callsStatus() const { + return _callsStatus; + } + bool hasCalls() const; + void setCallsStatus(CallsStatus callsStatus); + typedef QList Photos; Photos photos; int photosCount = -1; // -1 not loaded, 0 all loaded @@ -536,6 +548,7 @@ private: QString _about; QString _phone; BlockStatus _blockStatus = BlockStatus::Unknown; + CallsStatus _callsStatus = CallsStatus::Unknown; int _commonChatsCount = 0; static constexpr const uint64 NoAccess = 0xFFFFFFFFFFFFFFFFULL; diff --git a/Telegram/SourceFiles/window/top_bar_widget.cpp b/Telegram/SourceFiles/window/top_bar_widget.cpp index 07a7feff7..ccd296aca 100644 --- a/Telegram/SourceFiles/window/top_bar_widget.cpp +++ b/Telegram/SourceFiles/window/top_bar_widget.cpp @@ -33,6 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "dialogs/dialogs_layout.h" #include "window/window_controller.h" #include "calls/calls_instance.h" +#include "observer_peer.h" namespace Window { @@ -77,9 +78,15 @@ TopBarWidget::TopBarWidget(QWidget *parent, gsl::not_null c rtlupdate(0, 0, width(), height()); } }); + subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::UserHasCalls, [this](const Notify::PeerUpdate &update) { + if (update.peer->isUser()) { + updateControlsVisibility(); + } + })); + subscribe(Global::RefPhoneCallsEnabledChanged(), [this] { updateControlsVisibility(); }); setCursor(style::cur_pointer); - showAll(); + updateControlsVisibility(); } void TopBarWidget::onForwardSelection() { @@ -95,7 +102,7 @@ void TopBarWidget::onClearSelection() { } void TopBarWidget::onInfoClicked() { - PeerData *p = App::main() ? App::main()->historyPeer() : 0; + auto p = App::main() ? App::main()->historyPeer() : nullptr; if (p) Ui::showPeerProfile(p); } @@ -190,12 +197,12 @@ void TopBarWidget::paintEvent(QPaintEvent *e) { if (!_menuToggle->isHidden()) { decreaseWidth += _menuToggle->width(); } - if (!_call->isHidden()) { - decreaseWidth += _call->width(); - } if (!_search->isHidden()) { decreaseWidth += _search->width(); } + if (!_call->isHidden()) { + decreaseWidth += _call->width(); + } auto paintCounter = App::main()->paintTopBar(p, decreaseWidth, ms); p.restore(); @@ -279,17 +286,17 @@ void TopBarWidget::updateControlsGeometry() { } else { right += _info->width(); } - _call->moveToRight(right, otherButtonsTop); - if (!_call->isHidden()) right += _call->width(); _search->moveToRight(right, otherButtonsTop); + right += _search->width(); + _call->moveToRight(right, otherButtonsTop); } void TopBarWidget::animationFinished() { updateMembersShowArea(); - showAll(); + updateControlsVisibility(); } -void TopBarWidget::showAll() { +void TopBarWidget::updateControlsVisibility() { auto historyPeer = App::main() ? App::main()->historyPeer() : nullptr; auto overviewPeer = App::main() ? App::main()->overviewPeer() : nullptr; @@ -309,7 +316,11 @@ void TopBarWidget::showAll() { _menuToggle->show(); } _search->show(); - _call->setVisible(historyPeer->isUser()); + auto callsEnabled = false; + if (auto user = historyPeer->asUser()) { + callsEnabled = Global::PhoneCallsEnabled() && user->hasCalls(); + } + _call->setVisible(callsEnabled); } else { _search->hide(); _call->hide(); @@ -377,7 +388,7 @@ void TopBarWidget::showSelected(SelectedState state) { if (_canDelete != canDelete || _canForward != canForward) { _canDelete = canDelete; _canForward = canForward; - showAll(); + updateControlsVisibility(); } if (wasSelected != hasSelected) { setCursor(hasSelected ? style::cur_default : style::cur_pointer); @@ -396,7 +407,7 @@ void TopBarWidget::selectedShowCallback() { void TopBarWidget::updateAdaptiveLayout() { updateMembersShowArea(); - showAll(); + updateControlsVisibility(); if (!Adaptive::OneColumn()) { unsubscribe(base::take(_unreadCounterSubscription)); } else if (!_unreadCounterSubscription) { diff --git a/Telegram/SourceFiles/window/top_bar_widget.h b/Telegram/SourceFiles/window/top_bar_widget.h index ad4d8aa15..3b43715dc 100644 --- a/Telegram/SourceFiles/window/top_bar_widget.h +++ b/Telegram/SourceFiles/window/top_bar_widget.h @@ -46,7 +46,7 @@ public: int canForwardCount = 0; }; - void showAll(); + void updateControlsVisibility(); void showSelected(SelectedState state); void animationFinished(); void updateMembersShowArea(); diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index ecfa3b155..907db320d 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -54,6 +54,27 @@ MainMenu::MainMenu(QWidget *parent) : TWidget(parent) _menu->setTriggeredCallback([](QAction *action, int actionTop, Ui::Menu::TriggeredSource source) { emit action->triggered(); }); + refreshMenu(); + + _telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop"))); + _telegram->setLink(1, MakeShared(qsl("https://desktop.telegram.org"))); + _version->setRichText(textcmdLink(1, lng_settings_current_version(lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, lang(lng_menu_about))); + _version->setLink(1, MakeShared(qsl("https://desktop.telegram.org/changelog"))); + _version->setLink(2, MakeShared([] { Ui::show(Box()); })); + + subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); }); + subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); }); + subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::UserPhoneChanged, [this](const Notify::PeerUpdate &update) { + if (update.peer->isSelf()) { + updatePhone(); + } + })); + subscribe(Global::RefPhoneCallsEnabledChanged(), [this] { refreshMenu(); }); + updatePhone(); +} + +void MainMenu::refreshMenu() { + _menu->clearActions(); _menu->addAction(lang(lng_create_group_title), [] { App::wnd()->onShowNewGroup(); }, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver); @@ -63,9 +84,11 @@ MainMenu::MainMenu(QWidget *parent) : TWidget(parent) _menu->addAction(lang(lng_menu_contacts), [] { Ui::show(Box()); }, &st::mainMenuContacts, &st::mainMenuContactsOver); - _menu->addAction(lang(lng_menu_calls), [] { - Ui::show(Box(std::make_unique())); - }, &st::mainMenuCalls, &st::mainMenuCallsOver); + if (Global::PhoneCallsEnabled()) { + _menu->addAction(lang(lng_menu_calls), [] { + Ui::show(Box(std::make_unique())); + }, &st::mainMenuCalls, &st::mainMenuCallsOver); + } _menu->addAction(lang(lng_menu_settings), [] { App::wnd()->showSettings(); }, &st::mainMenuSettings, &st::mainMenuSettingsOver); @@ -73,18 +96,6 @@ MainMenu::MainMenu(QWidget *parent) : TWidget(parent) QDesktopServices::openUrl(telegramFaqLink()); }, &st::mainMenuHelp, &st::mainMenuHelpOver); - _telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop"))); - _telegram->setLink(1, MakeShared(qsl("https://desktop.telegram.org"))); - _version->setRichText(textcmdLink(1, lng_settings_current_version(lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, lang(lng_menu_about))); - _version->setLink(1, MakeShared(qsl("https://desktop.telegram.org/changelog"))); - _version->setLink(2, MakeShared([] { Ui::show(Box()); })); - - subscribe(AuthSession::CurrentDownloaderTaskFinished(), [this] { update(); }); - subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::UserPhoneChanged, [this](const Notify::PeerUpdate &update) { - if (update.peer->isSelf()) { - updatePhone(); - } - })); updatePhone(); } diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index a21ddc632..dd2185e08 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -49,6 +49,7 @@ private: void checkSelf(); void updateControlsGeometry(); void updatePhone(); + void refreshMenu(); object_ptr _userpicButton = { nullptr }; object_ptr _cloudButton = { nullptr };