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
26 changes: 26 additions & 0 deletions src/retroshare/rsposted.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "retroshare/rsgxscommon.h"
#include "retroshare/rsgxscircles.h"
#include "serialiser/rsserializable.h"
#include "serialiser/rstlvidset.h"

class RsPosted;

Expand All @@ -46,13 +47,17 @@ struct RsPostedGroup: public RsSerializable, RsGxsGenericGroupData
std::string mDescription;
RsGxsImage mGroupImage;

/** @brief List of board pinned posts, those are displayed on top */
RsTlvGxsMsgIdSet mPinnedPosts;

/// @see RsSerializable
virtual void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx ) override
{
RS_SERIAL_PROCESS(mMeta);
RS_SERIAL_PROCESS(mDescription);
RS_SERIAL_PROCESS(mGroupImage);
RS_SERIAL_PROCESS(mPinnedPosts);
}
};

Expand Down Expand Up @@ -115,6 +120,8 @@ struct RsPostedPost: public RsSerializable, RsGxsGenericMsgData
#define RSPOSTED_VIEWMODE_HOT 3
#define RSPOSTED_VIEWMODE_COMMENTS 4

#define RSPOSTED_FLAG_POST_IS_PINNED 0x0001


enum class RsPostedEventCode: uint8_t
{
Expand All @@ -131,6 +138,7 @@ enum class RsPostedEventCode: uint8_t
NEW_COMMENT = 0x0a,
NEW_VOTE = 0x0b,
BOARD_DELETED = 0x0c,
PINNED_POSTS_CHANGED = 0x0d,
};


Expand Down Expand Up @@ -240,6 +248,24 @@ class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService
*/
virtual bool editBoard(RsPostedGroup& board) =0;

/**
* @brief Pin a post to the top of a board. Admin-only. Blocking API.
* @jsonapi{development}
* @param[in] boardId Id of the board
* @param[in] postId Id of the post to pin
* @return false on error, true otherwise
*/
virtual bool pinPost(const RsGxsGroupId& boardId, const RsGxsMessageId& postId) =0;

/**
* @brief Unpin a post from a board. Admin-only. Blocking API.
* @jsonapi{development}
* @param[in] boardId Id of the board
* @param[in] postId Id of the post to unpin
* @return false on error, true otherwise
*/
virtual bool unpinPost(const RsGxsGroupId& boardId, const RsGxsMessageId& postId) =0;

/**
* @brief Create board. Blocking API.
* @jsonapi{development}
Expand Down
15 changes: 15 additions & 0 deletions src/rsitems/rsposteditems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ void RsGxsPostedGroupItem::serial_process(RsGenericSerializer::SerializeJob j,Rs
return ;

RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mGroupImage,"mGroupImage") ;

// Backward compat: if only description+image were written, stop here
if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize)
return ;

RsTypeSerializer::serial_process<RsTlvItem>(j,ctx,mPinnedPosts,"mPinnedPosts") ;
}

RsItem *RsGxsPostedSerialiser::create_item(uint16_t service_id,uint8_t item_subtype) const
Expand Down Expand Up @@ -119,6 +125,7 @@ void RsGxsPostedGroupItem::clear()
{
mDescription.clear();
mGroupImage.TlvClear();
mPinnedPosts.TlvClear();
}

bool RsGxsPostedGroupItem::fromPostedGroup(RsPostedGroup &group, bool moveImage)
Expand All @@ -137,6 +144,10 @@ bool RsGxsPostedGroupItem::fromPostedGroup(RsPostedGroup &group, bool moveImage)
{
mGroupImage.binData.setBinData(group.mGroupImage.mData, group.mGroupImage.mSize);
}

// Copy pinned posts
mPinnedPosts = group.mPinnedPosts;

return true;
}

Expand All @@ -154,5 +165,9 @@ bool RsGxsPostedGroupItem::toPostedGroup(RsPostedGroup &group, bool moveImage)
{
group.mGroupImage.copy((uint8_t *) mGroupImage.binData.bin_data, mGroupImage.binData.bin_len);
}

// Copy pinned posts
group.mPinnedPosts = mPinnedPosts;

return true;
}
2 changes: 2 additions & 0 deletions src/rsitems/rsposteditems.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "rsitems/rsgxscommentitems.h"
#include "rsitems/rsgxsitems.h"
#include "serialiser/rstlvimage.h"
#include "serialiser/rstlvidset.h"

#include "retroshare/rsposted.h"

Expand All @@ -48,6 +49,7 @@ class RsGxsPostedGroupItem : public RsGxsGrpItem

std::string mDescription;
RsTlvImage mGroupImage;
RsTlvGxsMsgIdSet mPinnedPosts;

};

Expand Down
28 changes: 28 additions & 0 deletions src/services/p3posted.cc
Original file line number Diff line number Diff line change
Expand Up @@ -890,5 +890,33 @@ bool p3Posted::editBoard(RsPostedGroup& board)
return true;
}

bool p3Posted::pinPost(const RsGxsGroupId& boardId, const RsGxsMessageId& postId)
{
std::vector<RsPostedGroup> groupsInfo;
if(!getBoardsInfo({boardId}, groupsInfo))
{
std::cerr << __PRETTY_FUNCTION__ << " Error! Board not found." << std::endl;
return false;
}

RsPostedGroup board = groupsInfo.front();
board.mPinnedPosts.ids.insert(postId);
return editBoard(board);
}

bool p3Posted::unpinPost(const RsGxsGroupId& boardId, const RsGxsMessageId& postId)
{
std::vector<RsPostedGroup> groupsInfo;
if(!getBoardsInfo({boardId}, groupsInfo))
{
std::cerr << __PRETTY_FUNCTION__ << " Error! Board not found." << std::endl;
return false;
}

RsPostedGroup board = groupsInfo.front();
board.mPinnedPosts.ids.erase(postId);
return editBoard(board);
}

RsPosted::~RsPosted() = default;
RsGxsPostedEvent::~RsGxsPostedEvent() = default;
3 changes: 3 additions & 0 deletions src/services/p3posted.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)

bool editBoard(RsPostedGroup& board) override;

bool pinPost(const RsGxsGroupId& boardId, const RsGxsMessageId& postId) override;
bool unpinPost(const RsGxsGroupId& boardId, const RsGxsMessageId& postId) override;

bool createBoard(RsPostedGroup& board) override;

bool createBoardV2(const std::string& board_name,
Expand Down