aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp23
-rw-r--r--lib/connection.h38
2 files changed, 30 insertions, 31 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 6babcf27..1c63adeb 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -723,7 +723,7 @@ void Connection::stopSync()
QString Connection::nextBatchToken() const { return d->data->lastEvent(); }
-PostReceiptJob* Connection::postReceipt(Room* room, RoomEvent* event) const
+PostReceiptJob* Connection::postReceipt(Room* room, RoomEvent* event)
{
return callApi<PostReceiptJob>(room->id(), "m.read", event->id());
}
@@ -773,7 +773,7 @@ inline auto splitMediaId(const QString& mediaId)
MediaThumbnailJob* Connection::getThumbnail(const QString& mediaId,
QSize requestedSize,
- RunningPolicy policy) const
+ RunningPolicy policy)
{
auto idParts = splitMediaId(mediaId);
return callApi<MediaThumbnailJob>(policy, idParts.front(), idParts.back(),
@@ -781,21 +781,21 @@ MediaThumbnailJob* Connection::getThumbnail(const QString& mediaId,
}
MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, QSize requestedSize,
- RunningPolicy policy) const
+ RunningPolicy policy)
{
return getThumbnail(url.authority() + url.path(), requestedSize, policy);
}
MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, int requestedWidth,
int requestedHeight,
- RunningPolicy policy) const
+ RunningPolicy policy)
{
return getThumbnail(url, QSize(requestedWidth, requestedHeight), policy);
}
UploadContentJob*
Connection::uploadContent(QIODevice* contentSource, const QString& filename,
- const QString& overrideContentType) const
+ const QString& overrideContentType)
{
Q_ASSERT(contentSource != nullptr);
auto contentType = overrideContentType;
@@ -820,19 +820,19 @@ UploadContentJob* Connection::uploadFile(const QString& fileName,
overrideContentType);
}
-GetContentJob* Connection::getContent(const QString& mediaId) const
+GetContentJob* Connection::getContent(const QString& mediaId)
{
auto idParts = splitMediaId(mediaId);
return callApi<GetContentJob>(idParts.front(), idParts.back());
}
-GetContentJob* Connection::getContent(const QUrl& url) const
+GetContentJob* Connection::getContent(const QUrl& url)
{
return getContent(url.authority() + url.path());
}
DownloadFileJob* Connection::downloadFile(const QUrl& url,
- const QString& localFilename) const
+ const QString& localFilename)
{
auto mediaId = url.authority() + url.path();
auto idParts = splitMediaId(mediaId);
@@ -1011,7 +1011,7 @@ ForgetRoomJob* Connection::forgetRoom(const QString& id)
SendToDeviceJob*
Connection::sendToDevices(const QString& eventType,
- const UsersToDevicesToEvents& eventsMap) const
+ const UsersToDevicesToEvents& eventsMap)
{
QHash<QString, QHash<QString, QJsonObject>> json;
json.reserve(int(eventsMap.size()));
@@ -1032,7 +1032,7 @@ Connection::sendToDevices(const QString& eventType,
}
SendMessageJob* Connection::sendMessage(const QString& roomId,
- const RoomEvent& event) const
+ const RoomEvent& event)
{
const auto txnId = event.transactionId().isEmpty() ? generateTxnId()
: event.transactionId();
@@ -1609,8 +1609,9 @@ void Connection::setLazyLoading(bool newValue)
}
}
-void Connection::run(BaseJob* job, RunningPolicy runningPolicy) const
+void Connection::run(BaseJob* job, RunningPolicy runningPolicy)
{
+ job->setParent(this); // Protects from #397, #398
connect(job, &BaseJob::failure, this, &Connection::requestFailed);
job->initiate(d->data.get(), runningPolicy & BackgroundRequest);
}
diff --git a/lib/connection.h b/lib/connection.h
index 350571f1..b0263732 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -423,7 +423,7 @@ public:
void setLazyLoading(bool newValue);
/*! Start a pre-created job object on this connection */
- void run(BaseJob* job, RunningPolicy runningPolicy = ForegroundRequest) const;
+ void run(BaseJob* job, RunningPolicy runningPolicy = ForegroundRequest);
/*! Start a job of a specified type with specified arguments and policy
*
@@ -438,7 +438,7 @@ public:
* \sa BaseJob::isBackground. QNetworkRequest::BackgroundRequestAttribute
*/
template <typename JobT, typename... JobArgTs>
- JobT* callApi(RunningPolicy runningPolicy, JobArgTs&&... jobArgs) const
+ JobT* callApi(RunningPolicy runningPolicy, JobArgTs&&... jobArgs)
{
auto job = new JobT(std::forward<JobArgTs>(jobArgs)...);
run(job, runningPolicy);
@@ -450,7 +450,7 @@ public:
* This is an overload that runs the job with "foreground" policy.
*/
template <typename JobT, typename... JobArgTs>
- JobT* callApi(JobArgTs&&... jobArgs) const
+ JobT* callApi(JobArgTs&&... jobArgs)
{
return callApi<JobT>(ForegroundRequest,
std::forward<JobArgTs>(jobArgs)...);
@@ -544,25 +544,24 @@ public slots:
virtual MediaThumbnailJob*
getThumbnail(const QString& mediaId, QSize requestedSize,
- RunningPolicy policy = BackgroundRequest) const;
- MediaThumbnailJob*
- getThumbnail(const QUrl& url, QSize requestedSize,
- RunningPolicy policy = BackgroundRequest) const;
- MediaThumbnailJob*
- getThumbnail(const QUrl& url, int requestedWidth, int requestedHeight,
- RunningPolicy policy = BackgroundRequest) const;
+ RunningPolicy policy = BackgroundRequest);
+ MediaThumbnailJob* getThumbnail(const QUrl& url, QSize requestedSize,
+ RunningPolicy policy = BackgroundRequest);
+ MediaThumbnailJob* getThumbnail(const QUrl& url, int requestedWidth,
+ int requestedHeight,
+ RunningPolicy policy = BackgroundRequest);
// QIODevice* should already be open
- UploadContentJob*
- uploadContent(QIODevice* contentSource, const QString& filename = {},
- const QString& overrideContentType = {}) const;
+ UploadContentJob* uploadContent(QIODevice* contentSource,
+ const QString& filename = {},
+ const QString& overrideContentType = {});
UploadContentJob* uploadFile(const QString& fileName,
const QString& overrideContentType = {});
- GetContentJob* getContent(const QString& mediaId) const;
- GetContentJob* getContent(const QUrl& url) const;
+ GetContentJob* getContent(const QString& mediaId);
+ GetContentJob* getContent(const QUrl& url);
// If localFilename is empty, a temporary file will be created
DownloadFileJob* downloadFile(const QUrl& url,
- const QString& localFilename = {}) const;
+ const QString& localFilename = {});
/**
* \brief Create a room (generic method)
@@ -641,11 +640,10 @@ public slots:
ForgetRoomJob* forgetRoom(const QString& id);
SendToDeviceJob* sendToDevices(const QString& eventType,
- const UsersToDevicesToEvents& eventsMap) const;
+ const UsersToDevicesToEvents& eventsMap);
/** \deprecated This method is experimental and may be removed any time */
- SendMessageJob* sendMessage(const QString& roomId,
- const RoomEvent& event) const;
+ SendMessageJob* sendMessage(const QString& roomId, const RoomEvent& event);
/** \deprecated Do not use this directly, use Room::leaveRoom() instead */
virtual LeaveRoomJob* leaveRoom(Room* room);
@@ -654,7 +652,7 @@ public slots:
/** @deprecated Use callApi<PostReceiptJob>() or Room::postReceipt() instead
*/
- virtual PostReceiptJob* postReceipt(Room* room, RoomEvent* event) const;
+ virtual PostReceiptJob* postReceipt(Room* room, RoomEvent* event);
signals:
/**