From f84824271f092dbac34a8481027b063c35dafc97 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 10 Nov 2018 16:24:47 +0100 Subject: [PATCH 1/8] Implement ostream operator<< for RsSerializable So it is not necessary to define it for each class we want to print in debug --- libretroshare/src/libretroshare.pro | 3 +- .../src/serialiser/rsserializable.cc | 31 +++++++++++++++++++ libretroshare/src/serialiser/rsserializable.h | 5 +++ libretroshare/src/util/rsjson.h | 2 +- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 libretroshare/src/serialiser/rsserializable.cc diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index f6094100e..6adf9970d 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -764,7 +764,8 @@ HEADERS += serialiser/rsserializable.h \ serialiser/rstypeserializer.h \ util/rsjson.h -SOURCES += serialiser/rsserializer.cc \ +SOURCES += serialiser/rsserializable.cc \ + serialiser/rsserializer.cc \ serialiser/rstypeserializer.cc \ util/rsjson.cc diff --git a/libretroshare/src/serialiser/rsserializable.cc b/libretroshare/src/serialiser/rsserializable.cc new file mode 100644 index 000000000..a5a329e6d --- /dev/null +++ b/libretroshare/src/serialiser/rsserializable.cc @@ -0,0 +1,31 @@ +/******************************************************************************* + * libretroshare: retroshare core library * + * * + * Copyright (C) 2018 Gioacchino Mazzurco * + * * + * 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 . * + * * + *******************************************************************************/ + +#include "serialiser/rsserializable.h" + +#include + +std::ostream& operator<<(std::ostream& out, const RsSerializable& serializable) +{ + RsGenericSerializer::SerializeContext ctx; + const_cast(serializable) // safe with TO_JSON + .serial_process(RsGenericSerializer::TO_JSON, ctx); + return out << ctx.mJson; +} diff --git a/libretroshare/src/serialiser/rsserializable.h b/libretroshare/src/serialiser/rsserializable.h index fc6d73662..147cce20e 100644 --- a/libretroshare/src/serialiser/rsserializable.h +++ b/libretroshare/src/serialiser/rsserializable.h @@ -20,8 +20,11 @@ * * *******************************************************************************/ #pragma once + #include "serialiser/rsserializer.h" +#include + /** @brief Minimal ancestor for all serializable structs in RetroShare. * If you want your struct to be easly serializable you should inherit from this @@ -49,3 +52,5 @@ struct RsSerializable #define RS_SERIAL_PROCESS(I) do { \ RsTypeSerializer::serial_process(j, ctx, I, #I ); \ } while(0) + +std::ostream &operator<<(std::ostream& out, const RsSerializable& serializable); diff --git a/libretroshare/src/util/rsjson.h b/libretroshare/src/util/rsjson.h index c52584b7e..8bbb2a992 100644 --- a/libretroshare/src/util/rsjson.h +++ b/libretroshare/src/util/rsjson.h @@ -39,7 +39,7 @@ typedef rapidjson::Document RsJson; * @param[in] jDoc JSON document to print * @return same output stream passed as out parameter */ -std::ostream &operator<<(std::ostream &out, const RsJson &jDoc); +std::ostream& operator<<(std::ostream &out, const RsJson &jDoc); /** * Stream manipulator to print RsJson in compact format From 72dd985162c9924e47c6d1e99c4bbbe1cd9fbc8b Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 10 Nov 2018 16:28:15 +0100 Subject: [PATCH 2/8] Deprecate TLV items, to avoid temptation to use them in new code --- libretroshare/src/serialiser/rstlvidset.h | 8 +++++--- libretroshare/src/serialiser/rstlvitem.h | 16 +++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/serialiser/rstlvidset.h b/libretroshare/src/serialiser/rstlvidset.h index f722947de..732eee64c 100644 --- a/libretroshare/src/serialiser/rstlvidset.h +++ b/libretroshare/src/serialiser/rstlvidset.h @@ -28,13 +28,15 @@ #include "serialiser/rstlvbase.h" #include "serialiser/rstlvitem.h" - +#include "util/rsdeprecate.h" #include #include #include -template class t_RsTlvIdSet: public RsTlvItem +/// @deprecated use plain std::set<> instead +template class RS_DEPRECATED_FOR(std::set<>) t_RsTlvIdSet + : public RsTlvItem { public: t_RsTlvIdSet() {} @@ -122,7 +124,7 @@ typedef t_RsTlvIdSet RsTlvGxsMsgIdSet typedef t_RsTlvIdSet RsTlvGxsCircleIdSet ; typedef t_RsTlvIdSet RsTlvNodeGroupIdSet ; -class RsTlvServiceIdSet: public RsTlvItem +class RS_DEPRECATED RsTlvServiceIdSet: public RsTlvItem { public: RsTlvServiceIdSet() { return; } diff --git a/libretroshare/src/serialiser/rstlvitem.h b/libretroshare/src/serialiser/rstlvitem.h index 1623a8224..4d45cd120 100644 --- a/libretroshare/src/serialiser/rstlvitem.h +++ b/libretroshare/src/serialiser/rstlvitem.h @@ -26,15 +26,18 @@ * ******************************************************************/ +#include "util/rsdeprecate.h" + #include #include #include -//! A base class for all tlv items -/*! This class is provided to allow the serialisation and deserialization of compund -tlv items -*/ -class RsTlvItem +/*! A base class for all tlv items + * This class is provided to allow the serialisation and deserialization of + * compund tlv items + * @deprecated TLV serialization system is deprecated! + */ +class RS_DEPRECATED_FOR(RsSerializable) RsTlvItem { public: RsTlvItem() { return; } @@ -51,8 +54,7 @@ std::ostream &printEnd(std::ostream &out, std::string clsName, uint16_t indent) std::ostream &printIndent(std::ostream &out, uint16_t indent); - -class RsTlvUnit: public RsTlvItem +class RS_DEPRECATED_FOR(RsSerializable) RsTlvUnit: public RsTlvItem { public: RsTlvUnit(uint16_t tlv_type); From 1d110600fc48bac6c5766e15a78bb39a6b498523 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 10 Nov 2018 16:29:39 +0100 Subject: [PATCH 3/8] Minor cleanups in GxsChannels --- libretroshare/src/retroshare/rsgxschannels.h | 7 +------ libretroshare/src/services/p3gxschannels.cc | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 37edf7b05..6aa4a6081 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -1,4 +1,3 @@ -#pragma once /******************************************************************************* * libretroshare/src/retroshare: rsgxschannels.h * * * @@ -21,6 +20,7 @@ * along with this program. If not, see . * * * *******************************************************************************/ +#pragma once #include #include @@ -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 { diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 0b4c05dca..380f1d378 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -1033,7 +1033,7 @@ bool p3GxsChannels::createChannel(RsGxsChannelGroup& channel) uint32_t token; if(!createGroup(token, channel)) { - std::cerr << __PRETTY_FUNCTION__ << "Error! Failed updating group." + std::cerr << __PRETTY_FUNCTION__ << "Error! Failed creating group." << std::endl; return false; } From 8b8ad3bce5ccf380b151b15e6359113df09fca7c Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 10 Nov 2018 16:30:35 +0100 Subject: [PATCH 4/8] Forum API for creation and posting Deprecate old functions that expose internal functioning --- libretroshare/src/retroshare/rsgxsforums.h | 96 +++++++++++++++------- libretroshare/src/services/p3gxsforums.cc | 38 +++++++++ libretroshare/src/services/p3gxsforums.h | 3 + 3 files changed, 108 insertions(+), 29 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 690523055..f5121b64c 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -3,7 +3,8 @@ * * * libretroshare: retroshare core library * * * - * Copyright 2012-2012 by Robert Fernie * + * Copyright (C) 2012 by Robert Fernie * + * Copyright (C) 2018 Gioacchino Mazzurco * * * * 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,61 +20,98 @@ * along with this program. If not, see . * * * *******************************************************************************/ -#ifndef RETROSHARE_GXS_FORUM_GUI_INTERFACE_H -#define RETROSHARE_GXS_FORUM_GUI_INTERFACE_H +#pragma once -#include +#include #include #include #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 > 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; + + /* Specific Service Data */ virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; virtual bool getMsgData(const uint32_t &token, std::vector &msgs) = 0; @@ -89,8 +127,12 @@ public: //virtual bool groupRestoreKeys(const std::string &groupId); //virtual bool groupShareKeys(const std::string &groupId, std::list& 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 @@ -98,9 +140,5 @@ public: * @return false groupId not set, true if set and accepted (still check token for completion) */ virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group) = 0; - }; - - -#endif diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index ccee5ba71..f913b5e1f 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -379,6 +379,33 @@ bool p3GxsForums::getMsgData(const uint32_t &token, std::vector & /********************************************************************************************/ +bool p3GxsForums::createForum(RsGxsForumGroup& forum) +{ + uint32_t token; + if(!createGroup(token, forum)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failed creating group." + << std::endl; + return false; + } + + if(waitToken(token) != RsTokenService::COMPLETE) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed." + << std::endl; + return false; + } + + if(!RsGenExchange::getPublishedGroupMeta(token, forum.mMeta)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting updated " + << " group data." << std::endl; + return false; + } + + return true; +} + bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group) { std::cerr << "p3GxsForums::createGroup()" << std::endl; @@ -407,6 +434,17 @@ bool p3GxsForums::updateGroup(uint32_t &token, RsGxsForumGroup &group) return true; } +bool p3GxsForums::createMessage(RsGxsForumMsg& message) +{ + uint32_t token; + if( !createMsg(token, message) + || waitToken(token) != RsTokenService::COMPLETE ) return false; + + if(RsGenExchange::getPublishedMsgMeta(token, message.mMeta)) return true; + + return false; +} + bool p3GxsForums::createMsg(uint32_t &token, RsGxsForumMsg &msg) { std::cerr << "p3GxsForums::createForumMsg() GroupId: " << msg.mMeta.mGroupId; diff --git a/libretroshare/src/services/p3gxsforums.h b/libretroshare/src/services/p3gxsforums.h index ef3dd46d8..3e88d0cb3 100644 --- a/libretroshare/src/services/p3gxsforums.h +++ b/libretroshare/src/services/p3gxsforums.h @@ -74,6 +74,9 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI //virtual bool groupRestoreKeys(const std::string &groupId); //virtual bool groupShareKeys(const std::string &groupId, std::list& peers); + virtual bool createForum(RsGxsForumGroup& forum); + virtual bool createMessage(RsGxsForumMsg& message); + virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group); virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg); From ba58eba34e7d8549b9df8df6edf85789f04dc9e6 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Fri, 16 Nov 2018 17:03:25 +0100 Subject: [PATCH 5/8] Complete API for forums Add new blocking methods Deprecate old unsafe methods --- libretroshare/src/retroshare/rsgxsforums.h | 70 ++++++++++++++------ libretroshare/src/services/p3gxsforums.cc | 70 ++++++++++++++++++++ libretroshare/src/services/p3gxsforums.h | 76 +++++++++++----------- 3 files changed, 158 insertions(+), 58 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index f5121b64c..4c6b6e483 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -111,34 +111,66 @@ public: */ 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& 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& forumIds, + std::vector& 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& forumIds, + std::vector& 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 &groups) = 0; + RS_DEPRECATED_FOR(getForumsContent) virtual bool getMsgData(const uint32_t &token, std::vector &msgs) = 0; - //Not currently used - //virtual bool getRelatedMessages(const uint32_t &token, std::vector &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& 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; }; diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index f913b5e1f..09680f196 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -406,6 +406,76 @@ bool p3GxsForums::createForum(RsGxsForumGroup& forum) return true; } +bool p3GxsForums::editForum(RsGxsForumGroup& forum) +{ + uint32_t token; + if(!updateGroup(token, forum)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failed updating group." + << std::endl; + return false; + } + + if(waitToken(token) != RsTokenService::COMPLETE) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed." + << std::endl; + return false; + } + + if(!RsGenExchange::getPublishedGroupMeta(token, forum.mMeta)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting updated " + << " group data." << std::endl; + return false; + } + + return true; +} + +bool p3GxsForums::getForumsSummaries( + std::list& forums ) +{ + uint32_t token; + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; + if( !requestGroupInfo(token, opts) + || waitToken(token) != RsTokenService::COMPLETE ) return false; + return getGroupSummary(token, forums); +} + +bool p3GxsForums::getForumsInfo( + const std::list& forumIds, + std::vector& forumsInfo ) +{ + uint32_t token; + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; + if( !requestGroupInfo(token, opts, forumIds) + || waitToken(token) != RsTokenService::COMPLETE ) return false; + return getGroupData(token, forumsInfo); +} + +bool p3GxsForums::getForumsContent( + const std::list& forumIds, + std::vector& messages ) +{ + uint32_t token; + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; + if( !requestMsgInfo(token, opts, forumIds) + || waitToken(token) != RsTokenService::COMPLETE ) return false; + return getMsgData(token, messages); +} + +bool p3GxsForums::markRead(const RsGxsGrpMsgIdPair& msgId, bool read) +{ + uint32_t token; + setMessageReadStatus(token, msgId, read); + if(waitToken(token) != RsTokenService::COMPLETE ) return false; + return true; +} + bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group) { std::cerr << "p3GxsForums::createGroup()" << std::endl; diff --git a/libretroshare/src/services/p3gxsforums.h b/libretroshare/src/services/p3gxsforums.h index 3e88d0cb3..36b40a972 100644 --- a/libretroshare/src/services/p3gxsforums.h +++ b/libretroshare/src/services/p3gxsforums.h @@ -38,58 +38,56 @@ class p3GxsForums: public RsGenExchange, public RsGxsForums, public p3Config, public RsTickEvent /* only needed for testing - remove after */ { - public: +public: + p3GxsForums( + RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs); - p3GxsForums(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs); + virtual RsServiceInfo getServiceInfo(); + virtual void service_tick(); -virtual RsServiceInfo getServiceInfo(); - -virtual void service_tick(); - - protected: - - -virtual void notifyChanges(std::vector& changes); - - // Overloaded from RsTickEvent. -virtual void handle_event(uint32_t event_type, const std::string &elabel); +protected: + virtual void notifyChanges(std::vector& changes); + /// Overloaded from RsTickEvent. + virtual void handle_event(uint32_t event_type, const std::string &elabel); virtual RsSerialiser* setupSerialiser(); // @see p3Config::setupSerialiser() virtual bool saveList(bool &cleanup, std::list&saveList); // @see p3Config::saveList(bool &cleanup, std::list&) virtual bool loadList(std::list& loadList); // @see p3Config::loadList(std::list&) - public: - -virtual bool getGroupData(const uint32_t &token, std::vector &groups); -virtual bool getMsgData(const uint32_t &token, std::vector &msgs); -//Not currently used -//virtual bool getRelatedMessages(const uint32_t &token, std::vector &msgs); - - ////////////////////////////////////////////////////////////////////////////// -virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read); - -//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& peers); - +public: + /// @see RsGxsForums::createForum virtual bool createForum(RsGxsForumGroup& forum); + + /// @see RsGxsForums::createMessage virtual bool createMessage(RsGxsForumMsg& message); -virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group); -virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg); + /// @see RsGxsForums::editForum + virtual bool editForum(RsGxsForumGroup& forum); -/*! - * 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) - */ -virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group); + /// @see RsGxsForums::getForumsSummaries + virtual bool getForumsSummaries(std::list& forums); + /// @see RsGxsForums::getForumsInfo + virtual bool getForumsInfo( + const std::list& forumIds, + std::vector& forumsInfo ); - private: + /// @see RsGxsForums::getForumsContent + virtual bool getForumsContent( + const std::list& forumIds, + std::vector& messages ); + + /// @see RsGxsForums::markRead + virtual bool markRead(const RsGxsGrpMsgIdPair& messageId, bool read); + + virtual bool getGroupData(const uint32_t &token, std::vector &groups); + virtual bool getMsgData(const uint32_t &token, std::vector &msgs); + virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read); + virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group); + virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg); + virtual bool updateGroup(uint32_t &token, RsGxsForumGroup &group); + +private: static uint32_t forumsAuthenPolicy(); From e311b2887010ae2b130c68ea97ded78d27b42621 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Fri, 16 Nov 2018 17:50:34 +0100 Subject: [PATCH 6/8] Complete channel API with comment and vote creation --- libretroshare/src/retroshare/rsgxschannels.h | 16 ++++++ libretroshare/src/services/p3gxschannels.cc | 54 ++++++++++++++++++++ libretroshare/src/services/p3gxschannels.h | 6 +++ 3 files changed, 76 insertions(+) diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 6aa4a6081..aa89b9341 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -107,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} @@ -115,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} diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 380f1d378..84610b107 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -1059,6 +1059,60 @@ bool p3GxsChannels::createChannel(RsGxsChannelGroup& channel) return true; } +bool p3GxsChannels::createComment(RsGxsComment& comment) +{ + uint32_t token; + if(!createComment(token, comment)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failed creating comment." + << std::endl; + return false; + } + + if(waitToken(token) != RsTokenService::COMPLETE) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed." + << std::endl; + return false; + } + + if(!RsGenExchange::getPublishedMsgMeta(token, comment.mMeta)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting generated " + << " comment data." << std::endl; + return false; + } + + return true; +} + +bool p3GxsChannels::createVote(RsGxsVote& vote) +{ + uint32_t token; + if(!createVote(token, vote)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failed creating vote." + << std::endl; + return false; + } + + if(waitToken(token) != RsTokenService::COMPLETE) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! GXS operation failed." + << std::endl; + return false; + } + + if(!RsGenExchange::getPublishedMsgMeta(token, vote.mMeta)) + { + std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting generated " + << " vote data." << std::endl; + return false; + } + + return true; +} + bool p3GxsChannels::editChannel(RsGxsChannelGroup& channel) { uint32_t token; diff --git a/libretroshare/src/services/p3gxschannels.h b/libretroshare/src/services/p3gxschannels.h index 3caf31c59..e5d49772b 100644 --- a/libretroshare/src/services/p3gxschannels.h +++ b/libretroshare/src/services/p3gxschannels.h @@ -189,12 +189,18 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); /// Implementation of @see RsGxsChannels::createChannel virtual bool createChannel(RsGxsChannelGroup& channel); + /// Implementation of @see RsGxsChannels::createComment + virtual bool createComment(RsGxsComment& comment); + /// Implementation of @see RsGxsChannels::editChannel virtual bool editChannel(RsGxsChannelGroup& channel); /// Implementation of @see RsGxsChannels::createPost virtual bool createPost(RsGxsChannelPost& post); + /// Implementation of @see RsGxsChannels::createVote + virtual bool createVote(RsGxsVote& vote); + /// Implementation of @see RsGxsChannels::subscribeToChannel virtual bool subscribeToChannel( const RsGxsGroupId &groupId, bool subscribe ); From f670a18b13aa0cdef984923e914d1621fb352caf Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Fri, 16 Nov 2018 19:09:37 +0100 Subject: [PATCH 7/8] Break too long line in retroshare.pri --- retroshare.pri | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/retroshare.pri b/retroshare.pri index a8025dc79..dd0032b54 100644 --- a/retroshare.pri +++ b/retroshare.pri @@ -111,8 +111,9 @@ rs_onlyhiddennode:CONFIG -= no_rs_onlyhiddennode CONFIG *= rs_gxs no_rs_gxs:CONFIG -= rs_gxs -# To disable GXS distrubuting all available posts independed of the "sync" settings append the following -# assignation to qmake command line "CONFIG+=no_rs_gxs_send_all" +# To disable GXS distrubuting all available posts independed of the "sync" +# settings append the following assignation to qmake command line +# "CONFIG+=no_rs_gxs_send_all" CONFIG *= rs_gxs_send_all no_rs_gxs_send_all:CONFIG -= rs_gxs_send_all From 2b58e3f461989843d9e57ab8ef1f70a1c052bdd6 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 17 Nov 2018 17:19:13 +0100 Subject: [PATCH 8/8] RsGxsChannels local search support --- libretroshare/src/gxs/rsgenexchange.cc | 6 +++++ libretroshare/src/gxs/rsgenexchange.h | 9 +++++++ libretroshare/src/retroshare/rsgxschannels.h | 13 +++++++++ libretroshare/src/services/p3gxschannels.cc | 28 +++++++++++++++++++- libretroshare/src/services/p3gxschannels.h | 5 ++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 183751356..27c8c260a 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -3429,3 +3429,9 @@ void RsGenExchange::turtleSearchRequest(const std::string& match_string) { mNetService->turtleSearchRequest(match_string) ; } + +bool RsGenExchange::localSearch( const std::string& matchString, + std::list& results ) +{ + return mNetService->search(matchString, results); +} diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index a180c7741..ea3a43d7c 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -313,6 +313,15 @@ public: void turtleGroupRequest(const RsGxsGroupId& group_id); void turtleSearchRequest(const std::string& match_string); + /** + * @brief Search local groups. Blocking API. + * @param matchString string to look for in the search + * @param results storage for results + * @return false on error, true otherwise + */ + bool localSearch( const std::string& matchString, + std::list& results ); + protected: bool messagePublicationTest(const RsGxsMsgMetaData&) ; diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index aa89b9341..f1aef6e7f 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -287,6 +287,19 @@ public: const std::function& 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& multiCallback, + rstime_t maxWait = 30 ) = 0; + /* Following functions are deprecated as they expose internal functioning * semantic, instead of a safe to use API */ diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 84610b107..847395686 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -36,6 +36,7 @@ #include "retroshare/rsnotify.h" #include +#include // For Dummy Msgs. #include "util/rsrandom.h" @@ -50,7 +51,7 @@ * #define GXSCHANNEL_DEBUG 1 ****/ -/*extern*/ RsGxsChannels *rsGxsChannels = nullptr; +/*extern*/ RsGxsChannels* rsGxsChannels = nullptr; #define GXSCHANNEL_STOREPERIOD (3600 * 24 * 30) @@ -1969,6 +1970,31 @@ bool p3GxsChannels::turtleChannelRequest( return true; } +/// @see RsGxsChannels::localSearchRequest +bool p3GxsChannels::localSearchRequest( + const std::string& matchString, + const std::function& multiCallback, + rstime_t maxWait ) +{ + if(matchString.empty()) + { + std::cerr << __PRETTY_FUNCTION__ << " match string can't be empty!" + << std::endl; + return false; + } + + auto timeout = std::chrono::steady_clock::now() + std::chrono::seconds(maxWait); + RsThread::async([=]() + { + std::list results; + RsGenExchange::localSearch(matchString, results); + if(std::chrono::steady_clock::now() < timeout) + for(const RsGxsGroupSummary& result : results) multiCallback(result); + }); + + return true; +} + void p3GxsChannels::receiveDistantSearchResults( TurtleRequestId id, const RsGxsGroupId& grpId ) { diff --git a/libretroshare/src/services/p3gxschannels.h b/libretroshare/src/services/p3gxschannels.h index e5d49772b..20be70aec 100644 --- a/libretroshare/src/services/p3gxschannels.h +++ b/libretroshare/src/services/p3gxschannels.h @@ -118,6 +118,11 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin const std::function& multiCallback, rstime_t maxWait = 300 ); + /// @see RsGxsChannels::localSearchRequest + virtual bool localSearchRequest(const std::string& matchString, + const std::function& multiCallback, + rstime_t maxWait = 30 ) override; + /** * Receive results from turtle search @see RsGenExchange @see RsNxsObserver * @see RsGxsNetService::receiveTurtleSearchResults