add ReceivedBy

This commit is contained in:
Green Sky 2024-04-20 15:10:37 +02:00
parent 1409485ef1
commit 1a3fcc6757
No known key found for this signature in database
2 changed files with 35 additions and 1 deletions

View File

@ -14,7 +14,12 @@ namespace Message::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ContactFrom, c)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ContactTo, c)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Read, ts)
// TODO: SyncedBy
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ReceivedBy, ts)
// ReadBy
// SyncedBy
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MessageText, text)
// TODO: remove
@ -27,3 +32,27 @@ namespace Message::Components {
} // Message::Components
namespace entt {
// is this really not needed?
//template<typename Key, typename Value>
//inline void to_json(nlohmann::json& j, const dense_map<Key, Value>& m) {
//}
// TODO: using the internal stuff might be bad for abi
template<typename Key, typename Value>
inline void from_json(const nlohmann::json& j, dense_map<Key, Value>& m) {
if (!j.is_array()) {
throw (nlohmann::detail::type_error::create(302, nlohmann::detail::concat("type must be array, but is ", j.type_name()), &j));
}
m.clear();
for (const auto& p : j) {
if (!p.is_array()) {
throw (nlohmann::detail::type_error::create(302, nlohmann::detail::concat("type must be array, but is ", p.type_name()), &j));
}
m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
}
}
} // entt

View File

@ -13,10 +13,15 @@ void registerMessageComponents(MessageSerializerNJ& msnj) {
msnj.registerDeserializer<Message::Components::ContactFrom>();
msnj.registerSerializer<Message::Components::ContactTo>();
msnj.registerDeserializer<Message::Components::ContactTo>();
msnj.registerSerializer<Message::Components::TagUnread>();
msnj.registerDeserializer<Message::Components::TagUnread>();
msnj.registerSerializer<Message::Components::Read>();
msnj.registerDeserializer<Message::Components::Read>();
msnj.registerSerializer<Message::Components::ReceivedBy>();
msnj.registerDeserializer<Message::Components::ReceivedBy>();
msnj.registerSerializer<Message::Components::MessageText>();
msnj.registerDeserializer<Message::Components::MessageText>();
msnj.registerSerializer<Message::Components::TagMessageIsAction>();