1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(status): move isOnline into Status from Friend

Allows checking if a status if equivalent to Online without needing a Friend
class.
This commit is contained in:
Anthony Bilinski 2019-11-16 18:06:33 -08:00
parent 05064771ab
commit 239dfdc65c
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
12 changed files with 22 additions and 18 deletions

View File

@ -22,6 +22,7 @@
#include "src/model/dialogs/idialogsmanager.h" #include "src/model/dialogs/idialogsmanager.h"
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/group.h" #include "src/model/group.h"
#include "src/model/status.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/widget/contentdialog.h" #include "src/widget/contentdialog.h"
@ -67,7 +68,7 @@ void FriendChatroom::setActive(bool _active)
bool FriendChatroom::canBeInvited() const bool FriendChatroom::canBeInvited() const
{ {
return frnd->isOnline(); return Status::isOnline(frnd->getStatus());
} }
int FriendChatroom::getCircleId() const int FriendChatroom::getCircleId() const

View File

@ -25,6 +25,7 @@
#include "src/model/dialogs/idialogsmanager.h" #include "src/model/dialogs/idialogsmanager.h"
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/group.h" #include "src/model/group.h"
#include "src/model/status.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
GroupChatroom::GroupChatroom(Group* group, IDialogsManager* dialogsManager) GroupChatroom::GroupChatroom(Group* group, IDialogsManager* dialogsManager)
@ -64,7 +65,7 @@ void GroupChatroom::inviteFriend(const ToxPk& pk)
const Friend* frnd = FriendList::findFriend(pk); const Friend* frnd = FriendList::findFriend(pk);
const auto friendId = frnd->getId(); const auto friendId = frnd->getId();
const auto groupId = group->getId(); const auto groupId = group->getId();
const auto canInvite = frnd->isOnline(); const auto canInvite = Status::isOnline(frnd->getStatus());
if (canInvite) { if (canInvite) {
Core::getInstance()->groupInviteFriend(friendId, groupId); Core::getInstance()->groupInviteFriend(friendId, groupId);

View File

@ -162,11 +162,6 @@ Status::Status Friend::getStatus() const
return friendStatus; return friendStatus;
} }
bool Friend::isOnline() const
{
return friendStatus != Status::Status::Offline && friendStatus != Status::Status::Blocked;
}
bool Friend::useHistory() const bool Friend::useHistory() const
{ {
return true; return true;

View File

@ -53,8 +53,6 @@ public:
void setStatus(Status::Status s); void setStatus(Status::Status s);
Status::Status getStatus() const; Status::Status getStatus() const;
bool isOnline() const;
bool useHistory() const override final; bool useHistory() const override final;
signals: signals:

View File

@ -19,6 +19,7 @@
#include "friendmessagedispatcher.h" #include "friendmessagedispatcher.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/model/status.h"
namespace { namespace {
@ -69,7 +70,7 @@ FriendMessageDispatcher::sendMessage(bool isAction, const QString& content)
bool messageSent = false; bool messageSent = false;
if (f.isOnline()) { if (Status::isOnline(f.getStatus())) {
messageSent = sendMessageToCore(messageSender, f, message, receipt); messageSent = sendMessageToCore(messageSender, f, message, receipt);
} }
@ -109,7 +110,7 @@ void FriendMessageDispatcher::onReceiptReceived(ReceiptNum receipt)
*/ */
void FriendMessageDispatcher::onFriendStatusChange(const ToxPk&, Status::Status) void FriendMessageDispatcher::onFriendStatusChange(const ToxPk&, Status::Status)
{ {
if (f.isOnline()) { if (Status::isOnline(f.getStatus())) {
offlineMsgEngine.deliverOfflineMsgs(); offlineMsgEngine.deliverOfflineMsgs();
} }
} }

View File

@ -75,4 +75,9 @@ namespace Status
return ":/img/status/" + statusSuffix + eventSuffix + ".svg"; return ":/img/status/" + statusSuffix + eventSuffix + ".svg";
} }
} }
bool isOnline(Status status)
{
return status != Status::Offline && status != Status::Blocked;
}
} // namespace Status } // namespace Status

View File

