mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-04 17:15:31 -05:00
Implement GXS Circle link based on GXS group base64
This commit is contained in:
parent
6f3d842d30
commit
6a797cd073
@ -274,6 +274,54 @@ public:
|
|||||||
virtual bool cancelCircleMembership(
|
virtual bool cancelCircleMembership(
|
||||||
const RsGxsId& ownGxsId, const RsGxsCircleId& circleId ) = 0;
|
const RsGxsId& ownGxsId, const RsGxsCircleId& circleId ) = 0;
|
||||||
|
|
||||||
|
/// default base URL used for circle links @see exportCircleLink
|
||||||
|
static const std::string DEFAULT_CIRCLE_BASE_URL;
|
||||||
|
|
||||||
|
/// Circle link query field used to store circle name @see exportCircleLink
|
||||||
|
static const std::string CIRCLE_URL_NAME_FIELD;
|
||||||
|
|
||||||
|
/// Circle link query field used to store circle id @see exportCircleLink
|
||||||
|
static const std::string CIRCLE_URL_ID_FIELD;
|
||||||
|
|
||||||
|
/// Circle link query field used to store circle data @see exportCircleLink
|
||||||
|
static const std::string CIRCLE_URL_DATA_FIELD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get link to a circle
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[out] link storage for the generated link
|
||||||
|
* @param[in] circleId Id of the circle of which we want to generate a link
|
||||||
|
* @param[in] includeGxsData if true include the circle GXS group data so
|
||||||
|
* the receiver can request circle membership even if the circle hasn't
|
||||||
|
* propagated through GXS to her yet
|
||||||
|
* @param[in] baseUrl URL into which to sneak in the RetroShare circle link
|
||||||
|
* radix, this is primarly useful to induce applications into making the
|
||||||
|
* link clickable, or to disguise the RetroShare circle link into a
|
||||||
|
* "normal" looking web link. If empty the circle data link will be
|
||||||
|
* outputted in plain base64 format.
|
||||||
|
* @param[out] errMsg optional storage for error message, meaningful only in
|
||||||
|
* case of failure
|
||||||
|
* @return false if something failed, true otherwhise
|
||||||
|
*/
|
||||||
|
virtual bool exportCircleLink(
|
||||||
|
std::string& link, const RsGxsCircleId& circleId,
|
||||||
|
bool includeGxsData = true,
|
||||||
|
const std::string& baseUrl = RsGxsCircles::DEFAULT_CIRCLE_BASE_URL,
|
||||||
|
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Import circle from full link
|
||||||
|
* @param[in] link circle link either in radix or link format
|
||||||
|
* @param[out] circleId optional storage for parsed circle id
|
||||||
|
* @param[out] errMsg optional storage for error message, meaningful only in
|
||||||
|
* case of failure
|
||||||
|
* @return false if some error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool importCircleLink(
|
||||||
|
const std::string& link,
|
||||||
|
RsGxsCircleId& circleId = RS_DEFAULT_STORAGE_PARAM(RsGxsCircleId),
|
||||||
|
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0;
|
||||||
|
|
||||||
RS_DEPRECATED_FOR("getCirclesSummaries getCirclesInfo")
|
RS_DEPRECATED_FOR("getCirclesSummaries getCirclesInfo")
|
||||||
virtual bool getGroupData(
|
virtual bool getGroupData(
|
||||||
const uint32_t& token, std::vector<RsGxsCircleGroup>& groups ) = 0;
|
const uint32_t& token, std::vector<RsGxsCircleGroup>& groups ) = 0;
|
||||||
|
@ -339,6 +339,76 @@ bool p3GxsCircles::inviteIdsToCircle( const std::set<RsGxsId>& identities,
|
|||||||
return editCircle(circleGrp);
|
return editCircle(circleGrp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool p3GxsCircles::exportCircleLink(
|
||||||
|
std::string& link, const RsGxsCircleId& circleId,
|
||||||
|
bool includeGxsData, const std::string& baseUrl, std::string& errMsg )
|
||||||
|
{
|
||||||
|
constexpr auto fname = __PRETTY_FUNCTION__;
|
||||||
|
const auto failure = [&](const std::string& err)
|
||||||
|
{
|
||||||
|
errMsg = err;
|
||||||
|
RsErr() << fname << " " << err << std::endl;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if(circleId.isNull()) return failure("circleId cannot be null");
|
||||||
|
|
||||||
|
const bool outputRadix = baseUrl.empty();
|
||||||
|
if(outputRadix && !includeGxsData) return
|
||||||
|
failure("includeGxsData must be true if format requested is base64");
|
||||||
|
|
||||||
|
RsGxsGroupId&& groupId = static_cast<RsGxsGroupId>(circleId);
|
||||||
|
if( includeGxsData &&
|
||||||
|
!RsGenExchange::exportGroupBase64(link, groupId, errMsg) )
|
||||||
|
return failure(errMsg);
|
||||||
|
|
||||||
|
if(outputRadix) return true;
|
||||||
|
|
||||||
|
std::vector<RsGxsCircleGroup> circlesInfo;
|
||||||
|
if( !getCirclesInfo(
|
||||||
|
std::list<RsGxsGroupId>({groupId}), circlesInfo )
|
||||||
|
|| circlesInfo.empty() )
|
||||||
|
return failure("failure retrieving circle information");
|
||||||
|
|
||||||
|
RsUrl inviteUrl(baseUrl);
|
||||||
|
inviteUrl.setQueryKV(CIRCLE_URL_ID_FIELD, circleId.toStdString());
|
||||||
|
inviteUrl.setQueryKV(CIRCLE_URL_NAME_FIELD, circlesInfo[0].mMeta.mGroupName);
|
||||||
|
if(includeGxsData) inviteUrl.setQueryKV(CIRCLE_URL_DATA_FIELD, link);
|
||||||
|
|
||||||
|
link = inviteUrl.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool p3GxsCircles::importCircleLink(
|
||||||
|
const std::string& link, RsGxsCircleId& circleId,
|
||||||
|
std::string& errMsg )
|
||||||
|
{
|
||||||
|
constexpr auto fname = __PRETTY_FUNCTION__;
|
||||||
|
const auto failure = [&](const std::string& err)
|
||||||
|
{
|
||||||
|
errMsg = err;
|
||||||
|
RsErr() << fname << " " << err << std::endl;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if(link.empty()) return failure("link is empty");
|
||||||
|
|
||||||
|
const std::string* radixPtr(&link);
|
||||||
|
|
||||||
|
RsUrl url(link);
|
||||||
|
const auto& query = url.query();
|
||||||
|
const auto qIt = query.find(CIRCLE_URL_DATA_FIELD);
|
||||||
|
if(qIt != query.end()) radixPtr = &qIt->second;
|
||||||
|
|
||||||
|
if(radixPtr->empty()) return failure(CIRCLE_URL_DATA_FIELD + " is empty");
|
||||||
|
|
||||||
|
if(!RsGenExchange::importGroupBase64(
|
||||||
|
*radixPtr, reinterpret_cast<RsGxsGroupId&>(circleId), errMsg) )
|
||||||
|
return failure(errMsg);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t p3GxsCircles::circleAuthenPolicy()
|
uint32_t p3GxsCircles::circleAuthenPolicy()
|
||||||
{
|
{
|
||||||
uint32_t policy = 0;
|
uint32_t policy = 0;
|
||||||
@ -454,7 +524,8 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||||||
/******************* RsCircles Interface ***************************************/
|
/******************* RsCircles Interface ***************************************/
|
||||||
/********************************************************************************/
|
/********************************************************************************/
|
||||||
|
|
||||||
bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details)
|
bool p3GxsCircles::getCircleDetails(
|
||||||
|
const RsGxsCircleId& id, RsGxsCircleDetails& details)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef DEBUG_CIRCLES
|
#ifdef DEBUG_CIRCLES
|
||||||
@ -2243,6 +2314,12 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static*/ const std::string RsGxsCircles::DEFAULT_CIRCLE_BASE_URL =
|
||||||
|
"retroshare:///circles";
|
||||||
|
/*static*/ const std::string RsGxsCircles::CIRCLE_URL_NAME_FIELD = "circleName";
|
||||||
|
/*static*/ const std::string RsGxsCircles::CIRCLE_URL_ID_FIELD = "circleId";
|
||||||
|
/*static*/ const std::string RsGxsCircles::CIRCLE_URL_DATA_FIELD = "circleData";
|
||||||
|
|
||||||
RsGxsCircles::~RsGxsCircles() = default;
|
RsGxsCircles::~RsGxsCircles() = default;
|
||||||
RsGxsCircleMsg::~RsGxsCircleMsg() = default;
|
RsGxsCircleMsg::~RsGxsCircleMsg() = default;
|
||||||
RsGxsCircleDetails::~RsGxsCircleDetails() = default;
|
RsGxsCircleDetails::~RsGxsCircleDetails() = default;
|
||||||
|
@ -169,14 +169,15 @@ class RsGxsCircleCache
|
|||||||
|
|
||||||
class PgpAuxUtils;
|
class PgpAuxUtils;
|
||||||
|
|
||||||
class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles, public GxsTokenQueue, public RsTickEvent
|
class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
|
||||||
|
public GxsTokenQueue, public RsTickEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
p3GxsCircles(RsGeneralDataService* gds, RsNetworkExchangeService* nes, p3IdService *identities, PgpAuxUtils *pgpUtils);
|
p3GxsCircles(
|
||||||
|
RsGeneralDataService* gds, RsNetworkExchangeService* nes,
|
||||||
|
p3IdService* identities, PgpAuxUtils* pgpUtils );
|
||||||
|
|
||||||
virtual RsServiceInfo getServiceInfo();
|
RsServiceInfo getServiceInfo() override;
|
||||||
|
|
||||||
/*********** External Interface ***************/
|
|
||||||
|
|
||||||
/// @see RsGxsCircles
|
/// @see RsGxsCircles
|
||||||
bool createCircle(
|
bool createCircle(
|
||||||
@ -207,6 +208,21 @@ virtual RsServiceInfo getServiceInfo();
|
|||||||
bool inviteIdsToCircle( const std::set<RsGxsId>& identities,
|
bool inviteIdsToCircle( const std::set<RsGxsId>& identities,
|
||||||
const RsGxsCircleId& circleId ) override;
|
const RsGxsCircleId& circleId ) override;
|
||||||
|
|
||||||
|
/// @see RsGxsCircles
|
||||||
|
bool exportCircleLink(
|
||||||
|
std::string& link, const RsGxsCircleId& circleId,
|
||||||
|
bool includeGxsData = true,
|
||||||
|
const std::string& baseUrl = DEFAULT_CIRCLE_BASE_URL,
|
||||||
|
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||||
|
) override;
|
||||||
|
|
||||||
|
/// @see RsGxsCircles
|
||||||
|
bool importCircleLink(
|
||||||
|
const std::string& link,
|
||||||
|
RsGxsCircleId& circleId = RS_DEFAULT_STORAGE_PARAM(RsGxsCircleId),
|
||||||
|
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||||
|
) override;
|
||||||
|
|
||||||
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details);
|
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details);
|
||||||
virtual bool getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds);
|
virtual bool getCircleExternalIdList(std::list<RsGxsCircleId> &circleIds);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user