attempt to fix bug in closing GxsChannelComment feed item

This commit is contained in:
csoler 2023-11-17 14:10:14 +01:00
parent 9db3208f72
commit 6555cc5792
2 changed files with 36 additions and 1 deletions

View file

@ -53,6 +53,10 @@ ChannelsCommentsItem::ChannelsCommentsItem(FeedHolder *feedHolder, uint32_t feed
GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, messageId, isHome, rsGxsChannels, autoUpdate), GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, messageId, isHome, rsGxsChannels, autoUpdate),
mGroupMeta(group_meta) mGroupMeta(group_meta)
{ {
mLoadingGroup = false;
mLoadingMessage = false;
mLoadingComment = false;
mPost.mMeta.mMsgId = messageId; // useful for uniqueIdentifer() before the post is loaded mPost.mMeta.mMsgId = messageId; // useful for uniqueIdentifer() before the post is loaded
mPost.mMeta.mGroupId = mGroupMeta.mGroupId; mPost.mMeta.mGroupId = mGroupMeta.mGroupId;
@ -74,6 +78,10 @@ ChannelsCommentsItem::ChannelsCommentsItem(FeedHolder *feedHolder, uint32_t feed
ChannelsCommentsItem::ChannelsCommentsItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate,const std::set<RsGxsMessageId>& older_versions) : ChannelsCommentsItem::ChannelsCommentsItem(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) // this one should be in GxsFeedItem GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsGxsChannels, autoUpdate) // this one should be in GxsFeedItem
{ {
mLoadingGroup = false;
mLoadingMessage = false;
mLoadingComment = false;
mPost.mMeta.mMsgId = messageId; // useful for uniqueIdentifer() before the post is loaded mPost.mMeta.mMsgId = messageId; // useful for uniqueIdentifer() before the post is loaded
QVector<RsGxsMessageId> v; QVector<RsGxsMessageId> v;
@ -114,6 +122,19 @@ void ChannelsCommentsItem::paintEvent(QPaintEvent *e)
ChannelsCommentsItem::~ChannelsCommentsItem() ChannelsCommentsItem::~ChannelsCommentsItem()
{ {
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(300);
while( (mLoadingGroup || mLoadingMessage || mLoadingComment)
&& std::chrono::steady_clock::now() < timeout)
{
RsDbg() << __PRETTY_FUNCTION__ << " is Waiting for "
<< (mLoadingGroup ? "Group " : "")
<< (mLoadingMessage ? "Message " : "")
<< (mLoadingComment ? "Comment " : "")
<< "loading." << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
delete(ui); delete(ui);
} }
@ -255,6 +276,7 @@ void ChannelsCommentsItem::loadGroup()
return; return;
} }
RsGxsChannelGroup group(groups[0]); RsGxsChannelGroup group(groups[0]);
mLoadingGroup = true;
RsQThreadUtils::postToObject( [group,this]() RsQThreadUtils::postToObject( [group,this]()
{ {
@ -263,6 +285,7 @@ void ChannelsCommentsItem::loadGroup()
* after a blocking call to RetroShare API complete */ * after a blocking call to RetroShare API complete */
mGroupMeta = group.mMeta; mGroupMeta = group.mMeta;
mLoadingGroup = false;
}, this ); }, this );
}); });
@ -293,8 +316,9 @@ void ChannelsCommentsItem::loadMessage()
std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl; std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl;
#endif #endif
RsGxsChannelPost post(posts[0]); // no reference to temporary here, because we pass this to a thread RsGxsChannelPost post(posts[0]); // no reference to temporary here, because we pass this to a thread
mLoadingMessage = true;
RsQThreadUtils::postToObject( [post,this]() { setPost(post); }, this ); RsQThreadUtils::postToObject( [post,this]() { setPost(post); mLoadingMessage=false; }, this );
} }
else if(comments.size() == 1) else if(comments.size() == 1)
{ {
@ -302,6 +326,7 @@ void ChannelsCommentsItem::loadMessage()
#ifdef DEBUG_ITEM #ifdef DEBUG_ITEM
std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl; std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl;
#endif #endif
mLoadingComment = true;
RsQThreadUtils::postToObject( [cmt,this]() RsQThreadUtils::postToObject( [cmt,this]()
{ {
@ -323,6 +348,7 @@ void ChannelsCommentsItem::loadMessage()
//Change this item to be uploaded with thread element. //Change this item to be uploaded with thread element.
setMessageId(cmt.mMeta.mThreadId); setMessageId(cmt.mMeta.mThreadId);
mLoadingComment=false;
requestMessage(); requestMessage();
}, this ); }, this );
@ -344,6 +370,8 @@ void ChannelsCommentsItem::loadMessage()
void ChannelsCommentsItem::loadComment() void ChannelsCommentsItem::loadComment()
{ {
#ifdef DOES_NOTHING
#ifdef DEBUG_ITEM #ifdef DEBUG_ITEM
std::cerr << "ChannelsCommentsItem::loadComment()"; std::cerr << "ChannelsCommentsItem::loadComment()";
std::cerr << std::endl; std::cerr << std::endl;
@ -369,6 +397,8 @@ void ChannelsCommentsItem::loadComment()
int comNb = comments.size(); int comNb = comments.size();
mLoadingComment=true;
RsQThreadUtils::postToObject( [comNb]() RsQThreadUtils::postToObject( [comNb]()
{ {
QString sComButText = tr("Comment"); QString sComButText = tr("Comment");
@ -381,6 +411,7 @@ void ChannelsCommentsItem::loadComment()
}, this ); }, this );
}); });
#endif
} }
void ChannelsCommentsItem::fill() void ChannelsCommentsItem::fill()

View file

@ -113,6 +113,10 @@ private:
bool mCloseOnRead; bool mCloseOnRead;
bool mLoaded; bool mLoaded;
bool mLoadingGroup;
bool mLoadingMessage;
bool mLoadingComment;
RsGroupMetaData mGroupMeta; RsGroupMetaData mGroupMeta;
RsGxsChannelPost mPost; RsGxsChannelPost mPost;