2012-10-05 18:12:52 +00:00
|
|
|
#ifndef P3POSTED_H
|
|
|
|
#define P3POSTED_H
|
|
|
|
|
2012-11-30 18:54:25 +00:00
|
|
|
#include <map>
|
|
|
|
|
2012-10-05 18:12:52 +00:00
|
|
|
#include "retroshare/rsposted.h"
|
|
|
|
#include "gxs/rsgenexchange.h"
|
|
|
|
|
2012-11-30 18:54:25 +00:00
|
|
|
|
|
|
|
class GxsPostedPostRanking
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
uint32_t pubToken;
|
|
|
|
uint32_t reqToken;
|
|
|
|
RsPosted::RankType rType;
|
|
|
|
RsGxsGroupId grpId;
|
2012-12-11 22:26:11 +00:00
|
|
|
RsPostedPostRanking rankingResult;
|
2012-11-30 18:54:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GxsPostedCommentRanking
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
uint32_t pubToken;
|
|
|
|
uint32_t reqToken;
|
|
|
|
RsPosted::RankType rType;
|
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
PostedRanking result;
|
|
|
|
};
|
|
|
|
|
2012-12-02 19:40:17 +00:00
|
|
|
class PostedScore {
|
|
|
|
public:
|
2012-12-08 21:50:13 +00:00
|
|
|
|
|
|
|
PostedScore() : upVotes(0), downVotes(0), commentCount(0), date(0) {}
|
|
|
|
uint32_t upVotes, downVotes;
|
|
|
|
uint32_t commentCount;
|
2012-12-02 19:40:17 +00:00
|
|
|
time_t date;
|
|
|
|
RsGxsMessageId msgId;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-05 18:12:52 +00:00
|
|
|
class p3Posted : public RsGenExchange, public RsPosted
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* This confirms this class as an abstract one that \n
|
|
|
|
* should not be instantiated \n
|
|
|
|
* The deriving class should implement this function \n
|
|
|
|
* as it is called by the backend GXS system to \n
|
|
|
|
* update client of changes which should \n
|
|
|
|
* instigate client to retrieve new content from the system
|
|
|
|
* @param changes the changes that have occured to data held by this service
|
|
|
|
*/
|
|
|
|
void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
|
|
|
|
|
2012-10-21 19:45:35 +00:00
|
|
|
void service_tick();
|
|
|
|
|
2012-12-05 22:45:44 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
void generateTopics();
|
|
|
|
/*!
|
|
|
|
* Exists solely for testing
|
|
|
|
*/
|
|
|
|
void generatePosts();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Exists solely for testing
|
|
|
|
* Generates random votes to existing posts
|
|
|
|
* in the system
|
|
|
|
*/
|
2012-12-09 22:38:49 +00:00
|
|
|
void generateVotesAndComments();
|
2012-12-05 22:45:44 +00:00
|
|
|
|
2012-10-05 18:12:52 +00:00
|
|
|
public:
|
|
|
|
|
2012-10-21 19:45:35 +00:00
|
|
|
bool getGroup(const uint32_t &token, std::vector<RsPostedGroup> &group);
|
|
|
|
bool getPost(const uint32_t &token, PostedPostResult& posts) ;
|
|
|
|
bool getComment(const uint32_t &token, PostedCommentResult& comments) ;
|
2012-11-25 21:50:45 +00:00
|
|
|
bool getRelatedComment(const uint32_t& token, PostedRelatedCommentResult &comments);
|
2012-12-11 22:26:11 +00:00
|
|
|
bool getPostRanking(const uint32_t &token, RsPostedPostRanking &ranking);
|
2012-10-05 18:12:52 +00:00
|
|
|
|
|
|
|
bool submitGroup(uint32_t &token, RsPostedGroup &group);
|
|
|
|
bool submitPost(uint32_t &token, RsPostedPost &post);
|
|
|
|
bool submitVote(uint32_t &token, RsPostedVote &vote);
|
|
|
|
bool submitComment(uint32_t &token, RsPostedComment &comment) ;
|
|
|
|
// Special Ranking Request.
|
2012-12-11 22:26:11 +00:00
|
|
|
bool requestPostRankings(uint32_t &token, const RankType &rType, const RsGxsGroupId &groupId);
|
2012-11-30 18:54:25 +00:00
|
|
|
bool requestCommentRankings(uint32_t &token, const RankType &rType, const RsGxsGrpMsgIdPair &msgId);
|
|
|
|
|
2012-12-08 21:50:13 +00:00
|
|
|
bool retrieveScores(const std::string& serviceString, uint32_t& upVotes, uint32_t& downVotes, uint32_t& nComments) const;
|
|
|
|
|
2012-11-30 18:54:25 +00:00
|
|
|
private:
|
|
|
|
|
2012-12-02 19:40:17 +00:00
|
|
|
/* Functions for processing rankings */
|
|
|
|
|
2012-11-30 18:54:25 +00:00
|
|
|
void processRankings();
|
2012-12-11 22:26:11 +00:00
|
|
|
void processPostRanks();
|
2012-11-30 18:54:25 +00:00
|
|
|
void processCommentRanks();
|
|
|
|
void discardCalc(const uint32_t& token);
|
2012-12-11 22:26:11 +00:00
|
|
|
bool completePostedPostCalc(GxsPostedPostRanking* gpp);
|
2012-12-02 19:40:17 +00:00
|
|
|
void completePostedCommentRanking(GxsPostedCommentRanking* gpc);
|
2012-12-08 21:50:13 +00:00
|
|
|
|
2012-12-02 19:40:17 +00:00
|
|
|
bool storeScores(std::string& serviceString, uint32_t& upVotes, uint32_t downVotes, uint32_t nComments) const;
|
|
|
|
|
|
|
|
// for posts
|
|
|
|
void calcPostedPostRank(const std::vector<RsMsgMetaData>, PostedRanking& ranking, bool com(const PostedScore& i, const PostedScore &j)) const;
|
|
|
|
|
|
|
|
// for comments
|
|
|
|
void calcPostedCommentsRank(const std::map<RsGxsMessageId, std::vector<RsGxsMessageId> >& msgBranches, std::map<RsGxsMessageId, RsMsgMetaData>& msgMetas,
|
|
|
|
PostedRanking& ranking, bool com(const PostedScore& i, const PostedScore &j)) const;
|
|
|
|
|
|
|
|
/* Functions for maintaing vote counts in meta data */
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Update votes should only be called when a vote comes in
|
|
|
|
* Several phases to calculating votes.
|
|
|
|
* First get all messages for groups which you are subscribed
|
|
|
|
* Then for these messages get all the votes accorded to them
|
|
|
|
* Then do the calculation and update messages
|
|
|
|
* Also stores updates for messages which have new scores
|
|
|
|
*/
|
|
|
|
void updateVotes();
|
2012-12-08 21:50:13 +00:00
|
|
|
bool updateRequestGroups();
|
|
|
|
bool updateRequestMessages();
|
|
|
|
bool updateRequestVotesComments();
|
|
|
|
bool updateCompleteVotes();
|
|
|
|
bool updateCompleteComments();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* The aim of this is create notifications
|
|
|
|
* for the UI of changes to a post if their vote
|
|
|
|
* or comment count has changed
|
|
|
|
*/
|
|
|
|
bool updateComplete();
|
|
|
|
|
2012-11-30 18:54:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2012-12-02 19:40:17 +00:00
|
|
|
// for calculating ranks
|
2012-12-11 22:26:11 +00:00
|
|
|
std::vector<GxsPostedPostRanking*> mPendingPostRanks;
|
|
|
|
std::vector<GxsPostedPostRanking*> mCompletionPostRanks;
|
|
|
|
std::map<uint32_t, RsPostedPostRanking> mCompletePostRanks;
|
2012-11-30 18:54:25 +00:00
|
|
|
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCommentRanks;
|
|
|
|
std::map<uint32_t, GxsPostedCommentRanking*> mPendingCalculationCommentRanks;
|
2012-10-05 18:12:52 +00:00
|
|
|
|
2012-12-02 19:40:17 +00:00
|
|
|
// for maintaining vote counts in msg meta
|
2012-12-08 21:50:13 +00:00
|
|
|
uint32_t mUpdateRequestGroup, mUpdateRequestMessages, mUpdateRequestComments, mUpdateRequestVotes;
|
|
|
|
bool mPostUpdate;
|
2012-12-02 19:40:17 +00:00
|
|
|
uint32_t mUpdatePhase;
|
|
|
|
std::vector<RsGxsGrpMsgIdPair> mMsgsPendingUpdate;
|
2012-12-08 21:50:13 +00:00
|
|
|
time_t mLastUpdate;
|
|
|
|
GxsMsgMetaMap mMsgMetaUpdate;
|
|
|
|
std::map<RsGxsGrpMsgIdPair, PostedScore > mMsgCounts;
|
|
|
|
std::vector<uint32_t> mChangeTokens;
|
2012-12-02 19:40:17 +00:00
|
|
|
|
|
|
|
RsTokenService* mTokenService;
|
2012-11-30 18:54:25 +00:00
|
|
|
RsMutex mPostedMutex;
|
2012-12-05 22:45:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
// for data generation
|
|
|
|
|
2012-12-09 22:38:49 +00:00
|
|
|
bool mGeneratingPosts, mGeneratingTopics,
|
|
|
|
mRequestPhase1, mRequestPhase2, mRequestPhase3, mGenerateVotesAndComments;
|
2012-12-08 21:50:13 +00:00
|
|
|
std::vector<uint32_t> mTokens;
|
|
|
|
uint32_t mToken;
|
|
|
|
std::list<RsGxsGroupId> mGrpIds;
|
|
|
|
|
2012-10-05 18:12:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // P3POSTED_H
|