diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 82412ecce..8905c65bb 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -115,6 +115,7 @@ ChatForm::ChatForm(Friend* chatFriend) connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered); connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged); connect(core, &Core::fileSendFailed, this, &ChatForm::onFileSendFailed); + connect(core, &Core::friendStatusChanged, this, &ChatForm::onFriendStatusChanged); connect(this, &ChatForm::chatAreaCleared, getOfflineMsgEngine(), &OfflineMsgEngine::removeAllReceipts); connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this, [&](const QPoint& pos) { @@ -521,13 +522,10 @@ void ChatForm::enableCallButtons() disableCallButtonsTimer->start(1500); // 1.5sec qDebug() << "timer started!!"; } - } void ChatForm::disableCallButtons() { - qDebug() << "disableCallButtons"; - // Prevents race enable / disable / onEnable, when it should be disabled if (disableCallButtonsTimer) { @@ -557,7 +555,6 @@ void ChatForm::disableCallButtons() void ChatForm::onEnableCallButtons() { - qDebug() << "onEnableCallButtons"; audioInputFlag = false; audioOutputFlag = false; @@ -573,9 +570,12 @@ void ChatForm::onEnableCallButtons() connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered())); - disableCallButtonsTimer->stop(); - delete disableCallButtonsTimer; - disableCallButtonsTimer = nullptr; + if (disableCallButtonsTimer != nullptr) + { + disableCallButtonsTimer->stop(); + delete disableCallButtonsTimer; + disableCallButtonsTimer = nullptr; + } } void ChatForm::onMicMuteToggle() @@ -626,6 +626,15 @@ void ChatForm::onFileSendFailed(uint32_t FriendId, const QString &fname) addSystemInfoMessage(tr("Failed to send file \"%1\"").arg(fname), ChatMessage::ERROR, QDateTime::currentDateTime()); } +void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status) +{ + // Disable call buttons if friend is offline + if(friendId == f->getFriendID() && status == Status::Offline) + disableCallButtons(); + else + onEnableCallButtons(); +} + void ChatForm::onAvatarChange(uint32_t FriendId, const QPixmap &pic) { if (FriendId != f->getFriendID()) @@ -931,6 +940,12 @@ void ChatForm::show(ContentLayout* contentLayout) { GenericChatForm::show(contentLayout); + // Disable call buttons if friend is offline + if(f->getStatus() == Status::Offline) + disableCallButtons(); + else + onEnableCallButtons(); + if (callConfirm) callConfirm->show(); } diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index a3f2f90fc..37569bc56 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -79,6 +79,7 @@ private slots: void onMicMuteToggle(); void onVolMuteToggle(); void onFileSendFailed(uint32_t FriendId, const QString &fname); + void onFriendStatusChanged(uint32_t friendId, Status status); void onLoadHistory(); void onUpdateTime(); void onEnableCallButtons();