mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-06 08:05:18 -04:00
Added logic for rank calculation and interface methods
Disabled posting when no post is selected Added notes section when viewing post (tres basic) fix for comment item serialisation fix for subscription token option not in this commit ;) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5913 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5a55c1b5d6
commit
44d32626bc
9 changed files with 304 additions and 182 deletions
|
@ -70,6 +70,7 @@ typedef std::map<RsGxsGroupId, std::vector<RsPostedComment> > PostedCommentResul
|
|||
typedef std::map<RsGxsGroupId, std::vector<RsPostedVote> > PostedVoteResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPostedComment> > PostedRelatedCommentResult;
|
||||
typedef std::pair<RsGxsGroupId, int32_t> GroupRank;
|
||||
typedef std::map<RsGxsMessageId, uint32_t> PostedRanking;
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
|
||||
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
|
||||
|
@ -81,6 +82,8 @@ class RsPosted : public RsGxsIfaceImpl
|
|||
{
|
||||
public:
|
||||
|
||||
enum RankType {TopRankType, BestRankType, NewRankType };
|
||||
|
||||
static const uint32_t FLAG_MSGTYPE_POST;
|
||||
static const uint32_t FLAG_MSGTYPE_VOTE;
|
||||
static const uint32_t FLAG_MSGTYPE_COMMENT;
|
||||
|
@ -91,19 +94,33 @@ virtual ~RsPosted() { return; }
|
|||
|
||||
/* Specific Service Data */
|
||||
|
||||
virtual bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group) = 0;
|
||||
virtual bool getPost(const uint32_t &token, PostedPostResult &post) = 0;
|
||||
virtual bool getComment(const uint32_t &token, PostedCommentResult &comment) = 0;
|
||||
virtual bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult& comments) = 0;
|
||||
virtual bool getGroupRank(const uint32_t &token, GroupRank& grpRank) = 0;
|
||||
virtual bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group) = 0;
|
||||
virtual bool getPost(const uint32_t &token, PostedPostResult &post) = 0;
|
||||
virtual bool getComment(const uint32_t &token, PostedCommentResult &comment) = 0;
|
||||
virtual bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult& comments) = 0;
|
||||
virtual bool getRanking(const uint32_t& token, PostedRanking& ranking) = 0;
|
||||
|
||||
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group) = 0;
|
||||
virtual bool submitPost(uint32_t &token, RsPostedPost &post) = 0;
|
||||
virtual bool submitVote(uint32_t &token, RsPostedVote &vote) = 0;
|
||||
virtual bool submitComment(uint32_t &token, RsPostedComment &comment) = 0;
|
||||
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group) = 0;
|
||||
virtual bool submitPost(uint32_t &token, RsPostedPost &post) = 0;
|
||||
virtual bool submitVote(uint32_t &token, RsPostedVote &vote) = 0;
|
||||
virtual bool submitComment(uint32_t &token, RsPostedComment &comment) = 0;
|
||||
|
||||
// Special Ranking Request.
|
||||
virtual bool requestRanking(uint32_t &token, RsGxsGroupId groupId) = 0;
|
||||
/*!
|
||||
* Makes request for posts of a topic
|
||||
* @param token
|
||||
* @param rType
|
||||
* @param groupId
|
||||
*/
|
||||
virtual bool requestMessageRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
|
||||
|
||||
/*!
|
||||
* Makes request for ranking of comments for a post
|
||||
* @param token
|
||||
* @param rType type of ranking to collect
|
||||
* @param msgId message id of post as groupid-messageid pair
|
||||
*/
|
||||
virtual bool requestCommentRankings(uint32_t &token, const RankType& rType, const RsGxsGrpMsgIdPair& msgId) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -435,7 +435,7 @@ RsGxsPostedCommentItem* RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem(v
|
|||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_GXSV1_TYPE_POSTED != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_POSTED_POST_ITEM != getRsItemSubType(rstype)))
|
||||
(RS_PKT_SUBTYPE_POSTED_COMMENT_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
#ifdef GXS_POSTED_SERIAL_DEBUG
|
||||
std::cerr << "RsGxsPostedSerialiser::deserialiseGxsPostedCommentItem() FAIL wrong type" << std::endl;
|
||||
|
|
|
@ -14,7 +14,7 @@ RsPostedComment::RsPostedComment(const RsGxsPostedCommentItem & item)
|
|||
}
|
||||
|
||||
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
||||
: RsGenExchange(gds, nes, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV1_TYPE_POSTED), RsPosted(this)
|
||||
: RsGenExchange(gds, nes, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV1_TYPE_POSTED), RsPosted(this), mPostedMutex("Posted")
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -129,11 +129,6 @@ bool p3Posted::getRelatedComment(const uint32_t& token, PostedRelatedCommentResu
|
|||
return RsGenExchange::getMsgRelatedDataT<RsGxsPostedCommentItem, RsPostedComment>(token, comments);
|
||||
}
|
||||
|
||||
bool p3Posted::getGroupRank(const uint32_t &token, GroupRank &grpRank)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool p3Posted::submitGroup(uint32_t &token, RsPostedGroup &group)
|
||||
{
|
||||
RsGxsPostedGroupItem* grpItem = new RsGxsPostedGroupItem();
|
||||
|
@ -177,7 +172,125 @@ bool p3Posted::submitComment(uint32_t &token, RsPostedComment &comment)
|
|||
}
|
||||
|
||||
// Special Ranking Request.
|
||||
bool p3Posted::requestRanking(uint32_t &token, RsGxsGroupId groupId)
|
||||
bool p3Posted::requestCommentRankings(uint32_t &token, const RankType &rType, const RsGxsGrpMsgIdPair &msgId)
|
||||
{
|
||||
token = RsGenExchange::generatePublicToken();
|
||||
|
||||
RsStackMutex stack(mPostedMutex);
|
||||
|
||||
GxsPostedCommentRanking* gpc = new GxsPostedCommentRanking();
|
||||
gpc->msgId = msgId;
|
||||
gpc->rType = rType;
|
||||
gpc->pubToken = token;
|
||||
|
||||
mPendingCommentRanks.insert(std::make_pair(token, gpc));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Posted::requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId)
|
||||
{
|
||||
token = RsGenExchange::generatePublicToken();
|
||||
|
||||
RsStackMutex stack(mPostedMutex);
|
||||
GxsPostedPostRanking* gp = new GxsPostedPostRanking();
|
||||
gp->grpId = groupId;
|
||||
gp->rType = rType;
|
||||
gp->pubToken = token;
|
||||
|
||||
mPendingPostRanks.insert(std::make_pair(token, gp));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Posted::getRanking(const uint32_t &token, PostedRanking &ranking)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void p3Posted::processRankings()
|
||||
{
|
||||
processMessageRanks();
|
||||
|
||||
processCommentRanks();
|
||||
}
|
||||
|
||||
void p3Posted::processMessageRanks()
|
||||
{
|
||||
|
||||
RsStackMutex stack(mPostedMutex);
|
||||
std::map<uint32_t, GxsPostedPostRanking*>::iterator mit =mPendingPostRanks.begin();
|
||||
|
||||
for(; mit !=mPendingPostRanks.begin(); mit++)
|
||||
{
|
||||
uint32_t token;
|
||||
std::list<RsGxsGroupId> grpL;
|
||||
grpL.push_back(mit->second->grpId);
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
opts.mOptions = RS_TOKREQOPT_MSG_LATEST | RS_TOKREQOPT_MSG_THREAD;
|
||||
RsGenExchange::getTokenService()->requestMsgInfo(token, GXS_REQUEST_TYPE_GROUP_DATA, opts, grpL);
|
||||
GxsPostedPostRanking* gp = mit->second;
|
||||
gp->reqToken = token;
|
||||
|
||||
while(true)
|
||||
{
|
||||
uint32_t status = RsGenExchange::getTokenService()->requestStatus(token);
|
||||
|
||||
if(RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE
|
||||
== status)
|
||||
{
|
||||
completePostedPostCalc(gp);
|
||||
break;
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED
|
||||
== status)
|
||||
{
|
||||
discardCalc(token);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mPendingPostRanks.clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void p3Posted::discardCalc(const uint32_t &token)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void p3Posted::completePostedPostCalc(GxsPostedPostRanking *gpp)
|
||||
{
|
||||
GxsMsgMetaMap msgMetas;
|
||||
getMsgMeta(gpp->reqToken, msgMetas);
|
||||
|
||||
GxsMsgMetaMap::iterator mit = msgMetas.begin();
|
||||
|
||||
for(; mit != msgMetas.end(); mit++ )
|
||||
{
|
||||
RsGxsMsgMetaData* m = NULL;
|
||||
//retrieveScores(m->mServiceString, upVotes, downVotes, nComments);
|
||||
|
||||
// then dependent on rank request type process for that way
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool p3Posted::retrieveScores(const std::string &serviceString, uint32_t &upVotes, uint32_t downVotes, uint32_t nComments)
|
||||
{
|
||||
if (2 == sscanf(serviceString.c_str(), "%d %d %d", &upVotes, &downVotes, &nComments))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void p3Posted::processCommentRanks()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,34 @@
|
|||
#ifndef P3POSTED_H
|
||||
#define P3POSTED_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "retroshare/rsposted.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
|
||||
|
||||
class GxsPostedPostRanking
|
||||
{
|
||||
public:
|
||||
|
||||
uint32_t pubToken;
|
||||
uint32_t reqToken;
|
||||
RsPosted::RankType rType;
|
||||
RsGxsGroupId grpId;
|
||||
PostedRanking result;
|
||||
};
|
||||
|
||||
class GxsPostedCommentRanking
|
||||
{
|
||||
public:
|
||||
|
||||
uint32_t pubToken;
|
||||
uint32_t reqToken;
|
||||
RsPosted::RankType rType;
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
PostedRanking result;
|
||||
};
|
||||
|
||||
class p3Posted : public RsGenExchange, public RsPosted
|
||||
{
|
||||
public:
|
||||
|
@ -30,20 +55,34 @@ public:
|
|||
bool getPost(const uint32_t &token, PostedPostResult& posts) ;
|
||||
bool getComment(const uint32_t &token, PostedCommentResult& comments) ;
|
||||
bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult &comments);
|
||||
bool getGroupRank(const uint32_t& token, GroupRank& grpRank);
|
||||
bool getRanking(const uint32_t &token, PostedRanking &ranking);
|
||||
|
||||
bool submitGroup(uint32_t &token, RsPostedGroup &group);
|
||||
bool submitPost(uint32_t &token, RsPostedPost &post);
|
||||
bool submitVote(uint32_t &token, RsPostedVote &vote);
|
||||
bool submitComment(uint32_t &token, RsPostedComment &comment) ;
|
||||
// Special Ranking Request.
|
||||
bool requestRanking(uint32_t &token, RsGxsGroupId groupId) ;
|
||||
bool requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
||||
bool requestCommentRankings(uint32_t &token, const RankType &rType, const RsGxsGrpMsgIdPair &msgId);
|
||||
|
||||
// Control Ranking Calculations.
|
||||
// bool setViewMode(uint32_t mode);
|
||||
// bool setViewPeriod(uint32_t period);
|
||||
// bool setViewRange(uint32_t first, uint32_t count);
|
||||
private:
|
||||
|
||||
void processRankings();
|
||||
void processMessageRanks();
|
||||
void processCommentRanks();
|
||||
void discardCalc(const uint32_t& token);
|
||||
void completePostedPostCalc(GxsPostedPostRanking* gpp);
|
||||
bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments);
|
||||
|
||||
private:
|
||||
|
||||
std::map<uint32_t, GxsPostedPostRanking*> mPendingPostRanks;
|
||||
std::map<uint32_t, GxsPostedPostRanking*> mPendingCalculationPostRanks;
|
||||
|
||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCommentRanks;
|
||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
|
||||
|
||||
RsMutex mPostedMutex;
|
||||
};
|
||||
|
||||
#endif // P3POSTED_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue