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

@ -68,12 +68,10 @@ struct RsGxsChannelGroup : RsSerializable, RsGxsGenericGroupData
~RsGxsChannelGroup() override;
};
struct RsGxsChannelPost : RsSerializable
struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData
{
RsGxsChannelPost() : mCount(0), mSize(0) {}
RsMsgMetaData mMeta;
std::set<RsGxsMessageId> mOlderVersions;
std::string mMsg; // UTF8 encoded.

View File

@ -43,11 +43,12 @@
enum class TokenRequestType: uint8_t
{
GROUP_INFO = 0x01,
MSG_INFO = 0x02,
MSG_RELATED_INFO = 0x03,
GROUP_STATISTICS = 0x04,
SERVICE_STATISTICS = 0x05,
NO_KILL_TYPE = 0x06,
POSTS = 0x02,
ALL_POSTS = 0x03,
MSG_RELATED_INFO = 0x04,
GROUP_STATISTICS = 0x05,
SERVICE_STATISTICS = 0x06,
NO_KILL_TYPE = 0x07,
};
class RsGxsIfaceHelper
@ -278,13 +279,12 @@ public:
}
/// @see RsTokenService::requestMsgInfo
bool requestMsgInfo( uint32_t& token,
const RsTokReqOptions& opts, const GxsMsgReq& msgIds )
bool requestMsgInfo( uint32_t& token, const RsTokReqOptions& opts, const GxsMsgReq& msgIds )
{
if(mTokenService.requestMsgInfo(token, 0, opts, msgIds))
{
RS_STACK_MUTEX(mMtx);
mActiveTokens[token]=TokenRequestType::MSG_INFO;
mActiveTokens[token]= msgIds.empty()?(TokenRequestType::ALL_POSTS):(TokenRequestType::POSTS);
locked_dumpTokens();
return true;
}
@ -298,7 +298,7 @@ public:
if(mTokenService.requestMsgInfo(token, 0, opts, grpIds))
{
RS_STACK_MUTEX(mMtx);
mActiveTokens[token]=TokenRequestType::MSG_INFO;
mActiveTokens[token]=TokenRequestType::ALL_POSTS;
locked_dumpTokens();
return true;
}

View File

@ -184,6 +184,14 @@ struct RsMsgMetaData : RsSerializable
}
};
struct RsGxsGenericMsgData
{
virtual ~RsGxsGenericMsgData() = default; // making the type polymorphic
RsMsgMetaData mMeta;
};
class GxsGroupStatistic
{
public:

View File

@ -46,14 +46,13 @@ struct RsPostedGroup: RsGxsGenericGroupData
RsGxsImage mGroupImage;
};
struct RsPostedPost
struct RsPostedPost: public RsGxsGenericMsgData
{
RsPostedPost(): mHaveVoted(false), mUpVotes(0), mDownVotes(0), mComments(0),
mHotScore(0), mTopScore(0), mNewScore(0) {}
bool calculateScores(rstime_t ref_time);
RsMsgMetaData mMeta;
std::string mLink;
std::string mNotes;

View File

@ -885,30 +885,16 @@ void PostedListWidget::shallowClearPosts()
}
}
bool PostedListWidget::insertGroupData(const uint32_t &token, RsGroupMetaData &metaData)
bool PostedListWidget::insertGroupData(const RsGxsGenericGroupData *data)
{
std::vector<RsPostedGroup> groups;
rsPosted->getGroupData(token, groups);
if (groups.size() == 1)
{
insertPostedDetails(groups[0]);
metaData = groups[0].mMeta;
return true;
}
return false;
insertPostedDetails(*dynamic_cast<const RsPostedGroup*>(data));
}
void PostedListWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePostThread */*thread*/)
void PostedListWidget::insertAllPostedPosts(const std::vector<RsPostedPost>& posts, GxsMessageFramePostThread */*thread*/)
{
std::vector<RsPostedPost> posts;
rsPosted->getPostData(token, posts);
std::vector<RsPostedPost>::iterator vit;
for(vit = posts.begin(); vit != posts.end(); ++vit)
for(auto vit = posts.begin(); vit != posts.end(); ++vit)
{
RsPostedPost& p = *vit;
const RsPostedPost& p = *vit;
loadPost(p);
loadPostCardView(p);
}
@ -916,15 +902,11 @@ void PostedListWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePost
applyRanking();
}
void PostedListWidget::insertPosts(const uint32_t &token)
void PostedListWidget::insertPostedPosts(const std::vector<RsPostedPost>& posts)
{
std::vector<RsPostedPost> posts;
rsPosted->getPostData(token, posts);
std::vector<RsPostedPost>::iterator vit;
for(vit = posts.begin(); vit != posts.end(); ++vit)
for(auto vit = posts.begin(); vit != posts.end(); ++vit)
{
RsPostedPost& p = *vit;
const RsPostedPost& p = *vit;
// modify post content
if(mPosts.find(p.mMeta.mMsgId) != mPosts.end())
@ -1047,3 +1029,68 @@ void PostedListWidget::setViewMode(int viewMode)
return;
}
}
void PostedListWidget::getMsgData(const std::set<RsGxsMessageId>& msgIds,std::vector<RsGxsGenericMsgData*>& psts)
{
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> comments;
rsPosted->getBoardContent( groupId(),msgIds,posts,comments );
psts.clear();
for(auto& post: posts)
psts.push_back(new RsPostedPost(post));
}
void PostedListWidget::getAllMsgData(std::vector<RsGxsGenericMsgData*>& psts)
{
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> comments;
rsPosted->getBoardContent( groupId(),std::set<RsGxsMessageId>(),posts,comments );
psts.clear();
for(auto& post: posts)
psts.push_back(new RsPostedPost(post));
}
bool PostedListWidget::getGroupData(RsGxsGenericGroupData*& data)
{
std::vector<RsPostedGroup> groupInfo ;
data = nullptr;
if(! rsPosted->getBoardsInfo(std::list<RsGxsGroupId>({groupId()}),groupInfo) || groupInfo.size() != 1)
return false;
data = new RsPostedGroup(groupInfo[0]);
return true;
}
void PostedListWidget::insertPosts(const std::vector<RsGxsGenericMsgData*>& posts)
{
std::vector<RsPostedPost> 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<RsPostedPost*>(post));
delete post;
}
insertPostedPosts(cposts);
}
void PostedListWidget::insertAllPosts(const std::vector<RsGxsGenericMsgData*>& posts, GxsMessageFramePostThread *thread)
{
std::vector<RsPostedPost> 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<RsPostedPost*>(post));
delete post;
}
insertAllPostedPosts(cposts, NULL);
}

