mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
1/4 convertion of GxsGroupFrameDialog to blocking API
This commit is contained in:
parent
1a9ac16546
commit
2387150f64
@ -25,6 +25,9 @@
|
||||
* #define RS_DATA_SERVICE_DEBUG_TIME 1
|
||||
* #define RS_DATA_SERVICE_DEBUG_CACHE 1
|
||||
****/
|
||||
#define RS_DATA_SERVICE_DEBUG 1
|
||||
#define RS_DATA_SERVICE_DEBUG_TIME 1
|
||||
#define RS_DATA_SERVICE_DEBUG_CACHE 1
|
||||
|
||||
#include <fstream>
|
||||
#include <util/rsdir.h>
|
||||
@ -1343,6 +1346,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
||||
}
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
if(mDbName==std::string("gxsforums_db"))
|
||||
std::cerr << "RsDataService::retrieveGxsMsgMetaData() " << mDbName << ", Requests: " << reqIds.size() << ", Results: " << resultCount << ", Time: " << timer.duration() << std::endl;
|
||||
#endif
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
/***********
|
||||
* #define DATA_DEBUG 1
|
||||
**********/
|
||||
#define DATA_DEBUG 1
|
||||
|
||||
RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds) :
|
||||
mDataStore(ds), mDataMutex("RsGxsDataAccess"), mNextToken(0) {}
|
||||
|
@ -45,11 +45,10 @@ class RsGxsChannels;
|
||||
extern RsGxsChannels* rsGxsChannels;
|
||||
|
||||
|
||||
struct RsGxsChannelGroup : RsSerializable
|
||||
struct RsGxsChannelGroup : RsSerializable, RsGxsGenericGroupData
|
||||
{
|
||||
RsGxsChannelGroup() : mAutoDownload(false) {}
|
||||
|
||||
RsGroupMetaData mMeta;
|
||||
std::string mDescription;
|
||||
RsGxsImage mImage;
|
||||
|
||||
|
@ -54,11 +54,8 @@ static const uint32_t RS_GXS_FORUM_MSG_FLAGS_MODERATED = 0x00000001;
|
||||
#define IS_FORUM_MSG_MODERATION(flags) (flags & RS_GXS_FORUM_MSG_FLAGS_MODERATED)
|
||||
|
||||
|
||||
struct RsGxsForumGroup : RsSerializable
|
||||
struct RsGxsForumGroup : RsSerializable, RsGxsGenericGroupData
|
||||
{
|
||||
/** Forum GXS metadata */
|
||||
RsGroupMetaData mMeta;
|
||||
|
||||
/** @brief Forum desciption */
|
||||
std::string mDescription;
|
||||
|
||||
|
@ -118,8 +118,15 @@ struct RsGroupMetaData : RsSerializable
|
||||
}
|
||||
};
|
||||
|
||||
// This is the parent class of all interface-level GXS group data. Derived classes
|
||||
// will include service-specific information, such as icon, description, etc
|
||||
|
||||
struct RsGxsGenericGroupData
|
||||
{
|
||||
virtual ~RsGxsGenericGroupData() = default; // making the type polymorphic
|
||||
|
||||
RsGroupMetaData mMeta;
|
||||
};
|
||||
|
||||
struct RsMsgMetaData : RsSerializable
|
||||
{
|
||||
|
@ -40,9 +40,8 @@ class RsPosted;
|
||||
*/
|
||||
extern RsPosted* rsPosted;
|
||||
|
||||
struct RsPostedGroup
|
||||
struct RsPostedGroup: RsGxsGenericGroupData
|
||||
{
|
||||
RsGroupMetaData mMeta;
|
||||
std::string mDescription;
|
||||
RsGxsImage mGroupImage;
|
||||
};
|
||||
@ -150,6 +149,8 @@ public:
|
||||
const std::list<RsGxsGroupId>& boardsIds,
|
||||
std::vector<RsPostedGroup>& boardsInfo ) = 0;
|
||||
|
||||
virtual bool getBoardsSummaries(std::list<RsGroupMetaData>& groupInfo) =0;
|
||||
|
||||
virtual bool getBoardContent(
|
||||
const RsGxsGroupId& boardId,
|
||||
const std::set<RsGxsMessageId>& contentsIds,
|
||||
|
@ -1033,15 +1033,23 @@ bool p3GxsChannels::getChannelsSummaries(
|
||||
return getGroupSummary(token, channels);
|
||||
}
|
||||
|
||||
bool p3GxsChannels::getChannelsInfo(
|
||||
const std::list<RsGxsGroupId>& chanIds,
|
||||
std::vector<RsGxsChannelGroup>& channelsInfo )
|
||||
bool p3GxsChannels::getChannelsInfo( const std::list<RsGxsGroupId>& chanIds, std::vector<RsGxsChannelGroup>& channelsInfo )
|
||||
{
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
if( !requestGroupInfo(token, opts, chanIds)
|
||||
|| waitToken(token) != RsTokenService::COMPLETE ) return false;
|
||||
|
||||
if(chanIds.empty())
|
||||
{
|
||||
if( !requestGroupInfo(token, opts) || waitToken(token) != RsTokenService::COMPLETE )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !requestGroupInfo(token, opts, chanIds) || waitToken(token) != RsTokenService::COMPLETE )
|
||||
return false;
|
||||
}
|
||||
|
||||
return getGroupData(token, channelsInfo) && !channelsInfo.empty();
|
||||
}
|
||||
|
||||
|
@ -666,15 +666,22 @@ bool p3GxsForums::getForumsSummaries( std::list<RsGroupMetaData>& forums )
|
||||
return getGroupSummary(token, forums);
|
||||
}
|
||||
|
||||
bool p3GxsForums::getForumsInfo(
|
||||
const std::list<RsGxsGroupId>& forumIds,
|
||||
std::vector<RsGxsForumGroup>& forumsInfo )
|
||||
bool p3GxsForums::getForumsInfo( const std::list<RsGxsGroupId>& forumIds, std::vector<RsGxsForumGroup>& forumsInfo )
|
||||
{
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||
if( !requestGroupInfo(token, opts, forumIds)
|
||||
|| waitToken(token,std::chrono::milliseconds(5000)) != RsTokenService::COMPLETE ) return false;
|
||||
|
||||
if(forumIds.empty())
|
||||
{
|
||||
if( !requestGroupInfo(token, opts) || waitToken(token,std::chrono::milliseconds(5000)) != RsTokenService::COMPLETE )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !requestGroupInfo(token, opts, forumIds) || waitToken(token,std::chrono::milliseconds(5000)) != RsTokenService::COMPLETE )
|
||||
return false;
|
||||
}
|
||||
return getGroupData(token, forumsInfo);
|
||||
}
|
||||
|
||||
|
@ -330,5 +330,15 @@ bool p3Posted::getBoardContent( const RsGxsGroupId& groupId,
|
||||
return getPostData(token, posts, comments);
|
||||
}
|
||||
|
||||
bool p3Posted::getBoardsSummaries(std::list<RsGroupMetaData>& boards )
|
||||
{
|
||||
uint32_t token;
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
||||
if( !requestGroupInfo(token, opts) || waitToken(token) != RsTokenService::COMPLETE ) return false;
|
||||
|
||||
return getGroupSummary(token, boards);
|
||||
}
|
||||
|
||||
RsPosted::~RsPosted() = default;
|
||||
RsGxsPostedEvent::~RsGxsPostedEvent() = default;
|
||||
|
@ -66,6 +66,8 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
|
||||
std::vector<RsPostedPost>& posts,
|
||||
std::vector<RsGxsComment>& comments ) override;
|
||||
|
||||
bool getBoardsSummaries(std::list<RsGroupMetaData>& groupInfo) override;
|
||||
|
||||
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups);
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts);
|
||||
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) { std::vector<RsGxsComment> cmts; return getPostData( token, posts, cmts);}
|
||||
|
@ -150,6 +150,21 @@ QString PostedDialog::icon(IconType type)
|
||||
return "";
|
||||
}
|
||||
|
||||
bool PostedDialog::getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo)
|
||||
{
|
||||
std::vector<RsPostedGroup> groups;
|
||||
|
||||
// request all group infos at once
|
||||
|
||||
if(! rsPosted->getBoardsInfo(std::list<RsGxsGroupId>(),groups))
|
||||
return false;
|
||||
|
||||
/* Save groups to fill icons and description */
|
||||
|
||||
for (auto& group: groups)
|
||||
groupInfo.push_back(new RsPostedGroup(group));
|
||||
}
|
||||
|
||||
GxsGroupDialog *PostedDialog::createNewGroupDialog(TokenQueue *tokenQueue)
|
||||
{
|
||||
return new PostedGroupDialog(tokenQueue, this);
|
||||
@ -180,6 +195,7 @@ QWidget *PostedDialog::createCommentHeaderWidget(const RsGxsGroupId &grpId, cons
|
||||
return new PostedItem(NULL, 0, grpId, msgId, true, false);
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
void PostedDialog::loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata *&userdata)
|
||||
{
|
||||
std::vector<RsPostedGroup> groups;
|
||||
@ -205,25 +221,23 @@ void PostedDialog::loadGroupSummaryToken(const uint32_t &token, std::list<RsGrou
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void PostedDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata)
|
||||
void PostedDialog::groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupData, GroupItemInfo &groupItemInfo)
|
||||
{
|
||||
GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupInfo, groupItemInfo, userdata);
|
||||
GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupData, groupItemInfo);
|
||||
|
||||
const PostedGroupInfoData *postedData = dynamic_cast<const PostedGroupInfoData*>(userdata);
|
||||
if (!postedData) {
|
||||
std::cerr << "PostedDialog::groupInfoToGroupItemInfo() Failed to cast data to PostedGroupInfoData";
|
||||
std::cerr << std::endl;
|
||||
const RsPostedGroup *postedGroupData = dynamic_cast<const RsPostedGroup*>(groupData);
|
||||
|
||||
if (!postedGroupData)
|
||||
{
|
||||
std::cerr << "PostedDialog::groupInfoToGroupItemInfo() Failed to cast data to RsPostedGroup"<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QMap<RsGxsGroupId, QString>::const_iterator descriptionIt = postedData->mDescription.find(groupInfo.mGroupId);
|
||||
if (descriptionIt != postedData->mDescription.end()) {
|
||||
groupItemInfo.description = descriptionIt.value();
|
||||
}
|
||||
QPixmap image;
|
||||
GxsIdDetails::loadPixmapFromData(postedGroupData->mGroupImage.mData, postedGroupData->mGroupImage.mSize, image,GxsIdDetails::ORIGINAL);
|
||||
|
||||
QMap<RsGxsGroupId, QIcon>::const_iterator iconIt = postedData->mIcon.find(groupInfo.mGroupId);
|
||||
if (iconIt != postedData->mIcon.end()) {
|
||||
groupItemInfo.icon = iconIt.value();
|
||||
}
|
||||
groupItemInfo.description = QString::fromUtf8(postedGroupData->mDescription.c_str());
|
||||
groupItemInfo.icon = image;
|
||||
}
|
||||
|
@ -45,7 +45,9 @@ protected:
|
||||
virtual QString getHelpString() const ;
|
||||
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_POSTED; }
|
||||
virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Posted; }
|
||||
virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata);
|
||||
|
||||
void groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupData, GroupItemInfo &groupItemInfo) override;
|
||||
bool getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo) override;
|
||||
|
||||
private:
|
||||
/* GxsGroupFrameDialog */
|
||||
@ -59,7 +61,6 @@ private:
|
||||
virtual RsGxsCommentService *getCommentService();
|
||||
virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId);
|
||||
virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_DATA; } // request complete group data
|
||||
virtual void loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata* &userdata);
|
||||
|
||||
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
|
||||
RsEventsHandlerId_t mEventHandlerId;
|
||||
|
@ -33,6 +33,8 @@
|
||||
#include "gui/notifyqt.h"
|
||||
#include "gui/common/UIStateHelper.h"
|
||||
#include "gui/common/UserNotify.h"
|
||||
#include "util/qtthreadsutils.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
#include "GxsCommentDialog.h"
|
||||
|
||||
//#define DEBUG_GROUPFRAMEDIALOG
|
||||
@ -134,7 +136,7 @@ void GxsGroupFrameDialog::getGroupList(std::map<RsGxsGroupId, RsGroupMetaData> &
|
||||
group_list = mCachedGroupMetas ;
|
||||
|
||||
if(group_list.empty())
|
||||
requestGroupSummary();
|
||||
updateGroupSummary();
|
||||
}
|
||||
void GxsGroupFrameDialog::initUi()
|
||||
{
|
||||
@ -242,7 +244,7 @@ void GxsGroupFrameDialog::setHideTabBarWithOneTab(bool hideTabBarWithOneTab)
|
||||
void GxsGroupFrameDialog::updateDisplay(bool complete)
|
||||
{
|
||||
if(complete) // || !getGrpIds().empty() || !getGrpIdsMeta().empty()) {
|
||||
requestGroupSummary(); /* Update group list */
|
||||
updateGroupSummary(); /* Update group list */
|
||||
|
||||
updateSearchResults() ;
|
||||
}
|
||||
@ -896,16 +898,16 @@ void GxsGroupFrameDialog::messageTabWaitingChanged(QWidget *widget)
|
||||
}
|
||||
|
||||
///***** INSERT GROUP LISTS *****/
|
||||
void GxsGroupFrameDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata */*userdata*/)
|
||||
void GxsGroupFrameDialog::groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupInfo, GroupItemInfo &groupItemInfo)
|
||||
{
|
||||
groupItemInfo.id = QString::fromStdString(groupInfo.mGroupId.toStdString());
|
||||
groupItemInfo.name = QString::fromUtf8(groupInfo.mGroupName.c_str());
|
||||
groupItemInfo.popularity = groupInfo.mPop;
|
||||
groupItemInfo.lastpost = QDateTime::fromTime_t(groupInfo.mLastPost);
|
||||
groupItemInfo.subscribeFlags = groupInfo.mSubscribeFlags;
|
||||
groupItemInfo.publishKey = IS_GROUP_PUBLISHER(groupInfo.mSubscribeFlags) ;
|
||||
groupItemInfo.adminKey = IS_GROUP_ADMIN(groupInfo.mSubscribeFlags) ;
|
||||
groupItemInfo.max_visible_posts = groupInfo.mVisibleMsgCount ;
|
||||
groupItemInfo.id = QString::fromStdString(groupInfo->mMeta.mGroupId.toStdString());
|
||||
groupItemInfo.name = QString::fromUtf8(groupInfo->mMeta.mGroupName.c_str());
|
||||
groupItemInfo.popularity = groupInfo->mMeta.mPop;
|
||||
groupItemInfo.lastpost = QDateTime::fromTime_t(groupInfo->mMeta.mLastPost);
|
||||
groupItemInfo.subscribeFlags = groupInfo->mMeta.mSubscribeFlags;
|
||||
groupItemInfo.publishKey = IS_GROUP_PUBLISHER(groupInfo->mMeta.mSubscribeFlags) ;
|
||||
groupItemInfo.adminKey = IS_GROUP_ADMIN(groupInfo->mMeta.mSubscribeFlags) ;
|
||||
groupItemInfo.max_visible_posts = groupInfo->mMeta.mVisibleMsgCount ;
|
||||
|
||||
#if TOGXS
|
||||
if (groupInfo.mGroupFlags & RS_DISTRIB_AUTHEN_REQ) {
|
||||
@ -919,7 +921,7 @@ void GxsGroupFrameDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupI
|
||||
}
|
||||
}
|
||||
|
||||
void GxsGroupFrameDialog::insertGroupsData(const std::map<RsGxsGroupId,RsGroupMetaData> &groupList, const RsUserdata *userdata)
|
||||
void GxsGroupFrameDialog::insertGroupsData(const std::list<RsGxsGenericGroupData*>& groupList)
|
||||
{
|
||||
if (!mInitialized) {
|
||||
return;
|
||||
@ -933,54 +935,38 @@ void GxsGroupFrameDialog::insertGroupsData(const std::map<RsGxsGroupId,RsGroupMe
|
||||
QList<GroupItemInfo> otherList;
|
||||
std::multimap<uint32_t, GroupItemInfo> popMap;
|
||||
|
||||
for (auto it = groupList.begin(); it != groupList.end(); ++it) {
|
||||
for (auto& g:groupList)
|
||||
{
|
||||
/* sort it into Publish (Own), Subscribed, Popular and Other */
|
||||
uint32_t flags = it->second.mSubscribeFlags;
|
||||
uint32_t flags = g->mMeta.mSubscribeFlags;
|
||||
|
||||
GroupItemInfo groupItemInfo;
|
||||
groupInfoToGroupItemInfo(it->second, groupItemInfo, userdata);
|
||||
groupInfoToGroupItemInfo(g, groupItemInfo);
|
||||
|
||||
if (IS_GROUP_SUBSCRIBED(flags))
|
||||
{
|
||||
if (IS_GROUP_ADMIN(flags))
|
||||
{
|
||||
adminList.push_back(groupItemInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* subscribed group */
|
||||
subList.push_back(groupItemInfo);
|
||||
}
|
||||
subList.push_back(groupItemInfo); /* subscribed group */
|
||||
}
|
||||
else
|
||||
{
|
||||
//popMap.insert(std::make_pair(it->mPop, groupItemInfo)); /* rate the others by popularity */
|
||||
popMap.insert(std::make_pair(it->second.mLastPost, groupItemInfo)); /* rate the others by time of last post */
|
||||
}
|
||||
popMap.insert(std::make_pair(g->mMeta.mLastPost, groupItemInfo)); /* rate the others by time of last post */
|
||||
}
|
||||
|
||||
/* iterate backwards through popMap - take the top 5 or 10% of list */
|
||||
uint32_t popCount = 5;
|
||||
if (popCount < popMap.size() / 10)
|
||||
{
|
||||
popCount = popMap.size() / 10;
|
||||
}
|
||||
|
||||
uint32_t i = 0;
|
||||
std::multimap<uint32_t, GroupItemInfo>::reverse_iterator rit;
|
||||
//uint32_t popLimit = 0;
|
||||
//for(rit = popMap.rbegin(); ((rit != popMap.rend()) && (i < popCount)); ++rit, ++i) ;
|
||||
//if (rit != popMap.rend()) {
|
||||
// popLimit = rit->first;
|
||||
//}
|
||||
|
||||
for (rit = popMap.rbegin(); rit != popMap.rend(); ++rit,++i) {
|
||||
//if (rit->second.popularity > (int) popLimit) {
|
||||
for (rit = popMap.rbegin(); rit != popMap.rend(); ++rit,++i)
|
||||
if(i < popCount)
|
||||
popList.append(rit->second);
|
||||
else
|
||||
otherList.append(rit->second);
|
||||
}
|
||||
|
||||
/* now we can add them in as a tree! */
|
||||
ui->groupTreeWidget->fillGroupItems(mYourGroups, adminList);
|
||||
@ -995,9 +981,8 @@ void GxsGroupFrameDialog::insertGroupsData(const std::map<RsGxsGroupId,RsGroupMe
|
||||
mInFill = false;
|
||||
|
||||
/* Re-fill group */
|
||||
if (!ui->groupTreeWidget->activateId(QString::fromStdString(mGroupId.toStdString()), true)) {
|
||||
if (!ui->groupTreeWidget->activateId(QString::fromStdString(mGroupId.toStdString()), true))
|
||||
mGroupId.clear();
|
||||
}
|
||||
|
||||
updateMessageSummaryList(RsGxsGroupId());
|
||||
}
|
||||
@ -1032,6 +1017,48 @@ void GxsGroupFrameDialog::updateMessageSummaryList(RsGxsGroupId groupId)
|
||||
/** Request / Response of Data ********************************/
|
||||
/*********************** **** **** **** ***********************/
|
||||
|
||||
void GxsGroupFrameDialog::updateGroupSummary()
|
||||
{
|
||||
RsThread::async([this]()
|
||||
{
|
||||
std::list<RsGxsGenericGroupData*> groupInfo;
|
||||
|
||||
if(!getGroupData(groupInfo))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " failed to collect group info " << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
RsQThreadUtils::postToObject( [this,groupInfo]()
|
||||
{
|
||||
/* 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, note that
|
||||
* Qt::QueuedConnection is important!
|
||||
*/
|
||||
|
||||
insertGroupsData(groupInfo);
|
||||
updateSearchResults();
|
||||
|
||||
mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, false);
|
||||
|
||||
if (!mNavigatePendingGroupId.isNull()) {
|
||||
/* Navigate pending */
|
||||
navigate(mNavigatePendingGroupId, mNavigatePendingMsgId);
|
||||
|
||||
mNavigatePendingGroupId.clear();
|
||||
mNavigatePendingMsgId.clear();
|
||||
}
|
||||
// now delete the data that is not used anymore
|
||||
|
||||
for(auto& g:groupInfo)
|
||||
delete g;
|
||||
|
||||
}, this );
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
void GxsGroupFrameDialog::requestGroupSummary()
|
||||
{
|
||||
mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, true);
|
||||
@ -1056,37 +1083,14 @@ void GxsGroupFrameDialog::loadGroupSummaryToken(const uint32_t &token, std::list
|
||||
mInterface->getGroupSummary(token, groupInfo);
|
||||
}
|
||||
|
||||
void GxsGroupFrameDialog::loadGroupSummary(const uint32_t &token)
|
||||
void GxsGroupFrameDialog::loadGroupSummary(const std::list<RsGxsGenericGroupData*>& groupInfo)
|
||||
{
|
||||
#ifdef DEBUG_GROUPFRAMEDIALOG
|
||||
std::cerr << "GxsGroupFrameDialog::loadGroupSummary()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::list<RsGroupMetaData> groupInfo;
|
||||
RsUserdata *userdata = NULL;
|
||||
loadGroupSummaryToken(token, groupInfo, userdata);
|
||||
|
||||
mCachedGroupMetas.clear();
|
||||
for(auto it(groupInfo.begin());it!=groupInfo.end();++it)
|
||||
mCachedGroupMetas[(*it).mGroupId] = *it;
|
||||
|
||||
insertGroupsData(mCachedGroupMetas, userdata);
|
||||
updateSearchResults();
|
||||
|
||||
mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, false);
|
||||
|
||||
if (userdata) {
|
||||
delete(userdata);
|
||||
}
|
||||
|
||||
if (!mNavigatePendingGroupId.isNull()) {
|
||||
/* Navigate pending */
|
||||
navigate(mNavigatePendingGroupId, mNavigatePendingMsgId);
|
||||
|
||||
mNavigatePendingGroupId.clear();
|
||||
mNavigatePendingMsgId.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*********************** **** **** **** ***********************/
|
||||
@ -1145,6 +1149,7 @@ void GxsGroupFrameDialog::loadGroupSummary(const uint32_t &token)
|
||||
|
||||
// setValid(true);
|
||||
//}
|
||||
#endif
|
||||
|
||||
/*********************** **** **** **** ***********************/
|
||||
/*********************** **** **** **** ***********************/
|
||||
@ -1186,9 +1191,9 @@ void GxsGroupFrameDialog::loadRequest(const TokenQueue *queue, const TokenReques
|
||||
/* now switch on req */
|
||||
switch(req.mUserType)
|
||||
{
|
||||
case TOKEN_TYPE_GROUP_SUMMARY:
|
||||
loadGroupSummary(req.mToken);
|
||||
break;
|
||||
// case TOKEN_TYPE_GROUP_SUMMARY:
|
||||
// loadGroupSummary(req.mToken);
|
||||
// break;
|
||||
|
||||
// case TOKEN_TYPE_SUBSCRIBE_CHANGE:
|
||||
// acknowledgeSubscribeChange(req.mToken);
|
||||
|
@ -93,12 +93,14 @@ protected:
|
||||
bool getCurrentGroupName(QString& name);
|
||||
virtual RetroShareLink::enumType getLinkType() = 0;
|
||||
virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Nothing; }
|
||||
virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata);
|
||||
virtual void groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupInfo, GroupItemInfo &groupItemInfo);
|
||||
virtual void checkRequestGroup(const RsGxsGroupId& /* grpId */) {} // overload this one in order to retrieve full group data when the group is browsed
|
||||
|
||||
void updateMessageSummaryList(RsGxsGroupId groupId);
|
||||
|
||||
virtual const std::set<TurtleRequestId> getSearchRequests() const { return std::set<TurtleRequestId>(); } // overload this for subclasses that provide distant search
|
||||
|
||||
virtual bool getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo) =0;
|
||||
private slots:
|
||||
void todo();
|
||||
|
||||
@ -162,12 +164,13 @@ private:
|
||||
void processSettings(bool load);
|
||||
|
||||
// New Request/Response Loading Functions.
|
||||
void insertGroupsData(const std::map<RsGxsGroupId, RsGroupMetaData> &groupList, const RsUserdata *userdata);
|
||||
void insertGroupsData(const std::list<RsGxsGenericGroupData *> &groupList);
|
||||
|
||||
//void requestGroupSummary();
|
||||
void updateGroupSummary();
|
||||
void loadGroupSummary(const std::list<RsGxsGenericGroupData *> &groupInfo);
|
||||
|
||||
void requestGroupSummary();
|
||||
void loadGroupSummary(const uint32_t &token);
|
||||
virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_META; } // request only meta data
|
||||
virtual void loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata* &userdata); // use with requestGroupSummaryType
|
||||
|
||||
void requestGroupStatistics(const RsGxsGroupId &groupId);
|
||||
void loadGroupStatistics(const uint32_t &token);
|
||||
|
@ -36,15 +36,15 @@
|
||||
#include "gui/common/GroupTreeWidget.h"
|
||||
#include "util/qtthreadsutils.h"
|
||||
|
||||
class GxsChannelGroupInfoData : public RsUserdata
|
||||
{
|
||||
public:
|
||||
GxsChannelGroupInfoData() : RsUserdata() {}
|
||||
|
||||
public:
|
||||
QMap<RsGxsGroupId, QIcon> mIcon;
|
||||
QMap<RsGxsGroupId, QString> mDescription;
|
||||
};
|
||||
// class GxsChannelGroupInfoData : public RsUserdata
|
||||
// {
|
||||
// public:
|
||||
// GxsChannelGroupInfoData() : RsUserdata() {}
|
||||
//
|
||||
// public:
|
||||
// QMap<RsGxsGroupId, QIcon> mIcon;
|
||||
// QMap<RsGxsGroupId, QString> mDescription;
|
||||
// };
|
||||
|
||||
/** Constructor */
|
||||
GxsChannelDialog::GxsChannelDialog(QWidget *parent)
|
||||
@ -344,6 +344,34 @@ void GxsChannelDialog::toggleAutoDownload()
|
||||
});
|
||||
}
|
||||
|
||||
bool GxsChannelDialog::getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo)
|
||||
{
|
||||
std::vector<RsGxsChannelGroup> groups;
|
||||
|
||||
// request all group infos at once
|
||||
|
||||
if(! rsGxsChannels->getChannelsInfo(std::list<RsGxsGroupId>(),groups))
|
||||
return false;
|
||||
|
||||
/* Save groups to fill icons and description */
|
||||
|
||||
for (auto& group: groups)
|
||||
groupInfo.push_back(new RsGxsChannelGroup(group));
|
||||
|
||||
// if (group.mImage.mData != NULL) {
|
||||
// QPixmap image;
|
||||
// GxsIdDetails::loadPixmapFromData(group.mImage.mData, group.mImage.mSize, image,GxsIdDetails::ORIGINAL);
|
||||
// channelData->mIcon[group.mMeta.mGroupId] = image;
|
||||
// }
|
||||
//
|
||||
// if (!group.mDescription.empty()) {
|
||||
// channelData->mDescription[group.mMeta.mGroupId] = QString::fromUtf8(group.mDescription.c_str());
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
void GxsChannelDialog::loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata *&userdata)
|
||||
{
|
||||
std::vector<RsGxsChannelGroup> groups;
|
||||
@ -369,27 +397,25 @@ void GxsChannelDialog::loadGroupSummaryToken(const uint32_t &token, std::list<Rs
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void GxsChannelDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata)
|
||||
void GxsChannelDialog::groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupData, GroupItemInfo &groupItemInfo)
|
||||
{
|
||||
GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupInfo, groupItemInfo, userdata);
|
||||
GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupData, groupItemInfo);
|
||||
|
||||
const GxsChannelGroupInfoData *channelData = dynamic_cast<const GxsChannelGroupInfoData*>(userdata);
|
||||
if (!channelData) {
|
||||
std::cerr << "GxsChannelDialog::groupInfoToGroupItemInfo() Failed to cast data to GxsChannelGroupInfoData";
|
||||
std::cerr << std::endl;
|
||||
const RsGxsChannelGroup *channelGroupData = dynamic_cast<const RsGxsChannelGroup*>(groupData);
|
||||
|
||||
if (!channelGroupData)
|
||||
{
|
||||
std::cerr << "GxsChannelDialog::groupInfoToGroupItemInfo() Failed to cast data to GxsChannelGroupInfoData"<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QMap<RsGxsGroupId, QString>::const_iterator descriptionIt = channelData->mDescription.find(groupInfo.mGroupId);
|
||||
if (descriptionIt != channelData->mDescription.end()) {
|
||||
groupItemInfo.description = descriptionIt.value();
|
||||
}
|
||||
QPixmap image;
|
||||
GxsIdDetails::loadPixmapFromData(channelGroupData->mImage.mData, channelGroupData->mImage.mSize, image,GxsIdDetails::ORIGINAL);
|
||||
|
||||
QMap<RsGxsGroupId, QIcon>::const_iterator iconIt = channelData->mIcon.find(groupInfo.mGroupId);
|
||||
if (iconIt != channelData->mIcon.end()) {
|
||||
groupItemInfo.icon = iconIt.value();
|
||||
}
|
||||
groupItemInfo.description = QString::fromUtf8(channelGroupData->mDescription.c_str());
|
||||
groupItemInfo.icon = image;
|
||||
}
|
||||
|
||||
TurtleRequestId GxsChannelDialog::distantSearch(const QString& search_string)
|
||||
|
@ -46,7 +46,7 @@ protected:
|
||||
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; }
|
||||
virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Channel; }
|
||||
virtual QString getHelpString() const ;
|
||||
virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata);
|
||||
virtual void groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupData, GroupItemInfo &groupItemInfo);
|
||||
virtual bool getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSummary>& group_infos);
|
||||
virtual const std::set<TurtleRequestId> getSearchRequests() const override { return mSearchResults ; }
|
||||
|
||||
@ -73,7 +73,8 @@ private:
|
||||
virtual RsGxsCommentService *getCommentService();
|
||||
virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId);
|
||||
virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_DATA; } // request complete group data
|
||||
virtual void loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata* &userdata);
|
||||
|
||||
bool getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo) override;
|
||||
|
||||
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
|
||||
|
||||
|
@ -80,6 +80,18 @@ GxsForumsDialog::~GxsForumsDialog()
|
||||
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
||||
}
|
||||
|
||||
bool GxsForumsDialog::getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo)
|
||||
{
|
||||
std::vector<RsGxsForumGroup> groups;
|
||||
|
||||
if(! rsGxsForums->getForumsInfo(std::list<RsGxsGroupId>(),groups))
|
||||
return false;
|
||||
|
||||
for (auto& group: groups)
|
||||
groupInfo.push_back(new RsGxsForumGroup(group));
|
||||
}
|
||||
|
||||
|
||||
QString GxsForumsDialog::getHelpString() const
|
||||
{
|
||||
QString hlp_str = tr(
|
||||
@ -207,7 +219,26 @@ void GxsForumsDialog::loadGroupSummaryToken(const uint32_t &token, std::list<RsG
|
||||
}
|
||||
}
|
||||
|
||||
void GxsForumsDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata)
|
||||
void GxsForumsDialog::groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupData, GroupItemInfo &groupItemInfo)
|
||||
{
|
||||
GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupData, groupItemInfo);
|
||||
|
||||
const RsGxsForumGroup *forumGroupData = dynamic_cast<const RsGxsForumGroup*>(groupData);
|
||||
|
||||
if (!forumGroupData)
|
||||
{
|
||||
std::cerr << "GxsChannelDialog::groupInfoToGroupItemInfo() Failed to cast data to GxsChannelGroupInfoData"<< std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
groupItemInfo.description = QString::fromUtf8(forumGroupData->mDescription.c_str());
|
||||
|
||||
if ((IS_GROUP_PGP_AUTHED(groupData->mMeta.mSignFlags)) || (IS_GROUP_MESSAGE_TRACKING(groupData->mMeta.mSignFlags)) )
|
||||
groupItemInfo.icon = QIcon(":icons/png/forums-signed.png");
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
void ::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata)
|
||||
{
|
||||
GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupInfo, groupItemInfo, userdata);
|
||||
|
||||
@ -229,3 +260,4 @@ void GxsForumsDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo,
|
||||
groupItemInfo.icon = QIcon(":icons/png/forums-signed.png");
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -45,7 +45,9 @@ protected:
|
||||
virtual QString getHelpString() const ;
|
||||
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_FORUM; }
|
||||
virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Forum; }
|
||||
virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata);
|
||||
|
||||
void groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupData, GroupItemInfo &groupItemInfo) override;
|
||||
bool getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo) override;
|
||||
|
||||
private:
|
||||
/* GxsGroupFrameDialog */
|
||||
|
Loading…
Reference in New Issue
Block a user