/****************************************************************************** * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN */ #pragma once #include "jobs/basejob.h" namespace Quotient { /*! \brief Stop the requesting user participating in a particular room. * * This API stops a user participating in a particular room. * * If the user was already in the room, they will no longer be able to see * new events in the room. If the room requires an invite to join, they * will need to be re-invited before they can re-join. * * If the user was invited to the room, but had not joined, this call * serves to reject the invite. * * The user will still be allowed to retrieve history from the room which * they were previously allowed to see. */ class LeaveRoomJob : public BaseJob { public: /*! \brief Stop the requesting user participating in a particular room. * * \param roomId * The room identifier to leave. */ explicit LeaveRoomJob(const QString& roomId); /*! \brief Construct a URL without creating a full-fledged job object * * This function can be used when a URL for LeaveRoomJob * is necessary but the job itself isn't. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); }; /*! \brief Stop the requesting user remembering about a particular room. * * This API stops a user remembering about a particular room. * * In general, history is a first class citizen in Matrix. After this API * is called, however, a user will no longer be able to retrieve history * for this room. If all users on a homeserver forget a room, the room is * eligible for deletion from that homeserver. * * If the user is currently joined to the room, they must leave the room * before calling this API. */ class ForgetRoomJob : public BaseJob { public: /*! \brief Stop the requesting user remembering about a particular room. * * \param roomId * The room identifier to forget. */ explicit ForgetRoomJob(const QString& roomId); /*! \brief Construct a URL without creating a full-fledged job object * * This function can be used when a URL for ForgetRoomJob * is necessary but the job itself isn't. */ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); }; } // namespace Quotient ef='/nicolas/libquotient/tree/?id=4244cee8d5e0f760cccd2b45ad587670573ef03c'>root/lib/events/event.cpp
blob: fd6e393922ba2e8dad43f1c06f2fe61a2d4ad6bf (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/******************************************************************************
 * 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
 */

#include "event.h"

#include "logging.h"

#include <QtCore/QJsonDocument>

using namespace QMatrixClient;

event_type_t EventTypeRegistry::initializeTypeId(event_mtype_t matrixTypeId)
{
    const auto id = get().eventTypes.size();
    get().eventTypes.push_back(matrixTypeId);
    if (strncmp(matrixTypeId, "", 1) == 0)
        qDebug(EVENTS) << "Initialized unknown event type with id" << id;
    else
        qDebug(EVENTS) << "Initialized event type" << matrixTypeId
                       << "with id" << id;
    return id;
}

QString EventTypeRegistry::getMatrixType(event_type_t typeId)
{
    return typeId < get().eventTypes.size() ? get().eventTypes[typeId] : "";
}

Event::Event(Type type, const QJsonObject& json)
    : _type(type), _json(json)
{
    if (!json.contains(ContentKeyL) &&
            !json.value(UnsignedKeyL).toObject().contains(RedactedCauseKeyL))
    {
        qCWarning(EVENTS) << "Event without 'content' node";
        qCWarning(EVENTS) << formatJson << json;
    }
}

Event::Event(Type type, event_mtype_t matrixType, const QJsonObject& contentJson)
    : Event(type, basicEventJson(matrixType, contentJson))
{ }

Event::~Event() = default;

QString Event::matrixType() const
{
    return fullJson()[TypeKeyL].toString();
}

QByteArray Event::originalJson() const
{
    return QJsonDocument(_json).toJson();
}

const QJsonObject Event::contentJson() const
{
    return fullJson()[ContentKeyL].toObject();
}

const QJsonObject Event::unsignedJson() const
{
    return fullJson()[UnsignedKeyL].toObject();
}