From 6c0ef0317e195e6d426a595dc78a93bbf3337588 Mon Sep 17 00:00:00 2001 From: defnax <9952056+defnax@users.noreply.github.com> Date: Wed, 24 Dec 2025 21:34:20 +0100 Subject: [PATCH] Edit board post attempt --- src/retroshare/rsposted.h | 8 +++++-- src/services/p3posted.cc | 44 ++++++++++++++++++++++++++++++++------- src/services/p3posted.h | 6 ++++-- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/retroshare/rsposted.h b/src/retroshare/rsposted.h index 9829d973b..68125ca4f 100644 --- a/src/retroshare/rsposted.h +++ b/src/retroshare/rsposted.h @@ -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 @@ -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} diff --git a/src/services/p3posted.cc b/src/services/p3posted.cc index 2bb4f0847..ff0ac836f 100644 --- a/src/services/p3posted.cc +++ b/src/services/p3posted.cc @@ -729,8 +729,8 @@ 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 @@ -738,8 +738,8 @@ bool p3Posted::createPostV2(const RsGxsGroupId& boardId, 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; } @@ -747,13 +747,41 @@ bool p3Posted::createPostV2(const RsGxsGroupId& boardId, 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 s({origPostId}); + std::vector posts; + std::vector comments; + std::vector 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; @@ -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; } diff --git a/src/services/p3posted.h b/src/services/p3posted.h index 4adc2cf29..4559bd88d 100644 --- a/src/services/p3posted.h +++ b/src/services/p3posted.h @@ -96,8 +96,10 @@ virtual void receiveHelperChanges(std::vector& 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,