@ -38,6 +38,7 @@ namespace Status
QString getIconPath(Status status, bool event = false); QString getIconPath(Status status, bool event = false);
QString getTitle(Status status); QString getTitle(Status status);
QString getAssetSuffix(Status status); QString getAssetSuffix(Status status);
bool isOnline(Status status);
} }
#endif // STATUS_H #endif // STATUS_H

View File

@ -23,6 +23,7 @@
#include "src/nexus.h" #include "src/nexus.h"
#include "src/persistence/profile.h" #include "src/persistence/profile.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/model/status.h"
#include <QMutexLocker> #include <QMutexLocker>
#include <QTimer> #include <QTimer>
#include <QCoreApplication> #include <QCoreApplication>
@ -91,7 +92,7 @@ void OfflineMsgEngine::deliverOfflineMsgs()
{ {
QMutexLocker ml(&mutex); QMutexLocker ml(&mutex);
if (!f->isOnline()) { if (!Status::isOnline(f->getStatus())) {
return; return;
} }

View File

@ -404,7 +404,7 @@ void ChatForm::updateCallButtons()
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = Core::getInstance()->getAv();
const bool audio = av->isCallActive(f); const bool audio = av->isCallActive(f);
const bool video = av->isCallVideoEnabled(f); const bool video = av->isCallVideoEnabled(f);
const bool online = f->isOnline(); const bool online = Status::isOnline(f->getStatus());
headWidget->updateCallButtons(online, audio, video); headWidget->updateCallButtons(online, audio, video);
updateMuteMicButton(); updateMuteMicButton();
updateMuteVolButton(); updateMuteVolButton();
@ -431,7 +431,7 @@ void ChatForm::onFriendStatusChanged(uint32_t friendId, Status::Status status)
return; return;
} }
if (!f->isOnline()) { if (!Status::isOnline(f->getStatus())) {
// Hide the "is typing" message when a friend goes offline // Hide the "is typing" message when a friend goes offline
setFriendTyping(false); setFriendTyping(false);
} }

View File

@ -307,7 +307,7 @@ void GroupChatForm::dropEvent(QDropEvent* ev)
int friendId = frnd->getId(); int friendId = frnd->getId();
int groupId = group->getId(); int groupId = group->getId();
if (frnd->isOnline()) { if (Status::isOnline(frnd->getStatus())) {
Core::getInstance()->groupInviteFriend(friendId, groupId); Core::getInstance()->groupInviteFriend(friendId, groupId);
} }
} }

View File

@ -1231,7 +1231,7 @@ void Widget::onFriendStatusChanged(int friendId, Status::Status status)
FriendWidget* widget = friendWidgets[f->getPublicKey()]; FriendWidget* widget = friendWidgets[f->getPublicKey()];
if (isActualChange) { if (isActualChange) {
if (!f->isOnline()) { if (!Status::isOnline(f->getStatus())) {
contactListWidget->moveWidget(widget, Status::Status::Online); contactListWidget->moveWidget(widget, Status::Status::Online);
} else if (status == Status::Status::Offline) { } else if (status == Status::Status::Offline) {
contactListWidget->moveWidget(widget, Status::Status::Offline); contactListWidget->moveWidget(widget, Status::Status::Offline);

View File

@ -19,6 +19,7 @@
#include "src/core/core.h" #include "src/core/core.h"
#include "src/model/friend.h" #include "src/model/friend.h"
#include "src/model/status.h"
#include "src/persistence/offlinemsgengine.h" #include "src/persistence/offlinemsgengine.h"
#include <QtTest/QtTest> #include <QtTest/QtTest>
@ -35,7 +36,7 @@ public:
} }
bool sendMessage(uint32_t friendId, const QString& message, ReceiptNum& receipt) override bool sendMessage(uint32_t friendId, const QString& message, ReceiptNum& receipt) override
{ {
if (f->isOnline()) { if (Status::isOnline(f->getStatus())) {
receipt.get() = receiptNum++; receipt.get() = receiptNum++;
if (!dropReceipts) { if (!dropReceipts) {
msgs.push_back(message); msgs.push_back(message);
@ -45,7 +46,7 @@ public:
} else { } else {
numMessagesFailed++; numMessagesFailed++;
} }
return f->isOnline(); return Status::isOnline(f->getStatus());
} }
signals: signals: