Skip to content
Snippets Groups Projects
Select Git revision
  • 1c31a8072f09a454b9239e11740473c8a7dbee39
  • master default protected
  • test-ci
  • cat-fix-ssss
  • reportContent
  • effects_overhaul
  • ducktyping2
  • ducktyping
  • confetti
  • pushrules
  • cpp20
  • run-ci
  • fallbackkeys
  • sy-up
  • create-room-improv
  • v0.6.x
  • shhh
  • summaries
  • release-staging
  • update-synapse
  • fix-docs
  • v0.10.1
  • v0.10.0
  • v0.9.2
  • v0.9.1
  • v0.9.0
  • v0.8.2
  • v0.8.1
  • v0.8.0
  • v0.7.0
  • v0.6.2
  • v0.6.1
  • v0.6.0
  • v0.5.1
  • v0.5.0
  • v0.4.1
  • v0.4.0
  • v0.3.1
  • v0.3.0
  • v0.3.0-rc1
  • v0.2.1
41 results

notice.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    notice.cpp 1.03 KiB
    #include <nlohmann/json.hpp>
    #include <string>
    
    #include "mtx/events/common.hpp"
    #include "mtx/events/messages/notice.hpp"
    
    using json = nlohmann::json;
    
    namespace mtx {
    namespace events {
    namespace msg {
    
    void
    from_json(const json &obj, Notice &content)
    {
        content.body    = obj.at("body").get<std::string>();
        content.msgtype = obj.at("msgtype").get<std::string>();
    
        if (obj.count("format") != 0)
            content.format = obj.at("format").get<std::string>();
    
        if (obj.count("formatted_body") != 0)
            content.formatted_body = obj.at("formatted_body").get<std::string>();
    
        content.relations = common::parse_relations(obj);
    }
    
    void
    to_json(json &obj, const Notice &content)
    {
        obj["msgtype"] = "m.notice";
        obj["body"]    = content.body;
    
        if (!content.formatted_body.empty()) {
            obj["format"]         = mtx::common::FORMAT_MSG_TYPE;
            obj["formatted_body"] = content.formatted_body;
        }
    
        common::apply_relations(obj, content.relations);
    }
    
    } // namespace msg
    } // namespace events
    } // namespace mtx