Add API method to retrieve forum child posts

RsGxsDataAccess::getMsgRelatedInfo print errors also when not debugging
RsGxsForums::getChildPosts get child posts from parent id
p3gxsforums.cc remove a bit of deadcode
This commit is contained in:
Gioacchino Mazzurco 2020-07-15 23:04:43 +02:00
parent 271af0dac1
commit c01d797386
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
4 changed files with 113 additions and 104 deletions

View File

@ -1240,61 +1240,42 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
onlyThreadMsgs = true;
}
if (onlyAllVersions && onlyChildMsgs)
{
#ifdef DATA_DEBUG
RsDbg() << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (VERSIONS & PARENT)" << std::endl;
#endif
if(onlyAllVersions && onlyChildMsgs)
{
RS_ERR("Incompatible FLAGS (VERSIONS & PARENT)");
return false;
}
return false;
}
if(onlyAllVersions && onlyThreadMsgs)
{
RS_ERR("Incompatible FLAGS (VERSIONS & THREAD)");
return false;
}
if (onlyAllVersions && onlyThreadMsgs)
{
#ifdef DATA_DEBUG
RsDbg() << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (VERSIONS & THREAD)" << std::endl;
#endif
if((!onlyLatestMsgs) && onlyChildMsgs)
{
RS_ERR("Incompatible FLAGS (!LATEST & PARENT)");
return false;
}
return false;
}
if((!onlyLatestMsgs) && onlyThreadMsgs)
{
RS_ERR("Incompatible FLAGS (!LATEST & THREAD)");
return false;
}
if ((!onlyLatestMsgs) && onlyChildMsgs)
{
#ifdef DATA_DEBUG
RsDbg() << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (!LATEST & PARENT)" << std::endl;
#endif
if(onlyChildMsgs && onlyThreadMsgs)
{
RS_ERR("Incompatible FLAGS (PARENT & THREAD)");
return false;
}
return false;
}
if ((!onlyLatestMsgs) && onlyThreadMsgs)
{
#ifdef DATA_DEBUG
RsDbg() << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (!LATEST & THREAD)" << std::endl;
#endif
return false;
}
if (onlyChildMsgs && onlyThreadMsgs)
{
#ifdef DATA_DEBUG
RsDbg() << "RsGxsDataAccess::getMsgRelatedList() ERROR Incompatible FLAGS (PARENT & THREAD)" << std::endl;
#endif
return false;
}
/* FALL BACK OPTION */
if ((!onlyLatestMsgs) && (!onlyAllVersions) && (!onlyChildMsgs) && (!onlyThreadMsgs))
{
#ifdef DATA_DEBUG
RsDbg() << "RsGxsDataAccess::getMsgRelatedList() FALLBACK -> NO FLAGS -> SIMPLY RETURN nothing" << std::endl;
#endif
return true;
}
if( (!onlyLatestMsgs) && (!onlyAllVersions) && (!onlyChildMsgs) &&
(!onlyThreadMsgs) )
{
RS_WARN("NO FLAGS -> SIMPLY RETURN nothing");
return true;
}
for(auto vit_msgIds(req->mMsgIds.begin()); vit_msgIds != req->mMsgIds.end(); ++vit_msgIds)
{
@ -1330,14 +1311,11 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
}
}
if(!origMeta)
{
#ifdef DATA_DEBUG
RsDbg() << "RsGxsDataAccess::getMsgRelatedInfo(): Cannot find meta of msgId (to relate to)!"
<< std::endl;
#endif
return false;
}
if(!origMeta)
{
RS_ERR("Cannot find meta of msgId: ", msgId, " to relate to");
return false;
}
const RsGxsMessageId& origMsgId = origMeta->mOrigMsgId;
std::map<RsGxsMessageId, const RsGxsMsgMetaData*>& metaMap = filterMap[grpId];

View File

