diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index 19d13dd4a..8541e2c3e 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -44,6 +44,7 @@ PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroup requestGroup(); requestMessage(); + requestComment(); } PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate) : @@ -53,6 +54,7 @@ PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedGr setGroup(group, false); setPost(post); + requestComment(); } PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate) : @@ -62,6 +64,7 @@ PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedPo requestGroup(); setPost(post); + requestComment(); } PostedItem::~PostedItem() @@ -195,6 +198,26 @@ void PostedItem::loadMessage(const uint32_t &token) } } +void PostedItem::loadComment(const uint32_t &token) +{ + std::vector cmts; + if (!rsPosted->getRelatedComments(token, cmts)) + { + std::cerr << "GxsChannelPostItem::loadComment() ERROR getting data"; + std::cerr << std::endl; + return; + } + + size_t comNb = cmts.size(); + QString sComButText = tr("Comment"); + if (comNb == 1) { + sComButText = sComButText.append("(1)"); + } else if (comNb > 1) { + sComButText = tr("Comments").append("(%1)").arg(comNb); + } + ui->commentButton->setText(sComButText); +} + void PostedItem::fill() { if (isLoading()) { diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 46afc263c..2d2297a01 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -72,8 +72,9 @@ protected: virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; } /* GxsFeedItem */ - virtual void loadMessage(const uint32_t &token); virtual QString messageName(); + virtual void loadMessage(const uint32_t &token); + virtual void loadComment(const uint32_t &token); private: void setup(); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index ea77307e2..a3d3ba4bd 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -52,6 +52,7 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, requestGroup(); requestMessage(); + requestComment(); } GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup &group, const RsGxsChannelPost &post, bool isHome, bool autoUpdate) : @@ -66,6 +67,7 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, setGroup(group, false); setPost(post); + requestComment(); } GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, bool isHome, bool autoUpdate) : @@ -80,6 +82,7 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, requestGroup(); setPost(post); + requestComment(); } GxsChannelPostItem::~GxsChannelPostItem() @@ -276,6 +279,31 @@ void GxsChannelPostItem::loadMessage(const uint32_t &token) } } +void GxsChannelPostItem::loadComment(const uint32_t &token) +{ +#ifdef DEBUG_ITEM + std::cerr << "GxsChannelPostItem::loadComment()"; + std::cerr << std::endl; +#endif + + std::vector cmts; + if (!rsGxsChannels->getRelatedComments(token, cmts)) + { + std::cerr << "GxsChannelPostItem::loadComment() ERROR getting data"; + std::cerr << std::endl; + return; + } + + size_t comNb = cmts.size(); + QString sComButText = tr("Comment"); + if (comNb == 1) { + sComButText = sComButText.append("(1)"); + } else if (comNb > 1) { + sComButText = tr("Comments").append("(%1)").arg(comNb); + } + ui->commentButton->setText(sComButText); +} + void GxsChannelPostItem::fill() { /* fill in */ diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index 2c9194e21..8574f4e16 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -68,8 +68,9 @@ protected: virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; } /* GxsFeedItem */ - virtual void loadMessage(const uint32_t &token); virtual QString messageName(); + virtual void loadMessage(const uint32_t &token); + virtual void loadComment(const uint32_t &token); private slots: /* default stuff */ diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h index 9d9ec2006..19b98bc4a 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h @@ -63,8 +63,9 @@ protected: virtual bool isLoading(); /* GxsFeedItem */ - virtual void loadMessage(const uint32_t &token); virtual QString messageName(); + virtual void loadMessage(const uint32_t &token); + virtual void loadComment(const uint32_t &/*token*/){ return;} private slots: /* default stuff */ diff --git a/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp b/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp index 77b1463d9..328ae8bae 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp @@ -44,6 +44,7 @@ GxsFeedItem::GxsFeedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGro mMessageId = messageId; mTokenTypeMessage = nextTokenType(); + mTokenTypeComment = nextTokenType(); } GxsFeedItem::~GxsFeedItem() @@ -132,6 +133,37 @@ void GxsFeedItem::requestMessage() mLoadQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeMessage); } +void GxsFeedItem::requestComment() +{ +#ifdef DEBUG_ITEM + std::cerr << "GxsFeedItem::requestComment()"; + std::cerr << std::endl; +#endif + + if (!initLoadQueue()) { + return; + } + + if (mLoadQueue->activeRequestExist(mTokenTypeComment)) { + /* Request already running */ + return; + } + + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA; + opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST; + + RsGxsGrpMsgIdPair msgIdPair; + msgIdPair.first = groupId(); + msgIdPair.second = messageId(); + + std::vector msgIds; + msgIds.push_back(msgIdPair); + + uint32_t token; + mLoadQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeComment); +} + void GxsFeedItem::loadRequest(const TokenQueue *queue, const TokenRequest &req) { #ifdef DEBUG_ITEM @@ -144,6 +176,10 @@ void GxsFeedItem::loadRequest(const TokenQueue *queue, const TokenRequest &req) loadMessage(req.mToken); return; } + if (req.mUserType == mTokenTypeComment) { + loadComment(req.mToken); + return; + } } GxsGroupFeedItem::loadRequest(queue, req); diff --git a/retroshare-gui/src/gui/gxs/GxsFeedItem.h b/retroshare-gui/src/gui/gxs/GxsFeedItem.h index 7061a4ce8..9f62ada2a 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedItem.h +++ b/retroshare-gui/src/gui/gxs/GxsFeedItem.h @@ -42,9 +42,11 @@ public: protected: /* load message data */ void requestMessage(); + void requestComment(); - virtual void loadMessage(const uint32_t &token) = 0; virtual QString messageName() = 0; + virtual void loadMessage(const uint32_t &token) = 0; + virtual void loadComment(const uint32_t &token) = 0; /* GxsGroupFeedItem */ virtual bool isLoading(); @@ -60,6 +62,7 @@ protected slots: private: RsGxsMessageId mMessageId; uint32_t mTokenTypeMessage; + uint32_t mTokenTypeComment; }; Q_DECLARE_METATYPE(RsGxsMessageId)