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; ~RsGxsChannelGroup() override;
}; };
struct RsGxsChannelPost : RsSerializable struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData
{ {
RsGxsChannelPost() : mCount(0), mSize(0) {} RsGxsChannelPost() : mCount(0), mSize(0) {}
RsMsgMetaData mMeta;
std::set<RsGxsMessageId> mOlderVersions; std::set<RsGxsMessageId> mOlderVersions;
std::string mMsg; // UTF8 encoded. std::string mMsg; // UTF8 encoded.

View File

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

View File

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

View File

@ -46,14 +46,13 @@ struct RsPostedGroup: RsGxsGenericGroupData
RsGxsImage mGroupImage; RsGxsImage mGroupImage;
}; };
struct RsPostedPost struct RsPostedPost: public RsGxsGenericMsgData
{ {
RsPostedPost(): mHaveVoted(false), mUpVotes(0), mDownVotes(0), mComments(0), RsPostedPost(): mHaveVoted(false), mUpVotes(0), mDownVotes(0), mComments(0),
mHotScore(0), mTopScore(0), mNewScore(0) {} mHotScore(0), mTopScore(0), mNewScore(0) {}
bool calculateScores(rstime_t ref_time); bool calculateScores(rstime_t ref_time);
RsMsgMetaData mMeta;
std::string mLink; std::string mLink;
std::string mNotes; 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; insertPostedDetails(*dynamic_cast<const RsPostedGroup*>(data));
rsPosted->getGroupData(token, groups);
if (groups.size() == 1)
{
insertPostedDetails(groups[0]);
metaData = groups[0].mMeta;
return true;
}
return false;
} }
void PostedListWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePostThread */*thread*/) void PostedListWidget::insertAllPostedPosts(const std::vector<RsPostedPost>& posts, GxsMessageFramePostThread */*thread*/)
{ {
std::vector<RsPostedPost> posts; for(auto vit = posts.begin(); vit != posts.end(); ++vit)
rsPosted->getPostData(token, posts);
std::vector<RsPostedPost>::iterator vit;
for(vit = posts.begin(); vit != posts.end(); ++vit)
{ {
RsPostedPost& p = *vit; const RsPostedPost& p = *vit;
loadPost(p); loadPost(p);
loadPostCardView(p); loadPostCardView(p);
} }
@ -916,15 +902,11 @@ void PostedListWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePost
applyRanking(); applyRanking();
} }
void PostedListWidget::insertPosts(const uint32_t &token) void PostedListWidget::insertPostedPosts(const std::vector<RsPostedPost>& posts)
{ {
std::vector<RsPostedPost> posts; for(auto vit = posts.begin(); vit != posts.end(); ++vit)
rsPosted->getPostData(token, posts);
std::vector<RsPostedPost>::iterator vit;
for(vit = posts.begin(); vit != posts.end(); ++vit)
{ {
RsPostedPost& p = *vit; const RsPostedPost& p = *vit;
// modify post content // modify post content
if(mPosts.find(p.mMeta.mMsgId) != mPosts.end()) if(mPosts.find(p.mMeta.mMsgId) != mPosts.end())
@ -1047,3 +1029,68 @@ void PostedListWidget::setViewMode(int viewMode)
return; 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: protected:
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event); 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 */ /* 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 clearPosts();
virtual void blank(); virtual void blank();
virtual bool navigatePostItem(const RsGxsMessageId& msgId); 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 */ /* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read, uint32_t &token); 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 "gui/common/UIStateHelper.h"
#include "retroshare/rsgxsifacehelper.h" #include "retroshare/rsgxsifacehelper.h"
#include "util/qtthreadsutils.h"
//#define ENABLE_DEBUG 1 //#define ENABLE_DEBUG 1
@ -98,8 +99,8 @@ void GxsMessageFramePostWidget::updateDisplay(bool complete)
{ {
if (complete) { if (complete) {
/* Fill complete */ /* Fill complete */
requestGroupData(); loadGroupData();
requestAllPosts(); loadAllPosts();
return; return;
} }
@ -162,6 +163,7 @@ void GxsMessageFramePostWidget::fillThreadFinished()
/** Request / Response of Data ********************************/ /** Request / Response of Data ********************************/
/**************************************************************/ /**************************************************************/
#ifdef TO_REMOVE
void GxsMessageFramePostWidget::requestGroupData() void GxsMessageFramePostWidget::requestGroupData()
{ {
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
@ -230,7 +232,72 @@ void GxsMessageFramePostWidget::loadGroupData(const uint32_t &token)
emit groupChanged(this); 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() void GxsMessageFramePostWidget::requestAllPosts()
{ {
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
@ -313,8 +380,142 @@ void GxsMessageFramePostWidget::loadAllPosts(const uint32_t &token)
emit groupChanged(this); 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 #ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::requestPosts()"; std::cerr << "GxsMessageFramePostWidget::requestPosts()";
@ -397,13 +598,14 @@ void GxsMessageFramePostWidget::loadRequest(const TokenQueue *queue, const Token
GxsMessageFrameWidget::loadRequest(queue, req); GxsMessageFrameWidget::loadRequest(queue, req);
} }
#endif
/**************************************************************/ /**************************************************************/
/** GxsMessageFramePostThread *********************************/ /** GxsMessageFramePostThread *********************************/
/**************************************************************/ /**************************************************************/
GxsMessageFramePostThread::GxsMessageFramePostThread(uint32_t token, GxsMessageFramePostWidget *parent) GxsMessageFramePostThread::GxsMessageFramePostThread(const std::vector<RsGxsGenericMsgData*>& posts,GxsMessageFramePostWidget *parent)
: QThread(parent), mToken(token), mParent(parent) : mPosts(posts),QThread(parent), mParent(parent)
{ {
mStopped = false; mStopped = false;
} }
@ -417,9 +619,9 @@ GxsMessageFramePostThread::~GxsMessageFramePostThread()
void GxsMessageFramePostThread::stop(bool waitForStop) void GxsMessageFramePostThread::stop(bool waitForStop)
{ {
if (waitForStop) { if (waitForStop)
disconnect(); disconnect();
}
mStopped = true; mStopped = true;
QApplication::processEvents(); QApplication::processEvents();
@ -435,7 +637,12 @@ void GxsMessageFramePostThread::run()
std::cerr << "GxsMessageFramePostThread::run()" << std::endl; std::cerr << "GxsMessageFramePostThread::run()" << std::endl;
#endif #endif
mParent->insertAllPosts(mToken, this); mParent->insertAllPosts(mPosts,this);
for(auto& ppost:mPosts)
delete ppost;
mPosts.clear(); // dont keep deleted pointers
#ifdef ENABLE_DEBUG #ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostThread::run() stopped: " << (stopped() ? "yes" : "no") << std::endl; std::cerr << "GxsMessageFramePostThread::run() stopped: " << (stopped() ? "yes" : "no") << std::endl;

View File

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

View File

@ -506,7 +506,7 @@ void GxsChannelPostsWidget::fillThreadCreatePost(const QVariant &post, bool rela
createPostItem(post.value<RsGxsChannelPost>(), related); 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) { if (related && thread) {
std::cerr << "GxsChannelPostsWidget::insertChannelPosts fill only related posts as thread is not possible" << std::endl; 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; insertChannelDetails(*dynamic_cast<const RsGxsChannelGroup*>(data));
rsGxsChannels->getGroupData(token, groups); mChannelGroupId = data->mMeta.mGroupId;
return true;
if(groups.size() == 1) }
{
insertChannelDetails(groups[0]); #ifdef TO_REMOVE
metaData = groups[0].mMeta; void GxsChannelPostsWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread)
mChannelGroupId = groups[0].mMeta.mGroupId; {
return true; 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 else
{ {
RsGxsChannelGroup distant_group; RsGxsChannelGroup distant_group;
if(rsGxsChannels->retrieveDistantGroup(groupId(),distant_group)) if(rsGxsChannels->retrieveDistantGroup(groupId(),distant_group))
{ {
insertChannelDetails(distant_group); insertChannelDetails(distant_group);
metaData = distant_group.mMeta; data = new RsGxsChannelGroup(distant_group);
mChannelGroupId = distant_group.mMeta.mGroupId; mChannelGroupId = distant_group.mMeta.mGroupId;
return true ; return true ;
} }
@ -761,14 +803,32 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa
return false; 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; std::vector<RsGxsChannelPost> cposts;
rsGxsChannels->getPostData(token, posts);
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) void GxsChannelPostsWidget::insertPosts(const uint32_t &token)
{ {
std::vector<RsGxsChannelPost> posts; std::vector<RsGxsChannelPost> posts;
@ -776,6 +836,7 @@ void GxsChannelPostsWidget::insertPosts(const uint32_t &token)
insertChannelPosts(posts, NULL, true); insertChannelPosts(posts, NULL, true);
} }
#endif
class GxsChannelPostsReadData class GxsChannelPostsReadData
{ {

View File

@ -65,7 +65,7 @@ public:
protected: protected:
/* GxsMessageFramePostWidget */ /* GxsMessageFramePostWidget */
virtual void groupNameChanged(const QString &name); 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 insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread);
virtual void insertPosts(const uint32_t &token); virtual void insertPosts(const uint32_t &token);
virtual void clearPosts(); virtual void clearPosts();
@ -74,6 +74,12 @@ protected:
virtual bool navigatePostItem(const RsGxsMessageId& msgId); virtual bool navigatePostItem(const RsGxsMessageId& msgId);
virtual void blank() ; 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 */ /* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read, uint32_t &token); virtual void setAllMessagesReadDo(bool read, uint32_t &token);