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

refactor(status): add Blocked status, deduplicate status parsing

Blocked status will represent friends who are removed from Toxcore, but who still exist in UI and can be readded to Toxcore at a future time using their public key. Blocked friends are similar to offline friends, but have a different status icon and will be seperated in the friends list.
This commit is contained in:
Anthony Bilinski 2019-04-11 00:30:37 -07:00
parent 0f5ad725d7
commit ec500b6673
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
14 changed files with 49 additions and 63 deletions

1
img/status/blocked.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><path fill="#FF5A79" d="M32 2C15.432 2 2 15.431 2 32.001 2 48.566 15.432 62 32 62s30-13.434 30-29.999C62 15.431 48.568 2 32 2zm22 30.001c0 4.629-1.434 8.922-3.875 12.466L19.533 13.875A21.896 21.896 0 0 1 32 10c12.15 0 22 9.85 22 22.001zm-44 0c0-4.631 1.434-8.924 3.876-12.468l30.591 30.59A21.887 21.887 0 0 1 32 54c-12.15 0-22-9.851-22-21.999z"/></svg>

After

Width:  |  Height:  |  Size: 435 B

View File

@ -48,7 +48,8 @@ enum class Status
Online = 0,
Away,
Busy,
Offline
Offline,
Blocked
};
class Core;

View File

@ -46,7 +46,7 @@ void FriendChatroom::setActive(bool _active)
bool FriendChatroom::canBeInvited() const
{
return frnd->getStatus() != Status::Offline;
return frnd->isOnline();
}
int FriendChatroom::getCircleId() const

View File

@ -43,7 +43,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->getStatus() != Status::Offline;
const auto canInvite = frnd->isOnline();
if (canInvite) {
Core::getInstance()->groupInviteFriend(friendId, groupId);

View File

@ -164,3 +164,8 @@ Status Friend::getStatus() const
{
return friendStatus;
}
bool Friend::isOnline() const
{
return friendStatus != Status::Offline && friendStatus != Status::Blocked;
}

View File

@ -52,6 +52,7 @@ public:
void setStatus(Status s);
Status getStatus() const;
bool isOnline() const;
signals:
void nameChanged(uint32_t friendId, const QString& name);

View File

@ -102,7 +102,7 @@ void OfflineMsgEngine::deliverOfflineMsgs()
return;
}
if (f->getStatus() == Status::Offline) {
if (!f->isOnline()) {
return;
}

View File

@ -386,13 +386,7 @@ void ContentDialog::updateTitleAndStatusIcon()
}
Status currentStatus = activeChatroomWidget->getFriend()->getStatus();
QMap<Status, QIcon> icons{{Status::Online, QIcon(":/img/status/online.svg")},
{Status::Away, QIcon(":/img/status/away.svg")},
{Status::Busy, QIcon(":/img/status/busy.svg")},
{Status::Offline, QIcon(":/img/status/offline.svg")}};
setWindowIcon(icons[currentStatus]);
setWindowIcon(QIcon{Widget::getStatusIconPath(currentStatus)});
}
/**

View File

@ -75,21 +75,7 @@ namespace
QString statusToString(const Status status)
{
QString result;
switch (status) {
case Status::Online:
result = ChatForm::tr("online", "contact status");
break;
case Status::Away:
result = ChatForm::tr("away", "contact status");
break;
case Status::Busy:
result = ChatForm::tr("busy", "contact status");
break;
case Status::Offline:
result = ChatForm::tr("offline", "contact status");
break;
}
return result;
return ChatForm::tr(Widget::getStatusTitle(status).toLatin1().data(), "contact status");
}
QString secondsToDHMS(quint32 duration)
@ -523,7 +509,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->getStatus() != Status::Offline;
const bool online = f->isOnline();
headWidget->updateCallButtons(online, audio, video);
updateMuteMicButton();
updateMuteVolButton();
@ -639,7 +625,7 @@ void ChatForm::onFriendStatusChanged(uint32_t friendId, Status status)
return;
}
if (status == Status::Offline) {
if (!f->isOnline()) {
// Hide the "is typing" message when a friend goes offline
setFriendTyping(false);
} else {
@ -935,7 +921,7 @@ void ChatForm::sendLoadedMessage(ChatMessage::Ptr chatMsg, MessageMetadata const
ReceiptNum receipt;
bool messageSent{false};
if (f->getStatus() != Status::Offline) {
if (f->isOnline()) {
Core* core = Core::getInstance();
uint32_t friendId = f->getId();
QString stringMsg = chatMsg->toString();
@ -1141,7 +1127,7 @@ void ChatForm::SendMessageStr(QString msg)
ReceiptNum receipt;
bool messageSent{false};
if (f->getStatus() != Status::Offline) {
if (f->isOnline()) {
Core* core = Core::getInstance();
uint32_t friendId = f->getId();
messageSent = isAction ? core->sendAction(friendId, part, receipt) : core->sendMessage(friendId, part, receipt);

View File

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

View File

@ -62,7 +62,7 @@ FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom, bool compac
, isDefaultAvatar{true}
{
avatar->setPixmap(QPixmap(":/img/contact.svg"));
statusPic.setPixmap(QPixmap(":/img/status/offline.svg"));
statusPic.setPixmap(QPixmap(Widget::getStatusIconPath(Status::Offline)));
statusPic.setMargin(3);
auto frnd = chatroom->getFriend();
@ -322,23 +322,9 @@ void FriendWidget::setActive(bool active)
void FriendWidget::updateStatusLight()
{
// clang-format off
static const QString statuses[] = {
":img/status/online.svg",
":img/status/online_notification.svg",
":img/status/away.svg",
":img/status/away_notification.svg",
":img/status/busy.svg",
":img/status/busy_notification.svg",
":img/status/offline.svg",
":img/status/offline_notification.svg",
};
// clang-format on
const auto frnd = chatroom->getFriend();
const bool event = frnd->getEventFlag();
const int index = static_cast<int>(frnd->getStatus()) * 2 + event;
statusPic.setPixmap(QPixmap(statuses[index]));
statusPic.setPixmap(QPixmap(Widget::getStatusIconPath(frnd->getStatus(), event)));
if (event) {
const Settings& s = Settings::getInstance();

View File

@ -39,6 +39,7 @@
#include "src/widget/friendwidget.h"
#include "src/widget/style.h"
#include "src/widget/translator.h"
#include "src/widget/widget.h"
#include "tool/croppinglabel.h"
GroupWidget::GroupWidget(std::shared_ptr<GroupChatroom> chatroom, bool compact)
@ -47,7 +48,7 @@ GroupWidget::GroupWidget(std::shared_ptr<GroupChatroom> chatroom, bool compact)
, chatroom{chatroom}
{
avatar->setPixmap(Style::scaleSvgImage(":img/group.svg", avatar->width(), avatar->height()));
statusPic.setPixmap(QPixmap(":img/status/online.svg"));
statusPic.setPixmap(QPixmap(Widget::getStatusIconPath(Status::Online)));
statusPic.setMargin(3);
Group* g = chatroom->getGroup();
@ -178,13 +179,9 @@ void GroupWidget::updateStatusLight()
{
Group* g = chatroom->getGroup();
if (g->getEventFlag()) {
statusPic.setPixmap(QPixmap(":img/status/online_notification.svg"));
statusPic.setMargin(1);
} else {
statusPic.setPixmap(QPixmap(":img/status/online.svg"));
statusPic.setMargin(3);
}
const bool event = g->getEventFlag();
statusPic.setPixmap(QPixmap(Widget::getStatusIconPath(Status::Online, event)));
statusPic.setMargin(event ? 1 : 3);
}
QString GroupWidget::getStatusString() const

View File

@ -1047,7 +1047,7 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
FriendWidget* widget = friendWidgets[friendId];
if (isActualChange) {
if (f->getStatus() == Status::Offline) {
if (!f->isOnline()) {
contactListWidget->moveWidget(widget, Status::Online);
} else if (status == Status::Offline) {
contactListWidget->moveWidget(widget, Status::Offline);
@ -2194,17 +2194,24 @@ void Widget::previousContact()
cycleContacts(false);
}
QString Widget::getStatusIconPath(Status status)
QString Widget::getStatusIconPath(Status status, bool event)
{
QString eventSuffix{""};
if (event) {
eventSuffix = "_notification";
}
switch (status) {
case Status::Online:
return ":/img/status/online.svg";
return ":/img/status/online" + eventSuffix + ".svg";
case Status::Away:
return ":/img/status/away.svg";
return ":/img/status/away" + eventSuffix + ".svg";
case Status::Busy:
return ":/img/status/busy.svg";
return ":/img/status/busy" + eventSuffix + ".svg";
case Status::Offline:
return ":/img/status/offline.svg";
return ":/img/status/offline" + eventSuffix + ".svg";
case Status::Blocked:
return ":/img/status/blocked.svg";
}
qWarning() << "Status unknown";
assert(false);
@ -2256,6 +2263,8 @@ QString Widget::getStatusTitle(Status status)
return QStringLiteral("busy");
case Status::Offline:
return QStringLiteral("offline");
case Status::Blocked:
return QStringLiteral("blocked");
}
assert(false);
@ -2270,8 +2279,14 @@ Status Widget::getStatusFromString(QString status)
return Status::Away;
else if (status == QStringLiteral("busy"))
return Status::Busy;
else
else if (status == QStringLiteral("offline"))
return Status::Offline;
else if (status == QStringLiteral("blocked"))
return Status::Blocked;
else {
assert(false);
return Status::Offline;
}
}
void Widget::searchContacts()

View File

@ -135,7 +135,7 @@ public:
void reloadHistory();
void reloadTheme();
static QString getStatusIconPath(Status status);
static QString getStatusIconPath(Status status, bool event = false);
static inline QIcon prepareIcon(QString path, int w = 0, int h = 0);
static QPixmap getStatusIconPixmap(QString path, uint32_t w, uint32_t h);
static QString getStatusTitle(Status status);