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:
parent
05064771ab
commit
239dfdc65c
|
@ -22,6 +22,7 @@
|
|||
#include "src/model/dialogs/idialogsmanager.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/model/group.h"
|
||||
#include "src/model/status.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/widget/contentdialog.h"
|
||||
|
||||
|
@ -67,7 +68,7 @@ void FriendChatroom::setActive(bool _active)
|
|||
|
||||
bool FriendChatroom::canBeInvited() const
|
||||
{
|
||||
return frnd->isOnline();
|
||||
return Status::isOnline(frnd->getStatus());
|
||||
}
|
||||
|
||||
int FriendChatroom::getCircleId() const
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "src/model/dialogs/idialogsmanager.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/model/group.h"
|
||||
#include "src/model/status.h"
|
||||
#include "src/persistence/settings.h"
|
||||
|
||||
GroupChatroom::GroupChatroom(Group* group, IDialogsManager* dialogsManager)
|
||||
|
@ -64,7 +65,7 @@ void GroupChatroom::inviteFriend(const ToxPk& pk)
|
|||
const Friend* frnd = FriendList::findFriend(pk);
|
||||
const auto friendId = frnd->getId();
|
||||
const auto groupId = group->getId();
|
||||
const auto canInvite = frnd->isOnline();
|
||||
const auto canInvite = Status::isOnline(frnd->getStatus());
|
||||
|
||||
if (canInvite) {
|
||||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||
|
|
|
@ -162,11 +162,6 @@ Status::Status Friend::getStatus() const
|
|||
return friendStatus;
|
||||
}
|
||||
|
||||
bool Friend::isOnline() const
|
||||
{
|
||||
return friendStatus != Status::Status::Offline && friendStatus != Status::Status::Blocked;
|
||||
}
|
||||
|
||||
bool Friend::useHistory() const
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -53,8 +53,6 @@ public:
|
|||
|
||||
void setStatus(Status::Status s);
|
||||
Status::Status getStatus() const;
|
||||
bool isOnline() const;
|
||||
|
||||
bool useHistory() const override final;
|
||||
|
||||
signals:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "friendmessagedispatcher.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/model/status.h"
|
||||
|
||||
|
||||
namespace {
|
||||
|
@ -69,7 +70,7 @@ FriendMessageDispatcher::sendMessage(bool isAction, const QString& content)
|
|||
|
||||
bool messageSent = false;
|
||||
|
||||
if (f.isOnline()) {
|
||||
if (Status::isOnline(f.getStatus())) {
|
||||
messageSent = sendMessageToCore(messageSender, f, message, receipt);
|
||||
}
|
||||
|
||||
|
@ -109,7 +110,7 @@ void FriendMessageDispatcher::onReceiptReceived(ReceiptNum receipt)
|
|||
*/
|
||||
void FriendMessageDispatcher::onFriendStatusChange(const ToxPk&, Status::Status)
|
||||
{
|
||||
if (f.isOnline()) {
|
||||
if (Status::isOnline(f.getStatus())) {
|
||||
offlineMsgEngine.deliverOfflineMsgs();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,4 +75,9 @@ namespace Status
|
|||
return ":/img/status/" + statusSuffix + eventSuffix + ".svg";
|
||||
}
|
||||
}
|
||||
|
||||
bool isOnline(Status status)
|
||||
{
|
||||
return status != Status::Offline && status != Status::Blocked;
|
||||
}
|
||||
} // namespace Status
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace Status
|
|||
QString getIconPath(Status status, bool event = false);
|
||||
QString getTitle(Status status);
|
||||
QString getAssetSuffix(Status status);
|
||||
bool isOnline(Status status);
|
||||
}
|
||||
|
||||
#endif // STATUS_H
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "src/nexus.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/model/status.h"
|
||||
#include <QMutexLocker>
|
||||
#include <QTimer>
|
||||
#include <QCoreApplication>
|
||||
|
@ -91,7 +92,7 @@ void OfflineMsgEngine::deliverOfflineMsgs()
|
|||
{
|
||||
QMutexLocker ml(&mutex);
|
||||
|
||||
if (!f->isOnline()) {
|
||||
if (!Status::isOnline(f->getStatus())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -404,7 +404,7 @@ void ChatForm::updateCallButtons()
|
|||
CoreAV* av = Core::getInstance()->getAv();
|
||||
const bool audio = av->isCallActive(f);
|
||||
const bool video = av->isCallVideoEnabled(f);
|
||||
const bool online = f->isOnline();
|
||||
const bool online = Status::isOnline(f->getStatus());
|
||||
headWidget->updateCallButtons(online, audio, video);
|
||||
updateMuteMicButton();
|
||||
updateMuteVolButton();
|
||||
|
@ -431,7 +431,7 @@ void ChatForm::onFriendStatusChanged(uint32_t friendId, Status::Status status)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!f->isOnline()) {
|
||||
if (!Status::isOnline(f->getStatus())) {
|
||||
// Hide the "is typing" message when a friend goes offline
|
||||
setFriendTyping(false);
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ void GroupChatForm::dropEvent(QDropEvent* ev)
|
|||
|
||||
int friendId = frnd->getId();
|
||||
int groupId = group->getId();
|
||||
if (frnd->isOnline()) {
|
||||
if (Status::isOnline(frnd->getStatus())) {
|
||||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1231,7 +1231,7 @@ void Widget::onFriendStatusChanged(int friendId, Status::Status status)
|
|||
|
||||
FriendWidget* widget = friendWidgets[f->getPublicKey()];
|
||||
if (isActualChange) {
|
||||
if (!f->isOnline()) {
|
||||
if (!Status::isOnline(f->getStatus())) {
|
||||
contactListWidget->moveWidget(widget, Status::Status::Online);
|
||||
} else if (status == Status::Status::Offline) {
|
||||
contactListWidget->moveWidget(widget, Status::Status::Offline);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "src/core/core.h"
|
||||
#include "src/model/friend.h"
|
||||
#include "src/model/status.h"
|
||||
#include "src/persistence/offlinemsgengine.h"
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
}
|
||||
bool sendMessage(uint32_t friendId, const QString& message, ReceiptNum& receipt) override
|
||||
{
|
||||
if (f->isOnline()) {
|
||||
if (Status::isOnline(f->getStatus())) {
|
||||
receipt.get() = receiptNum++;
|
||||
if (!dropReceipts) {
|
||||
msgs.push_back(message);
|
||||
|
@ -45,7 +46,7 @@ public:
|
|||
} else {
|
||||
numMessagesFailed++;
|
||||
}
|
||||
return f->isOnline();
|
||||
return Status::isOnline(f->getStatus());
|
||||
}
|
||||
|
||||
signals:
|
||||
|
|
Loading…
Reference in New Issue
Block a user