Merge pull request #1401 from G10h4ck/forum_api

0.6.5 Safer forum API
This commit is contained in:
csoler 2018-11-20 21:45:45 +01:00 committed by GitHub
commit a802e494f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 453 additions and 102 deletions

View file

@ -1,4 +1,3 @@
#pragma once
/*******************************************************************************
* libretroshare/src/retroshare: rsgxschannels.h *
* *
@ -21,6 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#pragma once
#include <cstdint>
#include <string>
@ -62,9 +62,6 @@ struct RsGxsChannelGroup : RsSerializable
}
};
std::ostream &operator<<(std::ostream& out, const RsGxsChannelGroup& group);
struct RsGxsChannelPost : RsSerializable
{
RsGxsChannelPost() : mCount(0), mSize(0) {}
@ -95,8 +92,6 @@ struct RsGxsChannelPost : RsSerializable
}
};
std::ostream &operator<<(std::ostream& out, const RsGxsChannelPost& post);
class RsGxsChannels: public RsGxsIfaceHelper, public RsGxsCommentService
{
@ -112,6 +107,14 @@ public:
*/
virtual bool createChannel(RsGxsChannelGroup& channel) = 0;
/**
* @brief Add a comment on a post or on another comment
* @jsonapi{development}
* @param[inout] comment
* @return false on error, true otherwise
*/
virtual bool createComment(RsGxsComment& comment) = 0;
/**
* @brief Create channel post. Blocking API.
* @jsonapi{development}
@ -120,6 +123,14 @@ public:
*/
virtual bool createPost(RsGxsChannelPost& post) = 0;
/**
* @brief createVote
* @jsonapi{development}
* @param[inout] vote
* @return false on error, true otherwise
*/
virtual bool createVote(RsGxsVote& vote) = 0;
/**
* @brief Edit channel details.
* @jsonapi{development}
@ -276,6 +287,19 @@ public:
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
rstime_t maxWait = 300 ) = 0;
/**
* @brief Search local channels
* @jsonapi{development}
* @param[in] matchString string to look for in the search
* @param multiCallback function that will be called for each result
* @param[in] maxWait maximum wait time in seconds for search results
* @return false on error, true otherwise
*/
virtual bool localSearchRequest(
const std::string& matchString,
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
rstime_t maxWait = 30 ) = 0;
/* Following functions are deprecated as they expose internal functioning
* semantic, instead of a safe to use API */

View file

@ -3,7 +3,8 @@
* *
* libretroshare: retroshare core library *
* *
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2012 by Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2018 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,88 +20,157 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef RETROSHARE_GXS_FORUM_GUI_INTERFACE_H
#define RETROSHARE_GXS_FORUM_GUI_INTERFACE_H
#pragma once
#include <inttypes.h>
#include <cstdint>
#include <string>
#include <list>
#include "retroshare/rstokenservice.h"
#include "retroshare/rsgxsifacehelper.h"
#include "serialiser/rstlvidset.h"
#include "serialiser/rsserializable.h"
// Forum Service message flags, to be used in RsMsgMetaData::mMsgFlags
// 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.
static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MASK = 0x0000000f ;
static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001 ;
#define IS_FORUM_MSG_MODERATION(flags) (flags & RS_GXS_FORUM_MSG_FLAGS_MODERATED)
/* The Main Interface Class - for information about your Peers */
class RsGxsForums;
extern RsGxsForums *rsGxsForums;
class RsGxsForumGroup
/**
* Pointer to global instance of RsGxsChannels service implementation
* @jsonapi{development}
*/
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
* private forum flags, the upper bytes being used for internal GXS stuff.
*/
static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MASK = 0x0000000f;
static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001;
#define IS_FORUM_MSG_MODERATION(flags) (flags & RS_GXS_FORUM_MSG_FLAGS_MODERATED)
struct RsGxsForumGroup : RsSerializable
{
public:
RsGroupMetaData mMeta;
std::string mDescription;
// What's below is optional, and handled by the serialiser
/* What's below is optional, and handled by the serialiser
* TODO: run away from TLV old serializables as those types are opaque to
* JSON API! */
RsTlvGxsIdSet mAdminList;
RsTlvGxsMsgIdSet mPinnedPosts;
RsTlvGxsIdSet mAdminList;
RsTlvGxsMsgIdSet mPinnedPosts;
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mDescription);
RS_SERIAL_PROCESS(mAdminList);
RS_SERIAL_PROCESS(mPinnedPosts);
}
};
class RsGxsForumMsg
struct RsGxsForumMsg : RsSerializable
{
public:
RsMsgMetaData mMeta;
std::string mMsg;
/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mMsg);
}
};
//typedef std::map<RsGxsGroupId, std::vector<RsGxsForumMsg> > GxsForumMsgResult;
std::ostream &operator<<(std::ostream &out, const RsGxsForumGroup &group);
std::ostream &operator<<(std::ostream &out, const RsGxsForumMsg &msg);
class RsGxsForums: public RsGxsIfaceHelper
{
public:
explicit RsGxsForums(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsGxsForums() {}
/**
* @brief Create forum. Blocking API.
* @jsonapi{development}
* @param[inout] forum Forum data (name, description...)
* @return false on error, true otherwise
*/
virtual bool createForum(RsGxsForumGroup& forum) = 0;
/**
* @brief Create forum message. Blocking API.
* @jsonapi{development}
* @param[inout] message
* @return false on error, true otherwise
*/
virtual bool createMessage(RsGxsForumMsg& message) = 0;
/**
* @brief Edit forum details.
* @jsonapi{development}
* @param[in] forum Forum data (name, description...) with modifications
* @return false on error, true otherwise
*/
virtual bool editForum(RsGxsForumGroup& forum) = 0;
/**
* @brief Get forums summaries list. Blocking API.
* @jsonapi{development}
* @param[out] forums list where to store the forums summaries
* @return false if something failed, true otherwhise
*/
virtual bool getForumsSummaries(std::list<RsGroupMetaData>& forums) = 0;
/**
* @brief Get forums information (description, thumbnail...).
* Blocking API.
* @jsonapi{development}
* @param[in] forumIds ids of the forums of which to get the informations
* @param[out] forumsInfo storage for the forums informations
* @return false if something failed, true otherwhise
*/
virtual bool getForumsInfo(
const std::list<RsGxsGroupId>& forumIds,
std::vector<RsGxsForumGroup>& forumsInfo ) = 0;
/**
* @brief Get content of specified forums. Blocking API
* @jsonapi{development}
* @param[in] forumIds id of the channels of which the content is requested
* @param[out] messages storage for the forum messages
* @return false if something failed, true otherwhise
*/
virtual bool getForumsContent(
const std::list<RsGxsGroupId>& forumIds,
std::vector<RsGxsForumMsg>& messages ) = 0;
/**
* @brief Toggle message read status. Blocking API.
* @jsonapi{development}
* @param[in] messageId post identifier
* @param[in] read true to mark as read, false to mark as unread
* @return false on error, true otherwise
*/
virtual bool markRead(const RsGxsGrpMsgIdPair& messageId, bool read) = 0;
/* Specific Service Data */
RS_DEPRECATED_FOR("getForumsSummaries, getForumsInfo")
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups) = 0;
RS_DEPRECATED_FOR(getForumsContent)
virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs) = 0;
//Not currently used
//virtual bool getRelatedMessages(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs) = 0;
//////////////////////////////////////////////////////////////////////////////
RS_DEPRECATED_FOR(markRead)
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
//virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask);
//virtual bool groupRestoreKeys(const std::string &groupId);
//virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
RS_DEPRECATED_FOR(createForum)
virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group) = 0;
RS_DEPRECATED_FOR(createMessage)
virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg) = 0;
/*!
* To update forum group with new information
* @param token the token used to check completion status of update
* @param group group to be updated, groupId element must be set or will be rejected
* @return false groupId not set, true if set and accepted (still check token for completion)
*/
RS_DEPRECATED_FOR(editForum)
virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group) = 0;
};
#endif