started improving Boards the same way than Channels. Not working yet

This commit is contained in:
csoler 2020-04-21 20:59:14 +02:00
parent 5120f693be
commit 958db27eaa
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
8 changed files with 165 additions and 203 deletions

View File

@ -40,43 +40,48 @@
/** Constructor */
PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) :
GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsPosted, autoUpdate)
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)
{
setup();
mPost.mMeta.mMsgId = post_id;
mPost.mMeta.mGroupId = mGroupMeta.mGroupId;
requestGroup();
requestMessage();
requestComment();
mLoaded = false;
setup();
}
PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate) :
GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, autoUpdate)
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)
{
setup();
mMessageId = post.mMeta.mMsgId;
mPost.mMeta.mMsgId = post_id;
mLoaded = false;
setGroup(group, false);
setPost(post);
requestComment();
}
PostedCardView::PostedCardView(FeedHolder *feedHolder, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate) :
GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, autoUpdate)
{
setup();
requestGroup();
setPost(post);
requestComment();
loadGroup();
}
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()
{
@ -125,23 +130,6 @@ void PostedCardView::setup()
ui->readAndClearButton->hide();
}
bool PostedCardView::setGroup(const RsPostedGroup &group, bool doFill)
{
if (groupId() != group.mMeta.mGroupId) {
std::cerr << "PostedCardView::setGroup() - Wrong id, cannot set post";
std::cerr << std::endl;
return false;
}
mGroup = group;
if (doFill) {
fill();
}
return true;
}
bool PostedCardView::setPost(const RsPostedPost &post, bool doFill)
{
if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) {
@ -192,7 +180,7 @@ void PostedCardView::loadGroup()
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */
setGroup(group);
mGroupMeta = group.mMeta;
}, this );
});
@ -218,7 +206,7 @@ void PostedCardView::loadMessage()
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 );
RsQThreadUtils::postToObject( [post,this]() { setPost(post,true); }, this );
}
else if(comments.size() == 1)
{
@ -461,19 +449,19 @@ void PostedCardView::fill()
emit sizeChanged(this);
}
const RsPostedPost &PostedCardView::getPost() const
{
return mPost;
}
//const RsPostedPost &PostedCardView::getPost() const
//{
// return mPost;
//}
RsPostedPost &PostedCardView::post()
{
return mPost;
}
//RsPostedPost &PostedCardView::post()
//{
// return mPost;
//}
QString PostedCardView::groupName()
{
return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str());
return QString::fromUtf8(mGroupMeta.mGroupName.c_str());
}
QString PostedCardView::messageName()
@ -586,11 +574,11 @@ void PostedCardView::doExpand(bool open)
void PostedCardView::copyMessageLink()
{
if (groupId().isNull() || mMessageId.isNull()) {
if (groupId().isNull() || messageId().isNull()) {
return;
}
RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), mMessageId, messageName());
RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName());
if (link.valid()) {
QList<RetroShareLink> urls;

View File

@ -38,22 +38,21 @@ class PostedCardView : public GxsFeedItem
Q_OBJECT
public:
PostedCardView(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate);
PostedCardView(FeedHolder *parent, uint32_t feedId, const RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate);
PostedCardView(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate);
PostedCardView(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId& messageId, bool isHome, bool autoUpdate);
PostedCardView(FeedHolder *parent, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId& post_id, bool isHome, bool autoUpdate);
virtual ~PostedCardView();
bool setGroup(const RsPostedGroup& group, bool doFill = true);
bool setPost(const RsPostedPost& post, bool doFill = true);
const RsPostedPost &getPost() const;
RsPostedPost &post();
const RsPostedPost &getPost() const { return mPost; }
//RsPostedPost& post();
uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + mMessageId.toStdString()); }
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();
@ -84,10 +83,10 @@ private:
private:
bool mInFill;
bool mLoaded;
RsPostedGroup mGroup;
RsGroupMetaData mGroupMeta;
RsPostedPost mPost;
RsGxsMessageId mMessageId;
/** Qt Designer generated object */
Ui::PostedCardView *ui;

