fixing async loading of channels. To be tested.

This commit is contained in:
csoler 2017-07-03 23:21:31 +02:00
parent f0ed0dd471
commit d876bb721b
3 changed files with 80 additions and 28 deletions

View File

@ -46,16 +46,29 @@
#define COLOR_NORMAL QColor(248, 248, 248)
#define COLOR_NEW QColor(220, 236, 253)
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) :
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate,const std::set<RsGxsMessageId>& older_versions) :
GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsGxsChannels, autoUpdate)
{
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();
requestGroup();
requestMessage();
requestComment();
mLoaded = false ;
}
// This code has been suspended because it adds more complexity than usefulness.
// It was used to load a channel post where the post item is already known.
#ifdef SUSPENDED
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup &group, const RsGxsChannelPost &post, bool isHome, bool autoUpdate) :
GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, autoUpdate)
{
@ -82,9 +95,9 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId,
setup();
setGroup(group, false);
//requestGroup(); //Already have RsGxsChannelGroup
setPost(post);
requestComment();
setPost(post,false);
mLoaded = false ;
}
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, bool isHome, bool autoUpdate) :
@ -97,10 +110,30 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId,
setup();
mLoaded = true ;
requestGroup();
setPost(post);
requestComment();
}
#endif
void GxsChannelPostItem::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 ;
requestGroup();
requestMessage();
requestComment();
}
GxsFeedItem::paintEvent(e) ;
}
GxsChannelPostItem::~GxsChannelPostItem()
{
@ -349,6 +382,14 @@ void GxsChannelPostItem::fill()
QString title;
if(mPost.mThumbnail.mData != NULL)
{
QPixmap thumbnail;
thumbnail.loadFromData(mPost.mThumbnail.mData, mPost.mThumbnail.mSize, "PNG");
// Wiping data - as its been passed to thumbnail.
ui->logoLabel->setPixmap(thumbnail);
}
if (!mIsHome)
{
if (mCloseOnRead && !IS_MSG_NEW(mPost.mMeta.mMsgStatus)) {
@ -386,9 +427,12 @@ void GxsChannelPostItem::fill()
/* subject */
ui->titleLabel->setText(QString::fromUtf8(mPost.mMeta.mMsgName.c_str()));
uint32_t autorized_lines = (int)floor((ui->logoLabel->height() - ui->titleLabel->height() - ui->buttonHLayout->sizeHint().height())/QFontMetricsF(ui->subjectLabel->font()).height());
// fill first 4 lines of message. (csoler) Disabled the replacement of smileys and links, because the cost is too crazy
//ui->subjectLabel->setText(RsHtml().formatText(NULL, RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
ui->subjectLabel->setText(RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4)) ;
ui->subjectLabel->setText(RsHtml().formatText(NULL, RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), autorized_lines), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
//ui->subjectLabel->setText(RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 2)) ;
//QString score = QString::number(post.mTopScore);
// scoreLabel->setText(score);
@ -496,14 +540,6 @@ void GxsChannelPostItem::fill()
layout->addWidget(fi);
}
if(mPost.mThumbnail.mData != NULL)
{
QPixmap thumbnail;
thumbnail.loadFromData(mPost.mThumbnail.mData, mPost.mThumbnail.mSize, "PNG");
// Wiping data - as its been passed to thumbnail.
ui->logoLabel->setPixmap(thumbnail);
}
mInFill = false;
}

View File

@ -41,9 +41,14 @@ class GxsChannelPostItem : public GxsFeedItem
Q_OBJECT
public:
GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate);
GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup &group, const RsGxsChannelPost &post, bool isHome, bool autoUpdate);
GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, bool isHome, bool autoUpdate);
// This one is used in NewFeed for incoming channel posts. Only the group and msg ids are known at this point.
// It can be used for all apparences of channel posts. But in rder to merge comments from the previous versions of the post, the list of
// previous posts should be supplied. It's optional. If not supplied only the comments of the new version will be displayed.
GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate, const std::set<RsGxsMessageId>& older_versions = std::set<RsGxsMessageId>());
//GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup &group, const RsGxsChannelPost &post, bool isHome, bool autoUpdate);
//GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, bool isHome, bool autoUpdate);
virtual ~GxsChannelPostItem();
bool setGroup(const RsGxsChannelGroup &group, bool doFill = true);
@ -62,6 +67,11 @@ protected:
virtual void doExpand(bool open);
virtual void expandFill(bool first);
// 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 *);
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
@ -101,6 +111,7 @@ private:
private:
bool mInFill;
bool mCloseOnRead;
bool mLoaded;
RsGxsChannelGroup mGroup;
RsGxsChannelPost mPost;

View File

@ -407,10 +407,12 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost &post, bool re
if(item)
{
ui->feedWidget->removeFeedItem(item) ;
RsGxsChannelGroup dummyGroup;
dummyGroup.mMeta.mGroupId = groupId();
dummyGroup.mMeta.mSubscribeFlags = 0xffffffff;
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, dummyGroup, post, true, false);
//RsGxsChannelGroup dummyGroup;
//dummyGroup.mMeta.mGroupId = groupId();
//dummyGroup.mMeta.mSubscribeFlags = 0xffffffff;
//GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, dummyGroup, post, true, false);
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, post.mMeta.mGroupId, post.mMeta.mMsgId, true, false,post.mOlderVersions);
ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs));
return ;
@ -427,10 +429,13 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost &post, bool re
ui->feedWidget->setSort(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs));
} else {
/* Group is not always available because of the TokenQueue */
RsGxsChannelGroup dummyGroup;
dummyGroup.mMeta.mGroupId = groupId();
dummyGroup.mMeta.mSubscribeFlags = 0xffffffff;
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, dummyGroup, post, true, false);
//RsGxsChannelGroup dummyGroup;
//dummyGroup.mMeta.mGroupId = groupId();
//dummyGroup.mMeta.mSubscribeFlags = 0xffffffff;
//GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, dummyGroup, post, true, false);
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, post.mMeta.mGroupId, post.mMeta.mMsgId, true, false,post.mOlderVersions);
ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs));
}