Merge pull request #441 from PhenomRetroShare/Fix_PostedFeedItemWithComments

Fix Posted Feed Item when received comment.
This commit is contained in:
Cyril Soler 2016-07-22 20:39:55 -04:00 committed by GitHub
commit e5d9bd51e3
6 changed files with 112 additions and 42 deletions

View File

@ -83,6 +83,7 @@ virtual ~RsPosted() { return; }
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) = 0;
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts) = 0;
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
//Not currently used
//virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;

View File

@ -98,8 +98,13 @@ bool p3Posted::getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &g
return ok;
}
bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msgs)
bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msgs, std::vector<RsGxsComment> &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,31 +115,59 @@ bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msg
for(; mit != msgData.end(); ++mit)
{
RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; vit != msgItems.end(); ++vit)
{
RsGxsPostedPostItem* item = dynamic_cast<RsGxsPostedPostItem*>(*vit);
RsGxsPostedPostItem* postItem = dynamic_cast<RsGxsPostedPostItem*>(*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;
RsGxsCommentItem* cmtItem = dynamic_cast<RsGxsCommentItem*>(*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;
}

View File

@ -63,7 +63,8 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
// Posted Specific DataTypes.
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups);
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts);
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts);
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) { std::vector<RsGxsComment> cmts; return getPostData( token, posts, cmts);}
//Not currently used
//virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts);

View File

@ -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<RsPostedPost> posts;
if (!rsPosted->getPostData(token, posts))
std::vector<RsGxsComment> 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)

View File

@ -13,9 +13,9 @@
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="PostedItemVLayout">
<item>
<widget class="QFrame" name="frame">
<widget class="QFrame" name="mainFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -31,7 +31,7 @@
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="mainFrameVLayout">
<item>
<widget class="StyledLabel" name="titleLabel">
<property name="sizePolicy">
@ -61,7 +61,31 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="newCommHLayout">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="newCommentLabel">
<property name="text">
<string>New Comment:</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="ElidedLabel" name="commLabel">
<property name="text">
<string>Comment Value</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="buttonHLayout">
<item>
<widget class="StyledLabel" name="scoreLabel">
<property name="text">
@ -207,7 +231,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="fromBoldLabel_2">
<widget class="QLabel" name="siteBoldLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -297,21 +321,7 @@
</layout>
</item>
</layout>
<zorder>readAndClearButton</zorder>
<zorder>dateBoldLabel</zorder>
<zorder>dateLabel</zorder>
<zorder>fromBoldLabel</zorder>
<zorder>commentButton</zorder>
<zorder>newLabel</zorder>
<zorder>siteLabel</zorder>
<zorder>fromLabel</zorder>
<zorder>readButton</zorder>
<zorder>fromBoldLabel_2</zorder>
<zorder>clearButton</zorder>
<zorder>titleLabel</zorder>
<zorder>voteDownButton</zorder>
<zorder>voteUpButton</zorder>
<zorder>scoreLabel</zorder>
<zorder></zorder>
</widget>
</item>
@ -357,6 +367,12 @@
<extends>QLabel</extends>
<header>gui/gxs/GxsIdLabel.h</header>
</customwidget>
<customwidget>
<class>ElidedLabel</class>
<extends>QLabel</extends>
<header location="global">gui/common/ElidedLabel.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>

View File

@ -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;
}
}