diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 690523055..f5121b64c 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -3,7 +3,8 @@ * * * libretroshare: retroshare core library * * * - * Copyright 2012-2012 by Robert Fernie * + * Copyright (C) 2012 by Robert Fernie * + * Copyright (C) 2018 Gioacchino Mazzurco * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -19,61 +20,98 @@ * along with this program. If not, see . * * * *******************************************************************************/ -#ifndef RETROSHARE_GXS_FORUM_GUI_INTERFACE_H -#define RETROSHARE_GXS_FORUM_GUI_INTERFACE_H +#pragma once -#include +#include #include #include #include "retroshare/rstokenservice.h" #include "retroshare/rsgxsifacehelper.h" #include "serialiser/rstlvidset.h" +#include "serialiser/rsserializable.h" -// Forum Service message flags, to be used in RsMsgMetaData::mMsgFlags -// Gxs imposes to use the first two bytes (lower bytes) of mMsgFlags for private forum flags, the upper bytes being used for internal GXS stuff. - -static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MASK = 0x0000000f ; -static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001 ; - -#define IS_FORUM_MSG_MODERATION(flags) (flags & RS_GXS_FORUM_MSG_FLAGS_MODERATED) /* The Main Interface Class - for information about your Peers */ class RsGxsForums; -extern RsGxsForums *rsGxsForums; -class RsGxsForumGroup +/** + * Pointer to global instance of RsGxsChannels service implementation + * @jsonapi{development} + */ +extern RsGxsForums* rsGxsForums; + + +/** Forum Service message flags, to be used in RsMsgMetaData::mMsgFlags + * Gxs imposes to use the first two bytes (lower bytes) of mMsgFlags for + * private forum flags, the upper bytes being used for internal GXS stuff. + */ +static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MASK = 0x0000000f; +static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001; + +#define IS_FORUM_MSG_MODERATION(flags) (flags & RS_GXS_FORUM_MSG_FLAGS_MODERATED) + + +struct RsGxsForumGroup : RsSerializable { - public: RsGroupMetaData mMeta; std::string mDescription; - // What's below is optional, and handled by the serialiser + /* 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! */ + RsTlvGxsIdSet mAdminList; + RsTlvGxsMsgIdSet mPinnedPosts; - 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); + } }; -class RsGxsForumMsg +struct RsGxsForumMsg : RsSerializable { - public: RsMsgMetaData mMeta; std::string mMsg; + + /// @see RsSerializable + virtual void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) + { + RS_SERIAL_PROCESS(mMeta); + RS_SERIAL_PROCESS(mMsg); + } }; -//typedef std::map > GxsForumMsgResult; - -std::ostream &operator<<(std::ostream &out, const RsGxsForumGroup &group); -std::ostream &operator<<(std::ostream &out, const RsGxsForumMsg &msg); - class RsGxsForums: public RsGxsIfaceHelper { public: - explicit RsGxsForums(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {} virtual ~RsGxsForums() {} + /** + * @brief Create forum. Blocking API. + * @jsonapi{development} + * @param[inout] forum Forum data (name, description...) + * @return false on error, true otherwise + */ + virtual bool createForum(RsGxsForumGroup& forum) = 0; + + /** + * @brief Create forum message. Blocking API. + * @jsonapi{development} + * @param[inout] message + * @return false on error, true otherwise + */ + virtual bool createMessage(RsGxsForumMsg& message) = 0; + + /* Specific Service Data */ virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; virtual bool getMsgData(const uint32_t &token, std::vector &msgs) = 0; @@ -89,8 +127,12 @@ public: //virtual bool groupRestoreKeys(const std::string &groupId); //virtual bool groupShareKeys(const std::string &groupId, std::list& peers); + RS_DEPRECATED_FOR(createForum) virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group) = 0; + + RS_DEPRECATED_FOR(createMessage) virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg) = 0; + /*! * To update forum group with new information * @param token the token used to check completion status of update @@ -98,9 +140,5 @@ public: * @return false groupId not set, true if set and accepted (still check token for completion) */ virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group) = 0; - }; - - -#endif diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index ccee5ba71..f913b5e1f 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -379,6 +379,33 @@ bool p3GxsForums::getMsgData(const uint32_t &token, std::vector & /********************************************************************************************/ +bool p3GxsForums::createForum(RsGxsForumGroup& forum) +{ + uint32_t token; + if(!createGroup(token, forum)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failed creating group." + << std::endl; + return false; + } + + if(waitToken(token) != RsTokenService::COMPLETE) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed." + << std::endl; + return false; + } + + if(!RsGenExchange::getPublishedGroupMeta(token, forum.mMeta)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting updated " + << " group data." << std::endl; + return false; + } + + return true; +} + bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group) { std::cerr << "p3GxsForums::createGroup()" << std::endl; @@ -407,6 +434,17 @@ bool p3GxsForums::updateGroup(uint32_t &token, RsGxsForumGroup &group) return true; } +bool p3GxsForums::createMessage(RsGxsForumMsg& message) +{ + uint32_t token; + if( !createMsg(token, message) + || waitToken(token) != RsTokenService::COMPLETE ) return false; + + if(RsGenExchange::getPublishedMsgMeta(token, message.mMeta)) return true; + + return false; +} + bool p3GxsForums::createMsg(uint32_t &token, RsGxsForumMsg &msg) { std::cerr << "p3GxsForums::createForumMsg() GroupId: " << msg.mMeta.mGroupId; diff --git a/libretroshare/src/services/p3gxsforums.h b/libretroshare/src/services/p3gxsforums.h index ef3dd46d8..3e88d0cb3 100644 --- a/libretroshare/src/services/p3gxsforums.h +++ b/libretroshare/src/services/p3gxsforums.h @@ -74,6 +74,9 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI //virtual bool groupRestoreKeys(const std::string &groupId); //virtual bool groupShareKeys(const std::string &groupId, std::list& peers); + virtual bool createForum(RsGxsForumGroup& forum); + virtual bool createMessage(RsGxsForumMsg& message); + virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group); virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg);