mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-20 20:34:25 -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
13 changed files with 297 additions and 92 deletions
|
@ -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);
|
||||
|
@ -114,8 +113,7 @@ private:
|
|||
std::list<TokenRequest> mRequests;
|
||||
|
||||
RsTokenService *mService;
|
||||
TokenResponse *mResponder;
|
||||
QMutex mTokenMtx;
|
||||
TokenResponse *mResponder;
|
||||
|
||||
QTimer *mTrigger;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue