Comment and Vote update now functional

Voting and comment count update in gui added via msg notification
clarified comments in RsTokenService

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5958 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-12-09 22:38:49 +00:00
parent 62176264d3
commit 30b48c59ef
12 changed files with 339 additions and 36 deletions

View file

@ -26,6 +26,7 @@
#include <retroshare/rsposted.h>
#include <iostream>
#include <sstream>

View file

@ -43,6 +43,18 @@ PostedItem::PostedItem(PostedHolder *postHolder, const RsPostedPost &post)
setupUi(this);
setAttribute ( Qt::WA_DeleteOnClose, true );
setContent(mPost);
connect( commentButton, SIGNAL( clicked() ), this, SLOT( loadComments() ) );
connect( voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
connect( voteDownButton, SIGNAL(clicked()), this, SLOT( makeDownVote()));
return;
}
void PostedItem::setContent(const RsPostedPost &post)
{
mPost = post;
QDateTime qtime;
qtime.setTime_t(mPost.mMeta.mPublishTs);
QString timestamp = qtime.toString("dd.MMMM yyyy hh:mm");
@ -57,16 +69,20 @@ PostedItem::PostedItem(PostedHolder *postHolder, const RsPostedPost &post)
uint32_t up, down, nComments;
rsPosted->retrieveScores(mPost.mMeta.mServiceString, up, down, nComments);
bool ok = rsPosted->retrieveScores(mPost.mMeta.mServiceString, up, down, nComments);
int32_t vote = up - down;
scoreLabel->setText(QString::number(vote));
if(ok)
{
int32_t vote = up - down;
scoreLabel->setText(QString::number(vote));
connect( commentButton, SIGNAL( clicked() ), this, SLOT( loadComments() ) );
connect( voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
connect( voteDownButton, SIGNAL(clicked()), this, SLOT( makeDownVote()));
numCommentsLabel->setText("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px;"
"margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span"
"style=\" font-size:10pt; font-weight:600;\">#</span><span "
"style=\" font-size:8pt; font-weight:600;\"> Comments: "
+ QString::number(nComments) + "</span></p>");
}
return;
}
RsPostedPost PostedItem::getPost() const

View file

@ -38,15 +38,15 @@ class PostedHolder
virtual void showComments(const RsPostedPost& post) = 0;
};
class PostedItem : public QWidget, private Ui::PostedItem
{
Q_OBJECT
public:
PostedItem(PostedHolder *parent, const RsPostedPost &item);
PostedItem(PostedHolder *parent, const RsPostedPost &post);
RsPostedPost getPost() const;
void setContent(const RsPostedPost& post);
private slots:
void loadComments();

View file

@ -250,7 +250,18 @@ border-radius: 10px}</string>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="1,0">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,1,0">
<item>
<widget class="QLabel" name="numCommentsLabel">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:10pt; font-weight:600;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot; font-size:8pt; font-weight:600;&quot;&gt; Comments: 0&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

View file

@ -140,21 +140,68 @@ void PostedListDialog::showComments(const RsPostedPost& post)
void PostedListDialog::updateDisplay()
{
std::list<std::string> groupIds;
std::list<std::string>::iterator it;
if (!rsPosted)
return;
std::list<std::string> groupIds;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
if (rsPosted->updated())
{
/* update Forums List */
insertGroups();
insertThreads();
rsPosted->groupsChanged(groupIds);
if(!groupIds.empty())
{
std::list<std::string>::iterator it = std::find(groupIds.begin(), groupIds.end(), mCurrTopicId);
if(it != groupIds.end()){
requestGroupSummary();
return;
}
}
rsPosted->msgsChanged(msgs);
if(!msgs.empty())
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit = msgs.find(mCurrTopicId);
if(mit != msgs.end())
{
updateDisplayedItems(mit->second);
}
}
}
}
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);
}
void PostedListDialog::changedTopic(const QString &id)
{
mCurrTopicId = id.toStdString();
@ -362,7 +409,8 @@ void PostedListDialog::loadGroupThreadData_InsertThreads(const uint32_t &token)
for(; vit != posts.end(); vit++)
{
loadPost(*vit);
RsPostedPost& p = *vit;
loadPost(p);
}
}
@ -371,6 +419,7 @@ void PostedListDialog::loadPost(const RsPostedPost &post)
PostedItem *item = new PostedItem(this, post);
connect(item, SIGNAL(vote(RsGxsGrpMsgIdPair,bool)), this, SLOT(submitVote(RsGxsGrpMsgIdPair,bool)));
QLayout *alayout = ui.scrollAreaWidgetContents->layout();
mPosts.insert(post.mMeta.mMsgId, item);
alayout->addWidget(item);
}
@ -415,9 +464,37 @@ void PostedListDialog::clearPosts()
alayout->removeWidget(item);
delete item;
}
mPosts.clear();
}
void PostedListDialog::updateCurrentDisplayComplete(const uint32_t &token)
{
std::cerr << "PostedListDialog::loadGroupThreadData_InsertThreads()";
std::cerr << std::endl;
PostedPostResult result;
rsPosted->getPost(token, result);
if(result.find(mCurrTopicId) == result.end())
return;
std::vector<RsPostedPost>& posts = result[mCurrTopicId];
std::vector<RsPostedPost>::iterator vit = posts.begin();
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);
}
}
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
@ -470,6 +547,17 @@ void PostedListDialog::loadRequest(const TokenQueue *queue, const TokenRequest &
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;
default:
std::cerr << "PostedListDialog::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;

View file

@ -104,13 +104,16 @@ private:
void loadVoteData(const uint32_t &token);
// update displayed item
void updateDisplayedItems(const std::vector<RsGxsMessageId>& msgIds);
void updateCurrentDisplayComplete(const uint32_t& token);
void insertGroupData(const std::list<RsGroupMetaData> &groupList);
void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo);
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
private:
QTreeWidgetItem *yourTopics;
@ -124,6 +127,7 @@ private:
RsGxsGroupId mCurrTopicId;
QMap<RsGxsGroupId, RsPostedGroup> mGroups;
QMap<RsGxsMessageId, PostedItem*> mPosts;
TokenQueue *mPostedQueue;
CommentHolder* mCommentHolder;

View file

@ -4,5 +4,6 @@
#define TOKEN_USER_TYPE_POST 4
#define TOKEN_USER_TYPE_VOTE 5
#define TOKEN_USER_TYPE_TOPIC 6
#define TOKEN_USER_TYPE_POST_MOD 7
#endif // POSTEDUSERTYPES_H