Skip to content

Commit

Permalink
isJobRunning() -> isJobPending()
Browse files Browse the repository at this point in the history
To be very clear what this function checks. See also #437.
  • Loading branch information
KitsuneRal committed Jan 7, 2021
1 parent aa79040 commit 78a3137
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions lib/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class Avatar::Private {
explicit Private(QUrl url = {}) : _url(move(url)) {}
~Private()
{
if (isJobRunning(_thumbnailRequest))
if (isJobPending(_thumbnailRequest))
_thumbnailRequest->abandon();
if (isJobRunning(_uploadRequest))
if (isJobPending(_uploadRequest))
_uploadRequest->abandon();
}

Expand Down Expand Up @@ -87,15 +87,15 @@ QImage Avatar::get(Connection* connection, int width, int height,
bool Avatar::upload(Connection* connection, const QString& fileName,
upload_callback_t callback) const
{
if (isJobRunning(d->_uploadRequest))
if (isJobPending(d->_uploadRequest))
return false;
return d->upload(connection->uploadFile(fileName), move(callback));
}

bool Avatar::upload(Connection* connection, QIODevice* source,
upload_callback_t callback) const
{
if (isJobRunning(d->_uploadRequest) || !source->isReadable())
if (isJobPending(d->_uploadRequest) || !source->isReadable())
return false;
return d->upload(connection->uploadContent(source), move(callback));
}
Expand Down Expand Up @@ -125,7 +125,7 @@ QImage Avatar::Private::get(Connection* connection, QSize size,
&& checkUrl(_url)) {
qCDebug(MAIN) << "Getting avatar from" << _url.toString();
_requestedSize = size;
if (isJobRunning(_thumbnailRequest))
if (isJobPending(_thumbnailRequest))
_thumbnailRequest->abandon();
if (callback)
callbacks.emplace_back(move(callback));
Expand Down Expand Up @@ -157,7 +157,7 @@ QImage Avatar::Private::get(Connection* connection, QSize size,
bool Avatar::Private::upload(UploadContentJob* job, upload_callback_t &&callback)
{
_uploadRequest = job;
if (!isJobRunning(_uploadRequest))
if (!isJobPending(_uploadRequest))
return false;
_uploadRequest->connect(_uploadRequest, &BaseJob::success, _uploadRequest,
[job, callback] { callback(job->contentUri()); });
Expand Down Expand Up @@ -194,7 +194,7 @@ bool Avatar::updateUrl(const QUrl& newUrl)

d->_url = newUrl;
d->_imageSource = Private::Unknown;
if (isJobRunning(d->_thumbnailRequest))
if (isJobPending(d->_thumbnailRequest))
d->_thumbnailRequest->abandon();
return true;
}
8 changes: 4 additions & 4 deletions lib/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Connection::~Connection()

void Connection::resolveServer(const QString& mxid)
{
if (isJobRunning(d->resolverJob))
if (isJobPending(d->resolverJob))
d->resolverJob->abandon();

auto maybeBaseUrl = QUrl::fromUserInput(serverPart(mxid));
Expand Down Expand Up @@ -1229,7 +1229,7 @@ QByteArray Connection::accessToken() const
{
// The logout job needs access token to do its job; so the token is
// kept inside d->data but no more exposed to the outside world.
return isJobRunning(d->logoutJob) ? QByteArray() : d->data->accessToken();
return isJobPending(d->logoutJob) ? QByteArray() : d->data->accessToken();
}

bool Connection::isLoggedIn() const { return !accessToken().isEmpty(); }
Expand Down Expand Up @@ -1544,10 +1544,10 @@ QByteArray Connection::generateTxnId() const

void Connection::setHomeserver(const QUrl& url)
{
if (isJobRunning(d->resolverJob))
if (isJobPending(d->resolverJob))
d->resolverJob->abandon();
d->resolverJob = nullptr;
if (isJobRunning(d->loginFlowsJob))
if (isJobPending(d->loginFlowsJob))
d->loginFlowsJob->abandon();
d->loginFlowsJob = nullptr;
d->loginFlows.clear();
Expand Down
2 changes: 1 addition & 1 deletion lib/jobs/basejob.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private Q_SLOTS:
QScopedPointer<Private> d;
};

inline bool isJobRunning(BaseJob* job)
inline bool isJobPending(BaseJob* job)
{
return job && job->error() == BaseJob::Pending;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ const Room::RelatedEvents Room::relatedEvents(const RoomEvent& evt,
void Room::Private::getAllMembers()
{
// If already loaded or already loading, there's nothing to do here.
if (q->joinedCount() <= membersMap.size() || isJobRunning(allMembersJob))
if (q->joinedCount() <= membersMap.size() || isJobPending(allMembersJob))
return;

allMembersJob = connection->callApi<GetMembersByRoomJob>(
Expand Down Expand Up @@ -1685,7 +1685,7 @@ QString Room::retryMessage(const QString& txnId)
<< "File for transaction" << txnId
<< "has already been uploaded, bypassing re-upload";
} else {
if (isJobRunning(transferIt->job)) {
if (isJobPending(transferIt->job)) {
qCDebug(MESSAGES) << "Abandoning the upload job for transaction"
<< txnId << "and starting again";
transferIt->job->abandon();
Expand Down Expand Up @@ -1718,7 +1718,7 @@ void Room::discardMessage(const QString& txnId)
const auto& transferIt = d->fileTransfers.find(txnId);
if (transferIt != d->fileTransfers.end()) {
Q_ASSERT(transferIt->isUpload);
if (isJobRunning(transferIt->job)) {
if (isJobPending(transferIt->job)) {
transferIt->status = FileTransferInfo::Cancelled;
transferIt->job->abandon();
emit fileTransferFailed(txnId, tr("File upload cancelled"));
Expand Down Expand Up @@ -1924,7 +1924,7 @@ void Room::getPreviousContent(int limit, const QString &filter) { d->getPrevious

void Room::Private::getPreviousContent(int limit, const QString &filter)
{
if (isJobRunning(eventsHistoryJob))
if (isJobPending(eventsHistoryJob))
return;

eventsHistoryJob =
Expand Down Expand Up @@ -1977,7 +1977,7 @@ void Room::uploadFile(const QString& id, const QUrl& localFilename,
"localFilename should point at a local file");
auto fileName = localFilename.toLocalFile();
auto job = connection()->uploadFile(fileName, overrideContentType);
if (isJobRunning(job)) {
if (isJobPending(job)) {
d->fileTransfers[id] = { job, fileName, true };
connect(job, &BaseJob::uploadProgress, this,
[this, id](qint64 sent, qint64 total) {
Expand Down Expand Up @@ -2033,7 +2033,7 @@ void Room::downloadFile(const QString& eventId, const QUrl& localFilename)
qDebug(MAIN) << "File path:" << filePath;
}
auto job = connection()->downloadFile(fileUrl, filePath);
if (isJobRunning(job)) {
if (isJobPending(job)) {
// If there was a previous transfer (completed or failed), overwrite it.
d->fileTransfers[eventId] = { job, job->targetFileName() };
connect(job, &BaseJob::downloadProgress, this,
Expand Down Expand Up @@ -2061,7 +2061,7 @@ void Room::cancelFileTransfer(const QString& id)
<< d->id;
return;
}
if (isJobRunning(it->job))
if (isJobPending(it->job))
it->job->abandon();
d->fileTransfers.remove(id);
emit fileTransferCancelled(id);
Expand Down

0 comments on commit 78a3137

Please sign in to comment.