mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-26 09:41:29 -05:00
Recommiting from old repo:
commit msg from last: Fixed minor bug in group creation msg now set to unread and unprocessed on creation (added read flag in gxsflags.h also) Got topic and post generation working Additional changes: Voting update now working git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5951 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
0c49fba4d8
commit
6527aaf2d8
@ -1264,6 +1264,7 @@ void RsGenExchange::publishMsgs()
|
|||||||
msg->metaData->serialise(metaDataBuff, &size);
|
msg->metaData->serialise(metaDataBuff, &size);
|
||||||
msg->meta.setBinData(metaDataBuff, size);
|
msg->meta.setBinData(metaDataBuff, size);
|
||||||
|
|
||||||
|
msg->metaData->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_UNREAD;
|
||||||
msgId = msg->msgId;
|
msgId = msg->msgId;
|
||||||
grpId = msg->grpId;
|
grpId = msg->grpId;
|
||||||
mDataAccess->addMsgData(msg);
|
mDataAccess->addMsgData(msg);
|
||||||
@ -1322,9 +1323,11 @@ void RsGenExchange::publishGrps()
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for(; mit != mGrpsToPublish.end(); mit++)
|
for(; mit != mGrpsToPublish.end(); mit++)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(i > GEN_EXCH_GRP_CHUNK-1) break;
|
||||||
|
|
||||||
toRemove.push_back(mit->first);
|
toRemove.push_back(mit->first);
|
||||||
i++;
|
i++;
|
||||||
if(i > GEN_EXCH_GRP_CHUNK) break;
|
|
||||||
|
|
||||||
RsNxsGrp* grp = new RsNxsGrp(mServType);
|
RsNxsGrp* grp = new RsNxsGrp(mServType);
|
||||||
RsGxsGrpItem* grpItem = mit->second;
|
RsGxsGrpItem* grpItem = mit->second;
|
||||||
|
@ -403,20 +403,20 @@ public:
|
|||||||
void setGroupServiceString(uint32_t& token, const RsGxsGroupId& grpId, const std::string& servString);
|
void setGroupServiceString(uint32_t& token, const RsGxsGroupId& grpId, const std::string& servString);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* sets the msg status flag
|
* sets the msg status flag
|
||||||
* @param token this is set to token value associated to this request
|
* @param token this is set to token value associated to this request
|
||||||
* @param grpId Id of group whose subscribe file will be changed
|
* @param grpId Id of group whose subscribe file will be changed
|
||||||
* @param status
|
* @param status
|
||||||
* @param mask Mask to apply to status flag
|
* @param mask Mask to apply to status flag
|
||||||
*/
|
*/
|
||||||
void setMsgStatusFlags(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const uint32_t& status, const uint32_t& mask);
|
void setMsgStatusFlags(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const uint32_t& status, const uint32_t& mask);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* sets the message service string
|
* sets the message service string
|
||||||
* @param token this is set to token value associated to this request
|
* @param token this is set to token value associated to this request
|
||||||
* @param msgId Id of message whose service string will be changed
|
* @param msgId Id of message whose service string will be changed
|
||||||
* @param servString The service string to set msg to
|
* @param servString The service string to set msg to
|
||||||
*/
|
*/
|
||||||
void setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const std::string& servString );
|
void setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const std::string& servString );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -91,6 +91,8 @@ namespace GXS_SERV {
|
|||||||
|
|
||||||
static const uint32_t GXS_MSG_STATUS_UNREAD = 0x00000200;
|
static const uint32_t GXS_MSG_STATUS_UNREAD = 0x00000200;
|
||||||
|
|
||||||
|
static const uint32_t GXS_MSG_STATUS_READ = 0x00000400;
|
||||||
|
|
||||||
/** END GXS Msg status flags **/
|
/** END GXS Msg status flags **/
|
||||||
|
|
||||||
/** START GXS Grp status flags **/
|
/** START GXS Grp status flags **/
|
||||||
|
@ -78,6 +78,7 @@ std::ostream &operator<<(std::ostream &out, const RsPostedVote &vote);
|
|||||||
std::ostream &operator<<(std::ostream &out, const RsPostedComment &comment);
|
std::ostream &operator<<(std::ostream &out, const RsPostedComment &comment);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RsPosted : public RsGxsIfaceImpl
|
class RsPosted : public RsGxsIfaceImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -106,6 +107,8 @@ virtual ~RsPosted() { return; }
|
|||||||
virtual bool submitVote(uint32_t &token, RsPostedVote &vote) = 0;
|
virtual bool submitVote(uint32_t &token, RsPostedVote &vote) = 0;
|
||||||
virtual bool submitComment(uint32_t &token, RsPostedComment &comment) = 0;
|
virtual bool submitComment(uint32_t &token, RsPostedComment &comment) = 0;
|
||||||
|
|
||||||
|
virtual bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const = 0;
|
||||||
|
|
||||||
// Special Ranking Request.
|
// Special Ranking Request.
|
||||||
/*!
|
/*!
|
||||||
* Makes request for posts of a topic
|
* Makes request for posts of a topic
|
||||||
|
@ -7,10 +7,19 @@
|
|||||||
#include "gxs/rsgxsflags.h"
|
#include "gxs/rsgxsflags.h"
|
||||||
#include "serialiser/rsposteditems.h"
|
#include "serialiser/rsposteditems.h"
|
||||||
|
|
||||||
#define NUM_TOPICS_TO_GENERATE 7
|
#define UPDATE_PHASE_GRP_REQUEST 1
|
||||||
#define NUM_POSTS_TO_GENERATE 8
|
#define UPDATE_PHASE_MSG_REQUEST 2
|
||||||
|
#define UPDATE_PHASE_VOTE_COMMENT_REQUEST 3
|
||||||
|
#define UPDATE_PHASE_VOTE_COUNT 4
|
||||||
|
#define UPDATE_PHASE_COMMENT_COUNT 5
|
||||||
|
#define UPDATE_PHASE_COMPLETE 6
|
||||||
|
|
||||||
|
#define NUM_TOPICS_TO_GENERATE 1
|
||||||
|
#define NUM_POSTS_TO_GENERATE 1
|
||||||
#define NUM_VOTES_TO_GENERATE 23
|
#define NUM_VOTES_TO_GENERATE 23
|
||||||
|
|
||||||
|
#define VOTE_UPDATE_PERIOD 20 // 20 seconds
|
||||||
|
|
||||||
const uint32_t RsPosted::FLAG_MSGTYPE_COMMENT = 0x0001;
|
const uint32_t RsPosted::FLAG_MSGTYPE_COMMENT = 0x0001;
|
||||||
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
|
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
|
||||||
const uint32_t RsPosted::FLAG_MSGTYPE_VOTE = 0x0004;
|
const uint32_t RsPosted::FLAG_MSGTYPE_VOTE = 0x0004;
|
||||||
@ -34,8 +43,12 @@ RsPostedVote::RsPostedVote(const RsGxsPostedVoteItem& item)
|
|||||||
|
|
||||||
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
||||||
: RsGenExchange(gds, nes, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV1_TYPE_POSTED), RsPosted(this), mPostedMutex("Posted"),
|
: RsGenExchange(gds, nes, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV1_TYPE_POSTED), RsPosted(this), mPostedMutex("Posted"),
|
||||||
mTokenService(NULL), mGeneratingTopics(true), mGeneratingPosts(false)
|
mTokenService(NULL), mGeneratingTopics(true), mGeneratingPosts(false), mRequestPhase1(true), mRequestPhase2(false), mRequestPhase3(false)
|
||||||
{
|
{
|
||||||
|
mPostUpdate = false;
|
||||||
|
mLastUpdate = time(NULL);
|
||||||
|
mUpdatePhase = UPDATE_PHASE_GRP_REQUEST;
|
||||||
|
|
||||||
mTokenService = RsGenExchange::getTokenService();
|
mTokenService = RsGenExchange::getTokenService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,78 +59,100 @@ void p3Posted::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||||||
|
|
||||||
void p3Posted::service_tick()
|
void p3Posted::service_tick()
|
||||||
{
|
{
|
||||||
generateTopics();
|
|
||||||
|
|
||||||
//generatePosts();
|
generateTopics();
|
||||||
|
generatePosts();
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
if((now > (time_t) (VOTE_UPDATE_PERIOD + mLastUpdate)) &&
|
||||||
|
(mUpdatePhase == UPDATE_PHASE_GRP_REQUEST))
|
||||||
|
{
|
||||||
|
mPostUpdate = true;
|
||||||
|
mLastUpdate = time(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateVotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3Posted::generatePosts()
|
void p3Posted::generatePosts()
|
||||||
{
|
{
|
||||||
if(mGeneratingPosts)
|
if(mGeneratingPosts)
|
||||||
{
|
{
|
||||||
// request topics then chose at random which one to use to generate a post about
|
|
||||||
uint32_t token;
|
|
||||||
RsTokReqOptions opts;
|
if(mRequestPhase1)
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
|
||||||
mTokenService->requestGroupInfo(token, 0, opts);
|
|
||||||
double timeDelta = 2.; // slow tick
|
|
||||||
while(mTokenService->requestStatus(token) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
|
||||||
{
|
{
|
||||||
#ifndef WINDOWS_SYS
|
// request topics then chose at random which one to use to generate a post about
|
||||||
usleep((int) (timeDelta * 1000000));
|
RsTokReqOptions opts;
|
||||||
#else
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
||||||
Sleep((int) (timeDelta * 1000));
|
mTokenService->requestGroupInfo(mToken, 0, opts);
|
||||||
#endif
|
mRequestPhase1 = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if(!mRequestPhase2)
|
||||||
|
{
|
||||||
|
if(mTokenService->requestStatus(mToken) == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||||
|
{
|
||||||
|
RsGenExchange::getGroupList(mToken, mGrpIds);
|
||||||
|
|
||||||
|
mRequestPhase2 = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<RsGxsGroupId> grpIds;
|
if(mRequestPhase2)
|
||||||
RsGenExchange::getGroupList(token, grpIds);
|
|
||||||
|
|
||||||
|
|
||||||
// for each group generate NUM_POSTS_TO_GENERATE posts
|
|
||||||
std::list<RsGxsGroupId>::iterator lit = grpIds.begin();
|
|
||||||
|
|
||||||
for(; lit != grpIds.end(); lit++)
|
|
||||||
{
|
{
|
||||||
RsGxsGroupId& grpId = *lit;
|
// for each group generate NUM_POSTS_TO_GENERATE posts
|
||||||
|
std::list<RsGxsGroupId>::iterator lit = mGrpIds.begin();
|
||||||
|
|
||||||
std::vector<uint32_t> tokens;
|
for(; lit != mGrpIds.end(); lit++)
|
||||||
|
|
||||||
for(int i=0; i < NUM_POSTS_TO_GENERATE; i++)
|
|
||||||
{
|
{
|
||||||
std::ostringstream ostrm;
|
RsGxsGroupId& grpId = *lit;
|
||||||
ostrm << i;
|
|
||||||
std::string link = "link" + ostrm.str();
|
|
||||||
|
|
||||||
RsPostedPost post;
|
for(int i=0; i < NUM_POSTS_TO_GENERATE; i++)
|
||||||
post.mLink = link;
|
{
|
||||||
post.mNotes = link;
|
std::ostringstream ostrm;
|
||||||
post.mMeta.mMsgName = link;
|
ostrm << i;
|
||||||
post.mMeta.mGroupId = grpId;
|
std::string link = "link " + ostrm.str();
|
||||||
|
|
||||||
submitPost(token, post);
|
RsPostedPost post;
|
||||||
tokens.push_back(token);
|
post.mLink = link;
|
||||||
|
post.mNotes = link;
|
||||||
|
post.mMeta.mMsgName = link;
|
||||||
|
post.mMeta.mGroupId = grpId;
|
||||||
|
|
||||||
|
uint32_t token;
|
||||||
|
submitPost(token, post);
|
||||||
|
mTokens.push_back(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!tokens.empty())
|
mRequestPhase2 = false;
|
||||||
{
|
mRequestPhase3 = true;
|
||||||
std::vector<uint32_t>::iterator vit = tokens.begin();
|
|
||||||
|
|
||||||
for(; vit != tokens.end(); )
|
}
|
||||||
|
else if(mRequestPhase3)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!mTokens.empty())
|
||||||
|
{
|
||||||
|
std::vector<uint32_t>::iterator vit = mTokens.begin();
|
||||||
|
|
||||||
|
for(; vit != mTokens.end(); )
|
||||||
{
|
{
|
||||||
if(mTokenService->requestStatus(*vit) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
if(mTokenService->requestStatus(*vit) == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||||
vit = tokens.erase(vit);
|
vit = mTokens.erase(vit);
|
||||||
else
|
else
|
||||||
vit++;
|
vit++;
|
||||||
}
|
}
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
// stop generating posts after acknowledging all the ones you created
|
||||||
|
mGeneratingPosts = false;
|
||||||
|
mRequestPhase3 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// stop generating posts after acknowledging all the ones you created
|
|
||||||
mGeneratingPosts = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,40 +160,53 @@ void p3Posted::generateTopics()
|
|||||||
{
|
{
|
||||||
if(mGeneratingTopics)
|
if(mGeneratingTopics)
|
||||||
{
|
{
|
||||||
std::vector<uint32_t> tokens;
|
if(mRequestPhase1)
|
||||||
|
|
||||||
for(int i=0; i < NUM_TOPICS_TO_GENERATE; i++)
|
|
||||||
{
|
{
|
||||||
std::ostringstream strm;
|
|
||||||
strm << i;
|
|
||||||
std::string topicName = "Topic " + strm.str();
|
|
||||||
|
|
||||||
RsPostedGroup topic;
|
|
||||||
topic.mMeta.mGroupName = topicName;
|
|
||||||
|
|
||||||
uint32_t token;
|
|
||||||
submitGroup(token, topic);
|
|
||||||
tokens.push_back(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while(!tokens.empty())
|
for(int i=0; i < NUM_TOPICS_TO_GENERATE; i++)
|
||||||
{
|
|
||||||
std::vector<uint32_t>::iterator vit = tokens.begin();
|
|
||||||
|
|
||||||
for(; vit != tokens.end(); )
|
|
||||||
{
|
{
|
||||||
if(mTokenService->requestStatus(*vit) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
std::ostringstream strm;
|
||||||
vit = tokens.erase(vit);
|
strm << i;
|
||||||
else
|
std::string topicName = "Topic " + strm.str();
|
||||||
vit++;
|
|
||||||
|
RsPostedGroup topic;
|
||||||
|
topic.mMeta.mGroupName = topicName;
|
||||||
|
|
||||||
|
uint32_t token;
|
||||||
|
submitGroup(token, topic);
|
||||||
|
mTokens.push_back(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
mRequestPhase1 = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!mTokens.empty())
|
||||||
|
{
|
||||||
|
std::vector<uint32_t>::iterator vit = mTokens.begin();
|
||||||
|
|
||||||
|
for(; vit != mTokens.end(); )
|
||||||
|
{
|
||||||
|
if(mTokenService->requestStatus(*vit) == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||||
|
{
|
||||||
|
RsGxsGroupId grpId;
|
||||||
|
RsGenExchange::acknowledgeTokenGrp(*vit, grpId);
|
||||||
|
vit = mTokens.erase(vit);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
vit++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mGeneratingPosts = true;
|
||||||
|
mGeneratingTopics = false;
|
||||||
|
mRequestPhase1 = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mGeneratingTopics = false;
|
|
||||||
mGeneratingPosts = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Posted::getGroup(const uint32_t &token, std::vector<RsPostedGroup> &groups)
|
bool p3Posted::getGroup(const uint32_t &token, std::vector<RsPostedGroup> &groups)
|
||||||
@ -594,7 +642,7 @@ void p3Posted::completePostedCommentRanking(GxsPostedCommentRanking *gpc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Posted::retrieveScores(const std::string &serviceString, uint32_t &upVotes, uint32_t downVotes, uint32_t nComments) const
|
bool p3Posted::retrieveScores(const std::string &serviceString, uint32_t &upVotes, uint32_t& downVotes, uint32_t& nComments) const
|
||||||
{
|
{
|
||||||
if (3 == sscanf(serviceString.c_str(), "%d %d %d", &upVotes, &downVotes, &nComments))
|
if (3 == sscanf(serviceString.c_str(), "%d %d %d", &upVotes, &downVotes, &nComments))
|
||||||
{
|
{
|
||||||
@ -619,191 +667,222 @@ void p3Posted::processCommentRanks()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void p3Posted::updateVotes()
|
void p3Posted::updateVotes()
|
||||||
{
|
{
|
||||||
if(!mUpdateTokenQueued)
|
// any request failure stops update process
|
||||||
{
|
|
||||||
mUpdateTokenQueued = true;
|
|
||||||
|
|
||||||
|
if(mPostUpdate)
|
||||||
|
{
|
||||||
switch(mUpdatePhase)
|
switch(mUpdatePhase)
|
||||||
{
|
{
|
||||||
// case UPDATE_PHASE_GRP_REQUEST:
|
case UPDATE_PHASE_GRP_REQUEST:
|
||||||
// {
|
{
|
||||||
// updateRequestGroups(mUpda);
|
mPostUpdate = updateRequestGroups();
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// case UPDATE_PHASE_GRP_MSG_REQUEST:
|
case UPDATE_PHASE_MSG_REQUEST:
|
||||||
// {
|
{
|
||||||
// updateRequestMessages(mVoteUpdataToken);
|
mPostUpdate = updateRequestMessages();
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// case UPDATE_VOTE_COMMENT_REQUEST:
|
case UPDATE_PHASE_VOTE_COMMENT_REQUEST:
|
||||||
// {
|
{
|
||||||
// updateRequestVotesComments(mVoteUpdataToken);
|
mPostUpdate = updateRequestVotesComments();
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// case UPDATE_COMPLETE_UPDATE:
|
case UPDATE_PHASE_VOTE_COUNT:
|
||||||
// {
|
{
|
||||||
// updateCompleteUpdate();
|
mPostUpdate = updateCompleteVotes();
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// default:
|
case UPDATE_PHASE_COMPLETE:
|
||||||
// break;
|
{
|
||||||
|
updateComplete();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
std::cerr << "Unknown update phase, we should not be here!" << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// first get all msgs for groups for which you are subscribed to.
|
|
||||||
// then request comments for them
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Posted::updateRequestGroups(uint32_t &token)
|
bool p3Posted::updateRequestGroups()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
RsTokReqOptions opts;
|
RsTokReqOptions opts;
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
||||||
opts.mSubscribeMask = GXS_SERV::GROUP_SUBSCRIBE_MASK;
|
// opts.mSubscribeMask = GXS_SERV::GROUP_SUBSCRIBE_MASK;
|
||||||
opts.mSubscribeFilter = GXS_SERV::GROUP_SUBSCRIBE_ADMIN |
|
// opts.mSubscribeFilter = GXS_SERV::GROUP_SUBSCRIBE_ADMIN |
|
||||||
GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
// GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
||||||
mTokenService->requestGroupInfo(token, 0, opts);
|
mTokenService->requestGroupInfo(mUpdateRequestGroup, 0, opts);
|
||||||
|
|
||||||
mUpdatePhase = UPDATE_PHASE_GRP_MSG_REQUEST;
|
mUpdatePhase = UPDATE_PHASE_MSG_REQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Posted::updateRequestMessages(uint32_t &token)
|
bool p3Posted::updateRequestMessages()
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t status = mTokenService->requestStatus(token);
|
uint32_t status = mTokenService->requestStatus(mUpdateRequestGroup);
|
||||||
|
|
||||||
if(status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
if(status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||||
{
|
{
|
||||||
std::list<RsGxsGroupId> grpIds;
|
std::list<RsGxsGroupId> grpIds;
|
||||||
RsGenExchange::getGroupList(token, grpIds);
|
RsGenExchange::getGroupList(mUpdateRequestGroup, grpIds);
|
||||||
RsTokReqOptions opts;
|
RsTokReqOptions opts;
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_IDS;
|
opts.mReqType = GXS_REQUEST_TYPE_MSG_META;
|
||||||
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_THREAD;
|
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_THREAD;
|
||||||
mTokenService->requestMsgInfo(token, 0, opts, grpIds);
|
mTokenService->requestMsgInfo(mUpdateRequestMessages, 0, opts, grpIds);
|
||||||
mUpdatePhase = UPDATE_VOTE_COMMENT_REQUEST;
|
mUpdatePhase = UPDATE_PHASE_VOTE_COMMENT_REQUEST;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
||||||
{
|
{
|
||||||
mTokenService->cancelRequest(token);
|
mTokenService->cancelRequest(mUpdateRequestGroup);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Posted::updateRequestVotesComments(uint32_t &token)
|
bool p3Posted::updateRequestVotesComments()
|
||||||
{
|
{
|
||||||
|
|
||||||
uint32_t status = mTokenService->requestStatus(token);
|
uint32_t status = mTokenService->requestStatus(mUpdateRequestMessages);
|
||||||
|
|
||||||
if(status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
if(status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||||
{
|
{
|
||||||
|
|
||||||
GxsMsgIdResult result;
|
RsGenExchange::getMsgMeta(mUpdateRequestMessages, mMsgMetaUpdate);
|
||||||
RsGenExchange::getMsgList(token, result);
|
|
||||||
|
|
||||||
std::vector<RsGxsGrpMsgIdPair> msgIds;
|
std::vector<RsGxsGrpMsgIdPair> msgIds;
|
||||||
|
|
||||||
GxsMsgIdResult::iterator mit = result.begin();
|
GxsMsgMetaMap::iterator mit = mMsgMetaUpdate.begin();
|
||||||
|
|
||||||
for(; mit != result.end(); mit++)
|
for(; mit != mMsgMetaUpdate.end(); mit++)
|
||||||
{
|
{
|
||||||
std::vector<RsGxsMessageId>& msgIdV = mit->second;
|
std::vector<RsMsgMetaData>& msgIdV = mit->second;
|
||||||
std::vector<RsGxsMessageId>::const_iterator cit = msgIdV.begin();
|
std::vector<RsMsgMetaData>::const_iterator cit = msgIdV.begin();
|
||||||
|
|
||||||
for(; cit != msgIdV.end(); cit++)
|
for(; cit != msgIdV.end(); cit++)
|
||||||
msgIds.push_back(std::make_pair(mit->first, *cit));
|
msgIds.push_back(std::make_pair(mit->first, cit->mMsgId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// only need ids for comments
|
|
||||||
RsTokReqOptions opts;
|
RsTokReqOptions opts;
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_IDS;
|
// // only need ids for comments
|
||||||
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_PARENT;
|
//
|
||||||
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
// opts.mReqType = GXS_REQUEST_TYPE_MSG_IDS;
|
||||||
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_COMMENT;
|
// opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_PARENT;
|
||||||
mTokenService->requestMsgRelatedInfo(mCommentToken, 0, opts, msgIds);
|
// opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
||||||
|
// opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_COMMENT;
|
||||||
|
// mTokenService->requestMsgRelatedInfo(mCommentToken, 0, opts, msgIds);
|
||||||
|
|
||||||
// need actual data from votes
|
// need actual data for votes
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
|
||||||
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_PARENT;
|
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_PARENT;
|
||||||
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
||||||
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_VOTE;
|
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_VOTE;
|
||||||
mTokenService->requestMsgRelatedInfo(mVoteToken, 0, opts, msgIds);
|
mTokenService->requestMsgRelatedInfo(mUpdateRequestVotes, 0, opts, msgIds);
|
||||||
|
|
||||||
mUpdatePhase = UPDATE_COMPLETE_UPDATE;
|
mUpdatePhase = UPDATE_PHASE_VOTE_COUNT;
|
||||||
mMsgsPendingUpdate = msgIds;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
||||||
{
|
{
|
||||||
mTokenService->cancelRequest(token);
|
mTokenService->cancelRequest(mUpdateRequestMessages);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Posted::updateCompleteUpdate()
|
|
||||||
|
bool p3Posted::updateCompleteVotes()
|
||||||
{
|
{
|
||||||
uint32_t commentStatus = mTokenService->requestStatus(mCommentToken);
|
uint32_t status = mTokenService->requestStatus(mUpdateRequestVotes);
|
||||||
uint32_t voteStatus = mTokenService->requestStatus(mVoteToken);
|
|
||||||
|
|
||||||
bool ready = commentStatus == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE;
|
if(status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||||
ready &= voteStatus == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE;
|
|
||||||
|
|
||||||
bool failed = commentStatus == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED;
|
|
||||||
failed &= voteStatus == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED;
|
|
||||||
|
|
||||||
if(ready)
|
|
||||||
{
|
{
|
||||||
std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMessageId> > msgCommentIds;
|
|
||||||
std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedVote> > votes;
|
std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedVote> > votes;
|
||||||
getMsgRelatedDataT<RsGxsPostedVoteItem, RsPostedVote>(mVoteToken, votes);
|
getMsgRelatedDataT<RsGxsPostedVoteItem, RsPostedVote>(mUpdateRequestVotes,
|
||||||
std::vector<RsGxsGrpMsgIdPair>::iterator vit = mMsgsPendingUpdate.begin();
|
votes);
|
||||||
|
|
||||||
for(; vit != mMsgsPendingUpdate.end();vit++)
|
// now for each msg count the number of votes and thats it
|
||||||
|
|
||||||
|
std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedVote> >::iterator mit = votes.begin();
|
||||||
|
|
||||||
|
for(; mit != votes.end(); mit++)
|
||||||
{
|
{
|
||||||
updateMsg(*vit, votes[*vit], msgCommentIds[*vit]);
|
const std::vector<RsPostedVote>& v = mit->second;
|
||||||
|
std::vector<RsPostedVote>::const_iterator cit = v.begin();
|
||||||
|
|
||||||
|
for(; cit != v.end(); cit++)
|
||||||
|
{
|
||||||
|
const RsPostedVote& vote = *cit;
|
||||||
|
|
||||||
|
if(vote.mDirection)
|
||||||
|
{
|
||||||
|
mMsgCounts[mit->first].upVotes++;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
mMsgCounts[mit->first].downVotes++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mUpdatePhase = 0;
|
mUpdatePhase = UPDATE_PHASE_COMPLETE;
|
||||||
}
|
}
|
||||||
else if(failed)
|
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
||||||
{
|
{
|
||||||
mTokenService->cancelRequest(mCommentToken);
|
mTokenService->cancelRequest(mUpdateRequestVotes);
|
||||||
mTokenService->cancelRequest(mVoteToken);
|
|
||||||
return false;
|
return false;
|
||||||
}else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool p3Posted::updateMsg(const RsGxsGrpMsgIdPair& msgId, const std::vector<RsPostedVote> &msgVotes,
|
bool p3Posted::updateComplete()
|
||||||
const std::vector<RsGxsMessageId>& msgCommentIds)
|
|
||||||
{
|
{
|
||||||
|
// now compare with msg meta to see what currently store there
|
||||||
|
|
||||||
uint32_t nComments = msgCommentIds.size();
|
GxsMsgMetaMap::iterator mit = mMsgMetaUpdate.begin();
|
||||||
uint32_t nUp = 0, nDown = 0;
|
|
||||||
|
|
||||||
std::vector<RsPostedVote>::const_iterator cit = msgVotes.begin();
|
for(; mit != mMsgMetaUpdate.end(); mit++)
|
||||||
|
|
||||||
for(; cit != msgVotes.end(); cit++)
|
|
||||||
{
|
{
|
||||||
const RsPostedVote& v = *cit;
|
const std::vector<RsMsgMetaData>& msgMetaV = mit->second;
|
||||||
|
std::vector<RsMsgMetaData>::const_iterator cit = msgMetaV.begin();
|
||||||
|
|
||||||
if(v.mDirection == 0)
|
for(; cit != msgMetaV.end(); cit++)
|
||||||
{
|
{
|
||||||
nDown++;
|
const RsMsgMetaData& msgMeta = *cit;
|
||||||
}else
|
uint32_t upVotes, downVotes, nComments;
|
||||||
{
|
retrieveScores(msgMeta.mServiceString, upVotes, downVotes, nComments);
|
||||||
nUp++;
|
|
||||||
|
RsGxsGrpMsgIdPair msgId;
|
||||||
|
msgId.first = mit->first;
|
||||||
|
msgId.second = msgMeta.mMsgId;
|
||||||
|
PostedScore& sc = mMsgCounts[msgId];
|
||||||
|
|
||||||
|
bool changed = (sc.upVotes != upVotes) || (sc.downVotes != downVotes);
|
||||||
|
|
||||||
|
if(changed)
|
||||||
|
{
|
||||||
|
std::string servStr;
|
||||||
|
storeScores(servStr, sc.upVotes, sc.downVotes, 0);
|
||||||
|
uint32_t token;
|
||||||
|
setMsgServiceString(token, msgId, servStr);
|
||||||
|
mChangeTokens.push_back(token);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mMsgCounts.erase(msgId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string servStr;
|
|
||||||
storeScores(servStr, nUp, nDown, nComments);
|
|
||||||
uint32_t token;
|
|
||||||
setMsgServiceString(token, msgId, servStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
mPostUpdate = false;
|
||||||
|
mUpdatePhase = UPDATE_PHASE_GRP_REQUEST;
|
||||||
|
}
|
||||||
|
@ -31,16 +31,15 @@ public:
|
|||||||
|
|
||||||
class PostedScore {
|
class PostedScore {
|
||||||
public:
|
public:
|
||||||
int32_t upVotes, downVotes;
|
|
||||||
|
PostedScore() : upVotes(0), downVotes(0), commentCount(0), date(0) {}
|
||||||
|
uint32_t upVotes, downVotes;
|
||||||
|
uint32_t commentCount;
|
||||||
time_t date;
|
time_t date;
|
||||||
RsGxsMessageId msgId;
|
RsGxsMessageId msgId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define UPDATE_PHASE_GRP_REQUEST 1
|
|
||||||
#define UPDATE_PHASE_GRP_MSG_REQUEST 2
|
|
||||||
#define UPDATE_VOTE_COMMENT_REQUEST 3
|
|
||||||
#define UPDATE_COMPLETE_UPDATE 4
|
|
||||||
|
|
||||||
class p3Posted : public RsGenExchange, public RsPosted
|
class p3Posted : public RsGenExchange, public RsPosted
|
||||||
{
|
{
|
||||||
@ -93,6 +92,8 @@ public:
|
|||||||
bool requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
bool requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
||||||
bool requestCommentRankings(uint32_t &token, const RankType &rType, const RsGxsGrpMsgIdPair &msgId);
|
bool requestCommentRankings(uint32_t &token, const RankType &rType, const RsGxsGrpMsgIdPair &msgId);
|
||||||
|
|
||||||
|
bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/* Functions for processing rankings */
|
/* Functions for processing rankings */
|
||||||
@ -103,7 +104,7 @@ private:
|
|||||||
void discardCalc(const uint32_t& token);
|
void discardCalc(const uint32_t& token);
|
||||||
void completePostedPostCalc(GxsPostedPostRanking* gpp);
|
void completePostedPostCalc(GxsPostedPostRanking* gpp);
|
||||||
void completePostedCommentRanking(GxsPostedCommentRanking* gpc);
|
void completePostedCommentRanking(GxsPostedCommentRanking* gpc);
|
||||||
bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
|
|
||||||
bool storeScores(std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
|
bool storeScores(std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
|
||||||
|
|
||||||
// for posts
|
// for posts
|
||||||
@ -124,12 +125,19 @@ private:
|
|||||||
* Also stores updates for messages which have new scores
|
* Also stores updates for messages which have new scores
|
||||||
*/
|
*/
|
||||||
void updateVotes();
|
void updateVotes();
|
||||||
bool updateRequestGroups(uint32_t& token);
|
bool updateRequestGroups();
|
||||||
bool updateRequestMessages(uint32_t& token);
|
bool updateRequestMessages();
|
||||||
bool updateRequestVotesComments(uint32_t& token);
|
bool updateRequestVotesComments();
|
||||||
bool updateCompleteUpdate();
|
bool updateCompleteVotes();
|
||||||
bool updateMsg(const RsGxsGrpMsgIdPair& msgId, const std::vector<RsPostedVote>& msgVotes,
|
bool updateCompleteComments();
|
||||||
const std::vector<RsGxsMessageId>& msgCommentIds);
|
|
||||||
|
/*!
|
||||||
|
* The aim of this is create notifications
|
||||||
|
* for the UI of changes to a post if their vote
|
||||||
|
* or comment count has changed
|
||||||
|
*/
|
||||||
|
bool updateComplete();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -140,10 +148,14 @@ private:
|
|||||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
|
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
|
||||||
|
|
||||||
// for maintaining vote counts in msg meta
|
// for maintaining vote counts in msg meta
|
||||||
uint32_t mVoteUpdataToken, mVoteToken, mCommentToken;
|
uint32_t mUpdateRequestGroup, mUpdateRequestMessages, mUpdateRequestComments, mUpdateRequestVotes;
|
||||||
bool mUpdateTokenQueued;
|
bool mPostUpdate;
|
||||||
uint32_t mUpdatePhase;
|
uint32_t mUpdatePhase;
|
||||||
std::vector<RsGxsGrpMsgIdPair> mMsgsPendingUpdate;
|
std::vector<RsGxsGrpMsgIdPair> mMsgsPendingUpdate;
|
||||||
|
time_t mLastUpdate;
|
||||||
|
GxsMsgMetaMap mMsgMetaUpdate;
|
||||||
|
std::map<RsGxsGrpMsgIdPair, PostedScore > mMsgCounts;
|
||||||
|
std::vector<uint32_t> mChangeTokens;
|
||||||
|
|
||||||
RsTokenService* mTokenService;
|
RsTokenService* mTokenService;
|
||||||
RsMutex mPostedMutex;
|
RsMutex mPostedMutex;
|
||||||
@ -151,7 +163,11 @@ private:
|
|||||||
|
|
||||||
// for data generation
|
// for data generation
|
||||||
|
|
||||||
bool mGeneratingPosts, mGeneratingTopics;
|
bool mGeneratingPosts, mGeneratingTopics, mRequestPhase1, mRequestPhase2, mRequestPhase3;
|
||||||
|
std::vector<uint32_t> mTokens;
|
||||||
|
uint32_t mToken;
|
||||||
|
std::list<RsGxsGroupId> mGrpIds;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // P3POSTED_H
|
#endif // P3POSTED_H
|
||||||
|
@ -55,7 +55,12 @@ PostedItem::PostedItem(PostedHolder *postHolder, const RsPostedPost &post)
|
|||||||
"><span style=\" text-decoration: underline; color:#0000ff;\">" +
|
"><span style=\" text-decoration: underline; color:#0000ff;\">" +
|
||||||
QString::fromStdString(post.mLink) + "</span></a>");
|
QString::fromStdString(post.mLink) + "</span></a>");
|
||||||
|
|
||||||
scoreLabel->setText(QString("1"));
|
uint32_t up, down, nComments;
|
||||||
|
|
||||||
|
rsPosted->retrieveScores(mPost.mMeta.mServiceString, up, down, nComments);
|
||||||
|
|
||||||
|
int32_t vote = up - down;
|
||||||
|
scoreLabel->setText(QString::number(vote));
|
||||||
|
|
||||||
connect( commentButton, SIGNAL( clicked() ), this, SLOT( loadComments() ) );
|
connect( commentButton, SIGNAL( clicked() ), this, SLOT( loadComments() ) );
|
||||||
connect( voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
|
connect( voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
|
||||||
@ -72,16 +77,16 @@ RsPostedPost PostedItem::getPost() const
|
|||||||
void PostedItem::makeDownVote()
|
void PostedItem::makeDownVote()
|
||||||
{
|
{
|
||||||
RsGxsGrpMsgIdPair msgId;
|
RsGxsGrpMsgIdPair msgId;
|
||||||
msgId.first = mPost.mMeta.mMsgId;
|
msgId.first = mPost.mMeta.mGroupId;
|
||||||
msgId.second = mPost.mMeta.mGroupId;
|
msgId.second = mPost.mMeta.mMsgId;
|
||||||
emit vote(msgId, false);
|
emit vote(msgId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostedItem::makeUpVote()
|
void PostedItem::makeUpVote()
|
||||||
{
|
{
|
||||||
RsGxsGrpMsgIdPair msgId;
|
RsGxsGrpMsgIdPair msgId;
|
||||||
msgId.first = mPost.mMeta.mMsgId;
|
msgId.first = mPost.mMeta.mGroupId;
|
||||||
msgId.second = mPost.mMeta.mGroupId;
|
msgId.second = mPost.mMeta.mMsgId;
|
||||||
emit vote(msgId, true);
|
emit vote(msgId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ border-radius: 10px}</string>
|
|||||||
</font>
|
</font>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>1</string>
|
<string>0</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user