Extend libresapi with minimal support for channels

The code is not elegant as this version of the API will be soon obsolete
  but it offer a bunch of channels functionalities, comments and votes
  are not implemented yet

/channels/list_channels get all visibile channels
/channels/get_channel get content of a subscribed channel
/channels/toggle_subscribe subscribe/unsubscribe to a channel
/channels/toggle_auto_download set/unset auto-download for files attached
  to posts in a channel
/channels/toggle_read mark a post as read
/channels/create_channel create a new channel
/channels/create_post create a new post in given channel, group_id
  paramenter renamed to channel_id for consistence

mChannels use reference instead of pointer as it must be valid
  for the whole lifetime of the object
RsGxsCommentService and derivatives use proper types for parameter, avoid
  reference when unneeded
This commit is contained in:
Gioacchino Mazzurco 2018-03-28 16:30:35 +02:00
parent 73c6deebf4
commit 8d1f1da242
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
7 changed files with 449 additions and 77 deletions

View file

@ -124,24 +124,27 @@ class RsGxsComment
};
class RsGxsCommentService
struct RsGxsCommentService
{
public:
RsGxsCommentService() {}
virtual ~RsGxsCommentService() {}
RsGxsCommentService() { return; }
virtual ~RsGxsCommentService() { return; }
/** Get previously requested comment data with token */
virtual bool getCommentData( uint32_t token,
std::vector<RsGxsComment> &comments ) = 0;
virtual bool getRelatedComments( uint32_t token,
std::vector<RsGxsComment> &comments ) = 0;
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 createComment(uint32_t &token, RsGxsComment &comment) = 0;
virtual bool createVote(uint32_t &token, RsGxsVote &vote) = 0;
//virtual bool getDetailedCommentData(const uint32_t &token, std::vector<RsGxsComment> &comments);
virtual bool createComment(uint32_t &token, RsGxsComment &comment) = 0;
virtual bool createVote(uint32_t &token, RsGxsVote &vote) = 0;
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) = 0;
virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) = 0;
virtual bool acknowledgeComment(
uint32_t token,
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) = 0;
virtual bool acknowledgeVote(
uint32_t token,
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) = 0;
};

View file

@ -1179,7 +1179,9 @@ void p3GxsChannels::setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsg
setMsgStatusFlags(token, msgId, status, mask);
}
void p3GxsChannels::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
void p3GxsChannels::setMessageReadStatus( uint32_t& token,
const RsGxsGrpMsgIdPair& msgId,
bool read )
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::setMessageReadStatus()";
@ -1189,10 +1191,8 @@ void p3GxsChannels::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPai
/* Always remove status unprocessed */
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
uint32_t status = GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
if (read)
{
status = 0;
}
if (read) status = 0;
setMsgStatusFlags(token, msgId, status, mask);
}

View file

@ -108,15 +108,12 @@ virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std:
virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::string& directory);
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsCommentData(token, msgs);
}
virtual bool getCommentData(uint32_t token, std::vector<RsGxsComment> &msgs)
{ return mCommentService->getGxsCommentData(token, msgs); }
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool getRelatedComments( uint32_t token,
std::vector<RsGxsComment> &msgs )
{ return mCommentService->getGxsRelatedComments(token, msgs); }
virtual bool createComment(uint32_t &token, RsGxsComment &msg)
{
@ -128,13 +125,13 @@ virtual bool createVote(uint32_t &token, RsGxsVote &msg)
return mCommentService->createGxsVote(token, msg);
}
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
virtual bool acknowledgeComment(uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return acknowledgeMsg(token, msgId);
}
virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
virtual bool acknowledgeVote(uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
if (mCommentService->acknowledgeVote(token, msgId))
{

View file

@ -83,16 +83,14 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
}
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsCommentData(token, msgs);
}
/** Comment service - Provide RsGxsCommentService -
* redirect to p3GxsCommentService */
virtual bool getCommentData(uint32_t token, std::vector<RsGxsComment> &msgs)
{ return mCommentService->getGxsCommentData(token, msgs); }
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs)
{
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool getRelatedComments( uint32_t token,
std::vector<RsGxsComment> &msgs )
{ return mCommentService->getGxsRelatedComments(token, msgs); }
virtual bool createComment(uint32_t &token, RsGxsComment &msg)
{
@ -104,17 +102,14 @@ virtual bool createVote(uint32_t &token, RsGxsVote &msg)
return mCommentService->createGxsVote(token, msg);
}
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
return acknowledgeMsg(token, msgId);
}
virtual bool acknowledgeComment(
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId )
{ return acknowledgeMsg(token, msgId); }
virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
virtual bool acknowledgeVote(
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId )
{
if (mCommentService->acknowledgeVote(token, msgId))
{
return true;
}
if (mCommentService->acknowledgeVote(token, msgId)) return true;
return acknowledgeMsg(token, msgId);
}
};