Merge branch 'v0.6-ImprovedGUI' of https://github.com/csoler/RetroShare into json_api

This commit is contained in:
Gioacchino Mazzurco 2019-04-12 21:39:05 +02:00
commit 81f73aaf44
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
4 changed files with 95 additions and 84 deletions

View File

@ -186,7 +186,7 @@ class NetInterface;
class PQInterface: public RateInterface class PQInterface: public RateInterface
{ {
public: public:
explicit PQInterface(const RsPeerId &id) :peerId(id), traf_in(0), traf_out(0) { return; } explicit PQInterface(const RsPeerId &id) :traf_in(0), traf_out(0),peerId(id) { return; }
virtual ~PQInterface() { return; } virtual ~PQInterface() { return; }
/*! /*!

View File

@ -107,43 +107,40 @@ public:
* @param[in] name Name of the channel * @param[in] name Name of the channel
* @param[in] description Description of the channel * @param[in] description Description of the channel
* @param[in] thumbnail Optional image to show as channel thumbnail. * @param[in] thumbnail Optional image to show as channel thumbnail.
* @param[in] authorId Optional id of the author. Leave empty for an * @param[in] authorId Optional id of the author. Leave empty for an anonymous channel.
* anonymous channel.
* @param[in] circleType Optional visibility rule, default public. * @param[in] circleType Optional visibility rule, default public.
* @param[in] circleId If the channel is not public specify the id of the * @param[in] circleId If the channel is not public specify the id of the circle who can see the channel. Depending on the value you pass for
* circle who can see the channel. Depending on the value you pass for
* circleType this should be be an external circle if EXTERNAL is passed, a * circleType this should be be an external circle if EXTERNAL is passed, a
* local friend group id if NODES_GROUP is passed, empty otherwise. * local friend group id if NODES_GROUP is passed, empty otherwise.
* @param[out] channelId Optional storage for the id of the created channel, * @param[out] channelId Optional storage for the id of the created channel, meaningful only if creations succeeds.
* meaningful only if creations succeeds. * @param[out] errorMessage Optional storage for error messsage, meaningful only if creation fail.
* @param[out] errorMessage Optional storage for error messsage, meaningful
* only if creation fail.
* @return False on error, true otherwise. * @return False on error, true otherwise.
*/ */
virtual bool createChannelV2( virtual bool createChannelV2(const std::string& name,
const std::string& name, const std::string& description, const std::string& description,
const RsGxsImage& thumbnail = RsGxsImage(), const RsGxsImage& thumbnail = RsGxsImage(),
const RsGxsId& authorId = RsGxsId(), const RsGxsId& authorId = RsGxsId(),
RsGxsCircleType circleType = RsGxsCircleType::PUBLIC, RsGxsCircleType circleType = RsGxsCircleType::PUBLIC,
const RsGxsCircleId& circleId = RsGxsCircleId(), const RsGxsCircleId& circleId = RsGxsCircleId(),
RsGxsGroupId& channelId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId), RsGxsGroupId& channelGroupId = RS_DEFAULT_STORAGE_PARAM(RsGxsGroupId),
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0; std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0;
/** /**
* @brief Add a comment on a post or on another comment * @brief Add a comment on a post or on another comment. Blocking API.
* @jsonapi{development} * @jsonapi{development}
* @param[in] channelId Id of the channel in which the comment is to be posted * @param[in] channelId Id of the channel in which the comment is to be posted
* @param[in] parentId Id of the parent of the comment that is either a * @param[in] threadId Id of the post (that is a thread) in the channel where the comment is placed
* channel post Id or the Id of another comment. * @param[in] parentId Id of the parent of the comment that is either a channel post Id or the Id of another comment.
* @param[in] comment UTF-8 string containing the comment * @param[in] authorId Id of the author of the comment
* @param[out] commentMessageId Optional storage for the id of the comment * @param[in] comment UTF-8 string containing the comment itself
* that was created, meaningful only on success. * @param[out] commentMessageId Optional storage for the id of the comment that was created, meaningful only on success.
* @param[out] errorMessage Optional storage for error message, meaningful * @param[out] errorMessage Optional storage for error message, meaningful only on failure.
* only on failure.
* @return false on error, true otherwise * @return false on error, true otherwise
*/ */
virtual bool createCommentV2( virtual bool createCommentV2(const RsGxsGroupId& channelId,
const RsGxsGroupId& channelId, const RsGxsMessageId& parentId, const RsGxsMessageId& threadId,
const RsGxsMessageId& parentId,
const RsGxsId& authorId,
const std::string& comment, const std::string& comment,
RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId), RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) )=0; std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) )=0;
@ -151,19 +148,14 @@ public:
/** /**
* @brief Create channel post. Blocking API. * @brief Create channel post. Blocking API.
* @jsonapi{development} * @jsonapi{development}
* @param[in] channelId Id of the channel where to put the post. Beware you * @param[in] channelId Id of the channel where to put the post. Beware you need publish rights on that channel to post.
* need publish rights on that channel to post.
* @param[in] title Title of the post * @param[in] title Title of the post
* @param[in] mBody Text content of the post * @param[in] mBody Text content of the post
* @param[in] files Optional list of attached files. These are supposed to * @param[in] files Optional list of attached files. These are supposed to be already shared, @see ExtraFileHash() below otherwise.
* be already shared, @see ExtraFileHash() below otherwise.
* @param[in] thumbnail Optional thumbnail image for the post. * @param[in] thumbnail Optional thumbnail image for the post.
* @param[in] origPostId If this is supposed to replace an already existent * @param[in] origPostId If this is supposed to replace an already existent post, the id of the old post. If left blank a new post will be created.
* post, the id of the old post. If left blank a new post will be created. * @param[out] postId Optional storage for the id of the created post, meaningful only on success.
* @param[out] postId Optional storage for the id of the created post, * @param[out] errorMessage Optional storage for the error message, meaningful only on failure.
* meaningful only on success.
* @param[out] errorMessage Optional storage for the error message,
* meaningful only on failure.
* @return false on error, true otherwise * @return false on error, true otherwise
*/ */
virtual bool createPostV2( virtual bool createPostV2(
@ -182,10 +174,8 @@ public:
* @param[in] postId Id of the channel post of which a comment is voted * @param[in] postId Id of the channel post of which a comment is voted
* @param[in] commentId Id of the comment that is voted * @param[in] commentId Id of the comment that is voted
* @param[in] authorId Id of the author. Needs to be of an owned identity. * @param[in] authorId Id of the author. Needs to be of an owned identity.
* @param[in] vote Vote value, either RsGxsVoteType::DOWN or * @param[in] vote Vote value, either RsGxsVoteType::DOWN or RsGxsVoteType::UP
* RsGxsVoteType::UP * @param[out] voteId Optional storage for the id of the created vote, meaningful only on success.
* @param[out] voteId Optional storage for the id of the created vote,
* meaningful only on success.
* @param[out] errorMessage Optional storage for error message, meaningful * @param[out] errorMessage Optional storage for error message, meaningful
* only on failure. * only on failure.
* @return false on error, true otherwise * @return false on error, true otherwise

View File

@ -1431,10 +1431,13 @@ bool p3GxsChannels::createPostV2(
return false; return false;
} }
bool p3GxsChannels::createCommentV2( bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
const RsGxsGroupId& channelId, const RsGxsMessageId& parentId, const RsGxsMessageId& threadId,
const std::string& comment, RsGxsMessageId& commentMessageId, const RsGxsMessageId& parentId,
std::string& errorMessage ) const RsGxsId& authorId,
const std::string& comment,
RsGxsMessageId& commentMessageId,
std::string& errorMessage)
{ {
std::vector<RsGxsChannelGroup> channelsInfo; std::vector<RsGxsChannelGroup> channelsInfo;
if(!getChannelsInfo(std::list<RsGxsGroupId>({channelId}),channelsInfo)) if(!getChannelsInfo(std::list<RsGxsGroupId>({channelId}),channelsInfo))
@ -1444,32 +1447,49 @@ bool p3GxsChannels::createCommentV2(
return false; return false;
} }
if(parentId.isNull())
{
errorMessage = "You cannot comment post " + parentId.toStdString()
+ " of channel with Id " + channelId.toStdString()
+ ": please supply a non null post Id!";
return false;
}
std::set<RsGxsMessageId> s({parentId});
std::vector<RsGxsChannelPost> posts; std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments; std::vector<RsGxsComment> comments;
if(!getChannelContent(channelId,s,posts,comments)) if(!getChannelContent( channelId,std::set<RsGxsMessageId>({threadId}),posts,comments )) // does the post thread exist?
{ {
errorMessage = "You cannot comment post " + parentId.toStdString() errorMessage = "You cannot comment post " + threadId.toStdString() + " of channel with Id " + channelId.toStdString() + ": this post does not exists locally!";
+ " of channel with Id " + channelId.toStdString() return false;
+ ": this post does not exists locally!"; }
if(posts.size() != 1 || !posts[0].mMeta.mParentId.isNull()) // check that the post thread Id is actually that of a post thread
{
errorMessage = std::string("You cannot comment post " + threadId.toStdString() + " of channel with Id " + channelId.toStdString() + ": supplied threadId is not a thread, or parentMsgId is not a comment!");
return false;
}
if(!parentId.isNull())
if(!getChannelContent( channelId,std::set<RsGxsMessageId>({parentId}),posts,comments )) // does the post thread exist?
{
errorMessage = std::string("You cannot comment post " + parentId.toStdString() + ": supplied parent comment Id is not a comment!");
return false;
}
else if(comments.size() != 1 || comments[0].mMeta.mParentId.isNull()) // is the comment parent actually a comment?
{
errorMessage = std::string("You cannot comment post " + parentId.toStdString() + " of channel with Id " + channelId.toStdString() + ": supplied mParentMsgId is not a comment Id!");
return false;
}
if(!rsIdentity->isOwnId(authorId)) // is the voter ID actually ours?
{
errorMessage = std::string("You cannot comment to channel with Id " + channelId.toStdString() + " with identity " + authorId.toStdString() + " because it is not yours.");
return false; return false;
} }
// Now create the comment // Now create the comment
RsGxsComment cmt; RsGxsComment cmt;
cmt.mComment = comment;
cmt.mMeta.mGroupId = channelId; cmt.mMeta.mGroupId = channelId;
cmt.mMeta.mThreadId = threadId;
cmt.mMeta.mParentId = parentId; cmt.mMeta.mParentId = parentId;
cmt.mMeta.mAuthorId = authorId;
cmt.mComment = comment;
uint32_t token; uint32_t token;
if(!createNewComment(token, cmt)) if(!createNewComment(token, cmt))

View File

@ -212,12 +212,13 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
virtual bool createComment(RsGxsComment& comment) override; virtual bool createComment(RsGxsComment& comment) override;
/// Implementation of @see RsGxsChannels::createComment /// Implementation of @see RsGxsChannels::createComment
virtual bool createCommentV2( virtual bool createCommentV2(const RsGxsGroupId& channelId,
const RsGxsGroupId& channelId, const RsGxsMessageId& parentId, const RsGxsMessageId& threadId,
const RsGxsMessageId& parentId,
const RsGxsId& authorId,
const std::string& comment, const std::string& comment,
RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId), RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)) override;
) override;
/// Implementation of @see RsGxsChannels::editChannel /// Implementation of @see RsGxsChannels::editChannel
virtual bool editChannel(RsGxsChannelGroup& channel) override; virtual bool editChannel(RsGxsChannelGroup& channel) override;