Add Comment Number On Button.

This commit is contained in:
Phenom 2016-08-07 14:40:04 +02:00
parent dea776a61a
commit ea6bbac732
7 changed files with 97 additions and 4 deletions

View File

@ -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<RsGxsComment> 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()) {

View File

@ -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();

View File

@ -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<RsGxsComment> 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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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<RsGxsGrpMsgIdPair> 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);

View File

@ -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)