From 7c7da7e6d16ae674981434dbb5fef889c3fc7c90 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 23 Jul 2016 01:48:23 +0200 Subject: [PATCH] Fix Posted Feed Item when received comment. --- libretroshare/src/retroshare/rsposted.h | 1 + libretroshare/src/services/p3posted.cc | 53 ++++++++++++++---- libretroshare/src/services/p3posted.h | 3 +- retroshare-gui/src/gui/Posted/PostedItem.cpp | 40 ++++++++++---- retroshare-gui/src/gui/Posted/PostedItem.ui | 54 ++++++++++++------- .../src/gui/feeds/GxsChannelPostItem.cpp | 3 +- 6 files changed, 112 insertions(+), 42 deletions(-) diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 4a4c96269..69f9a17a5 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -83,6 +83,7 @@ virtual ~RsPosted() { return; } /* Specific Service Data */ virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; +virtual bool getPostData(const uint32_t &token, std::vector &posts, std::vector &cmts) = 0; virtual bool getPostData(const uint32_t &token, std::vector &posts) = 0; //Not currently used //virtual bool getRelatedPosts(const uint32_t &token, std::vector &posts) = 0; diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index 271d269e1..b231149d5 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -98,8 +98,13 @@ bool p3Posted::getGroupData(const uint32_t &token, std::vector &g return ok; } -bool p3Posted::getPostData(const uint32_t &token, std::vector &msgs) +bool p3Posted::getPostData(const uint32_t &token, std::vector &msgs, std::vector &cmts) { +#ifdef POSTED_DEBUG + std::cerr << "p3Posted::getPostData()"; + std::cerr << std::endl; +#endif + GxsMsgDataMap msgData; bool ok = RsGenExchange::getMsgData(token, msgData); time_t now = time(NULL); @@ -110,32 +115,60 @@ bool p3Posted::getPostData(const uint32_t &token, std::vector &msg for(; mit != msgData.end(); ++mit) { - RsGxsGroupId grpId = mit->first; std::vector& msgItems = mit->second; std::vector::iterator vit = msgItems.begin(); for(; vit != msgItems.end(); ++vit) { - RsGxsPostedPostItem* item = dynamic_cast(*vit); + RsGxsPostedPostItem* postItem = dynamic_cast(*vit); - if(item) + if(postItem) { - RsPostedPost msg = item->mPost; - msg.mMeta = item->meta; + RsPostedPost msg = postItem->mPost; + msg.mMeta = postItem->meta; msg.calculateScores(now); msgs.push_back(msg); - delete item; + delete postItem; } else { - std::cerr << "Not a PostedPostItem, deleting!" << std::endl; - delete *vit; + RsGxsCommentItem* cmtItem = dynamic_cast(*vit); + if(cmtItem) + { + RsGxsComment cmt; + RsGxsMsgItem *mi = (*vit); + cmt = cmtItem->mMsg; + cmt.mMeta = mi->meta; +#ifdef GXSCOMMENT_DEBUG + std::cerr << "p3Posted::getPostData Found Comment:" << std::endl; + cmt.print(std::cerr," ", "cmt"); +#endif + cmts.push_back(cmt); + delete cmtItem; + } + else + { + RsGxsMsgItem* msg = (*vit); + //const uint16_t RS_SERVICE_GXS_TYPE_CHANNELS = 0x0217; + //const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03; + //const uint8_t RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM = 0xf1; + std::cerr << "Not a PostedPostItem neither a RsGxsCommentItem" + << " PacketService=" << std::hex << (int)msg->PacketService() << std::dec + << " PacketSubType=" << std::hex << (int)msg->PacketSubType() << std::dec + << " , deleting!" << std::endl; + delete *vit; + } } } } } - + else + { + std::cerr << "p3GxsChannels::getPostData() ERROR in request"; + std::cerr << std::endl; + } + return ok; } diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index 63ef72d32..0cb2bcd74 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -63,7 +63,8 @@ virtual void receiveHelperChanges(std::vector& changes) // Posted Specific DataTypes. virtual bool getGroupData(const uint32_t &token, std::vector &groups); -virtual bool getPostData(const uint32_t &token, std::vector &posts); +virtual bool getPostData(const uint32_t &token, std::vector &posts, std::vector &cmts); +virtual bool getPostData(const uint32_t &token, std::vector &posts) { std::vector cmts; return getPostData( token, posts, cmts);} //Not currently used //virtual bool getRelatedPosts(const uint32_t &token, std::vector &posts); diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index b8bcd0994..19d13dd4a 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -84,6 +84,8 @@ void PostedItem::setup() ui->dateLabel->clear(); ui->fromLabel->clear(); ui->siteLabel->clear(); + ui->newCommentLabel->hide(); + ui->commLabel->hide(); /* general ones */ connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(removeItem())); @@ -160,21 +162,37 @@ void PostedItem::loadGroup(const uint32_t &token) void PostedItem::loadMessage(const uint32_t &token) { std::vector posts; - if (!rsPosted->getPostData(token, posts)) + std::vector cmts; + if (!rsPosted->getPostData(token, posts, cmts)) { std::cerr << "GxsChannelPostItem::loadMessage() ERROR getting data"; std::cerr << std::endl; return; } - if (posts.size() != 1) + if (posts.size() == 1) { - std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items"; + setPost(posts[0]); + } + else if (cmts.size() == 1) + { + RsGxsComment cmt = cmts[0]; + + ui->newCommentLabel->show(); + ui->commLabel->show(); + ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str())); + + //Change this item to be uploaded with thread element. + setMessageId(cmt.mMeta.mThreadId); + requestMessage(); + } + else + { + std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It."; std::cerr << std::endl; + removeItem(); return; } - - setPost(posts[0]); } void PostedItem::fill() @@ -390,15 +408,15 @@ void PostedItem::setReadStatus(bool isNew, bool isUnread) ui->newLabel->setVisible(isNew); /* unpolish widget to clear the stylesheet's palette cache */ - ui->frame->style()->unpolish(ui->frame); + ui->mainFrame->style()->unpolish(ui->mainFrame); - QPalette palette = ui->frame->palette(); - palette.setColor(ui->frame->backgroundRole(), isNew ? COLOR_NEW : COLOR_NORMAL); // QScrollArea + QPalette palette = ui->mainFrame->palette(); + palette.setColor(ui->mainFrame->backgroundRole(), isNew ? COLOR_NEW : COLOR_NORMAL); // QScrollArea palette.setColor(QPalette::Base, isNew ? COLOR_NEW : COLOR_NORMAL); // QTreeWidget - ui->frame->setPalette(palette); + ui->mainFrame->setPalette(palette); - ui->frame->setProperty("new", isNew); - Rshare::refreshStyleSheet(ui->frame, false); + ui->mainFrame->setProperty("new", isNew); + Rshare::refreshStyleSheet(ui->mainFrame, false); } void PostedItem::readToggled(bool checked) diff --git a/retroshare-gui/src/gui/Posted/PostedItem.ui b/retroshare-gui/src/gui/Posted/PostedItem.ui index a93d83b4d..8e150784f 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.ui +++ b/retroshare-gui/src/gui/Posted/PostedItem.ui @@ -13,9 +13,9 @@ - + - + 0 @@ -31,7 +31,7 @@ QFrame::Sunken - + @@ -59,9 +59,33 @@ true + + + + + 0 + + + + + New Comment: + + + true + + + + + + + Comment Value + + + + - + @@ -207,7 +231,7 @@ - + 0 @@ -297,21 +321,7 @@ - readAndClearButton - dateBoldLabel - dateLabel - fromBoldLabel - commentButton - newLabel - siteLabel - fromLabel - readButton - fromBoldLabel_2 - clearButton titleLabel - voteDownButton - voteUpButton - scoreLabel @@ -357,6 +367,12 @@ QLabel
gui/gxs/GxsIdLabel.h
+ + ElidedLabel + QLabel +
gui/common/ElidedLabel.h
+ 1 +
diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index 086d711eb..ea77307e2 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -269,8 +269,9 @@ void GxsChannelPostItem::loadMessage(const uint32_t &token) } else { - std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items"; + std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It."; std::cerr << std::endl; + removeItem(); return; } }