-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support location message type #88
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,35 @@ to_json(json &obj, const VideoInfo &info) | |
obj["xyz.amorgan.blurhash"] = info.blurhash; | ||
} | ||
|
||
void | ||
from_json(const json &obj, LocationInfo &info) | ||
{ | ||
if (obj.find("thumbnail_url") != obj.end()) | ||
info.thumbnail_url = obj.at("thumbnail_url").get<std::string>(); | ||
|
||
if (obj.find("thumbnail_info") != obj.end()) | ||
info.thumbnail_info = obj.at("thumbnail_info").get<ThumbnailInfo>(); | ||
|
||
if (obj.find("thumbnail_file") != obj.end()) | ||
info.thumbnail_file = obj.at("thumbnail_file").get<crypto::EncryptedFile>(); | ||
|
||
if (obj.find("xyz.amorgan.blurhash") != obj.end()) | ||
info.blurhash = obj.at("xyz.amorgan.blurhash").get<std::string>(); | ||
Comment on lines
+184
to
+185
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is wrong. I think only the thumbnail has a blurhash. |
||
} | ||
|
||
void | ||
to_json(json &obj, const LocationInfo &info) | ||
{ | ||
if (!info.thumbnail_url.empty()) { | ||
obj["thumbnail_url"] = info.thumbnail_url; | ||
obj["thumbnail_info"] = info.thumbnail_info; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be serialized when a thumbnail_url or a thumbnail_file is present. |
||
} | ||
if (info.thumbnail_file) | ||
obj["thumbnail_file"] = info.thumbnail_file.value(); | ||
if (!info.blurhash.empty()) | ||
obj["xyz.amorgan.blurhash"] = info.blurhash; | ||
Comment on lines
+197
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Also not existing, afaik) |
||
} | ||
|
||
void | ||
to_json(json &obj, const RelationType &type) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <nlohmann/json.hpp> | ||
#include <string> | ||
|
||
#include "mtx/events/common.hpp" | ||
#include "mtx/events/messages/location.hpp" | ||
|
||
using json = nlohmann::json; | ||
|
||
namespace mtx { | ||
namespace events { | ||
namespace msg { | ||
|
||
void | ||
from_json(const json &obj, Location &content) | ||
{ | ||
content.body = obj.at("body").get<std::string>(); | ||
content.msgtype = obj.at("msgtype").get<std::string>(); | ||
if (obj.find("geo_uri") != obj.end()) | ||
content.geo_uri = obj.at("geo_uri").get<std::string>(); | ||
|
||
if (obj.find("info") != obj.end()) | ||
content.info = obj.at("info").get<common::LocationInfo>(); | ||
|
||
content.relations = common::parse_relations(obj); | ||
} | ||
|
||
void | ||
to_json(json &obj, const Location &content) | ||
{ | ||
obj["msgtype"] = "m.location"; | ||
obj["body"] = content.body; | ||
|
||
obj["geo_uri"] = content.geo_uri; | ||
obj["info"] = content.info; | ||
common::apply_relations(obj, content.relations); | ||
} | ||
|
||
} // namespace msg | ||
} // namespace events | ||
} // namespace mtx |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -410,8 +410,8 @@ parse_timeline_events(const json &events, | |||||||
break; | ||||||||
} | ||||||||
case MsgType::Location: { | ||||||||
/* events::RoomEvent<events::msg::Location> location = e; */ | ||||||||
/* container.emplace_back(location); */ | ||||||||
events::RoomEvent<events::msg::Location> location = e; | ||||||||
container.emplace_back(location); | ||||||||
Comment on lines
+413
to
+414
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you write that in the style of the lines above, i.e.:
Suggested change
|
||||||||
break; | ||||||||
} | ||||||||
case MsgType::Notice: { | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can delete these.