@ -4,7 +4,8 @@
* libretroshare: retroshare core library *
* *
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* Copyright (C) 2018-2020 Gioacchino Mazzurco <gio@eigenlab.org> *
* Copyright (C) 2019-2020 Asociación Civil Altermundi <info@altermundi.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -25,6 +26,7 @@
#include <cstdint>
#include <string>
#include <list>
#include <system_error>
#include "retroshare/rstokenservice.h"
#include "retroshare/rsgxsifacehelper.h"
@ -353,6 +355,19 @@ public:
RsGxsGroupId& forumId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0;
/**
* @brief Get posts related to the given post.
* If the set is empty, nothing is returned.
* @jsonapi{development}
* @param[in] forumId id of the forum of which the content is requested
* @param[in] parentId id of the post of which child posts (aka replies)
* are requested.
* @param[out] childPosts storage for the child posts
* @return false if something failed, true otherwhise
*/
virtual std::error_condition getChildPosts(
const RsGxsGroupId& forumId, const RsGxsMessageId& parentId,
std::vector<RsGxsForumMsg>& childPosts ) = 0;
/**
* @brief Create forum. Blocking API.

View File

@ -4,7 +4,8 @@
* libretroshare: retroshare core library *
* *
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* Copyright (C) 2018-2020 Gioacchino Mazzurco <gio@eigenlab.org> *
* Copyright (C) 2019-2020 Asociación Civil Altermundi <info@altermundi.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -20,16 +21,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include <cstdio>
#include <memory>
#include "services/p3gxsforums.h"
#include "rsitems/rsgxsforumitems.h"
#include "retroshare/rspeers.h"
#include "retroshare/rsidentity.h"
#include "util/rsdebug.h"
#include "rsserver/p3face.h"
#include "retroshare/rsnotify.h"
#include "util/rsdebuglevel2.h"
#include "retroshare/rsgxsflags.h"
#include <stdio.h>
// For Dummy Msgs.
#include "util/rsrandom.h"
@ -422,46 +427,6 @@ bool p3GxsForums::getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &
return ok;
}
//Not currently used
/*bool p3GxsForums::getRelatedMessages(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs)
{
GxsMsgRelatedDataMap msgData;
bool ok = RsGenExchange::getMsgRelatedData(token, msgData);
if(ok)
{
GxsMsgRelatedDataMap::iterator mit = msgData.begin();
for(; mit != msgData.end(); ++mit)
{
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; vit != msgItems.end(); ++vit)
{
RsGxsForumMsgItem* item = dynamic_cast<RsGxsForumMsgItem*>(*vit);
if(item)
{
RsGxsForumMsg msg = item->mMsg;
msg.mMeta = item->meta;
msgs.push_back(msg);
delete item;
}
else
{
std::cerr << "Not a GxsForumMsgItem, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
}*/
/********************************************************************************************/
bool p3GxsForums::createForumV2(
const std::string& name, const std::string& description,
const RsGxsId& authorId, const std::set<RsGxsId>& moderatorsIds,
@ -826,6 +791,51 @@ bool p3GxsForums::importForumLink(
return true;
}
std::error_condition p3GxsForums::getChildPosts(
const RsGxsGroupId& forumId, const RsGxsMessageId& parentId,
std::vector<RsGxsForumMsg>& childPosts )
{
RS_DBG3("forumId: ", forumId, " parentId: ", parentId);
if(forumId.isNull() || parentId.isNull())
return std::errc::invalid_argument;
std::vector<RsGxsGrpMsgIdPair> msgIds;
msgIds.push_back(RsGxsGrpMsgIdPair(forumId, parentId));
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_PARENT | RS_TOKREQOPT_MSG_LATEST;
uint32_t token;
if( !requestMsgRelatedInfo(token, opts, msgIds) ||
waitToken(token) != RsTokenService::COMPLETE )
return std::errc::timed_out;
GxsMsgRelatedDataMap msgData;
if(!getMsgRelatedData(token, msgData))
return std::errc::no_message_available;
for(auto& mit: msgData)
{
for(auto& vit: mit.second)
{
auto msgItem = dynamic_cast<RsGxsForumMsgItem*>(vit);
if(msgItem)
{
RsGxsForumMsg post = msgItem->mMsg;
post.mMeta = msgItem->meta;
childPosts.push_back(post);
}
else RS_WARN("Got item of unexpected type: ", vit);
delete vit;
}
}
return std::error_condition();
}
bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group)
{
std::cerr << "p3GxsForums::createGroup()" << std::endl;

View File

@ -4,7 +4,8 @@
* libretroshare: retroshare core library *
* *
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* Copyright (C) 2018-2020 Gioacchino Mazzurco <gio@eigenlab.org> *
* Copyright (C) 2019-2020 Asociación Civil Altermundi <info@altermundi.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -131,6 +132,11 @@ public:
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
) override;
/// @see RsGxsForums
std::error_condition getChildPosts(
const RsGxsGroupId& forumId, const RsGxsMessageId& parentId,
std::vector<RsGxsForumMsg>& childPosts ) override;
/// implementation of rsGxsGorums
///
bool getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups) override;