diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index a1dbdf83c..474136466 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -3,7 +3,8 @@ * * * libretroshare: retroshare core library * * * - * Copyright 2008-2012 by Robert Fernie, Christopher Evi-Parker * + * Copyright (C) 2008-2012 Robert Fernie, Christopher Evi-Parker * + * Copyright (C) 2020 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,8 +20,7 @@ * along with this program. If not, see . * * * *******************************************************************************/ -#ifndef RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H -#define RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H +#pragma once #include #include @@ -32,20 +32,62 @@ #include "retroshare/rsgxscommon.h" #include "serialiser/rsserializable.h" -/* The Main Interface Class - for information about your Posted */ class RsPosted; -extern RsPosted *rsPosted; -class RsPostedPost; -class RsPostedGroup +/** + * Pointer to global instance of RsGxsChannels service implementation + * @jsonapi{development} + */ +extern RsPosted* rsPosted; + +struct RsPostedGroup { - public: - RsPostedGroup() { return; } - RsGroupMetaData mMeta; std::string mDescription; RsGxsImage mGroupImage; +}; +struct RsPostedPost +{ + RsPostedPost(): mHaveVoted(false), mUpVotes(0), mDownVotes(0), mComments(0), + mHotScore(0), mTopScore(0), mNewScore(0) {} + + bool calculateScores(rstime_t ref_time); + + RsMsgMetaData mMeta; + std::string mLink; + std::string mNotes; + + bool mHaveVoted; + + // Calculated. + uint32_t mUpVotes; + uint32_t mDownVotes; + uint32_t mComments; + + + // and Calculated Scores:??? + double mHotScore; + double mTopScore; + double mNewScore; + + RsGxsImage mImage; + + /// @see RsSerializable + /*virtual void serial_process( RsGenericSerializer::SerializeJob j, + RsGenericSerializer::SerializeContext& ctx ) + { + RS_SERIAL_PROCESS(mImage); + RS_SERIAL_PROCESS(mMeta); + RS_SERIAL_PROCESS(mLink); + RS_SERIAL_PROCESS(mHaveVoted); + RS_SERIAL_PROCESS(mUpVotes); + RS_SERIAL_PROCESS(mDownVotes); + RS_SERIAL_PROCESS(mComments); + RS_SERIAL_PROCESS(mHotScore); + RS_SERIAL_PROCESS(mTopScore); + RS_SERIAL_PROCESS(mNewScore); + }*/ }; @@ -65,9 +107,6 @@ class RsPostedGroup #define RSPOSTED_VIEWMODE_COMMENTS 4 -std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group); -std::ostream &operator<<(std::ostream &out, const RsPostedPost &post); - enum class RsPostedEventCode: uint8_t { UNKNOWN = 0x00, @@ -98,25 +137,41 @@ struct RsGxsPostedEvent: RsEvent RS_SERIAL_PROCESS(mPostedGroupId); RS_SERIAL_PROCESS(mPostedMsgId); } + + ~RsGxsPostedEvent() override; }; class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService { - public: - - enum RankType {TopRankType, HotRankType, NewRankType }; - - //static const uint32_t FLAG_MSGTYPE_POST; - //static const uint32_t FLAG_MSGTYPE_MASK; - +public: explicit RsPosted(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {} - virtual ~RsPosted() {} - /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; -virtual bool getPostData(const uint32_t &token, std::vector &posts, std::vector &cmts) = 0; -virtual bool getPostData(const uint32_t &token, std::vector &posts) = 0; -//Not currently used + virtual bool getBoardsInfo( + const std::list& boardsIds, + std::vector& boardsInfo ) = 0; + + virtual bool getBoardContent( + const RsGxsGroupId& boardId, + const std::set& contentsIds, + std::vector& posts, + std::vector& comments ) = 0; + + enum RS_DEPRECATED RankType {TopRankType, HotRankType, NewRankType }; + + RS_DEPRECATED_FOR(getBoardsInfo) + virtual bool getGroupData( const uint32_t& token, + std::vector &groups ) = 0; + + RS_DEPRECATED_FOR(getBoardsContent) + virtual bool getPostData( + const uint32_t& token, std::vector& posts, + std::vector& cmts) = 0; + + RS_DEPRECATED_FOR(getBoardsContent) + virtual bool getPostData( + const uint32_t& token, std::vector& posts) = 0; + + //Not currently used //virtual bool getRelatedPosts(const uint32_t &token, std::vector &posts) = 0; /* From RsGxsCommentService */ @@ -134,62 +189,6 @@ virtual bool createPost(uint32_t &token, RsPostedPost &post) = 0; virtual bool updateGroup(uint32_t &token, RsPostedGroup &group) = 0; virtual bool groupShareKeys(const RsGxsGroupId& group,const std::set& peers) = 0 ; + + virtual ~RsPosted(); }; - - -class RsPostedPost -{ - public: - RsPostedPost() - { - //mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST; - mUpVotes = 0; - mDownVotes = 0; - mComments = 0; - mHaveVoted = false; - - mHotScore = 0; - mTopScore = 0; - mNewScore = 0; - } - - bool calculateScores(rstime_t ref_time); - - RsMsgMetaData mMeta; - std::string mLink; - std::string mNotes; - - bool mHaveVoted; - - // Calculated. - uint32_t mUpVotes; - uint32_t mDownVotes; - uint32_t mComments; - - - // and Calculated Scores:??? - double mHotScore; - double mTopScore; - double mNewScore; - - RsGxsImage mImage; - - /// @see RsSerializable - /*virtual void serial_process( RsGenericSerializer::SerializeJob j, - RsGenericSerializer::SerializeContext& ctx ) - { - RS_SERIAL_PROCESS(mImage); - RS_SERIAL_PROCESS(mMeta); - RS_SERIAL_PROCESS(mLink); - RS_SERIAL_PROCESS(mHaveVoted); - RS_SERIAL_PROCESS(mUpVotes); - RS_SERIAL_PROCESS(mDownVotes); - RS_SERIAL_PROCESS(mComments); - RS_SERIAL_PROCESS(mHotScore); - RS_SERIAL_PROCESS(mTopScore); - RS_SERIAL_PROCESS(mNewScore); - }*/ -}; - - -#endif // RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index 1a1efe0b6..0eed0965e 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -30,7 +30,7 @@ * #define POSTED_DEBUG 1 ****/ -RsPosted *rsPosted = NULL; +/*extern*/ RsPosted* rsPosted = nullptr; /********************************************************************************/ /******************* Startup / Tick ******************************************/ @@ -300,4 +300,35 @@ bool p3Posted::createPost(uint32_t &token, RsPostedPost &msg) return true; } -/********************************************************************************************/ +bool p3Posted::getBoardsInfo( + const std::list& boardsIds, + std::vector& channelsInfo ) +{ + uint32_t token; + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; + if( !requestGroupInfo(token, opts, boardsIds) + || waitToken(token) != RsTokenService::COMPLETE ) return false; + return getGroupData(token, channelsInfo) && !channelsInfo.empty(); +} + +bool p3Posted::getBoardContent( const RsGxsGroupId& channelId, + const std::set& contentsIds, + std::vector& posts, + std::vector& comments ) +{ + uint32_t token; + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; + + GxsMsgReq msgIds; + msgIds[channelId] = contentsIds; + + if( !requestMsgInfo(token, opts, msgIds) || + waitToken(token) != RsTokenService::COMPLETE ) return false; + + return getPostData(token, posts, comments); +} + +RsPosted::~RsPosted() = default; +RsGxsPostedEvent::~RsGxsPostedEvent() = default; diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index 402f69298..b8674e242 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -39,12 +39,12 @@ class p3Posted: public p3PostBase, public RsPosted { - public: +public: p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs); -virtual RsServiceInfo getServiceInfo(); + virtual RsServiceInfo getServiceInfo(); - protected: +protected: virtual void notifyChanges(std::vector& changes) { @@ -58,8 +58,17 @@ virtual void receiveHelperChanges(std::vector& changes) return RsGxsIfaceHelper::receiveChanges(changes); } - // Posted Specific DataTypes. -virtual bool getGroupData(const uint32_t &token, std::vector &groups); + bool getBoardsInfo( + const std::list& boardsIds, + std::vector& channelsInfo ) override; + + bool getBoardContent( + const RsGxsGroupId& boardId, + const std::set& contentsIds, + std::vector& posts, + std::vector& comments ) override; + + virtual bool getGroupData(const uint32_t &token, std::vector &groups); virtual bool getPostData(const uint32_t &token, std::vector &posts, std::vector &cmts); virtual bool getPostData(const uint32_t &token, std::vector &posts) { std::vector cmts; return getPostData( token, posts, cmts);} //Not currently used