Merge pull request #2026 from csoler/v0.6-BoardsGUI

V0.6 boards gui
This commit is contained in:
csoler 2020-10-12 20:07:42 +02:00 committed by GitHub
commit ce6fb603c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 5208 additions and 370 deletions

View file

@ -48,7 +48,7 @@ public:
TYPE_UPDATED = 0x07,
TYPE_MESSAGE_DELETED = 0x08,
TYPE_GROUP_DELETED = 0x09,
};
};
virtual NotifyType getType() = 0;

View file

@ -115,6 +115,7 @@ enum class RsPostedEventCode: uint8_t
UPDATED_MESSAGE = 0x05,
READ_STATUS_CHANGED = 0x06,
STATISTICS_CHANGED = 0x07,
MESSAGE_VOTES_UPDATED = 0x08,
};
@ -127,6 +128,7 @@ struct RsGxsPostedEvent: RsEvent
RsPostedEventCode mPostedEventCode;
RsGxsGroupId mPostedGroupId;
RsGxsMessageId mPostedMsgId;
RsGxsMessageId mPostedThreadId;
///* @see RsEvent @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
@ -172,7 +174,11 @@ public:
virtual bool getBoardsServiceStatistics(GxsServiceStatistic& stat) =0;
enum RS_DEPRECATED RankType {TopRankType, HotRankType, NewRankType };
virtual bool voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& voterId) =0;
virtual bool setPostReadStatus(const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
enum RS_DEPRECATED RankType {TopRankType, HotRankType, NewRankType };
RS_DEPRECATED_FOR(getBoardsInfo)
virtual bool getGroupData( const uint32_t& token,
@ -201,8 +207,9 @@ public:
//virtual bool createNewComment(uint32_t &token, RsGxsComment &comment) = 0;
//virtual bool createNewVote(uint32_t &token, RsGxsVote &vote) = 0;
RS_DEPRECATED_FOR(setPostReadStatus)
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
//////////////////////////////////////////////////////////////////////////////
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0;
virtual bool createPost(uint32_t &token, RsPostedPost &post) = 0;

View file

@ -38,6 +38,7 @@
/****
* #define POSTBASE_DEBUG 1
****/
#define POSTBASE_DEBUG 1
#define POSTBASE_BACKGROUND_PROCESSING 0x0002
#define PROCESSING_START_PERIOD 30
@ -88,101 +89,123 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
#endif
for(auto it = changes.begin(); it != changes.end(); ++it)
{
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
{
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
if (msgChange)
{
if(msgChange)
{
// To start with we are just going to trigger updates on these groups.
// FUTURE OPTIMISATION.
// It could be taken a step further and directly request these msgs for an update.
addGroupForProcessing(msgChange->mGroupId);
if (rsEvents)
{
switch(msgChange->getType())
{
case RsGxsNotify::TYPE_RECEIVED_NEW:
case RsGxsNotify::TYPE_PUBLISHED:
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedMsgId = msgChange->mMsgId;
ev->mPostedThreadId = msgChange->mNewMsgItem->meta.mThreadId;
ev->mPostedGroupId = msgChange->mGroupId;
ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE;
rsEvents->postEvent(ev);
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification";
std::cerr << std::endl;
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: NEW/PUBLISHED ID=" << msgChange->mMsgId << " in group " << msgChange->mGroupId << ", thread ID = " << msgChange->mNewMsgItem->meta.mThreadId << std::endl;
#endif
}
break;
case RsGxsNotify::TYPE_PROCESSED:
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedMsgId = msgChange->mMsgId;
ev->mPostedGroupId = msgChange->mGroupId;
ev->mPostedEventCode = RsPostedEventCode::MESSAGE_VOTES_UPDATED;
rsEvents->postEvent(ev);
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Msgs for Group: " << mit->first;
std::cerr << std::endl;
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: PROCESSED ID=" << msgChange->mMsgId << " in group " << msgChange->mGroupId << std::endl;
#endif
// To start with we are just going to trigger updates on these groups.
// FUTURE OPTIMISATION.
// It could be taken a step further and directly request these msgs for an update.
addGroupForProcessing(msgChange->mGroupId);
if (rsEvents && (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED))
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedMsgId = msgChange->mMsgId;
ev->mPostedGroupId = msgChange->mGroupId;
ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE;
rsEvents->postEvent(ev);
}
}
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange *>(*it);
/* pass on Group Changes to GUI */
if (grpChange && rsEvents)
{
}
break;
default:
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Found Group Change Notification";
std::cerr << std::endl;
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: type " << msgChange->getType() << " (ignored) " << msgChange->mMsgId << std::endl;
#endif
break;
}
}
}
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange *>(*it);
/* pass on Group Changes to GUI */
if (grpChange && rsEvents)
{
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Found Group Change Notification";
std::cerr << std::endl;
#endif
const RsGxsGroupId& group_id(grpChange->mGroupId);
switch(grpChange->getType())
{
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED;
rsEvents->postEvent(ev);
}
break;
{
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED;
rsEvents->postEvent(ev);
}
break;
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::STATISTICS_CHANGED;
rsEvents->postEvent(ev);
}
break;
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::STATISTICS_CHANGED;
rsEvents->postEvent(ev);
}
break;
case RsGxsNotify::TYPE_PUBLISHED:
case RsGxsNotify::TYPE_RECEIVED_NEW:
{
/* group received */
case RsGxsNotify::TYPE_PUBLISHED:
case RsGxsNotify::TYPE_RECEIVED_NEW:
{
/* group received */
if(mKnownPosted.find(group_id) == mKnownPosted.end())
{
mKnownPosted.insert(std::make_pair(group_id, time(nullptr)));
IndicateConfigChanged();
if(mKnownPosted.find(group_id) == mKnownPosted.end())
{
mKnownPosted.insert(std::make_pair(group_id, time(nullptr)));
IndicateConfigChanged();
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
rsEvents->postEvent(ev);
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
rsEvents->postEvent(ev);
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << group_id;
std::cerr << std::endl;
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << group_id;
std::cerr << std::endl;
#endif
}
else
RsInfo() << __PRETTY_FUNCTION__
<< " Not notifying already known forum "
<< group_id << std::endl;
}
break;
}
else
RsInfo() << __PRETTY_FUNCTION__
<< " Not notifying already known forum "
<< group_id << std::endl;
}
break;
default:
RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl;
break;
}
}
default:
RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl;
break;
}
}
delete *it;
}
}
}
void p3PostBase::service_tick()

