aboutsummaryrefslogtreecommitdiff
path: root/lib/mxcreply.cpp
blob: f389ac85357b5fabc5e00c48b36a0c15dbc09bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-FileCopyrightText: Tobias Fella <fella@posteo.de>
// SPDX-License-Identifier: LGPL-2.1-or-later

#include "mxcreply.h"

#include <QtCore/QBuffer>
#include "connection.h"
#include "room.h"
#include "networkaccessmanager.h"
#include "events/stickerevent.h"

using namespace Quotient;

class MxcReply::Private
{
public:
    QNetworkReply *m_reply = nullptr;
};

MxcReply::MxcReply(QNetworkReply* reply)
{
    reply->setParent(this);
    d->m_reply = reply;
    connect(d->m_reply, &QNetworkReply::finished, this, [this]() {
        setError(d->m_reply->error(), d->m_reply->errorString());
        setOpenMode(ReadOnly);
        Q_EMIT finished();
    });
}

MxcReply::MxcReply(QNetworkReply* reply, Room* room, const QString &eventId)
    : d(std::make_unique<Private>())
{
    reply->setParent(this);
    d->m_reply = reply;
    connect(d->m_reply, &QNetworkReply::finished, this, [this, eventId]() {
        setError(d->m_reply->error(), d->m_reply->errorString());
        setOpenMode(ReadOnly);
        Q_EMIT finished();
    });
}

bool MxcReply::isSequential() const
{
    return true;
}

qint64 MxcReply::readData(char *data, qint64 maxSize)
{
    return d->m_reply->read(data, maxSize);
}

void MxcReply::abort()
{
    d->m_reply->abort();
}