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:
John Preston 2017-04-28 20:16:14 +03:00
parent f4911431d5
commit 30d000e139
18 changed files with 134 additions and 44 deletions

View File

@ -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);

View File

@ -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*> delegate, gsl::not_null<UserData*> 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<Endpoint> 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.

View File

@ -132,7 +132,9 @@ private:
bool _finishAfterRequestingCall = false;
base::Observable<State> _stateChanged;
TimeMs _startTime = 0;
base::DelayedCallTimer _hangupByTimeoutTimer;
base::DelayedCallTimer _finishByTimeoutTimer;
base::Timer _discardByTimeoutTimer;
bool _mute = false;
base::Observable<bool> _muteChanged;

View File

@ -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);

View File

@ -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<void> 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<void>, PhoneCallsEnabledChanged);
DefineVar(Global, HiddenPinnedMessagesMap, HiddenPinnedMessages);

View File

@ -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<void>, PhoneCallsEnabledChanged);
typedef QMap<PeerId, MsgId> HiddenPinnedMessagesMap;
DeclareVar(HiddenPinnedMessagesMap, HiddenPinnedMessages);

View File

@ -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());

View File

@ -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)) {

View File

@ -402,6 +402,11 @@ void Messenger::startLocalStorage() {
}
}
});
subscribe(authSessionChanged(), [this] {
if (_mtproto) {
_mtproto->configLoadRequest();
}
});
}
void Messenger::regPhotoUpdate(const PeerId &peer, const FullMsgId &msgId) {

View File

@ -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();

View File

@ -59,6 +59,7 @@ struct PeerUpdate {
UserOnlineChanged = 0x00200000U,
BotCanAddToGroups = 0x00400000U,
UserCommonChatsChanged = 0x00800000U,
UserHasCalls = 0x01000000U,
// For chats
ChatCanEdit = 0x00010000U,

View File

@ -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);

View File

@ -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;

View File

@ -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<PhotoData*> 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;

View File

@ -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<Window::Controller*> 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) {

View File

@ -46,7 +46,7 @@ public:
int canForwardCount = 0;
};
void showAll();
void updateControlsVisibility();
void showSelected(SelectedState state);
void animationFinished();
void updateMembersShowArea();

View File

@ -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<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), [] {
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<ContactsBox>());
}, &st::mainMenuContacts, &st::mainMenuContactsOver);
_menu->addAction(lang(lng_menu_calls), [] {
Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>()));
}, &st::mainMenuCalls, &st::mainMenuCallsOver);
if (Global::PhoneCallsEnabled()) {
_menu->addAction(lang(lng_menu_calls), [] {
Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>()));
}, &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<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();
}

View File

@ -49,6 +49,7 @@ private:
void checkSelf();
void updateControlsGeometry();
void updatePhone();
void refreshMenu();
object_ptr<Profile::UserpicButton> _userpicButton = { nullptr };
object_ptr<Ui::IconButton> _cloudButton = { nullptr };