Merge pull request #917 from csoler/v0.6-ImprovedGUI

attempt to delay channel post loading on demand when displayed
This commit is contained in:
csoler 2017-07-03 21:54:22 +02:00 committed by GitHub
commit f5abf54aaf
3 changed files with 48 additions and 16 deletions

View File

@ -51,11 +51,13 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId,
{
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 +84,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 +99,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()
{

View File

@ -41,9 +41,11 @@ class GxsChannelPostItem : public GxsFeedItem
Q_OBJECT
public:
// This one is used in NewFeed for incoming channel posts. Only the group and msg ids are known at this point.
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);
//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 +64,8 @@ protected:
virtual void doExpand(bool open);
virtual void expandFill(bool first);
virtual void paintEvent(QPaintEvent *);
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
@ -101,6 +105,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, true);
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, true);
ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs));
}