2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Add "line busy" call state with a redial button.

This commit is contained in:
John Preston
2017-04-29 21:00:27 +03:00
parent d5ff728da6
commit f42f79ea95
8 changed files with 109 additions and 30 deletions

View File

@@ -78,9 +78,10 @@ Call::Call(gsl::not_null<Delegate*> delegate, gsl::not_null<UserData*> user, Typ
: _delegate(delegate)
, _user(user)
, _type(type) {
_discardByTimeoutTimer.setCallback([this] { hangup(); });
if (_type == Type::Outgoing) {
setState(State::Requesting);
_discardByTimeoutTimer.setCallback([this] { hangup(); });
}
}
@@ -198,11 +199,26 @@ TimeMs Call::getDurationMs() const {
}
void Call::hangup() {
auto missed = (_state == State::Ringing || (_state == State::Waiting && _type == Type::Outgoing));
auto declined = (_state == State::WaitingIncoming);
auto reason = missed ? MTP_phoneCallDiscardReasonMissed() :
declined ? MTP_phoneCallDiscardReasonBusy() : MTP_phoneCallDiscardReasonHangup();
finish(reason);
if (_state == State::Busy) {
// Cancel call instead of redial.
setState(Call::Ended);
} else {
auto missed = (_state == State::Ringing || (_state == State::Waiting && _type == Type::Outgoing));
auto declined = (_state == State::WaitingIncoming);
auto reason = missed ? MTP_phoneCallDiscardReasonMissed() :
declined ? MTP_phoneCallDiscardReasonBusy() : MTP_phoneCallDiscardReasonHangup();
finish(reason);
}
}
void Call::redial() {
if (_state != State::Busy) {
return;
}
t_assert(_controller == nullptr);
_type = Type::Outgoing;
setState(State::Requesting);
_delegate->callRedial(this);
}
bool Call::isKeyShaForFingerprintReady() const {
@@ -490,8 +506,7 @@ void Call::setState(State state) {
_delegate->callFailed(this);
break;
case State::Busy:
setState(State::Ended);
// _hangupByTimeoutTimer.call(kHangupTimeoutMs, [this] { setState(State::Ended); });
destroyController();
// TODO play sound
break;
}
@@ -552,7 +567,7 @@ void Call::handleControllerError(int error) {
setState(State::Failed);
}
Call::~Call() {
void Call::destroyController() {
if (_controller) {
DEBUG_LOG(("Call Info: Destroying call controller.."));
_controller.reset();
@@ -560,6 +575,10 @@ Call::~Call() {
}
}
Call::~Call() {
destroyController();
}
void UpdateConfig(const std::map<std::string, std::string> &data) {
tgvoip::ServerConfig::GetSharedInstance()->Update(data);
}