View File

@ -58,15 +58,22 @@ public:
protected:
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
void insertAllPostedPosts(const std::vector<RsPostedPost>& posts, GxsMessageFramePostThread *thread) ;
void insertPostedPosts(const std::vector<RsPostedPost>& posts);
/* GxsMessageFramePostWidget */
virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData);
virtual void insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread);
virtual void insertPosts(const uint32_t &token);
virtual void clearPosts();
virtual void blank();
virtual bool navigatePostItem(const RsGxsMessageId& msgId);
virtual void getMsgData(const std::set<RsGxsMessageId>& msgIds,std::vector<RsGxsGenericMsgData*>& posts) override;
virtual void getAllMsgData(std::vector<RsGxsGenericMsgData*>& posts) override;
virtual bool getGroupData(RsGxsGenericGroupData*& data) override;
virtual bool insertGroupData(const RsGxsGenericGroupData *data) 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);

View File

@ -1009,53 +1009,3 @@ void GxsGroupDialog::loadGroup(const RsGxsGroupId& grpId)
});
}
#ifdef TO_REMOVE
void GxsGroupDialog::requestGroup(const RsGxsGroupId &groupId)
{
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(groupId);
std::cerr << "GxsGroupDialog::requestGroup() Requesting Group Summary(" << groupId << ")";
std::cerr << std::endl;
uint32_t token;
if (mInternalTokenQueue)
mInternalTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, GXSGROUP_INTERNAL_LOADGROUP) ;
}
void GxsGroupDialog::loadGroup(uint32_t token)
{
std::cerr << "GxsGroupDialog::loadGroup(" << token << ")";
std::cerr << std::endl;
QString description;
if (service_loadGroup(token, mMode, mGrpMeta, description))
{
updateFromExistingMeta(description);
}
}
void GxsGroupDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
std::cerr << "GxsGroupDialog::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl;
if (queue == mInternalTokenQueue)
{
/* now switch on req */
switch(req.mUserType)
{
case GXSGROUP_INTERNAL_LOADGROUP:
loadGroup(req.mToken);
break;
default:
std::cerr << "GxsGroupDialog::loadGroup() UNKNOWN UserType ";
std::cerr << std::endl;
break;
}
}
}
#endif

