2013-03-15 17:02:43 -04:00
|
|
|
/*
|
|
|
|
* Retroshare Gxs Support
|
|
|
|
*
|
|
|
|
* Copyright 2012-2013 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".
|
|
|
|
*
|
|
|
|
*/
|
2012-07-31 21:47:53 -04:00
|
|
|
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QDateTime>
|
2012-11-25 16:50:45 -05:00
|
|
|
#include <QMenu>
|
2012-07-31 21:47:53 -04:00
|
|
|
|
|
|
|
#include "gui/gxs/GxsCommentTreeWidget.h"
|
2013-03-11 16:53:15 -04:00
|
|
|
#include "gui/gxs/GxsCreateCommentDialog.h"
|
2013-03-12 20:33:14 -04:00
|
|
|
#include "gui/gxs/GxsIdTreeWidgetItem.h"
|
2012-07-31 21:47:53 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
#define PCITEM_COLUMN_COMMENT 0
|
|
|
|
#define PCITEM_COLUMN_AUTHOR 1
|
|
|
|
#define PCITEM_COLUMN_DATE 2
|
2013-03-12 20:33:14 -04:00
|
|
|
#define PCITEM_COLUMN_SCORE 3
|
|
|
|
#define PCITEM_COLUMN_UPVOTES 4
|
|
|
|
#define PCITEM_COLUMN_DOWNVOTES 5
|
2013-03-15 17:02:43 -04:00
|
|
|
#define PCITEM_COLUMN_OWNVOTE 6
|
|
|
|
#define PCITEM_COLUMN_MSGID 7
|
|
|
|
#define PCITEM_COLUMN_PARENTID 8
|
2012-07-31 21:47:53 -04:00
|
|
|
|
|
|
|
#define GXSCOMMENTS_LOADTHREAD 1
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
#define COMMENT_VOTE_ACK 0x001234
|
|
|
|
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
/* Images for context menu icons */
|
2013-03-12 20:33:14 -04:00
|
|
|
#define IMAGE_MESSAGE ":/images/folder-draft.png"
|
2013-08-31 17:47:00 -04:00
|
|
|
#define IMAGE_VOTEUP ":/images/vote_up.png"
|
|
|
|
#define IMAGE_VOTEDOWN ":/images/vote_down.png"
|
2012-07-31 21:47:53 -04:00
|
|
|
|
|
|
|
GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent)
|
2014-10-12 06:46:09 -04:00
|
|
|
:QTreeWidget(parent), mTokenQueue(NULL), mRsTokenService(NULL), mCommentService(NULL)
|
2012-07-31 21:47:53 -04:00
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
// QTreeWidget* widget = this;
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
// QFont font = QFont("ARIAL", 10);
|
|
|
|
// font.setBold(true);
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
// QString name("test");
|
|
|
|
// QTreeWidgetItem *item = new QTreeWidgetItem();
|
|
|
|
// item->setText(0, name);
|
|
|
|
// item->setFont(0, font);
|
|
|
|
// item->setSizeHint(0, QSize(18, 18));
|
|
|
|
// item->setForeground(0, QBrush(QColor(79, 79, 79)));
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
// addTopLevelItem(item);
|
|
|
|
// item->setExpanded(true);
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
return;
|
2012-07-31 21:47:53 -04:00
|
|
|
}
|
|
|
|
|
2014-10-12 06:46:09 -04:00
|
|
|
GxsCommentTreeWidget::~GxsCommentTreeWidget()
|
|
|
|
{
|
|
|
|
if (mTokenQueue) {
|
|
|
|
delete(mTokenQueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
void GxsCommentTreeWidget::setCurrentMsgId(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
|
|
|
{
|
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
Q_UNUSED(previous);
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
if(current)
|
|
|
|
{
|
2014-04-20 12:34:26 -04:00
|
|
|
mCurrentMsgId = RsGxsMessageId(current->text(PCITEM_COLUMN_MSGID).toStdString());
|
2013-03-12 20:33:14 -04:00
|
|
|
}
|
2012-11-25 16:50:45 -05:00
|
|
|
}
|
|
|
|
|
2014-10-12 06:46:09 -04:00
|
|
|
void GxsCommentTreeWidget::customPopUpMenu(const QPoint& /*point*/)
|
2012-11-25 16:50:45 -05:00
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
QMenu contextMnu( this );
|
|
|
|
QAction* action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Reply to Comment"), this, SLOT(replyToComment()));
|
2014-03-17 16:56:06 -04:00
|
|
|
action->setDisabled(mCurrentMsgId.isNull());
|
2013-03-12 20:33:14 -04:00
|
|
|
action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Submit Comment"), this, SLOT(makeComment()));
|
2014-03-17 16:56:06 -04:00
|
|
|
action->setDisabled(mThreadId.first.isNull());
|
2013-03-12 20:33:14 -04:00
|
|
|
|
|
|
|
contextMnu.addSeparator();
|
|
|
|
|
2013-08-31 17:47:00 -04:00
|
|
|
action = contextMnu.addAction(QIcon(IMAGE_VOTEUP), tr("Vote Up"), this, SLOT(voteUp()));
|
2014-03-17 16:56:06 -04:00
|
|
|
action->setDisabled(mVoterId.isNull());
|
2013-08-31 17:47:00 -04:00
|
|
|
action = contextMnu.addAction(QIcon(IMAGE_VOTEDOWN), tr("Vote Down"), this, SLOT(voteDown()));
|
2014-03-17 16:56:06 -04:00
|
|
|
action->setDisabled(mVoterId.isNull());
|
2013-03-12 20:33:14 -04:00
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
if (!mCurrentMsgId.isNull())
|
2013-03-12 20:33:14 -04:00
|
|
|
{
|
2015-05-08 14:08:27 -04:00
|
|
|
// not implemented yet
|
|
|
|
/*
|
2013-03-12 20:33:14 -04:00
|
|
|
contextMnu.addSeparator();
|
|
|
|
QMenu *rep_menu = contextMnu.addMenu(tr("Reputation"));
|
|
|
|
|
|
|
|
action = rep_menu->addAction(QIcon(IMAGE_MESSAGE), tr("Show Reputation"), this, SLOT(showReputation()));
|
|
|
|
contextMnu.addSeparator();
|
|
|
|
|
|
|
|
action = rep_menu->addAction(QIcon(IMAGE_MESSAGE), tr("Interesting User"), this, SLOT(markInteresting()));
|
|
|
|
contextMnu.addSeparator();
|
|
|
|
|
|
|
|
action = rep_menu->addAction(QIcon(IMAGE_MESSAGE), tr("Mark Spammy"), this, SLOT(markSpammer()));
|
|
|
|
action = rep_menu->addAction(QIcon(IMAGE_MESSAGE), tr("Ban User"), this, SLOT(banUser()));
|
2015-05-08 14:08:27 -04:00
|
|
|
*/
|
2013-03-12 20:33:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
contextMnu.exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::voteUp()
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::voteUp()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
vote(mThreadId.first, mThreadId.second, mCurrentMsgId, mVoterId, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::voteDown()
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::voteDown()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
vote(mThreadId.first, mThreadId.second, mCurrentMsgId, mVoterId, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::setVoteId(const RsGxsId &voterId)
|
|
|
|
{
|
|
|
|
mVoterId = voterId;
|
|
|
|
std::cerr << "GxsCommentTreeWidget::setVoterId(" << mVoterId << ")";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::vote(const RsGxsGroupId &groupId, const RsGxsMessageId &threadId,
|
|
|
|
const RsGxsMessageId &parentId, const RsGxsId &authorId, bool up)
|
|
|
|
{
|
|
|
|
RsGxsVote vote;
|
|
|
|
|
|
|
|
vote.mMeta.mGroupId = groupId;
|
|
|
|
vote.mMeta.mThreadId = threadId;
|
|
|
|
vote.mMeta.mParentId = parentId;
|
|
|
|
vote.mMeta.mAuthorId = authorId;
|
|
|
|
|
|
|
|
if (up)
|
|
|
|
{
|
|
|
|
vote.mVoteType = GXS_VOTE_UP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vote.mVoteType = GXS_VOTE_DOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "GxsCommentTreeWidget::vote()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
uint32_t token;
|
|
|
|
mCommentService->createVote(token, vote);
|
2013-03-15 17:02:43 -04:00
|
|
|
mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, COMMENT_VOTE_ACK);
|
2013-03-12 20:33:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::showReputation()
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::showReputation() TODO";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::markInteresting()
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::markInteresting() TODO";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::markSpammer()
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::markSpammer() TODO";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::banUser()
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::banUser() TODO";
|
|
|
|
std::cerr << std::endl;
|
2012-11-25 16:50:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::makeComment()
|
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, mThreadId, mThreadId.second, this);
|
|
|
|
pcc.exec();
|
2012-11-30 13:54:25 -05:00
|
|
|
}
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2012-11-30 13:54:25 -05:00
|
|
|
void GxsCommentTreeWidget::replyToComment()
|
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
msgId.first = mThreadId.first;
|
|
|
|
msgId.second = mCurrentMsgId;
|
|
|
|
GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, msgId, mThreadId.second, this);
|
|
|
|
pcc.exec();
|
2012-11-25 16:50:45 -05:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
void GxsCommentTreeWidget::setup(RsTokenService *token_service, RsGxsCommentService *comment_service)
|
2012-07-31 21:47:53 -04:00
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
mRsTokenService = token_service;
|
|
|
|
mCommentService = comment_service;
|
|
|
|
mTokenQueue = new TokenQueue(token_service, this);
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customPopUpMenu(QPoint)));
|
|
|
|
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(setCurrentMsgId(QTreeWidgetItem*, QTreeWidgetItem*)));
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
return;
|
2012-07-31 21:47:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Load Comments */
|
2012-11-25 16:50:45 -05:00
|
|
|
void GxsCommentTreeWidget::requestComments(const RsGxsGrpMsgIdPair& threadId)
|
2012-07-31 21:47:53 -04:00
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
/* request comments */
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
mThreadId = threadId;
|
|
|
|
service_requestComments(threadId);
|
2012-07-31 21:47:53 -04:00
|
|
|
}
|
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
void GxsCommentTreeWidget::service_requestComments(const RsGxsGrpMsgIdPair& threadId)
|
2012-07-31 21:47:53 -04:00
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
/* request comments */
|
|
|
|
std::cerr << "GxsCommentTreeWidget::service_requestComments(" << threadId.second << ")";
|
|
|
|
std::cerr << std::endl;
|
2012-11-30 13:54:25 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
|
|
|
|
opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST;
|
2012-11-30 13:54:25 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
std::vector<RsGxsGrpMsgIdPair> msgIds;
|
|
|
|
msgIds.push_back(threadId);
|
2012-11-30 13:54:25 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
uint32_t token;
|
|
|
|
mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, GXSCOMMENTS_LOADTHREAD);
|
2012-07-31 21:47:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Generic Handling */
|
|
|
|
void GxsCommentTreeWidget::clearItems()
|
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
mPendingInsertMap.clear();
|
|
|
|
mLoadingMap.clear();
|
2012-07-31 21:47:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::completeItems()
|
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
/* handle pending items */
|
2014-03-17 16:56:06 -04:00
|
|
|
RsGxsMessageId parentId;
|
2013-03-12 20:33:14 -04:00
|
|
|
QTreeWidgetItem *parent = NULL;
|
|
|
|
QList<QTreeWidgetItem *> topLevelItems;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsGxsMessageId, QTreeWidgetItem *>::iterator lit;
|
|
|
|
std::multimap<RsGxsMessageId, QTreeWidgetItem *>::iterator pit;
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
std::cerr << "GxsCommentTreeWidget::completeItems() " << mPendingInsertMap.size();
|
|
|
|
std::cerr << " PendingItems";
|
|
|
|
std::cerr << std::endl;
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2014-10-21 18:33:02 -04:00
|
|
|
for(pit = mPendingInsertMap.begin(); pit != mPendingInsertMap.end(); ++pit)
|
2013-03-12 20:33:14 -04:00
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::completeItems() item->parent: " << pit->first;
|
|
|
|
std::cerr << std::endl;
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
if (pit->first != parentId)
|
|
|
|
{
|
|
|
|
/* find parent */
|
|
|
|
parentId = pit->first;
|
|
|
|
lit = mLoadingMap.find(pit->first);
|
|
|
|
if (lit != mLoadingMap.end())
|
|
|
|
{
|
|
|
|
parent = lit->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parent = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::completeItems() Added to Parent";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
parent->addChild(pit->second);
|
|
|
|
}
|
|
|
|
else if (parentId == mThreadId.second)
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::completeItems() Added to topLevelItems";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
topLevelItems.append(pit->second);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
/* missing parent -> insert At Top Level */
|
|
|
|
QTreeWidgetItem *missingItem = service_createMissingItem(pit->first);
|
|
|
|
|
|
|
|
std::cerr << "GxsCommentTreeWidget::completeItems() Added MissingItem";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
parent = missingItem;
|
|
|
|
parent->addChild(pit->second);
|
|
|
|
topLevelItems.append(parent);
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
/* now push final tree into Tree */
|
|
|
|
clear();
|
|
|
|
insertTopLevelItems(0, topLevelItems);
|
|
|
|
|
|
|
|
/* cleanup temp stuff */
|
|
|
|
mLoadingMap.clear();
|
|
|
|
mPendingInsertMap.clear();
|
2012-07-31 21:47:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
void GxsCommentTreeWidget::addItem(RsGxsMessageId itemId, RsGxsMessageId parentId, QTreeWidgetItem *item)
|
2012-07-31 21:47:53 -04:00
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::addItem() Id: " << itemId;
|
|
|
|
std::cerr << " ParentId: " << parentId;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* store in map -> for children */
|
|
|
|
mLoadingMap[itemId] = item;
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsGxsMessageId, QTreeWidgetItem *>::iterator it;
|
2012-07-31 21:47:53 -04:00
|
|
|
it = mLoadingMap.find(parentId);
|
|
|
|
if (it != mLoadingMap.end())
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::addItem() Added to Parent";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
it->second->addChild(item);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::addItem() Added to Pending List";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
mPendingInsertMap.insert(std::make_pair(parentId, item));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsCommentTreeWidget::loadThread(const uint32_t &token)
|
|
|
|
{
|
|
|
|
clearItems();
|
|
|
|
|
|
|
|
service_loadThread(token);
|
|
|
|
|
|
|
|
completeItems();
|
|
|
|
}
|
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
void GxsCommentTreeWidget::acknowledgeComment(const uint32_t &token)
|
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
mCommentService->acknowledgeComment(token, msgId);
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
// simply reload data
|
|
|
|
service_requestComments(mThreadId);
|
2012-11-25 16:50:45 -05:00
|
|
|
}
|
|
|
|
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
void GxsCommentTreeWidget::acknowledgeVote(const uint32_t &token)
|
|
|
|
{
|
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
if (mCommentService->acknowledgeVote(token, msgId))
|
|
|
|
{
|
|
|
|
// reload data if vote was added.
|
|
|
|
service_requestComments(mThreadId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-31 21:47:53 -04:00
|
|
|
void GxsCommentTreeWidget::service_loadThread(const uint32_t &token)
|
|
|
|
{
|
2013-03-12 20:33:14 -04:00
|
|
|
std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!";
|
|
|
|
std::cerr << std::endl;
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
std::vector<RsGxsComment> comments;
|
|
|
|
mCommentService->getRelatedComments(token, comments);
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
std::vector<RsGxsComment>::iterator vit;
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2014-10-21 18:33:02 -04:00
|
|
|
for(vit = comments.begin(); vit != comments.end(); ++vit)
|
2013-03-12 20:33:14 -04:00
|
|
|
{
|
|
|
|
RsGxsComment &comment = *vit;
|
|
|
|
/* convert to a QTreeWidgetItem */
|
|
|
|
std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId;
|
|
|
|
std::cerr << std::endl;
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2014-09-16 15:11:22 -04:00
|
|
|
GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(NULL);
|
2013-03-12 20:33:14 -04:00
|
|
|
QString text;
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
{
|
|
|
|
QDateTime qtime;
|
|
|
|
qtime.setTime_t(comment.mMeta.mPublishTs);
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
text = qtime.toString("yyyy-MM-dd hh:mm:ss");
|
|
|
|
item->setText(PCITEM_COLUMN_DATE, text);
|
|
|
|
}
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
text = QString::fromUtf8(comment.mComment.c_str());
|
|
|
|
item->setText(PCITEM_COLUMN_COMMENT, text);
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
RsGxsId authorId = comment.mMeta.mAuthorId;
|
2015-03-09 16:41:14 -04:00
|
|
|
item->setId(authorId, PCITEM_COLUMN_AUTHOR, false);
|
2012-07-31 21:47:53 -04:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
text = QString::number(comment.mScore);
|
|
|
|
item->setText(PCITEM_COLUMN_SCORE, text);
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
text = QString::number(comment.mUpVotes);
|
|
|
|
item->setText(PCITEM_COLUMN_UPVOTES, text);
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
text = QString::number(comment.mDownVotes);
|
|
|
|
item->setText(PCITEM_COLUMN_DOWNVOTES, text);
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
text = QString::number(comment.mOwnVote);
|
|
|
|
item->setText(PCITEM_COLUMN_OWNVOTE, text);
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
text = QString::fromUtf8(comment.mMeta.mMsgId.toStdString().c_str());
|
2013-03-12 20:33:14 -04:00
|
|
|
item->setText(PCITEM_COLUMN_MSGID, text);
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
text = QString::fromUtf8(comment.mMeta.mParentId.toStdString().c_str());
|
2013-03-12 20:33:14 -04:00
|
|
|
item->setText(PCITEM_COLUMN_PARENTID, text);
|
|
|
|
|
|
|
|
|
|
|
|
addItem(comment.mMeta.mMsgId, comment.mMeta.mParentId, item);
|
|
|
|
}
|
2012-07-31 21:47:53 -04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMessageId& parent)
|
2012-07-31 21:47:53 -04:00
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::service_createMissingItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
|
|
|
QString text("Unknown");
|
|
|
|
|
|
|
|
item->setText(PCITEM_COLUMN_DATE, text);
|
|
|
|
|
|
|
|
item->setText(PCITEM_COLUMN_COMMENT, text);
|
|
|
|
|
|
|
|
item->setText(PCITEM_COLUMN_AUTHOR, text);
|
|
|
|
|
|
|
|
item->setText(PCITEM_COLUMN_MSGID, text);
|
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
text = QString::fromUtf8(parent.toStdString().c_str());
|
2012-07-31 21:47:53 -04:00
|
|
|
item->setText(PCITEM_COLUMN_PARENTID, text);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
void GxsCommentTreeWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req)
|
2012-07-31 21:47:53 -04:00
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::loadRequest() UserType: " << req.mUserType;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
if (queue != mTokenQueue)
|
|
|
|
{
|
|
|
|
std::cerr << "GxsCommentTreeWidget::loadRequest() Queue ERROR";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now switch on req */
|
2013-03-12 20:33:14 -04:00
|
|
|
switch(req.mType)
|
2012-07-31 21:47:53 -04:00
|
|
|
{
|
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
case TOKENREQ_MSGINFO:
|
|
|
|
{
|
|
|
|
switch(req.mAnsType)
|
|
|
|
{
|
|
|
|
case RS_TOKREQ_ANSTYPE_ACK:
|
2013-03-15 17:02:43 -04:00
|
|
|
if (req.mUserType == COMMENT_VOTE_ACK)
|
|
|
|
{
|
|
|
|
acknowledgeVote(req.mToken);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
acknowledgeComment(req.mToken);
|
|
|
|
}
|
2013-03-12 20:33:14 -04:00
|
|
|
break;
|
|
|
|
case RS_TOKREQ_ANSTYPE_DATA:
|
|
|
|
loadThread(req.mToken);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
std::cerr << "GxsCommentTreeWidget::loadRequest() UNKNOWN UserType ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
2012-07-31 21:47:53 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|