forked from mirror/nheko
- Rooms without any history will be shown. - Room's state will be kept in sync and any updates will be visible.remotes/origin/HEAD
parent
8825e072f2
commit
1f90c58076
@ -0,0 +1,63 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef ROOM_STATE_H |
||||
#define ROOM_STATE_H |
||||
|
||||
#include <QPixmap> |
||||
|
||||
#include "AliasesEventContent.h" |
||||
#include "AvatarEventContent.h" |
||||
#include "CanonicalAliasEventContent.h" |
||||
#include "CreateEventContent.h" |
||||
#include "HistoryVisibilityEventContent.h" |
||||
#include "JoinRulesEventContent.h" |
||||
#include "NameEventContent.h" |
||||
#include "PowerLevelsEventContent.h" |
||||
#include "TopicEventContent.h" |
||||
|
||||
#include "Event.h" |
||||
#include "RoomEvent.h" |
||||
#include "StateEvent.h" |
||||
|
||||
namespace events = matrix::events; |
||||
|
||||
class RoomState |
||||
{ |
||||
public: |
||||
QString resolveName() const; |
||||
inline QString resolveTopic() const; |
||||
|
||||
QPixmap avatar_img_; |
||||
|
||||
events::StateEvent<events::AliasesEventContent> aliases; |
||||
events::StateEvent<events::AvatarEventContent> avatar; |
||||
events::StateEvent<events::CanonicalAliasEventContent> canonical_alias; |
||||
events::StateEvent<events::CreateEventContent> create; |
||||
events::StateEvent<events::HistoryVisibilityEventContent> history_visibility; |
||||
events::StateEvent<events::JoinRulesEventContent> join_rules; |
||||
events::StateEvent<events::NameEventContent> name; |
||||
events::StateEvent<events::PowerLevelsEventContent> power_levels; |
||||
events::StateEvent<events::TopicEventContent> topic; |
||||
}; |
||||
|
||||
inline QString RoomState::resolveTopic() const |
||||
{ |
||||
return topic.content().topic().simplified(); |
||||
} |
||||
|
||||
#endif // ROOM_STATE_H
|
@ -0,0 +1,67 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef MATRIX_MESSAGE_EVENT_H |
||||
#define MATRIX_MESSAGE_EVENT_H |
||||
|
||||
#include "MessageEventContent.h" |
||||
#include "RoomEvent.h" |
||||
|
||||
namespace matrix |
||||
{ |
||||
namespace events |
||||
{ |
||||
template <class MsgContent> |
||||
class MessageEvent : public RoomEvent<MessageEventContent> |
||||
{ |
||||
public: |
||||
inline MsgContent msgContent() const; |
||||
|
||||
void deserialize(const QJsonValue &data) override; |
||||
|
||||
private: |
||||
MsgContent msg_content_; |
||||
}; |
||||
|
||||
template <class MsgContent> |
||||
inline MsgContent MessageEvent<MsgContent>::msgContent() const |
||||
{ |
||||
return msg_content_; |
||||
} |
||||
|
||||
template <class MsgContent> |
||||
void MessageEvent<MsgContent>::deserialize(const QJsonValue &data) |
||||
{ |
||||
RoomEvent<MessageEventContent>::deserialize(data); |
||||
|
||||
msg_content_.deserialize(data.toObject().value("content").toObject()); |
||||
} |
||||
|
||||
namespace messages |
||||
{ |
||||
struct ThumbnailInfo { |
||||
int h; |
||||
int w; |
||||
int size; |
||||
|
||||
QString mimetype; |
||||
}; |
||||
} // namespace messages
|
||||
} // namespace events
|
||||
} // namespace matrix
|
||||
|
||||
#endif // MATRIX_MESSAGE_EVENT_H
|
@ -0,0 +1,78 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef MESSAGE_EVENT_CONTENT_H |
||||
#define MESSAGE_EVENT_CONTENT_H |
||||
|
||||
#include <QJsonValue> |
||||
|
||||
#include "Deserializable.h" |
||||
|
||||
namespace matrix |
||||
{ |
||||
namespace events |
||||
{ |
||||
enum MessageEventType { |
||||
// m.audio
|
||||
Audio, |
||||
|
||||
// m.emote
|
||||
Emote, |
||||
|
||||
// m.file
|
||||
File, |
||||
|
||||
// m.image
|
||||
Image, |
||||
|
||||
// m.location
|
||||
Location, |
||||
|
||||
// m.notice
|
||||
Notice, |
||||
|
||||
// m.text
|
||||
Text, |
||||
|
||||
// m.video
|
||||
Video, |
||||
|
||||
// Unrecognized message type
|
||||
Unknown, |
||||
}; |
||||
|
||||
MessageEventType extractMessageEventType(const QJsonObject &data); |
||||
|
||||
class MessageEventContent : public Deserializable |
||||
{ |
||||
public: |
||||
void deserialize(const QJsonValue &data) override; |
||||
|
||||
inline QString body() const; |
||||
|
||||
private: |
||||
QString body_; |
||||
}; |
||||
|
||||
inline QString MessageEventContent::body() const |
||||
{ |
||||
return body_; |
||||
} |
||||
} // namespace events
|
||||
} // namespace matrix
|
||||
|
||||
#endif // MESSAGE_EVENT_CONTENT_H
|
@ -0,0 +1,76 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef MESSAGE_EVENT_FILE_H |
||||
#define MESSAGE_EVENT_FILE_H |
||||
|
||||
#include <QJsonObject> |
||||
|
||||
#include "Deserializable.h" |
||||
#include "MessageEvent.h" |
||||
|
||||
namespace matrix |
||||
{ |
||||
namespace events |
||||
{ |
||||
namespace messages |
||||
{ |
||||
struct FileInfo { |
||||
int size; |
||||
|
||||
QString mimetype; |
||||
QString thumbnail_url; |
||||
ThumbnailInfo thumbnail_info; |
||||
}; |
||||
|
||||
class File : public Deserializable |
||||
{ |
||||
public: |
||||
inline QString url() const; |
||||
inline QString filename() const; |
||||
|
||||
inline FileInfo info() const; |
||||
|
||||
void deserialize(const QJsonObject &object) override; |
||||
|
||||
private: |
||||
QString url_; |
||||
QString filename_; |
||||
|
||||
FileInfo info_; |
||||
}; |
||||
|
||||
inline QString File::filename() const |
||||
{ |
||||
return filename_; |
||||
} |
||||
|
||||
inline QString File::url() const |
||||
{ |
||||
return url_; |
||||
} |
||||
|
||||
inline FileInfo File::info() const |
||||
{ |
||||
return info_; |
||||
} |
||||
|
||||
} // namespace messages
|
||||
} // namespace events
|
||||
} // namespace matrix
|
||||
|
||||
#endif // MESSAGE_EVENT_FILE_H
|
@ -0,0 +1,69 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef MESSAGE_EVENT_IMAGE_H |
||||
#define MESSAGE_EVENT_IMAGE_H |
||||
|
||||
#include <QJsonObject> |
||||
|
||||
#include "Deserializable.h" |
||||
#include "MessageEvent.h" |
||||
|
||||
namespace matrix |
||||
{ |
||||
namespace events |
||||
{ |
||||
namespace messages |
||||
{ |
||||
struct ImageInfo { |
||||
int h; |
||||
int w; |
||||
int size; |
||||
|
||||
QString mimetype; |
||||
QString thumbnail_url; |
||||
ThumbnailInfo thumbnail_info; |
||||
}; |
||||
|
||||
class Image : public Deserializable |
||||
{ |
||||
public: |
||||
inline QString url() const; |
||||
inline ImageInfo info() const; |
||||
|
||||
void deserialize(const QJsonObject &object) override; |
||||
|
||||
private: |
||||
QString url_; |
||||
ImageInfo info_; |
||||
}; |
||||
|
||||
inline QString Image::url() const |
||||
{ |
||||
return url_; |
||||
} |
||||
|
||||
inline ImageInfo Image::info() const |
||||
{ |
||||
return info_; |
||||
} |
||||
|
||||
} // namespace messages
|
||||
} // namespace events
|
||||
} // namespace matrix
|
||||
|
||||
#endif // MESSAGE_EVENT_IMAGE_H
|
@ -0,0 +1,65 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef MESSAGE_EVENT_LOCATION_H |
||||
#define MESSAGE_EVENT_LOCATION_H |
||||
|
||||
#include <QJsonObject> |
||||
|
||||
#include "Deserializable.h" |
||||
#include "MessageEvent.h" |
||||
|
||||
namespace matrix |
||||
{ |
||||
namespace events |
||||
{ |
||||
namespace messages |
||||
{ |
||||
struct LocationInfo { |
||||
QString thumbnail_url; |
||||
ThumbnailInfo thumbnail_info; |
||||
}; |
||||
|
||||
class Location : public Deserializable |
||||
{ |
||||
public: |
||||
inline QString geoUri() const; |
||||
inline LocationInfo info() const; |
||||
|
||||
void deserialize(const QJsonObject &object) override; |
||||
|
||||
private: |
||||
QString geo_uri_; |
||||
|
||||
LocationInfo info_; |
||||
}; |
||||
|
||||
inline QString Location::geoUri() const |
||||
{ |
||||
return geo_uri_; |
||||
} |
||||
|
||||
inline LocationInfo Location::info() const |
||||
{ |
||||
return info_; |
||||
} |
||||
|
||||
} // namespace messages
|
||||
} // namespace events
|
||||
} // namespace matrix
|
||||
|
||||
#endif // MESSAGE_EVENT_LOCATION_H
|
@ -0,0 +1,40 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef MESSAGE_EVENT_NOTICE_H |
||||
#define MESSAGE_EVENT_NOTICE_H |
||||
|
||||
#include <QJsonObject> |
||||
|
||||
#include "Deserializable.h" |
||||
|
||||
namespace matrix |
||||
{ |
||||
namespace events |
||||
{ |
||||
namespace messages |
||||
{ |
||||
class Notice : public Deserializable |
||||
{ |
||||
public: |
||||
void deserialize(const QJsonObject &obj) override; |
||||
}; |
||||
} // namespace messages
|
||||
} // namespace events
|
||||
} // namespace matrix
|
||||
|
||||
#endif // MESSAGE_EVENT_NOTICE_H
|
@ -0,0 +1,40 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef MESSAGE_EVENT_TEXT_H |
||||
#define MESSAGE_EVENT_TEXT_H |
||||
|
||||
#include <QJsonObject> |
||||
|
||||
#include "Deserializable.h" |
||||
|
||||
namespace matrix |
||||
{ |
||||
namespace events |
||||
{ |
||||
namespace messages |
||||
{ |
||||
class Text : public Deserializable |
||||
{ |
||||
public: |
||||
void deserialize(const QJsonObject &obj) override; |
||||
}; |
||||
} // namespace messages
|
||||
} // namespace events
|
||||
} // namespace matrix
|
||||
|
||||
#endif // MESSAGE_EVENT_TEXT_H
|
@ -0,0 +1,70 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef MESSAGE_EVENT_VIDEO_H |
||||
#define MESSAGE_EVENT_VIDEO_H |
||||
|
||||
#include <QJsonObject> |
||||
|
||||
#include "Deserializable.h" |
||||
#include "MessageEvent.h" |
||||
|
||||
namespace matrix |
||||
{ |
||||
namespace events |
||||
{ |
||||
namespace messages |
||||
{ |
||||
struct VideoInfo { |
||||
int h; |
||||
int w; |
||||
int size; |
||||
int duration; |
||||
|
||||
QString mimetype; |
||||
QString thumbnail_url; |
||||
ThumbnailInfo thumbnail_info; |
||||
}; |
||||
|
||||
class Video : public Deserializable |
||||
{ |
||||
public: |
||||
inline QString url() const; |
||||
inline VideoInfo info() const; |
||||
|
||||
void deserialize(const QJsonObject &object) override; |
||||
|
||||
private: |
||||
QString url_; |
||||
VideoInfo info_; |
||||
}; |
||||
|
||||
inline QString Video::url() const |
||||
{ |
||||
return url_; |
||||
} |
||||
|
||||
inline VideoInfo Video::info() const |
||||
{ |
||||
return info_; |
||||
} |
||||
|
||||
} // namespace messages
|
||||
} // namespace events
|
||||
} // namespace matrix
|
||||
|
||||
#endif // MESSAGE_EVENT_VIDEO_H
|
@ -0,0 +1,32 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "RoomState.h" |
||||
|
||||
QString RoomState::resolveName() const |
||||
{ |
||||
if (!name.content().name().isEmpty()) |
||||
return name.content().name().simplified(); |
||||
|
||||
if (!canonical_alias.content().alias().isEmpty()) |
||||
return canonical_alias.content().alias().simplified(); |
||||
|
||||
if (aliases.content().aliases().size() != 0) |
||||
return aliases.content().aliases()[0].simplified(); |
||||
|
||||
return "Unknown Room Name"; |
||||
} |
@ -0,0 +1,63 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include <QDebug> |
||||
|
||||
#include "MessageEventContent.h" |
||||
|
||||
using namespace matrix::events; |
||||
|
||||
MessageEventType matrix::events::extractMessageEventType(const QJsonObject &data) |
||||
{ |
||||
if (!data.contains("content")) |
||||
return MessageEventType::Unknown; |
||||
|
||||
auto content = data.value("content").toObject(); |
||||
auto msgtype = content.value("msgtype").toString(); |
||||
|
||||
if (msgtype == "m.audio") |
||||
return MessageEventType::Audio; |
||||
else if (msgtype == "m.emote") |
||||
return MessageEventType::Emote; |
||||
else if (msgtype == "m.file") |
||||
return MessageEventType::File; |
||||
else if (msgtype == "m.image") |
||||
return MessageEventType::Image; |
||||
else if (msgtype == "m.location") |
||||
return MessageEventType::Location; |
||||
else if (msgtype == "m.notice") |
||||
return MessageEventType::Notice; |
||||
else if (msgtype == "m.text") |
||||
return MessageEventType::Text; |
||||
else if (msgtype == "m.video") |
||||
return MessageEventType::Video; |
||||
else |
||||
return MessageEventType::Unknown; |
||||
} |
||||
|
||||
void MessageEventContent::deserialize(const QJsonValue &data) |
||||
{ |
||||
if (!data.isObject()) |
||||
throw DeserializationException("MessageEventContent is not a JSON object"); |
||||
|
||||
auto object = data.toObject(); |
||||
|
||||
if (!object.contains("body")) |
||||
throw DeserializationException("body key is missing"); |
||||
|
||||
body_ = object.value("body").toString(); |
||||
} |
@ -0,0 +1,39 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "Audio.h" |
||||
|
||||
using namespace matrix::events::messages; |
||||
|
||||
void Audio::deserialize(const QJsonObject &object) |
||||
{ |
||||
if (!object.contains("url")) |
||||
throw DeserializationException("url key is missing"); |
||||
|
||||
url_ = object.value("url").toString(); |
||||
|
||||
if (object.value("msgtype") != "m.audio") |
||||
throw DeserializationException("invalid msgtype for audio"); |
||||
|
||||
if (object.contains("info")) { |
||||
auto info = object.value("info").toObject(); |
||||
|
||||
info_.duration = info.value("duration").toInt(); |
||||
info_.mimetype = info.value("mimetype").toString(); |
||||
info_.size = info.value("size").toInt(); |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "Emote.h" |
||||
|
||||
using namespace matrix::events::messages; |
||||
|
||||
void Emote::deserialize(const QJsonObject &object) |
||||
{ |
||||
if (object.value("msgtype") != "m.emote") |
||||
throw DeserializationException("invalid msgtype for emote"); |
||||
} |
@ -0,0 +1,51 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "File.h" |
||||
|
||||
using namespace matrix::events::messages; |
||||
|
||||
void File::deserialize(const QJsonObject &object) |
||||
{ |
||||
if (!object.contains("url")) |
||||
throw DeserializationException("messages::File url key is missing"); |
||||
|
||||
if (!object.contains("filename")) |
||||
throw DeserializationException("messages::File filename key is missing"); |
||||
|
||||
if (object.value("msgtype") != "m.file") |
||||
throw DeserializationException("invalid msgtype for file"); |
||||
|
||||
url_ = object.value("url").toString(); |
||||
|
||||
if (object.contains("info")) { |
||||
auto file_info = object.value("info").toObject(); |
||||
|
||||
info_.size = file_info.value("size").toInt(); |
||||
info_.mimetype = file_info.value("mimetype").toString(); |
||||
info_.thumbnail_url = file_info.value("thumbnail_url").toString(); |
||||
|
||||
if (file_info.contains("thumbnail_info")) { |
||||
auto thumbinfo = file_info.value("thumbnail_info").toObject(); |
||||
|
||||
info_.thumbnail_info.h = thumbinfo.value("h").toInt(); |
||||
info_.thumbnail_info.w = thumbinfo.value("w").toInt(); |
||||
info_.thumbnail_info.size = thumbinfo.value("size").toInt(); |
||||
info_.thumbnail_info.mimetype = thumbinfo.value("mimetype").toString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "Image.h" |
||||
|
||||
using namespace matrix::events::messages; |
||||
|
||||
void Image::deserialize(const QJsonObject &object) |
||||
{ |
||||
if (!object.contains("url")) |
||||
throw DeserializationException("messages::Image url key is missing"); |
||||
|
||||
url_ = object.value("url").toString(); |
||||
|
||||
if (object.value("msgtype") != "m.image") |
||||
throw DeserializationException("invalid msgtype for image"); |
||||
|
||||
if (object.contains("info")) { |
||||
auto imginfo = object.value("info").toObject(); |
||||
|
||||
info_.w = imginfo.value("w").toInt(); |
||||
info_.h = imginfo.value("h").toInt(); |
||||
info_.size = imginfo.value("size").toInt(); |
||||
|
||||
info_.mimetype = imginfo.value("mimetype").toString(); |
||||
info_.thumbnail_url = imginfo.value("thumbnail_url").toString(); |
||||
|
||||
if (imginfo.contains("thumbnail_info")) { |
||||
auto thumbinfo = imginfo.value("thumbnail_info").toObject(); |
||||
|
||||
info_.thumbnail_info.h = thumbinfo.value("h").toInt(); |
||||
info_.thumbnail_info.w = thumbinfo.value("w").toInt(); |
||||
info_.thumbnail_info.size = thumbinfo.value("size").toInt(); |
||||
info_.thumbnail_info.mimetype = thumbinfo.value("mimetype").toString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "Location.h" |
||||
|
||||
using namespace matrix::events::messages; |
||||
|
||||
void Location::deserialize(const QJsonObject &object) |
||||
{ |
||||
if (!object.contains("geo_uri")) |
||||
throw DeserializationException("messages::Location geo_uri key is missing"); |
||||
|
||||
if (object.value("msgtype") != "m.location") |
||||
throw DeserializationException("invalid msgtype for location"); |
||||
|
||||
geo_uri_ = object.value("geo_uri").toString(); |
||||
|
||||
if (object.contains("info")) { |
||||
auto location_info = object.value("info").toObject(); |
||||
|
||||
info_.thumbnail_url = location_info.value("thumbnail_url").toString(); |
||||
|
||||
if (location_info.contains("thumbnail_info")) { |
||||
auto thumbinfo = location_info.value("thumbnail_info").toObject(); |
||||
|
||||
info_.thumbnail_info.h = thumbinfo.value("h").toInt(); |
||||
info_.thumbnail_info.w = thumbinfo.value("w").toInt(); |
||||
info_.thumbnail_info.size = thumbinfo.value("size").toInt(); |
||||
info_.thumbnail_info.mimetype = thumbinfo.value("mimetype").toString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "Notice.h" |
||||
|
||||
using namespace matrix::events::messages; |
||||
|
||||
void Notice::deserialize(const QJsonObject &object) |
||||
{ |
||||
if (object.value("msgtype") != "m.notice") |
||||
throw DeserializationException("invalid msgtype for notice"); |
||||
} |
@ -0,0 +1,26 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "Text.h" |
||||
|
||||
using namespace matrix::events::messages; |
||||
|
||||
void Text::deserialize(const QJsonObject &object) |
||||
{ |
||||
if (object.value("msgtype") != "m.text") |
||||
throw DeserializationException("invalid msgtype for text"); |
||||
} |
@ -0,0 +1,52 @@ |
||||
/*
|
||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program 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 General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "Video.h" |
||||
|
||||
using namespace matrix::events::messages; |
||||
|
||||
void Video::deserialize(const QJsonObject &object) |
||||
{ |
||||
if (!object.contains("url")) |
||||
throw DeserializationException("messages::Video url key is missing"); |
||||
|
||||
url_ = object.value("url").toString(); |
||||
|
||||
if (object.value("msgtype") != "m.video") |
||||
throw DeserializationException("invalid msgtype for video"); |
||||
|
||||
if (object.contains("info")) { |
||||
auto video_info = object.value("info").toObject(); |
||||
|
||||
info_.w = video_info.value("w").toInt(); |
||||
info_.h = video_info.value("h").toInt(); |
||||
info_.size = video_info.value("size").toInt(); |
||||
info_.duration = video_info.value("duration").toInt(); |
||||
|
||||
info_.mimetype = video_info.value("mimetype").toString(); |
||||
info_.thumbnail_url = video_info.value("thumbnail_url").toString(); |
||||
|
||||
if (video_info.contains("thumbnail_info")) { |
||||
auto thumbinfo = video_info.value("thumbnail_info").toObject(); |
||||
|
||||
info_.thumbnail_info.h = thumbinfo.value("h").toInt(); |
||||
info_.thumbnail_info.w = thumbinfo.value("w").toInt(); |
||||
info_.thumbnail_info.size = thumbinfo.value("size").toInt(); |
||||
info_.thumbnail_info.mimetype = thumbinfo.value("mimetype").toString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,115 @@ |
||||
#include <gtest/gtest.h> |
||||
|
||||
#include <QJsonArray> |
||||
#include <QJsonObject> |
||||
|
||||
#include "Event.h" |
||||
#include "RoomEvent.h" |
||||
#include "StateEvent.h" |
||||
|
||||
#include "AliasesEventContent.h" |
||||
#include "AvatarEventContent.h" |
||||
#include "CanonicalAliasEventContent.h" |
||||
#include "CreateEventContent.h" |
||||
#include "HistoryVisibilityEventContent.h" |
||||
#include "JoinRulesEventContent.h" |
||||
#include "MemberEventContent.h" |
||||
#include "NameEventContent.h" |
||||
#include "PowerLevelsEventContent.h" |
||||
#include "TopicEventContent.h" |
||||
|
||||
using namespace matrix::events; |
||||
|
||||
TEST(EventCollection, Deserialize) |
||||
{ |
||||
auto events = QJsonArray{ |
||||
QJsonObject{ |
||||
{"content", QJsonObject{{"name", "Name"}}}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"prev_content", QJsonObject{{"name", "Previous Name"}}}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"state_key", ""}, |
||||
{"type", "m.room.name"}}, |
||||
QJsonObject{ |
||||
{"content", QJsonObject{{"topic", "Topic"}}}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"prev_content", QJsonObject{{"topic", "Previous Topic"}}}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"state_key", ""}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.topic"}}, |
||||
}; |
||||
|
||||
for (const auto &event : events) { |
||||
EventType ty = extractEventType(event.toObject()); |
||||
|
||||
if (ty == EventType::RoomName) { |
||||
StateEvent<NameEventContent> name_event; |
||||
name_event.deserialize(event); |
||||
|
||||
EXPECT_EQ(name_event.content().name(), "Name"); |
||||
EXPECT_EQ(name_event.previousContent().name(), "Previous Name"); |
||||
} else if (ty == EventType::RoomTopic) { |
||||
StateEvent<TopicEventContent> topic_event; |
||||
topic_event.deserialize(event); |
||||
|
||||
EXPECT_EQ(topic_event.content().topic(), "Topic"); |
||||
EXPECT_EQ(topic_event.previousContent().topic(), "Previous Topic"); |
||||
} else { |
||||
ASSERT_EQ(false, true); |
||||
} |
||||
} |
||||
} |
||||
|
||||
TEST(EventCollection, DeserializationException) |
||||
{ |
||||
// Using wrong event types.
|
||||
auto events = QJsonArray{ |
||||
QJsonObject{ |
||||
{"content", QJsonObject{{"name", "Name"}}}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"prev_content", QJsonObject{{"name", "Previous Name"}}}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"state_key", ""}, |
||||
{"type", "m.room.topic"}}, |
||||
QJsonObject{ |
||||
{"content", QJsonObject{{"topic", "Topic"}}}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"prev_content", QJsonObject{{"topic", "Previous Topic"}}}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"state_key", ""}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.name"}}, |
||||
}; |
||||
|
||||
for (const auto &event : events) { |
||||
EventType ty = extractEventType(event.toObject()); |
||||
|
||||
if (ty == EventType::RoomName) { |
||||
StateEvent<NameEventContent> name_event; |
||||
|
||||
try { |
||||
name_event.deserialize(event); |
||||
} catch (const DeserializationException &e) { |
||||
ASSERT_STREQ("name key is missing", e.what()); |
||||
} |
||||
|
||||
} else if (ty == EventType::RoomTopic) { |
||||
StateEvent<TopicEventContent> topic_event; |
||||
|
||||
try { |
||||
topic_event.deserialize(event); |
||||
} catch (const DeserializationException &e) { |
||||
ASSERT_STREQ("topic key is missing", e.what()); |
||||
} |
||||
} else { |
||||
ASSERT_EQ(false, true); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,311 @@ |
||||
#include <gtest/gtest.h> |
||||
|
||||
#include <QJsonArray> |
||||
#include <QJsonObject> |
||||
|
||||
#include "MessageEvent.h" |
||||
#include "MessageEventContent.h" |
||||
|
||||
#include "Audio.h" |
||||
#include "Emote.h" |
||||
#include "File.h" |
||||
#include "Image.h" |
||||
#include "Location.h" |
||||
#include "Notice.h" |
||||
#include "Text.h" |
||||
#include "Video.h" |
||||
|
||||
using namespace matrix::events; |
||||
|
||||
TEST(MessageEvent, Audio) |
||||
{ |
||||
auto info = QJsonObject{ |
||||
{"duration", 2140786}, |
||||
{"mimetype", "audio/mpeg"}, |
||||
{"size", 1563688}}; |
||||
|
||||
auto content = QJsonObject{ |
||||
{"body", "Bee Gees - Stayin' Alive"}, |
||||
{"msgtype", "m.audio"}, |
||||
{"url", "mxc://localhost/2sdfj23f33r3faad"}, |
||||
{"info", info}}; |
||||
|
||||
auto event = QJsonObject{ |
||||
{"content", content}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.message"}}; |
||||
|
||||
MessageEvent<messages::Audio> audio; |
||||
audio.deserialize(event); |
||||
|
||||
EXPECT_EQ(audio.msgContent().info().duration, 2140786); |
||||
EXPECT_EQ(audio.msgContent().info().size, 1563688); |
||||
EXPECT_EQ(audio.msgContent().info().mimetype, "audio/mpeg"); |
||||
EXPECT_EQ(audio.content().body(), "Bee Gees - Stayin' Alive"); |
||||
} |
||||
|
||||
TEST(MessageEvent, Emote) |
||||
{ |
||||
auto content = QJsonObject{ |
||||
{"body", "emote message"}, |
||||
{"msgtype", "m.emote"}}; |
||||
|
||||
auto event = QJsonObject{ |
||||
{"content", content}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.message"}}; |
||||
|
||||
MessageEvent<messages::Emote> emote; |
||||
emote.deserialize(event); |
||||
|
||||
EXPECT_EQ(emote.content().body(), "emote message"); |
||||
} |
||||
|
||||
TEST(MessageEvent, File) |
||||
{ |
||||
auto thumbnail_info = QJsonObject{ |
||||
{"h", 300}, |
||||
{"w", 400}, |
||||
{"size", 3432434}, |
||||
{"mimetype", "image/jpeg"}}; |
||||
|
||||
auto file_info = QJsonObject{ |
||||
{"size", 24242424}, |
||||
{"mimetype", "application/msword"}, |
||||
{"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, |
||||
{"thumbnail_info", thumbnail_info}}; |
||||
|
||||
auto content = QJsonObject{ |
||||
{"body", "something-important.doc"}, |
||||
{"filename", "something-important.doc"}, |
||||
{"url", "mxc://localhost/23d233d32r3r2r"}, |
||||
{"info", file_info}, |
||||
{"msgtype", "m.file"}}; |
||||
|
||||
auto event = QJsonObject{ |
||||
{"content", content}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.message"}}; |
||||
|
||||
MessageEvent<messages::File> file; |
||||
file.deserialize(event); |
||||
|
||||
EXPECT_EQ(file.content().body(), "something-important.doc"); |
||||
EXPECT_EQ(file.msgContent().info().thumbnail_info.h, 300); |
||||
EXPECT_EQ(file.msgContent().info().thumbnail_info.w, 400); |
||||
EXPECT_EQ(file.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); |
||||
EXPECT_EQ(file.msgContent().info().mimetype, "application/msword"); |
||||
EXPECT_EQ(file.msgContent().info().size, 24242424); |
||||
EXPECT_EQ(file.content().body(), "something-important.doc"); |
||||
} |
||||
|
||||
TEST(MessageEvent, Image) |
||||
{ |
||||
auto thumbinfo = QJsonObject{ |
||||
{"h", 11}, |
||||
{"w", 22}, |
||||
{"size", 212}, |
||||
{"mimetype", "img/jpeg"}, |
||||
}; |
||||
|
||||
auto imginfo = QJsonObject{ |
||||
{"h", 110}, |
||||
{"w", 220}, |
||||
{"size", 2120}, |
||||
{"mimetype", "img/jpeg"}, |
||||
{"thumbnail_url", "https://images.com/image-thumb.jpg"}, |
||||
{"thumbnail_info", thumbinfo}, |
||||
}; |
||||
|
||||
auto content = QJsonObject{ |
||||
{"body", "Image title"}, |
||||
{"msgtype", "m.image"}, |
||||
{"url", "https://images.com/image.jpg"}, |
||||
{"info", imginfo}}; |
||||
|
||||
auto event = QJsonObject{ |
||||
{"content", content}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.message"}}; |
||||
|
||||
MessageEvent<messages::Image> img; |
||||
img.deserialize(event); |
||||
|
||||
EXPECT_EQ(img.content().body(), "Image title"); |
||||
EXPECT_EQ(img.msgContent().info().h, 110); |
||||
EXPECT_EQ(img.msgContent().info().w, 220); |
||||
EXPECT_EQ(img.msgContent().info().thumbnail_info.w, 22); |
||||
EXPECT_EQ(img.msgContent().info().mimetype, "img/jpeg"); |
||||
EXPECT_EQ(img.msgContent().info().thumbnail_url, "https://images.com/image-thumb.jpg"); |
||||
} |
||||
|
||||
TEST(MessageEvent, Location) |
||||
{ |
||||
auto thumbnail_info = QJsonObject{ |
||||
{"h", 300}, |
||||
{"w", 400}, |
||||
{"size", 3432434}, |
||||
{"mimetype", "image/jpeg"}}; |
||||
|
||||
auto info = QJsonObject{ |
||||
{"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, |
||||
{"thumbnail_info", thumbnail_info}}; |
||||
|
||||
auto content = QJsonObject{ |
||||
{"body", "Big Ben, London, UK"}, |
||||
{"geo_uri", "geo:51.5008,0.1247"}, |
||||
{"info", info}, |
||||
{"msgtype", "m.location"}}; |
||||
|
||||
auto event = QJsonObject{ |
||||
{"content", content}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.message"}}; |
||||
|
||||
MessageEvent<messages::Location> location; |
||||
location.deserialize(event); |
||||
|
||||
EXPECT_EQ(location.msgContent().info().thumbnail_info.h, 300); |
||||
EXPECT_EQ(location.msgContent().info().thumbnail_info.w, 400); |
||||
EXPECT_EQ(location.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); |
||||
EXPECT_EQ(location.msgContent().info().thumbnail_url, "mxc://localhost/adfaefaFAFSDFF3"); |
||||
EXPECT_EQ(location.content().body(), "Big Ben, London, UK"); |
||||
} |
||||
|
||||
TEST(MessageEvent, Notice) |
||||
{ |
||||
auto content = QJsonObject{ |
||||
{"body", "notice message"}, |
||||
{"msgtype", "m.notice"}}; |
||||
|
||||
auto event = QJsonObject{ |
||||
{"content", content}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.message"}}; |
||||
|
||||
MessageEvent<messages::Notice> notice; |
||||
notice.deserialize(event); |
||||
|
||||
EXPECT_EQ(notice.content().body(), "notice message"); |
||||
} |
||||
|
||||
TEST(MessageEvent, Text) |
||||
{ |
||||
auto content = QJsonObject{ |
||||
{"body", "text message"}, |
||||
{"msgtype", "m.text"}}; |
||||
|
||||
auto event = QJsonObject{ |
||||
{"content", content}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.message"}}; |
||||
|
||||
MessageEvent<messages::Text> text; |
||||
text.deserialize(event); |
||||
|
||||
EXPECT_EQ(text.content().body(), "text message"); |
||||
} |
||||
|
||||
TEST(MessageEvent, Video) |
||||
{ |
||||
auto thumbnail_info = QJsonObject{ |
||||
{"h", 300}, |
||||
{"w", 400}, |
||||
{"size", 3432434}, |
||||
{"mimetype", "image/jpeg"}}; |
||||
|
||||
auto video_info = QJsonObject{ |
||||
{"h", 222}, |
||||
{"w", 333}, |
||||
{"duration", 232323}, |
||||
{"size", 24242424}, |
||||
{"mimetype", "video/mp4"}, |
||||
{"thumbnail_url", "mxc://localhost/adfaefaFAFSDFF3"}, |
||||
{"thumbnail_info", thumbnail_info}}; |
||||
|
||||
auto content = QJsonObject{ |
||||
{"body", "Gangnam Style"}, |
||||
{"url", "mxc://localhost/23d233d32r3r2r"}, |
||||
{"info", video_info}, |
||||
{"msgtype", "m.video"}}; |
||||
|
||||
auto event = QJsonObject{ |
||||
{"content", content}, |
||||
{"event_id", "$asdfafdf8af:matrix.org"}, |
||||
{"room_id", "!aasdfaeae23r9:matrix.org"}, |
||||
{"sender", "@alice:matrix.org"}, |
||||
{"origin_server_ts", 1323238293289323LL}, |
||||
{"type", "m.room.message"}}; |
||||
|
||||
MessageEvent<messages::Video> video; |
||||
video.deserialize(event); |
||||
|
||||
EXPECT_EQ(video.msgContent().info().thumbnail_info.h, 300); |
||||
EXPECT_EQ(video.msgContent().info().thumbnail_info.w, 400); |
||||
EXPECT_EQ(video.msgContent().info().thumbnail_info.mimetype, "image/jpeg"); |
||||
EXPECT_EQ(video.msgContent().info().duration, 232323); |
||||
EXPECT_EQ(video.msgContent().info().size, 24242424); |
||||
EXPECT_EQ(video.msgContent().info().mimetype, "video/mp4"); |
||||
EXPECT_EQ(video.content().body(), "Gangnam Style"); |
||||
} |
||||
|
||||
TEST(MessageEvent, Types) |
||||
{ |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.audio"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::Audio); |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.emote"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::Emote); |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.file"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::File); |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.image"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::Image); |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.location"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::Location); |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.notice"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::Notice); |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.text"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::Text); |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.video"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::Video); |
||||
EXPECT_EQ(extractMessageEventType(QJsonObject{ |
||||
{"content", QJsonObject{{"msgtype", "m.random"}}}, {"type", "m.room.message"}, |
||||
}), |
||||
MessageEventType::Unknown); |
||||
} |
Loading…
Reference in new issue