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>
|
2013-02-28 16:58:38 -05:00
|
|
|
#include <retroshare/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 */
|
2013-03-11 16:53:15 -04:00
|
|
|
#define IMAGE_MESSAGE ":/images/folder-draft.png"
|
2012-07-01 19:05:03 -04:00
|
|
|
#define IMAGE_MESSAGEREPLY ":/images/mail_reply.png"
|
|
|
|
#define IMAGE_MESSAGEREMOVE ":/images/mail_delete.png"
|
2013-03-11 16:53:15 -04:00
|
|
|
#define IMAGE_DOWNLOAD ":/images/start.png"
|
|
|
|
#define IMAGE_DOWNLOADALL ":/images/startall.png"
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
/* Images for TreeWidget */
|
2013-03-11 16:53:15 -04:00
|
|
|
#define IMAGE_FOLDER ":/images/folder16.png"
|
|
|
|
#define IMAGE_FOLDERGREEN ":/images/folder_green.png"
|
|
|
|
#define IMAGE_FOLDERRED ":/images/folder_red.png"
|
2012-07-01 19:05:03 -04:00
|
|
|
#define IMAGE_FOLDERYELLOW ":/images/folder_yellow.png"
|
2013-03-11 16:53:15 -04:00
|
|
|
#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-07-01 19:05:03 -04:00
|
|
|
|
2012-12-05 17:45:44 -05:00
|
|
|
// token types to deal with
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
#define POSTED_DEFAULT_LISTING_LENGTH 10
|
|
|
|
#define POSTED_MAX_INDEX 10000
|
2012-12-05 17:45:44 -05:00
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
/** Constructor */
|
2013-03-11 16:53:15 -04:00
|
|
|
PostedListDialog::PostedListDialog(QWidget *parent)
|
|
|
|
: RsAutoUpdatePage(1000,parent), GxsServiceDialog(dynamic_cast<GxsCommentContainer *>(parent))
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
/* Setup Queue */
|
|
|
|
mPostedQueue = new TokenQueue(rsPosted->getTokenService(), this);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
connect( ui.groupTreeWidget, SIGNAL( treeCustomContextMenuRequested( QPoint ) ), this, SLOT( groupListCustomPopupMenu( QPoint ) ) );
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
connect( ui.groupTreeWidget, SIGNAL( treeCurrentItemChanged(QString) ), this, SLOT( changedTopic(QString) ) );
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04: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()));
|
2013-06-04 17:00:43 -04:00
|
|
|
connect(ui.nextButton, SIGNAL(clicked()), this, SLOT(showNext()));
|
|
|
|
connect(ui.prevButton, SIGNAL(clicked()), this, SLOT(showPrev()));
|
|
|
|
|
|
|
|
// default sort method.
|
|
|
|
mSortMethod = RsPosted::HotRankType;
|
|
|
|
mLastSortMethod = RsPosted::TopRankType; // to be different.
|
|
|
|
mPostIndex = 0;
|
|
|
|
mPostShow = POSTED_DEFAULT_LISTING_LENGTH;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
/* create posted tree */
|
|
|
|
yourTopics = ui.groupTreeWidget->addCategoryItem(tr("My Topics"), QIcon(IMAGE_FOLDER), true);
|
|
|
|
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-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
ui.hotSortButton->setChecked(true);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
connect( ui.newTopicButton, SIGNAL( clicked() ), this, SLOT( newTopic() ) );
|
|
|
|
connect(ui.refreshButton, SIGNAL(clicked()), this, SLOT(refreshTopics()));
|
|
|
|
connect(ui.submitPostButton, SIGNAL(clicked()), this, SLOT(newPost()));
|
2013-03-24 12:29:08 -04:00
|
|
|
|
|
|
|
refreshTopics();
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
|
|
|
|
void PostedListDialog::showNext()
|
|
|
|
{
|
|
|
|
mPostIndex += mPostShow;
|
|
|
|
if (mPostIndex > POSTED_MAX_INDEX)
|
|
|
|
mPostIndex = POSTED_MAX_INDEX;
|
|
|
|
applyRanking();
|
|
|
|
updateShowText();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::showPrev()
|
|
|
|
{
|
|
|
|
mPostIndex -= mPostShow;
|
|
|
|
if (mPostIndex < 0)
|
|
|
|
mPostIndex = 0;
|
|
|
|
applyRanking();
|
|
|
|
updateShowText();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::updateShowText()
|
|
|
|
{
|
|
|
|
QString showText = tr("Showing");
|
|
|
|
showText += " ";
|
|
|
|
showText += QString::number(mPostIndex + 1);
|
|
|
|
showText += "-";
|
|
|
|
showText += QString::number(mPostIndex + mPostShow);
|
|
|
|
ui.showLabel->setText(showText);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-15 19:43:15 -05:00
|
|
|
void PostedListDialog::getRankings()
|
2012-12-11 17:26:11 -05:00
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
if(mCurrTopicId.empty())
|
|
|
|
return;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "PostedListDialog::getRankings()";
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << std::endl;
|
2012-12-11 17:26:11 -05:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
int oldSortMethod = mSortMethod;
|
2012-12-15 19:43:15 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
QObject* button = sender();
|
|
|
|
if(button == ui.hotSortButton)
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
mSortMethod = RsPosted::HotRankType;
|
|
|
|
}
|
|
|
|
else if(button == ui.topSortButton)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
mSortMethod = RsPosted::TopRankType;
|
|
|
|
}
|
|
|
|
else if(button == ui.newSortButton)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
mSortMethod = RsPosted::NewRankType;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2013-06-04 17:00:43 -04:00
|
|
|
else
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
return;
|
2013-06-04 17:00:43 -04:00
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
if (oldSortMethod != mSortMethod)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
/* Reset Counter */
|
|
|
|
mPostIndex = 0;
|
|
|
|
updateShowText();
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
applyRanking();
|
2012-12-11 17:26:11 -05:00
|
|
|
}
|
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()
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::requestGroupSummary()";
|
|
|
|
std::cerr << std::endl;
|
2012-12-05 17:45:44 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
|
|
|
uint32_t token;
|
|
|
|
mPostedQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_USER_TYPE_TOPIC);
|
2013-06-04 17:00:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* refresh Id Chooser Too */
|
|
|
|
RsGxsId currentId = "";
|
|
|
|
ui.idChooser->getChosenId(currentId);
|
|
|
|
ui.idChooser->loadIds(IDCHOOSER_ID_REQUIRED, currentId);
|
2012-12-05 17:45:44 -05:00
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
void PostedListDialog::groupListCustomPopupMenu( QPoint /*point*/ )
|
|
|
|
{
|
2013-03-24 12:29:08 -04:00
|
|
|
if (mCurrTopicId.empty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t subscribeFlags = ui.groupTreeWidget->subscribeFlags(QString::fromStdString(mCurrTopicId));
|
|
|
|
|
|
|
|
QMenu contextMnu(this);
|
|
|
|
|
|
|
|
//bool isAdmin = IS_GROUP_ADMIN(subscribeFlags);
|
|
|
|
//bool isPublisher = IS_GROUP_PUBLISHER(subscribeFlags);
|
|
|
|
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
QAction *action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Submit Post"), this, SLOT(newPost()));
|
2013-03-24 12:29:08 -04:00
|
|
|
action->setEnabled(isSubscribed);
|
|
|
|
action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Subscribe"), this, SLOT(subscribeTopic()));
|
|
|
|
action->setEnabled(!isSubscribed);
|
|
|
|
action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Unsubscribe"), this, SLOT(unsubscribeTopic()));
|
|
|
|
action->setEnabled(isSubscribed);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
contextMnu.exec(QCursor::pos());
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
void PostedListDialog::newPost()
|
2012-11-07 18:24:23 -05:00
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
if(mCurrTopicId.empty())
|
|
|
|
return;
|
2012-12-15 19:43:15 -05:00
|
|
|
|
2013-03-24 12:29:08 -04:00
|
|
|
uint32_t subscribeFlags = ui.groupTreeWidget->subscribeFlags(QString::fromStdString(mCurrTopicId));
|
|
|
|
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
|
|
|
|
|
|
|
|
if (isSubscribed)
|
|
|
|
{
|
|
|
|
PostedCreatePostDialog cp(mPostedQueue, rsPosted, mCurrTopicId, this);
|
|
|
|
cp.exec();
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2013-03-24 12:29:08 -04:00
|
|
|
|
|
|
|
void PostedListDialog::unsubscribeTopic()
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::unsubscribeTopic()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
if(mCurrTopicId.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
rsPosted->subscribeToGroup(token, mCurrTopicId, false);
|
|
|
|
mPostedQueue->queueRequest(token, 0 , RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_SUBSCRIBE_CHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::subscribeTopic()
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::subscribeTopic()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
if(mCurrTopicId.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
rsPosted->subscribeToGroup(token, mCurrTopicId, true);
|
|
|
|
mPostedQueue->queueRequest(token, 0 , RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_SUBSCRIBE_CHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
void PostedListDialog::submitVote(const RsGxsGrpMsgIdPair &msgId, bool up)
|
|
|
|
{
|
|
|
|
/* must grab AuthorId from Layout */
|
|
|
|
RsGxsId authorId;
|
|
|
|
if (!ui.idChooser->getChosenId(authorId))
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::createPost() ERROR GETTING AuthorId!, Vote Failed";
|
|
|
|
std::cerr << std::endl;
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
QMessageBox::warning(this, tr("RetroShare"),tr("Please create or choose a Signing Id before Voting"),
|
|
|
|
QMessageBox::Ok, QMessageBox::Ok);
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
RsGxsVote vote;
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
vote.mMeta.mGroupId = msgId.first;
|
|
|
|
vote.mMeta.mThreadId = msgId.second;
|
|
|
|
vote.mMeta.mParentId = msgId.second;
|
|
|
|
vote.mMeta.mAuthorId = authorId;
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
if (up)
|
|
|
|
{
|
|
|
|
vote.mVoteType = GXS_VOTE_UP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vote.mVoteType = GXS_VOTE_DOWN;
|
|
|
|
}
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "PostedListDialog::submitVote()";
|
|
|
|
std::cerr << std::endl;
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "GroupId : " << vote.mMeta.mGroupId << std::endl;
|
|
|
|
std::cerr << "ThreadId : " << vote.mMeta.mThreadId << std::endl;
|
|
|
|
std::cerr << "ParentId : " << vote.mMeta.mParentId << std::endl;
|
|
|
|
std::cerr << "AuthorId : " << vote.mMeta.mAuthorId << std::endl;
|
2013-03-24 12:29:08 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
uint32_t token;
|
2013-06-04 17:00:43 -04:00
|
|
|
rsPosted->createVote(token, vote);
|
|
|
|
mPostedQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_VOTE);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2012-12-05 17:45:44 -05:00
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
/*****************************************************************************************/
|
|
|
|
// Overloaded from FeedHolder.
|
|
|
|
QScrollArea *PostedListDialog::getScrollArea()
|
|
|
|
{
|
|
|
|
return ui.scrollArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::deleteFeedItem(QWidget *item, uint32_t type)
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::deleteFeedItem() Nah";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::openChat(std::string peerId)
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::openChat() Nah";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::openComments(uint32_t feed_type, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title)
|
2012-11-22 17:40:31 -05:00
|
|
|
{
|
2013-03-15 17:02:43 -04:00
|
|
|
commentLoad(groupId, msgId, title);
|
2012-11-22 17:40:31 -05:00
|
|
|
}
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
/*****************************************************************************************/
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
void PostedListDialog::updateDisplay()
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
if (!rsPosted)
|
|
|
|
return;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::list<std::string> groupIds;
|
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
if (rsPosted->updated(true, true))
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "rsPosted->updated() returned true";
|
|
|
|
std::cerr << std::endl;
|
2013-03-11 16:53:15 -04:00
|
|
|
/* update Forums List */
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
rsPosted->groupsChanged(groupIds);
|
|
|
|
if(!groupIds.empty())
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "rsPosted->groupsChanged():";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
for(it = groupIds.begin(); it != groupIds.end(); it++)
|
|
|
|
{
|
|
|
|
std::cerr << "\t" << *it;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
it = std::find(groupIds.begin(), groupIds.end(), mCurrTopicId);
|
|
|
|
if(it != groupIds.end())
|
|
|
|
{
|
|
|
|
std::cerr << "current Group -> requesting Group Summary";
|
|
|
|
std::cerr << std::endl;
|
2013-03-11 16:53:15 -04:00
|
|
|
requestGroupSummary();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-07-06 19:19:10 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
rsPosted->msgsChanged(msgs);
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
if(!msgs.empty())
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "rsPosted->msgsChanged():";
|
|
|
|
std::cerr << std::endl;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
|
|
|
|
mit = msgs.find(mCurrTopicId);
|
2013-03-11 16:53:15 -04:00
|
|
|
if(mit != msgs.end())
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "current Group -> updating Displayed Items";
|
|
|
|
std::cerr << std::endl;
|
2013-03-11 16:53:15 -04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
RsTokReqOptions opts;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
|
|
|
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
GxsMsgReq msgs;
|
|
|
|
msgs[mCurrTopicId] = msgIds;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::updateDisplayedItems(" << mCurrTopicId << ")";
|
|
|
|
std::cerr << std::endl;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
std::vector<RsGxsMessageId>::const_iterator it;
|
|
|
|
for(it = msgIds.begin(); it != msgIds.end(); it++)
|
|
|
|
{
|
|
|
|
std::cerr << "\t\tMsgId: " << *it;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
uint32_t token;
|
|
|
|
mPostedQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgs, TOKEN_USER_TYPE_POST_MOD);
|
2012-12-09 17:38:49 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
void PostedListDialog::changedTopic(const QString &id)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
mCurrTopicId = id.toStdString();
|
|
|
|
insertThreads();
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************** **** **** **** ***********************/
|
2013-03-11 16:53:15 -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
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
PostedGroupDialog cf (mPostedQueue, this);
|
2012-07-30 19:55:21 -04:00
|
|
|
cf.exec ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::showGroupDetails()
|
|
|
|
{
|
|
|
|
if (mCurrTopicId.empty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
PostedGroupDialog cf(mGroups[mCurrTopicId], 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()
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::requestGroupSummary()";
|
|
|
|
std::cerr << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
2012-07-01 19:05:03 -04:00
|
|
|
uint32_t token;
|
2013-03-11 16:53:15 -04: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)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
RsGxsGroupId grpId;
|
|
|
|
rsPosted->acknowledgeGrp(token, grpId);
|
2012-10-29 18:41:41 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
if(!grpId.empty())
|
|
|
|
{
|
2012-10-29 18:41:41 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
|
|
|
uint32_t reqToken;
|
|
|
|
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
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
RsGxsGrpMsgIdPair msgId;
|
2012-11-17 16:43:21 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
// 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)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::loadGroupSummary()";
|
|
|
|
std::cerr << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::list<RsGroupMetaData> groupInfo;
|
|
|
|
rsPosted->getGroupSummary(token, groupInfo);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
if (groupInfo.size() > 0)
|
|
|
|
{
|
2013-03-24 12:29:08 -04:00
|
|
|
insertGroupData(groupInfo);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-24 12:29:08 -04:00
|
|
|
std::cerr << "PostedListDialog::loadGroupSummary() ERROR No Groups...";
|
|
|
|
std::cerr << std::endl;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
void PostedListDialog::loadPostData(const uint32_t &token)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
loadGroupThreadData_InsertThreads(token);
|
2012-11-17 16:43:21 -05:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:45:44 -05:00
|
|
|
void PostedListDialog::acknowledgeVoteMsg(const uint32_t &token)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
RsGxsGrpMsgIdPair msgId;
|
2012-12-05 17:45:44 -05:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
rsPosted->acknowledgeVote(token, msgId);
|
2012-12-05 17:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::loadVoteData(const uint32_t &token)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
return;
|
2012-12-05 17:45:44 -05:00
|
|
|
}
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::requestGroupSummary_CurrentForum(const std::string &forumId)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
RsTokReqOptions opts;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
std::list<std::string> grpIds;
|
|
|
|
grpIds.push_back(forumId);
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::requestGroupSummary_CurrentForum(" << forumId << ")";
|
|
|
|
std::cerr << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
mPostedQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, POSTEDDIALOG_CURRENTFORUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::loadGroupSummary_CurrentForum(const uint32_t &token)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::loadGroupSummary_CurrentForum()";
|
|
|
|
std::cerr << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::list<RsGroupMetaData> groupInfo;
|
|
|
|
rsPosted->getGroupSummary(token, groupInfo);
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
if (groupInfo.size() == 1)
|
|
|
|
{
|
2012-07-01 19:05:03 -04:00
|
|
|
RsGroupMetaData fi = groupInfo.front();
|
|
|
|
//insertForumThreads(fi);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::loadGroupSummary_CurrentForum() ERROR Invalid Number of Groups...";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
/*********************** **** **** **** ***********************/
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::insertThreads()
|
|
|
|
{
|
2013-03-11 16:53:15 -04: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
|
|
|
{
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::loadCurrentForumThreads(" << topicId << ")";
|
|
|
|
std::cerr << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
if (topicId.empty())
|
2012-07-07 21:31:23 -04:00
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::loadCurrentForumThreads() Empty GroupId .. ignoring Req";
|
|
|
|
std::cerr << std::endl;
|
2012-07-07 21:31:23 -04:00
|
|
|
return;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
clearPosts();
|
|
|
|
|
2013-03-11 16:53:15 -04: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
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
RsTokReqOptions opts;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
|
|
|
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-06-04 17:00:43 -04: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
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "PostedListDialog::requestGroupThreadData_InsertThreads(" << groupId << ")";
|
|
|
|
std::cerr << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
uint32_t token;
|
2013-06-04 17:00:43 -04: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)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
clearPosts();
|
2012-07-07 21:31:23 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::vector<RsPostedPost> posts;
|
|
|
|
rsPosted->getPostData(token, posts);
|
|
|
|
std::vector<RsPostedPost>::iterator vit;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
for(vit = posts.begin(); vit != posts.end(); vit++)
|
|
|
|
{
|
|
|
|
RsPostedPost& p = *vit;
|
|
|
|
loadPost(p);
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
applyRanking();
|
|
|
|
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::loadPost(const RsPostedPost &post)
|
|
|
|
{
|
2013-03-15 17:02:43 -04:00
|
|
|
PostedItem *item = new PostedItem(this, 0, post, true);
|
2013-03-11 16:53:15 -04:00
|
|
|
connect(item, SIGNAL(vote(RsGxsGrpMsgIdPair,bool)), this, SLOT(submitVote(RsGxsGrpMsgIdPair,bool)));
|
|
|
|
mPosts.insert(post.mMeta.mMsgId, item);
|
2013-06-04 17:00:43 -04:00
|
|
|
//QLayout *alayout = ui.scrollAreaWidgetContents->layout();
|
|
|
|
//alayout->addWidget(item);
|
|
|
|
mPostList.push_back(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CmpPIHot(const PostedItem *a, const PostedItem *b)
|
|
|
|
{
|
|
|
|
if (a->mPost.mHotScore == b->mPost.mHotScore)
|
|
|
|
{
|
|
|
|
(a->mPost.mNewScore > b->mPost.mNewScore);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (a->mPost.mHotScore > b->mPost.mHotScore);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CmpPITop(const PostedItem *a, const PostedItem *b)
|
|
|
|
{
|
|
|
|
if (a->mPost.mTopScore == b->mPost.mTopScore)
|
|
|
|
{
|
|
|
|
(a->mPost.mNewScore > b->mPost.mNewScore);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (a->mPost.mTopScore > b->mPost.mTopScore);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CmpPINew(const PostedItem *a, const PostedItem *b)
|
|
|
|
{
|
|
|
|
return (a->mPost.mNewScore > b->mPost.mNewScore);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::applyRanking()
|
|
|
|
{
|
|
|
|
/* uses current settings to sort posts, then add to layout */
|
|
|
|
std::cerr << "PostedListDialog::applyRanking()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
shallowClearPosts();
|
|
|
|
|
|
|
|
/* sort */
|
|
|
|
switch(mSortMethod)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case RsPosted::HotRankType:
|
|
|
|
std::cerr << "PostedListDialog::applyRanking() HOT";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
mPostList.sort(CmpPIHot);
|
|
|
|
break;
|
|
|
|
case RsPosted::NewRankType:
|
|
|
|
std::cerr << "PostedListDialog::applyRanking() NEW";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
mPostList.sort(CmpPINew);
|
|
|
|
break;
|
|
|
|
case RsPosted::TopRankType:
|
|
|
|
std::cerr << "PostedListDialog::applyRanking() TOP";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
mPostList.sort(CmpPITop);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mLastSortMethod = mSortMethod;
|
|
|
|
|
|
|
|
std::cerr << "PostedListDialog::applyRanking() Sorted mPostList";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* go through list (skipping out-of-date items) to get */
|
|
|
|
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
|
|
|
|
int counter = 0;
|
|
|
|
time_t min_ts = 0;
|
|
|
|
std::list<PostedItem *>::iterator it;
|
|
|
|
for(it = mPostList.begin(); it != mPostList.end(); it++)
|
|
|
|
{
|
|
|
|
PostedItem *item = (*it);
|
|
|
|
std::cerr << "PostedListDialog::applyRanking() Item: " << item;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
if (item->mPost.mMeta.mPublishTs < min_ts)
|
|
|
|
{
|
|
|
|
std::cerr << "\t Skipping OLD";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
item->hide();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (counter >= mPostIndex + mPostShow)
|
|
|
|
{
|
|
|
|
std::cerr << "\t END - Counter too high";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
item->hide();
|
|
|
|
}
|
|
|
|
else if (counter >= mPostIndex)
|
|
|
|
{
|
|
|
|
std::cerr << "\t Adding to Layout";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
/* add it in! */
|
|
|
|
item->show();
|
|
|
|
alayout->addWidget(item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "\t Skipping to Low";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
item->hide();
|
|
|
|
}
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "PostedListDialog::applyRanking() Loaded New Order";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
// trigger a redraw.
|
|
|
|
ui.scrollAreaWidgetContents->update();
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PostedListDialog::clearPosts()
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << "PostedListDialog::clearPosts()" << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
for(pit = postedItems.begin(); pit != postedItems.end(); pit++)
|
|
|
|
{
|
|
|
|
PostedItem *item = *pit;
|
|
|
|
alayout->removeWidget(item);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPosts.clear();
|
2013-06-04 17:00:43 -04:00
|
|
|
mPostList.clear();
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
void PostedListDialog::shallowClearPosts()
|
2012-12-09 17:38:49 -05:00
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "PostedListDialog::shallowClearPosts()" << std::endl;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::list<PostedItem *> postedItems;
|
|
|
|
std::list<PostedItem *>::iterator pit;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
|
|
|
|
int count = alayout->count();
|
|
|
|
for(int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
QLayoutItem *litem = alayout->itemAt(i);
|
|
|
|
if (!litem)
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "PostedListDialog::shallowClearPosts() missing litem";
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PostedItem *item = dynamic_cast<PostedItem *>(litem->widget());
|
|
|
|
if (item)
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "PostedListDialog::shallowClearPosts() item: " << item;
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
postedItems.push_back(item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "PostedListDialog::shallowClearPosts() Found Child, which is not a PostedItem???";
|
2013-03-11 16:53:15 -04:00
|
|
|
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
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
void PostedListDialog::updateCurrentDisplayComplete(const uint32_t &token)
|
|
|
|
{
|
2013-06-04 17:00:43 -04:00
|
|
|
std::cerr << "PostedListDialog::updateCurrentDisplayComplete()";
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << std::endl;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::vector<RsPostedPost> posts;
|
|
|
|
rsPosted->getPostData(token, posts);
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::vector<RsPostedPost>::iterator vit;
|
|
|
|
for(vit = posts.begin(); vit != posts.end(); vit++)
|
|
|
|
{
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
RsPostedPost& p = *vit;
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
// modify post content
|
|
|
|
if(mPosts.find(p.mMeta.mMsgId) != mPosts.end())
|
2013-06-04 17:00:43 -04:00
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::updateCurrentDisplayComplete() updating MsgId: " << p.mMeta.mMsgId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
mPosts[p.mMeta.mMsgId]->setContent(p);
|
2013-06-04 17:00:43 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::updateCurrentDisplayComplete() loading New MsgId: " << p.mMeta.mMsgId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
/* insert new entry */
|
|
|
|
loadPost(p);
|
|
|
|
}
|
|
|
|
}
|
2012-12-09 17:38:49 -05:00
|
|
|
|
2013-06-04 17:00:43 -04:00
|
|
|
time_t now = time(NULL);
|
|
|
|
QMap<RsGxsMessageId, PostedItem*>::iterator pit;
|
|
|
|
for(pit = mPosts.begin(); pit != mPosts.end(); pit++)
|
|
|
|
{
|
|
|
|
(*pit)->mPost.calculateScores(now);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2013-06-04 17:00:43 -04:00
|
|
|
|
|
|
|
applyRanking();
|
2012-12-09 17:38:49 -05:00
|
|
|
}
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-24 12:29:08 -04:00
|
|
|
|
|
|
|
void PostedListDialog::acknowledgeSubscribeChange(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::cerr << "PostedListDialog::acknowledgeSubscribeChange()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
std::vector<RsPostedPost> posts;
|
|
|
|
RsGxsGroupId groupId;
|
|
|
|
rsPosted->acknowledgeGrp(token, groupId);
|
|
|
|
|
|
|
|
refreshTopics();
|
|
|
|
}
|
|
|
|
|
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)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
/* now switch on req */
|
|
|
|
switch(req.mUserType)
|
2012-07-01 19:05:03 -04:00
|
|
|
{
|
2012-12-05 17:45:44 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
case TOKEN_USER_TYPE_TOPIC:
|
|
|
|
switch(req.mAnsType)
|
|
|
|
{
|
|
|
|
case RS_TOKREQ_ANSTYPE_SUMMARY:
|
|
|
|
loadGroupSummary(req.mToken);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TOKEN_USER_TYPE_POST:
|
|
|
|
switch(req.mAnsType)
|
|
|
|
{
|
|
|
|
case RS_TOKREQ_ANSTYPE_ACK:
|
|
|
|
acknowledgePostMsg(req.mToken);
|
|
|
|
break;
|
|
|
|
case RS_TOKREQ_ANSTYPE_DATA:
|
|
|
|
loadPostData(req.mToken);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|
2013-03-24 12:29:08 -04:00
|
|
|
case TOKEN_USER_TYPE_SUBSCRIBE_CHANGE:
|
|
|
|
acknowledgeSubscribeChange(req.mToken);
|
2013-03-11 16:53:15 -04:00
|
|
|
break;
|
|
|
|
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
|
|
|
|
2013-03-11 16:53:15 -04: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)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
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);
|
2013-03-24 12:29:08 -04:00
|
|
|
groupItemInfo.subscribeFlags = groupInfo.mSubscribeFlags;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostedListDialog::insertGroupData(const std::list<RsGroupMetaData> &groupList)
|
|
|
|
{
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
std::list<RsGroupMetaData>::const_iterator it;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
QList<GroupItemInfo> adminList;
|
|
|
|
QList<GroupItemInfo> subList;
|
|
|
|
QList<GroupItemInfo> popList;
|
|
|
|
QList<GroupItemInfo> otherList;
|
|
|
|
std::multimap<uint32_t, GroupItemInfo> popMap;
|
2012-07-01 19:05:03 -04:00
|
|
|
|
2013-03-24 12:29:08 -04:00
|
|
|
for (it = groupList.begin(); it != groupList.end(); it++)
|
|
|
|
{
|
2013-03-11 16:53:15 -04:00
|
|
|
/* sort it into Publish (Own), Subscribed, Popular and Other */
|
|
|
|
uint32_t flags = it->mSubscribeFlags;
|
2012-10-29 18:41:41 -04:00
|
|
|
|
2013-03-24 12:29:08 -04:00
|
|
|
GroupItemInfo groupItemInfo;
|
|
|
|
groupInfoToGroupItemInfo(*it, groupItemInfo);
|
|
|
|
|
|
|
|
if (IS_GROUP_SUBSCRIBED(flags))
|
|
|
|
{
|
|
|
|
if (IS_GROUP_ADMIN(flags) || IS_GROUP_PUBLISHER(flags))
|
|
|
|
{
|
|
|
|
adminList.push_back(groupItemInfo);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
subList.push_back(groupItemInfo);
|
|
|
|
}
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2013-03-24 12:29:08 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
popMap.insert(std::make_pair(it->mPop, groupItemInfo));
|
|
|
|
}
|
|
|
|
}
|
2013-03-11 16:53:15 -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;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
uint32_t popLimit = 0;
|
|
|
|
std::multimap<uint32_t, GroupItemInfo>::reverse_iterator rit;
|
|
|
|
for(rit = popMap.rbegin(); ((rit != popMap.rend()) && (i < popCount)); rit++, i++) ;
|
|
|
|
if (rit != popMap.rend()) {
|
|
|
|
popLimit = rit->first;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (rit = popMap.rbegin(); rit != popMap.rend(); rit++) {
|
|
|
|
if (rit->second.popularity < (int) popLimit) {
|
|
|
|
otherList.append(rit->second);
|
|
|
|
} else {
|
|
|
|
popList.append(rit->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now we can add them in as a tree! */
|
|
|
|
ui.groupTreeWidget->fillGroupItems(yourTopics, adminList);
|
|
|
|
ui.groupTreeWidget->fillGroupItems(subscribedTopics, subList);
|
|
|
|
ui.groupTreeWidget->fillGroupItems(popularTopics, popList);
|
|
|
|
ui.groupTreeWidget->fillGroupItems(otherTopics, otherList);
|
2012-07-01 19:05:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
/**************************************************************************************/
|
|
|
|
|
|
|
|
|