2018-05-29 21:54:27 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/services: p3gxsforums.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
2019-08-01 11:33:00 +02:00
|
|
|
* Copyright (C) 2012-2014 Robert Fernie <retroshare@lunamutt.com> *
|
|
|
|
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
2018-05-29 21:54:27 +02:00
|
|
|
* *
|
|
|
|
* 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/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2019-08-01 11:33:00 +02:00
|
|
|
#pragma once
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2019-08-01 11:33:00 +02:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2012-11-09 00:56:07 +00:00
|
|
|
|
|
|
|
#include "retroshare/rsgxsforums.h"
|
|
|
|
#include "gxs/rsgenexchange.h"
|
2019-08-01 11:33:00 +02:00
|
|
|
#include "retroshare/rsgxscircles.h"
|
2012-11-19 22:00:05 +00:00
|
|
|
#include "util/rstickevent.h"
|
2019-08-01 11:33:00 +02:00
|
|
|
#include "util/rsdebug.h"
|
2012-11-19 22:00:05 +00:00
|
|
|
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2018-02-16 23:51:43 +01:00
|
|
|
class p3GxsForums: public RsGenExchange, public RsGxsForums, public p3Config,
|
2012-11-19 22:00:05 +00:00
|
|
|
public RsTickEvent /* only needed for testing - remove after */
|
2012-11-09 00:56:07 +00:00
|
|
|
{
|
2018-11-16 17:03:25 +01:00
|
|
|
public:
|
|
|
|
p3GxsForums(
|
|
|
|
RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2018-11-16 17:03:25 +01:00
|
|
|
virtual RsServiceInfo getServiceInfo();
|
|
|
|
virtual void service_tick();
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2018-11-16 17:03:25 +01:00
|
|
|
protected:
|
|
|
|
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
|
|
|
/// Overloaded from RsTickEvent.
|
|
|
|
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
2018-02-16 23:24:01 +01:00
|
|
|
|
|
|
|
virtual RsSerialiser* setupSerialiser(); // @see p3Config::setupSerialiser()
|
|
|
|
virtual bool saveList(bool &cleanup, std::list<RsItem *>&saveList); // @see p3Config::saveList(bool &cleanup, std::list<RsItem *>&)
|
|
|
|
virtual bool loadList(std::list<RsItem *>& loadList); // @see p3Config::loadList(std::list<RsItem *>&)
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2018-11-16 17:03:25 +01:00
|
|
|
public:
|
2019-08-01 11:33:00 +02:00
|
|
|
/// @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)
|
2018-11-16 17:03:25 +01:00
|
|
|
virtual bool createForum(RsGxsForumGroup& forum);
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2019-08-01 11:33:00 +02:00
|
|
|
/// @see RsGxsForums::createMessage @deprecated
|
|
|
|
RS_DEPRECATED_FOR(createPost)
|
2018-11-16 17:03:25 +01:00
|
|
|
virtual bool createMessage(RsGxsForumMsg& message);
|
2012-11-11 15:56:34 +00:00
|
|
|
|
2018-11-16 17:03:25 +01:00
|
|
|
/// @see RsGxsForums::editForum
|
2019-08-01 11:33:00 +02:00
|
|
|
virtual bool editForum(RsGxsForumGroup& forum) override;
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2018-11-16 17:03:25 +01:00
|
|
|
/// @see RsGxsForums::getForumsSummaries
|
|
|
|
virtual bool getForumsSummaries(std::list<RsGroupMetaData>& forums);
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2018-11-16 17:03:25 +01:00
|
|
|
/// @see RsGxsForums::getForumsInfo
|
|
|
|
virtual bool getForumsInfo(
|
|
|
|
const std::list<RsGxsGroupId>& forumIds,
|
|
|
|
std::vector<RsGxsForumGroup>& forumsInfo );
|
2018-11-10 16:30:35 +01:00
|
|
|
|
2020-03-22 21:47:14 +01:00
|
|
|
/// Implementation of @see RsGxsForums::getForumStatistics
|
|
|
|
bool getForumStatistics(const RsGxsGroupId& ForumId,GxsGroupStatistic& stat) override;
|
|
|
|
|
2020-04-04 22:54:54 +02:00
|
|
|
/// Implementation of @see RsGxsForums::getForumServiceStatistics
|
|
|
|
bool getForumServiceStatistics(GxsServiceStatistic& stat) override;
|
|
|
|
|
2018-12-12 11:33:38 +01:00
|
|
|
/// @see RsGxsForums::getForumMsgMetaData
|
|
|
|
virtual bool getForumMsgMetaData(const RsGxsGroupId& forumId, std::vector<RsMsgMetaData>& msg_metas) ;
|
|
|
|
|
2018-12-16 17:40:47 +01:00
|
|
|
/// @see RsGxsForums::getForumContent
|
|
|
|
virtual bool getForumContent(
|
|
|
|
const RsGxsGroupId& forumId,
|
2019-08-01 11:33:00 +02:00
|
|
|
const std::set<RsGxsMessageId>& msgs_to_request,
|
2018-12-16 17:40:47 +01:00
|
|
|
std::vector<RsGxsForumMsg>& msgs );
|
2018-11-22 22:07:58 +01:00
|
|
|
|
2018-11-16 17:03:25 +01:00
|
|
|
/// @see RsGxsForums::markRead
|
|
|
|
virtual bool markRead(const RsGxsGrpMsgIdPair& messageId, bool read);
|
2012-11-19 22:00:05 +00:00
|
|
|
|
2018-11-22 16:41:19 +01:00
|
|
|
/// @see RsGxsForums::subscribeToForum
|
|
|
|
virtual bool subscribeToForum( const RsGxsGroupId& forumId,
|
|
|
|
bool subscribe );
|
|
|
|
|
2019-10-29 12:09:54 +01:00
|
|
|
/// @see RsGxsForums
|
|
|
|
bool exportForumLink(
|
|
|
|
std::string& link, const RsGxsGroupId& forumId,
|
|
|
|
bool includeGxsData = true,
|
|
|
|
const std::string& baseUrl = DEFAULT_FORUM_BASE_URL,
|
|
|
|
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
|
|
|
|
) override;
|
|
|
|
|
|
|
|
/// @see RsGxsForums
|
|
|
|
bool importForumLink(
|
|
|
|
const std::string& link,
|
|
|
|
RsGxsGroupId& forumId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
|
|
|
|
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
|
|
|
|
) override;
|
|
|
|
|
2020-03-22 21:47:14 +01:00
|
|
|
/// implementation of rsGxsGorums
|
|
|
|
///
|
|
|
|
bool getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups) override;
|
|
|
|
bool getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs) override;
|
|
|
|
void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) override;
|
|
|
|
bool createGroup(uint32_t &token, RsGxsForumGroup &group) override;
|
|
|
|
bool createMsg(uint32_t &token, RsGxsForumMsg &msg) override;
|
|
|
|
bool updateGroup(uint32_t &token, const RsGxsForumGroup &group) override;
|
|
|
|
|
|
|
|
bool getMsgMetaData(const uint32_t &token, GxsMsgMetaMap& msg_metas) ;
|
2012-11-19 22:00:05 +00:00
|
|
|
|
2018-11-16 17:03:25 +01:00
|
|
|
private:
|
2012-11-09 00:56:07 +00:00
|
|
|
|
2013-02-10 17:41:30 +00:00
|
|
|
static uint32_t forumsAuthenPolicy();
|
|
|
|
|
2012-11-19 22:00:05 +00:00
|
|
|
virtual bool generateDummyData();
|
|
|
|
|
2012-11-09 00:56:07 +00:00
|
|
|
std::string genRandomId();
|
|
|
|
|
2012-11-15 23:50:54 +00:00
|
|
|
void dummy_tick();
|
|
|
|
|
|
|
|
bool generateMessage(uint32_t &token, const RsGxsGroupId &grpId,
|
|
|
|
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
|
|
|
|
bool generateGroup(uint32_t &token, std::string groupName);
|
|
|
|
|
|
|
|
class ForumDummyRef
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ForumDummyRef() { return; }
|
|
|
|
ForumDummyRef(const RsGxsGroupId &grpId, const RsGxsMessageId &threadId, const RsGxsMessageId &msgId)
|
|
|
|
:mGroupId(grpId), mThreadId(threadId), mMsgId(msgId) { return; }
|
|
|
|
|
|
|
|
RsGxsGroupId mGroupId;
|
|
|
|
RsGxsMessageId mThreadId;
|
|
|
|
RsGxsMessageId mMsgId;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t mGenToken;
|
|
|
|
bool mGenActive;
|
|
|
|
int mGenCount;
|
|
|
|
std::vector<ForumDummyRef> mGenRefs;
|
|
|
|
RsGxsMessageId mGenThreadId;
|
2018-10-07 01:34:05 +02:00
|
|
|
std::map<RsGxsGroupId,rstime_t> mKnownForums ;
|
2012-11-15 23:50:54 +00:00
|
|
|
|
2019-12-16 22:44:37 +01:00
|
|
|
RsMutex mKnownForumsMutex;
|
2012-11-09 00:56:07 +00:00
|
|
|
};
|