diff options
author | Kitsune Ral <KitsuneRal@users.noreply.github.com> | 2016-04-05 20:46:45 +0300 |
---|---|---|
committer | Kitsune Ral <KitsuneRal@users.noreply.github.com> | 2016-04-05 20:46:45 +0300 |
commit | 7abdc7ec386776602758d84edc6b583d6dad4ecd (patch) | |
tree | 247b6affaa7828e5122f1c338dd35a729cc4ee19 /events | |
download | libquotient-7abdc7ec386776602758d84edc6b583d6dad4ecd.tar.gz libquotient-7abdc7ec386776602758d84edc6b583d6dad4ecd.zip |
Imported the current source tree from Quaternion/lib.
Diffstat (limited to 'events')
-rw-r--r-- | events/event.cpp | 148 | ||||
-rw-r--r-- | events/event.h | 58 | ||||
-rw-r--r-- | events/receiptevent.cpp | 97 | ||||
-rw-r--r-- | events/receiptevent.h | 56 | ||||
-rw-r--r-- | events/roomaliasesevent.cpp | 78 | ||||
-rw-r--r-- | events/roomaliasesevent.h | 44 | ||||
-rw-r--r-- | events/roomcanonicalaliasevent.cpp | 53 | ||||
-rw-r--r-- | events/roomcanonicalaliasevent.h | 42 | ||||
-rw-r--r-- | events/roommemberevent.cpp | 88 | ||||
-rw-r--r-- | events/roommemberevent.h | 50 | ||||
-rw-r--r-- | events/roommessageevent.cpp | 101 | ||||
-rw-r--r-- | events/roommessageevent.h | 45 | ||||
-rw-r--r-- | events/roomnameevent.cpp | 51 | ||||
-rw-r--r-- | events/roomnameevent.h | 44 | ||||
-rw-r--r-- | events/roomtopicevent.cpp | 51 | ||||
-rw-r--r-- | events/roomtopicevent.h | 44 | ||||
-rw-r--r-- | events/typingevent.cpp | 57 | ||||
-rw-r--r-- | events/typingevent.h | 44 | ||||
-rw-r--r-- | events/unknownevent.cpp | 60 | ||||
-rw-r--r-- | events/unknownevent.h | 43 |
20 files changed, 1254 insertions, 0 deletions
diff --git a/events/event.cpp b/events/event.cpp new file mode 100644 index 00000000..c3e94ce1 --- /dev/null +++ b/events/event.cpp @@ -0,0 +1,148 @@ +/****************************************************************************** + * 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 <QtCore/QJsonObject> +#include <QtCore/QJsonDocument> +#include <QtCore/QDateTime> +#include <QtCore/QDebug> + +#include "roommessageevent.h" +#include "roomnameevent.h" +#include "roomaliasesevent.h" +#include "roomcanonicalaliasevent.h" +#include "roommemberevent.h" +#include "roomtopicevent.h" +#include "typingevent.h" +#include "receiptevent.h" +#include "unknownevent.h" + +using namespace QMatrixClient; + +class Event::Private +{ + public: + EventType type; + QString id; + QDateTime timestamp; + QString roomId; + QString originalJson; +}; + +Event::Event(EventType type) + : d(new Private) +{ + d->type = type; +} + +Event::~Event() +{ + delete d; +} + +EventType Event::type() const +{ + return d->type; +} + +QString Event::id() const +{ + return d->id; +} + +QDateTime Event::timestamp() const +{ + return d->timestamp; +} + +QString Event::roomId() const +{ + return d->roomId; +} + +QString Event::originalJson() const +{ + return d->originalJson; +} + +Event* Event::fromJson(const QJsonObject& obj) +{ + //qDebug() << obj.value("type").toString(); + if( obj.value("type").toString() == "m.room.message" ) + { + return RoomMessageEvent::fromJson(obj); + } + if( obj.value("type").toString() == "m.room.name" ) + { + return RoomNameEvent::fromJson(obj); + } + if( obj.value("type").toString() == "m.room.aliases" ) + { + return RoomAliasesEvent::fromJson(obj); + } + if( obj.value("type").toString() == "m.room.canonical_alias" ) + { + return RoomCanonicalAliasEvent::fromJson(obj); + } + if( obj.value("type").toString() == "m.room.member" ) + { + return RoomMemberEvent::fromJson(obj); + } + if( obj.value("type").toString() == "m.room.topic" ) + { + return RoomTopicEvent::fromJson(obj); + } + if( obj.value("type").toString() == "m.typing" ) + { + qDebug() << "m.typing..."; + return TypingEvent::fromJson(obj); + } + if( obj.value("type").toString() == "m.receipt" ) + { + return ReceiptEvent::fromJson(obj); + } + //qDebug() << "Unknown event"; + return UnknownEvent::fromJson(obj); +} + +bool Event::parseJson(const QJsonObject& obj) +{ + d->originalJson = QString::fromUtf8(QJsonDocument(obj).toJson()); + bool correct = true; + if( obj.contains("event_id") ) + { + d->id = obj.value("event_id").toString(); + } else { + correct = false; + qDebug() << "Event: can't find event_id"; + } + if( obj.contains("origin_server_ts") ) + { + d->timestamp = QDateTime::fromMSecsSinceEpoch( (quint64) obj.value("origin_server_ts").toDouble(), Qt::UTC ); + } else { + correct = false; + qDebug() << "Event: can't find ts"; + //qDebug() << obj; + } + if( obj.contains("room_id") ) + { + d->roomId = obj.value("room_id").toString(); + } + return correct; +} diff --git a/events/event.h b/events/event.h new file mode 100644 index 00000000..b25b1378 --- /dev/null +++ b/events/event.h @@ -0,0 +1,58 @@ +/****************************************************************************** + * 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 + */ + +#ifndef QMATRIXCLIENT_EVENT_H +#define QMATRIXCLIENT_EVENT_H + +#include <QtCore/QString> +#include <QtCore/QDateTime> +#include <QtCore/QJsonObject> + +namespace QMatrixClient +{ + enum class EventType + { + RoomMessage, RoomName, RoomAliases, RoomCanonicalAlias, + RoomMember, RoomTopic, Typing, Receipt, Unknown + }; + + class Event + { + public: + Event(EventType type); + virtual ~Event(); + + EventType type() const; + QString id() const; + QDateTime timestamp() const; + QString roomId() const; + // only for debug purposes! + QString originalJson() const; + + static Event* fromJson(const QJsonObject& obj); + + protected: + bool parseJson(const QJsonObject& obj); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_EVENT_H diff --git a/events/receiptevent.cpp b/events/receiptevent.cpp new file mode 100644 index 00000000..d2a27079 --- /dev/null +++ b/events/receiptevent.cpp @@ -0,0 +1,97 @@ +/****************************************************************************** + * Copyright (C) 2016 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 + */ + +/* +Example of a Receipt Event: +{ + "content": { + "$1435641916114394fHBLK:matrix.org": { + "m.read": { + "@rikj:jki.re": { + "ts": 1436451550453 + } + } + } + }, + "room_id": "!KpjVgQyZpzBwvMBsnT:matrix.org", + "type": "m.receipt" +} +*/ + +#include "receiptevent.h" + +#include <QtCore/QJsonObject> +#include <QtCore/QJsonArray> +#include <QtCore/QDebug> + +using namespace QMatrixClient; + +Receipt::Receipt(QString event, QString user, QDateTime time) + : eventId(event) + , userId(user) + , timestamp(time) +{ +} + +class ReceiptEvent::Private +{ + public: + QHash<QString, QList<Receipt>> eventToReceipts; +}; + +ReceiptEvent::ReceiptEvent() + : Event(EventType::Receipt) + , d(new Private) +{ +} + +ReceiptEvent::~ReceiptEvent() +{ + delete d; +} + +QList<Receipt> ReceiptEvent::receiptsForEvent(QString eventId) const +{ + return d->eventToReceipts.value(eventId); +} + +QStringList ReceiptEvent::events() const +{ + return d->eventToReceipts.keys(); +} + +ReceiptEvent* ReceiptEvent::fromJson(const QJsonObject& obj) +{ + ReceiptEvent* e = new ReceiptEvent(); + e->parseJson(obj); + const QJsonObject contents = obj.value("content").toObject(); + for( const QString& eventId: contents.keys() ) + { + QJsonObject reads = contents.value(eventId).toObject().value("m.read").toObject(); + QList<Receipt> receipts; + for( const QString& userId: reads.keys() ) + { + QJsonObject user = reads.value(userId).toObject(); + QDateTime time = QDateTime::fromMSecsSinceEpoch( (quint64) user.value("ts").toDouble(), Qt::UTC ); + Receipt receipt(eventId, userId, time); + receipts.append(receipt); + } + e->d->eventToReceipts.insert(eventId, receipts); + } + return e; +} diff --git a/events/receiptevent.h b/events/receiptevent.h new file mode 100644 index 00000000..aa72ba90 --- /dev/null +++ b/events/receiptevent.h @@ -0,0 +1,56 @@ +/****************************************************************************** + * Copyright (C) 2016 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 + */ + +#ifndef QMATRIXCLIENT_RECEIPTEVENT_H +#define QMATRIXCLIENT_RECEIPTEVENT_H + +#include "event.h" + +#include <QtCore/QStringList> + +namespace QMatrixClient +{ + class Receipt + { + public: + QString eventId; + QString userId; + QDateTime timestamp; + + Receipt(QString event, QString user, QDateTime time); + }; + + class ReceiptEvent: public Event + { + public: + ReceiptEvent(); + virtual ~ReceiptEvent(); + + QList<Receipt> receiptsForEvent(QString eventId) const; + + QStringList events() const; + + static ReceiptEvent* fromJson(const QJsonObject& obj); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_RECEIPTEVENT_H diff --git a/events/roomaliasesevent.cpp b/events/roomaliasesevent.cpp new file mode 100644 index 00000000..6bbe0aff --- /dev/null +++ b/events/roomaliasesevent.cpp @@ -0,0 +1,78 @@ +/****************************************************************************** + * 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 + */ + +// Example of a RoomAliases Event: +// +// { +// "age":3758857346, +// "content":{ +// "aliases":["#freenode_#testest376:matrix.org"] +// }, +// "event_id":"$1439989428122drFjY:matrix.org", +// "origin_server_ts":1439989428910, +// "replaces_state":"$143613875199223YYPrN:matrix.org", +// "room_id":"!UoqtanuuSGTMvNRfDG:matrix.org", +// "state_key":"matrix.org", +// "type":"m.room.aliases", +// "user_id":"@appservice-irc:matrix.org" +// } + +#include "roomaliasesevent.h" + +#include <QtCore/QJsonObject> +#include <QtCore/QJsonArray> +#include <QtCore/QDebug> + +using namespace QMatrixClient; + +class RoomAliasesEvent::Private +{ + public: + QStringList aliases; +}; + +RoomAliasesEvent::RoomAliasesEvent() + : Event(EventType::RoomAliases) + , d(new Private) +{ +} + +RoomAliasesEvent::~RoomAliasesEvent() +{ + delete d; +} + +QStringList RoomAliasesEvent::aliases() const +{ + return d->aliases; +} + +RoomAliasesEvent* RoomAliasesEvent::fromJson(const QJsonObject& obj) +{ + qDebug() << "!!!!"; + RoomAliasesEvent* e = new RoomAliasesEvent(); + e->parseJson(obj); + const QJsonObject contents = obj.value("content").toObject(); + const QJsonArray aliases = contents.value("aliases").toArray(); + for( const QJsonValue& alias : aliases ) + { + e->d->aliases << alias.toString(); + } + qDebug() << e->d->aliases; + return e; +} diff --git a/events/roomaliasesevent.h b/events/roomaliasesevent.h new file mode 100644 index 00000000..89ea63b8 --- /dev/null +++ b/events/roomaliasesevent.h @@ -0,0 +1,44 @@ +/****************************************************************************** + * 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 + */ + +#ifndef QMATRIXCLIENT_ROOMALIASESEVENT_H +#define QMATRIXCLIENT_ROOMALIASESEVENT_H + +#include "event.h" + +#include <QtCore/QStringList> + +namespace QMatrixClient +{ + class RoomAliasesEvent: public Event + { + public: + RoomAliasesEvent(); + virtual ~RoomAliasesEvent(); + + QStringList aliases() const; + + static RoomAliasesEvent* fromJson(const QJsonObject& obj); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_ROOMALIASESEVENT_H
\ No newline at end of file diff --git a/events/roomcanonicalaliasevent.cpp b/events/roomcanonicalaliasevent.cpp new file mode 100644 index 00000000..d84c07fc --- /dev/null +++ b/events/roomcanonicalaliasevent.cpp @@ -0,0 +1,53 @@ +/****************************************************************************** + * Copyright (C) 2016 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 "roomcanonicalaliasevent.h" + +using namespace QMatrixClient; + +class RoomCanonicalAliasEvent::Private +{ + public: + QString alias; +}; + +RoomCanonicalAliasEvent::RoomCanonicalAliasEvent() + : Event(EventType::RoomCanonicalAlias) + , d(new Private) +{ +} + +RoomCanonicalAliasEvent::~RoomCanonicalAliasEvent() +{ + delete d; +} + +QString RoomCanonicalAliasEvent::alias() +{ + return d->alias; +} + +RoomCanonicalAliasEvent* RoomCanonicalAliasEvent::fromJson(const QJsonObject& obj) +{ + RoomCanonicalAliasEvent* e = new RoomCanonicalAliasEvent(); + e->parseJson(obj); + const QJsonObject contents = obj.value("content").toObject(); + e->d->alias = contents.value("alias").toString(); + return e; +} + diff --git a/events/roomcanonicalaliasevent.h b/events/roomcanonicalaliasevent.h new file mode 100644 index 00000000..f3ab8e5a --- /dev/null +++ b/events/roomcanonicalaliasevent.h @@ -0,0 +1,42 @@ +/****************************************************************************** + * Copyright (C) 2016 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 + */ + +#ifndef QMATRIXCLIENT_ROOMCANONICALALIASEVENT_H +#define QMATRIXCLIENT_ROOMCANONICALALIASEVENT_H + +#include "event.h" + +namespace QMatrixClient +{ + class RoomCanonicalAliasEvent: public Event + { + public: + RoomCanonicalAliasEvent(); + virtual ~RoomCanonicalAliasEvent(); + + QString alias(); + + static RoomCanonicalAliasEvent* fromJson(const QJsonObject& obj); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_ROOMCANONICALALIASEVENT_H
\ No newline at end of file diff --git a/events/roommemberevent.cpp b/events/roommemberevent.cpp new file mode 100644 index 00000000..e58bda8f --- /dev/null +++ b/events/roommemberevent.cpp @@ -0,0 +1,88 @@ +/****************************************************************************** + * 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 "roommemberevent.h" + +#include <QtCore/QDebug> +#include <QtCore/QUrl> + +using namespace QMatrixClient; + +class RoomMemberEvent::Private +{ + public: + MembershipType membership; + QString userId; + QString displayname; + QUrl avatarUrl; +}; + +RoomMemberEvent::RoomMemberEvent() + : Event(EventType::RoomMember) + , d(new Private) +{ +} + +RoomMemberEvent::~RoomMemberEvent() +{ + delete d; +} + +MembershipType RoomMemberEvent::membership() const +{ + return d->membership; +} + +QString RoomMemberEvent::userId() const +{ + return d->userId; +} + +QString RoomMemberEvent::displayName() const +{ + return d->displayname; +} + +QUrl RoomMemberEvent::avatarUrl() const +{ + return d->avatarUrl; +} + +RoomMemberEvent* RoomMemberEvent::fromJson(const QJsonObject& obj) +{ + RoomMemberEvent* e = new RoomMemberEvent(); + e->parseJson(obj); + e->d->userId = obj.value("state_key").toString(); + QJsonObject content = obj.value("content").toObject(); + e->d->displayname = content.value("displayname").toString(); + QString membershipString = content.value("membership").toString(); + if( membershipString == "invite" ) + e->d->membership = MembershipType::Invite; + else if( membershipString == "join" ) + e->d->membership = MembershipType::Join; + else if( membershipString == "knock" ) + e->d->membership = MembershipType::Knock; + else if( membershipString == "leave" ) + e->d->membership = MembershipType::Leave; + else if( membershipString == "ban" ) + e->d->membership = MembershipType::Ban; + else + qDebug() << "Unknown MembershipType: " << membershipString; + e->d->avatarUrl = QUrl(content.value("avatar_url").toString()); + return e; +} diff --git a/events/roommemberevent.h b/events/roommemberevent.h new file mode 100644 index 00000000..e47013cb --- /dev/null +++ b/events/roommemberevent.h @@ -0,0 +1,50 @@ +/****************************************************************************** + * 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 + */ + +#ifndef QMATRIXCLIENT_ROOMMEMBEREVENT_H +#define QMATRIXCLIENT_ROOMMEMBEREVENT_H + +#include <QtCore/QJsonObject> +#include <QtCore/QUrl> + +#include "event.h" + +namespace QMatrixClient +{ + enum class MembershipType {Invite, Join, Knock, Leave, Ban}; + + class RoomMemberEvent: public Event + { + public: + RoomMemberEvent(); + virtual ~RoomMemberEvent(); + + MembershipType membership() const; + QString userId() const; + QString displayName() const; + QUrl avatarUrl() const; + + static RoomMemberEvent* fromJson(const QJsonObject& obj); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_ROOMMEMBEREVENT_H diff --git a/events/roommessageevent.cpp b/events/roommessageevent.cpp new file mode 100644 index 00000000..ea03986b --- /dev/null +++ b/events/roommessageevent.cpp @@ -0,0 +1,101 @@ +/****************************************************************************** + * 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 "roommessageevent.h" + +#include <QtCore/QJsonObject> +#include <QtCore/QDateTime> +#include <QtCore/QDebug> + +using namespace QMatrixClient; + +class RoomMessageEvent::Private +{ + public: + Private() {} + + QString userId; + QString body; + QString msgtype; + QDateTime hsob_ts; +}; + +RoomMessageEvent::RoomMessageEvent() + : Event(EventType::RoomMessage) + , d(new Private) +{ + +} + +RoomMessageEvent::~RoomMessageEvent() +{ + delete d; +} + +QString RoomMessageEvent::userId() const +{ + return d->userId; +} + +QString RoomMessageEvent::msgtype() const +{ + return d->msgtype; +} + +QString RoomMessageEvent::body() const +{ + return d->body; +} + +QDateTime RoomMessageEvent::hsob_ts() const +{ + return d->hsob_ts; +} + +RoomMessageEvent* RoomMessageEvent::fromJson(const QJsonObject& obj) +{ + RoomMessageEvent* e = new RoomMessageEvent(); + e->parseJson(obj); + if( obj.contains("sender") ) + { + e->d->userId = obj.value("sender").toString(); + } else { + qDebug() << "RoomMessageEvent: user_id not found"; + } + if( obj.contains("content") ) + { + QJsonObject content = obj.value("content").toObject(); + if( content.contains("msgtype") ) + { + e->d->msgtype = content.value("msgtype").toString(); + } else { + qDebug() << "RoomMessageEvent: msgtype not found"; + } + if( content.contains("body") ) + { + e->d->body = content.value("body").toString(); + } else { + qDebug() << "RoomMessageEvent: body not found"; + } +// e->d->hsob_ts = QDateTime::fromMSecsSinceEpoch( content.value("hsoc_ts").toInt() ); +// } else { +// qDebug() << "RoomMessageEvent: hsoc_ts not found"; +// } + } + return e; +}
\ No newline at end of file diff --git a/events/roommessageevent.h b/events/roommessageevent.h new file mode 100644 index 00000000..dcc5b547 --- /dev/null +++ b/events/roommessageevent.h @@ -0,0 +1,45 @@ +/****************************************************************************** + * 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 + */ + +#ifndef QMATRIXCLIENT_ROOMMESSAGEEVENT_H +#define QMATRIXCLIENT_ROOMMESSAGEEVENT_H + +#include "event.h" + +namespace QMatrixClient +{ + class RoomMessageEvent: public Event + { + public: + RoomMessageEvent(); + virtual ~RoomMessageEvent(); + + QString userId() const; + QString msgtype() const; + QString body() const; + QDateTime hsob_ts() const; + + static RoomMessageEvent* fromJson( const QJsonObject& obj ); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_ROOMMESSAGEEVENT_H
\ No newline at end of file diff --git a/events/roomnameevent.cpp b/events/roomnameevent.cpp new file mode 100644 index 00000000..f4c31edf --- /dev/null +++ b/events/roomnameevent.cpp @@ -0,0 +1,51 @@ +/******************************************************************************
+ * Copyright (C) 2015 Kitsune Ral <kitsune-ral@users.sf.net>
+ *
+ * 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 "roomnameevent.h"
+
+using namespace QMatrixClient;
+
+struct RoomNameEvent::Private
+{
+ QString name;
+};
+
+RoomNameEvent::RoomNameEvent() :
+ Event(EventType::RoomName),
+ d(new Private)
+{
+}
+
+RoomNameEvent::~RoomNameEvent()
+{
+ delete d;
+}
+
+QString RoomNameEvent::name() const
+{
+ return d->name;
+}
+
+RoomNameEvent* RoomNameEvent::fromJson(const QJsonObject& obj)
+{
+ RoomNameEvent* e = new RoomNameEvent();
+ e->parseJson(obj);
+ const QJsonObject contents = obj.value("content").toObject();
+ e->d->name = contents.value("name").toString();
+ return e;
+}
diff --git a/events/roomnameevent.h b/events/roomnameevent.h new file mode 100644 index 00000000..436a1dd4 --- /dev/null +++ b/events/roomnameevent.h @@ -0,0 +1,44 @@ +/******************************************************************************
+ * Copyright (C) 2015 Kitsune Ral <kitsune-ral@users.sf.net>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_ROOMNAMEEVENT_H
+#define QMATRIXCLIENT_ROOMNAMEEVENT_H
+
+#include "event.h"
+
+namespace QMatrixClient
+{
+
+class RoomNameEvent : public Event
+{
+public:
+ RoomNameEvent();
+ virtual ~RoomNameEvent();
+
+ QString name() const;
+
+ static RoomNameEvent* fromJson(const QJsonObject& obj);
+
+private:
+ class Private;
+ Private *d;
+};
+
+}
+
+#endif // QMATRIXCLIENT_ROOMNAMEEVENT_H
diff --git a/events/roomtopicevent.cpp b/events/roomtopicevent.cpp new file mode 100644 index 00000000..5739d85e --- /dev/null +++ b/events/roomtopicevent.cpp @@ -0,0 +1,51 @@ +/****************************************************************************** + * 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 "roomtopicevent.h" + +using namespace QMatrixClient; + +class RoomTopicEvent::Private +{ + public: + QString topic; +}; + +RoomTopicEvent::RoomTopicEvent() + : Event(EventType::RoomTopic) + , d(new Private) +{ +} + +RoomTopicEvent::~RoomTopicEvent() +{ + delete d; +} + +QString RoomTopicEvent::topic() const +{ + return d->topic; +} + +RoomTopicEvent* RoomTopicEvent::fromJson(const QJsonObject& obj) +{ + RoomTopicEvent* e = new RoomTopicEvent(); + e->parseJson(obj); + e->d->topic = obj.value("content").toObject().value("topic").toString(); + return e; +} diff --git a/events/roomtopicevent.h b/events/roomtopicevent.h new file mode 100644 index 00000000..9c27339c --- /dev/null +++ b/events/roomtopicevent.h @@ -0,0 +1,44 @@ +/****************************************************************************** + * 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 + */ + +#ifndef QMATRIXCLIENT_ROOMTOPICEVENT_H +#define QMATRIXCLIENT_ROOMTOPICEVENT_H + +#include <QtCore/QJsonObject> + +#include "event.h" + +namespace QMatrixClient +{ + class RoomTopicEvent: public Event + { + public: + RoomTopicEvent(); + virtual ~RoomTopicEvent(); + + QString topic() const; + + static RoomTopicEvent* fromJson(const QJsonObject& obj); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_ROOMTOPICEVENT_H
\ No newline at end of file diff --git a/events/typingevent.cpp b/events/typingevent.cpp new file mode 100644 index 00000000..242094e1 --- /dev/null +++ b/events/typingevent.cpp @@ -0,0 +1,57 @@ +/****************************************************************************** + * 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 "typingevent.h" + +#include <QtCore/QJsonArray> + +using namespace QMatrixClient; + +class TypingEvent::Private +{ + public: + QStringList users; +}; + +TypingEvent::TypingEvent() + : Event(EventType::Typing) + , d( new Private ) +{ +} + +TypingEvent::~TypingEvent() +{ + delete d; +} + +QStringList TypingEvent::users() +{ + return d->users; +} + +TypingEvent* TypingEvent::fromJson(const QJsonObject& obj) +{ + TypingEvent* e = new TypingEvent(); + e->parseJson(obj); + QJsonArray array = obj.value("content").toObject().value("user_ids").toArray(); + for( const QJsonValue& user: array ) + { + e->d->users << user.toString(); + } + return e; +} diff --git a/events/typingevent.h b/events/typingevent.h new file mode 100644 index 00000000..2625dc66 --- /dev/null +++ b/events/typingevent.h @@ -0,0 +1,44 @@ +/****************************************************************************** + * 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 + */ + +#ifndef QMATRIXCLIENT_TYPINGEVENT_H +#define QMATRIXCLIENT_TYPINGEVENT_H + +#include <QtCore/QStringList> + +#include "event.h" + +namespace QMatrixClient +{ + class TypingEvent: public Event + { + public: + TypingEvent(); + virtual ~TypingEvent(); + + QStringList users(); + + static TypingEvent* fromJson(const QJsonObject& obj); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_TYPINGEVENT_H diff --git a/events/unknownevent.cpp b/events/unknownevent.cpp new file mode 100644 index 00000000..758d0ec8 --- /dev/null +++ b/events/unknownevent.cpp @@ -0,0 +1,60 @@ +/****************************************************************************** + * 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 "unknownevent.h" + +#include <QtCore/QJsonDocument> + +using namespace QMatrixClient; + +class UnknownEvent::Private +{ + public: + QString type; + QString content; +}; + +UnknownEvent::UnknownEvent() + : Event(EventType::Unknown) + , d(new Private) +{ +} + +UnknownEvent::~UnknownEvent() +{ + delete d; +} + +QString UnknownEvent::typeString() const +{ + return d->type; +} + +QString UnknownEvent::content() const +{ + return d->content; +} + +UnknownEvent* UnknownEvent::fromJson(const QJsonObject& obj) +{ + UnknownEvent* e = new UnknownEvent(); + e->parseJson(obj); + e->d->type = obj.value("type").toString(); + e->d->content = QString::fromUtf8(QJsonDocument(obj).toJson()); + return e; +}
\ No newline at end of file diff --git a/events/unknownevent.h b/events/unknownevent.h new file mode 100644 index 00000000..58493095 --- /dev/null +++ b/events/unknownevent.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * 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 + */ + +#ifndef QMATRIXCLIENT_UNKNOWNEVENT_H +#define QMATRIXCLIENT_UNKNOWNEVENT_H + +#include "event.h" + +namespace QMatrixClient +{ + class UnknownEvent: public Event + { + public: + UnknownEvent(); + virtual ~UnknownEvent(); + + QString typeString() const; + QString content() const; + + static UnknownEvent* fromJson(const QJsonObject& obj); + + private: + class Private; + Private* d; + }; +} + +#endif // QMATRIXCLIENT_UNKNOWNEVENT_H
\ No newline at end of file |