finished converting GxsMessageFrameWidget to blocking API

This commit is contained in:
csoler 2020-03-31 20:21:16 +02:00
parent 55c810f848
commit cf7a77e512
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
13 changed files with 98 additions and 41 deletions

View file

@ -217,7 +217,8 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
mmr->mMsgIds[*lit] = std::set<RsGxsMessageId>(); mmr->mMsgIds[*lit] = std::set<RsGxsMessageId>();
req = mmr; req = mmr;
}else if(reqType & GXS_REQUEST_TYPE_MSG_DATA) }
else if(reqType & GXS_REQUEST_TYPE_MSG_DATA)
{ {
MsgDataReq* mdr = new MsgDataReq(); MsgDataReq* mdr = new MsgDataReq();
@ -225,7 +226,8 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
mdr->mMsgIds[*lit] = std::set<RsGxsMessageId>(); mdr->mMsgIds[*lit] = std::set<RsGxsMessageId>();
req = mdr; req = mdr;
}else if(reqType & GXS_REQUEST_TYPE_MSG_IDS) }
else if(reqType & GXS_REQUEST_TYPE_MSG_IDS)
{ {
MsgIdReq* mir = new MsgIdReq(); MsgIdReq* mir = new MsgIdReq();

View file

@ -323,7 +323,20 @@ public:
std::vector<RsGxsChannelGroup>& channelsInfo ) = 0; std::vector<RsGxsChannelGroup>& channelsInfo ) = 0;
/** /**
* @brief Get channel contents * @brief Get all channel messages and comments in a given channel
* @jsonapi{development}
* @param[in] channelId id of the channel of which the content is requested
* @param[out] posts storage for posts
* @param[out] comments storage for the comments
* @return false if something failed, true otherwhise
*/
virtual bool getChannelAllContent(const RsGxsGroupId& channelId,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
/**
* @brief Get channel messages and comments corresponding to the given message ID list. If the list is empty, nothing is returned. Since
* comments are themselves messages, it is possible to get comments only by only supplying their message IDs.
* @jsonapi{development} * @jsonapi{development}
* @param[in] channelId id of the channel of which the content is requested * @param[in] channelId id of the channel of which the content is requested
* @param[in] contentsIds ids of requested contents * @param[in] contentsIds ids of requested contents
@ -331,10 +344,10 @@ public:
* @param[out] comments storage for the comments * @param[out] comments storage for the comments
* @return false if something failed, true otherwhise * @return false if something failed, true otherwhise
*/ */
virtual bool getChannelContent( const RsGxsGroupId& channelId, virtual bool getChannelContent(const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds, const std::set<RsGxsMessageId>& contentIds,
std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) = 0; std::vector<RsGxsComment>& comments ) = 0;
/** /**
* @brief Get channel content summaries * @brief Get channel content summaries

View file

@ -40,8 +40,11 @@
* are necessary, so at this point this workaround seems acceptable. * are necessary, so at this point this workaround seems acceptable.
*/ */
#define DEBUG_GXSIFACEHELPER 1
enum class TokenRequestType: uint8_t enum class TokenRequestType: uint8_t
{ {
UNDEFINED = 0x00,
GROUP_INFO = 0x01, GROUP_INFO = 0x01,
POSTS = 0x02, POSTS = 0x02,
ALL_POSTS = 0x03, ALL_POSTS = 0x03,
@ -284,7 +287,8 @@ public:
if(mTokenService.requestMsgInfo(token, 0, opts, msgIds)) if(mTokenService.requestMsgInfo(token, 0, opts, msgIds))
{ {
RS_STACK_MUTEX(mMtx); RS_STACK_MUTEX(mMtx);
mActiveTokens[token]= msgIds.empty()?(TokenRequestType::ALL_POSTS):(TokenRequestType::POSTS);
mActiveTokens[token]= (msgIds.size()==1 && msgIds.begin()->second.size()==0) ?(TokenRequestType::ALL_POSTS):(TokenRequestType::POSTS);
locked_dumpTokens(); locked_dumpTokens();
return true; return true;
} }
@ -459,15 +463,15 @@ private:
uint32_t count[7] = {0}; uint32_t count[7] = {0};
std::cerr << "Service 0x0" << std::hex << service_id std::cerr << "Service " << std::hex << service_id << std::dec
<< " (" << rsServiceControl->getServiceName(RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(service_id)) << " (" << rsServiceControl->getServiceName(RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(service_id))
<< ") this=0x" << (void*)this << ") Active tokens (per type): " ; << ") this=" << std::hex << (void*)this << std::dec << ") Active tokens (per type): " ;
for(auto& it: mActiveTokens) // let's count how many token of each type we've got. for(auto& it: mActiveTokens) // let's count how many token of each type we've got.
++count[static_cast<int>(it.second)]; ++count[static_cast<int>(it.second)];
for(uint32_t i=0;i<7;++i) for(uint32_t i=0;i<7;++i)
std::cerr /* << i << ":" */ << count[i] << " "; std::cerr << std::dec /* << i << ":" */ << count[i] << " ";
std::cerr << std::endl; std::cerr << std::endl;
} }
}; };

View file

@ -150,6 +150,11 @@ public:
virtual bool getBoardsSummaries(std::list<RsGroupMetaData>& groupInfo) =0; virtual bool getBoardsSummaries(std::list<RsGroupMetaData>& groupInfo) =0;
virtual bool getBoardAllContent(
const RsGxsGroupId& boardId,
std::vector<RsPostedPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
virtual bool getBoardContent( virtual bool getBoardContent(
const RsGxsGroupId& boardId, const RsGxsGroupId& boardId,
const std::set<RsGxsMessageId>& contentsIds, const std::set<RsGxsMessageId>& contentsIds,

View file

@ -1083,20 +1083,34 @@ bool p3GxsChannels::getContentSummaries(
return res; return res;
} }
bool p3GxsChannels::getChannelAllContent( const RsGxsGroupId& channelId,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments )
{
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
if( !requestMsgInfo(token, opts,std::list<RsGxsGroupId>({channelId})) || waitToken(token) != RsTokenService::COMPLETE )
return false;
return getPostData(token, posts, comments);
}
bool p3GxsChannels::getChannelContent( const RsGxsGroupId& channelId, bool p3GxsChannels::getChannelContent( const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds, const std::set<RsGxsMessageId>& contentIds,
std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) std::vector<RsGxsComment>& comments )
{ {
uint32_t token; uint32_t token;
RsTokReqOptions opts; RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
GxsMsgReq msgIds; GxsMsgReq msgIds;
msgIds[channelId] = contentsIds; msgIds[channelId] = contentIds;
if( !requestMsgInfo(token, opts, msgIds) || if( !requestMsgInfo(token, opts, msgIds) || waitToken(token) != RsTokenService::COMPLETE )
waitToken(token) != RsTokenService::COMPLETE ) return false; return false;
return getPostData(token, posts, comments); return getPostData(token, posts, comments);
} }

View file

@ -185,9 +185,14 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
const std::list<RsGxsGroupId>& chanIds, const std::list<RsGxsGroupId>& chanIds,
std::vector<RsGxsChannelGroup>& channelsInfo ) override; std::vector<RsGxsChannelGroup>& channelsInfo ) override;
/// Implementation of @see RsGxsChannels::getChannelContent /// Implementation of @see RsGxsChannels::getChannelAllMessages
bool getChannelContent( const RsGxsGroupId& channelId, bool getChannelAllContent(const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds, std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) override;
/// Implementation of @see RsGxsChannels::getChannelMessages
bool getChannelContent(const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentIds,
std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) override; std::vector<RsGxsComment>& comments ) override;

View file

@ -322,6 +322,20 @@ bool p3Posted::getBoardsInfo(
return getGroupData(token, groupsInfo) && !groupsInfo.empty(); return getGroupData(token, groupsInfo) && !groupsInfo.empty();
} }
bool p3Posted::getBoardAllContent( const RsGxsGroupId& groupId,
std::vector<RsPostedPost>& posts,
std::vector<RsGxsComment>& comments )
{
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
if( !requestMsgInfo(token, opts, std::list<RsGxsGroupId>({groupId})) || waitToken(token) != RsTokenService::COMPLETE )
return false;
return getPostData(token, posts, comments);
}
bool p3Posted::getBoardContent( const RsGxsGroupId& groupId, bool p3Posted::getBoardContent( const RsGxsGroupId& groupId,
const std::set<RsGxsMessageId>& contentsIds, const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsPostedPost>& posts, std::vector<RsPostedPost>& posts,

View file

@ -61,6 +61,10 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
bool getBoardsInfo(const std::list<RsGxsGroupId>& boardsIds, bool getBoardsInfo(const std::list<RsGxsGroupId>& boardsIds,
std::vector<RsPostedGroup>& groupsInfo ) override; std::vector<RsPostedGroup>& groupsInfo ) override;
bool getBoardAllContent(const RsGxsGroupId& groupId,
std::vector<RsPostedPost>& posts,
std::vector<RsGxsComment>& comments ) override;
bool getBoardContent(const RsGxsGroupId& groupId, bool getBoardContent(const RsGxsGroupId& groupId,
const std::set<RsGxsMessageId>& contentsIds, const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsPostedPost>& posts, std::vector<RsPostedPost>& posts,

View file

@ -888,6 +888,7 @@ void PostedListWidget::shallowClearPosts()
bool PostedListWidget::insertGroupData(const RsGxsGenericGroupData *data) bool PostedListWidget::insertGroupData(const RsGxsGenericGroupData *data)
{ {
insertPostedDetails(*dynamic_cast<const RsPostedGroup*>(data)); insertPostedDetails(*dynamic_cast<const RsPostedGroup*>(data));
return true;
} }
void PostedListWidget::insertAllPostedPosts(const std::vector<RsPostedPost>& posts, GxsMessageFramePostThread */*thread*/) void PostedListWidget::insertAllPostedPosts(const std::vector<RsPostedPost>& posts, GxsMessageFramePostThread */*thread*/)
@ -1048,7 +1049,7 @@ void PostedListWidget::getAllMsgData(std::vector<RsGxsGenericMsgData*>& psts)
std::vector<RsPostedPost> posts; std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> comments; std::vector<RsGxsComment> comments;
rsPosted->getBoardContent( groupId(),std::set<RsGxsMessageId>(),posts,comments ); rsPosted->getBoardAllContent( groupId(),posts,comments );
psts.clear(); psts.clear();
@ -1073,10 +1074,7 @@ void PostedListWidget::insertPosts(const std::vector<RsGxsGenericMsgData*>& post
std::vector<RsPostedPost> cposts; 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. 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)); cposts.push_back(*dynamic_cast<RsPostedPost*>(post));
delete post;
}
insertPostedPosts(cposts); insertPostedPosts(cposts);
} }
@ -1086,10 +1084,7 @@ void PostedListWidget::insertAllPosts(const std::vector<RsGxsGenericMsgData*>& p
std::vector<RsPostedPost> cposts; 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. 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)); cposts.push_back(*dynamic_cast<RsPostedPost*>(post));
delete post;
}
insertAllPostedPosts(cposts, NULL); insertAllPostedPosts(cposts, NULL);
} }

View file

@ -510,6 +510,12 @@ void GxsMessageFramePostWidget::loadPosts(const std::set<RsGxsMessageId>& msgIds
mNavigatePendingMsgId.clear(); mNavigatePendingMsgId.clear();
} }
// don't forget to delete posts.
for(auto& post:posts)
delete post;
}, this ); }, this );
}); });
} }

View file

@ -81,6 +81,8 @@ protected:
//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);
#endif #endif
// In the following 3 methods, the memory ownership is kept by GxsMessageFramePostWidget
virtual bool insertGroupData(const RsGxsGenericGroupData *data) =0; virtual bool insertGroupData(const RsGxsGenericGroupData *data) =0;
virtual void insertPosts(const std::vector<RsGxsGenericMsgData*>& posts) =0; virtual void insertPosts(const std::vector<RsGxsGenericMsgData*>& posts) =0;
virtual void insertAllPosts(const std::vector<RsGxsGenericMsgData*>& posts, GxsMessageFramePostThread *thread) =0; virtual void insertAllPosts(const std::vector<RsGxsGenericMsgData*>& posts, GxsMessageFramePostThread *thread) =0;

View file

@ -148,7 +148,7 @@ void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEven
case RsChannelEventCode::NEW_CHANNEL: case RsChannelEventCode::NEW_CHANNEL:
case RsChannelEventCode::UPDATED_MESSAGE: case RsChannelEventCode::UPDATED_MESSAGE:
case RsChannelEventCode::NEW_MESSAGE: case RsChannelEventCode::NEW_MESSAGE:
if(e->mChannelGroupId == mChannelGroupId) if(e->mChannelGroupId == groupId())
updateDisplay(true); updateDisplay(true);
break; break;
default: default:
@ -737,7 +737,6 @@ void GxsChannelPostsWidget::toggleAutoDownload()
bool GxsChannelPostsWidget::insertGroupData(const RsGxsGenericGroupData *data) bool GxsChannelPostsWidget::insertGroupData(const RsGxsGenericGroupData *data)
{ {
insertChannelDetails(*dynamic_cast<const RsGxsChannelGroup*>(data)); insertChannelDetails(*dynamic_cast<const RsGxsChannelGroup*>(data));
mChannelGroupId = data->mMeta.mGroupId;
return true; return true;
} }
@ -757,7 +756,7 @@ void GxsChannelPostsWidget::getMsgData(const std::set<RsGxsMessageId>& msgIds,st
std::vector<RsGxsChannelPost> posts; std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments; std::vector<RsGxsComment> comments;
rsGxsChannels->getChannelContent( mChannelGroupId,msgIds,posts,comments ); rsGxsChannels->getChannelContent( groupId(),msgIds,posts,comments );
psts.clear(); psts.clear();
@ -770,7 +769,7 @@ void GxsChannelPostsWidget::getAllMsgData(std::vector<RsGxsGenericMsgData*>& pst
std::vector<RsGxsChannelPost> posts; std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments; std::vector<RsGxsComment> comments;
rsGxsChannels->getChannelContent( mChannelGroupId,std::set<RsGxsMessageId>(),posts,comments ); rsGxsChannels->getChannelAllContent( groupId(),posts,comments );
psts.clear(); psts.clear();
@ -795,7 +794,6 @@ bool GxsChannelPostsWidget::getGroupData(RsGxsGenericGroupData *& data)
{ {
insertChannelDetails(distant_group); insertChannelDetails(distant_group);
data = new RsGxsChannelGroup(distant_group); data = new RsGxsChannelGroup(distant_group);
mChannelGroupId = distant_group.mMeta.mGroupId;
return true ; return true ;
} }
} }
@ -808,10 +806,7 @@ void GxsChannelPostsWidget::insertAllPosts(const std::vector<RsGxsGenericMsgData
std::vector<RsGxsChannelPost> cposts; 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. 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(*static_cast<RsGxsChannelPost*>(post));
cposts.push_back(*dynamic_cast<RsGxsChannelPost*>(post));
delete post;
}
insertChannelPosts(cposts, thread, false); insertChannelPosts(cposts, thread, false);
} }
@ -820,10 +815,7 @@ void GxsChannelPostsWidget::insertPosts(const std::vector<RsGxsGenericMsgData*>&
std::vector<RsGxsChannelPost> cposts; 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. 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(*static_cast<RsGxsChannelPost*>(post));
cposts.push_back(*dynamic_cast<RsGxsChannelPost*>(post));
delete post;
}
insertChannelPosts(cposts, NULL, true); insertChannelPosts(cposts, NULL, true);
} }

View file

@ -66,8 +66,10 @@ protected:
/* GxsMessageFramePostWidget */ /* GxsMessageFramePostWidget */
virtual void groupNameChanged(const QString &name); virtual void groupNameChanged(const QString &name);
virtual bool insertGroupData(const RsGxsGenericGroupData *data) override; virtual bool insertGroupData(const RsGxsGenericGroupData *data) override;
#ifdef TO_REMOVE
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);
#endif
virtual void clearPosts(); virtual void clearPosts();
virtual bool useThread() { return mUseThread; } virtual bool useThread() { return mUseThread; }
virtual void fillThreadCreatePost(const QVariant &post, bool related, int current, int count); virtual void fillThreadCreatePost(const QVariant &post, bool related, int current, int count);
@ -109,7 +111,6 @@ private:
QAction *mAutoDownloadAction; QAction *mAutoDownloadAction;
bool mUseThread; bool mUseThread;
RsGxsGroupId mChannelGroupId;
RsEventsHandlerId_t mEventHandlerId ; RsEventsHandlerId_t mEventHandlerId ;
/* UI - from Designer */ /* UI - from Designer */