mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -05:00
Expose comment editing capability in JSON API
This commit is contained in:
parent
3ffb57f998
commit
ddde80ddff
@ -142,10 +142,13 @@ public:
|
||||
* posted
|
||||
* @param[in] threadId Id of the post (that is a thread) in the channel
|
||||
* where the comment is placed
|
||||
* @param[in] comment UTF-8 string containing the comment itself
|
||||
* @param[in] authorId Id of the author of the 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] authorId Id of the author of the comment
|
||||
* @param[in] comment UTF-8 string containing the comment itself
|
||||
* @param[in] origCommentId If this is supposed to replace an already
|
||||
* existent comment, the id of the old post.
|
||||
* If left blank a new post will be created.
|
||||
* @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
|
||||
@ -155,9 +158,10 @@ public:
|
||||
virtual bool createCommentV2(
|
||||
const RsGxsGroupId& channelId,
|
||||
const RsGxsMessageId& threadId,
|
||||
const RsGxsMessageId& parentId,
|
||||
const RsGxsId& authorId,
|
||||
const std::string& comment,
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId = RsGxsMessageId(),
|
||||
const RsGxsMessageId& origCommentId = RsGxsMessageId(),
|
||||
RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) = 0;
|
||||
|
@ -1433,13 +1433,15 @@ bool p3GxsChannels::createPostV2(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
|
||||
const RsGxsMessageId& threadId,
|
||||
const RsGxsMessageId& parentId,
|
||||
const RsGxsId& authorId,
|
||||
const std::string& comment,
|
||||
RsGxsMessageId& commentMessageId,
|
||||
std::string& errorMessage)
|
||||
bool p3GxsChannels::createCommentV2(
|
||||
const RsGxsGroupId& channelId,
|
||||
const RsGxsMessageId& threadId,
|
||||
const std::string& comment,
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId,
|
||||
const RsGxsMessageId& origCommentId,
|
||||
RsGxsMessageId& commentMessageId,
|
||||
std::string& errorMessage )
|
||||
{
|
||||
std::vector<RsGxsChannelGroup> channelsInfo;
|
||||
if(!getChannelsInfo(std::list<RsGxsGroupId>({channelId}),channelsInfo))
|
||||
@ -1476,6 +1478,7 @@ bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
|
||||
}
|
||||
|
||||
if(!parentId.isNull())
|
||||
{
|
||||
if(!getChannelContent( // does the post thread exist?
|
||||
channelId,std::set<RsGxsMessageId>({parentId}),posts,comments ))
|
||||
{
|
||||
@ -1485,17 +1488,50 @@ bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
else if(comments.size() != 1 || comments[0].mMeta.mParentId.isNull())
|
||||
{ // is the comment parent actually a comment?
|
||||
errorMessage = "You cannot comment post " + parentId.toStdString()
|
||||
+ " of channel with Id " + channelId.toStdString() +
|
||||
": supplied mParentMsgId is not a comment Id!";
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
||||
<< std::endl;
|
||||
else
|
||||
{
|
||||
if(comments.size() != 1 || comments[0].mMeta.mParentId.isNull())
|
||||
{ // is the comment parent actually a comment?
|
||||
errorMessage = "You cannot comment post "
|
||||
+ parentId.toStdString()
|
||||
+ " of channel with Id " + channelId.toStdString() +
|
||||
": supplied mParentMsgId is not a comment Id!";
|
||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!origCommentId.isNull())
|
||||
{
|
||||
std::set<RsGxsMessageId> s({origCommentId});
|
||||
std::vector<RsGxsChannelPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
|
||||
if( !getChannelContent(channelId, s, posts, comments) ||
|
||||
comments.size() != 1 )
|
||||
{
|
||||
errorMessage = "You cannot edit comment "
|
||||
+ origCommentId.toStdString()
|
||||
+ " of channel with Id " + channelId.toStdString()
|
||||
+ ": this post does not exist locally!";
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!rsIdentity->isOwnId(authorId)) // is the voter ID actually ours?
|
||||
const RsGxsId& commentAuthor = comments[0].mMeta.mAuthorId;
|
||||
if(commentAuthor != authorId)
|
||||
{
|
||||
errorMessage = "Editor identity and creator doesn't match "
|
||||
+ authorId.toStdString() + " != "
|
||||
+ commentAuthor.toStdString();
|
||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!rsIdentity->isOwnId(authorId)) // is the author ID actually ours?
|
||||
{
|
||||
errorMessage = "You cannot comment to channel with Id " +
|
||||
channelId.toStdString() + " with identity " +
|
||||
@ -1511,6 +1547,7 @@ bool p3GxsChannels::createCommentV2(const RsGxsGroupId& channelId,
|
||||
cmt.mMeta.mThreadId = threadId;
|
||||
cmt.mMeta.mParentId = parentId;
|
||||
cmt.mMeta.mAuthorId = authorId;
|
||||
cmt.mMeta.mOrigMsgId = origCommentId;
|
||||
cmt.mComment = comment;
|
||||
|
||||
uint32_t token;
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "gxs/rsgenexchange.h"
|
||||
#include "gxs/gxstokenqueue.h"
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rstickevent.h"
|
||||
|
||||
#include <map>
|
||||
@ -213,11 +213,14 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
|
||||
|
||||
/// Implementation of @see RsGxsChannels::createComment
|
||||
virtual bool createCommentV2(
|
||||
const RsGxsGroupId& channelId, const RsGxsMessageId& threadId,
|
||||
const RsGxsMessageId& parentId, const RsGxsId& authorId,
|
||||
const RsGxsGroupId& channelId,
|
||||
const RsGxsMessageId& threadId,
|
||||
const std::string& comment,
|
||||
RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
const RsGxsId& authorId,
|
||||
const RsGxsMessageId& parentId = RsGxsMessageId(),
|
||||
const RsGxsMessageId& origCommentId = RsGxsMessageId(),
|
||||
RsGxsMessageId& commentMessageId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
|
||||
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
|
||||
) override;
|
||||
|
||||
/// Implementation of @see RsGxsChannels::editChannel
|
||||
|
Loading…
Reference in New Issue
Block a user