GxsChannels optimizable API

This commit is contained in:
Gioacchino Mazzurco 2018-12-12 21:35:31 +01:00
parent bdf9bd5c56
commit 7113eb7bfc
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
3 changed files with 58 additions and 17 deletions

View File

@ -197,17 +197,28 @@ public:
std::vector<RsGxsChannelGroup>& channelsInfo ) = 0;
/**
* @brief Get content of specified channels. Blocking API
* @brief Get channel contents
* @jsonapi{development}
* @param[in] chanIds id of the channels of which the content is requested
* @param[out] posts storage for the posts
* @param[in] channelId id of the channel of which the content is requested
* @param[in] contentsIds ids of requested contents
* @param[out] posts storage for posts
* @param[out] comments storage for the comments
* @return false if something failed, true otherwhise
*/
virtual bool getChannelsContent(
const std::list<RsGxsGroupId>& chanIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
virtual bool getChannelContent( const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
/**
* @brief Get channel content summaries
* @jsonapi{development}
* @param[in] channelId id of the channel of which the content is requested
* @param[out] summaries storage for summaries
* @return false if something failed, true otherwhise
*/
virtual bool getContentSummaries( const RsGxsGroupId& channelId,
std::vector<RsMsgMetaData>& summaries ) = 0;
/**
* @brief Toggle post read status. Blocking API.

View File

@ -1016,16 +1016,42 @@ bool p3GxsChannels::getChannelsInfo(
return getGroupData(token, channelsInfo);
}
bool p3GxsChannels::getChannelsContent(
const std::list<RsGxsGroupId>& chanIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments )
bool p3GxsChannels::getContentSummaries(
const RsGxsGroupId& channelId, std::vector<RsMsgMetaData>& summaries )
{
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_META;
std::list<RsGxsGroupId> channelIds;
channelIds.push_back(channelId);
if( !requestMsgInfo(token, opts, channelIds) ||
waitToken(token, std::chrono::seconds(5)) != RsTokenService::COMPLETE )
return false;
GxsMsgMetaMap metaMap;
bool res = RsGenExchange::getMsgMeta(token, metaMap);
summaries = metaMap[channelId];
return res;
}
bool p3GxsChannels::getChannelContent( const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments )
{
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
if( !requestMsgInfo(token, opts, chanIds)
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
GxsMsgReq msgIds;
msgIds[channelId] = contentsIds;
if( !requestMsgInfo(token, opts, msgIds) ||
waitToken(token) != RsTokenService::COMPLETE ) return false;
return getPostData(token, posts, comments);
}

View File

@ -186,10 +186,14 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
std::vector<RsGxsChannelGroup>& channelsInfo );
/// Implementation of @see RsGxsChannels::getChannelContent
virtual bool getChannelsContent(
const std::list<RsGxsGroupId>& chanIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments );
virtual bool getChannelContent( const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments );
/// Implementation of @see RsGxsChannels::getContentSummaries
virtual bool getContentSummaries( const RsGxsGroupId& channelId,
std::vector<RsMsgMetaData>& summaries );
/// Implementation of @see RsGxsChannels::createChannel
virtual bool createChannel(RsGxsChannelGroup& channel);