View File

@ -41,37 +41,27 @@
/** Constructor */
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) :
GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsPosted, autoUpdate)
PostedItem::PostedItem(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)
{
setup();
mPost.mMeta.mMsgId = post_id;
mPost.mMeta.mGroupId = mGroupMeta.mGroupId;
requestGroup();
requestMessage();
requestComment();
mLoaded = false;
setup();
}
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate) :
GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, autoUpdate)
PostedItem::PostedItem(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();
mMessageId = post.mMeta.mMsgId;
setGroup(group, false);
setPost(post);
requestComment();
}
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate) :
GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, autoUpdate)
{
setup();
requestGroup();
setPost(post);
requestComment();
loadGroup();
}
PostedItem::~PostedItem()
@ -79,6 +69,23 @@ PostedItem::~PostedItem()
delete(ui);
}
void PostedItem::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 PostedItem::setup()
{
/* Invoke the Qt Designer generated object setup routine */
@ -137,23 +144,6 @@ void PostedItem::setup()
ui->nameLabel->hide();
}
bool PostedItem::setGroup(const RsPostedGroup &group, bool doFill)
{
if (groupId() != group.mMeta.mGroupId) {
std::cerr << "PostedItem::setGroup() - Wrong id, cannot set post";
std::cerr << std::endl;
return false;
}
mGroup = group;
if (doFill) {
fill();
}
return true;
}
bool PostedItem::setPost(const RsPostedPost &post, bool doFill)
{
if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) {
@ -204,7 +194,7 @@ void PostedItem::loadGroup()
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */
setGroup(group);
mGroupMeta = group.mMeta;
}, this );
});
@ -303,7 +293,7 @@ void PostedItem::loadComment()
void PostedItem::fill()
{
RetroShareLink link = RetroShareLink::createGxsGroupLink(RetroShareLink::TYPE_POSTED, mGroup.mMeta.mGroupId, groupName());
RetroShareLink link = RetroShareLink::createGxsGroupLink(RetroShareLink::TYPE_POSTED, mGroupMeta.mGroupId, groupName());
ui->nameLabel->setText(link.toHtml());
QPixmap sqpixmap2 = QPixmap(":/images/thumb-default.png");
@ -486,19 +476,9 @@ void PostedItem::fill()
emit sizeChanged(this);
}
const RsPostedPost &PostedItem::getPost() const
{
return mPost;
}
RsPostedPost &PostedItem::post()
{
return mPost;
}
QString PostedItem::groupName()
{
return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str());
return QString::fromUtf8(mGroupMeta.mGroupName.c_str());
}
QString PostedItem::messageName()
@ -619,11 +599,11 @@ void PostedItem::doExpand(bool open)
void PostedItem::copyMessageLink()
{
if (groupId().isNull() || mMessageId.isNull()) {
if (groupId().isNull() || messageId().isNull()) {
return;
}
RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), mMessageId, messageName());
RetroShareLink link = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_POSTED, groupId(), messageId(), messageName());
if (link.valid()) {
QList<RetroShareLink> urls;
@ -663,7 +643,7 @@ void PostedItem::viewPicture()
PView->setName(authorID);
PView->setTime(timestamp);
PView->setGroupId(groupId());
PView->setMessageId(mMessageId);
PView->setMessageId(messageId());
PView->show();

View File

@ -38,21 +38,21 @@ class PostedItem : 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 RsPostedGroup &group, const RsPostedPost &post, bool isHome, bool autoUpdate);
PostedItem(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome, bool autoUpdate);
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();
bool setGroup(const RsPostedGroup& group, bool doFill = true);
bool setPost(const RsPostedPost& post, bool doFill = true);
const RsPostedPost& getPost() const;
RsPostedPost &post();
const RsPostedPost& getPost() const { return mPost ; }
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();
@ -87,10 +87,10 @@ private:
private:
bool mInFill;
bool mLoaded;
RsPostedGroup mGroup;
RsGroupMetaData mGroupMeta;
RsPostedPost mPost;
RsGxsMessageId mMessageId;
/** Qt Designer generated object */
Ui::PostedItem *ui;

