mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04: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->meta.setBinData(metaDataBuff, size);
|
||||
|
||||
msg->metaData->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_UNREAD;
|
||||
msgId = msg->msgId;
|
||||
grpId = msg->grpId;
|
||||
mDataAccess->addMsgData(msg);
|
||||
@ -1322,9 +1323,11 @@ void RsGenExchange::publishGrps()
|
||||
int i = 0;
|
||||
for(; mit != mGrpsToPublish.end(); mit++)
|
||||
{
|
||||
|
||||
if(i > GEN_EXCH_GRP_CHUNK-1) break;
|
||||
|
||||
toRemove.push_back(mit->first);
|
||||
i++;
|
||||
if(i > GEN_EXCH_GRP_CHUNK) break;
|
||||
|
||||
RsNxsGrp* grp = new RsNxsGrp(mServType);
|
||||
RsGxsGrpItem* grpItem = mit->second;
|
||||
|
@ -91,6 +91,8 @@ namespace GXS_SERV {
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_UNREAD = 0x00000200;
|
||||
|
||||
static const uint32_t GXS_MSG_STATUS_READ = 0x00000400;
|
||||
|
||||
/** END GXS Msg 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);
|
||||
|
||||
|
||||
|
||||
class RsPosted : public RsGxsIfaceImpl
|
||||
{
|
||||
public:
|
||||
@ -106,6 +107,8 @@ virtual ~RsPosted() { return; }
|
||||
virtual bool submitVote(uint32_t &token, RsPostedVote &vote) = 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.
|
||||
/*!
|
||||
* Makes request for posts of a topic
|
||||
|
@ -7,10 +7,19 @@
|
||||
#include "gxs/rsgxsflags.h"
|
||||
#include "serialiser/rsposteditems.h"
|
||||
|
||||
#define NUM_TOPICS_TO_GENERATE 7
|
||||
#define NUM_POSTS_TO_GENERATE 8
|
||||
#define UPDATE_PHASE_GRP_REQUEST 1
|
||||
#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 VOTE_UPDATE_PERIOD 20 // 20 seconds
|
||||
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_COMMENT = 0x0001;
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_VOTE = 0x0004;
|
||||
@ -34,8 +43,12 @@ RsPostedVote::RsPostedVote(const RsGxsPostedVoteItem& item)
|
||||
|
||||
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
||||
: 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();
|
||||
}
|
||||
|
||||
@ -46,43 +59,56 @@ void p3Posted::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
|
||||
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()
|
||||
{
|
||||
if(mGeneratingPosts)
|
||||
{
|
||||
|
||||
|
||||
if(mRequestPhase1)
|
||||
{
|
||||
// request topics then chose at random which one to use to generate a post about
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
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)
|
||||
mTokenService->requestGroupInfo(mToken, 0, opts);
|
||||
mRequestPhase1 = false;
|
||||
return;
|
||||
}
|
||||
else if(!mRequestPhase2)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
if(mTokenService->requestStatus(mToken) == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||
{
|
||||
RsGenExchange::getGroupList(mToken, mGrpIds);
|
||||
|
||||
mRequestPhase2 = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
RsGenExchange::getGroupList(token, grpIds);
|
||||
|
||||
|
||||
if(mRequestPhase2)
|
||||
{
|
||||
// for each group generate NUM_POSTS_TO_GENERATE posts
|
||||
std::list<RsGxsGroupId>::iterator lit = grpIds.begin();
|
||||
std::list<RsGxsGroupId>::iterator lit = mGrpIds.begin();
|
||||
|
||||
for(; lit != grpIds.end(); lit++)
|
||||
for(; lit != mGrpIds.end(); lit++)
|
||||
{
|
||||
RsGxsGroupId& grpId = *lit;
|
||||
|
||||
std::vector<uint32_t> tokens;
|
||||
|
||||
for(int i=0; i < NUM_POSTS_TO_GENERATE; i++)
|
||||
{
|
||||
std::ostringstream ostrm;
|
||||
@ -95,29 +121,38 @@ void p3Posted::generatePosts()
|
||||
post.mMeta.mMsgName = link;
|
||||
post.mMeta.mGroupId = grpId;
|
||||
|
||||
uint32_t token;
|
||||
submitPost(token, post);
|
||||
tokens.push_back(token);
|
||||
mTokens.push_back(token);
|
||||
}
|
||||
}
|
||||
|
||||
while(!tokens.empty())
|
||||
{
|
||||
std::vector<uint32_t>::iterator vit = tokens.begin();
|
||||
mRequestPhase2 = false;
|
||||
mRequestPhase3 = true;
|
||||
|
||||
for(; vit != tokens.end(); )
|
||||
}
|
||||
else if(mRequestPhase3)
|
||||
{
|
||||
if(mTokenService->requestStatus(*vit) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||
vit = tokens.erase(vit);
|
||||
|
||||
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)
|
||||
vit = mTokens.erase(vit);
|
||||
else
|
||||
vit++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}else
|
||||
{
|
||||
// stop generating posts after acknowledging all the ones you created
|
||||
mGeneratingPosts = false;
|
||||
mRequestPhase3 = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,7 +160,9 @@ void p3Posted::generateTopics()
|
||||
{
|
||||
if(mGeneratingTopics)
|
||||
{
|
||||
std::vector<uint32_t> tokens;
|
||||
if(mRequestPhase1)
|
||||
{
|
||||
|
||||
|
||||
for(int i=0; i < NUM_TOPICS_TO_GENERATE; i++)
|
||||
{
|
||||
@ -138,27 +175,38 @@ void p3Posted::generateTopics()
|
||||
|
||||
uint32_t token;
|
||||
submitGroup(token, topic);
|
||||
tokens.push_back(token);
|
||||
mTokens.push_back(token);
|
||||
}
|
||||
|
||||
|
||||
while(!tokens.empty())
|
||||
mRequestPhase1 = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<uint32_t>::iterator vit = tokens.begin();
|
||||
|
||||
for(; vit != tokens.end(); )
|
||||
if(!mTokens.empty())
|
||||
{
|
||||
if(mTokenService->requestStatus(*vit) != RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||
vit = tokens.erase(vit);
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
mGeneratingTopics = false;
|
||||
else
|
||||
{
|
||||
mGeneratingPosts = true;
|
||||
mGeneratingTopics = false;
|
||||
mRequestPhase1 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
@ -619,191 +667,222 @@ void p3Posted::processCommentRanks()
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3Posted::updateVotes()
|
||||
{
|
||||
if(!mUpdateTokenQueued)
|
||||
{
|
||||
mUpdateTokenQueued = true;
|
||||
// any request failure stops update process
|
||||
|
||||
if(mPostUpdate)
|
||||
{
|
||||
switch(mUpdatePhase)
|
||||
{
|
||||
// case UPDATE_PHASE_GRP_REQUEST:
|
||||
// {
|
||||
// updateRequestGroups(mUpda);
|
||||
// break;
|
||||
// }
|
||||
// case UPDATE_PHASE_GRP_MSG_REQUEST:
|
||||
// {
|
||||
// updateRequestMessages(mVoteUpdataToken);
|
||||
// break;
|
||||
// }
|
||||
// case UPDATE_VOTE_COMMENT_REQUEST:
|
||||
// {
|
||||
// updateRequestVotesComments(mVoteUpdataToken);
|
||||
// break;
|
||||
// }
|
||||
// case UPDATE_COMPLETE_UPDATE:
|
||||
// {
|
||||
// updateCompleteUpdate();
|
||||
// break;
|
||||
// }
|
||||
// default:
|
||||
// break;
|
||||
case UPDATE_PHASE_GRP_REQUEST:
|
||||
{
|
||||
mPostUpdate = updateRequestGroups();
|
||||
break;
|
||||
}
|
||||
case UPDATE_PHASE_MSG_REQUEST:
|
||||
{
|
||||
mPostUpdate = updateRequestMessages();
|
||||
break;
|
||||
}
|
||||
case UPDATE_PHASE_VOTE_COMMENT_REQUEST:
|
||||
{
|
||||
mPostUpdate = updateRequestVotesComments();
|
||||
break;
|
||||
}
|
||||
case UPDATE_PHASE_VOTE_COUNT:
|
||||
{
|
||||
mPostUpdate = updateCompleteVotes();
|
||||
break;
|
||||
}
|
||||
case UPDATE_PHASE_COMPLETE:
|
||||
{
|
||||
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;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_IDS;
|
||||
opts.mSubscribeMask = GXS_SERV::GROUP_SUBSCRIBE_MASK;
|
||||
opts.mSubscribeFilter = GXS_SERV::GROUP_SUBSCRIBE_ADMIN |
|
||||
GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
||||
mTokenService->requestGroupInfo(token, 0, opts);
|
||||
// opts.mSubscribeMask = GXS_SERV::GROUP_SUBSCRIBE_MASK;
|
||||
// opts.mSubscribeFilter = GXS_SERV::GROUP_SUBSCRIBE_ADMIN |
|
||||
// GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
||||
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)
|
||||
{
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
RsGenExchange::getGroupList(token, grpIds);
|
||||
RsGenExchange::getGroupList(mUpdateRequestGroup, grpIds);
|
||||
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;
|
||||
mTokenService->requestMsgInfo(token, 0, opts, grpIds);
|
||||
mUpdatePhase = UPDATE_VOTE_COMMENT_REQUEST;
|
||||
mTokenService->requestMsgInfo(mUpdateRequestMessages, 0, opts, grpIds);
|
||||
mUpdatePhase = UPDATE_PHASE_VOTE_COMMENT_REQUEST;
|
||||
return true;
|
||||
}
|
||||
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
||||
{
|
||||
mTokenService->cancelRequest(token);
|
||||
mTokenService->cancelRequest(mUpdateRequestGroup);
|
||||
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)
|
||||
{
|
||||
|
||||
GxsMsgIdResult result;
|
||||
RsGenExchange::getMsgList(token, result);
|
||||
RsGenExchange::getMsgMeta(mUpdateRequestMessages, mMsgMetaUpdate);
|
||||
|
||||
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<RsGxsMessageId>::const_iterator cit = msgIdV.begin();
|
||||
std::vector<RsMsgMetaData>& msgIdV = mit->second;
|
||||
std::vector<RsMsgMetaData>::const_iterator cit = msgIdV.begin();
|
||||
|
||||
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;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_IDS;
|
||||
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_PARENT;
|
||||
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
||||
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_COMMENT;
|
||||
mTokenService->requestMsgRelatedInfo(mCommentToken, 0, opts, msgIds);
|
||||
// // only need ids for comments
|
||||
//
|
||||
// opts.mReqType = GXS_REQUEST_TYPE_MSG_IDS;
|
||||
// opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_PARENT;
|
||||
// opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
||||
// opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_COMMENT;
|
||||
// mTokenService->requestMsgRelatedInfo(mCommentToken, 0, opts, msgIds);
|
||||
|
||||
// need actual data from votes
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
// need actual data for votes
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
|
||||
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_PARENT;
|
||||
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
||||
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_VOTE;
|
||||
mTokenService->requestMsgRelatedInfo(mVoteToken, 0, opts, msgIds);
|
||||
mTokenService->requestMsgRelatedInfo(mUpdateRequestVotes, 0, opts, msgIds);
|
||||
|
||||
mUpdatePhase = UPDATE_COMPLETE_UPDATE;
|
||||
mMsgsPendingUpdate = msgIds;
|
||||
mUpdatePhase = UPDATE_PHASE_VOTE_COUNT;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
||||
{
|
||||
mTokenService->cancelRequest(token);
|
||||
mTokenService->cancelRequest(mUpdateRequestMessages);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool p3Posted::updateCompleteUpdate()
|
||||
{
|
||||
uint32_t commentStatus = mTokenService->requestStatus(mCommentToken);
|
||||
uint32_t voteStatus = mTokenService->requestStatus(mVoteToken);
|
||||
|
||||
bool ready = commentStatus == 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;
|
||||
getMsgRelatedDataT<RsGxsPostedVoteItem, RsPostedVote>(mVoteToken, votes);
|
||||
std::vector<RsGxsGrpMsgIdPair>::iterator vit = mMsgsPendingUpdate.begin();
|
||||
|
||||
for(; vit != mMsgsPendingUpdate.end();vit++)
|
||||
{
|
||||
updateMsg(*vit, votes[*vit], msgCommentIds[*vit]);
|
||||
}
|
||||
mUpdatePhase = 0;
|
||||
}
|
||||
else if(failed)
|
||||
{
|
||||
mTokenService->cancelRequest(mCommentToken);
|
||||
mTokenService->cancelRequest(mVoteToken);
|
||||
return false;
|
||||
}else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool p3Posted::updateMsg(const RsGxsGrpMsgIdPair& msgId, const std::vector<RsPostedVote> &msgVotes,
|
||||
const std::vector<RsGxsMessageId>& msgCommentIds)
|
||||
|
||||
bool p3Posted::updateCompleteVotes()
|
||||
{
|
||||
uint32_t status = mTokenService->requestStatus(mUpdateRequestVotes);
|
||||
|
||||
uint32_t nComments = msgCommentIds.size();
|
||||
uint32_t nUp = 0, nDown = 0;
|
||||
|
||||
std::vector<RsPostedVote>::const_iterator cit = msgVotes.begin();
|
||||
|
||||
for(; cit != msgVotes.end(); cit++)
|
||||
if(status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
|
||||
{
|
||||
const RsPostedVote& v = *cit;
|
||||
std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedVote> > votes;
|
||||
getMsgRelatedDataT<RsGxsPostedVoteItem, RsPostedVote>(mUpdateRequestVotes,
|
||||
votes);
|
||||
|
||||
if(v.mDirection == 0)
|
||||
// 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++)
|
||||
{
|
||||
nDown++;
|
||||
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
|
||||
{
|
||||
nUp++;
|
||||
mMsgCounts[mit->first].downVotes++;
|
||||
}
|
||||
}
|
||||
std::string servStr;
|
||||
storeScores(servStr, nUp, nDown, nComments);
|
||||
uint32_t token;
|
||||
setMsgServiceString(token, msgId, servStr);
|
||||
}
|
||||
mUpdatePhase = UPDATE_PHASE_COMPLETE;
|
||||
}
|
||||
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
|
||||
{
|
||||
mTokenService->cancelRequest(mUpdateRequestVotes);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Posted::updateComplete()
|
||||
{
|
||||
// now compare with msg meta to see what currently store there
|
||||
|
||||
GxsMsgMetaMap::iterator mit = mMsgMetaUpdate.begin();
|
||||
|
||||
for(; mit != mMsgMetaUpdate.end(); mit++)
|
||||
{
|
||||
const std::vector<RsMsgMetaData>& msgMetaV = mit->second;
|
||||
std::vector<RsMsgMetaData>::const_iterator cit = msgMetaV.begin();
|
||||
|
||||
for(; cit != msgMetaV.end(); cit++)
|
||||
{
|
||||
const RsMsgMetaData& msgMeta = *cit;
|
||||
uint32_t upVotes, downVotes, nComments;
|
||||
retrieveScores(msgMeta.mServiceString, upVotes, downVotes, nComments);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mPostUpdate = false;
|
||||
mUpdatePhase = UPDATE_PHASE_GRP_REQUEST;
|
||||
}
|
||||
|
@ -31,16 +31,15 @@ public:
|
||||
|
||||
class PostedScore {
|
||||
public:
|
||||
int32_t upVotes, downVotes;
|
||||
|
||||
PostedScore() : upVotes(0), downVotes(0), commentCount(0), date(0) {}
|
||||
uint32_t upVotes, downVotes;
|
||||
uint32_t commentCount;
|
||||
time_t date;
|
||||
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
|
||||
{
|
||||
@ -93,6 +92,8 @@ public:
|
||||
bool requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
||||
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:
|
||||
|
||||
/* Functions for processing rankings */
|
||||
@ -103,7 +104,7 @@ private:
|
||||
void discardCalc(const uint32_t& token);
|
||||
void completePostedPostCalc(GxsPostedPostRanking* gpp);
|
||||
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;
|
||||
|
||||
// for posts
|
||||
@ -124,12 +125,19 @@ private:
|
||||
* Also stores updates for messages which have new scores
|
||||
*/
|
||||
void updateVotes();
|
||||
bool updateRequestGroups(uint32_t& token);
|
||||
bool updateRequestMessages(uint32_t& token);
|
||||
bool updateRequestVotesComments(uint32_t& token);
|
||||
bool updateCompleteUpdate();
|
||||
bool updateMsg(const RsGxsGrpMsgIdPair& msgId, const std::vector<RsPostedVote>& msgVotes,
|
||||
const std::vector<RsGxsMessageId>& msgCommentIds);
|
||||
bool updateRequestGroups();
|
||||
bool updateRequestMessages();
|
||||
bool updateRequestVotesComments();
|
||||
bool updateCompleteVotes();
|
||||
bool updateCompleteComments();
|
||||
|
||||
/*!
|
||||
* 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:
|
||||
|
||||
@ -140,10 +148,14 @@ private:
|
||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
|
||||
|
||||
// for maintaining vote counts in msg meta
|
||||
uint32_t mVoteUpdataToken, mVoteToken, mCommentToken;
|
||||
bool mUpdateTokenQueued;
|
||||
uint32_t mUpdateRequestGroup, mUpdateRequestMessages, mUpdateRequestComments, mUpdateRequestVotes;
|
||||
bool mPostUpdate;
|
||||
uint32_t mUpdatePhase;
|
||||
std::vector<RsGxsGrpMsgIdPair> mMsgsPendingUpdate;
|
||||
time_t mLastUpdate;
|
||||
GxsMsgMetaMap mMsgMetaUpdate;
|
||||
std::map<RsGxsGrpMsgIdPair, PostedScore > mMsgCounts;
|
||||
std::vector<uint32_t> mChangeTokens;
|
||||
|
||||
RsTokenService* mTokenService;
|
||||
RsMutex mPostedMutex;
|
||||
@ -151,7 +163,11 @@ private:
|
||||
|
||||
// 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
|
||||
|
@ -55,7 +55,12 @@ PostedItem::PostedItem(PostedHolder *postHolder, const RsPostedPost &post)
|
||||
"><span style=\" text-decoration: underline; color:#0000ff;\">" +
|
||||
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( voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
|
||||
@ -72,16 +77,16 @@ RsPostedPost PostedItem::getPost() const
|
||||
void PostedItem::makeDownVote()
|
||||
{
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mMsgId;
|
||||
msgId.second = mPost.mMeta.mGroupId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
emit vote(msgId, false);
|
||||
}
|
||||
|
||||
void PostedItem::makeUpVote()
|
||||
{
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mMsgId;
|
||||
msgId.second = mPost.mMeta.mGroupId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
emit vote(msgId, true);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ border-radius: 10px}</string>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
<string>0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user