mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-12-17 01:24:15 -05:00
improved code consistency in feed item loading/killing
This commit is contained in:
parent
516ccdf4bd
commit
c3fb087f92
12 changed files with 119 additions and 58 deletions
|
|
@ -78,7 +78,8 @@ BaseBoardsCommentsItem::BaseBoardsCommentsItem( FeedHolder *feedHolder, uint32_t
|
|||
|
||||
BaseBoardsCommentsItem::~BaseBoardsCommentsItem()
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(200);
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(GROUP_ITEM_LOADING_TIMEOUT_ms);
|
||||
|
||||
while( (mIsLoadingGroup || mIsLoadingMessage || mIsLoadingComment)
|
||||
&& std::chrono::steady_clock::now() < timeout)
|
||||
{
|
||||
|
|
@ -126,6 +127,7 @@ bool BaseBoardsCommentsItem::setPost(const RsPostedPost &post, bool doFill)
|
|||
void BaseBoardsCommentsItem::loadGroup()
|
||||
{
|
||||
mIsLoadingGroup = true;
|
||||
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ void ChannelsCommentsItem::paintEvent(QPaintEvent *e)
|
|||
|
||||
ChannelsCommentsItem::~ChannelsCommentsItem()
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(300);
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(GROUP_ITEM_LOADING_TIMEOUT_ms);
|
||||
|
||||
while( mLoading && std::chrono::steady_clock::now() < timeout )
|
||||
{
|
||||
|
|
@ -293,12 +293,14 @@ void ChannelsCommentsItem::load()
|
|||
if(!rsGxsChannels->getChannelsInfo(groupIds,groups)) // would be better to call channel Summaries for a single group
|
||||
{
|
||||
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mLoading= false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (groups.size() != 1)
|
||||
{
|
||||
std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items" << std::endl;
|
||||
mLoading= false;
|
||||
return;
|
||||
}
|
||||
RsGxsChannelGroup group(groups[0]);
|
||||
|
|
@ -312,6 +314,7 @@ void ChannelsCommentsItem::load()
|
|||
if(! rsGxsChannels->getChannelContent( groupId(), std::set<RsGxsMessageId>( { messageId(),mThreadId } ),posts,comments,votes))
|
||||
{
|
||||
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mLoading= false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -325,8 +328,12 @@ void ChannelsCommentsItem::load()
|
|||
|
||||
mGroupMeta = group.mMeta;
|
||||
|
||||
if(comments.size()==1)
|
||||
if(comments.size()!=1)
|
||||
{
|
||||
mLoading=false;
|
||||
removeItem();
|
||||
}
|
||||
|
||||
RsGxsComment cmt(comments[0]);
|
||||
|
||||
uint32_t autorized_lines = (int)floor( (ui->avatarLabel->height() - ui->button_HL->sizeHint().height())
|
||||
|
|
@ -345,12 +352,6 @@ void ChannelsCommentsItem::load()
|
|||
ui->avatarLabel->setPixmap(pixmap);
|
||||
|
||||
//Change this item to be uploaded with thread element. This is really bad practice.
|
||||
}
|
||||
else
|
||||
{
|
||||
mLoading=false;
|
||||
removeItem();
|
||||
}
|
||||
|
||||
if (posts.size() == 1)
|
||||
setPost(posts[0]);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
GxsChannelGroupItem::GxsChannelGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, bool isHome, bool autoUpdate) :
|
||||
GxsGroupFeedItem(feedHolder, feedId, groupId, isHome, rsGxsChannels, autoUpdate)
|
||||
{
|
||||
mIsLoading = false;
|
||||
setup();
|
||||
requestGroup();
|
||||
addEventHandler();
|
||||
|
|
@ -44,6 +45,7 @@ GxsChannelGroupItem::GxsChannelGroupItem(FeedHolder *feedHolder, uint32_t feedId
|
|||
GxsChannelGroupItem::GxsChannelGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup &group, bool isHome, bool autoUpdate) :
|
||||
GxsGroupFeedItem(feedHolder, feedId, group.mMeta.mGroupId, isHome, rsGxsChannels, autoUpdate)
|
||||
{
|
||||
mIsLoading = false;
|
||||
setup();
|
||||
setGroup(group);
|
||||
addEventHandler();
|
||||
|
|
@ -77,6 +79,14 @@ void GxsChannelGroupItem::addEventHandler()
|
|||
|
||||
GxsChannelGroupItem::~GxsChannelGroupItem()
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(GROUP_ITEM_LOADING_TIMEOUT_ms);
|
||||
|
||||
while( mIsLoading && std::chrono::steady_clock::now() < timeout )
|
||||
{
|
||||
RsDbg() << __PRETTY_FUNCTION__ << " is Waiting for data to load " << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
||||
delete(ui);
|
||||
}
|
||||
|
|
@ -121,6 +131,8 @@ bool GxsChannelGroupItem::setGroup(const RsGxsChannelGroup &group)
|
|||
|
||||
void GxsChannelGroupItem::loadGroup()
|
||||
{
|
||||
mIsLoading = true;
|
||||
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
|
@ -131,6 +143,7 @@ void GxsChannelGroupItem::loadGroup()
|
|||
if(!rsGxsChannels->getChannelsInfo(groupIds,groups))
|
||||
{
|
||||
RsErr() << "PostedItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mIsLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -138,6 +151,7 @@ void GxsChannelGroupItem::loadGroup()
|
|||
{
|
||||
std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
mIsLoading = false;
|
||||
return;
|
||||
}
|
||||
RsGxsChannelGroup group(groups[0]);
|
||||
|
|
@ -149,6 +163,7 @@ void GxsChannelGroupItem::loadGroup()
|
|||
* after a blocking call to RetroShare API complete */
|
||||
|
||||
setGroup(group);
|
||||
mIsLoading = false;
|
||||
|
||||
}, this );
|
||||
});
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ private:
|
|||
void setup();
|
||||
void addEventHandler();
|
||||
|
||||
bool mIsLoading;
|
||||
|
||||
private:
|
||||
RsGxsChannelGroup mGroup;
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ void GxsChannelPostItem::paintEvent(QPaintEvent *e)
|
|||
|
||||
GxsChannelPostItem::~GxsChannelPostItem()
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(300);
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(GROUP_ITEM_LOADING_TIMEOUT_ms);
|
||||
|
||||
while( (mLoadingGroup || mLoadingMessage || mLoadingComment)
|
||||
&& std::chrono::steady_clock::now() < timeout)
|
||||
|
|
@ -306,6 +306,7 @@ void GxsChannelPostItem::loadGroup()
|
|||
if(!rsGxsChannels->getChannelsInfo(groupIds,groups)) // would be better to call channel Summaries for a single group
|
||||
{
|
||||
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mLoadingGroup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -313,6 +314,7 @@ void GxsChannelPostItem::loadGroup()
|
|||
{
|
||||
std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
mLoadingGroup = false;
|
||||
return;
|
||||
}
|
||||
RsGxsChannelGroup group(groups[0]);
|
||||
|
|
@ -348,6 +350,7 @@ void GxsChannelPostItem::loadMessage()
|
|||
if(! rsGxsChannels->getChannelContent( groupId(), std::set<RsGxsMessageId>( { messageId() } ),posts,comments,votes))
|
||||
{
|
||||
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mLoadingMessage = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -377,11 +380,11 @@ void GxsChannelPostItem::loadMessage()
|
|||
ui->commLabel->show();
|
||||
ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str()));
|
||||
|
||||
//Change this item to be uploaded with thread element.
|
||||
// Change this item to be uploaded with thread element. Note: this is terrible coding.
|
||||
setMessageId(cmt.mMeta.mThreadId);
|
||||
requestMessage();
|
||||
|
||||
mLoadingMessage = false;
|
||||
|
||||
requestMessage();
|
||||
}, this );
|
||||
|
||||
}
|
||||
|
|
@ -424,6 +427,7 @@ void GxsChannelPostItem::loadComment()
|
|||
if(! rsGxsChannels->getChannelComments( groupId(),msgIds,comments))
|
||||
{
|
||||
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mLoadingComment = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -446,13 +450,6 @@ void GxsChannelPostItem::loadComment()
|
|||
|
||||
void GxsChannelPostItem::fill()
|
||||
{
|
||||
/* fill in */
|
||||
|
||||
// if (isLoading()) {
|
||||
// /* Wait for all requests */
|
||||
//return;
|
||||
// }
|
||||
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "GxsChannelPostItem::fill()";
|
||||
std::cerr << std::endl;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
GxsForumGroupItem::GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, bool isHome, bool autoUpdate) :
|
||||
GxsGroupFeedItem(feedHolder, feedId, groupId, isHome, rsGxsForums, autoUpdate)
|
||||
{
|
||||
mIsLoading = false;
|
||||
setup();
|
||||
requestGroup();
|
||||
addEventHandler();
|
||||
|
|
@ -44,6 +45,7 @@ GxsForumGroupItem::GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, co
|
|||
mAddedModerators(added_moderators),
|
||||
mRemovedModerators(removed_moderators)
|
||||
{
|
||||
mIsLoading = false;
|
||||
setup();
|
||||
requestGroup();
|
||||
addEventHandler();
|
||||
|
|
@ -85,6 +87,14 @@ GxsForumGroupItem::GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, co
|
|||
|
||||
GxsForumGroupItem::~GxsForumGroupItem()
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(GROUP_ITEM_LOADING_TIMEOUT_ms);
|
||||
|
||||
while( mIsLoading && std::chrono::steady_clock::now() < timeout )
|
||||
{
|
||||
RsDbg() << __PRETTY_FUNCTION__ << " is Waiting for data to load " << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
||||
delete(ui);
|
||||
}
|
||||
|
|
@ -129,6 +139,8 @@ bool GxsForumGroupItem::setGroup(const RsGxsForumGroup &group)
|
|||
|
||||
void GxsForumGroupItem::loadGroup()
|
||||
{
|
||||
mIsLoading = true;
|
||||
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
|
@ -143,6 +155,7 @@ void GxsForumGroupItem::loadGroup()
|
|||
if(!rsGxsForums->getForumsInfo(forumIds,groups))
|
||||
{
|
||||
RsErr() << "GxsForumGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mIsLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -150,6 +163,7 @@ void GxsForumGroupItem::loadGroup()
|
|||
{
|
||||
std::cerr << "GxsForumGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
mIsLoading = false;
|
||||
return;
|
||||
}
|
||||
RsGxsForumGroup group(groups[0]);// no reference to teporary accross threads!
|
||||
|
|
@ -161,6 +175,7 @@ void GxsForumGroupItem::loadGroup()
|
|||
* after a blocking call to RetroShare API complete */
|
||||
|
||||
setGroup(group);
|
||||
mIsLoading = false;
|
||||
|
||||
}, this );
|
||||
});
|
||||
|
|
|
|||
|
|
@ -69,6 +69,8 @@ private:
|
|||
/** Qt Designer generated object */
|
||||
Ui::GxsForumGroupItem *ui;
|
||||
|
||||
bool mIsLoading;
|
||||
|
||||
std::list<RsGxsId> mAddedModerators;
|
||||
std::list<RsGxsId> mRemovedModerators;
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ GxsForumMsgItem::GxsForumMsgItem(FeedHolder *feedHolder, uint32_t feedId, const
|
|||
|
||||
GxsForumMsgItem::~GxsForumMsgItem()
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(300);
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(GROUP_ITEM_LOADING_TIMEOUT_ms);
|
||||
|
||||
while( (mLoadingGroup || mLoadingMessage || mLoadingSetAsRead || mLoadingParentMessage)
|
||||
&& std::chrono::steady_clock::now() < timeout)
|
||||
|
|
@ -202,6 +202,7 @@ void GxsForumMsgItem::loadGroup()
|
|||
if(!rsGxsForums->getForumsInfo(forumIds,groups))
|
||||
{
|
||||
RsErr() << "GxsForumGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mLoadingGroup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -209,6 +210,7 @@ void GxsForumMsgItem::loadGroup()
|
|||
{
|
||||
std::cerr << "GxsForumGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
mLoadingGroup = false;
|
||||
return;
|
||||
}
|
||||
RsGxsForumGroup group(groups[0]);
|
||||
|
|
@ -249,6 +251,7 @@ void GxsForumMsgItem::loadMessage()
|
|||
{
|
||||
std::cerr << "GxsForumMsgItem::loadMessage() ERROR getting data";
|
||||
std::cerr << std::endl;
|
||||
mLoadingMessage = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -256,6 +259,7 @@ void GxsForumMsgItem::loadMessage()
|
|||
{
|
||||
std::cerr << "GxsForumMsgItem::loadMessage() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
mLoadingMessage = false;
|
||||
return;
|
||||
}
|
||||
RsGxsForumMsg msg(msgs[0]);
|
||||
|
|
@ -296,6 +300,7 @@ void GxsForumMsgItem::loadParentMessage(const RsGxsMessageId& parent_msg)
|
|||
{
|
||||
std::cerr << "GxsForumMsgItem::loadMessage() ERROR getting data";
|
||||
std::cerr << std::endl;
|
||||
mLoadingParentMessage = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -303,6 +308,7 @@ void GxsForumMsgItem::loadParentMessage(const RsGxsMessageId& parent_msg)
|
|||
{
|
||||
std::cerr << "GxsForumMsgItem::loadMessage() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
mLoadingParentMessage = false;
|
||||
return;
|
||||
}
|
||||
RsGxsForumMsg msg(msgs[0]);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
PostedGroupItem::PostedGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, bool isHome, bool autoUpdate) :
|
||||
GxsGroupFeedItem(feedHolder, feedId, groupId, isHome, rsPosted, autoUpdate)
|
||||
{
|
||||
mIsLoadingGroup = false;
|
||||
setup();
|
||||
|
||||
requestGroup();
|
||||
|
|
@ -43,6 +44,7 @@ PostedGroupItem::PostedGroupItem(FeedHolder *feedHolder, uint32_t feedId, const
|
|||
PostedGroupItem::PostedGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsPostedGroup &group, bool isHome, bool autoUpdate) :
|
||||
GxsGroupFeedItem(feedHolder, feedId, group.mMeta.mGroupId, isHome, rsPosted, autoUpdate)
|
||||
{
|
||||
mIsLoadingGroup = false;
|
||||
setup();
|
||||
|
||||
setGroup(group);
|
||||
|
|
@ -50,6 +52,16 @@ PostedGroupItem::PostedGroupItem(FeedHolder *feedHolder, uint32_t feedId, const
|
|||
|
||||
PostedGroupItem::~PostedGroupItem()
|
||||
{
|
||||
auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(GROUP_ITEM_LOADING_TIMEOUT_ms);
|
||||
|
||||
while( mIsLoadingGroup && std::chrono::steady_clock::now() < timeout)
|
||||
{
|
||||
RsDbg() << __PRETTY_FUNCTION__ << " is Waiting "
|
||||
<< (mIsLoadingGroup ? "Group " : "")
|
||||
<< "loading finished." << std::endl;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
delete(ui);
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +107,8 @@ bool PostedGroupItem::setGroup(const RsPostedGroup &group)
|
|||
|
||||
void PostedGroupItem::loadGroup()
|
||||
{
|
||||
mIsLoadingGroup = true;
|
||||
|
||||
RsThread::async([this]()
|
||||
{
|
||||
// 1 - get group data
|
||||
|
|
@ -109,6 +123,7 @@ void PostedGroupItem::loadGroup()
|
|||
if(!rsPosted->getBoardsInfo(groupIds,groups))
|
||||
{
|
||||
RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl;
|
||||
mIsLoadingGroup = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +131,7 @@ void PostedGroupItem::loadGroup()
|
|||
{
|
||||
std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items";
|
||||
std::cerr << std::endl;
|
||||
mIsLoadingGroup = false;
|
||||
return;
|
||||
}
|
||||
RsPostedGroup group(groups[0]);
|
||||
|
|
@ -127,6 +143,7 @@ void PostedGroupItem::loadGroup()
|
|||
* after a blocking call to RetroShare API complete */
|
||||
|
||||
setGroup(group);
|
||||
mIsLoadingGroup = false;
|
||||
|
||||
}, this );
|
||||
});
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ private:
|
|||
|
||||
private:
|
||||
RsPostedGroup mGroup;
|
||||
bool mIsLoadingGroup;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::PostedGroupItem *ui;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
* #define DEBUG_ITEM 1
|
||||
**/
|
||||
|
||||
const uint GxsGroupFeedItem::GROUP_ITEM_LOADING_TIMEOUT_ms = 2000;
|
||||
|
||||
GxsGroupFeedItem::GxsGroupFeedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, bool isHome, RsGxsIfaceHelper *iface, bool /*autoUpdate*/) :
|
||||
FeedItem(feedHolder,feedId,NULL)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ protected slots:
|
|||
protected:
|
||||
bool mIsHome;
|
||||
RsGxsIfaceHelper *mGxsIface;
|
||||
static const uint GROUP_ITEM_LOADING_TIMEOUT_ms ;
|
||||
|
||||
private slots:
|
||||
/* RsGxsUpdateBroadcastBase */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue