mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Reworked ranking process flow
added ranking retrieval in gui removed locks from TokenQueue refactored gxs p3 pointers in p3face header file and gxs services now shutdown correctly using join(led to bad segfaults on shutdown) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5972 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f8c83779af
commit
3eaf844ec8
@ -44,8 +44,8 @@
|
||||
|
||||
#define PUB_GRP_OFFSET 0
|
||||
#define RESTR_GRP_OFFSET 8
|
||||
#define PRIV_GRP_OFFSET 16
|
||||
#define GRP_OPTIONS_OFFSET 24
|
||||
#define PRIV_GRP_OFFSET 9
|
||||
#define GRP_OPTIONS_OFFSET 7
|
||||
|
||||
#define GXS_MASK "GXS_MASK_HACK"
|
||||
|
||||
|
@ -64,13 +64,14 @@ class RsPostedGroup
|
||||
class RsPostedPost;
|
||||
class RsPostedComment;
|
||||
class RsPostedVote;
|
||||
class RsPostedPostRanking;
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsPostedPost> > PostedPostResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsPostedComment> > PostedCommentResult;
|
||||
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;
|
||||
typedef std::map<uint32_t, RsGxsMessageId> PostedRanking;
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group);
|
||||
std::ostream &operator<<(std::ostream &out, const RsPostedPost &post);
|
||||
@ -100,7 +101,7 @@ virtual ~RsPosted() { return; }
|
||||
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 getPostRanking(const uint32_t& token, RsPostedPostRanking& ranking) = 0;
|
||||
|
||||
virtual bool submitGroup(uint32_t &token, RsPostedGroup &group) = 0;
|
||||
virtual bool submitPost(uint32_t &token, RsPostedPost &post) = 0;
|
||||
@ -116,7 +117,7 @@ virtual ~RsPosted() { return; }
|
||||
* @param rType
|
||||
* @param groupId
|
||||
*/
|
||||
virtual bool requestMessageRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
|
||||
virtual bool requestPostRankings(uint32_t &token, const RankType& rType, const RsGxsGroupId& groupId) = 0;
|
||||
|
||||
/*!
|
||||
* Makes request for ranking of comments for a post
|
||||
@ -175,4 +176,12 @@ class RsPostedComment
|
||||
RsMsgMetaData mMeta;
|
||||
};
|
||||
|
||||
class RsPostedPostRanking
|
||||
{
|
||||
public:
|
||||
|
||||
RsGxsGroupId grpId;
|
||||
PostedRanking ranking;
|
||||
RsPosted::RankType rType;
|
||||
};
|
||||
#endif // RSPOSTED_H
|
||||
|
@ -186,9 +186,21 @@ void RsServer::rsGlobalShutDown()
|
||||
mPluginsManager->stopPlugins();
|
||||
|
||||
// stop the p3distrib threads
|
||||
|
||||
mForums->join();
|
||||
mChannels->join();
|
||||
|
||||
if(mGxsCircles) mGxsCircles->join();
|
||||
if(mGxsForums) mGxsForums->join();
|
||||
if(mGxsIdService) mGxsIdService->join();
|
||||
if(mPosted) mPosted->join();
|
||||
if(mPhoto) mPhoto->join();
|
||||
if(mWiki) mWiki->join();
|
||||
if(mWire) mWire->join();
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef RS_USE_BLOGS
|
||||
mBlogs->join();
|
||||
#endif
|
||||
|
@ -76,6 +76,15 @@ RsServer::RsServer(RsIface &i, NotifyBase &callback)
|
||||
/* Config */
|
||||
mConfigMgr = NULL;
|
||||
mGeneralConfig = NULL;
|
||||
|
||||
/* GXS */
|
||||
mPhoto = NULL;
|
||||
mWiki = NULL;
|
||||
mPosted = NULL;
|
||||
mGxsCircles = NULL;
|
||||
mGxsIdService = NULL;
|
||||
mGxsForums = NULL;
|
||||
mWire = NULL;
|
||||
}
|
||||
|
||||
RsServer::~RsServer()
|
||||
|
@ -45,6 +45,15 @@
|
||||
#include "services/p3channels.h"
|
||||
#include "services/p3forums.h"
|
||||
|
||||
#include "services/p3idservice.h"
|
||||
#include "services/p3gxscircles.h"
|
||||
#include "services/p3wiki.h"
|
||||
#include "services/p3posted.h"
|
||||
#include "services/p3photoservice.h"
|
||||
#include "services/p3gxsforums.h"
|
||||
#include "services/p3wire.h"
|
||||
|
||||
|
||||
class p3PeerMgrIMPL;
|
||||
class p3LinkMgrIMPL;
|
||||
class p3NetMgrIMPL;
|
||||
@ -175,6 +184,16 @@ class RsServer: public RsControl, public RsThread
|
||||
p3Forums *mForums;
|
||||
/* caches (that need ticking) */
|
||||
|
||||
/* GXS */
|
||||
|
||||
p3Wiki *mWiki;
|
||||
p3Posted *mPosted;
|
||||
p3PhotoService *mPhoto;
|
||||
p3GxsCircles *mGxsCircles;
|
||||
p3IdService *mGxsIdService;
|
||||
p3GxsForums *mGxsForums;
|
||||
p3Wire *mWire;
|
||||
|
||||
/* Config */
|
||||
p3ConfigMgr *mConfigMgr;
|
||||
p3GeneralConfig *mGeneralConfig;
|
||||
|
@ -1823,15 +1823,6 @@ RsTurtle *rsTurtle = NULL ;
|
||||
#include "gxs/rsgxsflags.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_GXS_SERVICES
|
||||
#include "services/p3idservice.h"
|
||||
#include "services/p3gxscircles.h"
|
||||
#include "services/p3wiki.h"
|
||||
#include "services/p3posted.h"
|
||||
#include "services/p3photoservice.h"
|
||||
#include "services/p3gxsforums.h"
|
||||
#include "services/p3wire.h"
|
||||
#endif
|
||||
|
||||
#ifndef PQI_DISABLE_TUNNEL
|
||||
#include "services/p3tunnel.h"
|
||||
@ -2302,8 +2293,6 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
/**** Identity service ****/
|
||||
|
||||
p3IdService *mGxsIdService = NULL;
|
||||
|
||||
RsGeneralDataService* gxsid_ds = new RsDataService(currGxsDir + "/", "gxsid_db",
|
||||
RS_SERVICE_GXSV1_TYPE_GXSID, NULL);
|
||||
|
||||
@ -2318,7 +2307,6 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
/**** GxsCircle service ****/
|
||||
|
||||
p3GxsCircles *mGxsCircles = NULL;
|
||||
|
||||
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
|
||||
RS_SERVICE_GXSV1_TYPE_GXSCIRCLE, NULL);
|
||||
@ -2354,8 +2342,6 @@ int RsServer::StartupRetroShare()
|
||||
RsGenExchange::setAuthenPolicyFlag(flag, photoAuthenPolicy,
|
||||
RsGenExchange::GRP_OPTION_BITS);
|
||||
|
||||
p3PhotoService *mPhoto = NULL;
|
||||
|
||||
|
||||
RsGeneralDataService* photo_ds = new RsDataService(currGxsDir + "/", "photoV2_db",
|
||||
RS_SERVICE_GXSV1_TYPE_PHOTO, NULL);
|
||||
@ -2372,7 +2358,7 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
/**** Posted GXS service ****/
|
||||
|
||||
p3Posted *mPosted = NULL;
|
||||
|
||||
|
||||
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
|
||||
RS_SERVICE_GXSV1_TYPE_POSTED);
|
||||
@ -2388,7 +2374,7 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
/**** Wiki GXS service ****/
|
||||
|
||||
p3Wiki *mWiki = NULL;
|
||||
|
||||
|
||||
RsGeneralDataService* wiki_ds = new RsDataService(currGxsDir + "/", "wiki_db",
|
||||
RS_SERVICE_GXSV1_TYPE_WIKI);
|
||||
@ -2404,7 +2390,6 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
/**** Wire GXS service ****/
|
||||
|
||||
p3Wire *mWire = NULL;
|
||||
|
||||
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
|
||||
RS_SERVICE_GXSV1_TYPE_WIRE);
|
||||
@ -2420,8 +2405,6 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
/**** Forum GXS service ****/
|
||||
|
||||
p3GxsForums *mGxsForums = NULL;
|
||||
|
||||
RsGeneralDataService* gxsforums_ds = new RsDataService(currGxsDir + "/", "gxsforums_db",
|
||||
RS_SERVICE_GXSV1_TYPE_FORUMS);
|
||||
|
||||
|
@ -15,12 +15,12 @@
|
||||
#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_COMMENTS_TO_GENERATE 23
|
||||
#define NUM_TOPICS_TO_GENERATE 7
|
||||
#define NUM_POSTS_TO_GENERATE 7
|
||||
#define NUM_VOTES_TO_GENERATE 11
|
||||
#define NUM_COMMENTS_TO_GENERATE 4
|
||||
|
||||
#define VOTE_UPDATE_PERIOD 30 // 20 seconds
|
||||
#define VOTE_UPDATE_PERIOD 5 // 20 seconds
|
||||
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_COMMENT = 0x0001;
|
||||
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
|
||||
@ -77,6 +77,8 @@ void p3Posted::service_tick()
|
||||
}
|
||||
|
||||
updateVotes();
|
||||
|
||||
processRankings();
|
||||
}
|
||||
|
||||
void p3Posted::generateVotesAndComments()
|
||||
@ -157,6 +159,7 @@ void p3Posted::generateVotesAndComments()
|
||||
c.mComment = "Comment " + ostrm.str();
|
||||
c.mMeta.mParentId = msgId;
|
||||
c.mMeta.mGroupId = grpId;
|
||||
c.mMeta.mThreadId = msgId;
|
||||
|
||||
submitComment(token, c);
|
||||
mTokens.push_back(token);
|
||||
@ -490,7 +493,7 @@ bool p3Posted::requestCommentRankings(uint32_t &token, const RankType &rType, co
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Posted::requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId)
|
||||
bool p3Posted::requestPostRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId)
|
||||
{
|
||||
token = RsGenExchange::generatePublicToken();
|
||||
|
||||
@ -499,64 +502,111 @@ bool p3Posted::requestMessageRankings(uint32_t &token, const RankType &rType, co
|
||||
gp->grpId = groupId;
|
||||
gp->rType = rType;
|
||||
gp->pubToken = token;
|
||||
gp->rankingResult.rType = gp->rType;
|
||||
gp->grpId = gp->grpId;
|
||||
|
||||
mPendingPostRanks.insert(std::make_pair(token, gp));
|
||||
mPendingPostRanks.push_back(gp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3Posted::getRanking(const uint32_t &token, PostedRanking &ranking)
|
||||
bool p3Posted::getPostRanking(const uint32_t &token, RsPostedPostRanking &ranking)
|
||||
{
|
||||
RsStackMutex stack(mPostedMutex);
|
||||
|
||||
if( mCompletePostRanks.find(token) == mCompletePostRanks.end()) return false;
|
||||
|
||||
ranking = mCompletePostRanks[token];
|
||||
mCompletePostRanks.erase(token);
|
||||
|
||||
// put this in service tick as it's blocking
|
||||
// and likely costly
|
||||
disposeOfPublicToken(token);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void p3Posted::processRankings()
|
||||
{
|
||||
processMessageRanks();
|
||||
// processPostRanks();
|
||||
|
||||
processCommentRanks();
|
||||
//processCommentRanks();
|
||||
}
|
||||
|
||||
void p3Posted::processMessageRanks()
|
||||
void p3Posted::processPostRanks()
|
||||
{
|
||||
|
||||
RsStackMutex stack(mPostedMutex);
|
||||
std::map<uint32_t, GxsPostedPostRanking*>::iterator mit =mPendingPostRanks.begin();
|
||||
|
||||
std::vector<GxsPostedPostRanking*>::iterator vit = mPendingPostRanks.begin();
|
||||
|
||||
// go through all pending posts
|
||||
for(; mit !=mPendingPostRanks.begin(); mit++)
|
||||
for(; vit !=mPendingPostRanks.begin(); )
|
||||
{
|
||||
GxsPostedPostRanking* gp = *vit;
|
||||
uint32_t token;
|
||||
std::list<RsGxsGroupId> grpL;
|
||||
grpL.push_back(mit->second->grpId);
|
||||
grpL.push_back(gp->grpId);
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_META;
|
||||
opts.mMsgFlagFilter = RsPosted::FLAG_MSGTYPE_POST;
|
||||
opts.mMsgFlagMask = RsPosted::FLAG_MSGTYPE_MASK;
|
||||
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 = mTokenService->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;
|
||||
}
|
||||
}
|
||||
vit = mPendingPostRanks.erase(vit);
|
||||
mCompletionPostRanks.push_back(gp);
|
||||
}
|
||||
|
||||
mPendingPostRanks.clear();
|
||||
|
||||
vit = mCompletionPostRanks.begin();
|
||||
|
||||
for(; vit != mCompletionPostRanks.end(); )
|
||||
{
|
||||
bool ok = false;
|
||||
GxsPostedPostRanking *gp = *vit;
|
||||
uint32_t status = mTokenService->requestStatus(gp->reqToken);
|
||||
|
||||
if(RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE
|
||||
== status)
|
||||
{
|
||||
ok = completePostedPostCalc(gp);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
mCompletePostRanks.insert(
|
||||
std::make_pair(gp->pubToken, gp->rankingResult));
|
||||
}
|
||||
}
|
||||
else if(RsTokenService::GXS_REQUEST_V2_STATUS_FAILED
|
||||
== status)
|
||||
{
|
||||
discardCalc(gp->reqToken);
|
||||
ok = false;
|
||||
}else
|
||||
{
|
||||
vit++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ok)
|
||||
{
|
||||
updatePublicRequestStatus(gp->pubToken, RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE);
|
||||
}
|
||||
else
|
||||
{
|
||||
updatePublicRequestStatus(gp->pubToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
|
||||
}
|
||||
|
||||
vit = mCompletionPostRanks.erase(vit);
|
||||
delete gp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -617,25 +667,27 @@ bool PostedBestScoreComp(const PostedScore& i, const PostedScore& j)
|
||||
return i_score < j_score;
|
||||
}
|
||||
|
||||
void p3Posted::completePostedPostCalc(GxsPostedPostRanking *gpp)
|
||||
bool p3Posted::completePostedPostCalc(GxsPostedPostRanking *gpp)
|
||||
{
|
||||
GxsMsgMetaMap msgMetas;
|
||||
|
||||
if(getMsgMeta(gpp->reqToken, msgMetas))
|
||||
{
|
||||
std::vector<RsMsgMetaData> msgMetaV = msgMetas[gpp->grpId];
|
||||
std::vector<RsMsgMetaData>& msgMetaV = msgMetas[gpp->grpId];
|
||||
switch(gpp->rType)
|
||||
{
|
||||
case NewRankType:
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult, PostedNewScoreComp);
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedNewScoreComp);
|
||||
break;
|
||||
case TopRankType:
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult, PostedTopScoreComp);
|
||||
calcPostedPostRank(msgMetaV, gpp->rankingResult.ranking, PostedTopScoreComp);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Unknown ranking tpye: " << gpp->rType << std::endl;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -667,7 +719,7 @@ void p3Posted::calcPostedPostRank(const std::vector<RsMsgMetaData > msgMeta, Pos
|
||||
for(; vit != scores.end(); vit++)
|
||||
{
|
||||
const PostedScore& p = *vit;
|
||||
ranking.insert(std::make_pair(p.msgId, i++));
|
||||
ranking.insert(std::make_pair(i++, p.msgId));
|
||||
}
|
||||
}
|
||||
|
||||
@ -713,7 +765,7 @@ void p3Posted::calcPostedCommentsRank(const std::map<RsGxsMessageId, std::vector
|
||||
for(; cvit != scores.end(); cvit)
|
||||
{
|
||||
const PostedScore& p = *cvit;
|
||||
ranking.insert(std::make_pair(p.msgId, i++));
|
||||
ranking.insert(std::make_pair(i++, p.msgId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
uint32_t reqToken;
|
||||
RsPosted::RankType rType;
|
||||
RsGxsGroupId grpId;
|
||||
PostedRanking rankingResult;
|
||||
RsPostedPostRanking rankingResult;
|
||||
};
|
||||
|
||||
class GxsPostedCommentRanking
|
||||
@ -82,14 +82,14 @@ 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 getRanking(const uint32_t &token, PostedRanking &ranking);
|
||||
bool getPostRanking(const uint32_t &token, RsPostedPostRanking &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 requestMessageRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
||||
bool requestPostRankings(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;
|
||||
@ -99,10 +99,10 @@ private:
|
||||
/* Functions for processing rankings */
|
||||
|
||||
void processRankings();
|
||||
void processMessageRanks();
|
||||
void processPostRanks();
|
||||
void processCommentRanks();
|
||||
void discardCalc(const uint32_t& token);
|
||||
void completePostedPostCalc(GxsPostedPostRanking* gpp);
|
||||
bool completePostedPostCalc(GxsPostedPostRanking* gpp);
|
||||
void completePostedCommentRanking(GxsPostedCommentRanking* gpc);
|
||||
|
||||
bool storeScores(std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
|
||||
@ -142,8 +142,9 @@ private:
|
||||
private:
|
||||
|
||||
// for calculating ranks
|
||||
std::map<uint32_t, GxsPostedPostRanking*> mPendingPostRanks;
|
||||
std::map<uint32_t, GxsPostedPostRanking*> mPendingCalculationPostRanks;
|
||||
std::vector<GxsPostedPostRanking*> mPendingPostRanks;
|
||||
std::vector<GxsPostedPostRanking*> mCompletionPostRanks;
|
||||
std::map<uint32_t, RsPostedPostRanking> mCompletePostRanks;
|
||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCommentRanks;
|
||||
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
|
||||
|
||||
|
@ -80,6 +80,8 @@ PostedListDialog::PostedListDialog(CommentHolder *commentHolder, QWidget *parent
|
||||
|
||||
connect( ui.groupTreeWidget, SIGNAL( treeCurrentItemChanged(QString) ), this, SLOT( changedTopic(QString) ) );
|
||||
|
||||
connect(ui.hotSortButton, SIGNAL(clicked()), this, SLOT(getHotRankings()));
|
||||
|
||||
/* create posted tree */
|
||||
yourTopics = ui.groupTreeWidget->addCategoryItem(tr("Your Topics"), QIcon(IMAGE_FOLDER), true);
|
||||
subscribedTopics = ui.groupTreeWidget->addCategoryItem(tr("Subscribed Topics"), QIcon(IMAGE_FOLDERRED), true);
|
||||
@ -93,6 +95,60 @@ PostedListDialog::PostedListDialog(CommentHolder *commentHolder, QWidget *parent
|
||||
connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(refreshTopics()));
|
||||
}
|
||||
|
||||
void PostedListDialog::getHotRankings()
|
||||
{
|
||||
|
||||
if(mCurrTopicId.empty())
|
||||
return;
|
||||
|
||||
std::cerr << "PostedListDialog::getHotRankings()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||
uint32_t token;
|
||||
rsPosted->requestPostRankings(token, RsPosted::BestRankType, mCurrTopicId);
|
||||
mPostedQueue->queueRequest(token, TOKENREQ_GROUPINFO, RS_TOKREQ_ANSTYPE_DATA, TOKEN_USER_TYPE_POST_RANKINGS);
|
||||
}
|
||||
|
||||
void PostedListDialog::loadRankings(const uint32_t &token)
|
||||
{
|
||||
|
||||
RsPostedPostRanking rankings;
|
||||
|
||||
if(!rsPosted->getPostRanking(token, rankings))
|
||||
return;
|
||||
|
||||
if(rankings.grpId != mCurrTopicId)
|
||||
return;
|
||||
|
||||
applyRanking(rankings.ranking);
|
||||
}
|
||||
|
||||
void PostedListDialog::applyRanking(const PostedRanking& ranks)
|
||||
{
|
||||
std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
shallowClearPosts();
|
||||
|
||||
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
|
||||
|
||||
PostedRanking::const_iterator mit = ranks.begin();
|
||||
|
||||
for(; mit != ranks.end(); mit++)
|
||||
{
|
||||
const RsGxsMessageId& msgId = mit->second;
|
||||
|
||||
if(mPosts.find(msgId) != mPosts.end())
|
||||
alayout->addWidget(mPosts[msgId]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PostedListDialog::refreshTopics()
|
||||
{
|
||||
std::cerr << "PostedListDialog::requestGroupSummary()";
|
||||
@ -468,6 +524,48 @@ void PostedListDialog::clearPosts()
|
||||
mPosts.clear();
|
||||
}
|
||||
|
||||
void PostedListDialog::shallowClearPosts()
|
||||
{
|
||||
std::cerr << "PostedListDialog::clearPosts()" << std::endl;
|
||||
|
||||
std::list<PostedItem *> postedItems;
|
||||
std::list<PostedItem *>::iterator pit;
|
||||
|
||||
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
|
||||
int count = alayout->count();
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
QLayoutItem *litem = alayout->itemAt(i);
|
||||
if (!litem)
|
||||
{
|
||||
std::cerr << "PostedListDialog::clearPosts() missing litem";
|
||||
std::cerr << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
PostedItem *item = dynamic_cast<PostedItem *>(litem->widget());
|
||||
if (item)
|
||||
{
|
||||
std::cerr << "PostedListDialog::clearPosts() item: " << item;
|
||||
std::cerr << std::endl;
|
||||
|
||||
postedItems.push_back(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "PostedListDialog::clearPosts() Found Child, which is not a PostedItem???";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
for(pit = postedItems.begin(); pit != postedItems.end(); pit++)
|
||||
{
|
||||
PostedItem *item = *pit;
|
||||
alayout->removeWidget(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PostedListDialog::updateCurrentDisplayComplete(const uint32_t &token)
|
||||
{
|
||||
std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads()";
|
||||
@ -558,6 +656,17 @@ void PostedListDialog::loadRequest(const TokenQueue *queue, const TokenRequest &
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TOKEN_USER_TYPE_POST_RANKINGS:
|
||||
switch(req.mAnsType)
|
||||
{
|
||||
case RS_TOKREQ_ANSTYPE_DATA:
|
||||
loadRankings(req.mToken);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
std::cerr << "PostedListDialog::loadRequest() ERROR: INVALID TYPE";
|
||||
std::cerr << std::endl;
|
||||
|
@ -74,10 +74,17 @@ private slots:
|
||||
|
||||
void submitVote(const RsGxsGrpMsgIdPair& msgId, bool up);
|
||||
|
||||
void getHotRankings();
|
||||
|
||||
private:
|
||||
|
||||
void clearPosts();
|
||||
|
||||
/*!
|
||||
* Only removes it from layout
|
||||
*/
|
||||
void shallowClearPosts();
|
||||
|
||||
void updateDisplay();
|
||||
void loadPost(const RsPostedPost &post);
|
||||
|
||||
@ -103,6 +110,11 @@ private:
|
||||
void acknowledgeVoteMsg(const uint32_t& token);
|
||||
void loadVoteData(const uint32_t &token);
|
||||
|
||||
// ranking
|
||||
|
||||
void loadRankings(const uint32_t& token);
|
||||
void applyRanking(const PostedRanking& ranks);
|
||||
|
||||
|
||||
// update displayed item
|
||||
|
||||
|
@ -5,5 +5,6 @@
|
||||
#define TOKEN_USER_TYPE_VOTE 5
|
||||
#define TOKEN_USER_TYPE_TOPIC 6
|
||||
#define TOKEN_USER_TYPE_POST_MOD 7
|
||||
#define TOKEN_USER_TYPE_POST_RANKINGS 8
|
||||
|
||||
#endif // POSTEDUSERTYPES_H
|
||||
|
@ -98,9 +98,9 @@ void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t ansty
|
||||
gettimeofday(&req.mRequestTs, NULL);
|
||||
req.mPollTs = req.mRequestTs;
|
||||
|
||||
mTokenMtx.lock();
|
||||
|
||||
mRequests.push_back(req);
|
||||
mTokenMtx.unlock();
|
||||
|
||||
|
||||
if (mRequests.size() == 1)
|
||||
{
|
||||
@ -126,10 +126,10 @@ void TokenQueue::pollRequests()
|
||||
|
||||
TokenRequest req;
|
||||
|
||||
mTokenMtx.lock();
|
||||
|
||||
req = mRequests.front();
|
||||
mRequests.pop_front();
|
||||
mTokenMtx.unlock();
|
||||
|
||||
|
||||
if (checkForRequest(req.mToken))
|
||||
{
|
||||
@ -144,9 +144,9 @@ void TokenQueue::pollRequests()
|
||||
/* drop old requests too */
|
||||
if (time(NULL) - req.mRequestTs.tv_sec < MAX_REQUEST_AGE)
|
||||
{
|
||||
mTokenMtx.lock();
|
||||
|
||||
mRequests.push_back(req);
|
||||
mTokenMtx.unlock();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -170,9 +170,9 @@ bool TokenQueue::checkForRequest(uint32_t token)
|
||||
(RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE == status) );
|
||||
}
|
||||
|
||||
bool TokenQueue::activeRequestExist(const uint32_t& userType)
|
||||
bool TokenQueue::activeRequestExist(const uint32_t& userType) const
|
||||
{
|
||||
mTokenMtx.lock();
|
||||
|
||||
|
||||
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
||||
|
||||
@ -182,19 +182,19 @@ bool TokenQueue::activeRequestExist(const uint32_t& userType)
|
||||
|
||||
if(req.mUserType == userType)
|
||||
{
|
||||
mTokenMtx.unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
mTokenMtx.unlock();
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens)
|
||||
void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens) const
|
||||
{
|
||||
mTokenMtx.lock();
|
||||
|
||||
|
||||
std::list<TokenRequest>::const_iterator lit = mRequests.begin();
|
||||
|
||||
@ -206,7 +206,7 @@ void TokenQueue::activeRequestTokens(const uint32_t& userType, std::list<uint32_
|
||||
tokens.push_back(req.mToken);
|
||||
}
|
||||
|
||||
mTokenMtx.unlock();
|
||||
|
||||
}
|
||||
|
||||
void TokenQueue::loadRequest(const TokenRequest &req)
|
||||
@ -226,7 +226,7 @@ bool TokenQueue::cancelRequest(const uint32_t token)
|
||||
|
||||
std::list<TokenRequest>::iterator it;
|
||||
|
||||
mTokenMtx.lock();
|
||||
|
||||
for(it = mRequests.begin(); it != mRequests.end(); it++)
|
||||
{
|
||||
if (it->mToken == token)
|
||||
@ -236,12 +236,12 @@ bool TokenQueue::cancelRequest(const uint32_t token)
|
||||
std::cerr << "TokenQueue::cancelRequest() Cleared Request: " << token;
|
||||
std::cerr << std::endl;
|
||||
|
||||
mTokenMtx.unlock();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
mTokenMtx.unlock();
|
||||
|
||||
|
||||
std::cerr << "TokenQueue::cancelRequest() Failed to Find Request: " << token;
|
||||
std::cerr << std::endl;
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QMutex>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <sys/time.h>
|
||||
@ -100,8 +99,8 @@ public:
|
||||
bool checkForRequest(uint32_t token);
|
||||
void loadRequest(const TokenRequest &req);
|
||||
|
||||
bool activeRequestExist(const uint32_t& userType);
|
||||
void activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens);
|
||||
bool activeRequestExist(const uint32_t& userType) const;
|
||||
void activeRequestTokens(const uint32_t& userType, std::list<uint32_t>& tokens) const;
|
||||
|
||||
protected:
|
||||
void doPoll(float dt);
|
||||
@ -115,7 +114,6 @@ private:
|
||||
|
||||
RsTokenService *mService;
|
||||
TokenResponse *mResponder;
|
||||
QMutex mTokenMtx;
|
||||
|
||||
QTimer *mTrigger;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user