Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <blackslayer4@gmail.com>
  • Loading branch information
allexzander committed Sep 12, 2023
1 parent 472d3e1 commit 474233d
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions src/gui/tray/sortedactivitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,34 @@
*/

#include "activitylistmodel.h"
#include <QVector>

#include "sortedactivitylistmodel.h"

namespace
{
struct ActivityLinksSearchResult {
bool hasPOST = false;
bool hasREPLY = false;
bool hasWEB = false;
};

ActivityLinksSearchResult searchForVerbsInLinks(const QVector<OCC::ActivityLink> &links)
{
ActivityLinksSearchResult result;
for (const auto &link : links) {
if (link._verb == QByteArrayLiteral("POST")) {
result.hasPOST = true;
} else if (link._verb == QByteArrayLiteral("REPLY")) {
result.hasREPLY = true;
} else if (link._verb == QByteArrayLiteral("WEB")) {
result.hasWEB = true;
}
}
return result;
}
}

namespace OCC {

SortedActivityListModel::SortedActivityListModel(QObject *parent)
Expand Down Expand Up @@ -74,50 +99,24 @@ bool SortedActivityListModel::lessThan(const QModelIndex &sourceLeft, const QMod
return leftIsErrorFileItemStatus;
}

auto leftActivityNeedsPostInteraction = false;
auto rightActivityNeedsPostInteraction = false;

auto leftActivityNeedsReplyInteraction = false;
auto rightActivityNeedsReplyInteraction = false;

auto leftActivityNeedsWebInteraction = false;
auto rightActivityNeedsWebInteraction = false;

for (const auto &link : leftActivity._links) {
if (link._verb == QByteArrayLiteral("POST")) {
leftActivityNeedsPostInteraction = true;
} else if (link._verb == QByteArrayLiteral("REPLY")) {
leftActivityNeedsReplyInteraction = true;
} else if (link._verb == QByteArrayLiteral("WEB")) {
leftActivityNeedsWebInteraction = true;
}
}

for (const auto &link : rightActivity._links) {
if (link._verb == QByteArrayLiteral("POST")) {
rightActivityNeedsPostInteraction = true;
} else if (link._verb == QByteArrayLiteral("REPLY")) {
rightActivityNeedsReplyInteraction = true;
} else if (link._verb == QByteArrayLiteral("WEB")) {
rightActivityNeedsWebInteraction = true;
}
}
const auto leftActiviyVerbsSearchResult = searchForVerbsInLinks(leftActivity._links);
const auto rightActiviyVerbsSearchResult = searchForVerbsInLinks(rightActivity._links);

if (leftActivityNeedsPostInteraction && !rightActivityNeedsPostInteraction) {
if (leftActiviyVerbsSearchResult.hasPOST && !rightActiviyVerbsSearchResult.hasPOST) {
return true;
} else if (!leftActivityNeedsPostInteraction && rightActivityNeedsPostInteraction) {
} else if (!leftActiviyVerbsSearchResult.hasPOST && leftActiviyVerbsSearchResult.hasPOST) {
return false;
}

if (leftActivityNeedsReplyInteraction && !rightActivityNeedsReplyInteraction) {
if (leftActiviyVerbsSearchResult.hasREPLY && !leftActiviyVerbsSearchResult.hasREPLY) {
return true;
} else if (!leftActivityNeedsReplyInteraction && rightActivityNeedsReplyInteraction) {
} else if (!leftActiviyVerbsSearchResult.hasREPLY && leftActiviyVerbsSearchResult.hasREPLY) {
return false;
}

if (leftActivityNeedsWebInteraction && !rightActivityNeedsWebInteraction) {
if (leftActiviyVerbsSearchResult.hasWEB && !leftActiviyVerbsSearchResult.hasWEB) {
return true;
} else if (!leftActivityNeedsWebInteraction && rightActivityNeedsWebInteraction) {
} else if (!leftActiviyVerbsSearchResult.hasWEB && leftActiviyVerbsSearchResult.hasWEB) {
return false;
}

Expand Down

0 comments on commit 474233d

Please sign in to comment.