mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
splitted PostedCardView/PostedItem into 3 classes, one base and two UI classes, and factored as much as possible.
This commit is contained in:
parent
958db27eaa
commit
3f72f1ff09
@ -40,48 +40,80 @@
|
||||
|
||||
/** Constructor */
|
||||
|
||||
PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId &post_id, bool isHome, bool autoUpdate) :
|
||||
GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, post_id, isHome, rsPosted, autoUpdate),
|
||||
mGroupMeta(group_meta)
|
||||
PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId &post_id, bool isHome, bool autoUpdate)
|
||||
: BasePostedItem(feedHolder, feedId, group_meta, post_id, isHome, autoUpdate)
|
||||
{
|
||||
mPost.mMeta.mMsgId = post_id;
|
||||
mPost.mMeta.mGroupId = mGroupMeta.mGroupId;
|
||||
|
||||
mLoaded = false;
|
||||
setup();
|
||||
setup();
|
||||
}
|
||||
|
||||
PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) :
|
||||
GxsFeedItem(feedHolder, feedId, groupId, post_id, isHome, rsPosted, autoUpdate)
|
||||
PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate)
|
||||
: BasePostedItem(feedHolder, feedId, groupId, post_id, isHome, autoUpdate)
|
||||
{
|
||||
mPost.mMeta.mMsgId = post_id;
|
||||
mLoaded = false;
|
||||
|
||||
setup();
|
||||
|
||||
setup();
|
||||
loadGroup();
|
||||
}
|
||||
|
||||
void PostedCardView::setCommentsSize(int comNb)
|
||||
{
|
||||
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 PostedCardView::makeDownVote()
|
||||
{
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
|
||||
ui->voteUpButton->setEnabled(false);
|
||||
ui->voteDownButton->setEnabled(false);
|
||||
|
||||
emit vote(msgId, false);
|
||||
}
|
||||
|
||||
void PostedCardView::makeUpVote()
|
||||
{
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
|
||||
ui->voteUpButton->setEnabled(false);
|
||||
ui->voteDownButton->setEnabled(false);
|
||||
|
||||
emit vote(msgId, true);
|
||||
}
|
||||
|
||||
void PostedCardView::setReadStatus(bool isNew, bool isUnread)
|
||||
{
|
||||
if (isUnread)
|
||||
{
|
||||
ui->readButton->setChecked(true);
|
||||
ui->readButton->setIcon(QIcon(":/images/message-state-unread.png"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->readButton->setChecked(false);
|
||||
ui->readButton->setIcon(QIcon(":/images/message-state-read.png"));
|
||||
}
|
||||
|
||||
ui->newLabel->setVisible(isNew);
|
||||
|
||||
ui->mainFrame->setProperty("new", isNew);
|
||||
ui->mainFrame->style()->unpolish(ui->mainFrame);
|
||||
ui->mainFrame->style()->polish( ui->mainFrame);
|
||||
}
|
||||
|
||||
void PostedCardView::setComment(const RsGxsComment& cmt) {}
|
||||
|
||||
PostedCardView::~PostedCardView()
|
||||
{
|
||||
delete(ui);
|
||||
}
|
||||
void PostedCardView::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
/* This method employs a trick to trigger a deferred loading. The post and group is requested only
|
||||
* when actually displayed on the screen. */
|
||||
|
||||
if(!mLoaded)
|
||||
{
|
||||
mLoaded = true ;
|
||||
|
||||
fill();
|
||||
requestMessage();
|
||||
requestComment();
|
||||
}
|
||||
|
||||
GxsFeedItem::paintEvent(e) ;
|
||||
}
|
||||
|
||||
void PostedCardView::setup()
|
||||
{
|
||||
@ -130,144 +162,7 @@ void PostedCardView::setup()
|
||||
ui->readAndClearButton->hide();
|
||||
}
|
||||
|
||||
bool PostedCardView::setPost(const RsPostedPost &post, bool doFill)
|
||||
{
|
||||
if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) {
|
||||
std::cerr << "PostedCardView::setPost() - Wrong id, cannot set post";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
mPost = post;
|
||||
|
||||
if (doFill) {
|
||||
fill();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PostedCardView::loadGroup()
|
||||
{
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
||||
#ifdef DEBUG_FORUMS
|
||||
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
|
||||
#endif
|
||||
|
||||
std::vector<RsPostedGroup> groups;
|
||||
const std::list<RsGxsGroupId> groupIds = { groupId() };
|
||||
|
||||
if(!rsPosted->getBoardsInfo(groupIds,groups))
|
||||
{
|
||||
RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (groups.size() != 1)
|
||||
{
|
||||
std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
RsPostedGroup group(groups[0]);
|
||||
|
||||
RsQThreadUtils::postToObject( [group,this]()
|
||||
{
|
||||
/* Here it goes any code you want to be executed on the Qt Gui
|
||||
* thread, for example to update the data model with new information
|
||||
* after a blocking call to RetroShare API complete */
|
||||
|
||||
mGroupMeta = group.mMeta;
|
||||
|
||||
}, this );
|
||||
});
|
||||
}
|
||||
|
||||
void PostedCardView::loadMessage()
|
||||
{
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
||||
std::vector<RsPostedPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
|
||||
if(! rsPosted->getBoardContent( groupId(), std::set<RsGxsMessageId>( { messageId() } ),posts,comments))
|
||||
{
|
||||
RsErr() << "PostedItem::loadMessage() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (posts.size() == 1)
|
||||
{
|
||||
std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl;
|
||||
const RsPostedPost& post(posts[0]);
|
||||
|
||||
RsQThreadUtils::postToObject( [post,this]() { setPost(post,true); }, this );
|
||||
}
|
||||
else if(comments.size() == 1)
|
||||
{
|
||||
const RsGxsComment& cmt = comments[0];
|
||||
std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl;
|
||||
|
||||
RsQThreadUtils::postToObject( [cmt,this]()
|
||||
{
|
||||
//Change this item to be uploaded with thread element.
|
||||
setMessageId(cmt.mMeta.mThreadId);
|
||||
requestMessage();
|
||||
|
||||
}, this );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It.";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsQThreadUtils::postToObject( [this]() { removeItem(); }, this );
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void PostedCardView::loadComment()
|
||||
{
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
||||
std::set<RsGxsMessageId> msgIds;
|
||||
|
||||
for(auto MsgId: messageVersions())
|
||||
msgIds.insert(MsgId);
|
||||
|
||||
std::vector<RsPostedPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
|
||||
if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments))
|
||||
{
|
||||
RsErr() << "PostedCardView::loadGroup() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int comNb = comments.size();
|
||||
|
||||
RsQThreadUtils::postToObject( [comNb,this]()
|
||||
{
|
||||
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);
|
||||
|
||||
}, this );
|
||||
});
|
||||
}
|
||||
|
||||
void PostedCardView::fill()
|
||||
{
|
||||
@ -448,141 +343,4 @@ void PostedCardView::fill()
|
||||
|
||||
emit sizeChanged(this);
|
||||
}
|
||||
|
||||
//const RsPostedPost &PostedCardView::getPost() const
|
||||
//{
|
||||
// return mPost;
|
||||
//}
|
||||
|
||||
//RsPostedPost &PostedCardView::post()
|
||||
//{
|
||||
// return mPost;
|
||||
//}
|
||||
|
||||
QString PostedCardView::groupName()
|
||||
{
|
||||
return QString::fromUtf8(mGroupMeta.mGroupName.c_str());
|
||||
}
|
||||
|
||||
QString PostedCardView::messageName()
|
||||
{
|
||||
return QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
||||
}
|
||||
|
||||
void PostedCardView::makeDownVote()
|
||||
{
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
|
||||
ui->voteUpButton->setEnabled(false);
|
||||
ui->voteDownButton->setEnabled(false);
|
||||
|
||||
emit vote(msgId, false);
|
||||
}
|
||||
|
||||
void PostedCardView::makeUpVote()
|
||||
{
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
|
||||
ui->voteUpButton->setEnabled(false);
|
||||
ui->voteDownButton->setEnabled(false);
|
||||
|
||||
emit vote(msgId, true);
|
||||
}
|
||||
|
||||
void PostedCardView::loadComments()
|
||||
{
|
||||
std::cerr << "PostedCardView::loadComments()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (mFeedHolder)
|
||||
{
|
||||
QString title = QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
||||
|
||||
#warning (csoler) Posted item versions not handled yet. When it is the case, start here.
|
||||
|
||||
QVector<RsGxsMessageId> post_versions ;
|
||||
post_versions.push_back(mPost.mMeta.mMsgId) ;
|
||||
|
||||
mFeedHolder->openComments(0, mPost.mMeta.mGroupId, post_versions,mPost.mMeta.mMsgId, title);
|
||||
}
|
||||
}
|
||||
|
||||
void PostedCardView::setReadStatus(bool isNew, bool isUnread)
|
||||
{
|
||||
if (isUnread)
|
||||
{
|
||||
ui->readButton->setChecked(true);
|
||||
ui->readButton->setIcon(QIcon(":/images/message-state-unread.png"));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->readButton->setChecked(false);
|
||||
ui->readButton->setIcon(QIcon(":/images/message-state-read.png"));
|
||||
}
|
||||
|
||||
ui->newLabel->setVisible(isNew);
|
||||
|
||||
ui->mainFrame->setProperty("new", isNew);
|
||||
ui->mainFrame->style()->unpolish(ui->mainFrame);
|
||||
ui->mainFrame->style()->polish( ui->mainFrame);
|
||||
}
|
||||
|
||||
void PostedCardView::readToggled(bool checked)
|
||||
{
|
||||
if (mInFill) {
|
||||
return;
|
||||
}
|
||||
|
||||
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
|
||||
|
||||
uint32_t token;
|
||||
rsPosted->setMessageReadStatus(token, msgPair, !checked);
|
||||
|
||||
setReadStatus(false, checked);
|
||||
}
|
||||
|
||||
void PostedCardView::readAndClearItem()
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "PostedCardView::readAndClearItem()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
readToggled(false);
|
||||
removeItem();
|
||||
}
|
||||
|
||||
|
||||
void PostedCardView::doExpand(bool open)
|
||||
{
|
||||
/*if (open)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
emit sizeChanged(this);*/
|
||||
|
||||
}
|
||||
|
||||
void PostedCardView::copyMessageLink()
|
||||
{
|
||||
if (groupId().isNull() || messageId().isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName());
|
||||
|
||||
if (link.valid()) {
|
||||
QList<RetroShareLink> urls;
|
||||
urls.push_back(link);
|
||||
RSLinkClipboard::copyLinks(urls);
|
||||
}
|
||||
}
|
||||
void PostedCardView::toggleNotes() {}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <QMetaType>
|
||||
|
||||
#include <retroshare/rsposted.h>
|
||||
#include "gui/gxs/GxsFeedItem.h"
|
||||
#include "PostedItem.h"
|
||||
|
||||
namespace Ui {
|
||||
class PostedCardView;
|
||||
@ -33,7 +33,7 @@ class PostedCardView;
|
||||
class FeedHolder;
|
||||
class RsPostedPost;
|
||||
|
||||
class PostedCardView : public GxsFeedItem
|
||||
class PostedCardView : public BasePostedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -42,52 +42,21 @@ public:
|
||||
PostedCardView(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate);
|
||||
virtual ~PostedCardView();
|
||||
|
||||
bool setPost(const RsPostedPost& post, bool doFill = true);
|
||||
|
||||
const RsPostedPost &getPost() const { return mPost; }
|
||||
//RsPostedPost& post();
|
||||
|
||||
uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + messageId().toStdString()); }
|
||||
|
||||
protected:
|
||||
/* FeedItem */
|
||||
virtual void doExpand(bool open);
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
private slots:
|
||||
void loadComments();
|
||||
void makeUpVote();
|
||||
void makeDownVote();
|
||||
void readToggled(bool checked);
|
||||
void readAndClearItem();
|
||||
void copyMessageLink();
|
||||
|
||||
signals:
|
||||
void vote(const RsGxsGrpMsgIdPair& msgId, bool up);
|
||||
|
||||
protected:
|
||||
/* GxsGroupFeedItem */
|
||||
virtual QString groupName();
|
||||
virtual void loadGroup() override;
|
||||
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; }
|
||||
|
||||
/* GxsFeedItem */
|
||||
virtual QString messageName();
|
||||
virtual void loadMessage();
|
||||
virtual void loadComment();
|
||||
void setup() override;
|
||||
void fill() override;
|
||||
void doExpand(bool open) override {}
|
||||
void setComment(const RsGxsComment&) override;
|
||||
void setReadStatus(bool isNew, bool isUnread) override;
|
||||
void toggle() override {}
|
||||
void setCommentsSize(int comNb) override;
|
||||
void makeUpVote() override;
|
||||
void makeDownVote() override;
|
||||
void toggleNotes() override;
|
||||
|
||||
private:
|
||||
void setup();
|
||||
void fill();
|
||||
void setReadStatus(bool isNew, bool isUnread);
|
||||
|
||||
private:
|
||||
bool mInFill;
|
||||
bool mLoaded;
|
||||
|
||||
RsGroupMetaData mGroupMeta;
|
||||
RsPostedPost mPost;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::PostedCardView *ui;
|
||||
};
|
||||
|
@ -41,35 +41,27 @@
|
||||
|
||||
/** Constructor */
|
||||
|
||||
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) :
|
||||
//========================================================================================
|
||||
// BasePostedItem //
|
||||
//========================================================================================
|
||||
|
||||
BasePostedItem::BasePostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) :
|
||||
GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, post_id, isHome, rsPosted, autoUpdate),
|
||||
mGroupMeta(group_meta)
|
||||
{
|
||||
mPost.mMeta.mMsgId = post_id;
|
||||
mPost.mMeta.mGroupId = mGroupMeta.mGroupId;
|
||||
|
||||
mLoaded = false;
|
||||
|
||||
setup();
|
||||
}
|
||||
|
||||
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) :
|
||||
BasePostedItem::BasePostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) :
|
||||
GxsFeedItem(feedHolder, feedId, groupId, post_id, isHome, rsPosted, autoUpdate)
|
||||
{
|
||||
mPost.mMeta.mMsgId = post_id;
|
||||
|
||||
mLoaded = false;
|
||||
|
||||
setup();
|
||||
loadGroup();
|
||||
}
|
||||
|
||||
PostedItem::~PostedItem()
|
||||
{
|
||||
delete(ui);
|
||||
}
|
||||
|
||||
void PostedItem::paintEvent(QPaintEvent *e)
|
||||
void BasePostedItem::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
/* This method employs a trick to trigger a deferred loading. The post and group is requested only
|
||||
* when actually displayed on the screen. */
|
||||
@ -78,7 +70,6 @@ void PostedItem::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
mLoaded = true ;
|
||||
|
||||
fill();
|
||||
requestMessage();
|
||||
requestComment();
|
||||
}
|
||||
@ -86,6 +77,254 @@ void PostedItem::paintEvent(QPaintEvent *e)
|
||||
GxsFeedItem::paintEvent(e) ;
|
||||
}
|
||||
|
||||
bool BasePostedItem::setPost(const RsPostedPost &post, bool doFill)
|
||||
{
|
||||
if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) {
|
||||
std::cerr << "BasePostedItem::setPost() - Wrong id, cannot set post";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
mPost = post;
|
||||
|
||||
if (doFill)
|
||||
fill();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BasePostedItem::loadGroup()
|
||||
{
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
||||
#ifdef DEBUG_FORUMS
|
||||
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
|
||||
#endif
|
||||
|
||||
std::vector<RsPostedGroup> groups;
|
||||
const std::list<RsGxsGroupId> groupIds = { groupId() };
|
||||
|
||||
if(!rsPosted->getBoardsInfo(groupIds,groups))
|
||||
{
|
||||
RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (groups.size() != 1)
|
||||
{
|
||||
std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
RsPostedGroup group(groups[0]);
|
||||
|
||||
RsQThreadUtils::postToObject( [group,this]()
|
||||
{
|
||||
/* Here it goes any code you want to be executed on the Qt Gui
|
||||
* thread, for example to update the data model with new information
|
||||
* after a blocking call to RetroShare API complete */
|
||||
|
||||
mGroupMeta = group.mMeta;
|
||||
|
||||
}, this );
|
||||
});
|
||||
}
|
||||
|
||||
void BasePostedItem::loadMessage()
|
||||
{
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
||||
std::vector<RsPostedPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
|
||||
if(! rsPosted->getBoardContent( groupId(), std::set<RsGxsMessageId>( { messageId() } ),posts,comments))
|
||||
{
|
||||
RsErr() << "BasePostedItem::loadMessage() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (posts.size() == 1)
|
||||
{
|
||||
std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl;
|
||||
const RsPostedPost& post(posts[0]);
|
||||
|
||||
RsQThreadUtils::postToObject( [post,this]() { setPost(post,true); }, this );
|
||||
}
|
||||
else if(comments.size() == 1)
|
||||
{
|
||||
const RsGxsComment& cmt = comments[0];
|
||||
std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl;
|
||||
|
||||
RsQThreadUtils::postToObject( [cmt,this]()
|
||||
{
|
||||
setComment(cmt);
|
||||
|
||||
//Change this item to be uploaded with thread element.
|
||||
setMessageId(cmt.mMeta.mThreadId);
|
||||
requestMessage();
|
||||
|
||||
}, this );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It.";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsQThreadUtils::postToObject( [this]() { removeItem(); }, this );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void BasePostedItem::loadComment()
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "GxsChannelPostItem::loadComment()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
||||
std::set<RsGxsMessageId> msgIds;
|
||||
|
||||
for(auto MsgId: messageVersions())
|
||||
msgIds.insert(MsgId);
|
||||
|
||||
std::vector<RsPostedPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
|
||||
if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments))
|
||||
{
|
||||
RsErr() << "BasePostedItem::loadGroup() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int comNb = comments.size();
|
||||
|
||||
RsQThreadUtils::postToObject( [comNb,this]()
|
||||
{
|
||||
setCommentsSize(comNb);
|
||||
|
||||
}, this );
|
||||
});
|
||||
}
|
||||
|
||||
QString BasePostedItem::groupName()
|
||||
{
|
||||
return QString::fromUtf8(mGroupMeta.mGroupName.c_str());
|
||||
}
|
||||
|
||||
QString BasePostedItem::messageName()
|
||||
{
|
||||
return QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
||||
}
|
||||
|
||||
void BasePostedItem::loadComments()
|
||||
{
|
||||
std::cerr << "BasePostedItem::loadComments()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (mFeedHolder)
|
||||
{
|
||||
QString title = QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
||||
|
||||
#warning (csoler) Posted item versions not handled yet. When it is the case, start here.
|
||||
|
||||
QVector<RsGxsMessageId> post_versions ;
|
||||
post_versions.push_back(mPost.mMeta.mMsgId) ;
|
||||
|
||||
mFeedHolder->openComments(0, mPost.mMeta.mGroupId, post_versions,mPost.mMeta.mMsgId, title);
|
||||
}
|
||||
}
|
||||
void BasePostedItem::readToggled(bool checked)
|
||||
{
|
||||
if (mInFill) {
|
||||
return;
|
||||
}
|
||||
|
||||
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
|
||||
|
||||
uint32_t token;
|
||||
rsPosted->setMessageReadStatus(token, msgPair, !checked);
|
||||
|
||||
setReadStatus(false, checked);
|
||||
}
|
||||
|
||||
void BasePostedItem::readAndClearItem()
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "BasePostedItem::readAndClearItem()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
readToggled(false);
|
||||
removeItem();
|
||||
}
|
||||
void BasePostedItem::copyMessageLink()
|
||||
{
|
||||
if (groupId().isNull() || messageId().isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName());
|
||||
|
||||
if (link.valid()) {
|
||||
QList<RetroShareLink> urls;
|
||||
urls.push_back(link);
|
||||
RSLinkClipboard::copyLinks(urls);
|
||||
}
|
||||
}
|
||||
|
||||
void BasePostedItem::viewPicture()
|
||||
{
|
||||
if(mPost.mImage.mData == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString timestamp = misc::timeRelativeToNow(mPost.mMeta.mPublishTs);
|
||||
QPixmap pixmap;
|
||||
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
|
||||
RsGxsId authorID = mPost.mMeta.mAuthorId;
|
||||
|
||||
PhotoView *PView = new PhotoView(this);
|
||||
|
||||
PView->setPixmap(pixmap);
|
||||
PView->setTitle(messageName());
|
||||
PView->setName(authorID);
|
||||
PView->setTime(timestamp);
|
||||
PView->setGroupId(groupId());
|
||||
PView->setMessageId(messageId());
|
||||
|
||||
PView->show();
|
||||
|
||||
/* window will destroy itself! */
|
||||
}
|
||||
|
||||
//========================================================================================
|
||||
// PostedItem //
|
||||
//========================================================================================
|
||||
|
||||
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData &group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) :
|
||||
BasePostedItem(feedHolder, feedId, group_meta, post_id, isHome, autoUpdate)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
|
||||
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate) :
|
||||
BasePostedItem(feedHolder, feedId, groupId, post_id, isHome, autoUpdate)
|
||||
{
|
||||
setup();
|
||||
loadGroup();
|
||||
}
|
||||
|
||||
|
||||
void PostedItem::setup()
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
@ -144,151 +383,47 @@ void PostedItem::setup()
|
||||
ui->nameLabel->hide();
|
||||
}
|
||||
|
||||
bool PostedItem::setPost(const RsPostedPost &post, bool doFill)
|
||||
void PostedItem::makeDownVote()
|
||||
{
|
||||
if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) {
|
||||
std::cerr << "PostedItem::setPost() - Wrong id, cannot set post";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
|
||||
mPost = post;
|
||||
ui->voteUpButton->setEnabled(false);
|
||||
ui->voteDownButton->setEnabled(false);
|
||||
|
||||
if (doFill) {
|
||||
fill();
|
||||
}
|
||||
|
||||
return true;
|
||||
emit vote(msgId, false);
|
||||
}
|
||||
|
||||
void PostedItem::loadGroup()
|
||||
void PostedItem::makeUpVote()
|
||||
{
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
|
||||
#ifdef DEBUG_FORUMS
|
||||
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
|
||||
#endif
|
||||
ui->voteUpButton->setEnabled(false);
|
||||
ui->voteDownButton->setEnabled(false);
|
||||
|
||||
std::vector<RsPostedGroup> groups;
|
||||
const std::list<RsGxsGroupId> groupIds = { groupId() };
|
||||
|
||||
if(!rsPosted->getBoardsInfo(groupIds,groups))
|
||||
{
|
||||
RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (groups.size() != 1)
|
||||
{
|
||||
std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
RsPostedGroup group(groups[0]);
|
||||
|
||||
RsQThreadUtils::postToObject( [group,this]()
|
||||
{
|
||||
/* Here it goes any code you want to be executed on the Qt Gui
|
||||
* thread, for example to update the data model with new information
|
||||
* after a blocking call to RetroShare API complete */
|
||||
|
||||
mGroupMeta = group.mMeta;
|
||||
|
||||
}, this );
|
||||
});
|
||||
emit vote(msgId, true);
|
||||
}
|
||||
|
||||
void PostedItem::loadMessage()
|
||||
|
||||
|
||||
void PostedItem::setComment(const RsGxsComment& cmt)
|
||||
{
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
||||
std::vector<RsPostedPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
|
||||
if(! rsPosted->getBoardContent( groupId(), std::set<RsGxsMessageId>( { messageId() } ),posts,comments))
|
||||
{
|
||||
RsErr() << "PostedItem::loadMessage() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (posts.size() == 1)
|
||||
{
|
||||
std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl;
|
||||
const RsPostedPost& post(posts[0]);
|
||||
|
||||
RsQThreadUtils::postToObject( [post,this]() { setPost(post); }, this );
|
||||
}
|
||||
else if(comments.size() == 1)
|
||||
{
|
||||
const RsGxsComment& cmt = comments[0];
|
||||
std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl;
|
||||
|
||||
RsQThreadUtils::postToObject( [cmt,this]()
|
||||
{
|
||||
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();
|
||||
|
||||
}, this );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It.";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsQThreadUtils::postToObject( [this]() { removeItem(); }, this );
|
||||
}
|
||||
});
|
||||
ui->newCommentLabel->show();
|
||||
ui->commLabel->show();
|
||||
ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str()));
|
||||
}
|
||||
|
||||
void PostedItem::loadComment()
|
||||
void PostedItem::setCommentsSize(int comNb)
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "GxsChannelPostItem::loadComment()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
QString sComButText = tr("Comment");
|
||||
if (comNb == 1)
|
||||
sComButText = sComButText.append("(1)");
|
||||
else if(comNb > 1)
|
||||
sComButText = tr("Comments ").append("(%1)").arg(comNb);
|
||||
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
||||
std::set<RsGxsMessageId> msgIds;
|
||||
|
||||
for(auto MsgId: messageVersions())
|
||||
msgIds.insert(MsgId);
|
||||
|
||||
std::vector<RsPostedPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
|
||||
if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments))
|
||||
{
|
||||
RsErr() << "PostedItem::loadGroup() ERROR getting data" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int comNb = comments.size();
|
||||
|
||||
RsQThreadUtils::postToObject( [comNb,this]()
|
||||
{
|
||||
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);
|
||||
|
||||
}, this );
|
||||
});
|
||||
ui->commentButton->setText(sComButText);
|
||||
}
|
||||
|
||||
void PostedItem::fill()
|
||||
@ -317,6 +452,7 @@ void PostedItem::fill()
|
||||
QUrl url = QUrl::fromEncoded(urlarray.trimmed());
|
||||
QString urlstr = "Invalid Link";
|
||||
QString sitestr = "Invalid Link";
|
||||
|
||||
bool urlOkay = url.isValid();
|
||||
if (urlOkay)
|
||||
{
|
||||
@ -476,57 +612,6 @@ void PostedItem::fill()
|
||||
emit sizeChanged(this);
|
||||
}
|
||||
|
||||
QString PostedItem::groupName()
|
||||
{
|
||||
return QString::fromUtf8(mGroupMeta.mGroupName.c_str());
|
||||
}
|
||||
|
||||
QString PostedItem::messageName()
|
||||
{
|
||||
return QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
||||
}
|
||||
|
||||
void PostedItem::makeDownVote()
|
||||
{
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
|
||||
ui->voteUpButton->setEnabled(false);
|
||||
ui->voteDownButton->setEnabled(false);
|
||||
|
||||
emit vote(msgId, false);
|
||||
}
|
||||
|
||||
void PostedItem::makeUpVote()
|
||||
{
|
||||
RsGxsGrpMsgIdPair msgId;
|
||||
msgId.first = mPost.mMeta.mGroupId;
|
||||
msgId.second = mPost.mMeta.mMsgId;
|
||||
|
||||
ui->voteUpButton->setEnabled(false);
|
||||
ui->voteDownButton->setEnabled(false);
|
||||
|
||||
emit vote(msgId, true);
|
||||
}
|
||||
|
||||
void PostedItem::loadComments()
|
||||
{
|
||||
std::cerr << "PostedItem::loadComments()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
if (mFeedHolder)
|
||||
{
|
||||
QString title = QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
||||
|
||||
#warning (csoler) Posted item versions not handled yet. When it is the case, start here.
|
||||
|
||||
QVector<RsGxsMessageId> post_versions ;
|
||||
post_versions.push_back(mPost.mMeta.mMsgId) ;
|
||||
|
||||
mFeedHolder->openComments(0, mPost.mMeta.mGroupId, post_versions,mPost.mMeta.mMsgId, title);
|
||||
}
|
||||
}
|
||||
|
||||
void PostedItem::setReadStatus(bool isNew, bool isUnread)
|
||||
{
|
||||
@ -548,30 +633,6 @@ void PostedItem::setReadStatus(bool isNew, bool isUnread)
|
||||
ui->mainFrame->style()->polish( ui->mainFrame);
|
||||
}
|
||||
|
||||
void PostedItem::readToggled(bool checked)
|
||||
{
|
||||
if (mInFill) {
|
||||
return;
|
||||
}
|
||||
|
||||
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
|
||||
|
||||
uint32_t token;
|
||||
rsPosted->setMessageReadStatus(token, msgPair, !checked);
|
||||
|
||||
setReadStatus(false, checked);
|
||||
}
|
||||
|
||||
void PostedItem::readAndClearItem()
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "PostedItem::readAndClearItem()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
readToggled(false);
|
||||
removeItem();
|
||||
}
|
||||
|
||||
void PostedItem::toggle()
|
||||
{
|
||||
@ -597,21 +658,6 @@ void PostedItem::doExpand(bool open)
|
||||
|
||||
}
|
||||
|
||||
void PostedItem::copyMessageLink()
|
||||
{
|
||||
if (groupId().isNull() || messageId().isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName());
|
||||
|
||||
if (link.valid()) {
|
||||
QList<RetroShareLink> urls;
|
||||
urls.push_back(link);
|
||||
RSLinkClipboard::copyLinks(urls);
|
||||
}
|
||||
}
|
||||
|
||||
void PostedItem::toggleNotes()
|
||||
{
|
||||
if (ui->notesButton->isChecked())
|
||||
@ -625,27 +671,4 @@ void PostedItem::toggleNotes()
|
||||
|
||||
}
|
||||
|
||||
void PostedItem::viewPicture()
|
||||
{
|
||||
if(mPost.mImage.mData == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString timestamp = misc::timeRelativeToNow(mPost.mMeta.mPublishTs);
|
||||
QPixmap pixmap;
|
||||
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
|
||||
RsGxsId authorID = mPost.mMeta.mAuthorId;
|
||||
|
||||
PhotoView *PView = new PhotoView(this);
|
||||
|
||||
PView->setPixmap(pixmap);
|
||||
PView->setTitle(messageName());
|
||||
PView->setName(authorID);
|
||||
PView->setTime(timestamp);
|
||||
PView->setGroupId(groupId());
|
||||
PView->setMessageId(messageId());
|
||||
|
||||
PView->show();
|
||||
|
||||
/* window will destroy itself! */
|
||||
}
|
||||
|
@ -33,15 +33,14 @@ class PostedItem;
|
||||
class FeedHolder;
|
||||
class RsPostedPost;
|
||||
|
||||
class PostedItem : public GxsFeedItem
|
||||
class BasePostedItem : public GxsFeedItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate);
|
||||
PostedItem(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate);
|
||||
|
||||
virtual ~PostedItem();
|
||||
BasePostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate);
|
||||
BasePostedItem(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate);
|
||||
virtual ~BasePostedItem()=default;
|
||||
|
||||
bool setPost(const RsPostedPost& post, bool doFill = true);
|
||||
|
||||
@ -49,26 +48,21 @@ public:
|
||||
RsPostedPost& getPost() { return mPost ; }
|
||||
|
||||
uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + messageId().toStdString()); }
|
||||
protected:
|
||||
/* FeedItem */
|
||||
virtual void doExpand(bool open);
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
|
||||
private slots:
|
||||
void loadComments();
|
||||
void makeUpVote();
|
||||
void makeDownVote();
|
||||
void readToggled(bool checked);
|
||||
void readAndClearItem();
|
||||
void toggle() override;
|
||||
void copyMessageLink();
|
||||
void toggleNotes();
|
||||
void viewPicture();
|
||||
|
||||
signals:
|
||||
void vote(const RsGxsGrpMsgIdPair& msgId, bool up);
|
||||
|
||||
protected:
|
||||
/* FeedItem */
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
|
||||
/* GxsGroupFeedItem */
|
||||
virtual QString groupName();
|
||||
virtual void loadGroup() override;
|
||||
@ -80,18 +74,43 @@ protected:
|
||||
virtual void loadMessage();
|
||||
virtual void loadComment();
|
||||
|
||||
private:
|
||||
void setup();
|
||||
void fill();
|
||||
void setReadStatus(bool isNew, bool isUnread);
|
||||
|
||||
private:
|
||||
bool mInFill;
|
||||
bool mLoaded;
|
||||
|
||||
RsGroupMetaData mGroupMeta;
|
||||
RsPostedPost mPost;
|
||||
|
||||
virtual void setup()=0;
|
||||
virtual void fill()=0;
|
||||
virtual void doExpand(bool open)=0;
|
||||
virtual void setComment(const RsGxsComment&)=0;
|
||||
virtual void setReadStatus(bool isNew, bool isUnread)=0;
|
||||
virtual void setCommentsSize(int comNb)=0;
|
||||
virtual void makeUpVote()=0;
|
||||
virtual void makeDownVote()=0;
|
||||
virtual void toggleNotes()=0;
|
||||
|
||||
private:
|
||||
bool mLoaded;
|
||||
};
|
||||
|
||||
class PostedItem: public BasePostedItem
|
||||
{
|
||||
public:
|
||||
PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate);
|
||||
PostedItem(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate);
|
||||
|
||||
protected:
|
||||
void setup() override;
|
||||
void fill() override;
|
||||
void doExpand(bool open) override;
|
||||
void setComment(const RsGxsComment&) override;
|
||||
void setReadStatus(bool isNew, bool isUnread) override;
|
||||
void toggle() override ;
|
||||
void setCommentsSize(int comNb) override;
|
||||
void makeUpVote() override;
|
||||
void makeDownVote() override;
|
||||
void toggleNotes() override;
|
||||
|
||||
private:
|
||||
/** Qt Designer generated object */
|
||||
Ui::PostedItem *ui;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user