Implement GXS forum reasonable JSON API

Remove misleading comments around, and add some TODO of things we should
  fix at some point
This commit is contained in:
Gioacchino Mazzurco 2019-08-01 11:33:00 +02:00
parent 3ffb57f998
commit eff133b564
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
7 changed files with 353 additions and 85 deletions

View file

@ -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

View file

@ -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;
}
};

View file

@ -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

View file

@ -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;

View file

@ -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