mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Initial work on posted API
This commit is contained in:
parent
c9728cead0
commit
5604f7082b
@ -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 <gio@eigenlab.org> *
|
||||
* *
|
||||
* 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 <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H
|
||||
#define RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
@ -32,126 +32,25 @@
|
||||
#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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//#define RSPOSTED_MSGTYPE_POST 0x0001
|
||||
//#define RSPOSTED_MSGTYPE_VOTE 0x0002
|
||||
//#define RSPOSTED_MSGTYPE_COMMENT 0x0004
|
||||
|
||||
#define RSPOSTED_PERIOD_YEAR 1
|
||||
#define RSPOSTED_PERIOD_MONTH 2
|
||||
#define RSPOSTED_PERIOD_WEEK 3
|
||||
#define RSPOSTED_PERIOD_DAY 4
|
||||
#define RSPOSTED_PERIOD_HOUR 5
|
||||
|
||||
#define RSPOSTED_VIEWMODE_LATEST 1
|
||||
#define RSPOSTED_VIEWMODE_TOP 2
|
||||
#define RSPOSTED_VIEWMODE_HOT 3
|
||||
#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
|
||||
struct RsPostedPost
|
||||
{
|
||||
UNKNOWN = 0x00,
|
||||
NEW_POSTED_GROUP = 0x01,
|
||||
NEW_MESSAGE = 0x02,
|
||||
SUBSCRIBE_STATUS_CHANGED = 0x03,
|
||||
UPDATED_POSTED_GROUP = 0x04,
|
||||
UPDATED_MESSAGE = 0x05,
|
||||
READ_STATUS_CHANGED = 0x06,
|
||||
};
|
||||
|
||||
|
||||
struct RsGxsPostedEvent: RsEvent
|
||||
{
|
||||
RsGxsPostedEvent():
|
||||
RsEvent(RsEventType::GXS_POSTED),
|
||||
mPostedEventCode(RsPostedEventCode::UNKNOWN) {}
|
||||
|
||||
RsPostedEventCode mPostedEventCode;
|
||||
RsGxsGroupId mPostedGroupId;
|
||||
RsGxsMessageId mPostedMsgId;
|
||||
|
||||
///* @see RsEvent @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
|
||||
{
|
||||
RsEvent::serial_process(j, ctx);
|
||||
RS_SERIAL_PROCESS(mPostedEventCode);
|
||||
RS_SERIAL_PROCESS(mPostedGroupId);
|
||||
RS_SERIAL_PROCESS(mPostedMsgId);
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
explicit RsPosted(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsPosted() {}
|
||||
|
||||
/* Specific Service Data */
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts) = 0;
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
//Not currently used
|
||||
//virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
|
||||
/* From RsGxsCommentService */
|
||||
//virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
|
||||
//virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
|
||||
//virtual bool createNewComment(uint32_t &token, RsGxsComment &comment) = 0;
|
||||
//virtual bool createNewVote(uint32_t &token, RsGxsVote &vote) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
|
||||
|
||||
virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0;
|
||||
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<RsPeerId>& peers) = 0 ;
|
||||
};
|
||||
|
||||
|
||||
class RsPostedPost
|
||||
{
|
||||
public:
|
||||
RsPostedPost()
|
||||
{
|
||||
//mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
|
||||
mUpVotes = 0;
|
||||
mDownVotes = 0;
|
||||
mComments = 0;
|
||||
mHaveVoted = false;
|
||||
|
||||
mHotScore = 0;
|
||||
mTopScore = 0;
|
||||
mNewScore = 0;
|
||||
}
|
||||
RsPostedPost(): mHaveVoted(false), mUpVotes(0), mDownVotes(0), mComments(0),
|
||||
mHotScore(0), mTopScore(0), mNewScore(0) {}
|
||||
|
||||
bool calculateScores(rstime_t ref_time);
|
||||
|
||||
@ -192,4 +91,104 @@ class RsPostedPost
|
||||
};
|
||||
|
||||
|
||||
#endif // RETROSHARE_GXS_RSPOSTED_GUI_INTERFACE_H
|
||||
//#define RSPOSTED_MSGTYPE_POST 0x0001
|
||||
//#define RSPOSTED_MSGTYPE_VOTE 0x0002
|
||||
//#define RSPOSTED_MSGTYPE_COMMENT 0x0004
|
||||
|
||||
#define RSPOSTED_PERIOD_YEAR 1
|
||||
#define RSPOSTED_PERIOD_MONTH 2
|
||||
#define RSPOSTED_PERIOD_WEEK 3
|
||||
#define RSPOSTED_PERIOD_DAY 4
|
||||
#define RSPOSTED_PERIOD_HOUR 5
|
||||
|
||||
#define RSPOSTED_VIEWMODE_LATEST 1
|
||||
#define RSPOSTED_VIEWMODE_TOP 2
|
||||
#define RSPOSTED_VIEWMODE_HOT 3
|
||||
#define RSPOSTED_VIEWMODE_COMMENTS 4
|
||||
|
||||
|
||||
enum class RsPostedEventCode: uint8_t
|
||||
{
|
||||
UNKNOWN = 0x00,
|
||||
NEW_POSTED_GROUP = 0x01,
|
||||
NEW_MESSAGE = 0x02,
|
||||
SUBSCRIBE_STATUS_CHANGED = 0x03,
|
||||
UPDATED_POSTED_GROUP = 0x04,
|
||||
UPDATED_MESSAGE = 0x05,
|
||||
READ_STATUS_CHANGED = 0x06,
|
||||
};
|
||||
|
||||
|
||||
struct RsGxsPostedEvent: RsEvent
|
||||
{
|
||||
RsGxsPostedEvent():
|
||||
RsEvent(RsEventType::GXS_POSTED),
|
||||
mPostedEventCode(RsPostedEventCode::UNKNOWN) {}
|
||||
|
||||
RsPostedEventCode mPostedEventCode;
|
||||
RsGxsGroupId mPostedGroupId;
|
||||
RsGxsMessageId mPostedMsgId;
|
||||
|
||||
///* @see RsEvent @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
|
||||
{
|
||||
RsEvent::serial_process(j, ctx);
|
||||
RS_SERIAL_PROCESS(mPostedEventCode);
|
||||
RS_SERIAL_PROCESS(mPostedGroupId);
|
||||
RS_SERIAL_PROCESS(mPostedMsgId);
|
||||
}
|
||||
|
||||
~RsGxsPostedEvent() override;
|
||||
};
|
||||
|
||||
class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
|
||||
{
|
||||
public:
|
||||
explicit RsPosted(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
|
||||
virtual bool getBoardsInfo(
|
||||
const std::list<RsGxsGroupId>& boardsIds,
|
||||
std::vector<RsPostedGroup>& boardsInfo ) = 0;
|
||||
|
||||
virtual bool getBoardContent(
|
||||
const RsGxsGroupId& boardId,
|
||||
const std::set<RsGxsMessageId>& contentsIds,
|
||||
std::vector<RsPostedPost>& posts,
|
||||
std::vector<RsGxsComment>& comments ) = 0;
|
||||
|
||||
enum RS_DEPRECATED RankType {TopRankType, HotRankType, NewRankType };
|
||||
|
||||
RS_DEPRECATED_FOR(getBoardsInfo)
|
||||
virtual bool getGroupData( const uint32_t& token,
|
||||
std::vector<RsPostedGroup> &groups ) = 0;
|
||||
|
||||
RS_DEPRECATED_FOR(getBoardsContent)
|
||||
virtual bool getPostData(
|
||||
const uint32_t& token, std::vector<RsPostedPost>& posts,
|
||||
std::vector<RsGxsComment>& cmts) = 0;
|
||||
|
||||
RS_DEPRECATED_FOR(getBoardsContent)
|
||||
virtual bool getPostData(
|
||||
const uint32_t& token, std::vector<RsPostedPost>& posts) = 0;
|
||||
|
||||
//Not currently used
|
||||
//virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
|
||||
|
||||
/* From RsGxsCommentService */
|
||||
//virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
|
||||
//virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &comments) = 0;
|
||||
//virtual bool createNewComment(uint32_t &token, RsGxsComment &comment) = 0;
|
||||
//virtual bool createNewVote(uint32_t &token, RsGxsVote &vote) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
|
||||
|
||||
virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0;
|
||||
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<RsPeerId>& peers) = 0 ;
|
||||
|
||||
virtual ~RsPosted();
|
||||
};
|
||||
|
@ -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<RsGxsGroupId>& boardsIds,
|
||||
std::vector<RsPostedGroup>& 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<RsGxsMessageId>& contentsIds,
|
||||
std::vector<RsPostedPost>& posts,
|
||||
std::vector<RsGxsComment>& 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;
|
||||
|
@ -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<RsGxsNotify*>& changes)
|
||||
{
|
||||
@ -58,8 +58,17 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
|
||||
return RsGxsIfaceHelper::receiveChanges(changes);
|
||||
}
|
||||
|
||||
// Posted Specific DataTypes.
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups);
|
||||
bool getBoardsInfo(
|
||||
const std::list<RsGxsGroupId>& boardsIds,
|
||||
std::vector<RsPostedGroup>& channelsInfo ) override;
|
||||
|
||||
bool getBoardContent(
|
||||
const RsGxsGroupId& boardId,
|
||||
const std::set<RsGxsMessageId>& contentsIds,
|
||||
std::vector<RsPostedPost>& posts,
|
||||
std::vector<RsGxsComment>& comments ) override;
|
||||
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups);
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts);
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) { std::vector<RsGxsComment> cmts; return getPostData( token, posts, cmts);}
|
||||
//Not currently used
|
||||
|
Loading…
Reference in New Issue
Block a user