Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(chatform): Disable call buttons if friend is offline
Browse files Browse the repository at this point in the history
Call buttons would be enabled but non-functional if you were looking at a friend who was offline. We now check if the friend is offline and disable the call buttons if so.
  • Loading branch information
anoadragon453 committed Jul 4, 2016
1 parent 2c49ada commit bbefe01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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)
{
Expand Down Expand Up @@ -516,13 +517,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)
{
Expand Down Expand Up @@ -552,7 +550,6 @@ void ChatForm::disableCallButtons()

void ChatForm::onEnableCallButtons()
{
qDebug() << "onEnableCallButtons";
audioInputFlag = false;
audioOutputFlag = false;

Expand All @@ -568,9 +565,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()
Expand Down Expand Up @@ -621,6 +621,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())
Expand Down Expand Up @@ -916,6 +925,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();
}
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/chatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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();
Expand Down

0 comments on commit bbefe01

Please sign in to comment.