Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/retroshare/rsposted.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
* @param[in] link link attached to the post. Should be a https/http link
* @param[in] notes text attached to the post.
* @param[in] authorId signing author. Should be our own ID.
* @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.
* @param[in] image optional post image.
* @param[out] postId id of the post after it's been generated
* @param[out] error_message possible error message if the method returns false
Expand All @@ -298,8 +301,9 @@ class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
const std::string& notes,
const RsGxsId& authorId,
const RsGxsImage& image,
RsGxsMessageId& postId,
std::string& error_message) =0;
const RsGxsMessageId& origPostId = RsGxsMessageId(),
RsGxsMessageId& postId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0;

/** @brief Add a comment on a post or on another comment. Blocking API.
* @jsonapi{development}
Expand Down
44 changes: 36 additions & 8 deletions src/services/p3posted.cc
Original file line number Diff line number Diff line change
Expand Up @@ -729,31 +729,59 @@ bool p3Posted::createPostV2(const RsGxsGroupId& boardId,
const std::string& notes,
const RsGxsId& authorId,
const RsGxsImage& image,
RsGxsMessageId& postId,
std::string& error_message)
const RsGxsMessageId& origPostId,
RsGxsMessageId& postId, std::string& errorMessage )
{
// check boardId

std::vector<RsPostedGroup> groupsInfo;

if(!getBoardsInfo( { boardId }, groupsInfo))
{
error_message = "Board with Id " + boardId.toStdString() + " does not exist.";
RsErr() << error_message;
errorMessage = "Board with Id " + boardId.toStdString() + " does not exist.";
RsErr() << errorMessage;
return false;
}

// check author

if(!rsIdentity->isOwnId(authorId))
{
error_message = "Attempt to create a board post with an author that is not a own ID: " + authorId.toStdString() ;
RsErr() << error_message;
errorMessage = "Attempt to create a board post with an author that is not a own ID: " + authorId.toStdString() ;
RsErr() << errorMessage;
return false;
}

RsGxsMessageId top_level_parent ; // left blank intentionaly

if(!origPostId.isNull())
{
std::set<RsGxsMessageId> s({origPostId});
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> comments;
std::vector<RsGxsVote> votes;

if(!getBoardContent(boardId,s,posts,comments,votes) || posts.size()!=1)
{
errorMessage = "You cannot edit post " + origPostId.toStdString()
+ " of board with Id " + boardId.toStdString()
+ ": this post does not exist locally!";
return false;
}

// All post versions should have the same mOrigMsgId, so we copy that of the post we're editing.
// The edited post may not have an original post ID if it is itself the first version. In this case, the
// mOrigId is set to be the ID of the edited post.

top_level_parent = posts[0].mMeta.mOrigMsgId;

if(top_level_parent.isNull())
top_level_parent = origPostId;
}

RsPostedPost post;
post.mMeta.mGroupId = boardId;
post.mMeta.mOrigMsgId = top_level_parent;
post.mLink = link.toString();
post.mImage = image;
post.mNotes = notes;
Expand All @@ -766,8 +794,8 @@ bool p3Posted::createPostV2(const RsGxsGroupId& boardId,
post.serial_process(RsGenericSerializer::SIZE_ESTIMATE,ctx);

if(ctx.mSize > 200000) {
error_message = "Maximum size of 200000 bytes exceeded for board post.";
RsErr() << error_message;
errorMessage = "Maximum size of 200000 bytes exceeded for board post.";
RsErr() << errorMessage;
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions src/services/p3posted.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
const std::string& notes,
const RsGxsId& authorId,
const RsGxsImage& image,
RsGxsMessageId& postId,
std::string& error_message) override;
const RsGxsMessageId& origPostId = RsGxsMessageId(),
RsGxsMessageId& postId = RS_DEFAULT_STORAGE_PARAM(RsGxsMessageId),
std::string& errorMessage = RS_DEFAULT_STORAGE_PARAM(std::string)
) override;

bool voteForPost(const RsGxsGroupId& boardId,
const RsGxsMessageId& postMsgId,
Expand Down
Loading