2012-11-08 19:56:07 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services p3gxsforums.cc
|
|
|
|
*
|
|
|
|
* GxsForums 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.1 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 "services/p3gxsforums.h"
|
|
|
|
#include "serialiser/rsgxsforumitems.h"
|
|
|
|
|
2012-11-19 17:00:05 -05:00
|
|
|
#include <retroshare/rsidentity.h>
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
|
2013-02-28 16:58:38 -05:00
|
|
|
#include "retroshare/rsgxsflags.h"
|
2012-11-08 19:56:07 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
// For Dummy Msgs.
|
|
|
|
#include "util/rsrandom.h"
|
|
|
|
#include "util/rsstring.h"
|
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
/****
|
|
|
|
* #define GXSFORUM_DEBUG 1
|
|
|
|
****/
|
|
|
|
|
|
|
|
RsGxsForums *rsGxsForums = NULL;
|
|
|
|
|
|
|
|
|
2012-11-19 17:00:05 -05:00
|
|
|
#define FORUM_TESTEVENT_DUMMYDATA 0x0001
|
|
|
|
#define DUMMYDATA_PERIOD 60 // long enough for some RsIdentities to be generated.
|
2012-11-08 19:56:07 -05:00
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/******************* Startup / Tick ******************************************/
|
|
|
|
/********************************************************************************/
|
|
|
|
|
2013-02-10 13:41:15 -05:00
|
|
|
p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs)
|
2013-06-04 17:00:43 -04:00
|
|
|
: RsGenExchange(gds, nes, new RsGxsForumSerialiser(), RS_SERVICE_GXSV2_TYPE_FORUMS, gixs, forumsAuthenPolicy()), RsGxsForums(this)
|
2012-11-08 19:56:07 -05:00
|
|
|
{
|
2012-11-15 18:50:54 -05:00
|
|
|
// For Dummy Msgs.
|
|
|
|
mGenActive = false;
|
2013-02-10 10:40:07 -05:00
|
|
|
|
2013-03-11 16:40:28 -04:00
|
|
|
// Test Data disabled in Repo.
|
|
|
|
//RsTickEvent::schedule_in(FORUM_TESTEVENT_DUMMYDATA, DUMMYDATA_PERIOD);
|
2013-02-10 10:40:07 -05:00
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
}
|
|
|
|
|
2013-02-10 12:41:30 -05:00
|
|
|
uint32_t p3GxsForums::forumsAuthenPolicy()
|
|
|
|
{
|
2013-03-23 10:07:52 -04:00
|
|
|
uint32_t policy = 0;
|
2013-03-24 15:21:30 -04:00
|
|
|
uint32_t flag = GXS_SERV::MSG_AUTHEN_ROOT_AUTHOR_SIGN | GXS_SERV::MSG_AUTHEN_CHILD_AUTHOR_SIGN;
|
|
|
|
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::PUBLIC_GRP_BITS);
|
2013-02-10 12:41:30 -05:00
|
|
|
|
2013-03-24 15:21:30 -04:00
|
|
|
flag |= GXS_SERV::MSG_AUTHEN_ROOT_PUBLISH_SIGN | GXS_SERV::MSG_AUTHEN_CHILD_PUBLISH_SIGN;
|
2013-03-04 15:26:48 -05:00
|
|
|
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::RESTRICTED_GRP_BITS);
|
|
|
|
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::PRIVATE_GRP_BITS);
|
2013-03-08 14:55:59 -05:00
|
|
|
|
2013-03-24 15:21:30 -04:00
|
|
|
flag = 0;
|
|
|
|
RsGenExchange::setAuthenPolicyFlag(flag, policy, RsGenExchange::GRP_OPTION_BITS);
|
|
|
|
|
2013-03-04 15:26:48 -05:00
|
|
|
return policy;
|
|
|
|
}
|
2013-02-10 12:41:30 -05:00
|
|
|
|
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|
|
|
{
|
2013-02-28 16:58:38 -05:00
|
|
|
RsGxsIfaceHelper::receiveChanges(changes);
|
2012-11-08 19:56:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void p3GxsForums::service_tick()
|
|
|
|
{
|
2012-11-15 18:50:54 -05:00
|
|
|
dummy_tick();
|
2012-11-19 17:00:05 -05:00
|
|
|
RsTickEvent::tick_events();
|
2012-11-08 19:56:07 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3GxsForums::getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups)
|
|
|
|
{
|
|
|
|
std::vector<RsGxsGrpItem*> grpData;
|
|
|
|
bool ok = RsGenExchange::getGroupData(token, grpData);
|
|
|
|
|
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
|
|
|
|
|
|
|
|
for(; vit != grpData.end(); vit++)
|
|
|
|
{
|
|
|
|
RsGxsForumGroupItem* item = dynamic_cast<RsGxsForumGroupItem*>(*vit);
|
2013-07-20 21:50:13 -04:00
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
RsGxsForumGroup grp = item->mGroup;
|
|
|
|
item->mGroup.mMeta = item->meta;
|
|
|
|
grp.mMeta = item->mGroup.mMeta;
|
|
|
|
delete item;
|
|
|
|
groups.push_back(grp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Not a GxsForumGrpItem, deleting!" << std::endl;
|
|
|
|
delete *vit;
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Okay - chris is not going to be happy with this...
|
|
|
|
* but I can't be bothered with crazy data structures
|
|
|
|
* at the moment - fix it up later
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool p3GxsForums::getMsgData(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs)
|
|
|
|
{
|
|
|
|
GxsMsgDataMap msgData;
|
|
|
|
bool ok = RsGenExchange::getMsgData(token, msgData);
|
2013-07-20 21:50:13 -04:00
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
GxsMsgDataMap::iterator mit = msgData.begin();
|
2013-07-20 21:50:13 -04:00
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
for(; mit != msgData.end(); mit++)
|
|
|
|
{
|
|
|
|
RsGxsGroupId grpId = mit->first;
|
|
|
|
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
|
|
|
|
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
|
2013-07-20 21:50:13 -04:00
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
for(; vit != msgItems.end(); vit++)
|
|
|
|
{
|
|
|
|
RsGxsForumMsgItem* item = dynamic_cast<RsGxsForumMsgItem*>(*vit);
|
2013-07-20 21:50:13 -04:00
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
RsGxsForumMsg msg = item->mMsg;
|
|
|
|
msg.mMeta = item->meta;
|
|
|
|
msgs.push_back(msg);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Not a GxsForumMsgItem, deleting!" << std::endl;
|
|
|
|
delete *vit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-20 21:50:13 -04:00
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
|
|
|
|
bool p3GxsForums::getRelatedMessages(const uint32_t &token, std::vector<RsGxsForumMsg> &msgs)
|
|
|
|
{
|
|
|
|
GxsMsgRelatedDataMap msgData;
|
|
|
|
bool ok = RsGenExchange::getMsgRelatedData(token, msgData);
|
|
|
|
|
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
GxsMsgRelatedDataMap::iterator mit = msgData.begin();
|
|
|
|
|
|
|
|
for(; mit != msgData.end(); mit++)
|
|
|
|
{
|
|
|
|
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
|
|
|
|
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
|
|
|
|
|
|
|
|
for(; vit != msgItems.end(); vit++)
|
|
|
|
{
|
|
|
|
RsGxsForumMsgItem* item = dynamic_cast<RsGxsForumMsgItem*>(*vit);
|
|
|
|
|
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
RsGxsForumMsg msg = item->mMsg;
|
|
|
|
msg.mMeta = item->meta;
|
|
|
|
msgs.push_back(msg);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Not a GxsForumMsgItem, deleting!" << std::endl;
|
|
|
|
delete *vit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2012-11-08 19:56:07 -05:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
bool p3GxsForums::createGroup(uint32_t &token, RsGxsForumGroup &group)
|
|
|
|
{
|
|
|
|
std::cerr << "p3GxsForums::createGroup()" << std::endl;
|
|
|
|
|
|
|
|
RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem();
|
|
|
|
grpItem->mGroup = group;
|
|
|
|
grpItem->meta = group.mMeta;
|
|
|
|
|
|
|
|
RsGenExchange::publishGroup(token, grpItem);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-19 06:08:37 -05:00
|
|
|
bool p3GxsForums::updateGroup(uint32_t &token, RsGxsForumGroup &group)
|
2013-10-05 07:36:31 -04:00
|
|
|
{
|
2013-10-20 05:43:30 -04:00
|
|
|
std::cerr << "p3GxsForums::updateGroup()" << std::endl;
|
2013-10-05 07:36:31 -04:00
|
|
|
|
|
|
|
RsGxsForumGroupItem* grpItem = new RsGxsForumGroupItem();
|
|
|
|
grpItem->mGroup = group;
|
2013-10-06 17:07:31 -04:00
|
|
|
grpItem->meta = group.mMeta;
|
2013-10-05 07:36:31 -04:00
|
|
|
|
2014-02-19 06:08:37 -05:00
|
|
|
RsGenExchange::updateGroup(token, grpItem);
|
2013-10-05 07:36:31 -04:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
|
|
|
bool p3GxsForums::createMsg(uint32_t &token, RsGxsForumMsg &msg)
|
|
|
|
{
|
|
|
|
std::cerr << "p3GxsForums::createForumMsg() GroupId: " << msg.mMeta.mGroupId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
RsGxsForumMsgItem* msgItem = new RsGxsForumMsgItem();
|
|
|
|
msgItem->mMsg = msg;
|
|
|
|
msgItem->meta = msg.mMeta;
|
|
|
|
|
|
|
|
RsGenExchange::publishMsg(token, msgItem);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-11 10:56:34 -05:00
|
|
|
/********************************************************************************************/
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
void p3GxsForums::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read)
|
|
|
|
{
|
2012-12-08 21:32:47 -05:00
|
|
|
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_UNREAD | GXS_SERV::GXS_MSG_STATUS_UNPROCESSED;
|
2012-11-11 10:56:34 -05:00
|
|
|
uint32_t status = GXS_SERV::GXS_MSG_STATUS_UNREAD;
|
|
|
|
if (read)
|
|
|
|
{
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setMsgStatusFlags(token, msgId, status, mask);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
2012-11-08 19:56:07 -05:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
/* so we need the same tick idea as wiki for generating dummy forums
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_GEN_GROUPS 5
|
|
|
|
#define MAX_GEN_MESSAGES 100
|
2012-11-08 19:56:07 -05:00
|
|
|
|
|
|
|
std::string p3GxsForums::genRandomId()
|
|
|
|
{
|
2012-11-15 18:50:54 -05:00
|
|
|
std::string randomId;
|
|
|
|
for(int i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
randomId += (char) ('a' + (RSRandom::random_u32() % 26));
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
return randomId;
|
2012-11-08 19:56:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool p3GxsForums::generateDummyData()
|
|
|
|
{
|
2012-11-15 18:50:54 -05:00
|
|
|
mGenCount = 0;
|
|
|
|
mGenRefs.resize(MAX_GEN_MESSAGES);
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
std::string groupName;
|
|
|
|
rs_sprintf(groupName, "TestForum_%d", mGenCount);
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
std::cerr << "p3GxsForums::generateDummyData() Starting off with Group: " << groupName;
|
|
|
|
std::cerr << std::endl;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
/* create a new group */
|
|
|
|
generateGroup(mGenToken, groupName);
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
mGenActive = true;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
void p3GxsForums::dummy_tick()
|
|
|
|
{
|
|
|
|
/* check for a new callback */
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
if (mGenActive)
|
|
|
|
{
|
2012-12-08 21:32:47 -05:00
|
|
|
std::cerr << "p3GxsForums::dummyTick() AboutActive";
|
2012-11-15 18:50:54 -05:00
|
|
|
std::cerr << std::endl;
|
2012-12-08 21:32:47 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
uint32_t status = RsGenExchange::getTokenService()->requestStatus(mGenToken);
|
|
|
|
if (status != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
2012-11-08 19:56:07 -05:00
|
|
|
{
|
2012-11-15 18:50:54 -05:00
|
|
|
std::cerr << "p3GxsForums::dummy_tick() Status: " << status;
|
|
|
|
std::cerr << std::endl;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
if (status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
|
|
|
{
|
|
|
|
std::cerr << "p3GxsForums::dummy_tick() generateDummyMsgs() FAILED";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
mGenActive = false;
|
|
|
|
}
|
|
|
|
return;
|
2012-11-08 19:56:07 -05:00
|
|
|
}
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
if (mGenCount < MAX_GEN_GROUPS)
|
2012-11-08 19:56:07 -05:00
|
|
|
{
|
2012-11-15 18:50:54 -05:00
|
|
|
/* get the group Id */
|
|
|
|
RsGxsGroupId groupId;
|
|
|
|
RsGxsMessageId emptyId;
|
|
|
|
if (!acknowledgeTokenGrp(mGenToken, groupId))
|
|
|
|
{
|
|
|
|
std::cerr << " ERROR ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
mGenActive = false;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
std::cerr << "p3GxsForums::dummy_tick() Acknowledged GroupId: " << groupId;
|
|
|
|
std::cerr << std::endl;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
ForumDummyRef ref(groupId, emptyId, emptyId);
|
|
|
|
mGenRefs[mGenCount] = ref;
|
|
|
|
}
|
|
|
|
else if (mGenCount < MAX_GEN_MESSAGES)
|
|
|
|
{
|
|
|
|
/* get the msg Id, and generate next snapshot */
|
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
if (!acknowledgeTokenMsg(mGenToken, msgId))
|
|
|
|
{
|
|
|
|
std::cerr << " ERROR ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
mGenActive = false;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
std::cerr << "p3GxsForums::dummy_tick() Acknowledged <GroupId: " << msgId.first << ", MsgId: " << msgId.second << ">";
|
|
|
|
std::cerr << std::endl;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
/* store results for later selection */
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
ForumDummyRef ref(msgId.first, mGenThreadId, msgId.second);
|
|
|
|
mGenRefs[mGenCount] = ref;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "p3GxsForums::dummy_tick() Finished";
|
|
|
|
std::cerr << std::endl;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
/* done */
|
|
|
|
mGenActive = false;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
mGenCount++;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
if (mGenCount < MAX_GEN_GROUPS)
|
2012-11-08 19:56:07 -05:00
|
|
|
{
|
2012-11-15 18:50:54 -05:00
|
|
|
std::string groupName;
|
|
|
|
rs_sprintf(groupName, "TestForum_%d", mGenCount);
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
std::cerr << "p3GxsForums::dummy_tick() Generating Group: " << groupName;
|
|
|
|
std::cerr << std::endl;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
/* create a new group */
|
|
|
|
generateGroup(mGenToken, groupName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* create a new message */
|
|
|
|
uint32_t idx = (uint32_t) (mGenCount * RSRandom::random_f32());
|
|
|
|
ForumDummyRef &ref = mGenRefs[idx];
|
|
|
|
|
|
|
|
RsGxsGroupId grpId = ref.mGroupId;
|
|
|
|
RsGxsMessageId parentId = ref.mMsgId;
|
|
|
|
mGenThreadId = ref.mThreadId;
|
|
|
|
if (mGenThreadId.empty())
|
|
|
|
{
|
|
|
|
mGenThreadId = parentId;
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
std::cerr << "p3GxsForums::dummy_tick() Generating Msg ... ";
|
|
|
|
std::cerr << " GroupId: " << grpId;
|
|
|
|
std::cerr << " ThreadId: " << mGenThreadId;
|
|
|
|
std::cerr << " ParentId: " << parentId;
|
|
|
|
std::cerr << std::endl;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
generateMessage(mGenToken, grpId, parentId, mGenThreadId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
bool p3GxsForums::generateMessage(uint32_t &token, const RsGxsGroupId &grpId, const RsGxsMessageId &parentId, const RsGxsMessageId &threadId)
|
|
|
|
{
|
|
|
|
RsGxsForumMsg msg;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
std::string rndId = genRandomId();
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
rs_sprintf(msg.mMsg, "Forum Msg: GroupId: %s, ThreadId: %s, ParentId: %s + some randomness: %s",
|
|
|
|
grpId.c_str(), threadId.c_str(), parentId.c_str(), rndId.c_str());
|
|
|
|
|
|
|
|
msg.mMeta.mMsgName = msg.mMsg;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
msg.mMeta.mGroupId = grpId;
|
|
|
|
msg.mMeta.mThreadId = threadId;
|
|
|
|
msg.mMeta.mParentId = parentId;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-12-08 21:32:47 -05:00
|
|
|
msg.mMeta.mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_UNREAD;
|
|
|
|
|
2012-11-19 17:00:05 -05:00
|
|
|
/* chose a random Id to sign with */
|
|
|
|
std::list<RsGxsId> ownIds;
|
|
|
|
std::list<RsGxsId>::iterator it;
|
|
|
|
|
|
|
|
rsIdentity->getOwnIds(ownIds);
|
|
|
|
|
|
|
|
uint32_t idx = (uint32_t) (ownIds.size() * RSRandom::random_f32());
|
|
|
|
int i = 0;
|
2014-01-20 06:42:27 -05:00
|
|
|
for(it = ownIds.begin(); (it != ownIds.end()) && (i < idx); it++, i++) ;
|
2012-11-19 17:00:05 -05:00
|
|
|
|
|
|
|
if (it != ownIds.end())
|
|
|
|
{
|
|
|
|
std::cerr << "p3GxsForums::generateMessage() Author: " << *it;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
msg.mMeta.mAuthorId = *it;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "p3GxsForums::generateMessage() No Author!";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
createMsg(token, msg);
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-08 19:56:07 -05:00
|
|
|
|
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
bool p3GxsForums::generateGroup(uint32_t &token, std::string groupName)
|
|
|
|
{
|
|
|
|
/* generate a new forum */
|
|
|
|
RsGxsForumGroup forum;
|
|
|
|
forum.mMeta.mGroupName = groupName;
|
2012-11-08 19:56:07 -05:00
|
|
|
|
2012-11-15 18:50:54 -05:00
|
|
|
createGroup(token, forum);
|
2012-11-08 19:56:07 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-19 17:00:05 -05:00
|
|
|
|
|
|
|
// Overloaded from RsTickEvent for Event callbacks.
|
2012-11-29 17:48:28 -05:00
|
|
|
void p3GxsForums::handle_event(uint32_t event_type, const std::string &elabel)
|
2012-11-19 17:00:05 -05:00
|
|
|
{
|
|
|
|
std::cerr << "p3GxsForums::handle_event(" << event_type << ")";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
// stuff.
|
|
|
|
switch(event_type)
|
|
|
|
{
|
|
|
|
case FORUM_TESTEVENT_DUMMYDATA:
|
|
|
|
generateDummyData();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* error */
|
|
|
|
std::cerr << "p3GxsForums::handle_event() Unknown Event Type: " << event_type;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|