mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
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.
This commit is contained in:
parent
f4911431d5
commit
30d000e139
18 changed files with 134 additions and 44 deletions
|
@ -362,6 +362,7 @@ void ApiWrap::gotUserFull(UserData *user, const MTPUserFull &result, mtpRequestI
|
||||||
user->setBotInfoVersion(-1);
|
user->setBotInfoVersion(-1);
|
||||||
}
|
}
|
||||||
user->setBlockStatus(d.is_blocked() ? UserData::BlockStatus::Blocked : UserData::BlockStatus::NotBlocked);
|
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->setAbout(d.has_about() ? qs(d.vabout) : QString());
|
||||||
user->setCommonChatsCount(d.vcommon_chats_count.v);
|
user->setCommonChatsCount(d.vcommon_chats_count.v);
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,7 @@ namespace {
|
||||||
|
|
||||||
constexpr auto kMinLayer = 65;
|
constexpr auto kMinLayer = 65;
|
||||||
constexpr auto kMaxLayer = 65; // MTP::CurrentLayer?
|
constexpr auto kMaxLayer = 65; // MTP::CurrentLayer?
|
||||||
constexpr auto kHangupTimeoutMs = 5000; // TODO read from server config
|
constexpr auto kHangupTimeoutMs = 5000;
|
||||||
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
|
|
||||||
|
|
||||||
using tgvoip::Endpoint;
|
using tgvoip::Endpoint;
|
||||||
|
|
||||||
|
@ -80,6 +78,7 @@ Call::Call(gsl::not_null<Delegate*> delegate, gsl::not_null<UserData*> user, Typ
|
||||||
, _type(type) {
|
, _type(type) {
|
||||||
if (_type == Type::Outgoing) {
|
if (_type == Type::Outgoing) {
|
||||||
setState(State::Requesting);
|
setState(State::Requesting);
|
||||||
|
_discardByTimeoutTimer.setCallback([this] { hangup(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,10 +131,12 @@ void Call::startOutgoing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(State::Waiting);
|
setState(State::Waiting);
|
||||||
|
|
||||||
if (_finishAfterRequestingCall) {
|
if (_finishAfterRequestingCall) {
|
||||||
hangup();
|
hangup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_discardByTimeoutTimer.callOnce(Global::CallReceiveTimeoutMs());
|
||||||
|
|
||||||
auto &phoneCall = call.vphone_call.c_phoneCallWaiting();
|
auto &phoneCall = call.vphone_call.c_phoneCallWaiting();
|
||||||
_id = phoneCall.vid.v;
|
_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()));
|
LOG(("Call Error: Wrong call participant_id %1, expected %2.").arg(data.vparticipant_id.v).arg(AuthSession::CurrentUserId()));
|
||||||
setState(State::Failed);
|
setState(State::Failed);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
_id = data.vid.v;
|
_id = data.vid.v;
|
||||||
_accessHash = data.vaccess_hash.v;
|
_accessHash = data.vaccess_hash.v;
|
||||||
|
@ -257,6 +257,7 @@ bool Call::handleUpdate(const MTPPhoneCall &call) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (_state == State::Waiting && data.vreceive_date.v != 0) {
|
if (_state == State::Waiting && data.vreceive_date.v != 0) {
|
||||||
|
_discardByTimeoutTimer.callOnce(Global::CallRingTimeoutMs());
|
||||||
setState(State::Ringing);
|
setState(State::Ringing);
|
||||||
}
|
}
|
||||||
} return true;
|
} return true;
|
||||||
|
@ -362,6 +363,7 @@ void Call::startConfirmedCall(const MTPDphoneCall &call) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Call::createAndStartController(const MTPDphoneCall &call) {
|
void Call::createAndStartController(const MTPDphoneCall &call) {
|
||||||
|
_discardByTimeoutTimer.cancel();
|
||||||
if (!checkCallFields(call)) {
|
if (!checkCallFields(call)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -371,8 +373,8 @@ void Call::createAndStartController(const MTPDphoneCall &call) {
|
||||||
config.enableAEC = true;
|
config.enableAEC = true;
|
||||||
config.enableNS = true;
|
config.enableNS = true;
|
||||||
config.enableAGC = true;
|
config.enableAGC = true;
|
||||||
config.init_timeout = 30;
|
config.init_timeout = Global::CallConnectTimeoutMs() / 1000;
|
||||||
config.recv_timeout = 10;
|
config.recv_timeout = Global::CallPacketTimeoutMs() / 1000;
|
||||||
|
|
||||||
std::vector<Endpoint> endpoints;
|
std::vector<Endpoint> endpoints;
|
||||||
ConvertEndpoint(endpoints, call.vconnection.c_phoneConnection());
|
ConvertEndpoint(endpoints, call.vconnection.c_phoneConnection());
|
||||||
|
@ -492,7 +494,7 @@ void Call::setState(State state) {
|
||||||
|
|
||||||
void Call::finish(const MTPPhoneCallDiscardReason &reason) {
|
void Call::finish(const MTPPhoneCallDiscardReason &reason) {
|
||||||
if (_state == State::Requesting) {
|
if (_state == State::Requesting) {
|
||||||
_hangupByTimeoutTimer.call(kHangupTimeoutMs, [this] { setState(State::Ended); });
|
_finishByTimeoutTimer.call(kHangupTimeoutMs, [this] { setState(State::Ended); });
|
||||||
_finishAfterRequestingCall = true;
|
_finishAfterRequestingCall = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -507,7 +509,7 @@ void Call::finish(const MTPPhoneCallDiscardReason &reason) {
|
||||||
setState(State::HangingUp);
|
setState(State::HangingUp);
|
||||||
auto duration = getDurationMs() / 1000;
|
auto duration = getDurationMs() / 1000;
|
||||||
auto connectionId = _controller ? _controller->GetPreferredRelayID() : 0;
|
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) {
|
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
|
// This could be destroyed by updates, so we set Ended after
|
||||||
// updates being handled, but in a guarded way.
|
// updates being handled, but in a guarded way.
|
||||||
|
|
|
@ -132,7 +132,9 @@ private:
|
||||||
bool _finishAfterRequestingCall = false;
|
bool _finishAfterRequestingCall = false;
|
||||||
base::Observable<State> _stateChanged;
|
base::Observable<State> _stateChanged;
|
||||||
TimeMs _startTime = 0;
|
TimeMs _startTime = 0;
|
||||||
base::DelayedCallTimer _hangupByTimeoutTimer;
|
base::DelayedCallTimer _finishByTimeoutTimer;
|
||||||
|
base::Timer _discardByTimeoutTimer;
|
||||||
|
|
||||||
bool _mute = false;
|
bool _mute = false;
|
||||||
base::Observable<bool> _muteChanged;
|
base::Observable<bool> _muteChanged;
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,8 @@ void Instance::handleCallUpdate(const MTPPhoneCall &call) {
|
||||||
}
|
}
|
||||||
if (_currentCall || !user || user->isSelf()) {
|
if (_currentCall || !user || user->isSelf()) {
|
||||||
request(MTPphone_DiscardCall(MTP_inputPhoneCall(phoneCall.vid, phoneCall.vaccess_hash), MTP_int(0), MTP_phoneCallDiscardReasonBusy(), MTP_long(0))).send();
|
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 {
|
} else {
|
||||||
createCall(user, Call::Type::Incoming);
|
createCall(user, Call::Type::Incoming);
|
||||||
_currentCall->handleUpdate(call);
|
_currentCall->handleUpdate(call);
|
||||||
|
|
|
@ -630,6 +630,12 @@ struct Data {
|
||||||
int32 StickersRecentLimit = 30;
|
int32 StickersRecentLimit = 30;
|
||||||
int32 PinnedDialogsCountMax = 5;
|
int32 PinnedDialogsCountMax = 5;
|
||||||
QString InternalLinksDomain = qsl("https://t.me/");
|
QString InternalLinksDomain = qsl("https://t.me/");
|
||||||
|
int32 CallReceiveTimeoutMs = 20000;
|
||||||
|
int32 CallRingTimeoutMs = 90000;
|
||||||
|
int32 CallConnectTimeoutMs = 30000;
|
||||||
|
int32 CallPacketTimeoutMs = 10000;
|
||||||
|
bool PhoneCallsEnabled = true;
|
||||||
|
base::Observable<void> PhoneCallsEnabledChanged;
|
||||||
|
|
||||||
HiddenPinnedMessagesMap HiddenPinnedMessages;
|
HiddenPinnedMessagesMap HiddenPinnedMessages;
|
||||||
|
|
||||||
|
@ -746,6 +752,12 @@ DefineVar(Global, int32, EditTimeLimit);
|
||||||
DefineVar(Global, int32, StickersRecentLimit);
|
DefineVar(Global, int32, StickersRecentLimit);
|
||||||
DefineVar(Global, int32, PinnedDialogsCountMax);
|
DefineVar(Global, int32, PinnedDialogsCountMax);
|
||||||
DefineVar(Global, QString, InternalLinksDomain);
|
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<void>, PhoneCallsEnabledChanged);
|
||||||
|
|
||||||
DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages);
|
DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages);
|
||||||
|
|
||||||
|
|
|
@ -336,6 +336,12 @@ DeclareVar(int32, EditTimeLimit);
|
||||||
DeclareVar(int32, StickersRecentLimit);
|
DeclareVar(int32, StickersRecentLimit);
|
||||||
DeclareVar(int32, PinnedDialogsCountMax);
|
DeclareVar(int32, PinnedDialogsCountMax);
|
||||||
DeclareVar(QString, InternalLinksDomain);
|
DeclareVar(QString, InternalLinksDomain);
|
||||||
|
DeclareVar(int32, CallReceiveTimeoutMs);
|
||||||
|
DeclareVar(int32, CallRingTimeoutMs);
|
||||||
|
DeclareVar(int32, CallConnectTimeoutMs);
|
||||||
|
DeclareVar(int32, CallPacketTimeoutMs);
|
||||||
|
DeclareVar(bool, PhoneCallsEnabled);
|
||||||
|
DeclareRefVar(base::Observable<void>, PhoneCallsEnabledChanged);
|
||||||
|
|
||||||
typedef QMap<PeerId, MsgId> HiddenPinnedMessagesMap;
|
typedef QMap<PeerId, MsgId> HiddenPinnedMessagesMap;
|
||||||
DeclareVar(HiddenPinnedMessagesMap, HiddenPinnedMessages);
|
DeclareVar(HiddenPinnedMessagesMap, HiddenPinnedMessages);
|
||||||
|
|
|
@ -2916,7 +2916,7 @@ void HistoryWidget::showAnimated(Window::SlideDirection direction, const Window:
|
||||||
|
|
||||||
_cacheUnder = params.oldContentCache;
|
_cacheUnder = params.oldContentCache;
|
||||||
show();
|
show();
|
||||||
_topBar->showAll();
|
_topBar->updateControlsVisibility();
|
||||||
historyDownAnimationFinish();
|
historyDownAnimationFinish();
|
||||||
_topShadow->setVisible(params.withTopBarShadow ? false : true);
|
_topShadow->setVisible(params.withTopBarShadow ? false : true);
|
||||||
_cacheOver = App::main()->grabForShowAnimation(params);
|
_cacheOver = App::main()->grabForShowAnimation(params);
|
||||||
|
@ -5760,7 +5760,7 @@ void HistoryWidget::peerUpdated(PeerData *data) {
|
||||||
if (App::api()) {
|
if (App::api()) {
|
||||||
if (data->isChat() && data->asChat()->noParticipantInfo()) {
|
if (data->isChat() && data->asChat()->noParticipantInfo()) {
|
||||||
App::api()->requestFullPeer(data);
|
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);
|
App::api()->requestFullPeer(data);
|
||||||
} else if (data->isMegagroup() && !data->asChannel()->mgInfo->botStatus) {
|
} else if (data->isMegagroup() && !data->asChannel()->mgInfo->botStatus) {
|
||||||
App::api()->requestBots(data->asChannel());
|
App::api()->requestBots(data->asChannel());
|
||||||
|
|
|
@ -4893,6 +4893,10 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
|
||||||
Messenger::Instance().dcOptions()->addFromList(d.vdc_options);
|
Messenger::Instance().dcOptions()->addFromList(d.vdc_options);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case mtpc_updateConfig: {
|
||||||
|
Messenger::Instance().mtp()->configLoadRequest();
|
||||||
|
} break;
|
||||||
|
|
||||||
case mtpc_updateUserPhone: {
|
case mtpc_updateUserPhone: {
|
||||||
auto &d = update.c_updateUserPhone();
|
auto &d = update.c_updateUserPhone();
|
||||||
if (auto user = App::userLoaded(d.vuser_id.v)) {
|
if (auto user = App::userLoaded(d.vuser_id.v)) {
|
||||||
|
|
|
@ -402,6 +402,11 @@ void Messenger::startLocalStorage() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
subscribe(authSessionChanged(), [this] {
|
||||||
|
if (_mtproto) {
|
||||||
|
_mtproto->configLoadRequest();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Messenger::regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId) {
|
void Messenger::regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId) {
|
||||||
|
|
|
@ -575,14 +575,22 @@ void Instance::Private::configLoadDone(const MTPConfig &result) {
|
||||||
Global::SetOnlineCloudTimeout(data.vonline_cloud_timeout_ms.v);
|
Global::SetOnlineCloudTimeout(data.vonline_cloud_timeout_ms.v);
|
||||||
Global::SetNotifyCloudDelay(data.vnotify_cloud_delay_ms.v);
|
Global::SetNotifyCloudDelay(data.vnotify_cloud_delay_ms.v);
|
||||||
Global::SetNotifyDefaultDelay(data.vnotify_default_delay_ms.v);
|
Global::SetNotifyDefaultDelay(data.vnotify_default_delay_ms.v);
|
||||||
Global::SetChatBigSize(data.vchat_big_size.v); // ?
|
Global::SetChatBigSize(data.vchat_big_size.v);
|
||||||
Global::SetPushChatPeriod(data.vpush_chat_period_ms.v); // ?
|
Global::SetPushChatPeriod(data.vpush_chat_period_ms.v);
|
||||||
Global::SetPushChatLimit(data.vpush_chat_limit.v); // ?
|
Global::SetPushChatLimit(data.vpush_chat_limit.v);
|
||||||
Global::SetSavedGifsLimit(data.vsaved_gifs_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::SetStickersRecentLimit(data.vstickers_recent_limit.v);
|
||||||
Global::SetPinnedDialogsCountMax(data.vpinned_dialogs_count_max.v);
|
Global::SetPinnedDialogsCountMax(data.vpinned_dialogs_count_max.v);
|
||||||
Messenger::Instance().setInternalLinkDomain(qs(data.vme_url_prefix));
|
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();
|
Local::writeSettings();
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ struct PeerUpdate {
|
||||||
UserOnlineChanged = 0x00200000U,
|
UserOnlineChanged = 0x00200000U,
|
||||||
BotCanAddToGroups = 0x00400000U,
|
BotCanAddToGroups = 0x00400000U,
|
||||||
UserCommonChatsChanged = 0x00800000U,
|
UserCommonChatsChanged = 0x00800000U,
|
||||||
|
UserHasCalls = 0x01000000U,
|
||||||
|
|
||||||
// For chats
|
// For chats
|
||||||
ChatCanEdit = 0x00010000U,
|
ChatCanEdit = 0x00010000U,
|
||||||
|
|
|
@ -2149,7 +2149,7 @@ void OverviewWidget::showAnimated(Window::SlideDirection direction, const Window
|
||||||
|
|
||||||
_cacheUnder = params.oldContentCache;
|
_cacheUnder = params.oldContentCache;
|
||||||
show();
|
show();
|
||||||
_topBar->showAll();
|
_topBar->updateControlsVisibility();
|
||||||
_topShadow->setVisible(params.withTopBarShadow ? false : true);
|
_topShadow->setVisible(params.withTopBarShadow ? false : true);
|
||||||
_cacheOver = App::main()->grabForShowAnimation(params);
|
_cacheOver = App::main()->grabForShowAnimation(params);
|
||||||
_topShadow->setVisible(params.withTopBarShadow ? true : false);
|
_topShadow->setVisible(params.withTopBarShadow ? true : false);
|
||||||
|
|
|
@ -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
|
void ChatData::setPhoto(const MTPChatPhoto &p, const PhotoId &phId) { // see Local::readPeer as well
|
||||||
PhotoId newPhotoId = photoId;
|
PhotoId newPhotoId = photoId;
|
||||||
ImagePtr newPhoto = _userpic;
|
ImagePtr newPhoto = _userpic;
|
||||||
|
|
|
@ -508,6 +508,18 @@ public:
|
||||||
}
|
}
|
||||||
void setBlockStatus(BlockStatus blockStatus);
|
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<PhotoData*> Photos;
|
typedef QList<PhotoData*> Photos;
|
||||||
Photos photos;
|
Photos photos;
|
||||||
int photosCount = -1; // -1 not loaded, 0 all loaded
|
int photosCount = -1; // -1 not loaded, 0 all loaded
|
||||||
|
@ -536,6 +548,7 @@ private:
|
||||||
QString _about;
|
QString _about;
|
||||||
QString _phone;
|
QString _phone;
|
||||||
BlockStatus _blockStatus = BlockStatus::Unknown;
|
BlockStatus _blockStatus = BlockStatus::Unknown;
|
||||||
|
CallsStatus _callsStatus = CallsStatus::Unknown;
|
||||||
int _commonChatsCount = 0;
|
int _commonChatsCount = 0;
|
||||||
|
|
||||||
static constexpr const uint64 NoAccess = 0xFFFFFFFFFFFFFFFFULL;
|
static constexpr const uint64 NoAccess = 0xFFFFFFFFFFFFFFFFULL;
|
||||||
|
|
|
@ -33,6 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
#include "dialogs/dialogs_layout.h"
|
#include "dialogs/dialogs_layout.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "calls/calls_instance.h"
|
#include "calls/calls_instance.h"
|
||||||
|
#include "observer_peer.h"
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
|
|
||||||
|
@ -77,9 +78,15 @@ TopBarWidget::TopBarWidget(QWidget *parent, gsl::not_null<Window::Controller*> c
|
||||||
rtlupdate(0, 0, width(), height());
|
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);
|
setCursor(style::cur_pointer);
|
||||||
showAll();
|
updateControlsVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopBarWidget::onForwardSelection() {
|
void TopBarWidget::onForwardSelection() {
|
||||||
|
@ -95,7 +102,7 @@ void TopBarWidget::onClearSelection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopBarWidget::onInfoClicked() {
|
void TopBarWidget::onInfoClicked() {
|
||||||
PeerData *p = App::main() ? App::main()->historyPeer() : 0;
|
auto p = App::main() ? App::main()->historyPeer() : nullptr;
|
||||||
if (p) Ui::showPeerProfile(p);
|
if (p) Ui::showPeerProfile(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,12 +197,12 @@ void TopBarWidget::paintEvent(QPaintEvent *e) {
|
||||||
if (!_menuToggle->isHidden()) {
|
if (!_menuToggle->isHidden()) {
|
||||||
decreaseWidth += _menuToggle->width();
|
decreaseWidth += _menuToggle->width();
|
||||||
}
|
}
|
||||||
if (!_call->isHidden()) {
|
|
||||||
decreaseWidth += _call->width();
|
|
||||||
}
|
|
||||||
if (!_search->isHidden()) {
|
if (!_search->isHidden()) {
|
||||||
decreaseWidth += _search->width();
|
decreaseWidth += _search->width();
|
||||||
}
|
}
|
||||||
|
if (!_call->isHidden()) {
|
||||||
|
decreaseWidth += _call->width();
|
||||||
|
}
|
||||||
auto paintCounter = App::main()->paintTopBar(p, decreaseWidth, ms);
|
auto paintCounter = App::main()->paintTopBar(p, decreaseWidth, ms);
|
||||||
p.restore();
|
p.restore();
|
||||||
|
|
||||||
|
@ -279,17 +286,17 @@ void TopBarWidget::updateControlsGeometry() {
|
||||||
} else {
|
} else {
|
||||||
right += _info->width();
|
right += _info->width();
|
||||||
}
|
}
|
||||||
_call->moveToRight(right, otherButtonsTop);
|
|
||||||
if (!_call->isHidden()) right += _call->width();
|
|
||||||
_search->moveToRight(right, otherButtonsTop);
|
_search->moveToRight(right, otherButtonsTop);
|
||||||
|
right += _search->width();
|
||||||
|
_call->moveToRight(right, otherButtonsTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopBarWidget::animationFinished() {
|
void TopBarWidget::animationFinished() {
|
||||||
updateMembersShowArea();
|
updateMembersShowArea();
|
||||||
showAll();
|
updateControlsVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopBarWidget::showAll() {
|
void TopBarWidget::updateControlsVisibility() {
|
||||||
auto historyPeer = App::main() ? App::main()->historyPeer() : nullptr;
|
auto historyPeer = App::main() ? App::main()->historyPeer() : nullptr;
|
||||||
auto overviewPeer = App::main() ? App::main()->overviewPeer() : nullptr;
|
auto overviewPeer = App::main() ? App::main()->overviewPeer() : nullptr;
|
||||||
|
|
||||||
|
@ -309,7 +316,11 @@ void TopBarWidget::showAll() {
|
||||||
_menuToggle->show();
|
_menuToggle->show();
|
||||||
}
|
}
|
||||||
_search->show();
|
_search->show();
|
||||||
_call->setVisible(historyPeer->isUser());
|
auto callsEnabled = false;
|
||||||
|
if (auto user = historyPeer->asUser()) {
|
||||||
|
callsEnabled = Global::PhoneCallsEnabled() && user->hasCalls();
|
||||||
|
}
|
||||||
|
_call->setVisible(callsEnabled);
|
||||||
} else {
|
} else {
|
||||||
_search->hide();
|
_search->hide();
|
||||||
_call->hide();
|
_call->hide();
|
||||||
|
@ -377,7 +388,7 @@ void TopBarWidget::showSelected(SelectedState state) {
|
||||||
if (_canDelete != canDelete || _canForward != canForward) {
|
if (_canDelete != canDelete || _canForward != canForward) {
|
||||||
_canDelete = canDelete;
|
_canDelete = canDelete;
|
||||||
_canForward = canForward;
|
_canForward = canForward;
|
||||||
showAll();
|
updateControlsVisibility();
|
||||||
}
|
}
|
||||||
if (wasSelected != hasSelected) {
|
if (wasSelected != hasSelected) {
|
||||||
setCursor(hasSelected ? style::cur_default : style::cur_pointer);
|
setCursor(hasSelected ? style::cur_default : style::cur_pointer);
|
||||||
|
@ -396,7 +407,7 @@ void TopBarWidget::selectedShowCallback() {
|
||||||
|
|
||||||
void TopBarWidget::updateAdaptiveLayout() {
|
void TopBarWidget::updateAdaptiveLayout() {
|
||||||
updateMembersShowArea();
|
updateMembersShowArea();
|
||||||
showAll();
|
updateControlsVisibility();
|
||||||
if (!Adaptive::OneColumn()) {
|
if (!Adaptive::OneColumn()) {
|
||||||
unsubscribe(base::take(_unreadCounterSubscription));
|
unsubscribe(base::take(_unreadCounterSubscription));
|
||||||
} else if (!_unreadCounterSubscription) {
|
} else if (!_unreadCounterSubscription) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
int canForwardCount = 0;
|
int canForwardCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void showAll();
|
void updateControlsVisibility();
|
||||||
void showSelected(SelectedState state);
|
void showSelected(SelectedState state);
|
||||||
void animationFinished();
|
void animationFinished();
|
||||||
void updateMembersShowArea();
|
void updateMembersShowArea();
|
||||||
|
|
|
@ -54,6 +54,27 @@ MainMenu::MainMenu(QWidget *parent) : TWidget(parent)
|
||||||
_menu->setTriggeredCallback([](QAction *action, int actionTop, Ui::Menu::TriggeredSource source) {
|
_menu->setTriggeredCallback([](QAction *action, int actionTop, Ui::Menu::TriggeredSource source) {
|
||||||
emit action->triggered();
|
emit action->triggered();
|
||||||
});
|
});
|
||||||
|
refreshMenu();
|
||||||
|
|
||||||
|
_telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop")));
|
||||||
|
_telegram->setLink(1, MakeShared<UrlClickHandler>(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<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog")));
|
||||||
|
_version->setLink(2, MakeShared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
|
||||||
|
|
||||||
|
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), [] {
|
_menu->addAction(lang(lng_create_group_title), [] {
|
||||||
App::wnd()->onShowNewGroup();
|
App::wnd()->onShowNewGroup();
|
||||||
}, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver);
|
}, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver);
|
||||||
|
@ -63,9 +84,11 @@ MainMenu::MainMenu(QWidget *parent) : TWidget(parent)
|
||||||
_menu->addAction(lang(lng_menu_contacts), [] {
|
_menu->addAction(lang(lng_menu_contacts), [] {
|
||||||
Ui::show(Box<ContactsBox>());
|
Ui::show(Box<ContactsBox>());
|
||||||
}, &st::mainMenuContacts, &st::mainMenuContactsOver);
|
}, &st::mainMenuContacts, &st::mainMenuContactsOver);
|
||||||
_menu->addAction(lang(lng_menu_calls), [] {
|
if (Global::PhoneCallsEnabled()) {
|
||||||
Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>()));
|
_menu->addAction(lang(lng_menu_calls), [] {
|
||||||
}, &st::mainMenuCalls, &st::mainMenuCallsOver);
|
Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>()));
|
||||||
|
}, &st::mainMenuCalls, &st::mainMenuCallsOver);
|
||||||
|
}
|
||||||
_menu->addAction(lang(lng_menu_settings), [] {
|
_menu->addAction(lang(lng_menu_settings), [] {
|
||||||
App::wnd()->showSettings();
|
App::wnd()->showSettings();
|
||||||
}, &st::mainMenuSettings, &st::mainMenuSettingsOver);
|
}, &st::mainMenuSettings, &st::mainMenuSettingsOver);
|
||||||
|
@ -73,18 +96,6 @@ MainMenu::MainMenu(QWidget *parent) : TWidget(parent)
|
||||||
QDesktopServices::openUrl(telegramFaqLink());
|
QDesktopServices::openUrl(telegramFaqLink());
|
||||||
}, &st::mainMenuHelp, &st::mainMenuHelpOver);
|
}, &st::mainMenuHelp, &st::mainMenuHelpOver);
|
||||||
|
|
||||||
_telegram->setRichText(textcmdLink(1, qsl("Telegram Desktop")));
|
|
||||||
_telegram->setLink(1, MakeShared<UrlClickHandler>(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<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog")));
|
|
||||||
_version->setLink(2, MakeShared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
|
|
||||||
|
|
||||||
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();
|
updatePhone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ private:
|
||||||
void checkSelf();
|
void checkSelf();
|
||||||
void updateControlsGeometry();
|
void updateControlsGeometry();
|
||||||
void updatePhone();
|
void updatePhone();
|
||||||
|
void refreshMenu();
|
||||||
|
|
||||||
object_ptr<Profile::UserpicButton> _userpicButton = { nullptr };
|
object_ptr<Profile::UserpicButton> _userpicButton = { nullptr };
|
||||||
object_ptr<Ui::IconButton> _cloudButton = { nullptr };
|
object_ptr<Ui::IconButton> _cloudButton = { nullptr };
|
||||||
|
|
Loading…
Add table
Reference in a new issue