Implement links for RsGxsChannels

This commit is contained in:
Gioacchino Mazzurco 2019-10-28 18:45:50 +01:00
parent 6a797cd073
commit d9a8c5c09f
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
3 changed files with 150 additions and 1 deletions

View file

@ -2466,6 +2466,85 @@ void p3GxsChannels::cleanTimedOutCallbacks()
} // RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex)
}
bool p3GxsChannels::exportChannelLink(
std::string& link, const RsGxsGroupId& chanId, 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(chanId.isNull()) return failure("chanId cannot be null");
const bool outputRadix = baseUrl.empty();
if(outputRadix && !includeGxsData) return
failure("includeGxsData must be true if format requested is base64");
if( includeGxsData &&
!RsGenExchange::exportGroupBase64(link, chanId, errMsg) )
return failure(errMsg);
if(outputRadix) return true;
std::vector<RsGxsChannelGroup> chansInfo;
if( !getChannelsInfo(std::list<RsGxsGroupId>({chanId}), chansInfo)
|| chansInfo.empty() )
return failure("failure retrieving channel information");
RsUrl inviteUrl(baseUrl);
inviteUrl.setQueryKV(CHANNEL_URL_ID_FIELD, chanId.toStdString());
inviteUrl.setQueryKV(CHANNEL_URL_NAME_FIELD, chansInfo[0].mMeta.mGroupName);
if(includeGxsData) inviteUrl.setQueryKV(CHANNEL_URL_DATA_FIELD, link);
link = inviteUrl.toString();
return true;
}
bool p3GxsChannels::importChannelLink(
const std::string& link, RsGxsGroupId& chanId, 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(CHANNEL_URL_DATA_FIELD);
if(qIt != query.end()) radixPtr = &qIt->second;
if(radixPtr->empty()) return failure(CHANNEL_URL_DATA_FIELD + " is empty");
if(!RsGenExchange::importGroupBase64(*radixPtr, chanId, errMsg))
return failure(errMsg);
return true;
}
/*static*/ const std::string RsGxsChannels::DEFAULT_CHANNEL_BASE_URL =
"retroshare:///channels";
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_NAME_FIELD =
"chanName";
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_ID_FIELD =
"chanId";
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_DATA_FIELD =
"chanData";
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_MSG_TITLE_FIELD =
"chanMsgTitle";
/*static*/ const std::string RsGxsChannels::CHANNEL_URL_MSG_ID_FIELD =
"chanMsgId";
RsGxsChannelGroup::~RsGxsChannelGroup() = default;
RsGxsChannelPost::~RsGxsChannelPost() = default;
RsGxsChannels::~RsGxsChannels() = default;

View file

@ -246,9 +246,24 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
bool subscribeToChannel( const RsGxsGroupId &groupId,
bool subscribe ) override;
/// Implementation of @see RsGxsChannels::setPostRead
/// @see RsGxsChannels
virtual bool markRead(const RsGxsGrpMsgIdPair& msgId, bool read);
/// @see RsGxsChannels
bool exportChannelLink(
std::string& link, const RsGxsGroupId& chanId,
bool includeGxsData = true,
const std::string& baseUrl = DEFAULT_CHANNEL_BASE_URL,
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
) override;
/// @see RsGxsChannels
bool importChannelLink(
const std::string& link,
RsGxsGroupId& chanId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string)
) override;
virtual bool shareChannelKeys(
const RsGxsGroupId& channelId, const std::set<RsPeerId>& peers );