Comment and Vote update now functional

Voting and comment count update in gui added via msg notification
clarified comments in RsTokenService

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5958 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-12-09 22:38:49 +00:00
parent 62176264d3
commit 30b48c59ef
12 changed files with 339 additions and 36 deletions

View file

@ -64,7 +64,7 @@ public:
bool requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts);
/*!
* Use this to get msg related information, store this value to pole for request completion
* Use this to get msg information (id, meta, or data), store token value to poll for request completion
* @param token The token returned for the request
* @param ansType The type of result wanted
* @param opts Additional option that affect outcome of request. Please see specific services, for valid values
@ -74,11 +74,12 @@ public:
bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const GxsMsgReq& msgIds);
/*!
* Use this to get msg related information, store this value to pole for request completion
* Use this to get message information (id, meta, or data), store token value to poll for request completion
* @param token The token returned for the request
* @param ansType The type of result wanted
* @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @param groupIds The ids of the groups to get, this retrieve all the msgs info for each grpId in list
* @param groupIds The ids of the groups to get, this retrieve all the msgs info for each grpId in list, if group Id list is empty \n
* all messages for all groups are retrieved
* @return true if request successful false otherwise
*/
bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId>& grpIds);

View file

@ -163,10 +163,10 @@ public:
* @param token The token returned for the request
* @param ansType The type of result wanted
* @param opts Additional option that affect outcome of request. Please see specific services, for valid values
* @param groupIds The ids of the groups to get, this retrieve all the msgs info for each grpId in list
* @param groupIds The ids of the groups to get, this retrieves all the msgs info for each grpId in list
* @return true if request successful false otherwise
*/
virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId>& msgIds) = 0;
virtual bool requestMsgInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list<RsGxsGroupId>& grpIds) = 0;
/*!
* For requesting msgs related to a given msg id within a group

View file

@ -134,6 +134,7 @@ class RsPostedPost
RsPostedPost()
{
mMeta.mMsgFlags = RsPosted::FLAG_MSGTYPE_POST;
mMeta.mServiceString = " 0 0 0";
return;
}

View file

@ -18,8 +18,9 @@
#define NUM_TOPICS_TO_GENERATE 1
#define NUM_POSTS_TO_GENERATE 1
#define NUM_VOTES_TO_GENERATE 23
#define NUM_COMMENTS_TO_GENERATE 23
#define VOTE_UPDATE_PERIOD 20 // 20 seconds
#define VOTE_UPDATE_PERIOD 30 // 20 seconds
const uint32_t RsPosted::FLAG_MSGTYPE_COMMENT = 0x0001;
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
@ -44,7 +45,8 @@ 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), mRequestPhase1(true), mRequestPhase2(false), mRequestPhase3(false)
mTokenService(NULL), mGeneratingTopics(true), mGeneratingPosts(false), mRequestPhase1(true), mRequestPhase2(false),
mRequestPhase3(false), mGenerateVotesAndComments(false)
{
mPostUpdate = false;
mLastUpdate = time(NULL);
@ -63,6 +65,7 @@ void p3Posted::service_tick()
generateTopics();
generatePosts();
generateVotesAndComments();
time_t now = time(NULL);
@ -76,6 +79,121 @@ void p3Posted::service_tick()
updateVotes();
}
void p3Posted::generateVotesAndComments()
{
if(mGenerateVotesAndComments)
{
if(mRequestPhase1)
{
// request topics then chose at random which one to use to generate a post about
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_IDS;
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_POST;
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
mTokenService->requestMsgInfo(mToken, 0, opts, mGrpIds);
mRequestPhase1 = false;
mRequestPhase2 = true;
return;
}
if(mRequestPhase2)
{
if(mTokenService->requestStatus(mToken) == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
{
GxsMsgIdResult msgIds;
RsGenExchange::getMsgList(mToken, msgIds);
// for each msg generate a random number of votes and comments
GxsMsgIdResult::iterator mit = msgIds.begin();
for(; mit != msgIds.end(); mit++)
{
const RsGxsGroupId& grpId = mit->first;
std::vector<RsGxsMessageId>& msgIdsV = mit->second;
std::vector<RsGxsMessageId>::iterator vit = msgIdsV.begin();
for(; vit != msgIdsV.end(); vit++)
{
const RsGxsMessageId& msgId = *vit;
int nVotes = rand()%NUM_VOTES_TO_GENERATE;
uint32_t token;
for(int i=1; i < nVotes; i++)
{
RsPostedVote v;
v.mDirection = (rand()%10 > 3) ? 0 : 1;
v.mMeta.mParentId = msgId;
v.mMeta.mGroupId = grpId;
std::ostringstream ostrm;
ostrm << i;
v.mMeta.mMsgName = "Vote " + ostrm.str();
submitVote(token, v);
mTokens.push_back(token);
}
int nComments = rand()%NUM_COMMENTS_TO_GENERATE;
// single level comments for now
for(int i=1; i < nComments; i++)
{
RsPostedComment c;
std::ostringstream ostrm;
ostrm << i;
c.mComment = "Comment " + ostrm.str();
c.mMeta.mParentId = msgId;
c.mMeta.mGroupId = grpId;
submitComment(token, c);
mTokens.push_back(token);
}
}
}
mRequestPhase2 = false;
mRequestPhase3 = true;
}
}
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)
vit = mTokens.erase(vit);
else
vit++;
}
}else
{
// stop generating posts after acknowledging all the ones you created
mGeneratingPosts = false;
mRequestPhase3 = false;
}
}
}
}
void p3Posted::generatePosts()
{
if(mGeneratingPosts)
@ -151,6 +269,8 @@ void p3Posted::generatePosts()
// stop generating posts after acknowledging all the ones you created
mGeneratingPosts = false;
mRequestPhase3 = false;
mGenerateVotesAndComments = true;
mRequestPhase1 = true;
}
}
@ -544,7 +664,7 @@ void p3Posted::calcPostedPostRank(const std::vector<RsMsgMetaData > msgMeta, Pos
std::vector<PostedScore>::iterator vit = scores.begin();
int i = 1;
for(; vit != scores.end(); vit)
for(; vit != scores.end(); vit++)
{
const PostedScore& p = *vit;
ranking.insert(std::make_pair(p.msgId, i++));
@ -697,6 +817,11 @@ void p3Posted::updateVotes()
mPostUpdate = updateCompleteVotes();
break;
}
case UPDATE_PHASE_COMMENT_COUNT:
{
mPostUpdate = updateCompleteComments();
break;
}
case UPDATE_PHASE_COMPLETE:
{
updateComplete();
@ -774,13 +899,13 @@ bool p3Posted::updateRequestVotesComments()
}
RsTokReqOptions opts;
// // 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);
// only need ids for comments
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_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(mUpdateRequestComments, 0, opts, msgIds);
// need actual data for votes
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
@ -835,7 +960,7 @@ bool p3Posted::updateCompleteVotes()
}
}
}
mUpdatePhase = UPDATE_PHASE_COMPLETE;
mUpdatePhase = UPDATE_PHASE_COMMENT_COUNT;
}
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
{
@ -845,6 +970,39 @@ bool p3Posted::updateCompleteVotes()
return true;
}
bool p3Posted::updateCompleteComments()
{
uint32_t status = mTokenService->requestStatus(mUpdateRequestComments);
if(status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE)
{
MsgRelatedIdResult commentIds;
RsGenExchange::getMsgRelatedList(mUpdateRequestComments, commentIds);
// now for each msg count the number of votes and thats it
MsgRelatedIdResult::iterator mit = commentIds.begin();
for(; mit != commentIds.end(); mit++)
{
const std::vector<RsGxsMessageId>& v = mit->second;
std::vector<RsGxsMessageId>::const_iterator cit = v.begin();
for(; cit != v.end(); cit++)
{
mMsgCounts[mit->first].commentCount++;
}
}
mUpdatePhase = UPDATE_PHASE_COMPLETE;
}
else if(status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED)
{
mTokenService->cancelRequest(mUpdateRequestComments);
return false;
}
return true;
}
bool p3Posted::updateComplete()
{
// now compare with msg meta to see what currently store there
@ -867,12 +1025,13 @@ bool p3Posted::updateComplete()
msgId.second = msgMeta.mMsgId;
PostedScore& sc = mMsgCounts[msgId];
bool changed = (sc.upVotes != upVotes) || (sc.downVotes != downVotes);
bool changed = (sc.upVotes != upVotes) || (sc.downVotes != downVotes)
|| (sc.commentCount != nComments);
if(changed)
{
std::string servStr;
storeScores(servStr, sc.upVotes, sc.downVotes, 0);
storeScores(servStr, sc.upVotes, sc.downVotes, sc.commentCount);
uint32_t token;
setMsgServiceString(token, msgId, servStr);
mChangeTokens.push_back(token);
@ -886,4 +1045,24 @@ bool p3Posted::updateComplete()
mPostUpdate = false;
mUpdatePhase = UPDATE_PHASE_GRP_REQUEST;
if(!mMsgCounts.empty())
{
RsGxsMsgChange* msgChange = new RsGxsMsgChange();
std::map<RsGxsGrpMsgIdPair, PostedScore >::iterator mit_c = mMsgCounts.begin();
for(; mit_c != mMsgCounts.end(); mit_c++)
{
const RsGxsGrpMsgIdPair& msgId = mit_c->first;
msgChange->msgChangeMap[msgId.first].push_back(msgId.second);
}
std::vector<RsGxsNotify*> n;
n.push_back(msgChange);
notifyChanges(n);
mMsgCounts.clear();
}
}

View file

@ -74,7 +74,7 @@ public:
* Generates random votes to existing posts
* in the system
*/
void generateVotes();
void generateVotesAndComments();
public:
@ -163,7 +163,8 @@ private:
// for data generation
bool mGeneratingPosts, mGeneratingTopics, mRequestPhase1, mRequestPhase2, mRequestPhase3;
bool mGeneratingPosts, mGeneratingTopics,
mRequestPhase1, mRequestPhase2, mRequestPhase3, mGenerateVotesAndComments;
std::vector<uint32_t> mTokens;
uint32_t mToken;
std::list<RsGxsGroupId> mGrpIds;