aboutsummaryrefslogtreecommitdiff
path: root/connectiondata.h
blob: 7a2f2e9093dc6e4239fd8ca1a2ad0736f37c8192 (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
/******************************************************************************
 * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#pragma once

#include <QtCore/QUrl>

#include <memory>

class QNetworkAccessManager;

namespace QMatrixClient
{
    class ConnectionData
    {
        public:
            explicit ConnectionData(QUrl baseUrl);
            virtual ~ConnectionData();

            QByteArray accessToken() const;
            QUrl baseUrl() const;
            const QString& deviceId() const;

            QNetworkAccessManager* nam() const;
            void setBaseUrl(QUrl baseUrl);
            void setToken(QByteArray accessToken);
            void setHost( QString host );
            void setPort( int port );
            void setDeviceId(const QString& deviceId);

            QString lastEvent() const;
            void setLastEvent( QString identifier );

            QByteArray generateTxnId() const;

        private:
            struct Private;
            std::unique_ptr<Private> d;
    };
}  // namespace QMatrixClient
e.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#pragma once

#include "converters.h"

#include "events/eventloader.h"
#include "events/roommemberevent.h"
#include "jobs/basejob.h"

#include <QtCore/QHash>

namespace Quotient
{

// Operations

/// Get a single event by event ID.
/*!
 * Get a single event based on ``roomId/eventId``. You must have permission to
 * retrieve this event e.g. by being a member in the room for this event.
 */
class GetOneRoomEventJob : public BaseJob
{
public:
    /*! Get a single event by event ID.
     * \param roomId
     *   The ID of the room the event is in.
     * \param eventId
     *   The event ID to get.
     */
    explicit GetOneRoomEventJob(const QString& roomId, const QString& eventId);

    /*! Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for
     * GetOneRoomEventJob is necessary but the job
     * itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
                               const QString& eventId);

    ~GetOneRoomEventJob() override;

    // Result properties

    /// The full event.
    EventPtr&& data();

protected:
    Status parseJson(const QJsonDocument& data) override;

private:
    class Private;
    QScopedPointer<Private> d;
};

/// Get the state identified by the type and key.
/*!
 * Looks up the contents of a state event in a room. If the user is
 * joined to the room then the state is taken from the current
 * state of the room. If the user has left the room then the state is
 * taken from the state of the room when they left.
 */
class GetRoomStateWithKeyJob : public BaseJob
{
public:
    /*! Get the state identified by the type and key.
     * \param roomId
     *   The room to look up the state in.
     * \param eventType
     *   The type of state to look up.
     * \param stateKey
     *   The key of the state to look up.
     */
    explicit GetRoomStateWithKeyJob(const QString& roomId,
                                    const QString& eventType,
                                    const QString& stateKey);

    /*! Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for
     * GetRoomStateWithKeyJob is necessary but the job
     * itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
                               const QString& eventType,
                               const QString& stateKey);
};

/// Get the state identified by the type, with the empty state key.
/*!
 * Looks up the contents of a state event in a room. If the user is
 * joined to the room then the state is taken from the current
 * state of the room. If the user has left the room then the state is
 * taken from the state of the room when they left.
 *
 * This looks up the state event with the empty state key.
 */
class GetRoomStateByTypeJob : public BaseJob
{
public:
    /*! Get the state identified by the type, with the empty state key.
     * \param roomId
     *   The room to look up the state in.
     * \param eventType
     *   The type of state to look up.
     */
    explicit GetRoomStateByTypeJob(const QString& roomId,
                                   const QString& eventType);

    /*! Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for
     * GetRoomStateByTypeJob is necessary but the job
     * itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
                               const QString& eventType);
};

/// Get all state events in the current state of a room.
/*!
 * Get the state events for the current state of a room.
 */
class GetRoomStateJob : public BaseJob
{
public:
    /*! Get all state events in the current state of a room.
     * \param roomId
     *   The room to look up the state for.
     */
    explicit GetRoomStateJob(const QString& roomId);

    /*! Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for
     * GetRoomStateJob is necessary but the job
     * itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);

    ~GetRoomStateJob() override;

    // Result properties

    /// If the user is a member of the room this will be the
    /// current state of the room as a list of events. If the user
    /// has left the room then this will be the state of the room
    /// when they left as a list of events.
    StateEvents&& data();

protected:
    Status parseJson(const QJsonDocument& data) override;

private:
    class Private;
    QScopedPointer<Private> d;
};

/// Get the m.room.member events for the room.
/*!
 * Get the list of members for this room.
 */
class GetMembersByRoomJob : public BaseJob
{
public:
    /*! Get the m.room.member events for the room.
     * \param roomId
     *   The room to get the member events for.
     * \param at
     *   The token defining the timeline position as-of which to return
     *   the list of members. This token can be obtained from a batch token
     *   returned for each room by the sync API, or from
     *   a ``start``/``end`` token returned by a ``/messages`` request.
     * \param membership
     *   Only return users with the specified membership
     * \param notMembership
     *   Only return users with membership state other than specified
     */
    explicit GetMembersByRoomJob(const QString& roomId, const QString& at = {},
                                 const QString& membership = {},
                                 const QString& notMembership = {});

    /*! Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for
     * GetMembersByRoomJob is necessary but the job
     * itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
                               const QString& at = {},
                               const QString& membership = {},
                               const QString& notMembership = {});

    ~GetMembersByRoomJob() override;

    // Result properties

    /// Get the list of members for this room.
    EventsArray<RoomMemberEvent>&& chunk();

protected:
    Status parseJson(const QJsonDocument& data) override;

private:
    class Private;
    QScopedPointer<Private> d;
};

/// Gets the list of currently joined users and their profile data.
/*!
 * This API returns a map of MXIDs to member info objects for members of the
 * room. The current user must be in the room for it to work, unless it is an
 * Application Service in which case any of the AS's users must be in the room.
 * This API is primarily for Application Services and should be faster to
 * respond than ``/members`` as it can be implemented more efficiently on the
 * server.
 */
class GetJoinedMembersByRoomJob : public BaseJob
{
public:
    // Inner data structures

    /// This API returns a map of MXIDs to member info objects for members of
    /// the room. The current user must be in the room for it to work, unless it
    /// is an Application Service in which case any of the AS's users must be in
    /// the room. This API is primarily for Application Services and should be
    /// faster to respond than ``/members`` as it can be implemented more
    /// efficiently on the server.
    struct RoomMember
    {
        /// The display name of the user this object is representing.
        QString displayName;
        /// The mxc avatar url of the user this object is representing.
        QString avatarUrl;
    };

    // Construction/destruction

    /*! Gets the list of currently joined users and their profile data.
     * \param roomId
     *   The room to get the members of.
     */
    explicit GetJoinedMembersByRoomJob(const QString& roomId);

    /*! Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for
     * GetJoinedMembersByRoomJob is necessary but the job
     * itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);

    ~GetJoinedMembersByRoomJob() override;

    // Result properties

    /// A map from user ID to a RoomMember object.
    const QHash<QString, RoomMember>& joined() const;

protected:
    Status parseJson(const QJsonDocument& data) override;

private:
    class Private;
    QScopedPointer<Private> d;
};

} // namespace Quotient