View File

@ -481,26 +481,22 @@ void PostedListWidget::insertPostedDetails(const RsPostedGroup &group)
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
void PostedListWidget::loadPost(const RsPostedPost &post)
void PostedListWidget::loadPost(const RsPostedPost& post)
{
/* Group is not always available because of the TokenQueue */
RsPostedGroup dummyGroup;
dummyGroup.mMeta.mGroupId = groupId();
PostedItem *item = new PostedItem(this, 0, dummyGroup, post, true, false);
PostedItem *item = new PostedItem(this, 0, mGroup.mMeta, post.mMeta.mMsgId, true, false);
connect(item, SIGNAL(vote(RsGxsGrpMsgIdPair,bool)), this, SLOT(submitVote(RsGxsGrpMsgIdPair,bool)));
mPosts.insert(post.mMeta.mMsgId, item);
mPostItems.push_back(item);
}
void PostedListWidget::loadPostCardView(const RsPostedPost &post)
void PostedListWidget::loadPostCardView(const RsPostedPost& post)
{
/* Group is not always available because of the TokenQueue */
RsPostedGroup dummyGroup;
dummyGroup.mMeta.mGroupId = groupId();
PostedCardView *cvitem = new PostedCardView(this, 0, dummyGroup, post, true, false);
PostedCardView *cvitem = new PostedCardView(this, 0, mGroup.mMeta, post.mMeta.mMsgId, true, false);
connect(cvitem, SIGNAL(vote(RsGxsGrpMsgIdPair,bool)), this, SLOT(submitVote(RsGxsGrpMsgIdPair,bool)));
mCVPosts.insert(post.mMeta.mMsgId, cvitem);
@ -928,7 +924,7 @@ void PostedListWidget::insertPostedPosts(const std::vector<RsPostedPost>& posts)
std::cerr << std::endl;
#endif
/* insert new entry */
loadPost(p);
//loadPost(p);
loadPostCardView(p);
}
}
@ -937,7 +933,7 @@ void PostedListWidget::insertPostedPosts(const std::vector<RsPostedPost>& posts)
QMap<RsGxsMessageId, PostedItem*>::iterator pit;
for(pit = mPosts.begin(); pit != mPosts.end(); ++pit)
{
(*pit)->post().calculateScores(now);
(*pit)->getPost().calculateScores(now);
}
applyRanking();
@ -1067,7 +1063,8 @@ bool PostedListWidget::getGroupData(RsGxsGenericGroupData*& data)
if(! rsPosted->getBoardsInfo(std::list<RsGxsGroupId>({groupId()}),groupInfo) || groupInfo.size() != 1)
return false;
data = new RsPostedGroup(groupInfo[0]);
mGroup = groupInfo[0];
data = new RsPostedGroup(mGroup);
return true;
}

View File

@ -23,6 +23,7 @@
#include <QMap>
#include "retroshare/rsposted.h"
#include "gui/gxs/GxsMessageFramePostWidget.h"
#include "gui/feeds/FeedHolder.h"
@ -127,6 +128,7 @@ private:
uint32_t mTokenTypeVote;
RsPostedGroup mGroup;
QMap<RsGxsMessageId, PostedItem*> mPosts;
QList<PostedItem*> mPostItems;

View File

