Merge pull request #2059 from G10h4ck/stubborn_post

Forum add API to mark a post to be kept forever
This commit is contained in:
csoler 2020-09-01 22:28:10 +02:00 committed by GitHub
commit e2a04c1baa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 4 deletions

View File

@ -282,7 +282,7 @@ bool RsGenExchange::messagePublicationTest(const RsGxsMsgMetaData& meta)
rstime_t storageTimeLimit = meta.mPublishTs + st;
return meta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_KEEP || st == 0 || storageTimeLimit >= time(NULL);
return meta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_KEEP_FOREVER || st == 0 || storageTimeLimit >= time(NULL);
}
bool RsGenExchange::acknowledgeTokenMsg(const uint32_t& token,

View File

@ -107,7 +107,7 @@ bool RsGxsMessageCleanUp::clean()
bool remove = store_period > 0 && ((meta->mPublishTs + store_period) < now) && !have_kids;
// check client does not want the message kept regardless of age
remove &= !(meta->mMsgStatus & GXS_SERV::GXS_MSG_STATUS_KEEP);
remove &= !(meta->mMsgStatus & GXS_SERV::GXS_MSG_STATUS_KEEP_FOREVER);
// if not subscribed remove messages (can optimise this really)
remove = remove || (grpMeta->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED);

View File

@ -107,7 +107,8 @@ namespace GXS_SERV {
static const uint32_t GXS_MSG_STATUS_UNPROCESSED = 0x00000001; // Flags to store the read/process status of group messages.
static const uint32_t GXS_MSG_STATUS_GUI_UNREAD = 0x00000002; // The actual meaning may depend on the type of service.
static const uint32_t GXS_MSG_STATUS_GUI_NEW = 0x00000004; //
static const uint32_t GXS_MSG_STATUS_KEEP = 0x00000008; //
/** Do not delete message even if older then group maximum storage time */
static const uint32_t GXS_MSG_STATUS_KEEP_FOREVER = 0x00000008;
static const uint32_t GXS_MSG_STATUS_DELETE = 0x00000020; //
/** END GXS Msg status flags **/

View File

@ -363,12 +363,25 @@ public:
* @param[in] parentId id of the post of which child posts (aka replies)
* are requested.
* @param[out] childPosts storage for the child posts
* @return false if something failed, true otherwhise
* @return Success or error details
*/
virtual std::error_condition getChildPosts(
const RsGxsGroupId& forumId, const RsGxsMessageId& parentId,
std::vector<RsGxsForumMsg>& childPosts ) = 0;
/**
* @brief Set keep forever flag on a post so it is not deleted even if older
* then group maximum storage time
* @jsonapi{development}
* @param[in] forumId id of the forum of which the post pertain
* @param[in] postId id of the post on which to set the flag
* @param[in] keepForever true to set the flag, false to unset it
* @return Success or error details
*/
virtual std::error_condition setPostKeepForever(
const RsGxsGroupId& forumId, const RsGxsMessageId& postId,
bool keepForever ) = 0;
/**
* @brief Create forum. Blocking API.
* @jsonapi{development}

View File

@ -919,6 +919,9 @@ void p3GxsForums::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair&
setMsgStatusFlags(token, msgId, status, mask);
/* WARNING: The event may be received before the operation is completed!
* TODO: move notification to blocking method markRead(...) which wait the
* operation to complete */
if (rsEvents)
{
auto ev = std::make_shared<RsGxsForumEvent>();
@ -933,6 +936,37 @@ void p3GxsForums::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair&
/********************************************************************************************/
/********************************************************************************************/
std::error_condition p3GxsForums::setPostKeepForever(
const RsGxsGroupId& forumId, const RsGxsMessageId& postId,
bool keepForever )
{
if(forumId.isNull() || postId.isNull()) return std::errc::invalid_argument;
uint32_t mask = GXS_SERV::GXS_MSG_STATUS_KEEP_FOREVER;
uint32_t status = keepForever ? GXS_SERV::GXS_MSG_STATUS_KEEP_FOREVER : 0;
uint32_t token;
setMsgStatusFlags(token, RsGxsGrpMsgIdPair(forumId, postId), status, mask);
switch(waitToken(token))
{
case RsTokenService::PENDING: // [[fallthrough]];
case RsTokenService::PARTIAL: return std::errc::timed_out;
case RsTokenService::COMPLETE: // [[fallthrough]];
case RsTokenService::DONE:
{
auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumGroupId = forumId;
ev->mForumMsgId = postId;
ev->mForumEventCode = RsForumEventCode::UPDATED_MESSAGE;
rsEvents->postEvent(ev);
return std::error_condition();
}
case RsTokenService::CANCELLED: return std::errc::operation_canceled;
default: return std::errc::bad_message;
}
}
/* so we need the same tick idea as wiki for generating dummy forums
*/

View File

@ -137,6 +137,11 @@ public:
const RsGxsGroupId& forumId, const RsGxsMessageId& parentId,
std::vector<RsGxsForumMsg>& childPosts ) override;
/// @see RsGxsForums
std::error_condition setPostKeepForever(
const RsGxsGroupId& forumId, const RsGxsMessageId& postId,
bool keepForever );
/// implementation of rsGxsGorums
///
bool getGroupData(const uint32_t &token, std::vector<RsGxsForumGroup> &groups) override;