mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #1609 from G10h4ck/forum_jsonapi
Implement GXS forum reasonable JSON API
This commit is contained in:
commit
5dc340d884
@ -1,6 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* libretroshare/src/retroshare: rsflags.h *
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2019 by Retroshare Team <contact@retroshare.cc> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
/* G10h4ck: TODO we should redefine flags in a way that the flag declaration and
|
||||
* the flags values (bit fields) would be strongly logically linked.
|
||||
* A possible way is to take an enum class containing the names of each
|
||||
* bitfield and corresponding value as template parameter, this way would also
|
||||
* avoid the need of dumb template parameter that is used only to make the
|
||||
* types incompatible but that doesn't help finding what are the possible values
|
||||
* for a kind of flag. Another appealing approach seems the first one described
|
||||
* here https://softwareengineering.stackexchange.com/questions/194412/using-scoped-enums-for-bit-flags-in-c
|
||||
* a few simple macros could be used instead of the template class */
|
||||
|
||||
// This class provides a representation for flags that can be combined with bitwise
|
||||
// operations. However, because the class is templated with an id, it's not possible to
|
||||
|
@ -142,19 +142,6 @@ struct RsGxsComment : RsSerializable
|
||||
RS_SERIAL_PROCESS(mOwnVote);
|
||||
RS_SERIAL_PROCESS(mVotes);
|
||||
}
|
||||
|
||||
const std::ostream &print(std::ostream &out, std::string indent = "", std::string varName = "") const {
|
||||
out << indent << varName << " of RsGxsComment Values ###################" << std::endl;
|
||||
mMeta.print(out, indent + " ", "mMeta");
|
||||
out << indent << " mComment: " << mComment << std::endl;
|
||||
out << indent << " mUpVotes: " << mUpVotes << std::endl;
|
||||
out << indent << " mDownVotes: " << mDownVotes << std::endl;
|
||||
out << indent << " mScore: " << mScore << std::endl;
|
||||
out << indent << " mOwnVote: " << mOwnVote << std::endl;
|
||||
out << indent << " mVotes.size(): " << mVotes.size() << std::endl;
|
||||
out << indent << "######################################################" << std::endl;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -52,12 +52,11 @@ namespace GXS_SERV {
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_MASK = 0x0000ff00;
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_NONE = 0x00000000;
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG = 0x00000100; // Anti-spam feature. Allows to ask higher reputation to anonymous IDs
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_REQUIRED = 0x00000200; // unused
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_REQUIRED = 0x00000200;
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_IFNOPUBSIGN = 0x00000400; // ???
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES = 0x00000800; // not used anymore
|
||||
static const uint32_t FLAG_AUTHOR_AUTHENTICATION_GPG_KNOWN = 0x00001000; // Anti-spam feature. Allows to ask higher reputation to unknown IDs and anonymous IDs
|
||||
|
||||
// These are *not used*
|
||||
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_MASK = 0x000000ff;
|
||||
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_ENCRYPTED = 0x00000001;
|
||||
static const uint32_t FLAG_GROUP_SIGN_PUBLISH_ALLSIGNED = 0x00000002; // unused
|
||||
|
@ -3,8 +3,8 @@
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2012 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 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 *
|
||||
@ -30,9 +30,9 @@
|
||||
#include "retroshare/rsgxsifacehelper.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "serialiser/rsserializable.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsGxsForums;
|
||||
|
||||
/**
|
||||
@ -43,8 +43,10 @@ extern RsGxsForums* rsGxsForums;
|
||||
|
||||
|
||||
/** Forum Service message flags, to be used in RsMsgMetaData::mMsgFlags
|
||||
* Gxs imposes to use the first two bytes (lower bytes) of mMsgFlags for
|
||||
* Gxs imposes to use the first two bytes (lower bytes) of mMsgFlags for
|
||||
* private forum flags, the upper bytes being used for internal GXS stuff.
|
||||
* @todo mixing service level flags and GXS level flag into the same member is
|
||||
* prone to confusion, use separated members for those things
|
||||
*/
|
||||
static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MASK = 0x0000000f;
|
||||
static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001;
|
||||
@ -54,38 +56,52 @@ static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001;
|
||||
|
||||
struct RsGxsForumGroup : RsSerializable
|
||||
{
|
||||
virtual ~RsGxsForumGroup() {}
|
||||
|
||||
/** Forum GXS metadata */
|
||||
RsGroupMetaData mMeta;
|
||||
|
||||
/** @brief Forum desciption */
|
||||
std::string mDescription;
|
||||
|
||||
/* TODO: run away from TLV old serializables as those types are opaque to
|
||||
/** @brief List of forum moderators ids
|
||||
* @todo run away from TLV old serializables as those types are opaque to
|
||||
* JSON API! */
|
||||
RsTlvGxsIdSet mAdminList;
|
||||
|
||||
/** @brief List of forum pinned posts, those are usually displayed on top
|
||||
* @todo run away from TLV old serializables as those types are opaque to
|
||||
* JSON API! */
|
||||
RsTlvGxsMsgIdSet mPinnedPosts;
|
||||
|
||||
/// @see RsSerializable
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx );
|
||||
virtual void serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override;
|
||||
|
||||
/// utility functions
|
||||
~RsGxsForumGroup() override;
|
||||
|
||||
/* G10h4ck: We should avoid actual methods in this contexts as they are
|
||||
* invisible to JSON API */
|
||||
bool canEditPosts(const RsGxsId& id) const;
|
||||
};
|
||||
|
||||
struct RsGxsForumMsg : RsSerializable
|
||||
{
|
||||
virtual ~RsGxsForumMsg() {}
|
||||
|
||||
/** @brief Forum post GXS metadata */
|
||||
RsMsgMetaData mMeta;
|
||||
|
||||
/** @brief Forum post content */
|
||||
std::string mMsg;
|
||||
|
||||
/// @see RsSerializable
|
||||
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
virtual void serial_process(
|
||||
RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mMeta);
|
||||
RS_SERIAL_PROCESS(mMsg);
|
||||
}
|
||||
|
||||
~RsGxsForumMsg() override;
|
||||
};
|
||||
|
||||
|
||||
@ -93,23 +109,67 @@ class RsGxsForums: public RsGxsIfaceHelper
|
||||
{
|
||||
public:
|
||||
explicit RsGxsForums(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
|
||||
virtual ~RsGxsForums() {}
|
||||
virtual ~RsGxsForums();
|
||||
|
||||
/**
|
||||
* @brief Create forum. Blocking API.
|
||||
* @brief Create forum.
|
||||
* @jsonapi{development}
|
||||
* @param[inout] forum Forum data (name, description...)
|
||||
* @return false on error, true otherwise
|
||||
* @param[in] name Name of the forum
|
||||
* @param[in] description Optional description of the forum
|
||||
* @param[in] authorId Optional id of the froum owner author
|
||||
* @param[in] moderatorsIds Optional list of forum moderators
|
||||
* @param[in] circleType Optional visibility rule, default public.
|
||||
* @param[in] circleId If the forum is not public specify the id of
|
||||
* the circle who can see the forum. Depending on
|
||||
* the value you pass for circleType this should
|
||||
* be a circle if EXTERNAL is passed, a local
|
||||
* friends group id if NODES_GROUP is passed,
|
||||
* empty otherwise.
|
||||
* @param[out] forumId Optional storage for the id of the created
|
||||
* forum, meaningful only if creations succeeds.
|
||||
* @param[out] errorMessage Optional storage for error messsage, meaningful
|
||||
* only if creation fail.
|
||||
* @return False on error, true otherwise.
|
||||
*/
|
||||
virtual bool createForum(RsGxsForumGroup& forum) = 0;
|
||||
virtual bool createForumV2(
|
||||
const std::string& name, const std::string& description,
|
||||
const RsGxsId& authorId = RsGxsId(),
|
||||
const std::set<RsGxsId>& moderatorsIds = std::set<RsGxsId>(),
|
||||
RsGxsCircleType circleType = RsGxsCircleType::PUBLIC,
|
||||
const RsGxsCircleId& circleId = RsGxsCircleId(),
|
||||
RsGxsGroupId& forumId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* @brief Create forum message. Blocking API.
|
||||
* @brief Create a post on the given forum.
|
||||
* @jsonapi{development}
|
||||
* @param[inout] message
|
||||
* @param[in] forumId Id of the forum in which the post is to be
|
||||
* submitted
|
||||
* @param[in] title UTF-8 string containing the title of the post
|
||||
* @param[in] mBody UTF-8 string containing the text of the post
|
||||
* @param[in] authorId Id of the author of the comment
|
||||
* @param[in] parentId Optional Id of the parent post if this post is a
|
||||
* reply to another post, empty otherwise.
|
||||
* @param[in] origPostId If this is supposed to replace an already
|
||||
* existent post, the id of the old post.
|
||||
* If left blank a new post will be created.
|
||||
* @param[out] postMsgId Optional storage for the id of the created,
|
||||
* meaningful only on success.
|
||||
* @param[out] errorMessage Optional storage for error message, meaningful
|
||||
* only on failure.
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool createMessage(RsGxsForumMsg& message) = 0;
|
||||
virtual bool createPost(
|
||||
const RsGxsGroupId& forumId,
|
||||
const std::string& title,
|
||||
const std::string& mBody,
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId = RsGxsMessageId(),
|
||||
const RsGxsMessageId& origPostId = RsGxsMessageId(),
|
||||
RsGxsMessageId& postMsgId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
||||
/**
|
||||
* @brief Edit forum details.
|
||||
@ -159,7 +219,7 @@ public:
|
||||
*/
|
||||
virtual bool getForumContent(
|
||||
const RsGxsGroupId& forumId,
|
||||
std::set<RsGxsMessageId>& msgsIds,
|
||||
const std::set<RsGxsMessageId>& msgsIds,
|
||||
std::vector<RsGxsForumMsg>& msgs) = 0;
|
||||
|
||||
/**
|
||||
@ -181,6 +241,26 @@ public:
|
||||
virtual bool subscribeToForum( const RsGxsGroupId& forumId,
|
||||
bool subscribe ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Create forum. Blocking API.
|
||||
* @jsonapi{development}
|
||||
* @param[inout] forum Forum data (name, description...)
|
||||
* @return false on error, true otherwise
|
||||
* @deprecated @see createForumV2
|
||||
*/
|
||||
RS_DEPRECATED_FOR(createForumV2)
|
||||
virtual bool createForum(RsGxsForumGroup& forum) = 0;
|
||||
|
||||
/**
|
||||
* @brief Create forum message. Blocking API.
|
||||
* @jsonapi{development}
|
||||
* @param[inout] message
|
||||
* @return false on error, true otherwise
|
||||
* @deprecated @see createPost
|
||||
*/
|
||||
RS_DEPRECATED_FOR(createPost)
|
||||
virtual bool createMessage(RsGxsForumMsg& message) = 0;
|
||||
|
||||
/* Specific Service Data */
|
||||
RS_DEPRECATED_FOR("getForumsSummaries, getForumsInfo")
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups) = 0;
|
||||
|
@ -140,14 +140,20 @@ struct RsMsgMetaData : RsSerializable
|
||||
std::string mMsgName;
|
||||
rstime_t mPublishTs;
|
||||
|
||||
/// the lower 16 bits for service, upper 16 bits for GXS
|
||||
uint32_t mMsgFlags;
|
||||
/** the lower 16 bits for service, upper 16 bits for GXS
|
||||
* @todo mixing service level flags and GXS level flag into the same member
|
||||
* is prone to confusion, use separated members for those things, this could
|
||||
* be done without breaking network retro-compatibility */
|
||||
uint32_t mMsgFlags;
|
||||
|
||||
// BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG.
|
||||
// normally READ / UNREAD flags. LOCAL Data.
|
||||
|
||||
/// the first 16 bits for service, last 16 for GXS
|
||||
uint32_t mMsgStatus;
|
||||
/** the first 16 bits for service, last 16 for GXS
|
||||
* @todo mixing service level flags and GXS level flag into the same member
|
||||
* is prone to confusion, use separated members for those things, this could
|
||||
* be done without breaking network retro-compatibility */
|
||||
uint32_t mMsgStatus;
|
||||
|
||||
rstime_t mChildTs;
|
||||
std::string mServiceString; // Service Specific Free-Form extra storage.
|
||||
@ -169,25 +175,6 @@ struct RsMsgMetaData : RsSerializable
|
||||
RS_SERIAL_PROCESS(mChildTs);
|
||||
RS_SERIAL_PROCESS(mServiceString);
|
||||
}
|
||||
|
||||
const std::ostream &print(std::ostream &out, std::string indent = "", std::string varName = "") const {
|
||||
out
|
||||
<< indent << varName << " of RsMsgMetaData Values ###################" << std::endl
|
||||
<< indent << " mGroupId: " << mGroupId.toStdString() << std::endl
|
||||
<< indent << " mMsgId: " << mMsgId.toStdString() << std::endl
|
||||
<< indent << " mThreadId: " << mThreadId.toStdString() << std::endl
|
||||
<< indent << " mParentId: " << mParentId.toStdString() << std::endl
|
||||
<< indent << " mOrigMsgId: " << mOrigMsgId.toStdString() << std::endl
|
||||
<< indent << " mAuthorId: " << mAuthorId.toStdString() << std::endl
|
||||
<< indent << " mMsgName: " << mMsgName << std::endl
|
||||
<< indent << " mPublishTs: " << mPublishTs << std::endl
|
||||
<< indent << " mMsgFlags: " << std::hex << mMsgFlags << std::dec << std::endl
|
||||
<< indent << " mMsgStatus: " << std::hex << mMsgStatus << std::dec << std::endl
|
||||
<< indent << " mChildTs: " << mChildTs << std::endl
|
||||
<< indent << " mServiceString: " << mServiceString << std::endl
|
||||
<< indent << "######################################################" << std::endl;
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
class GxsGroupStatistic
|
||||
|
@ -3,7 +3,8 @@
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 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 *
|
||||
@ -21,8 +22,8 @@
|
||||
*******************************************************************************/
|
||||
#include "services/p3gxsforums.h"
|
||||
#include "rsitems/rsgxsforumitems.h"
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "retroshare/rsidentity.h"
|
||||
|
||||
#include "rsserver/p3face.h"
|
||||
#include "retroshare/rsnotify.h"
|
||||
@ -384,6 +385,165 @@ bool p3GxsForums::getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
bool p3GxsForums::createForumV2(
|
||||
const std::string& name, const std::string& description,
|
||||
const RsGxsId& authorId, const std::set<RsGxsId>& moderatorsIds,
|
||||
RsGxsCircleType circleType, const RsGxsCircleId& circleId,
|
||||
RsGxsGroupId& forumId, std::string& errorMessage )
|
||||
{
|
||||
auto createFail = [&](std::string mErr)
|
||||
{
|
||||
errorMessage = mErr;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
||||
return false;
|
||||
};
|
||||
|
||||
if(name.empty()) return createFail("Forum name is required");
|
||||
|
||||
if(!authorId.isNull() && !rsIdentity->isOwnId(authorId))
|
||||
return createFail("Author must be iether null or and identity owned by "
|
||||
"this node");
|
||||
|
||||
switch(circleType)
|
||||
{
|
||||
case RsGxsCircleType::PUBLIC: // fallthrough
|
||||
case RsGxsCircleType::LOCAL: // fallthrough
|
||||
case RsGxsCircleType::YOUR_EYES_ONLY:
|
||||
break;
|
||||
case RsGxsCircleType::EXTERNAL:
|
||||
if(circleId.isNull())
|
||||
return createFail("circleType is EXTERNAL but circleId is null");
|
||||
break;
|
||||
case RsGxsCircleType::NODES_GROUP:
|
||||
{
|
||||
RsGroupInfo ginfo;
|
||||
if(!rsPeers->getGroupInfo(RsNodeGroupId(circleId), ginfo))
|
||||
return createFail("circleType is NODES_GROUP but circleId does not "
|
||||
"correspond to an actual group of friends");
|
||||
break;
|
||||
}
|
||||
default: return createFail("circleType has invalid value");
|
||||
}
|
||||
|
||||
// Create a consistent channel group meta from the information supplied
|
||||
RsGxsForumGroup forum;
|
||||
|
||||
forum.mMeta.mGroupName = name;
|
||||
forum.mMeta.mAuthorId = authorId;
|
||||
forum.mMeta.mCircleType = static_cast<uint32_t>(circleType);
|
||||
|
||||
forum.mMeta.mSignFlags = GXS_SERV::FLAG_GROUP_SIGN_PUBLISH_NONEREQ
|
||||
| GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_REQUIRED;
|
||||
|
||||
forum.mMeta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC;
|
||||
|
||||
forum.mMeta.mCircleId.clear();
|
||||
forum.mMeta.mInternalCircle.clear();
|
||||
|
||||
switch(circleType)
|
||||
{
|
||||
case RsGxsCircleType::NODES_GROUP:
|
||||
forum.mMeta.mInternalCircle = circleId; break;
|
||||
case RsGxsCircleType::EXTERNAL:
|
||||
forum.mMeta.mCircleId = circleId; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
forum.mDescription = description;
|
||||
forum.mAdminList.ids = moderatorsIds;
|
||||
|
||||
uint32_t token;
|
||||
if(!createGroup(token, forum))
|
||||
return createFail("Failed creating GXS group.");
|
||||
|
||||
// wait for the group creation to complete.
|
||||
RsTokenService::GxsRequestStatus wSt =
|
||||
waitToken( token, std::chrono::milliseconds(5000),
|
||||
std::chrono::milliseconds(20) );
|
||||
if(wSt != RsTokenService::COMPLETE)
|
||||
return createFail( "GXS operation waitToken failed with: "
|
||||
+ std::to_string(wSt) );
|
||||
|
||||
if(!RsGenExchange::getPublishedGroupMeta(token, forum.mMeta))
|
||||
return createFail("Failure getting updated group data.");
|
||||
|
||||
forumId = forum.mMeta.mGroupId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsForums::createPost(
|
||||
const RsGxsGroupId& forumId, const std::string& title,
|
||||
const std::string& mBody,
|
||||
const RsGxsId& authorId, const RsGxsMessageId& parentId,
|
||||
const RsGxsMessageId& origPostId, RsGxsMessageId& postMsgId,
|
||||
std::string& errorMessage )
|
||||
{
|
||||
RsGxsForumMsg post;
|
||||
|
||||
auto failure = [&](std::string errMsg)
|
||||
{
|
||||
errorMessage = errMsg;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
||||
return false;
|
||||
};
|
||||
|
||||
if(title.empty()) return failure("Title is required");
|
||||
|
||||
if(authorId.isNull()) return failure("Author id is needed");
|
||||
|
||||
if(!rsIdentity->isOwnId(authorId))
|
||||
return failure( "Author id: " + authorId.toStdString() + " is not of"
|
||||
"own identity" );
|
||||
|
||||
if(!parentId.isNull())
|
||||
{
|
||||
std::vector<RsGxsForumMsg> msgs;
|
||||
if( getForumContent(forumId, std::set<RsGxsMessageId>({parentId}), msgs)
|
||||
&& msgs.size() == 1 )
|
||||
{
|
||||
post.mMeta.mParentId = parentId;
|
||||
post.mMeta.mThreadId = msgs[0].mMeta.mThreadId;
|
||||
}
|
||||
else return failure("Parent post " + parentId.toStdString()
|
||||
+ " doesn't exists locally");
|
||||
}
|
||||
|
||||
std::vector<RsGxsForumGroup> forumInfo;
|
||||
if(!getForumsInfo(std::list<RsGxsGroupId>({forumId}), forumInfo))
|
||||
return failure( "Forum with Id " + forumId.toStdString()
|
||||
+ " does not exist locally." );
|
||||
|
||||
if(!origPostId.isNull())
|
||||
{
|
||||
std::vector<RsGxsForumMsg> msgs;
|
||||
if( getForumContent( forumId,
|
||||
std::set<RsGxsMessageId>({origPostId}), msgs)
|
||||
&& msgs.size() == 1 )
|
||||
post.mMeta.mOrigMsgId = origPostId;
|
||||
else return failure("Original post " + origPostId.toStdString()
|
||||
+ " doesn't exists locally");
|
||||
}
|
||||
|
||||
post.mMeta.mGroupId = forumId;
|
||||
post.mMeta.mMsgName = title;
|
||||
post.mMeta.mAuthorId = authorId;
|
||||
post.mMsg = mBody;
|
||||
|
||||
uint32_t token;
|
||||
if( !createMsg(token, post)
|
||||
|| waitToken(
|
||||
token,
|
||||
std::chrono::milliseconds(5000) ) != RsTokenService::COMPLETE )
|
||||
return failure("Failure creating GXS message");
|
||||
|
||||
if(!RsGenExchange::getPublishedMsgMeta(token, post.mMeta))
|
||||
return failure("Failure getting created GXS message metadata");
|
||||
|
||||
postMsgId = post.mMeta.mMsgId;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsForums::createForum(RsGxsForumGroup& forum)
|
||||
{
|
||||
uint32_t token;
|
||||
@ -461,8 +621,9 @@ bool p3GxsForums::getForumsInfo(
|
||||
}
|
||||
|
||||
bool p3GxsForums::getForumContent(
|
||||
const RsGxsGroupId& forumId, std::set<RsGxsMessageId>& msgs_to_request,
|
||||
std::vector<RsGxsForumMsg>& msgs )
|
||||
const RsGxsGroupId& forumId,
|
||||
const std::set<RsGxsMessageId>& msgs_to_request,
|
||||
std::vector<RsGxsForumMsg>& msgs )
|
||||
{
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
@ -844,3 +1005,6 @@ bool RsGxsForumGroup::canEditPosts(const RsGxsId& id) const
|
||||
id == mMeta.mAuthorId;
|
||||
}
|
||||
|
||||
RsGxsForumGroup::~RsGxsForumGroup() = default;
|
||||
RsGxsForumMsg::~RsGxsForumMsg() = default;
|
||||
RsGxsForums::~RsGxsForums() = default;
|
||||
|
@ -3,7 +3,8 @@
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright 2012-2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2019 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,21 +20,17 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#ifndef P3_GXSFORUMS_SERVICE_HEADER
|
||||
#define P3_GXSFORUMS_SERVICE_HEADER
|
||||
|
||||
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
|
||||
#include "util/rstickevent.h"
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
#include "util/rstickevent.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
|
||||
class p3GxsForums: public RsGenExchange, public RsGxsForums, public p3Config,
|
||||
public RsTickEvent /* only needed for testing - remove after */
|
||||
@ -55,14 +52,39 @@ protected:
|
||||
virtual bool loadList(std::list<RsItem *>& loadList); // @see p3Config::loadList(std::list<RsItem *>&)
|
||||
|
||||
public:
|
||||
/// @see RsGxsForums::createForum
|
||||
/// @see RsGxsForums::createForumV2
|
||||
bool createForumV2(
|
||||
const std::string& name, const std::string& description,
|
||||
const RsGxsId& authorId = RsGxsId(),
|
||||
const std::set<RsGxsId>& moderatorsIds = std::set<RsGxsId>(),
|
||||
RsGxsCircleType circleType = RsGxsCircleType::PUBLIC,
|
||||
const RsGxsCircleId& circleId = RsGxsCircleId(),
|
||||
RsGxsGroupId& forumId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// @see RsGxsForums::createPost
|
||||
bool createPost(
|
||||
const RsGxsGroupId& forumId,
|
||||
const std::string& title,
|
||||
const std::string& mBody,
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId = RsGxsMessageId(),
|
||||
const RsGxsMessageId& origPostId = RsGxsMessageId(),
|
||||
RsGxsMessageId& postMsgId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// @see RsGxsForums::createForum @deprecated
|
||||
RS_DEPRECATED_FOR(createForumV2)
|
||||
virtual bool createForum(RsGxsForumGroup& forum);
|
||||
|
||||
/// @see RsGxsForums::createMessage
|
||||
/// @see RsGxsForums::createMessage @deprecated
|
||||
RS_DEPRECATED_FOR(createPost)
|
||||
virtual bool createMessage(RsGxsForumMsg& message);
|
||||
|
||||
/// @see RsGxsForums::editForum
|
||||
virtual bool editForum(RsGxsForumGroup& forum);
|
||||
virtual bool editForum(RsGxsForumGroup& forum) override;
|
||||
|
||||
/// @see RsGxsForums::getForumsSummaries
|
||||
virtual bool getForumsSummaries(std::list<RsGroupMetaData>& forums);
|
||||
@ -78,7 +100,7 @@ public:
|
||||
/// @see RsGxsForums::getForumContent
|
||||
virtual bool getForumContent(
|
||||
const RsGxsGroupId& forumId,
|
||||
std::set<RsGxsMessageId>& msgs_to_request,
|
||||
const std::set<RsGxsMessageId>& msgs_to_request,
|
||||
std::vector<RsGxsForumMsg>& msgs );
|
||||
|
||||
/// @see RsGxsForums::markRead
|
||||
@ -130,5 +152,3 @@ bool generateGroup(uint32_t &token, std::string groupName);
|
||||
std::map<RsGxsGroupId,rstime_t> mKnownForums ;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user