View file

@ -442,6 +442,57 @@ bool p3Posted::createBoard(RsPostedGroup& board)
return true;
}
bool p3Posted::voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& authorId)
{
// Do some basic tests
if(!rsIdentity->isOwnId(authorId)) // This is ruled out before waitToken complains. Not sure it's needed.
{
std::cerr << __PRETTY_FUNCTION__ << ": vote submitted with an ID that is not yours! This cannot work." << std::endl;
return false;
}
RsGxsVote vote;
vote.mMeta.mGroupId = postGrpId;
vote.mMeta.mThreadId = postMsgId;
vote.mMeta.mParentId = postMsgId;
vote.mMeta.mAuthorId = authorId;
if (up)
vote.mVoteType = GXS_VOTE_UP;
else
vote.mVoteType = GXS_VOTE_DOWN;
uint32_t token;
if(!createNewVote(token, vote))
{
std::cerr << __PRETTY_FUNCTION__ << " Error! Failed submitting vote to (group,msg) " << postGrpId << "," << postMsgId << " from author " << authorId << std::endl;
return false;
}
if(waitToken(token) != RsTokenService::COMPLETE)
{
std::cerr << __PRETTY_FUNCTION__ << " Error! GXS operation failed." << std::endl;
return false;
}
return true;
}
bool p3Posted::setPostReadStatus(const RsGxsGrpMsgIdPair& msgId, bool read)
{
uint32_t token;
setMessageReadStatus(token,msgId,read);
if(waitToken(token) != RsTokenService::COMPLETE)
{
std::cerr << __PRETTY_FUNCTION__ << " Error! GXS operation failed." << std::endl;
return false;
}
return true;
}
bool p3Posted::editBoard(RsPostedGroup& board)
{
uint32_t token;

View file

@ -84,7 +84,11 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
bool createBoard(RsPostedGroup& board) override;
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) override;
bool voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& voterId) override;
bool setPostReadStatus(const RsGxsGrpMsgIdPair& msgId, bool read) override;
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) override;
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts, std::vector<RsGxsVote> &vots) override;
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts) override;
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts) override;
@ -126,17 +130,17 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
return mCommentService->createGxsComment(token, msg) && waitToken(token) == RsTokenService::COMPLETE ;
}
virtual bool createNewVote(uint32_t &token, RsGxsVote &msg)
virtual bool createNewVote(uint32_t &token, RsGxsVote &msg) override
{
return mCommentService->createGxsVote(token, msg);
}
virtual bool acknowledgeComment(
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId )
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) override
{ return acknowledgeMsg(token, msgId); }
virtual bool acknowledgeVote(
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId )
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) override
{
if (mCommentService->acknowledgeVote(token, msgId)) return true;
return acknowledgeMsg(token, msgId);