2012-07-01 19:05:03 -04:00
|
|
|
/*
|
|
|
|
* Retroshare Posted List
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PostedListDialog.h"
|
|
|
|
|
2012-10-29 18:41:41 -04:00
|
|
|
#include "gui/Posted/PostedGroupDialog.h"
|
2012-11-07 18:24:23 -05:00
|
|
|
#include "gui/Posted/PostedCreatePostDialog.h"
|
2012-11-22 17:40:31 -05:00
|
|
|
#include "gui/Posted/PostedDialog.h"
|
2012-07-30 19:55:21 -04:00
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
#include <retroshare/rsposted.h>
|
2012-10-29 18:41:41 -04:00
|
|
|
#include <gxs/rsgxsflags.h>
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
//#define DEBUG_FORUMS
|
|
|
|
|
|
|
|
/* Images for context menu icons */
|
|
|
|
#define IMAGE_MESSAGE ":/images/folder-draft.png"
|
|
|
|
#define IMAGE_MESSAGEREPLY ":/images/mail_reply.png"
|
|
|
|
#define IMAGE_MESSAGEREMOVE ":/images/mail_delete.png"
|
|
|
|
#define IMAGE_DOWNLOAD ":/images/start.png"
|
|
|
|
#define IMAGE_DOWNLOADALL ":/images/startall.png"
|
|
|
|
|
|
|
|
/* Images for TreeWidget */
|
|
|
|
#define IMAGE_FOLDER ":/images/folder16.png"
|
|
|
|
#define IMAGE_FOLDERGREEN ":/images/folder_green.png"
|
|
|
|
#define IMAGE_FOLDERRED ":/images/folder_red.png"
|
|
|
|
#define IMAGE_FOLDERYELLOW ":/images/folder_yellow.png"
|
|
|
|
#define IMAGE_FORUM ":/images/konversation16.png"
|
|
|
|
#define IMAGE_SUBSCRIBE ":/images/edit_add24.png"
|
|
|
|
#define IMAGE_UNSUBSCRIBE ":/images/cancel.png"
|
|
|
|
#define IMAGE_INFO ":/images/info16.png"
|
|
|
|
#define IMAGE_NEWFORUM ":/images/new_forum16.png"
|
|
|
|
#define IMAGE_FORUMAUTHD ":/images/konv_message2.png"
|
|
|
|
#define IMAGE_COPYLINK ":/images/copyrslink.png"
|
|
|
|
|
2012-12-05 17:45:44 -05:00
|
|
|
// token types to deal with
|
|
|
|
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
/** Constructor */
|
2012-11-22 17:40:31 -05:00
|
|
|
PostedListDialog::PostedListDialog(CommentHolder *commentHolder, QWidget *parent)
|
|
|
|
: RsAutoUpdatePage(1000,parent), mCommentHolder(commentHolder)
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
/* Setup Queue */
|
|
|
|
mPostedQueue = new TokenQueue(rsPosted->getTokenService(), this);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
connect( ui.groupTreeWidget, SIGNAL( treeCustomContextMenuRequested( QPoint ) ), this, SLOT( groupListCustomPopupMenu( QPoint ) ) );
|
|
|
|
|
|
|
|
connect( ui.groupTreeWidget, SIGNAL( treeCurrentItemChanged(QString) ), this, SLOT( changedTopic(QString) ) );
|
|
|
|
|
2012-12-15 19:43:15 -05:00
|
|
|
connect(ui.hotSortButton, SIGNAL(clicked()), this, SLOT(getRankings()));
|
|
|
|
connect(ui.newSortButton, SIGNAL(clicked()), this, SLOT(getRankings()));
|
|
|
|
connect(ui.topSortButton, SIGNAL(clicked()), this, SLOT(getRankings()));
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
/* create posted tree */
|
2012-11-28 14:58:14 -05:00
|
|
|
yourTopics = ui.groupTreeWidget->addCategoryItem(tr("My Topics"), QIcon(IMAGE_FOLDER), true);
|
2012-07-01 19:05:03 -04:00
|
|
|
subscribedTopics = ui.groupTreeWidget->addCategoryItem(tr("Subscribed Topics"), QIcon(IMAGE_FOLDERRED), true);
|
|
|
|
popularTopics = ui.groupTreeWidget->addCategoryItem(tr("Popular Topics"), QIcon(IMAGE_FOLDERGREEN), false);
|
|
|
|
otherTopics = ui.groupTreeWidget->addCategoryItem(tr("Other Topics"), QIcon(IMAGE_FOLDERYELLOW), false);
|
|
|
|
|
2012-07-30 19:55:21 -04:00
|
|
|
ui.hotSortButton->setChecked(true);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
connect( ui.newTopicButton, SIGNAL( clicked() ), this, SLOT( newTopic() ) );
|
2012-12-05 17:45:44 -05:00
|
|
|
connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(refreshTopics()));
|
2012-12-15 19:43:15 -05:00
|
|
|
connect(ui.submitPostButton, SIGNAL(clicked()), this, SLOT(newPost()));
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2012-12-15 19:43:15 -05:00
|
|
|
void PostedListDialog::getRankings()
|
2012-12-11 17:26:11 -05:00
|
|
|
{
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
if(mCurrTopicId.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::cerr << "PostedListDialog::getHotRankings()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
|
|
|
uint32_t token;
|
2012-12-15 19:43:15 -05:00
|
|
|
|
|
|
|
QObject* button = sender();
|
|
|
|
if(button == ui.hotSortButton)
|
|
|
|
{
|
|
|
|
rsPosted->requestPostRankings(token, RsPosted::HotRankType, mCurrTopicId);
|
|
|
|
}else if(button == ui.topSortButton)
|
|
|
|
{
|
|
|
|
rsPosted->requestPostRankings(token, RsPosted::TopRankType, mCurrTopicId);
|
|
|
|
}else if(button == ui.newSortButton)
|
|
|
|
{
|
|
|
|
rsPosted->requestPostRankings(token, RsPosted::NewRankType, mCurrTopicId);
|
|
|
|
}else{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
mPostedQueue->queueRequest(token, TOKENREQ_GROUPINFO, RS_TOKREQ_ANSTYPE_DATA, TOKEN_USER_TYPE_POST_RANKINGS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::loadRankings(const uint32_t &token)
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
RsPostedPostRanking rankings;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
if(!rsPosted->getPostRanking(token, rankings))
|
|
|
|
return;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
if(rankings.grpId != mCurrTopicId)
|
|
|
|
return;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
applyRanking(rankings.ranking);
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
void PostedListDialog::applyRanking(const PostedRanking& ranks)
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads()";
|
|
|
|
std::cerr << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
shallowClearPosts();
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
PostedRanking::const_iterator mit = ranks.begin();
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
for(; mit != ranks.end(); mit++)
|
|
|
|
{
|
|
|
|
const RsGxsMessageId& msgId = mit->second;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
if(mPosts.find(msgId) != mPosts.end())
|
|
|
|
alayout->addWidget(mPosts[msgId]);
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
return;
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
|
2012-12-05 17:45:44 -05:00
|
|
|
void PostedListDialog::refreshTopics()
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::requestGroupSummary()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
|
|
|
uint32_t token;
|
|
|
|
mPostedQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_USER_TYPE_TOPIC);
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
void PostedListDialog::groupListCustomPopupMenu( QPoint /*point*/ )
|
|
|
|
{
|
|
|
|
QMenu contextMnu( this );
|
|
|
|
|
2012-11-22 17:40:31 -05:00
|
|
|
QAction *action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Submit Post"), this, SLOT(newPost()));
|
2012-11-07 18:24:23 -05:00
|
|
|
action->setDisabled (mCurrTopicId.empty());
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
contextMnu.exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
void PostedListDialog::newPost()
|
2012-11-07 18:24:23 -05:00
|
|
|
{
|
2012-12-15 19:43:15 -05:00
|
|
|
if(mCurrTopicId.empty())
|
|
|
|
return;
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
PostedCreatePostDialog cp(mPostedQueue, rsPosted, mCurrTopicId, this);
|
|
|
|
cp.exec();
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:45:44 -05:00
|
|
|
void PostedListDialog::submitVote(const RsGxsGrpMsgIdPair &msgId, bool up)
|
|
|
|
{
|
|
|
|
uint32_t token;
|
|
|
|
RsPostedVote vote;
|
|
|
|
|
|
|
|
vote.mMeta.mGroupId = msgId.first;
|
|
|
|
vote.mMeta.mParentId = msgId.second;
|
|
|
|
vote.mDirection = (uint8_t)up;
|
|
|
|
rsPosted->submitVote(token, vote);
|
|
|
|
|
|
|
|
mPostedQueue->queueRequest(token, 0 , RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_VOTE);
|
|
|
|
}
|
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
void PostedListDialog::showComments(const RsPostedPost& post)
|
2012-11-22 17:40:31 -05:00
|
|
|
{
|
2012-11-25 16:50:45 -05:00
|
|
|
mCommentHolder->commentLoad(post);
|
2012-11-22 17:40:31 -05:00
|
|
|
}
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
void PostedListDialog::updateDisplay()
|
|
|
|
{
|
|
|
|
if (!rsPosted)
|
|
|
|
return;
|
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
|
|
|
|
std::list<std::string> groupIds;
|
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
|
|
|
|
|
|
|
|
2013-02-07 18:04:16 -05:00
|
|
|
if (rsPosted->updated(true, true))
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
|
|
|
/* update Forums List */
|
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
rsPosted->groupsChanged(groupIds);
|
|
|
|
if(!groupIds.empty())
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
2012-12-09 17:38:49 -05:00
|
|
|
std::list<std::string>::iterator it = std::find(groupIds.begin(), groupIds.end(), mCurrTopicId);
|
|
|
|
|
|
|
|
if(it != groupIds.end()){
|
|
|
|
requestGroupSummary();
|
|
|
|
return;
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
2012-07-06 19:19:10 -04:00
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
rsPosted->msgsChanged(msgs);
|
|
|
|
|
|
|
|
if(!msgs.empty())
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit = msgs.find(mCurrTopicId);
|
|
|
|
if(mit != msgs.end())
|
|
|
|
{
|
|
|
|
updateDisplayedItems(mit->second);
|
|
|
|
}
|
|
|
|
}
|
2012-07-06 19:19:10 -04:00
|
|
|
}
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
void PostedListDialog::updateDisplayedItems(const std::vector<RsGxsMessageId> &msgIds)
|
|
|
|
{
|
|
|
|
|
|
|
|
RsTokReqOptions opts;
|
|
|
|
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
|
|
|
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
|
|
|
|
|
|
|
|
|
|
|
|
GxsMsgReq msgs;
|
|
|
|
msgs[mCurrTopicId] = msgIds;
|
|
|
|
|
|
|
|
std::cerr << "PostedListDialog::updateDisplayedItems(" << mCurrTopicId << ")";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
mPostedQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgs, TOKEN_USER_TYPE_POST_MOD);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
void PostedListDialog::changedTopic(const QString &id)
|
|
|
|
{
|
|
|
|
mCurrTopicId = id.toStdString();
|
|
|
|
insertThreads();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************** **** **** **** ***********************/
|
2012-07-30 19:55:21 -04:00
|
|
|
/** New / Edit Groups ********************************/
|
2012-07-01 19:05:03 -04:00
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
void PostedListDialog::newTopic()
|
2012-07-30 19:55:21 -04:00
|
|
|
{
|
2012-11-07 18:24:23 -05:00
|
|
|
PostedGroupDialog cf (mPostedQueue, rsPosted, this);
|
2012-07-30 19:55:21 -04:00
|
|
|
cf.exec ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::showGroupDetails()
|
|
|
|
{
|
|
|
|
if (mCurrTopicId.empty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-28 17:27:19 -05:00
|
|
|
PostedGroupDialog cf(mGroups[mCurrTopicId], GxsGroupDialog::MODE_SHOW, this);
|
2012-07-30 19:55:21 -04:00
|
|
|
cf.exec ();
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::insertGroups()
|
|
|
|
{
|
|
|
|
requestGroupSummary();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::requestGroupSummary()
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::requestGroupSummary()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
RsTokReqOptions opts;
|
2012-12-05 17:45:44 -05:00
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
2012-07-01 19:05:03 -04:00
|
|
|
uint32_t token;
|
2012-12-05 17:45:44 -05:00
|
|
|
mPostedQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_USER_TYPE_TOPIC);
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2012-10-29 18:41:41 -04:00
|
|
|
void PostedListDialog::acknowledgeGroup(const uint32_t &token)
|
|
|
|
{
|
|
|
|
RsGxsGroupId grpId;
|
|
|
|
rsPosted->acknowledgeGrp(token, grpId);
|
|
|
|
|
|
|
|
if(!grpId.empty())
|
|
|
|
{
|
|
|
|
|
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
|
|
|
uint32_t reqToken;
|
2012-12-05 17:45:44 -05:00
|
|
|
mPostedQueue->requestGroupInfo(reqToken, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_USER_TYPE_TOPIC);
|
2012-10-29 18:41:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:45:44 -05:00
|
|
|
void PostedListDialog::acknowledgePostMsg(const uint32_t &token)
|
2012-11-17 16:43:21 -05:00
|
|
|
{
|
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
|
|
|
|
// just acknowledge, don't load anything
|
|
|
|
rsPosted->acknowledgeMsg(token, msgId);
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::loadGroupSummary(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadGroupSummary()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
std::list<RsGroupMetaData> groupInfo;
|
|
|
|
rsPosted->getGroupSummary(token, groupInfo);
|
|
|
|
|
|
|
|
if (groupInfo.size() > 0)
|
|
|
|
{
|
|
|
|
insertGroupData(groupInfo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadGroupSummary() ERROR No Groups...";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
void PostedListDialog::loadPostData(const uint32_t &token)
|
|
|
|
{
|
|
|
|
loadGroupThreadData_InsertThreads(token);
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:45:44 -05:00
|
|
|
void PostedListDialog::acknowledgeVoteMsg(const uint32_t &token)
|
|
|
|
{
|
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
|
|
|
|
rsPosted->acknowledgeMsg(token, msgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::loadVoteData(const uint32_t &token)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::requestGroupSummary_CurrentForum(const std::string &forumId)
|
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
RsTokReqOptions opts;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
std::list<std::string> grpIds;
|
|
|
|
grpIds.push_back(forumId);
|
|
|
|
|
|
|
|
std::cerr << "PostedListDialog::requestGroupSummary_CurrentForum(" << forumId << ")";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
mPostedQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, POSTEDDIALOG_CURRENTFORUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::loadGroupSummary_CurrentForum(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadGroupSummary_CurrentForum()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
std::list<RsGroupMetaData> groupInfo;
|
|
|
|
rsPosted->getGroupSummary(token, groupInfo);
|
|
|
|
|
|
|
|
if (groupInfo.size() == 1)
|
|
|
|
{
|
|
|
|
RsGroupMetaData fi = groupInfo.front();
|
|
|
|
//insertForumThreads(fi);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadGroupSummary_CurrentForum() ERROR Invalid Number of Groups...";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::insertThreads()
|
|
|
|
{
|
2012-11-17 16:43:21 -05:00
|
|
|
loadCurrentTopicThreads(mCurrTopicId);
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
void PostedListDialog::loadCurrentTopicThreads(const std::string &topicId)
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
std::cerr << "PostedListDialog::loadCurrentForumThreads(" << topicId << ")";
|
2012-07-01 19:05:03 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
if (topicId.empty())
|
2012-07-07 21:31:23 -04:00
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadCurrentForumThreads() Empty GroupId .. ignoring Req";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
2012-11-17 16:43:21 -05:00
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
clearPosts();
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
/* initiate loading */
|
|
|
|
requestGroupThreadData_InsertThreads(topicId);
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-07 21:31:23 -04:00
|
|
|
void PostedListDialog::requestGroupThreadData_InsertThreads(const std::string &groupId)
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
RsTokReqOptions opts;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
|
|
|
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
std::list<RsGxsGroupId> grpIds;
|
2012-07-07 21:31:23 -04:00
|
|
|
grpIds.push_back(groupId);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-07-07 21:31:23 -04:00
|
|
|
std::cerr << "PostedListDialog::requestGroupThreadData_InsertThreads(" << groupId << ")";
|
2012-07-01 19:05:03 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
uint32_t token;
|
2012-12-05 17:45:44 -05:00
|
|
|
mPostedQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grpIds, TOKEN_USER_TYPE_POST);
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::loadGroupThreadData_InsertThreads(const uint32_t &token)
|
|
|
|
{
|
2012-11-17 16:43:21 -05:00
|
|
|
std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads()";
|
|
|
|
std::cerr << std::endl;
|
2012-07-07 21:31:23 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
clearPosts();
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
PostedPostResult result;
|
|
|
|
rsPosted->getPost(token, result);
|
|
|
|
std::vector<RsPostedPost>& posts = result[mCurrTopicId];
|
|
|
|
std::vector<RsPostedPost>::iterator vit = posts.begin();
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
for(; vit != posts.end(); vit++)
|
|
|
|
{
|
2012-12-09 17:38:49 -05:00
|
|
|
RsPostedPost& p = *vit;
|
|
|
|
loadPost(p);
|
2012-11-17 16:43:21 -05:00
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::loadPost(const RsPostedPost &post)
|
|
|
|
{
|
2012-11-17 16:43:21 -05:00
|
|
|
PostedItem *item = new PostedItem(this, post);
|
2012-12-05 17:45:44 -05:00
|
|
|
connect(item, SIGNAL(vote(RsGxsGrpMsgIdPair,bool)), this, SLOT(submitVote(RsGxsGrpMsgIdPair,bool)));
|
2012-11-17 16:43:21 -05:00
|
|
|
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
|
2012-12-09 17:38:49 -05:00
|
|
|
mPosts.insert(post.mMeta.mMsgId, item);
|
2012-11-17 16:43:21 -05:00
|
|
|
alayout->addWidget(item);
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::clearPosts()
|
|
|
|
{
|
2012-11-17 16:43:21 -05:00
|
|
|
std::cerr << "PostedListDialog::clearPosts()" << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
std::list<PostedItem *> postedItems;
|
|
|
|
std::list<PostedItem *>::iterator pit;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
for(pit = postedItems.begin(); pit != postedItems.end(); pit++)
|
|
|
|
{
|
|
|
|
PostedItem *item = *pit;
|
|
|
|
alayout->removeWidget(item);
|
|
|
|
delete item;
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
mPosts.clear();
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2012-12-11 17:26:11 -05:00
|
|
|
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);
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
void PostedListDialog::updateCurrentDisplayComplete(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
PostedPostResult result;
|
|
|
|
rsPosted->getPost(token, result);
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
if(result.find(mCurrTopicId) == result.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<RsPostedPost>& posts = result[mCurrTopicId];
|
|
|
|
std::vector<RsPostedPost>::iterator vit = posts.begin();
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
for(; vit != posts.end(); vit++)
|
|
|
|
{
|
|
|
|
|
|
|
|
RsPostedPost& p = *vit;
|
|
|
|
|
|
|
|
// modify post content
|
|
|
|
if(mPosts.find(p.mMeta.mMsgId) != mPosts.end())
|
|
|
|
mPosts[p.mMeta.mMsgId]->setContent(p);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
|
|
|
|
void PostedListDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req)
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadRequest() UserType: " << req.mUserType;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
if (queue == mPostedQueue)
|
2012-12-05 17:45:44 -05:00
|
|
|
{
|
2012-07-01 19:05:03 -04:00
|
|
|
/* now switch on req */
|
2012-12-05 17:45:44 -05:00
|
|
|
switch(req.mUserType)
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
2012-12-05 17:45:44 -05:00
|
|
|
|
|
|
|
case TOKEN_USER_TYPE_TOPIC:
|
2012-10-29 18:41:41 -04:00
|
|
|
switch(req.mAnsType)
|
|
|
|
{
|
|
|
|
case RS_TOKREQ_ANSTYPE_SUMMARY:
|
|
|
|
loadGroupSummary(req.mToken);
|
2012-11-25 16:50:45 -05:00
|
|
|
break;
|
2012-10-29 18:41:41 -04:00
|
|
|
default:
|
|
|
|
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2012-12-05 17:45:44 -05:00
|
|
|
case TOKEN_USER_TYPE_POST:
|
2012-11-17 16:43:21 -05:00
|
|
|
switch(req.mAnsType)
|
|
|
|
{
|
|
|
|
case RS_TOKREQ_ANSTYPE_ACK:
|
2012-12-05 17:45:44 -05:00
|
|
|
acknowledgePostMsg(req.mToken);
|
2012-11-17 16:43:21 -05:00
|
|
|
break;
|
|
|
|
case RS_TOKREQ_ANSTYPE_DATA:
|
|
|
|
loadPostData(req.mToken);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-05 17:45:44 -05:00
|
|
|
break;
|
|
|
|
case TOKEN_USER_TYPE_VOTE:
|
|
|
|
switch(req.mAnsType)
|
|
|
|
{
|
|
|
|
case RS_TOKREQ_ANSTYPE_ACK:
|
|
|
|
acknowledgeVoteMsg(req.mToken);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2012-12-09 17:38:49 -05:00
|
|
|
case TOKEN_USER_TYPE_POST_MOD:
|
|
|
|
switch(req.mAnsType)
|
|
|
|
{
|
|
|
|
case RS_TOKREQ_ANSTYPE_DATA:
|
|
|
|
updateCurrentDisplayComplete(req.mToken);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2012-12-11 17:26:11 -05:00
|
|
|
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;
|
2012-10-29 18:41:41 -04:00
|
|
|
default:
|
|
|
|
std::cerr << "PostedListDialog::loadRequest() ERROR: INVALID TYPE";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
}
|
2012-12-05 17:45:44 -05:00
|
|
|
|
|
|
|
/* now switch on req */
|
|
|
|
switch(req.mType)
|
|
|
|
{
|
|
|
|
case TOKENREQ_GROUPINFO:
|
|
|
|
switch(req.mAnsType)
|
|
|
|
{
|
|
|
|
case RS_TOKREQ_ANSTYPE_ACK:
|
|
|
|
acknowledgeGroup(req.mToken);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************** Groups **********************/
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo)
|
|
|
|
{
|
|
|
|
groupItemInfo.id = QString::fromStdString(groupInfo.mGroupId);
|
|
|
|
groupItemInfo.name = QString::fromUtf8(groupInfo.mGroupName.c_str());
|
|
|
|
//groupItemInfo.description = QString::fromUtf8(groupInfo.forumDesc);
|
|
|
|
groupItemInfo.popularity = groupInfo.mPop;
|
|
|
|
groupItemInfo.lastpost = QDateTime::fromTime_t(groupInfo.mLastPost);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::insertGroupData(const std::list<RsGroupMetaData> &groupList)
|
|
|
|
{
|
|
|
|
|
2012-10-29 18:41:41 -04:00
|
|
|
std::list<RsGroupMetaData>::const_iterator it;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
QList<GroupItemInfo> adminList;
|
|
|
|
QList<GroupItemInfo> subList;
|
|
|
|
QList<GroupItemInfo> popList;
|
|
|
|
QList<GroupItemInfo> otherList;
|
|
|
|
std::multimap<uint32_t, GroupItemInfo> popMap;
|
|
|
|
|
|
|
|
for (it = groupList.begin(); it != groupList.end(); it++) {
|
2012-10-29 18:41:41 -04:00
|
|
|
/* sort it into Publish (Own), Subscribed, Popular and Other */
|
|
|
|
uint32_t flags = it->mSubscribeFlags;
|
|
|
|
|
|
|
|
GroupItemInfo groupItemInfo;
|
|
|
|
groupInfoToGroupItemInfo(*it, groupItemInfo);
|
|
|
|
|
|
|
|
// if (flags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) {
|
|
|
|
adminList.push_back(groupItemInfo);
|
|
|
|
// } else if (flags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED) {
|
|
|
|
/* subscribed forum */
|
|
|
|
// subList.push_back(groupItemInfo);
|
|
|
|
// } else {
|
|
|
|
/* rate the others by popularity */
|
|
|
|
// popMap.insert(std::make_pair(it->mPop, groupItemInfo));
|
|
|
|
}
|
|
|
|
// }
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-10-29 18:41:41 -04:00
|
|
|
/* iterate backwards through popMap - take the top 5 or 10% of list */
|
|
|
|
uint32_t popCount = 5;
|
|
|
|
if (popCount < popMap.size() / 10)
|
|
|
|
{
|
|
|
|
popCount = popMap.size() / 10;
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-10-29 18:41:41 -04:00
|
|
|
uint32_t i = 0;
|
|
|
|
uint32_t popLimit = 0;
|
2012-07-01 19:05:03 -04:00
|
|
|
std::multimap<uint32_t, GroupItemInfo>::reverse_iterator rit;
|
2012-10-29 18:41:41 -04:00
|
|
|
for(rit = popMap.rbegin(); ((rit != popMap.rend()) && (i < popCount)); rit++, i++) ;
|
2012-07-01 19:05:03 -04:00
|
|
|
if (rit != popMap.rend()) {
|
2012-10-29 18:41:41 -04:00
|
|
|
popLimit = rit->first;
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (rit = popMap.rbegin(); rit != popMap.rend(); rit++) {
|
2012-10-29 18:41:41 -04:00
|
|
|
if (rit->second.popularity < (int) popLimit) {
|
|
|
|
otherList.append(rit->second);
|
|
|
|
} else {
|
|
|
|
popList.append(rit->second);
|
|
|
|
}
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-10-29 18:41:41 -04:00
|
|
|
/* now we can add them in as a tree! */
|
2012-07-01 19:05:03 -04:00
|
|
|
ui.groupTreeWidget->fillGroupItems(yourTopics, adminList);
|
|
|
|
ui.groupTreeWidget->fillGroupItems(subscribedTopics, subList);
|
|
|
|
ui.groupTreeWidget->fillGroupItems(popularTopics, popList);
|
|
|
|
ui.groupTreeWidget->fillGroupItems(otherTopics, otherList);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
|
|
|
|
|