fixed bug in circle chooser that showed duplicates. Removed mCircleExternalIdList (not really useful now that circles are cached) and used a std::set to ensure uniqueness

This commit is contained in:
csoler 2020-12-05 20:12:03 +01:00
parent af76cf028c
commit dbd6477acd
4 changed files with 12 additions and 140 deletions

View File

@ -312,8 +312,7 @@ public:
* @param[out] details Storage for the circle details
* @return false if something failed, true otherwhise
*/
virtual bool getCircleDetails(
const RsGxsCircleId& id, RsGxsCircleDetails& details ) = 0;
virtual bool getCircleDetails(const RsGxsCircleId& id, RsGxsCircleDetails& details ) = 0;
/**
* @brief Get list of known external circles ids. Memory cached
@ -321,8 +320,7 @@ public:
* @param[in] circleIds Storage for circles id list
* @return false if something failed, true otherwhise
*/
virtual bool getCircleExternalIdList(
std::list<RsGxsCircleId>& circleIds ) = 0;
virtual bool getCircleExternalIdList(std::set<RsGxsCircleId>& circleIds ) = 0;
/**
* @brief Get circles summaries list.

View File

@ -153,7 +153,7 @@ p3GxsCircles::p3GxsCircles( RsGeneralDataService *gds, RsNetworkExchangeService
mLastCacheUpdateEvent = 0;
mLastDebugPrintTS = 0;
RsTickEvent::schedule_now(CIRCLE_EVENT_LOADIDS);
RsTickEvent::schedule_now(CIRCLE_EVENT_CACHELOAD);
mDummyIdToken = 0;
}
@ -654,10 +654,8 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
// for new circles we need to add them to the list.
// we don't know the type of this circle here
// original behavior was to add all ids to the external ids list
addCircleIdToList(RsGxsCircleId(*git), 0);
circles_to_reload.insert(RsGxsCircleId(*git));
} // fallthrough
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
{
@ -824,7 +822,7 @@ bool p3GxsCircles::getCircleDetails(const RsGxsCircleId& id, RsGxsCircleDetails&
return false;
}
bool p3GxsCircles::getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds)
bool p3GxsCircles::getCircleExternalIdList(std::set<RsGxsCircleId> &circleIds)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::getCircleIdList()";
@ -832,14 +830,10 @@ bool p3GxsCircles::getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds)
#endif // DEBUG_CIRCLES
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
if (circleIds.empty())
circleIds = mCircleExternalIdList;
else
{
std::list<RsGxsCircleId>::const_iterator it;
for(it = mCircleExternalIdList.begin(); it != mCircleExternalIdList.begin(); ++it)
circleIds.push_back(*it);
}
for(auto& cache: mCircleCache)
if(cache.second.mIsExternal)
circleIds.insert(cache.first);
return true;
}
@ -1006,18 +1000,6 @@ bool p3GxsCircles::getMsgData(const uint32_t &token, std::vector<RsGxsCircleMsg>
for(; vit != msgItems.end(); ++vit)
{
#ifdef TO_REMOVE
RsGxsCircleMsgItem* item = dynamic_cast<RsGxsCircleMsgItem*>(*vit);
if(item)
{
RsGxsCircleMsg msg = item->mMsg;
msg.mMeta = item->meta;
msgs.push_back(msg);
delete item;
}
#endif
RsGxsCircleSubscriptionRequestItem* rsItem = dynamic_cast<RsGxsCircleSubscriptionRequestItem*>(*vit);
if (rsItem)
@ -1087,10 +1069,6 @@ RsGenExchange::ServiceCreate_Return p3GxsCircles::service_CreateGroup(RsGxsGrpIt
item->meta.mCircleId = RsGxsCircleId(item->meta.mGroupId);
}
// the advantage of adding the id to the list now is, that we know the cirlce type at this point
// this is not the case in NotifyChanges()
addCircleIdToList(RsGxsCircleId(item->meta.mGroupId), item->meta.mCircleType);
return SERVICE_CREATE_SUCCESS;
}
@ -1210,67 +1188,6 @@ bool RsGxsCircleCache::addLocalFriend(const RsPgpId &pgpId)
return true;
}
/************************************************************************************/
/************************************************************************************/
bool p3GxsCircles::request_CircleIdList()
{
/* trigger request to load missing ids into cache */
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::request_CircleIdList()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
uint32_t token = 0;
RsGenExchange::getTokenService()->requestGroupInfo(token, ansType, opts);
GxsTokenQueue::queueRequest(token, CIRCLEREQ_CIRCLE_LIST);
return true;
}
bool p3GxsCircles::load_CircleIdList(uint32_t token)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::load_CircleIdList() : " << token;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
std::list<RsGroupMetaData> groups;
bool ok = RsGenExchange::getGroupMeta(token, groups);
if(ok)
{
// Save List
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCirclePersonalIdList.clear();
mCircleExternalIdList.clear();
}
for(std::list<RsGroupMetaData>::iterator it = groups.begin(); it != groups.end(); ++it)
{
addCircleIdToList(RsGxsCircleId(it->mGroupId), it->mCircleType);
}
}
else
{
std::cerr << "p3GxsCircles::load_CircleIdList() ERROR no data";
std::cerr << std::endl;
return false;
}
return true;
}
/************************************************************************************/
/************************************************************************************/
/************************************************************************************/
@ -1713,24 +1630,6 @@ bool p3GxsCircles::locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache& cac
return true;
}
void p3GxsCircles::addCircleIdToList(const RsGxsCircleId &circleId, uint32_t circleType)
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
if (circleType == GXS_CIRCLE_TYPE_LOCAL)
{
if(mCirclePersonalIdList.end() == std::find(mCirclePersonalIdList.begin(), mCirclePersonalIdList.end(), circleId)){
mCirclePersonalIdList.push_back(circleId);
}
}
else
{
if(mCircleExternalIdList.end() == std::find(mCircleExternalIdList.begin(), mCircleExternalIdList.end(), circleId)){
mCircleExternalIdList.push_back(circleId);
}
}
}
bool p3GxsCircles::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
{
#ifdef GXSFORUMS_CHANNELS
@ -1802,10 +1701,6 @@ void p3GxsCircles::handleResponse(uint32_t token, uint32_t req_type)
// stuff.
switch(req_type)
{
case CIRCLEREQ_CIRCLE_LIST:
load_CircleIdList(token);
break;
case CIRCLEREQ_MESSAGE_DATA:
processMembershipRequests(token);
break;
@ -1831,10 +1726,6 @@ void p3GxsCircles::handle_event(uint32_t event_type, const std::string &elabel)
// stuff.
switch(event_type)
{
case CIRCLE_EVENT_LOADIDS:
request_CircleIdList();
break;
case CIRCLE_EVENT_CACHELOAD:
cache_start_load();
break;

View File

@ -271,7 +271,7 @@ public:
) override;
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details) override;
virtual bool getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds) override;
virtual bool getCircleExternalIdList(std::set<RsGxsCircleId> &circleIds) override;
virtual bool isLoaded(const RsGxsCircleId &circleId) override;
virtual bool loadCircle(const RsGxsCircleId &circleId) override;
@ -326,8 +326,6 @@ protected:
private:
// Load data.
bool request_CircleIdList();
bool load_CircleIdList(uint32_t token);
bool processMembershipRequests(uint32_t token);
// Need some crazy arsed cache to store the circle info.
@ -351,21 +349,11 @@ protected:
p3IdService *mIdentities; // Needed for constructing Circle Info,
PgpAuxUtils *mPgpUtils;
// put a circle id into the external or personal circle id list
// this function locks the mutex
// if the id is already in the list, it will not be added again
// G10h4ck: this is terrible, an std::set instead of a list should be used
// to guarantee uniqueness
void addCircleIdToList(const RsGxsCircleId& circleId, uint32_t circleType);
RsMutex mCircleMtx; /* Locked Below Here */
RsMutex mKnownCirclesMtx; /* Locked Below Here */
std::map<RsGxsGroupId,rstime_t> mKnownCircles;
std::list<RsGxsCircleId> mCircleExternalIdList;
std::list<RsGxsCircleId> mCirclePersonalIdList;
/***** Caching Circle Info, *****/
// waiting for subcircle to load. (first is part of each of the second list)

View File

@ -63,7 +63,7 @@ bool MakeGxsCircleDesc(const RsGxsCircleId &id, QString &desc)
void GxsCircleChooser::loadGxsCircles()
{
std::list<RsGxsCircleId> ids;
std::set<RsGxsCircleId> ids;
rsGxsCircles->getCircleExternalIdList(ids);
if (ids.empty())
@ -73,10 +73,9 @@ void GxsCircleChooser::loadGxsCircles()
return;
}
std::list<RsGxsCircleId>::iterator it;
int i = 0;
int def = -1;
for(it = ids.begin(); it != ids.end(); ++it, ++i)
for(auto it(ids.begin()); it != ids.end(); ++it, ++i)
{
/* add to Chooser */
QString str;
@ -91,15 +90,11 @@ void GxsCircleChooser::loadGxsCircles()
addItem(str, id);
if (mDefaultCircleId == *it)
{
def = i;
}
}
if (def >= 0)
{
setCurrentIndex(def);
}
}
bool GxsCircleChooser::getChosenCircle(RsGxsCircleId &id)