View File

@ -1068,99 +1068,6 @@ void GxsGroupFrameDialog::updateGroupSummary()
});
}
#ifdef TO_REMOVE
void GxsGroupFrameDialog::requestGroupSummary()
{
mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, true);
#ifdef DEBUG_GROUPFRAMEDIALOG
std::cerr << "GxsGroupFrameDialog::requestGroupSummary()";
std::cerr << std::endl;
#endif
mTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_GROUP_SUMMARY);
RsTokReqOptions opts;
opts.mReqType = requestGroupSummaryType();
uint32_t token;
mTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_TYPE_GROUP_SUMMARY);
}
void GxsGroupFrameDialog::loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata *&/*userdata*/)
{
/* Default implementation for request type GXS_REQUEST_TYPE_GROUP_META */
mInterface->getGroupSummary(token, groupInfo);
}
void GxsGroupFrameDialog::loadGroupSummary(const std::list<RsGxsGenericGroupData*>& groupInfo)
{
#ifdef DEBUG_GROUPFRAMEDIALOG
std::cerr << "GxsGroupFrameDialog::loadGroupSummary()";
std::cerr << std::endl;
#endif
}
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
//void GxsGroupFrameDialog::acknowledgeSubscribeChange(const uint32_t &token)
//{
//#ifdef DEBUG_GROUPFRAMEDIALOG
// std::cerr << "GxsGroupFrameDialog::acknowledgeSubscribeChange()";
// std::cerr << std::endl;
//#endif
// RsGxsGroupId groupId;
// mInterface->acknowledgeGrp(token, groupId);
// fillComplete();
//}
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
//void GxsGroupFrameDialog::requestGroupSummary_CurrentGroup(const RsGxsGroupId &groupId)
//{
// RsTokReqOptions opts;
// opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
// std::list<std::string> grpIds;
// grpIds.push_back(groupId);
// std::cerr << "GxsGroupFrameDialog::requestGroupSummary_CurrentGroup(" << groupId << ")";
// std::cerr << std::endl;
// uint32_t token;
// mInteface->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_CURRENTGROUP);
//}
//void GxsGroupFrameDialog::loadGroupSummary_CurrentGroup(const uint32_t &token)
//{
// std::cerr << "GxsGroupFrameDialog::loadGroupSummary_CurrentGroup()";
// std::cerr << std::endl;
// std::list<RsGroupMetaData> groupInfo;
// rsGxsForums->getGroupSummary(token, groupInfo);
// if (groupInfo.size() == 1)
// {
// RsGroupMetaData fi = groupInfo.front();
// mSubscribeFlags = fi.mSubscribeFlags;
// }
// else
// {
// resetData();
// std::cerr << "GxsGroupFrameDialog::loadGroupSummary_CurrentGroup() ERROR Invalid Number of Groups...";
// std::cerr << std::endl;
// }
// setValid(true);
//}
#endif
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/

View File

