mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
More improvements to new Cache Services.
* Added p3Posted service. This is a *better* Links Cloud, based on the new Cache system. * Fixed p3GxsService retrival of Thread / Children messages. (for Forum support). * Added Dummy Data for testing Forum integration. * switched on both these services in libretroshare git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5268 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
0b0549f437
commit
d83e1ea6ec
@ -692,6 +692,8 @@ HEADERS += services/p3photoservice.h \
|
|||||||
services/p3idservice.h \
|
services/p3idservice.h \
|
||||||
retroshare/rsforumsv2.h \
|
retroshare/rsforumsv2.h \
|
||||||
services/p3forumsv2.h \
|
services/p3forumsv2.h \
|
||||||
|
retroshare/rsposted.h \
|
||||||
|
services/p3posted.h \
|
||||||
|
|
||||||
SOURCES += services/p3photoservice.cc \
|
SOURCES += services/p3photoservice.cc \
|
||||||
serialiser/rsphotoitems.cc \
|
serialiser/rsphotoitems.cc \
|
||||||
@ -700,6 +702,7 @@ SOURCES += services/p3photoservice.cc \
|
|||||||
services/p3wire.cc \
|
services/p3wire.cc \
|
||||||
services/p3idservice.cc \
|
services/p3idservice.cc \
|
||||||
services/p3forumsv2.cc \
|
services/p3forumsv2.cc \
|
||||||
|
services/p3posted.cc \
|
||||||
|
|
||||||
# Other Old Code.
|
# Other Old Code.
|
||||||
# rsserver/p3photo.cc \
|
# rsserver/p3photo.cc \
|
||||||
|
112
libretroshare/src/retroshare/rsposted.h
Normal file
112
libretroshare/src/retroshare/rsposted.h
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#ifndef RETROSHARE_POSTED_GUI_INTERFACE_H
|
||||||
|
#define RETROSHARE_POSTED_GUI_INTERFACE_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/retroshare: rsposted.h
|
||||||
|
*
|
||||||
|
* RetroShare C++ Interface.
|
||||||
|
*
|
||||||
|
* Copyright 2008-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".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#include <retroshare/rsidentity.h>
|
||||||
|
|
||||||
|
/* The Main Interface Class - for information about your Peers */
|
||||||
|
class RsPosted;
|
||||||
|
extern RsPosted *rsPosted;
|
||||||
|
|
||||||
|
|
||||||
|
class RsPostedGroup
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsGroupMetaData mMeta;
|
||||||
|
RsPostedGroup() { return; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class RsPostedMsg
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsPostedMsg(uint32_t t)
|
||||||
|
:postedType(t) { return; }
|
||||||
|
|
||||||
|
RsMsgMetaData mMeta;
|
||||||
|
uint32_t postedType;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define RSPOSTED_MSG_POST 1
|
||||||
|
#define RSPOSTED_MSG_VOTE 1
|
||||||
|
#define RSPOSTED_MSG_COMMENT 1
|
||||||
|
|
||||||
|
|
||||||
|
class RsPostedPost: public RsPostedMsg
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsPostedPost(): RsPostedMsg(RSPOSTED_MSG_POST) { return; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class RsPostedVote: public RsPostedMsg
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsPostedVote(): RsPostedMsg(RSPOSTED_MSG_VOTE) { return; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class RsPostedComment: public RsPostedMsg
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RsPostedComment(): RsPostedMsg(RSPOSTED_MSG_COMMENT) { return; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const RsPostedVote &vote);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const RsPostedComment &comment);
|
||||||
|
|
||||||
|
|
||||||
|
class RsPosted: public RsTokenService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
RsPosted() { return; }
|
||||||
|
virtual ~RsPosted() { return; }
|
||||||
|
|
||||||
|
/* changed? */
|
||||||
|
virtual bool updated() = 0;
|
||||||
|
|
||||||
|
/* Specific Service Data */
|
||||||
|
virtual bool getGroup(const uint32_t &token, RsPostedGroup &group) = 0;
|
||||||
|
virtual bool getPost(const uint32_t &token, RsPostedPost &post) = 0;
|
||||||
|
virtual bool getComment(const uint32_t &token, RsPostedComment &comment) = 0;
|
||||||
|
|
||||||
|
/* details are updated in album - to choose Album ID, and storage path */
|
||||||
|
virtual bool submitGroup(RsPostedGroup &group, bool isNew) = 0;
|
||||||
|
virtual bool submitPost(RsPostedPost &post, bool isNew) = 0;
|
||||||
|
virtual bool submitVote(RsPostedVote &vote, bool isNew) = 0;
|
||||||
|
virtual bool submitComment(RsPostedComment &comment, bool isNew) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -1737,6 +1737,7 @@ RsTurtle *rsTurtle = NULL ;
|
|||||||
#include "services/p3wire.h"
|
#include "services/p3wire.h"
|
||||||
#include "services/p3idservice.h"
|
#include "services/p3idservice.h"
|
||||||
#include "services/p3forumsv2.h"
|
#include "services/p3forumsv2.h"
|
||||||
|
#include "services/p3posted.h"
|
||||||
|
|
||||||
#ifndef PQI_DISABLE_TUNNEL
|
#ifndef PQI_DISABLE_TUNNEL
|
||||||
#include "services/p3tunnel.h"
|
#include "services/p3tunnel.h"
|
||||||
@ -2152,8 +2153,12 @@ int RsServer::StartupRetroShare()
|
|||||||
pqih -> addService(mIdentity);
|
pqih -> addService(mIdentity);
|
||||||
|
|
||||||
// Testing New Cache Services.
|
// Testing New Cache Services.
|
||||||
//p3ForumsV2 *mForumsV2 = new p3ForumsV2(RS_SERVICE_TYPE_FORUMSV2);
|
p3ForumsV2 *mForumsV2 = new p3ForumsV2(RS_SERVICE_TYPE_FORUMSV2);
|
||||||
//pqih -> addService(mForumsV2);
|
pqih -> addService(mForumsV2);
|
||||||
|
|
||||||
|
// Testing New Cache Services.
|
||||||
|
p3PostedService *mPosted = new p3PostedService(RS_SERVICE_TYPE_POSTED);
|
||||||
|
pqih -> addService(mPosted);
|
||||||
|
|
||||||
#ifndef RS_RELEASE
|
#ifndef RS_RELEASE
|
||||||
p3GameLauncher *gameLauncher = new p3GameLauncher(mLinkMgr);
|
p3GameLauncher *gameLauncher = new p3GameLauncher(mLinkMgr);
|
||||||
@ -2426,7 +2431,8 @@ int RsServer::StartupRetroShare()
|
|||||||
rsPhoto = mPhotos;
|
rsPhoto = mPhotos;
|
||||||
rsWiki = mWikis;
|
rsWiki = mWikis;
|
||||||
rsWire = mWire;
|
rsWire = mWire;
|
||||||
//rsForumsV2 = mForumsV2;
|
rsForumsV2 = mForumsV2;
|
||||||
|
rsPosted = mPosted;
|
||||||
|
|
||||||
#ifdef RS_USE_BLOGS
|
#ifdef RS_USE_BLOGS
|
||||||
rsBlogs = mBlogs;
|
rsBlogs = mBlogs;
|
||||||
|
@ -108,6 +108,7 @@ const uint16_t RS_SERVICE_TYPE_PHOTO = 0xf101;
|
|||||||
const uint16_t RS_SERVICE_TYPE_WIKI = 0xf102;
|
const uint16_t RS_SERVICE_TYPE_WIKI = 0xf102;
|
||||||
const uint16_t RS_SERVICE_TYPE_WIRE = 0xf103;
|
const uint16_t RS_SERVICE_TYPE_WIRE = 0xf103;
|
||||||
const uint16_t RS_SERVICE_TYPE_FORUMSV2 = 0xf104;
|
const uint16_t RS_SERVICE_TYPE_FORUMSV2 = 0xf104;
|
||||||
|
const uint16_t RS_SERVICE_TYPE_POSTED = 0xf105;
|
||||||
|
|
||||||
//const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf110;
|
//const uint16_t RS_SERVICE_TYPE_DISTRIB = 0xf110;
|
||||||
//const uint16_t RS_SERVICE_TYPE_FORUM = 0xf120;
|
//const uint16_t RS_SERVICE_TYPE_FORUM = 0xf120;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "services/p3forumsv2.h"
|
#include "services/p3forumsv2.h"
|
||||||
|
|
||||||
#include "util/rsrandom.h"
|
#include "util/rsrandom.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/****
|
/****
|
||||||
* #define FORUMV2_DEBUG 1
|
* #define FORUMV2_DEBUG 1
|
||||||
@ -42,9 +43,14 @@ RsForumsV2 *rsForumsV2 = NULL;
|
|||||||
p3ForumsV2::p3ForumsV2(uint16_t type)
|
p3ForumsV2::p3ForumsV2(uint16_t type)
|
||||||
:p3GxsDataService(type, new ForumDataProxy()), mForumMtx("p3ForumsV2"), mUpdated(true)
|
:p3GxsDataService(type, new ForumDataProxy()), mForumMtx("p3ForumsV2"), mUpdated(true)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
|
{
|
||||||
|
RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
|
mForumProxy = (ForumDataProxy *) mProxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateDummyData();
|
||||||
|
|
||||||
mForumProxy = (ForumDataProxy *) mProxy;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,14 +592,13 @@ bool ForumDataProxy::convertMsgToMetaData(void *msgData, RsMsgMetaData &meta)
|
|||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
bool p3ForumsV2::generateDummyData()
|
bool p3ForumsV2::generateDummyData()
|
||||||
{
|
{
|
||||||
/* so we want to generate 100's of forums */
|
/* so we want to generate 100's of forums */
|
||||||
#define MAX_FORUMS 100
|
#define MAX_FORUMS 10 //100
|
||||||
#define MAX_THREADS 1000
|
#define MAX_THREADS 10 //1000
|
||||||
#define MAX_MSGS 10000
|
#define MAX_MSGS 100 //10000
|
||||||
|
|
||||||
std::list<RsForumV2Group> mGroups;
|
std::list<RsForumV2Group> mGroups;
|
||||||
std::list<RsForumV2Group>::iterator git;
|
std::list<RsForumV2Group>::iterator git;
|
||||||
@ -601,11 +606,25 @@ bool p3ForumsV2::generateDummyData()
|
|||||||
std::list<RsForumV2Msg> mMsgs;
|
std::list<RsForumV2Msg> mMsgs;
|
||||||
std::list<RsForumV2Msg>::iterator mit;
|
std::list<RsForumV2Msg>::iterator mit;
|
||||||
|
|
||||||
for(int i = 0; i < MAX_FORUMS; i++)
|
#define DUMMY_NAME_MAX_LEN 10000
|
||||||
|
char name[DUMMY_NAME_MAX_LEN];
|
||||||
|
int i, j;
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_FORUMS; i++)
|
||||||
{
|
{
|
||||||
/* generate a new forum */
|
/* generate a new forum */
|
||||||
RsForumV2Group forum;
|
RsForumV2Group forum;
|
||||||
|
|
||||||
|
/* generate a temp id */
|
||||||
|
forum.mMeta.mGroupId = genRandomId();
|
||||||
|
|
||||||
|
snprintf(name, DUMMY_NAME_MAX_LEN, "TestForum_%d", i+1);
|
||||||
|
|
||||||
|
forum.mMeta.mGroupId = genRandomId();
|
||||||
|
forum.mMeta.mGroupName = name;
|
||||||
|
|
||||||
|
forum.mMeta.mPublishTs = now - (RSRandom::random_f32() * 100000);
|
||||||
/* key fields to fill in:
|
/* key fields to fill in:
|
||||||
* GroupId.
|
* GroupId.
|
||||||
* Name.
|
* Name.
|
||||||
@ -613,11 +632,33 @@ bool p3ForumsV2::generateDummyData()
|
|||||||
* Pop.
|
* Pop.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* use probability to decide which are subscribed / own / popularity.
|
/* use probability to decide which are subscribed / own / popularity.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
float rnd = RSRandom::random_f32();
|
||||||
|
if (rnd < 0.1)
|
||||||
|
{
|
||||||
|
forum.mMeta.mSubscribeFlags = RS_DISTRIB_ADMIN;
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (rnd < 0.3)
|
||||||
|
{
|
||||||
|
forum.mMeta.mSubscribeFlags = RS_DISTRIB_SUBSCRIBED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
forum.mMeta.mSubscribeFlags = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
forum.mMeta.mPop = (int) (RSRandom::random_f32() * 10.0);
|
||||||
|
|
||||||
mGroups.push_back(forum);
|
mGroups.push_back(forum);
|
||||||
|
|
||||||
|
|
||||||
|
//std::cerr << "p3ForumsV2::generateDummyData() Generated Forum: " << forum.mMeta;
|
||||||
|
//std::cerr << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -628,7 +669,7 @@ bool p3ForumsV2::generateDummyData()
|
|||||||
/* rotate the Forum Groups Around, then pick one.
|
/* rotate the Forum Groups Around, then pick one.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int rnd;
|
int rnd = (int) (RSRandom::random_f32() * 10.0);
|
||||||
|
|
||||||
for(j = 0; j < rnd; j++)
|
for(j = 0; j < rnd; j++)
|
||||||
{
|
{
|
||||||
@ -653,8 +694,23 @@ bool p3ForumsV2::generateDummyData()
|
|||||||
*
|
*
|
||||||
* ChildTS ????
|
* ChildTS ????
|
||||||
*/
|
*/
|
||||||
|
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => ThreadMsg_%d", forum.mMeta.mGroupName.c_str(), i+1);
|
||||||
|
msg.mMeta.mMsgName = name;
|
||||||
|
|
||||||
|
msg.mMeta.mGroupId = forum.mMeta.mGroupId;
|
||||||
|
msg.mMeta.mMsgId = genRandomId();
|
||||||
|
msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId;
|
||||||
|
msg.mMeta.mThreadId = msg.mMeta.mMsgId;
|
||||||
|
msg.mMeta.mParentId = "";
|
||||||
|
|
||||||
|
msg.mMeta.mPublishTs = forum.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
|
||||||
|
if (msg.mMeta.mPublishTs > now)
|
||||||
|
msg.mMeta.mPublishTs = now - 1;
|
||||||
|
|
||||||
mMsgs.push_back(msg);
|
mMsgs.push_back(msg);
|
||||||
|
|
||||||
|
//std::cerr << "p3ForumsV2::generateDummyData() Generated Thread: " << msg.mMeta;
|
||||||
|
//std::cerr << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,7 +721,7 @@ bool p3ForumsV2::generateDummyData()
|
|||||||
/* rotate the Forum Groups Around, then pick one.
|
/* rotate the Forum Groups Around, then pick one.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int rnd;
|
int rnd = (int) (RSRandom::random_f32() * 10.0);
|
||||||
|
|
||||||
for(j = 0; j < rnd; j++)
|
for(j = 0; j < rnd; j++)
|
||||||
{
|
{
|
||||||
@ -690,25 +746,44 @@ bool p3ForumsV2::generateDummyData()
|
|||||||
*
|
*
|
||||||
* ChildTS ????
|
* ChildTS ????
|
||||||
*/
|
*/
|
||||||
|
snprintf(name, DUMMY_NAME_MAX_LEN, "%s => Msg_%d", parent.mMeta.mMsgName.c_str(), i+1);
|
||||||
|
msg.mMeta.mMsgName = name;
|
||||||
|
msg.mMsg = name;
|
||||||
|
|
||||||
|
msg.mMeta.mGroupId = parent.mMeta.mGroupId;
|
||||||
|
msg.mMeta.mMsgId = genRandomId();
|
||||||
|
msg.mMeta.mOrigMsgId = msg.mMeta.mMsgId;
|
||||||
|
msg.mMeta.mThreadId = parent.mMeta.mThreadId;
|
||||||
|
msg.mMeta.mParentId = parent.mMeta.mOrigMsgId;
|
||||||
|
|
||||||
|
msg.mMeta.mPublishTs = parent.mMeta.mPublishTs + (RSRandom::random_f32() * 10000);
|
||||||
|
if (msg.mMeta.mPublishTs > now)
|
||||||
|
msg.mMeta.mPublishTs = now - 1;
|
||||||
|
|
||||||
|
mMsgs.push_back(msg);
|
||||||
|
|
||||||
|
//std::cerr << "p3ForumsV2::generateDummyData() Generated Child Msg: " << msg.mMeta;
|
||||||
|
//std::cerr << std::endl;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mUpdated = true;
|
||||||
|
|
||||||
/* Then - at the end, we push them all into the Proxy */
|
/* Then - at the end, we push them all into the Proxy */
|
||||||
for(git = mGroups.begin(); git != mGroups.end(); git++)
|
for(git = mGroups.begin(); git != mGroups.end(); git++)
|
||||||
{
|
{
|
||||||
/* pushback */
|
/* pushback */
|
||||||
|
mForumProxy->addForumGroup(*git);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(mit = mMsgs.begin(); mit != mMsgs.end(); mit++)
|
for(mit = mMsgs.begin(); mit != mMsgs.end(); mit++)
|
||||||
{
|
{
|
||||||
/* pushback */
|
/* pushback */
|
||||||
|
mForumProxy->addForumMsg(*mit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
@ -127,6 +127,7 @@ virtual bool createMsg(RsForumV2Msg &msg);
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
std::string genRandomId();
|
std::string genRandomId();
|
||||||
|
bool generateDummyData();
|
||||||
|
|
||||||
ForumDataProxy *mForumProxy;
|
ForumDataProxy *mForumProxy;
|
||||||
|
|
||||||
|
@ -385,20 +385,29 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
|
|||||||
|
|
||||||
bool onlyOrigMsgs = false;
|
bool onlyOrigMsgs = false;
|
||||||
bool onlyLatestMsgs = false;
|
bool onlyLatestMsgs = false;
|
||||||
|
bool onlyThreadHeadMsgs = false;
|
||||||
|
|
||||||
// Can only choose one of these two.
|
// Can only choose one of these two.
|
||||||
if (opts.mOptions & RS_TOKREQOPT_MSG_ORIGMSG)
|
if (opts.mOptions & RS_TOKREQOPT_MSG_ORIGMSG)
|
||||||
{
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgList() MSG_ORIGMSG";
|
||||||
|
std::cerr << std::endl;
|
||||||
onlyOrigMsgs = true;
|
onlyOrigMsgs = true;
|
||||||
}
|
}
|
||||||
else if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
|
else if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
|
||||||
{
|
{
|
||||||
std::cerr << "GxsDataProxy::getMsgList() REQUESTED LATEST!!!";
|
std::cerr << "GxsDataProxy::getMsgList() MSG_LATEST";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
onlyLatestMsgs = true;
|
onlyLatestMsgs = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.mOptions & RS_TOKREQOPT_MSG_THREAD)
|
||||||
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgList() MSG_THREAD";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
onlyThreadHeadMsgs = true;
|
||||||
|
}
|
||||||
|
|
||||||
std::list<std::string>::const_iterator it;
|
std::list<std::string>::const_iterator it;
|
||||||
std::map<std::string, RsMsgMetaData>::iterator mit;
|
std::map<std::string, RsMsgMetaData>::iterator mit;
|
||||||
|
|
||||||
@ -416,6 +425,16 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if we are grabbing thread Head... then parentId == empty. */
|
||||||
|
if (onlyThreadHeadMsgs)
|
||||||
|
{
|
||||||
|
if (!(mit->second.mParentId.empty()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
oit = origMsgTs.find(mit->second.mOrigMsgId);
|
oit = origMsgTs.find(mit->second.mOrigMsgId);
|
||||||
bool addMsg = false;
|
bool addMsg = false;
|
||||||
if (oit == origMsgTs.end())
|
if (oit == origMsgTs.end())
|
||||||
@ -460,6 +479,16 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt
|
|||||||
if (mit->second.mGroupId == *it)
|
if (mit->second.mGroupId == *it)
|
||||||
{
|
{
|
||||||
bool add = false;
|
bool add = false;
|
||||||
|
|
||||||
|
/* if we are grabbing thread Head... then parentId == empty. */
|
||||||
|
if (onlyThreadHeadMsgs)
|
||||||
|
{
|
||||||
|
if (!(mit->second.mParentId.empty()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (onlyOrigMsgs)
|
if (onlyOrigMsgs)
|
||||||
{
|
{
|
||||||
@ -498,18 +527,50 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
|
|||||||
|
|
||||||
bool onlyLatestMsgs = false;
|
bool onlyLatestMsgs = false;
|
||||||
bool onlyAllVersions = false;
|
bool onlyAllVersions = false;
|
||||||
|
bool onlyChildMsgs = false;
|
||||||
|
|
||||||
if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
|
if (opts.mOptions & RS_TOKREQOPT_MSG_LATEST)
|
||||||
{
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_LATEST";
|
||||||
|
std::cerr << std::endl;
|
||||||
onlyLatestMsgs = true;
|
onlyLatestMsgs = true;
|
||||||
}
|
}
|
||||||
else if (opts.mOptions & RS_TOKREQOPT_MSG_VERSIONS)
|
else if (opts.mOptions & RS_TOKREQOPT_MSG_VERSIONS)
|
||||||
{
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_VERSIONS";
|
||||||
|
std::cerr << std::endl;
|
||||||
onlyAllVersions = true;
|
onlyAllVersions = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FALL BACK OPTION */
|
if (opts.mOptions & RS_TOKREQOPT_MSG_PARENT)
|
||||||
if ((!onlyLatestMsgs) && (!onlyAllVersions))
|
|
||||||
{
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgRelatedList() MSG_PARENTS";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
onlyChildMsgs = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onlyAllVersions && onlyChildMsgs)
|
||||||
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgRelatedList() ERROR Incompatible FLAGS (VERSIONS & PARENT)";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!onlyLatestMsgs) && onlyChildMsgs)
|
||||||
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgRelatedList() ERROR Incompatible FLAGS (!LATEST & PARENT)";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* FALL BACK OPTION */
|
||||||
|
if ((!onlyLatestMsgs) && (!onlyAllVersions) && (!onlyChildMsgs))
|
||||||
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgRelatedList() FALLBACK -> NO FLAGS -> JUST COPY";
|
||||||
|
std::cerr << std::endl;
|
||||||
/* just copy */
|
/* just copy */
|
||||||
outMsgIds = msgIds;
|
outMsgIds = msgIds;
|
||||||
|
|
||||||
@ -532,22 +593,75 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt
|
|||||||
|
|
||||||
if (onlyLatestMsgs)
|
if (onlyLatestMsgs)
|
||||||
{
|
{
|
||||||
/* first guess is potentially better than Orig (can't be worse!) */
|
if (onlyChildMsgs)
|
||||||
time_t latestTs = mit->second.mPublishTs;
|
|
||||||
std::string latestMsgId = mit->second.mMsgId;
|
|
||||||
|
|
||||||
for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++)
|
|
||||||
{
|
{
|
||||||
if (mit->second.mOrigMsgId == origMsgId)
|
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
||||||
|
std::map<std::string, std::pair<std::string, uint32_t> > origMsgTs;
|
||||||
|
std::map<std::string, std::pair<std::string, uint32_t> >::iterator oit;
|
||||||
|
for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++)
|
||||||
{
|
{
|
||||||
if (mit->second.mPublishTs > latestTs)
|
// skip msgs that aren't children.
|
||||||
|
if (mit->second.mParentId != origMsgId)
|
||||||
{
|
{
|
||||||
latestTs = mit->second.mPublishTs;
|
continue;
|
||||||
latestMsgId = mit->first;
|
}
|
||||||
|
|
||||||
|
oit = origMsgTs.find(mit->second.mOrigMsgId);
|
||||||
|
bool addMsg = false;
|
||||||
|
if (oit == origMsgTs.end())
|
||||||
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgList() Found New OrigMsgId: ";
|
||||||
|
std::cerr << mit->second.mOrigMsgId;
|
||||||
|
std::cerr << " MsgId: " << mit->second.mMsgId;
|
||||||
|
std::cerr << " TS: " << mit->second.mPublishTs;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
addMsg = true;
|
||||||
|
}
|
||||||
|
// check timestamps.
|
||||||
|
else if (oit->second.second < mit->second.mPublishTs)
|
||||||
|
{
|
||||||
|
std::cerr << "GxsDataProxy::getMsgList() Found Later Msg. OrigMsgId: ";
|
||||||
|
std::cerr << mit->second.mOrigMsgId;
|
||||||
|
std::cerr << " MsgId: " << mit->second.mMsgId;
|
||||||
|
std::cerr << " TS: " << mit->second.mPublishTs;
|
||||||
|
|
||||||
|
addMsg = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addMsg)
|
||||||
|
{
|
||||||
|
// add as latest. (overwriting if necessary)
|
||||||
|
origMsgTs[mit->second.mOrigMsgId] = std::make_pair(mit->second.mMsgId, mit->second.mPublishTs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the discovered Latest Msgs.
|
||||||
|
for(oit = origMsgTs.begin(); oit != origMsgTs.end(); oit++)
|
||||||
|
{
|
||||||
|
outMsgIds.push_back(oit->second.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
/* first guess is potentially better than Orig (can't be worse!) */
|
||||||
|
time_t latestTs = mit->second.mPublishTs;
|
||||||
|
std::string latestMsgId = mit->second.mMsgId;
|
||||||
|
|
||||||
|
for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++)
|
||||||
|
{
|
||||||
|
if (mit->second.mOrigMsgId == origMsgId)
|
||||||
|
{
|
||||||
|
if (mit->second.mPublishTs > latestTs)
|
||||||
|
{
|
||||||
|
latestTs = mit->second.mPublishTs;
|
||||||
|
latestMsgId = mit->first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outMsgIds.push_back(latestMsgId);
|
||||||
}
|
}
|
||||||
outMsgIds.push_back(latestMsgId);
|
|
||||||
}
|
}
|
||||||
else if (onlyAllVersions)
|
else if (onlyAllVersions)
|
||||||
{
|
{
|
||||||
@ -934,7 +1048,8 @@ std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta)
|
|||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta)
|
std::ostream &operator<<(std::ostream &out, const RsMsgMetaData &meta)
|
||||||
{
|
{
|
||||||
out << "[ GroupId: " << meta.mGroupId << " MsgId: " << meta.mMsgId << " Name: " << meta.mMsgName << " ]";
|
out << "[ GroupId: " << meta.mGroupId << " MsgId: " << meta.mMsgId;
|
||||||
|
out << " Name: " << meta.mMsgName;
|
||||||
out << " OrigMsgId: " << meta.mOrigMsgId;
|
out << " OrigMsgId: " << meta.mOrigMsgId;
|
||||||
out << " ThreadId: " << meta.mThreadId;
|
out << " ThreadId: " << meta.mThreadId;
|
||||||
out << " ParentId: " << meta.mParentId;
|
out << " ParentId: " << meta.mParentId;
|
||||||
|
1102
libretroshare/src/services/p3posted.cc
Normal file
1102
libretroshare/src/services/p3posted.cc
Normal file
File diff suppressed because it is too large
Load Diff
138
libretroshare/src/services/p3posted.h
Normal file
138
libretroshare/src/services/p3posted.h
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/services: p3posted.h
|
||||||
|
*
|
||||||
|
* 3P/PQI network 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_POSTED_SERVICE_HEADER
|
||||||
|
#define P3_POSTED_SERVICE_HEADER
|
||||||
|
|
||||||
|
#include "services/p3gxsservice.h"
|
||||||
|
#include "retroshare/rsposted.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Posted Service
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class PostedDataProxy: public GxsDataProxy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool addGroup(const RsPostedGroup &group);
|
||||||
|
bool addPost(const RsPostedPost &post);
|
||||||
|
bool addVote(const RsPostedVote &vote);
|
||||||
|
bool addComment(const RsPostedComment &comment);
|
||||||
|
|
||||||
|
bool getGroup(const std::string &id, RsPostedGroup &group);
|
||||||
|
bool getPost(const std::string &id, RsPostedPost &post);
|
||||||
|
bool getVote(const std::string &id, RsPostedVote &vote);
|
||||||
|
bool getComment(const std::string &id, RsPostedComment &comment);
|
||||||
|
|
||||||
|
/* These Functions must be overloaded to complete the service */
|
||||||
|
virtual bool convertGroupToMetaData(void *groupData, RsGroupMetaData &meta);
|
||||||
|
virtual bool convertMsgToMetaData(void *groupData, RsMsgMetaData &meta);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class p3PostedService: public p3GxsDataService, public RsPosted
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
p3PostedService(uint16_t type);
|
||||||
|
|
||||||
|
virtual int tick();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// NEW INTERFACE.
|
||||||
|
/************* Extern Interface *******/
|
||||||
|
|
||||||
|
virtual bool updated();
|
||||||
|
|
||||||
|
/* Data Requests */
|
||||||
|
virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
|
||||||
|
virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &groupIds);
|
||||||
|
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<std::string> &msgIds);
|
||||||
|
|
||||||
|
/* Generic Lists */
|
||||||
|
virtual bool getGroupList( const uint32_t &token, std::list<std::string> &groupIds);
|
||||||
|
virtual bool getMsgList( const uint32_t &token, std::list<std::string> &msgIds);
|
||||||
|
|
||||||
|
/* Generic Summary */
|
||||||
|
virtual bool getGroupSummary( const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
|
||||||
|
virtual bool getMsgSummary( const uint32_t &token, std::list<RsMsgMetaData> &msgInfo);
|
||||||
|
|
||||||
|
/* Actual Data -> specific to Interface */
|
||||||
|
/* Specific Service Data */
|
||||||
|
virtual bool getGroup(const uint32_t &token, RsPostedGroup &group);
|
||||||
|
virtual bool getPost(const uint32_t &token, RsPostedPost &post);
|
||||||
|
virtual bool getComment(const uint32_t &token, RsPostedComment &comment);
|
||||||
|
|
||||||
|
|
||||||
|
/* Poll */
|
||||||
|
virtual uint32_t requestStatus(const uint32_t token);
|
||||||
|
|
||||||
|
/* Cancel Request */
|
||||||
|
virtual bool cancelRequest(const uint32_t &token);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/* Functions from Forums -> need to be implemented generically */
|
||||||
|
virtual bool groupsChanged(std::list<std::string> &groupIds);
|
||||||
|
|
||||||
|
// Get Message Status - is retrived via MessageSummary.
|
||||||
|
virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask);
|
||||||
|
|
||||||
|
//
|
||||||
|
virtual bool groupSubscribe(const std::string &groupId, bool subscribe);
|
||||||
|
|
||||||
|
virtual bool groupRestoreKeys(const std::string &groupId);
|
||||||
|
virtual bool groupShareKeys(const std::string &groupId, std::list<std::string>& peers);
|
||||||
|
|
||||||
|
/* details are updated in album - to choose Album ID, and storage path */
|
||||||
|
virtual bool submitGroup(RsPostedGroup &group, bool isNew);
|
||||||
|
virtual bool submitPost(RsPostedPost &post, bool isNew);
|
||||||
|
virtual bool submitVote(RsPostedVote &vote, bool isNew);
|
||||||
|
virtual bool submitComment(RsPostedComment &comment, bool isNew);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::string genRandomId();
|
||||||
|
bool generateDummyData();
|
||||||
|
|
||||||
|
PostedDataProxy *mPostedProxy;
|
||||||
|
|
||||||
|
RsMutex mPostedMtx;
|
||||||
|
bool mUpdated;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user