From cc8300a098c35d41d8e4b88c3905c030ef288ac6 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Thu, 25 Jul 2019 14:14:42 +0200 Subject: [PATCH] Workaround JSON API opacity of RsTlv*Set in RsGxsForumGroup JSON API user would bet an unusable base64 blob due to RsTlv opaque JSON serialization, this way the content of the set is serialized plainly so it is usable through JSON API, without breaking binary serialization compatibility. We must stop using those RsTlv derived items. --- libretroshare/src/retroshare/rsgxsforums.h | 19 ++++--------- libretroshare/src/services/p3gxsforums.cc | 31 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 1c95bed87..19a80b011 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -59,25 +59,17 @@ struct RsGxsForumGroup : RsSerializable RsGroupMetaData mMeta; std::string mDescription; - /* What's below is optional, and handled by the serialiser - * TODO: run away from TLV old serializables as those types are opaque to - * JSON API! */ + /* TODO: run away from TLV old serializables as those types are opaque to + * JSON API! */ RsTlvGxsIdSet mAdminList; RsTlvGxsMsgIdSet mPinnedPosts; /// @see RsSerializable virtual void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx ) - { - RS_SERIAL_PROCESS(mMeta); - RS_SERIAL_PROCESS(mDescription); - RS_SERIAL_PROCESS(mAdminList); - RS_SERIAL_PROCESS(mPinnedPosts); - } + RsGenericSerializer::SerializeContext& ctx ); - // utility functions - - bool canEditPosts(const RsGxsId& id) const { return mAdminList.ids.find(id) != mAdminList.ids.end() || id == mMeta.mAuthorId; } + /// utility functions + bool canEditPosts(const RsGxsId& id) const; }; struct RsGxsForumMsg : RsSerializable @@ -203,4 +195,3 @@ public: RS_DEPRECATED_FOR(editForum) virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group) = 0; }; - diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index 07f91e33f..e82a5a5e0 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -813,3 +813,34 @@ void p3GxsForums::handle_event(uint32_t event_type, const std::string &/*elabel* break; } } + +void RsGxsForumGroup::serial_process( + RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) +{ + RS_SERIAL_PROCESS(mMeta); + RS_SERIAL_PROCESS(mDescription); + + /* Work around to have usable JSON API, without breaking binary + * serialization retrocompatibility */ + switch (j) + { + case RsGenericSerializer::TO_JSON: // fallthrough + case RsGenericSerializer::FROM_JSON: + RsTypeSerializer::serial_process( j, ctx, + mAdminList.ids, "mAdminList" ); + RsTypeSerializer::serial_process( j, ctx, + mPinnedPosts.ids, "mPinnedPosts" ); + break; + default: + RS_SERIAL_PROCESS(mAdminList); + RS_SERIAL_PROCESS(mPinnedPosts); + } +} + +bool RsGxsForumGroup::canEditPosts(const RsGxsId& id) const +{ + return mAdminList.ids.find(id) != mAdminList.ids.end() || + id == mMeta.mAuthorId; +} +