@ -25,6 +25,7 @@
#include "gui/common/UIStateHelper.h"
#include "retroshare/rsgxsifacehelper.h"
#include "util/qtthreadsutils.h"
//#define ENABLE_DEBUG 1
@ -98,8 +99,8 @@ void GxsMessageFramePostWidget::updateDisplay(bool complete)
{
if (complete) {
/* Fill complete */
requestGroupData();
requestAllPosts();
loadGroupData();
loadAllPosts();
return;
}
@ -162,6 +163,7 @@ void GxsMessageFramePostWidget::fillThreadFinished()
/** Request / Response of Data ********************************/
/**************************************************************/
#ifdef TO_REMOVE
void GxsMessageFramePostWidget::requestGroupData()
{
#ifdef ENABLE_DEBUG
@ -230,7 +232,72 @@ void GxsMessageFramePostWidget::loadGroupData(const uint32_t &token)
emit groupChanged(this);
}
#endif
void GxsMessageFramePostWidget::loadGroupData()
{
mSubscribeFlags = 0;
mTokenQueue->cancelActiveRequestTokens(mTokenTypeGroupData);
if (groupId().isNull()) {
mStateHelper->setActive(mTokenTypeGroupData, false);
mStateHelper->setLoading(mTokenTypeGroupData, false);
mStateHelper->clear(mTokenTypeGroupData);
mGroupName.clear();
groupNameChanged(mGroupName);
emit groupChanged(this);
return;
}
mStateHelper->setLoading(mTokenTypeGroupData, true);
emit groupChanged(this);
RsThread::async([this]()
{
RsGxsGenericGroupData *data;
getGroupData(data);
RsQThreadUtils::postToObject( [data,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */
bool ok = insertGroupData(data);
mStateHelper->setLoading(mTokenTypeGroupData, false);
if (ok) {
mSubscribeFlags = data->mMeta.mSubscribeFlags;
mGroupName = QString::fromUtf8(data->mMeta.mGroupName.c_str());
groupNameChanged(mGroupName);
} else {
std::cerr << "GxsMessageFramePostWidget::loadGroupData() ERROR Not just one Group";
std::cerr << std::endl;
mStateHelper->clear(mTokenTypeGroupData);
mGroupName.clear();
groupNameChanged(mGroupName);
}
mStateHelper->setActive(mTokenTypeGroupData, ok);
emit groupChanged(this);
delete data;
}, this );
});
}
#ifdef TO_REMOVE
void GxsMessageFramePostWidget::requestAllPosts()
{
#ifdef ENABLE_DEBUG
@ -313,8 +380,142 @@ void GxsMessageFramePostWidget::loadAllPosts(const uint32_t &token)
emit groupChanged(this);
}
#endif
void GxsMessageFramePostWidget::requestPosts(const std::set<RsGxsMessageId> &msgIds)
void GxsMessageFramePostWidget::loadAllPosts()
{
mNavigatePendingMsgId.clear();
/* Request all posts */
mTokenQueue->cancelActiveRequestTokens(mTokenTypeAllPosts);
if (mFillThread) {
/* Stop current fill thread */
GxsMessageFramePostThread *thread = mFillThread;
mFillThread = NULL;
thread->stop(false);
mStateHelper->setLoading(mTokenTypeAllPosts, false);
}
clearPosts();
if (groupId().isNull()) {
mStateHelper->setActive(mTokenTypeAllPosts, false);
mStateHelper->setLoading(mTokenTypeAllPosts, false);
mStateHelper->clear(mTokenTypeAllPosts);
emit groupChanged(this);
return;
}
mStateHelper->setLoading(mTokenTypeAllPosts, true);
emit groupChanged(this);
RsThread::async([this]()
{
std::vector<RsGxsGenericMsgData*> posts;
getAllMsgData(posts);
RsQThreadUtils::postToObject( [posts,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */
mStateHelper->setActive(mTokenTypeAllPosts, true);
if (useThread()) {
/* Create fill thread */
mFillThread = new GxsMessageFramePostThread(posts,this);
// connect thread
connect(mFillThread, SIGNAL(finished()), this, SLOT(fillThreadFinished()), Qt::BlockingQueuedConnection);
connect(mFillThread, SIGNAL(addPost(QVariant,bool,int,int)), this, SLOT(fillThreadAddPost(QVariant,bool,int,int)), Qt::BlockingQueuedConnection);
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::loadAllPosts() Start fill thread" << std::endl;
#endif
/* Start thread */
mFillThread->start();
}
else
{
insertAllPosts(posts, NULL);
mStateHelper->setLoading(mTokenTypeAllPosts, false);
if (!mNavigatePendingMsgId.isNull())
{
navigate(mNavigatePendingMsgId);
mNavigatePendingMsgId.clear();
}
// don't forget to delete the posts
for(auto& ppost:posts)
delete ppost;
}
emit groupChanged(this);
}, this );
});
}
void GxsMessageFramePostWidget::loadPosts(const std::set<RsGxsMessageId>& msgIds)
{
mNavigatePendingMsgId.clear();
if (groupId().isNull())
{
mStateHelper->setActive(mTokenTypePosts, false);
mStateHelper->setLoading(mTokenTypePosts, false);
mStateHelper->clear(mTokenTypePosts);
emit groupChanged(this);
return;
}
if (msgIds.empty())
return;
mStateHelper->setLoading(mTokenTypePosts, true);
emit groupChanged(this);
RsThread::async([this,msgIds]()
{
std::vector<RsGxsGenericMsgData*> posts;
getMsgData(msgIds,posts);
RsQThreadUtils::postToObject( [posts,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */
mStateHelper->setActive(mTokenTypePosts, true);
insertPosts(posts);
mStateHelper->setLoading(mTokenTypePosts, false);
emit groupChanged(this);
if (!mNavigatePendingMsgId.isNull())
{
navigate(mNavigatePendingMsgId);
mNavigatePendingMsgId.clear();
}
}, this );
});
}
#ifdef TO_REMOVE
void GxsMessageFramePostWidget::requestPosts(const std::set<RsGxsMessageId>& msgIds)
{
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::requestPosts()";
@ -397,13 +598,14 @@ void GxsMessageFramePostWidget::loadRequest(const TokenQueue *queue, const Token
GxsMessageFrameWidget::loadRequest(queue, req);
}
#endif
/**************************************************************/
/** GxsMessageFramePostThread *********************************/
/**************************************************************/
GxsMessageFramePostThread::GxsMessageFramePostThread(uint32_t token, GxsMessageFramePostWidget *parent)
: QThread(parent), mToken(token), mParent(parent)
GxsMessageFramePostThread::GxsMessageFramePostThread(const std::vector<RsGxsGenericMsgData*>& posts,GxsMessageFramePostWidget *parent)
: mPosts(posts),QThread(parent), mParent(parent)
{
mStopped = false;
}
@ -417,9 +619,9 @@ GxsMessageFramePostThread::~GxsMessageFramePostThread()
void GxsMessageFramePostThread::stop(bool waitForStop)
{
if (waitForStop) {
if (waitForStop)
disconnect();
}
mStopped = true;
QApplication::processEvents();
@ -435,7 +637,12 @@ void GxsMessageFramePostThread::run()
std::cerr << "GxsMessageFramePostThread::run()" << std::endl;
#endif
mParent->insertAllPosts(mToken, this);
mParent->insertAllPosts(mPosts,this);
for(auto& ppost:mPosts)
delete ppost;
mPosts.clear(); // dont keep deleted pointers
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostThread::run() stopped: " << (stopped() ? "yes" : "no") << std::endl;

View File

@ -40,12 +40,16 @@ public:
/* GxsMessageFrameWidget */
virtual void groupIdChanged();
virtual QString groupName(bool withUnreadCount);
// virtual QIcon groupIcon() = 0;
virtual bool navigate(const RsGxsMessageId& msgId);
virtual bool isLoading();
// These should be derived in subclasses
virtual bool getGroupData(RsGxsGenericGroupData *& data) =0;
virtual void getMsgData(const std::set<RsGxsMessageId>& msgIds,std::vector<RsGxsGenericMsgData*>& posts) =0;
virtual void getAllMsgData(std::vector<RsGxsGenericMsgData*>& posts) =0;
/* GXS functions */
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
// virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
int subscribeFlags() { return mSubscribeFlags; }
@ -65,16 +69,21 @@ protected:
/* GXS functions */
void requestGroupData();
void loadGroupData(const uint32_t &token);
virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData) = 0;
void loadGroupData();
void loadAllPosts();
void loadPosts(const std::set<RsGxsMessageId>& msgIds);
#ifdef TO_REMOVE
void requestAllPosts();
void loadAllPosts(const uint32_t &token);
void loadAllPosts();
virtual void insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread) = 0;
void requestPosts(const std::set<RsGxsMessageId> &msgIds);
void loadPosts(const uint32_t &token);
virtual void insertPosts(const uint32_t &token) = 0;
//void requestPosts(const std::set<RsGxsMessageId> &msgIds);
//void loadPosts(const uint32_t &token);
#endif
virtual bool insertGroupData(const RsGxsGenericGroupData *data) =0;
virtual void insertPosts(const std::vector<RsGxsGenericMsgData*>& posts) =0;
virtual void insertAllPosts(const std::vector<RsGxsGenericMsgData*>& posts, GxsMessageFramePostThread *thread) =0;
private slots:
void fillThreadFinished();
@ -97,7 +106,7 @@ class GxsMessageFramePostThread : public QThread
Q_OBJECT
public:
GxsMessageFramePostThread(uint32_t token, GxsMessageFramePostWidget *parent);
GxsMessageFramePostThread(const std::vector<RsGxsGenericMsgData*>& posts,GxsMessageFramePostWidget *parent);
~GxsMessageFramePostThread();
void run();
@ -110,7 +119,7 @@ signals:
void addPost(const QVariant &post, bool related, int current, int count);
private:
uint32_t mToken;
std::vector<RsGxsGenericMsgData*> mPosts;
GxsMessageFramePostWidget *mParent;
volatile bool mStopped;
};

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);