@ -95,23 +95,23 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId,
// mPost = post ;
// }
void GxsChannelPostItem::init(const RsGxsMessageId& messageId,const std::set<RsGxsMessageId>& older_versions)
{
QVector<RsGxsMessageId> v;
//bool self = false;
for(std::set<RsGxsMessageId>::const_iterator it(older_versions.begin());it!=older_versions.end();++it)
v.push_back(*it) ;
if(older_versions.find(messageId) == older_versions.end())
v.push_back(messageId);
setMessageVersions(v) ;
setup();
mLoaded = false ;
}
// void GxsChannelPostItem::init(const RsGxsMessageId& messageId,const std::set<RsGxsMessageId>& older_versions)
// {
// QVector<RsGxsMessageId> v;
// //bool self = false;
//
// for(std::set<RsGxsMessageId>::const_iterator it(older_versions.begin());it!=older_versions.end();++it)
// v.push_back(*it) ;
//
// if(older_versions.find(messageId) == older_versions.end())
// v.push_back(messageId);
//
// setMessageVersions(v) ;
//
// setup();
//
// mLoaded = false ;
// }
void GxsChannelPostItem::paintEvent(QPaintEvent *e)
{
@ -267,6 +267,45 @@ void GxsChannelPostItem::loadComments()
comments(title);
}
void GxsChannelPostItem::loadGroup()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelGroupItem::loadGroup()";
std::cerr << std::endl;
#endif
RsThread::async([this]()
{
// 1 - get group data
std::vector<RsGxsChannelGroup> groups;
const std::list<RsGxsGroupId> groupIds = { groupId() };
if(!rsGxsChannels->getChannelsInfo(groupIds,groups)) // would be better to call channel Summaries for a single group
{
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
if (groups.size() != 1)
{
std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
RsGxsChannelGroup 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 GxsChannelPostItem::loadMessage()
{
#ifdef DEBUG_ITEM
@ -834,42 +873,4 @@ void GxsChannelPostItem::makeUpVote()
emit vote(msgId, true);
}
void GxsChannelPostItem::loadGroup()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelGroupItem::loadGroup()";
std::cerr << std::endl;
#endif
RsThread::async([this]()
{
// 1 - get group data
std::vector<RsGxsChannelGroup> groups;
const std::list<RsGxsGroupId> groupIds = { groupId() };
if(!rsGxsChannels->getChannelsInfo(groupIds,groups)) // would be better to call channel Summaries for a single group
{
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
if (groups.size() != 1)
{
std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
RsGxsChannelGroup 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 );
});
}

View File

@ -49,17 +49,12 @@ public:
GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData& group, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate, const std::set<RsGxsMessageId>& older_versions = std::set<RsGxsMessageId>());
// // This method can be called when additional information is known about the post. In this case, the widget will be initialized with some
// // minimap information from the post and completed when the use displays it, which shouldn't cost anything more.
//
// GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost& post, bool isHome, bool autoUpdate, const std::set<RsGxsMessageId>& older_versions = std::set<RsGxsMessageId>());
virtual ~GxsChannelPostItem();
uint64_t uniqueIdentifier() const override { return hash_64bits("GxsChannelPostItem " + messageId().toStdString()) ; }
bool setGroup(const RsGxsChannelGroup &group, bool doFill = true);
bool setPost(const RsGxsChannelPost &post, bool doFill = true);
bool setGroup(const RsGxsChannelGroup& group, bool doFill = true);
bool setPost(const RsGxsChannelPost& post, bool doFill = true);
void setFileCleanUpWarning(uint32_t time_left);
@ -72,7 +67,7 @@ public:
static uint64_t computeIdentifier(const RsGxsMessageId& msgid) { return hash64("GxsChannelPostItem " + msgid.toStdString()) ; }
protected:
void init(const RsGxsMessageId& messageId,const std::set<RsGxsMessageId>& older_versions);
//void init(const RsGxsMessageId& messageId,const std::set<RsGxsMessageId>& older_versions);
/* FeedItem */
virtual void doExpand(bool open);
@ -81,7 +76,7 @@ protected:
// This does nothing except triggering the loading of the post data and comments. This function is mainly used to detect
// when the post is actually made visible.
virtual void paintEvent(QPaintEvent *);
virtual void paintEvent(QPaintEvent *) override;
/* GxsGroupFeedItem */
virtual QString groupName();