mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 07:29:33 -05:00
Fix PostedItem loading thread.
Wait loading is finished before destruct.
This commit is contained in:
parent
cfcd68e661
commit
c268f998e6
@ -36,6 +36,8 @@
|
||||
#include "ui_PostedItem.h"
|
||||
|
||||
#include <retroshare/rsposted.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
#define LINK_IMAGE ":/images/thumb-link.png"
|
||||
@ -46,20 +48,40 @@
|
||||
// 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)
|
||||
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)
|
||||
, mInFill(false), mGroupMeta(group_meta)
|
||||
, mLoaded(false), mIsLoadingGroup(false), mIsLoadingMessage(false), mIsLoadingComment(false)
|
||||
{
|
||||
mPost.mMeta.mMsgId = post_id;
|
||||
mPost.mMeta.mGroupId = mGroupMeta.mGroupId;
|
||||
mLoaded = false;
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
, mInFill(false)
|
||||
, mLoaded(false), mIsLoadingGroup(false), mIsLoadingMessage(false), mIsLoadingComment(false)
|
||||
{
|
||||
mPost.mMeta.mMsgId = post_id;
|
||||
mLoaded = false;
|
||||
}
|
||||
|
||||
BasePostedItem::~BasePostedItem()
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(200);
|
||||
while( (mIsLoadingGroup || mIsLoadingMessage || mIsLoadingComment)
|
||||
&& std::chrono::steady_clock::now() < timeout)
|
||||
{
|
||||
RsDbg() << __PRETTY_FUNCTION__ << " is Waiting "
|
||||
<< (mIsLoadingGroup ? "Group " : "")
|
||||
<< (mIsLoadingMessage ? "Message " : "")
|
||||
<< (mIsLoadingComment ? "Comment " : "")
|
||||
<< "loading finished." << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
void BasePostedItem::paintEvent(QPaintEvent *e)
|
||||
@ -96,6 +118,7 @@ bool BasePostedItem::setPost(const RsPostedPost &post, bool doFill)
|
||||
|
||||
void BasePostedItem::loadGroup()
|
||||
{
|
||||
mIsLoadingGroup = true;
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
@ -110,13 +133,14 @@ void BasePostedItem::loadGroup()
|
||||
if(!rsPosted->getBoardsInfo(groupIds,groups))
|
||||
{
|
||||
RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mIsLoadingGroup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (groups.size() != 1)
|
||||
{
|
||||
std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items" << std::endl;
|
||||
mIsLoadingGroup = false;
|
||||
return;
|
||||
}
|
||||
RsPostedGroup group(groups[0]);
|
||||
@ -128,6 +152,7 @@ void BasePostedItem::loadGroup()
|
||||
* after a blocking call to RetroShare API complete */
|
||||
|
||||
mGroupMeta = group.mMeta;
|
||||
mIsLoadingGroup = false;
|
||||
|
||||
}, this );
|
||||
});
|
||||
@ -135,6 +160,7 @@ void BasePostedItem::loadGroup()
|
||||
|
||||
void BasePostedItem::loadMessage()
|
||||
{
|
||||
mIsLoadingMessage = true;
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
@ -145,6 +171,7 @@ void BasePostedItem::loadMessage()
|
||||
if(! rsPosted->getBoardContent( groupId(), std::set<RsGxsMessageId>( { messageId() } ),posts,comments))
|
||||
{
|
||||
RsErr() << "BasePostedItem::loadMessage() ERROR getting data" << std::endl;
|
||||
mIsLoadingMessage = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -153,7 +180,7 @@ void BasePostedItem::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,true); }, this );
|
||||
RsQThreadUtils::postToObject( [post,this]() { setPost(post,true); mIsLoadingMessage = false;}, this );
|
||||
}
|
||||
else if(comments.size() == 1)
|
||||
{
|
||||
@ -168,15 +195,15 @@ void BasePostedItem::loadMessage()
|
||||
setMessageId(cmt.mMeta.mThreadId);
|
||||
requestMessage();
|
||||
|
||||
mIsLoadingMessage = false;
|
||||
}, this );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It.";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It." << std::endl;
|
||||
|
||||
RsQThreadUtils::postToObject( [this]() { removeItem(); }, this );
|
||||
RsQThreadUtils::postToObject( [this]() { removeItem(); mIsLoadingMessage = false;}, this );
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -188,7 +215,7 @@ void BasePostedItem::loadComment()
|
||||
std::cerr << "GxsChannelPostItem::loadComment()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mIsLoadingComment = true;
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
@ -204,6 +231,7 @@ void BasePostedItem::loadComment()
|
||||
if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments))
|
||||
{
|
||||
RsErr() << "BasePostedItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mIsLoadingComment = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -212,7 +240,7 @@ void BasePostedItem::loadComment()
|
||||
RsQThreadUtils::postToObject( [comNb,this]()
|
||||
{
|
||||
setCommentsSize(comNb);
|
||||
|
||||
mIsLoadingComment = false;
|
||||
}, this );
|
||||
});
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class PostedItem;
|
||||
}
|
||||
|
||||
class FeedHolder;
|
||||
class RsPostedPost;
|
||||
struct RsPostedPost;
|
||||
|
||||
class BasePostedItem : public GxsFeedItem
|
||||
{
|
||||
@ -40,7 +40,7 @@ class BasePostedItem : public GxsFeedItem
|
||||
public:
|
||||
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;
|
||||
virtual ~BasePostedItem();
|
||||
|
||||
bool setPost(const RsPostedPost& post, bool doFill = true);
|
||||
|
||||
@ -64,15 +64,15 @@ protected:
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
|
||||
/* GxsGroupFeedItem */
|
||||
virtual QString groupName();
|
||||
virtual QString groupName() override;
|
||||
virtual void loadGroup() override;
|
||||
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; }
|
||||
virtual RetroShareLink::enumType getLinkType() override { return RetroShareLink::TYPE_UNKNOWN; }
|
||||
|
||||
/* GxsFeedItem */
|
||||
virtual QString messageName();
|
||||
virtual QString messageName() override;
|
||||
|
||||
virtual void loadMessage();
|
||||
virtual void loadComment();
|
||||
virtual void loadMessage() override;
|
||||
virtual void loadComment() override;
|
||||
|
||||
bool mInFill;
|
||||
RsGroupMetaData mGroupMeta;
|
||||
@ -80,7 +80,7 @@ protected:
|
||||
|
||||
virtual void setup()=0;
|
||||
virtual void fill()=0;
|
||||
virtual void doExpand(bool open)=0;
|
||||
virtual void doExpand(bool open) override =0;
|
||||
virtual void setComment(const RsGxsComment&)=0;
|
||||
virtual void setReadStatus(bool isNew, bool isUnread)=0;
|
||||
virtual void setCommentsSize(int comNb)=0;
|
||||
@ -90,6 +90,9 @@ protected:
|
||||
|
||||
private:
|
||||
bool mLoaded;
|
||||
bool mIsLoadingGroup;
|
||||
bool mIsLoadingMessage;
|
||||
bool mIsLoadingComment;
|
||||
};
|
||||
|
||||
class PostedItem: public BasePostedItem
|
||||
|
Loading…
Reference in New Issue
Block a user