2013-03-04 15:26:48 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services: p3gxschannels.h
|
|
|
|
*
|
|
|
|
* GxsChannel interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef P3_GXSCHANNELS_SERVICE_HEADER
|
|
|
|
#define P3_GXSCHANNELS_SERVICE_HEADER
|
|
|
|
|
|
|
|
|
|
|
|
#include "retroshare/rsgxschannels.h"
|
|
|
|
#include "services/p3gxscommon.h"
|
|
|
|
#include "gxs/rsgenexchange.h"
|
2013-03-11 16:40:28 -04:00
|
|
|
#include "gxs/gxstokenqueue.h"
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
#include "util/rstickevent.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
|
|
|
|
class SSGxsChannelGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool load(const std::string &input);
|
|
|
|
std::string save() const;
|
|
|
|
|
|
|
|
bool mAutoDownload;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
class p3GxsChannels: public RsGenExchange, public RsGxsChannels,
|
2013-03-11 16:40:28 -04:00
|
|
|
public GxsTokenQueue,
|
2013-03-04 15:26:48 -05:00
|
|
|
public RsTickEvent /* only needed for testing - remove after */
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
p3GxsChannels(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
|
|
|
|
|
|
|
|
virtual void service_tick();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
2013-03-16 08:31:31 -04:00
|
|
|
// Overloaded to cache new groups.
|
|
|
|
virtual RsGenExchange::ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
|
|
|
|
|
|
|
// Overloaded from RsTickEvent.
|
|
|
|
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups);
|
|
|
|
virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &posts);
|
|
|
|
|
|
|
|
virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsGxsChannelPost> &posts);
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
|
|
|
virtual bool createGroup(uint32_t &token, RsGxsChannelGroup &group);
|
|
|
|
virtual bool createPost(uint32_t &token, RsGxsChannelPost &post);
|
|
|
|
|
2013-03-16 08:31:31 -04:00
|
|
|
// no tokens... should be cached.
|
|
|
|
virtual bool setChannelAutoDownload(const RsGxsGroupId &groupId, bool enabled);
|
|
|
|
virtual bool getChannelAutoDownload(const RsGxsGroupId &groupid);
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
|
|
|
|
virtual bool getCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs)
|
|
|
|
{
|
|
|
|
return mCommentService->getGxsCommentData(token, msgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool getRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs)
|
|
|
|
{
|
|
|
|
return mCommentService->getGxsRelatedComments(token, msgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool createComment(uint32_t &token, RsGxsComment &msg)
|
|
|
|
{
|
|
|
|
return mCommentService->createGxsComment(token, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool createVote(uint32_t &token, RsGxsVote &msg)
|
|
|
|
{
|
|
|
|
return mCommentService->createGxsVote(token, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool acknowledgeComment(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
|
|
|
|
{
|
|
|
|
return acknowledgeMsg(token, msgId);
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
|
2013-03-15 16:46:49 -04:00
|
|
|
virtual bool acknowledgeVote(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
|
|
|
|
{
|
|
|
|
if (mCommentService->acknowledgeVote(token, msgId))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return acknowledgeMsg(token, msgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
// Overloaded from RsGxsIface.
|
2013-03-24 12:32:20 -04:00
|
|
|
virtual bool subscribeToGroup(uint32_t &token, const RsGxsGroupId &groupId, bool subscribe);
|
2013-03-11 16:40:28 -04:00
|
|
|
|
|
|
|
// Set Statuses.
|
|
|
|
virtual void setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool processed);
|
|
|
|
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
|
|
|
|
2013-03-12 20:24:57 -04:00
|
|
|
// File Interface
|
|
|
|
virtual bool ExtraFileHash(const std::string &path, std::string filename);
|
|
|
|
virtual bool ExtraFileRemove(const std::string &hash);
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
// Overloaded from GxsTokenQueue for Request callbacks.
|
|
|
|
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
private:
|
|
|
|
|
|
|
|
static uint32_t channelsAuthenPolicy();
|
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
// Handle Processing.
|
|
|
|
void request_AllSubscribedGroups();
|
|
|
|
void request_SpecificSubscribedGroups(const std::list<RsGxsGroupId> &groups);
|
|
|
|
void load_SubscribedGroups(const uint32_t &token);
|
|
|
|
|
|
|
|
void request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGroupId, RsGxsMessageId> > &ids);
|
|
|
|
void load_SpecificUnprocessedPosts(const uint32_t &token);
|
|
|
|
|
|
|
|
void request_GroupUnprocessedPosts(const std::list<RsGxsGroupId> &grouplist);
|
|
|
|
void load_GroupUnprocessedPosts(const uint32_t &token);
|
|
|
|
|
|
|
|
void handleUnprocessedPost(const RsGxsChannelPost &msg);
|
|
|
|
|
|
|
|
// Local Cache of Subscribed Groups. and AutoDownload Flag.
|
|
|
|
void updateSubscribedGroup(const RsGroupMetaData &group);
|
|
|
|
void clearUnsubscribedGroup(const RsGxsGroupId &id);
|
|
|
|
bool setAutoDownload(const RsGxsGroupId &groupId, bool enabled);
|
2013-03-16 08:31:31 -04:00
|
|
|
bool autoDownloadEnabled(const RsGxsGroupId &id);
|
2013-03-11 16:40:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::map<RsGxsGroupId, RsGroupMetaData> mSubscribedGroups;
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
|
|
|
|
// DUMMY DATA,
|
|
|
|
virtual bool generateDummyData();
|
|
|
|
|
|
|
|
std::string genRandomId();
|
|
|
|
|
|
|
|
void dummy_tick();
|
|
|
|
|
|
|
|
bool generatePost(uint32_t &token, const RsGxsGroupId &grpId);
|
|
|
|
bool generateComment(uint32_t &token, const RsGxsGroupId &grpId,
|
|
|
|
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
|
2013-03-12 20:24:57 -04:00
|
|
|
bool generateVote(uint32_t &token, const RsGxsGroupId &grpId,
|
|
|
|
const RsGxsMessageId &parentId, const RsGxsMessageId &threadId);
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
bool generateGroup(uint32_t &token, std::string groupName);
|
|
|
|
|
|
|
|
class ChannelDummyRef
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ChannelDummyRef() { return; }
|
|
|
|
ChannelDummyRef(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<ChannelDummyRef> mGenRefs;
|
|
|
|
RsGxsMessageId mGenThreadId;
|
|
|
|
|
|
|
|
p3GxsCommentService *mCommentService;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|