mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-05 01:25:39 -05:00
Fix p3GxsChannels::createCommentV2
This commit is contained in:
parent
ab93d31d17
commit
1b071d106f
@ -1423,65 +1423,44 @@ bool p3GxsChannels::createCommentV2(
|
|||||||
RsGxsMessageId& commentMessageId,
|
RsGxsMessageId& commentMessageId,
|
||||||
std::string& errorMessage )
|
std::string& errorMessage )
|
||||||
{
|
{
|
||||||
|
constexpr auto fname = __PRETTY_FUNCTION__;
|
||||||
|
const auto failure = [&](const std::string& err)
|
||||||
|
{
|
||||||
|
errorMessage = err;
|
||||||
|
RsErr() << fname << " " << err << std::endl;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if(channelId.isNull()) return failure("channelId cannot be null");
|
||||||
|
if(threadId.isNull()) return failure("threadId cannot be null");
|
||||||
|
if(parentId.isNull()) return failure("parentId cannot be null");
|
||||||
|
|
||||||
std::vector<RsGxsChannelGroup> channelsInfo;
|
std::vector<RsGxsChannelGroup> channelsInfo;
|
||||||
if(!getChannelsInfo(std::list<RsGxsGroupId>({channelId}),channelsInfo))
|
if(!getChannelsInfo(std::list<RsGxsGroupId>({channelId}),channelsInfo))
|
||||||
{
|
return failure( "Channel with Id " + channelId.toStdString()
|
||||||
errorMessage = "Channel with Id " + channelId.toStdString()
|
+ " does not exist." );
|
||||||
+ " does not exist.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<RsGxsChannelPost> posts;
|
std::vector<RsGxsChannelPost> posts;
|
||||||
std::vector<RsGxsComment> comments;
|
std::vector<RsGxsComment> comments;
|
||||||
|
|
||||||
if(!getChannelContent( // does the post thread exist?
|
if(!getChannelContent( // does the post thread exist?
|
||||||
channelId,std::set<RsGxsMessageId>({threadId}), posts, comments ))
|
channelId,std::set<RsGxsMessageId>({threadId}), posts, comments ))
|
||||||
{
|
return failure( "You cannot comment post " + threadId.toStdString() +
|
||||||
errorMessage = "You cannot comment post " + threadId.toStdString() +
|
" of channel with Id " + channelId.toStdString() +
|
||||||
" of channel with Id " + channelId.toStdString() +
|
": this post does not exists locally!" );
|
||||||
": this post does not exists locally!";
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
|
||||||
<< std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that the post thread Id is actually that of a post thread
|
// check that the post thread Id is actually that of a post thread
|
||||||
if(posts.size() != 1 || !posts[0].mMeta.mParentId.isNull())
|
if(posts.size() != 1 || !posts[0].mMeta.mParentId.isNull())
|
||||||
{
|
return failure( "You cannot comment post " + threadId.toStdString() +
|
||||||
errorMessage = "You cannot comment post " + threadId.toStdString() +
|
" of channel with Id " + channelId.toStdString() +
|
||||||
" of channel with Id " + channelId.toStdString() +
|
": supplied threadId is not a thread, or parentMsgId is"
|
||||||
": supplied threadId is not a thread, or parentMsgId is not a" +
|
" not a comment!");
|
||||||
" comment!";
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
|
||||||
<< std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!parentId.isNull())
|
if(!getChannelContent( // does the post thread exist?
|
||||||
{
|
channelId, std::set<RsGxsMessageId>({parentId}),
|
||||||
if(!getChannelContent( // does the post thread exist?
|
posts, comments ))
|
||||||
channelId,std::set<RsGxsMessageId>({parentId}),posts,comments ))
|
return failure( "You cannot comment post " + parentId.toStdString() +
|
||||||
{
|
": supplied parent doesn't exists locally!" );
|
||||||
errorMessage = "You cannot comment post " + parentId.toStdString() +
|
|
||||||
": supplied parent comment Id is not a comment!";
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
|
||||||
<< 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;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!origCommentId.isNull())
|
if(!origCommentId.isNull())
|
||||||
{
|
{
|
||||||
@ -1491,35 +1470,22 @@ bool p3GxsChannels::createCommentV2(
|
|||||||
|
|
||||||
if( !getChannelContent(channelId, s, posts, comments) ||
|
if( !getChannelContent(channelId, s, posts, comments) ||
|
||||||
comments.size() != 1 )
|
comments.size() != 1 )
|
||||||
{
|
return failure( "You cannot edit comment " +
|
||||||
errorMessage = "You cannot edit comment "
|
origCommentId.toStdString() +
|
||||||
+ origCommentId.toStdString()
|
" of channel with Id " + channelId.toStdString() +
|
||||||
+ " of channel with Id " + channelId.toStdString()
|
": this comment does not exist locally!");
|
||||||
+ ": this post does not exist locally!";
|
|
||||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const RsGxsId& commentAuthor = comments[0].mMeta.mAuthorId;
|
const RsGxsId& commentAuthor = comments[0].mMeta.mAuthorId;
|
||||||
if(commentAuthor != authorId)
|
if(commentAuthor != authorId)
|
||||||
{
|
return failure( "Editor identity and creator doesn't match "
|
||||||
errorMessage = "Editor identity and creator doesn't match "
|
+ authorId.toStdString() + " != "
|
||||||
+ authorId.toStdString() + " != "
|
+ commentAuthor.toStdString() );
|
||||||
+ commentAuthor.toStdString();
|
|
||||||
RsErr() << __PRETTY_FUNCTION__ << " " << errorMessage << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!rsIdentity->isOwnId(authorId)) // is the author ID actually ours?
|
if(!rsIdentity->isOwnId(authorId)) // is the author ID actually ours?
|
||||||
{
|
return failure( "You cannot comment to channel with Id " +
|
||||||
errorMessage = "You cannot comment to channel with Id " +
|
channelId.toStdString() + " with identity " +
|
||||||
channelId.toStdString() + " with identity " +
|
authorId.toStdString() + " because it is not yours." );
|
||||||
authorId.toStdString() + " because it is not yours.";
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
|
||||||
<< std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now create the comment
|
// Now create the comment
|
||||||
RsGxsComment cmt;
|
RsGxsComment cmt;
|
||||||
@ -1532,28 +1498,15 @@ bool p3GxsChannels::createCommentV2(
|
|||||||
|
|
||||||
uint32_t token;
|
uint32_t token;
|
||||||
if(!createNewComment(token, cmt))
|
if(!createNewComment(token, cmt))
|
||||||
{
|
return failure("createNewComment failed");
|
||||||
errorMessage = "Failed creating comment.";
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
|
||||||
<< std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(waitToken(token) != RsTokenService::COMPLETE)
|
RsTokenService::GxsRequestStatus wSt = waitToken(token);
|
||||||
{
|
if(wSt != RsTokenService::COMPLETE)
|
||||||
errorMessage = "GXS operation failed.";
|
return failure( "GXS operation waitToken failed with: " +
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
std::to_string(wSt) );
|
||||||
<< std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!RsGenExchange::getPublishedMsgMeta(token, cmt.mMeta))
|
if(!RsGenExchange::getPublishedMsgMeta(token, cmt.mMeta))
|
||||||
{
|
return failure("Failure getting created comment data.");
|
||||||
errorMessage = "Failure getting created comment data.";
|
|
||||||
std::cerr << __PRETTY_FUNCTION__ << " Error: " << errorMessage
|
|
||||||
<< std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
commentMessageId = cmt.mMeta.mMsgId;
|
commentMessageId = cmt.mMeta.mMsgId;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user