first pass for converting GxsMessageFrameWidget to blocking API

This commit is contained in:
csoler 2020-03-29 23:21:48 +02:00
parent c18dfb39c3
commit 55c810f848
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
12 changed files with 420 additions and 221 deletions

View file

@ -506,7 +506,7 @@ void GxsChannelPostsWidget::fillThreadCreatePost(const QVariant &post, bool rela
createPostItem(post.value<RsGxsChannelPost>(), related);
}
void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &posts, GxsMessageFramePostThread *thread, bool related)
void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost>& posts, GxsMessageFramePostThread *thread, bool related)
{
if (related && thread) {
std::cerr << "GxsChannelPostsWidget::insertChannelPosts fill only related posts as thread is not possible" << std::endl;
@ -734,25 +734,67 @@ void GxsChannelPostsWidget::toggleAutoDownload()
});
}
bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaData &metaData)
bool GxsChannelPostsWidget::insertGroupData(const RsGxsGenericGroupData *data)
{
std::vector<RsGxsChannelGroup> groups;
rsGxsChannels->getGroupData(token, groups);
insertChannelDetails(*dynamic_cast<const RsGxsChannelGroup*>(data));
mChannelGroupId = data->mMeta.mGroupId;
return true;
if(groups.size() == 1)
{
insertChannelDetails(groups[0]);
metaData = groups[0].mMeta;
mChannelGroupId = groups[0].mMeta.mGroupId;
return true;
}
}
#ifdef TO_REMOVE
void GxsChannelPostsWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread)
{
std::vector<RsGxsChannelPost> posts;
rsGxsChannels->getPostData(token, posts);
insertChannelPosts(posts, thread, false);
}
#endif
void GxsChannelPostsWidget::getMsgData(const std::set<RsGxsMessageId>& msgIds,std::vector<RsGxsGenericMsgData*>& psts)
{
std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments;
rsGxsChannels->getChannelContent( mChannelGroupId,msgIds,posts,comments );
psts.clear();
for(auto& post: posts)
psts.push_back(new RsGxsChannelPost(post));
}
void GxsChannelPostsWidget::getAllMsgData(std::vector<RsGxsGenericMsgData*>& psts)
{
std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments;
rsGxsChannels->getChannelContent( mChannelGroupId,std::set<RsGxsMessageId>(),posts,comments );
psts.clear();
for(auto& post: posts)
psts.push_back(new RsGxsChannelPost(post));
}
bool GxsChannelPostsWidget::getGroupData(RsGxsGenericGroupData *& data)
{
std::vector<RsGxsChannelGroup> groups;
if(rsGxsChannels->getChannelsInfo(std::list<RsGxsGroupId>({groupId()}),groups) && groups.size()==1)
{
data = new RsGxsChannelGroup(groups[0]);
return true;
}
else
{
RsGxsChannelGroup distant_group;
if(rsGxsChannels->retrieveDistantGroup(groupId(),distant_group))
{
insertChannelDetails(distant_group);
metaData = distant_group.mMeta;
data = new RsGxsChannelGroup(distant_group);
mChannelGroupId = distant_group.mMeta.mGroupId;
return true ;
}
@ -761,14 +803,32 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa
return false;
}
void GxsChannelPostsWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread)
void GxsChannelPostsWidget::insertAllPosts(const std::vector<RsGxsGenericMsgData*>& posts, GxsMessageFramePostThread *thread)
{
std::vector<RsGxsChannelPost> posts;
rsGxsChannels->getPostData(token, posts);
std::vector<RsGxsChannelPost> cposts;
insertChannelPosts(posts, thread, false);
for(auto post: posts) // This is not so nice but we have somehow to convert to RsGxsChannelPost at some timer, and the cposts list is being modified in the insert method.
{
cposts.push_back(*dynamic_cast<RsGxsChannelPost*>(post));
delete post;
}
insertChannelPosts(cposts, thread, false);
}
void GxsChannelPostsWidget::insertPosts(const std::vector<RsGxsGenericMsgData*>& posts)
{
std::vector<RsGxsChannelPost> cposts;
for(auto post: posts) // This is not so nice but we have somehow to convert to RsGxsChannelPost at some timer, and the cposts list is being modified in the insert method.
{
cposts.push_back(*dynamic_cast<RsGxsChannelPost*>(post));
delete post;
}
insertChannelPosts(cposts, NULL, true);
}
#ifdef TO_REMOVE
void GxsChannelPostsWidget::insertPosts(const uint32_t &token)
{
std::vector<RsGxsChannelPost> posts;
@ -776,6 +836,7 @@ void GxsChannelPostsWidget::insertPosts(const uint32_t &token)
insertChannelPosts(posts, NULL, true);
}
#endif
class GxsChannelPostsReadData
{

View file

@ -65,7 +65,7 @@ public:
protected:
/* GxsMessageFramePostWidget */
virtual void groupNameChanged(const QString &name);
virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData);
virtual bool insertGroupData(const RsGxsGenericGroupData *data) override;
virtual void insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread);
virtual void insertPosts(const uint32_t &token);
virtual void clearPosts();
@ -74,6 +74,12 @@ protected:
virtual bool navigatePostItem(const RsGxsMessageId& msgId);
virtual void blank() ;
virtual bool getGroupData(RsGxsGenericGroupData *& data) override;
virtual void getMsgData(const std::set<RsGxsMessageId>& msgIds,std::vector<RsGxsGenericMsgData*>& posts) override;
virtual void getAllMsgData(std::vector<RsGxsGenericMsgData*>& posts) override;
virtual void insertPosts(const std::vector<RsGxsGenericMsgData*>& posts) override;
virtual void insertAllPosts(const std::vector<RsGxsGenericMsgData*>& posts, GxsMessageFramePostThread *thread) override;
/* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read, uint32_t &token);