diff --git a/libretroshare/src/retroshare/rsforumsv2.h b/libretroshare/src/retroshare/rsforumsv2.h index 2dd29e7bc..7a6da888d 100644 --- a/libretroshare/src/retroshare/rsforumsv2.h +++ b/libretroshare/src/retroshare/rsforumsv2.h @@ -82,47 +82,12 @@ class RsForumsV2: public RsTokenService RsForumsV2() { return; } virtual ~RsForumsV2() { return; } - /* changed? */ -virtual bool updated() = 0; - - /* Data Requests */ -//virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) = 0; -//virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) = 0; -//virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &msgIds) = 0; - - /* Generic Lists */ -//virtual bool getGroupList( const uint32_t &token, std::list &groupIds) = 0; -//virtual bool getMsgList( const uint32_t &token, std::list &msgIds) = 0; - - /* Generic Summary */ -//virtual bool getGroupSummary( const uint32_t &token, std::list &groupInfo) = 0; -//virtual bool getMsgSummary( const uint32_t &token, std::list &msgInfo) = 0; - /* Specific Service Data */ virtual bool getGroupData(const uint32_t &token, RsForumV2Group &group) = 0; virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg) = 0; - - /* FUNCTIONS THAT HAVE BEEN COPIED FROM THE ORIGINAL FORUMS.... - * -> TODO, Split into generic and specific functions! - */ - ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -//virtual bool groupsChanged(std::list &groupIds) = 0; - - // Get Message Status - is retrived via MessageSummary. -//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) = 0; - - // -//virtual bool groupSubscribe(const std::string &groupId, bool subscribe) = 0; - -//virtual bool groupRestoreKeys(const std::string &groupId) = 0; -//virtual bool groupShareKeys(const std::string &groupId, std::list& peers) = 0; - - // ONES THAT WE ARE NOT IMPLEMENTING. (YET!) - //virtual bool getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status) = 0; // THINK WE CAN GENERALISE THIS TO: a list function, and you can just count the list entries... @@ -130,10 +95,9 @@ virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg) = 0; //virtual bool getMessageCount(const std::string &groupId, unsigned int &newCount, unsigned int &unreadCount) = 0; - /* details are updated in group - to choose GroupID */ -virtual bool createGroup(RsForumV2Group &group) = 0; -virtual bool createMsg(RsForumV2Msg &msg) = 0; +virtual bool createGroup(uint32_t &token, RsForumV2Group &group, bool isNew) = 0; +virtual bool createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew) = 0; }; diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index 115de483f..7df8beece 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -49,6 +49,12 @@ #define RS_TOKREQOPT_MSG_AUTHOR 0x0040 // MSGLIST: Messages from this AuthorId +// Status Filtering... should it be a different Option Field. +#define RS_TOKREQOPT_GROUP_UPDATED 0x0100 // GROUPLIST: Groups that have been updated. +#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups. +#define RS_TOKREQOPT_MSG_UPDATED 0x0200 // MSGLIST: Msg that have been updated from specified groups. + + // Read Status. #define RS_TOKREQOPT_READ 0x0001 @@ -60,27 +66,148 @@ -// TEMP FLAGS... TO FIX. -#define RSGXS_MSG_STATUS_MASK 0x000f -#define RSGXS_MSG_STATUS_READ 0x0001 -#define RSGXS_MSG_STATUS_UNREAD_BY_USER 0x0002 -#define RSGXS_MSG_STATUS_PROCESSED 0x0004 // By the Service. - - class RsTokReqOptions { public: - RsTokReqOptions() { mOptions = 0; mBefore = 0; mAfter = 0; } + RsTokReqOptions() + { + mOptions = 0; + mStatusFilter = 0; mStatusMask = 0; mSubscribeFilter = 0; + mBefore = 0; mAfter = 0; + } uint32_t mOptions; + + // Request specific matches with Group / Message Status. + // Should be usable with any Options... applied afterwards. + uint32_t mStatusFilter; + uint32_t mStatusMask; + + uint32_t mSubscribeFilter; // Only for Groups. + + // Time range... again applied after Options. time_t mBefore; time_t mAfter; }; +/********************************************************* + * Documentation for Groups Definitions. + * + * A Group is defined by: + * - TWO RSA Keys. (Admin Key & Publish Key) + * - Publish TS: Used to select the latest definition. + * + * - Operating Mode: + * - Circle (Public, External, Private). + * - Publish Mode: Encrypted / All-Signed / Only ThreadHead / None Required. + * - AuthorId: GPG Required / Any Required / Only if no Publish Signature. + * + * - Description: + * - Name & Description. + * - Optional AuthorId. + * + * Most of this information is contained inside the GroupMetaData. + * except for Actual Admin / Publish Keys, which are maintained internally. + * + ******* + * - Group Definition must be signed by Admin Key, otherwise invalid. + * - Circle Definition controls distribution of Group and Messages, see section on this for more details. + * - Public parts of Keys are distributed with Definition. + * - Private parts can be distributed to select people via alternative channels. + * - A Message Requires at least one signature: publish or Author. This signature will be used as MsgId. + * + * Groups will operate in the following modes: + * 1) Public Forum: PublishMode = None Required, AuthorId: Required. + * 2) Closed Forum: PublishMode = All-Signed, AuthorId: Required. + * 3) Private Forum: PublishMode = Encrypted, AuthorId: Required. + * + * 4) Anon Channel: PublishMode = All-Signed, AuthorId: None. + * 5) Anon Channel with Comments: PublishMode = Only ThreadHead, AuthorId: If No Publish Signature. + * 6) Private Channel: PublishMode = Encrypted. + * + * 7) Personal Photos - with comments: PublishMode = Only ThreadHead, AuthorId: Required. + * 8) Personal Photos - no comments: PublishMode = All-Signed, AuthorId: Required. + * + * 9 ) Public Wiki: PublishMode = None Required, AuthorId: Required. + * 10) Closed Wiki: PublishMode = All-Signed, AuthorId: Required. + * 11) Private Wiki: PublishMode = Encrypted, AuthorId: Required. + * + * 12) Twitter: PublishMode = Only ThreadHead, AuthorId: Required. + * + * 13) Posted: PublishMode = None Required, AuthorId: Required. + * + * + ****** + * + * Additionally to this information. The MetaData also contains several fields which can + * be used to store local information for the benefit of the service. + * + * In Particular: MsgStatus & GroupStatus inform the service if the user has read the message or if anything has changed. + * + ***/ +// Control of Publish Signatures. +#define RSGXS_GROUP_SIGN_PUBLISH_MASK 0x000000ff +#define RSGXS_GROUP_SIGN_PUBLISH_ENCRYPTED 0x00000001 +#define RSGXS_GROUP_SIGN_PUBLISH_ALLSIGNED 0x00000002 +#define RSGXS_GROUP_SIGN_PUBLISH_THREADHEAD 0x00000004 +#define RSGXS_GROUP_SIGN_PUBLISH_NONEREQ 0x00000008 + +// Author Signature. +#define RSGXS_GROUP_SIGN_AUTHOR_MASK 0x0000ff00 +#define RSGXS_GROUP_SIGN_AUTHOR_GPG 0x00000100 +#define RSGXS_GROUP_SIGN_AUTHOR_REQUIRED 0x00000200 +#define RSGXS_GROUP_SIGN_AUTHOR_IFNOPUBSIGN 0x00000400 +#define RSGXS_GROUP_SIGN_AUTHOR_NONE 0x00000800 + +// NB: That one signature is required... +// so some combinations are not possible. e.g. +// SIGN_PUBLISH_NONEREQ && SIGN_AUTHOR_NONE is not allowed. +// SIGN_PUBLISH_THREADHEAD && SIGN_AUTHOR_NONE is also invalid. + +#define RSGXS_GROUP_SIGN_RESERVED_MASK 0xffff0000 + + +// STATUS FLAGS: There is space here for Service specific flags - if they so desire. +// +// Msgs: UNREAD_BY_USER & PROCESSED are useful. +// Groups: NEW_MESSAGES & GROUP_UPDATED. + +#define RSGXS_MSG_STATUS_MASK 0x0000000f +#define RSGXS_MSG_STATUS_READ 0x00000001 // New or Not New +#define RSGXS_MSG_STATUS_UNREAD_BY_USER 0x00000002 +#define RSGXS_MSG_STATUS_UNPROCESSED 0x00000004 // By the Service. + +#define RSGXS_MSG_STATUS_SERVICE_MASK 0xffff0000 + +#define RSGXS_GROUP_STATUS_MASK 0x0000000f +#define RSGXS_GROUP_STATUS_UPDATED 0x00000001 +#define RSGXS_GROUP_STATUS_NEWGROUP 0x00000002 + +#define RSGXS_GROUP_STATUS_SERVICE_MASK 0xffff0000 + + + +// Subscription Flags. (LOCAL) +#define RSGXS_GROUP_SUBSCRIBE_MASK 0x0000000f +#define RSGXS_GROUP_SUBSCRIBE_ADMIN 0x00000001 +#define RSGXS_GROUP_SUBSCRIBE_PUBLISH 0x00000002 +#define RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED 0x00000004 +#define RSGXS_GROUP_SUBSCRIBE_MONITOR 0x00000008 + + +// Some MACROS for EASE OF USE. (USED BY FORUMSV2 At the moment. +#define IS_MSG_UNREAD(status) ((status & RSGXS_MSG_STATUS_READ) == 0 || (status & RSGXS_MSG_STATUS_UNREAD_BY_USER)) +#define IS_GROUP_ADMIN(subscribeFlags) (subscribeFlags & RSGXS_GROUP_SUBSCRIBE_ADMIN) +#define IS_GROUP_SUBSCRIBED(subscribeFlags) (subscribeFlags & (RSGXS_GROUP_SUBSCRIBE_ADMIN | RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED)) + + + +#define RSGXS_MAX_SERVICE_STRING 200 // Sensible limit for dbase usage. + class RsGroupMetaData { @@ -89,6 +216,7 @@ class RsGroupMetaData RsGroupMetaData() { mGroupFlags = 0; + mSignFlags = 0; mSubscribeFlags = 0; mPop = 0; @@ -101,10 +229,11 @@ class RsGroupMetaData std::string mGroupId; std::string mGroupName; - uint32_t mGroupFlags; + uint32_t mGroupFlags; // Service Specific Options ???? + uint32_t mSignFlags; // Combination of RSGXS_GROUP_SIGN_PUBLISH_MASK & RSGXS_GROUP_SIGN_AUTHOR_MASK. time_t mPublishTs; // Mandatory. - std::string mAuthorId; // Optional. + std::string mAuthorId; // Optional. // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. @@ -116,6 +245,7 @@ class RsGroupMetaData uint32_t mGroupStatus; + std::string mServiceString; // Service Specific Free-Form extra storage. }; @@ -145,13 +275,15 @@ class RsMsgMetaData std::string mMsgName; time_t mPublishTs; - uint32_t mMsgFlags; // Whats this for? + uint32_t mMsgFlags; // Whats this for? (Optional Service Specific - e.g. flag MsgType) // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. // normally READ / UNREAD flags. LOCAL Data. uint32_t mMsgStatus; time_t mChildTs; + std::string mServiceString; // Service Specific Free-Form extra storage. + }; std::ostream &operator<<(std::ostream &out, const RsGroupMetaData &meta); @@ -164,6 +296,9 @@ class RsTokenService RsTokenService() { return; } virtual ~RsTokenService() { return; } + /* changed? */ +virtual bool updated() = 0; + /* Data Requests */ virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) = 0; virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) = 0; @@ -190,14 +325,21 @@ virtual bool cancelRequest(const uint32_t &token) = 0; ////////////////////////////////////////////////////////////////////////////// /* Functions from Forums -> need to be implemented generically */ -virtual bool groupsChanged(std::list &groupIds) = 0; + // Groups Changed is now part of requestGroupInfo request. +//virtual bool groupsChanged(std::list &groupIds) = 0; - // Get Message Status - is retrived via MessageSummary. + // Message/Group Status - is retrived via requests... + // These operations could have a token, but for the moment we are going to assume + // they are async and always succeed - (or fail silently). virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) = 0; +virtual bool setGroupStatus(const std::string &grpId, const uint32_t status, const uint32_t statusMask) = 0; - // -virtual bool groupSubscribe(const std::string &groupId, bool subscribe) = 0; +virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) = 0; +virtual bool setMessageServiceString(const std::string &msgId, const std::string &str) = 0; +virtual bool setGroupServiceString(const std::string &grpId, const std::string &str) = 0; + + // (FUTURE WORK). virtual bool groupRestoreKeys(const std::string &groupId) = 0; virtual bool groupShareKeys(const std::string &groupId, std::list& peers) = 0; @@ -305,10 +447,6 @@ class RsIdentity: public RsTokenService virtual ~RsIdentity() { return; } - /* changed? */ -virtual bool updated() = 0; - - /* INCLUDES INTERFACE FROM RS TOKEN SERVICE */ ////////////////////////////////////////////////////////////////////////////// @@ -317,10 +455,8 @@ virtual bool updated() = 0; virtual bool getGroupData(const uint32_t &token, RsIdGroup &group) = 0; virtual bool getMsgData(const uint32_t &token, RsIdMsg &msg) = 0; -virtual bool createGroup(RsIdGroup &group) = 0; -virtual bool createMsg(RsIdMsg &msg) = 0; - - +virtual bool createGroup(uint32_t &token, RsIdGroup &group, bool isNew) = 0; +virtual bool createMsg(uint32_t &token, RsIdMsg &msg, bool isNew) = 0; /* In the Identity System - You don't access the Messages Directly. * as they represent idividuals opinions.... diff --git a/libretroshare/src/retroshare/rsphoto.h b/libretroshare/src/retroshare/rsphoto.h index 8fc78771a..15f8a4f9c 100644 --- a/libretroshare/src/retroshare/rsphoto.h +++ b/libretroshare/src/retroshare/rsphoto.h @@ -166,54 +166,12 @@ class RsPhoto: public RsTokenService RsPhoto() { return; } virtual ~RsPhoto() { return; } - /* changed? */ -virtual bool updated() = 0; - - /* Data Requests */ -//virtual bool requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) = 0; -//virtual bool requestMsgInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) = 0; -//virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &msgIds) = 0; - - /* Generic Lists */ -//virtual bool getGroupList( const uint32_t &token, std::list &groupIds) = 0; -//virtual bool getMsgList( const uint32_t &token, std::list &msgIds) = 0; - - /* Generic Summary */ -//virtual bool getGroupSummary( const uint32_t &token, std::list &groupInfo) = 0; -//virtual bool getMsgSummary( const uint32_t &token, std::list &msgInfo) = 0; - - /* Actual Data -> specific to Interface */ - - - - /* Poll */ -//virtual uint32_t requestStatus(const uint32_t token) = 0; - - /* Cancel Request */ -//virtual bool cancelRequest(const uint32_t &token) = 0; - - - ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -//virtual bool groupsChanged(std::list &groupIds) = 0; - - // Get Message Status - is retrived via MessageSummary. -//virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) = 0; - - // -//virtual bool groupSubscribe(const std::string &groupId, bool subscribe) = 0; - -//virtual bool groupRestoreKeys(const std::string &groupId) = 0; -//virtual bool groupShareKeys(const std::string &groupId, std::list& peers) = 0; - - /* Specific Service Data */ virtual bool getAlbum(const uint32_t &token, RsPhotoAlbum &album) = 0; virtual bool getPhoto(const uint32_t &token, RsPhotoPhoto &photo) = 0; -/* details are updated in album - to choose Album ID, and storage path */ -virtual bool submitAlbumDetails(RsPhotoAlbum &album, bool isNew) = 0; -virtual bool submitPhoto(RsPhotoPhoto &photo, bool isNew) = 0; +virtual bool submitAlbumDetails(uint32_t &token, RsPhotoAlbum &album, bool isNew) = 0; +virtual bool submitPhoto(uint32_t &token, RsPhotoPhoto &photo, bool isNew) = 0; }; diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 7bbe1fed8..22dfaed3f 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -53,29 +53,52 @@ class RsPostedMsg uint32_t postedType; }; -#define RSPOSTED_MSG_POST 1 -#define RSPOSTED_MSG_VOTE 1 -#define RSPOSTED_MSG_COMMENT 1 +#define RSPOSTED_MSGTYPE_POST 0x0001 +#define RSPOSTED_MSGTYPE_VOTE 0x0002 +#define RSPOSTED_MSGTYPE_COMMENT 0x0004 + +#define RSPOSTED_PERIOD_YEAR 1 +#define RSPOSTED_PERIOD_MONTH 2 +#define RSPOSTED_PERIOD_WEEK 3 +#define RSPOSTED_PERIOD_DAY 4 +#define RSPOSTED_PERIOD_HOUR 5 + +#define RSPOSTED_VIEWMODE_LATEST 1 +#define RSPOSTED_VIEWMODE_TOP 2 +#define RSPOSTED_VIEWMODE_HOT 3 +#define RSPOSTED_VIEWMODE_COMMENTS 4 class RsPostedPost: public RsPostedMsg { public: - RsPostedPost(): RsPostedMsg(RSPOSTED_MSG_POST) { return; } + RsPostedPost(): RsPostedMsg(RSPOSTED_MSGTYPE_POST) + { + mMeta.mMsgFlags = RSPOSTED_MSGTYPE_POST; + return; + } }; class RsPostedVote: public RsPostedMsg { public: - RsPostedVote(): RsPostedMsg(RSPOSTED_MSG_VOTE) { return; } + RsPostedVote(): RsPostedMsg(RSPOSTED_MSGTYPE_VOTE) + { + mMeta.mMsgFlags = RSPOSTED_MSGTYPE_VOTE; + return; + } }; class RsPostedComment: public RsPostedMsg { public: - RsPostedComment(): RsPostedMsg(RSPOSTED_MSG_COMMENT) { return; } + RsPostedComment(): RsPostedMsg(RSPOSTED_MSGTYPE_COMMENT) + { + mMeta.mMsgFlags = RSPOSTED_MSGTYPE_COMMENT; + return; + } }; @@ -92,19 +115,15 @@ class RsPosted: public RsTokenService RsPosted() { return; } virtual ~RsPosted() { return; } - /* changed? */ -virtual bool updated() = 0; - /* Specific Service Data */ virtual bool getGroup(const uint32_t &token, RsPostedGroup &group) = 0; virtual bool getPost(const uint32_t &token, RsPostedPost &post) = 0; virtual bool getComment(const uint32_t &token, RsPostedComment &comment) = 0; -/* details are updated in album - to choose Album ID, and storage path */ -virtual bool submitGroup(RsPostedGroup &group, bool isNew) = 0; -virtual bool submitPost(RsPostedPost &post, bool isNew) = 0; -virtual bool submitVote(RsPostedVote &vote, bool isNew) = 0; -virtual bool submitComment(RsPostedComment &comment, bool isNew) = 0; +virtual bool submitGroup(uint32_t &token, RsPostedGroup &group, bool isNew) = 0; +virtual bool submitPost(uint32_t &token, RsPostedPost &post, bool isNew) = 0; +virtual bool submitVote(uint32_t &token, RsPostedVote &vote, bool isNew) = 0; +virtual bool submitComment(uint32_t &token, RsPostedComment &comment, bool isNew) = 0; }; diff --git a/libretroshare/src/retroshare/rswiki.h b/libretroshare/src/retroshare/rswiki.h index 4062e8e84..5d4d98e1c 100644 --- a/libretroshare/src/retroshare/rswiki.h +++ b/libretroshare/src/retroshare/rswiki.h @@ -91,42 +91,12 @@ class RsWiki: public RsTokenService RsWiki() { return; } virtual ~RsWiki() { return; } - /* changed? */ -virtual bool updated() = 0; - - /* Data Requests (from RsTokenService) */ -//virtual bool requestGroupList( uint32_t &token, const RsTokReqOptions &opts) = 0; -//virtual bool requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds) = 0; -//virtual bool requestMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds) = 0; - -//virtual bool requestGroupData( uint32_t &token, const std::list &groupIds) = 0; -//virtual bool requestMsgData( uint32_t &token, const std::list &msgIds) = 0; - - /* Poll */ -//virtual uint32_t requestStatus(const uint32_t token) = 0; - - /* Generic List Data */ -virtual bool getGroupList(const uint32_t &token, std::list &groupIds) = 0; -virtual bool getMsgList(const uint32_t &token, std::list &msgIds) = 0; - /* Specific Service Data */ virtual bool getGroupData(const uint32_t &token, RsWikiGroup &group) = 0; virtual bool getMsgData(const uint32_t &token, RsWikiPage &page) = 0; - - -/* details are updated in group - to choose GroupID */ -virtual bool createGroup(RsWikiGroup &group) = 0; -virtual bool createPage(RsWikiPage &page) = 0; - -#if 0 -virtual bool getGroupList(std::list &groups) = 0; -virtual bool getGroup(const std::string &groupid, RsWikiGroup &group) = 0; -virtual bool getPage(const std::string &pageid, RsWikiPage &page) = 0; -virtual bool getPageVersions(const std::string &origPageId, std::list &pages) = 0; -virtual bool getOrigPageList(const std::string &groupid, std::list &pageIds) = 0; -virtual bool getLatestPage(const std::string &origPageId, std::string &pageId) = 0; -#endif +virtual bool createGroup(uint32_t &token, RsWikiGroup &group, bool isNew) = 0; +virtual bool createPage(uint32_t &token, RsWikiPage &page, bool isNew) = 0; }; diff --git a/libretroshare/src/retroshare/rswire.h b/libretroshare/src/retroshare/rswire.h index 406b13f68..0a5e1fda4 100644 --- a/libretroshare/src/retroshare/rswire.h +++ b/libretroshare/src/retroshare/rswire.h @@ -88,16 +88,13 @@ class RsWire: public RsTokenService RsWire() { return; } virtual ~RsWire() { return; } - /* changed? */ -virtual bool updated() = 0; - /* Specific Service Data */ virtual bool getGroupData(const uint32_t &token, RsWireGroup &group) = 0; virtual bool getMsgData(const uint32_t &token, RsWirePulse &pulse) = 0; /* Create Stuff */ -virtual bool createGroup(RsWireGroup &group) = 0; -virtual bool createPulse(RsWirePulse &pulse) = 0; +virtual bool createGroup(uint32_t &token, RsWireGroup &group, bool isNew) = 0; +virtual bool createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew) = 0; }; diff --git a/libretroshare/src/services/p3forumsv2.cc b/libretroshare/src/services/p3forumsv2.cc index 16f9f23c3..837e21709 100644 --- a/libretroshare/src/services/p3forumsv2.cc +++ b/libretroshare/src/services/p3forumsv2.cc @@ -354,25 +354,33 @@ bool p3ForumsV2::cancelRequest(const uint32_t &token) } ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -bool p3ForumsV2::groupsChanged(std::list &groupIds) -{ - return false; -} - // Get Message Status - is retrived via MessageSummary. bool p3ForumsV2::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) { - return false; + return mForumProxy->setMessageStatus(msgId, status, statusMask); } - - // -bool p3ForumsV2::groupSubscribe(const std::string &groupId, bool subscribe) +bool p3ForumsV2::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) { - return false; + return mForumProxy->setGroupStatus(groupId, status, statusMask); } +bool p3ForumsV2::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) +{ + return mForumProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); +} + +bool p3ForumsV2::setMessageServiceString(const std::string &msgId, const std::string &str) +{ + return mForumProxy->setMessageServiceString(msgId, str); +} + +bool p3ForumsV2::setGroupServiceString(const std::string &grpId, const std::string &str) +{ + return mForumProxy->setGroupServiceString(grpId, str); +} + + bool p3ForumsV2::groupRestoreKeys(const std::string &groupId) { @@ -384,20 +392,6 @@ bool p3ForumsV2::groupShareKeys(const std::string &groupId, std::listaddForumGroup(group); + } + + // Fake a request to return the GroupMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list groupIds; + groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. + + std::cerr << "p3ForumsV2::createGroup() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - - mForumProxy->addForumGroup(group); - return true; } -bool p3ForumsV2::createMsg(RsForumV2Msg &msg) +bool p3ForumsV2::createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew) { if (msg.mMeta.mGroupId.empty()) { @@ -479,11 +484,22 @@ bool p3ForumsV2::createMsg(RsForumV2Msg &msg) std::cerr << "p3ForumsV2::createForumMsg() OrigMsgId: " << msg.mMeta.mOrigMsgId; std::cerr << std::endl; - RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mForumMtx); /********** STACK LOCKED MTX ******/ - mUpdated = true; - - mForumProxy->addForumMsg(msg); + mUpdated = true; + mForumProxy->addForumMsg(msg); + } + + // Fake a request to return the MsgMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list msgIds; + msgIds.push_back(msg.mMeta.mMsgId); // It will just return this one. + + std::cerr << "p3ForumsV2::createMsg() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); return true; } @@ -640,12 +656,12 @@ bool p3ForumsV2::generateDummyData() float rnd = RSRandom::random_f32(); if (rnd < 0.1) { - forum.mMeta.mSubscribeFlags = RS_DISTRIB_ADMIN; + forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN; } else if (rnd < 0.3) { - forum.mMeta.mSubscribeFlags = RS_DISTRIB_SUBSCRIBED; + forum.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED; } else { diff --git a/libretroshare/src/services/p3forumsv2.h b/libretroshare/src/services/p3forumsv2.h index 2aeff0f49..f6c8d627f 100644 --- a/libretroshare/src/services/p3forumsv2.h +++ b/libretroshare/src/services/p3forumsv2.h @@ -34,17 +34,6 @@ #include /* - * Wiki Service - * - * This is an example service for the new cache system. - * For the moment, it will only hold data passed to it from the GUI. - * and spew that back when asked.... - * - * We are doing it like this - so we can check the required interface functionality. - * - * Expect it won't take long before it'll be properly linked into the backend! - * - * This will be transformed into a Plugin Service, once the basics have been worked out. * */ @@ -107,22 +96,17 @@ virtual uint32_t requestStatus(const uint32_t token); virtual bool cancelRequest(const uint32_t &token); ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -virtual bool groupsChanged(std::list &groupIds); - - // Get Message Status - is retrived via MessageSummary. virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); - - // -virtual bool groupSubscribe(const std::string &groupId, bool subscribe); +virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); +virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); +virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); +virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); virtual bool groupRestoreKeys(const std::string &groupId); virtual bool groupShareKeys(const std::string &groupId, std::list& peers); - -virtual bool createGroup(RsForumV2Group &group); -virtual bool createMsg(RsForumV2Msg &msg); - +virtual bool createGroup(uint32_t &token, RsForumV2Group &group, bool isNew); +virtual bool createMsg(uint32_t &token, RsForumV2Msg &msg, bool isNew); private: @@ -137,73 +121,6 @@ bool generateDummyData(); bool mUpdated; - - - -#if 0 - - /* Data Requests */ -virtual bool requestGroupList( uint32_t &token, const RsTokReqOptions &opts); -virtual bool requestMsgList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds); -virtual bool requestMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds); - -virtual bool requestGroupData( uint32_t &token, const std::list &groupIds); -virtual bool requestMsgData( uint32_t &token, const std::list &msgIds); - -virtual bool getGroupList(const uint32_t &token, std::list &groupIds); -virtual bool getMsgList(const uint32_t &token, std::list &msgIds); - -virtual bool getGroupData(const uint32_t &token, RsForumV2Group &group); -virtual bool getMsgData(const uint32_t &token, RsForumV2Msg &msg); - - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token); - -virtual bool createGroup(RsForumV2Group &group); -virtual bool createPage(RsForumV2Msg &msg); - - -/************* Old Extern Interface *******/ - -virtual bool updated(); -virtual bool getGroupList(std::list &group); - -virtual bool getGroup(const std::string &groupid, RsWikiGroup &group); -virtual bool getPage(const std::string &pageid, RsWikiPage &page); -virtual bool getPageVersions(const std::string &origPageId, std::list &pages); -virtual bool getOrigPageList(const std::string &groupid, std::list &pageIds); -virtual bool getLatestPage(const std::string &origPageId, std::string &page); - -virtual bool createGroup(RsWikiGroup &group); -virtual bool createPage(RsWikiPage &page); - - - private: - -virtual bool InternalgetGroupList(std::list &group); -virtual bool InternalgetGroup(const std::string &groupid, RsForumV2Group &group); -virtual bool InternalgetPage(const std::string &pageid, RsForumV2Msg &msg); -virtual bool InternalgetPageVersions(const std::string &origPageId, std::list &pages); -virtual bool InternalgetOrigPageList(const std::string &groupid, std::list &pageIds); -virtual bool InternalgetLatestPage(const std::string &origPageId, std::string &page); - -std::string genRandomId(); - - ForumDataProxy *mForumProxy; - - RsMutex mForumMtx; - - /***** below here is locked *****/ - - bool mUpdated; - - std::map > mGroupToOrigPages; - std::map > mOrigToPageVersions; - std::map mOrigPageToLatestPage; - std::map mGroups; - std::map mPages; -#endif - }; #endif diff --git a/libretroshare/src/services/p3gxsservice.cc b/libretroshare/src/services/p3gxsservice.cc index bfc116d97..0731546ca 100644 --- a/libretroshare/src/services/p3gxsservice.cc +++ b/libretroshare/src/services/p3gxsservice.cc @@ -341,6 +341,141 @@ GxsDataProxy::GxsDataProxy() } +static bool checkGroupFilter(const RsTokReqOptions &opts, const RsGroupMetaData &group) +{ + bool statusMatch = false; + if (opts.mStatusMask) + { + // Exact Flags match required. + if ((opts.mStatusMask & opts.mStatusFilter) == (opts.mStatusMask & group.mGroupStatus)) + { + statusMatch = true; + } + else + { + std::cerr << "checkGroupFilter() Dropping Group due to !StatusMatch "; + std::cerr << " Mask: " << opts.mStatusMask << " StatusFilter: " << opts.mStatusFilter; + std::cerr << " GroupStatus: " << group.mGroupStatus << " GroupId: " << group.mGroupId; + std::cerr << std::endl; + } + } + else + { + // no status comparision, + statusMatch = true; + } + + bool subMatch = false; + if (opts.mSubscribeFilter) + { + // Exact Flags match required. + if (opts.mSubscribeFilter & group.mSubscribeFlags) + { + subMatch = true; + } + else + { + std::cerr << "checkGroupFilter() Dropping Group due to !SubscribeMatch "; + std::cerr << " SubscribeFilter: " << opts.mSubscribeFilter; + std::cerr << " GroupSubscribeFlags: " << group.mSubscribeFlags << " GroupId: " << group.mGroupId; + std::cerr << std::endl; + } + } + else + { + // no subscribe comparision, + subMatch = true; + } + + return (statusMatch && subMatch); +} + + +static bool checkMsgFilter(const RsTokReqOptions &opts, const RsMsgMetaData &msg) +{ + bool statusMatch = false; + if (opts.mStatusMask) + { + // Exact Flags match required. + if ((opts.mStatusMask & opts.mStatusFilter) == (opts.mStatusMask & msg.mMsgStatus)) + { + statusMatch = true; + } + else + { + std::cerr << "checkMsgFilter() Dropping Msg due to !StatusMatch "; + std::cerr << " Mask: " << opts.mStatusMask << " StatusFilter: " << opts.mStatusFilter; + std::cerr << " MsgStatus: " << msg.mMsgStatus << " MsgId: " << msg.mMsgId; + std::cerr << std::endl; + } + } + else + { + // no status comparision, + statusMatch = true; + } + return statusMatch; +} + + +bool GxsDataProxy::filterGroupList(const RsTokReqOptions &opts, std::list &groupIds) +{ + std::list::iterator it; + for(it = groupIds.begin(); it != groupIds.end(); ) + { + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + bool keep = false; + /* find group */ + std::map::iterator mit; + mit = mGroupMetaData.find(*it); + if (mit != mGroupMetaData.end()) + { + keep = checkGroupFilter(opts, mit->second); + } + + if (keep) + { + it++; + } + else + { + it = groupIds.erase(it); + } + } + return true; +} + + +bool GxsDataProxy::filterMsgList(const RsTokReqOptions &opts, std::list &msgIds) +{ + std::list::iterator it; + for(it = msgIds.begin(); it != msgIds.end(); ) + { + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + bool keep = false; + /* find msg */ + std::map::iterator mit; + mit = mMsgMetaData.find(*it); + if (mit != mMsgMetaData.end()) + { + keep = checkMsgFilter(opts, mit->second); + } + + if (keep) + { + it++; + } + else + { + it = msgIds.erase(it); + } + } + return true; +} + + bool GxsDataProxy::getGroupList( uint32_t &token, const RsTokReqOptions &opts, const std::list &groupIds, std::list &outGroupIds) { @@ -368,6 +503,8 @@ bool GxsDataProxy::getGroupList( uint32_t &token, const RsTokReqOptions &opt outGroupIds = groupIds; } + filterGroupList(opts, outGroupIds); + return true; } @@ -415,9 +552,11 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt { if (onlyLatestMsgs) // THIS ONE IS HARD -> LOTS OF COMP. { + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + // RUN THROUGH ALL MSGS... in map origId -> TS. - std::map > origMsgTs; - std::map >::iterator oit; + std::map > origMsgTs; + std::map >::iterator oit; for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++) { if (mit->second.mGroupId != *it) @@ -474,6 +613,8 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt } else // ALL OTHER CASES. { + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++) { if (mit->second.mGroupId == *it) @@ -510,6 +651,9 @@ bool GxsDataProxy::getMsgList( uint32_t &token, const RsTokReqOptions &opt } } } + + filterMsgList(opts, outMsgIds); + return true; } @@ -573,6 +717,7 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt std::cerr << std::endl; /* just copy */ outMsgIds = msgIds; + filterMsgList(opts, outMsgIds); return true; } @@ -582,6 +727,8 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt for(it = msgIds.begin(); it != msgIds.end(); it++) { + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + /* getOriginal Message */ mit = mMsgMetaData.find(*it); if (mit == mMsgMetaData.end()) @@ -596,8 +743,8 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt if (onlyChildMsgs) { // RUN THROUGH ALL MSGS... in map origId -> TS. - std::map > origMsgTs; - std::map >::iterator oit; + std::map > origMsgTs; + std::map >::iterator oit; for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++) { // skip msgs that aren't children. @@ -665,6 +812,8 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt } else if (onlyAllVersions) { + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + for(mit = mMsgMetaData.begin(); mit != mMsgMetaData.end(); mit++) { if (mit->second.mOrigMsgId == origMsgId) @@ -675,6 +824,8 @@ bool GxsDataProxy::getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opt } } + filterMsgList(opts, outMsgIds); + return true; } @@ -693,6 +844,11 @@ bool GxsDataProxy::createGroup(void *groupData) RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + /* Set the Group Status Flags */ + meta.mGroupStatus |= (RSGXS_GROUP_STATUS_UPDATED | RSGXS_GROUP_STATUS_NEWGROUP); + + /* push into maps */ mGroupData[meta.mGroupId] = groupData; mGroupMetaData[meta.mGroupId] = meta; @@ -720,6 +876,25 @@ bool GxsDataProxy::createMsg(void *msgData) RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + /* find the group */ + std::map::iterator git; + git = mGroupMetaData.find(meta.mGroupId); + if (git == mGroupMetaData.end()) + { + std::cerr << "GxsDataProxy::createMsg() ERROR GroupId Doesn't exist, discarding"; + std::cerr << std::endl; + return false; + } + + /* flag the group as changed */ + git->second.mGroupStatus |= RSGXS_GROUP_STATUS_UPDATED; + + /* Set the Msg Status Flags */ + meta.mMsgStatus |= (RSGXS_MSG_STATUS_UNREAD_BY_USER | RSGXS_MSG_STATUS_UNPROCESSED); + + /* Set the Msg->GroupId Status Flags */ + /* push into maps */ mMsgData[meta.mMsgId] = msgData; mMsgMetaData[meta.mMsgId] = meta; @@ -733,6 +908,124 @@ bool GxsDataProxy::createMsg(void *msgData) } + // Get Message Status - is retrived via MessageSummary. +bool GxsDataProxy::setMessageStatus(const std::string &msgId,const uint32_t status, const uint32_t statusMask) +{ + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + std::map::iterator mit; + mit = mMsgMetaData.find(msgId); + + if (mit == mMsgMetaData.end()) + { + // error. + std::cerr << "GxsDataProxy::getMsgSummary() Error Finding MsgId: " << msgId; + std::cerr << std::endl; + } + else + { + /* tweak status */ + mit->second.mMsgStatus &= ~statusMask; + mit->second.mMsgStatus |= (status & statusMask); + } + + // always return true - as this is supposed to be async operation. + return true; +} + +bool GxsDataProxy::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) +{ + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + std::map::iterator git; + git = mGroupMetaData.find(groupId); + + if (git == mGroupMetaData.end()) + { + // error. + std::cerr << "GxsDataProxy::setGroupStatus() Error Finding GroupId: " << groupId; + std::cerr << std::endl; + } + else + { + /* tweak status */ + git->second.mGroupStatus &= ~statusMask; + git->second.mGroupStatus |= (status & statusMask); + } + + // always return true - as this is supposed to be async operation. + return true; +} + + +bool GxsDataProxy::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) +{ + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + std::map::iterator git; + git = mGroupMetaData.find(groupId); + + if (git == mGroupMetaData.end()) + { + // error. + std::cerr << "GxsDataProxy::setGroupSubscribeFlags() Error Finding GroupId: " << groupId; + std::cerr << std::endl; + } + else + { + /* tweak subscribe Flags */ + git->second.mSubscribeFlags &= ~subscribeMask; + git->second.mSubscribeFlags |= (subscribeFlags & subscribeMask); + } + + // always return true - as this is supposed to be async operation. + return true; +} + +bool GxsDataProxy::setMessageServiceString(const std::string &msgId, const std::string &str) +{ + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + std::map::iterator mit; + mit = mMsgMetaData.find(msgId); + + if (mit == mMsgMetaData.end()) + { + // error. + std::cerr << "GxsDataProxy::setMessageServiceString() Error Finding MsgId: " << msgId; + std::cerr << std::endl; + } + else + { + mit->second.mServiceString = str; + } + + // always return true - as this is supposed to be async operation. + return true; +} + +bool GxsDataProxy::setGroupServiceString(const std::string &groupId, const std::string &str) +{ + RsStackMutex stack(mDataMtx); /***** LOCKED *****/ + + std::map::iterator git; + git = mGroupMetaData.find(groupId); + + if (git == mGroupMetaData.end()) + { + // error. + std::cerr << "GxsDataProxy::setGroupServiceString() Error Finding GroupId: " << groupId; + std::cerr << std::endl; + } + else + { + git->second.mServiceString = str; + } + + // always return true - as this is supposed to be async operation. + return true; +} + /* These Functions must be overloaded to complete the service */ bool GxsDataProxy::convertGroupToMetaData(void *groupData, RsGroupMetaData &meta) diff --git a/libretroshare/src/services/p3gxsservice.h b/libretroshare/src/services/p3gxsservice.h index b2b4f45f4..e1580aeef 100644 --- a/libretroshare/src/services/p3gxsservice.h +++ b/libretroshare/src/services/p3gxsservice.h @@ -114,6 +114,10 @@ virtual bool getMsgList( uint32_t &token, const RsTokReqOptions &opts, con virtual bool getMsgRelatedList(uint32_t &token, const RsTokReqOptions &opts, const std::list &msgIds, std::list &outMsgIds); + /* This functions return a token - which can be used to retrieve the RsGroupMetaData, later + * This is required, as signatures and keys might have to be generated in the background + * Though at the moment: for this test system it won't change anything? FIXME. + */ virtual bool createGroup(void *groupData); virtual bool createMsg(void *msgData); @@ -137,6 +141,26 @@ virtual bool convertMsgToMetaData(void *groupData, RsMsgMetaData &meta); bool isUniqueMsg(const std::string &msgId); + /* Handle Status & Subscribe Modes */ +// This is removed as redundant - use getGroupList - with OptFlags to find these. +//virtual bool requestGroupsChanged(uint32_t &token); //std::list &groupIds); + + // Get Message Status - is retrived via MessageSummary. + // These operations could have a token, but for the moment we are going to assume + // they are async and always succeed - (or fail silently). +virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); +virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); +virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); + +virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); +virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); + + protected: + + bool filterGroupList(const RsTokReqOptions &opts, std::list &groupIds); + bool filterMsgList(const RsTokReqOptions &opts, std::list &msgIds); + + RsMutex mDataMtx; std::map mGroupData; diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index d54bfae4d..bb39c80a6 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -354,23 +354,29 @@ bool p3IdService::cancelRequest(const uint32_t &token) } ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -bool p3IdService::groupsChanged(std::list &groupIds) -{ - return false; -} - - // Get Message Status - is retrived via MessageSummary. bool p3IdService::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) { - return false; + return mIdProxy->setMessageStatus(msgId, status, statusMask); } - - // -bool p3IdService::groupSubscribe(const std::string &groupId, bool subscribe) +bool p3IdService::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) { - return false; + return mIdProxy->setGroupStatus(groupId, status, statusMask); +} + +bool p3IdService::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) +{ + return mIdProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); +} + +bool p3IdService::setMessageServiceString(const std::string &msgId, const std::string &str) +{ + return mIdProxy->setMessageServiceString(msgId, str); +} + +bool p3IdService::setGroupServiceString(const std::string &grpId, const std::string &str) +{ + return mIdProxy->setGroupServiceString(grpId, str); } @@ -399,7 +405,7 @@ std::string p3IdService::genRandomId() return randomId; } -bool p3IdService::createGroup(RsIdGroup &group) +bool p3IdService::createGroup(uint32_t &token, RsIdGroup &group, bool isNew) { if (group.mMeta.mGroupId.empty()) { @@ -414,12 +420,24 @@ bool p3IdService::createGroup(RsIdGroup &group) std::cerr << std::endl; return false; } + + { + RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ + + mUpdated = true; + mIdProxy->addGroup(group); + } + + // Fake a request to return the GroupMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list groupIds; + groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. + + std::cerr << "p3IdService::createGroup() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - - mIdProxy->addGroup(group); return true; } @@ -427,7 +445,7 @@ bool p3IdService::createGroup(RsIdGroup &group) -bool p3IdService::createMsg(RsIdMsg &msg) +bool p3IdService::createMsg(uint32_t &token, RsIdMsg &msg, bool isNew) { if (msg.mMeta.mGroupId.empty()) { @@ -463,11 +481,22 @@ bool p3IdService::createMsg(RsIdMsg &msg) std::cerr << "p3IdService::createMsg() OrigMsgId: " << msg.mMeta.mOrigMsgId; std::cerr << std::endl; - RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/ - mUpdated = true; - - mIdProxy->addMsg(msg); + mUpdated = true; + mIdProxy->addMsg(msg); + } + + // Fake a request to return the MsgMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list msgIds; + msgIds.push_back(msg.mMeta.mMsgId); // It will just return this one. + + std::cerr << "p3IdService::createMsg() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); return true; } diff --git a/libretroshare/src/services/p3idservice.h b/libretroshare/src/services/p3idservice.h index d627e319e..30e791abc 100644 --- a/libretroshare/src/services/p3idservice.h +++ b/libretroshare/src/services/p3idservice.h @@ -84,6 +84,8 @@ virtual bool getGroupSummary( const uint32_t &token, std::list &msgInfo); /* Actual Data -> specific to Interface */ +virtual bool getGroupData(const uint32_t &token, RsIdGroup &group); +virtual bool getMsgData(const uint32_t &token, RsIdMsg &msg); /* Poll */ virtual uint32_t requestStatus(const uint32_t token); @@ -91,70 +93,24 @@ virtual uint32_t requestStatus(const uint32_t token); /* Cancel Request */ virtual bool cancelRequest(const uint32_t &token); - - /* Functions from Forums -> need to be implemented generically */ -virtual bool groupsChanged(std::list &groupIds); - - // Get Message Status - is retrived via MessageSummary. + ////////////////////////////////////////////////////////////////////////////// virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); - - // -virtual bool groupSubscribe(const std::string &groupId, bool subscribe) ; +virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); +virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); +virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); +virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); virtual bool groupRestoreKeys(const std::string &groupId); virtual bool groupShareKeys(const std::string &groupId, std::list& peers); - ////////////////////////////////////////////////////////////////////////////// +virtual bool createGroup(uint32_t &token, RsIdGroup &group, bool isNew); +virtual bool createMsg(uint32_t &token, RsIdMsg &msg, bool isNew); - /* Specific Service Data */ -virtual bool getGroupData(const uint32_t &token, RsIdGroup &group); -virtual bool getMsgData(const uint32_t &token, RsIdMsg &msg); - -virtual bool createGroup(RsIdGroup &group); -virtual bool createMsg(RsIdMsg &msg); - - /* Interface now a request / poll / answer system */ - -#if 0 - - /* Data Requests */ -virtual bool requestIdentityList(uint32_t &token); -virtual bool requestIdentities(uint32_t &token, const std::list &ids); -virtual bool requestIdReputations(uint32_t &token, const std::list &ids); -virtual bool requestIdPeerOpinion(uint32_t &token, const std::string &aboutId, const std::string &peerId); -//virtual bool requestIdGpgDetails(uint32_t &token, const std::list &ids); - - /* Poll */ -virtual uint32_t requestStatus(const uint32_t token); - - /* Retrieve Data */ -virtual bool getIdentityList(const uint32_t token, std::list &ids); -virtual bool getIdentity(const uint32_t token, RsIdData &data); -virtual bool getIdReputation(const uint32_t token, RsIdReputation &reputation); -virtual bool getIdPeerOpinion(const uint32_t token, RsIdOpinion &opinion); -//virtual bool getIdGpgDetails(const uint32_t token, RsIdGpgDetails &gpgData); - - /* Updates */ -virtual bool updateIdentity(RsIdData &data); -virtual bool updateOpinion(RsIdOpinion &opinion); - - - - /* below here not part of the interface */ -bool fakeprocessrequests(); - -virtual bool InternalgetIdentityList(std::list &ids); -virtual bool InternalgetIdentity(const std::string &id, RsIdData &data); -virtual bool InternalgetIdReputation(const std::string &id, RsIdReputation &reputation); -virtual bool InternalgetIdPeerOpinion(const std::string &aboutid, const std::string &peerid, RsIdOpinion &opinion); - -#endif - -virtual void generateDummyData(); - private: +virtual void generateDummyData(); + std::string genRandomId(); IdDataProxy *mIdProxy; diff --git a/libretroshare/src/services/p3photoservice.cc b/libretroshare/src/services/p3photoservice.cc index 19624c027..e1dd0a50d 100644 --- a/libretroshare/src/services/p3photoservice.cc +++ b/libretroshare/src/services/p3photoservice.cc @@ -57,10 +57,10 @@ int p3PhotoService::tick() return 0; } -bool p3PhotoService::updated() +bool p3PhotoService::updated() { RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - + if (mUpdated) { mUpdated = false; @@ -70,7 +70,6 @@ bool p3PhotoService::updated() } - /* Data Requests */ bool p3PhotoService::requestGroupInfo( uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) { @@ -351,24 +350,30 @@ bool p3PhotoService::cancelRequest(const uint32_t &token) return clearRequest(token); } - ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -bool p3PhotoService::groupsChanged(std::list &groupIds) -{ - return false; -} - // Get Message Status - is retrived via MessageSummary. bool p3PhotoService::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) { - return false; + return mPhotoProxy->setMessageStatus(msgId, status, statusMask); } - - // -bool p3PhotoService::groupSubscribe(const std::string &groupId, bool subscribe) +bool p3PhotoService::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) { - return false; + return mPhotoProxy->setGroupStatus(groupId, status, statusMask); +} + +bool p3PhotoService::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) +{ + return mPhotoProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); +} + +bool p3PhotoService::setMessageServiceString(const std::string &msgId, const std::string &str) +{ + return mPhotoProxy->setMessageServiceString(msgId, str); +} + +bool p3PhotoService::setGroupServiceString(const std::string &grpId, const std::string &str) +{ + return mPhotoProxy->setGroupServiceString(grpId, str); } @@ -384,7 +389,8 @@ bool p3PhotoService::groupShareKeys(const std::string &groupId, std::listaddAlbum(album); + /* add / modify */ + mPhotoProxy->addAlbum(album); + } + + // Fake a request to return the GroupMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list groupIds; + groupIds.push_back(album.mMeta.mGroupId); // It will just return this one. + + std::cerr << "p3PhotoService::submitAlbumDetails() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); return true; } - -bool p3PhotoService::submitPhoto(RsPhotoPhoto &photo, bool isNew) +bool p3PhotoService::submitPhoto(uint32_t &token, RsPhotoPhoto &photo, bool isNew) { if (photo.mMeta.mGroupId.empty()) { @@ -450,11 +467,22 @@ bool p3PhotoService::submitPhoto(RsPhotoPhoto &photo, bool isNew) std::cerr << " MsgId: " << photo.mMeta.mMsgId; std::cerr << std::endl; - RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mPhotoMtx); /********** STACK LOCKED MTX ******/ - mUpdated = true; + mUpdated = true; + mPhotoProxy->addPhoto(photo); + } - mPhotoProxy->addPhoto(photo); + // Fake a request to return the MsgMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list msgIds; + msgIds.push_back(photo.mMeta.mMsgId); // It will just return this one. + + std::cerr << "p3PhotoService::submitPhoto() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); return true; } @@ -612,6 +640,7 @@ bool RsPhotoThumbnail::deleteImage() data = NULL; size = 0; } + return true; } diff --git a/libretroshare/src/services/p3photoservice.h b/libretroshare/src/services/p3photoservice.h index f51e39e99..16e4f2cc5 100644 --- a/libretroshare/src/services/p3photoservice.h +++ b/libretroshare/src/services/p3photoservice.h @@ -79,6 +79,7 @@ virtual int tick(); // NEW INTERFACE. /************* Extern Interface *******/ + /* changed? */ virtual bool updated(); /* Data Requests */ @@ -106,22 +107,19 @@ virtual uint32_t requestStatus(const uint32_t token); virtual bool cancelRequest(const uint32_t &token); ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -virtual bool groupsChanged(std::list &groupIds); - - // Get Message Status - is retrived via MessageSummary. virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); - - // -virtual bool groupSubscribe(const std::string &groupId, bool subscribe); +virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); +virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); +virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); +virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); virtual bool groupRestoreKeys(const std::string &groupId); virtual bool groupShareKeys(const std::string &groupId, std::list& peers); /* details are updated in album - to choose Album ID, and storage path */ -virtual bool submitAlbumDetails(RsPhotoAlbum &album, bool isNew); -virtual bool submitPhoto(RsPhotoPhoto &photo, bool isNew); +virtual bool submitAlbumDetails(uint32_t &token, RsPhotoAlbum &album, bool isNew); +virtual bool submitPhoto(uint32_t &token, RsPhotoPhoto &photo, bool isNew); diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index 0c51e5030..f7ff1d89f 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -27,6 +27,7 @@ #include "util/rsrandom.h" #include #include +#include /**** * #define POSTED_DEBUG 1 @@ -46,12 +47,29 @@ p3PostedService::p3PostedService(uint16_t type) RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ mPostedProxy = (PostedDataProxy *) mProxy; + + mViewMode = RSPOSTED_VIEWMODE_HOT; + mViewPeriod = RSPOSTED_PERIOD_WEEK; + mViewStart = 0; + mViewCount = 50; + + mProcessingRanking = false; + mRankingState = 0; + mRankingExternalToken = 0; + mRankingInternalToken = 0; + + mLastBgCheck = 0; + mBgProcessing = 0; + mBgPhase = 0; + mBgToken = 0; + } generateDummyData(); return; } +#define POSTED_BACKGROUND_PERIOD 60 int p3PostedService::tick() { @@ -59,7 +77,34 @@ int p3PostedService::tick() //std::cerr << std::endl; fakeprocessrequests(); + + // Contine Ranking Request. + checkRankingRequest(); + + // Run Background Stuff. + background_checkTokenRequest(); + + /* every minute - run a background check */ + time_t now = time(NULL); + bool doCheck = false; + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + if (now - mLastBgCheck > POSTED_BACKGROUND_PERIOD) + { + doCheck = true; + mLastBgCheck = now; + } + } + + if (doCheck) + { + background_requestGroups(); + } + + + + // Add in new votes + comments. return 0; } @@ -287,7 +332,7 @@ bool p3PostedService::getGroup(const uint32_t &token, RsPostedGroup &group) return false; } - /* convert to RsPhotoAlbum */ + /* convert to RsPostedGroup */ bool ans = mPostedProxy->getGroup(id, group); return ans; } @@ -385,17 +430,26 @@ bool p3PostedService::getComment(const uint32_t &token, RsPostedComment &comment /* Poll */ +/*** + * THE STANDARD ONE IS REPLACED - SO WE CAN HANDLE RANKING REQUESTS + * Its defined lower - next to the ranking code. + ***/ + +#if 0 uint32_t p3PostedService::requestStatus(const uint32_t token) { uint32_t status; uint32_t reqtype; uint32_t anstype; time_t ts; + checkRequestStatus(token, status, reqtype, anstype, ts); return status; } +#endif + /* Cancel Request */ bool p3PostedService::cancelRequest(const uint32_t &token) @@ -404,23 +458,32 @@ bool p3PostedService::cancelRequest(const uint32_t &token) } ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -bool p3PostedService::groupsChanged(std::list &groupIds) -{ - return false; -} - // Get Message Status - is retrived via MessageSummary. + + bool p3PostedService::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) { - return false; + return mPostedProxy->setMessageStatus(msgId, status, statusMask); } - - // -bool p3PostedService::groupSubscribe(const std::string &groupId, bool subscribe) +bool p3PostedService::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) { - return false; + return mPostedProxy->setGroupStatus(groupId, status, statusMask); +} + +bool p3PostedService::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) +{ + return mPostedProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); +} + +bool p3PostedService::setMessageServiceString(const std::string &msgId, const std::string &str) +{ + return mPostedProxy->setMessageServiceString(msgId, str); +} + +bool p3PostedService::setGroupServiceString(const std::string &grpId, const std::string &str) +{ + return mPostedProxy->setGroupServiceString(grpId, str); } @@ -435,7 +498,7 @@ bool p3PostedService::groupShareKeys(const std::string &groupId, std::listaddGroup(group); + } - /* add / modify */ - mPostedProxy->addGroup(group); + // Fake a request to return the GroupMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list groupIds; + groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. + + std::cerr << "p3PostedService::submitGroup() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); return true; } -bool p3PostedService::submitPost(RsPostedPost &post, bool isNew) +bool p3PostedService::submitPost(uint32_t &token, RsPostedPost &post, bool isNew) { if (post.mMeta.mGroupId.empty()) { @@ -500,18 +573,29 @@ bool p3PostedService::submitPost(RsPostedPost &post, bool isNew) std::cerr << " MsgId: " << post.mMeta.mMsgId; std::cerr << std::endl; - RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ - mUpdated = true; + mUpdated = true; + mPostedProxy->addPost(post); + } - mPostedProxy->addPost(post); + // Fake a request to return the MsgMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list msgIds; + msgIds.push_back(post.mMeta.mMsgId); // It will just return this one. + + std::cerr << "p3PostedService::submitPost() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); return true; } -bool p3PostedService::submitVote(RsPostedVote &vote, bool isNew) +bool p3PostedService::submitVote(uint32_t &token, RsPostedVote &vote, bool isNew) { if (vote.mMeta.mGroupId.empty()) { @@ -544,18 +628,29 @@ bool p3PostedService::submitVote(RsPostedVote &vote, bool isNew) std::cerr << " MsgId: " << vote.mMeta.mMsgId; std::cerr << std::endl; - RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ - mUpdated = true; + mUpdated = true; + mPostedProxy->addVote(vote); + } + + // Fake a request to return the MsgMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list msgIds; + msgIds.push_back(vote.mMeta.mMsgId); // It will just return this one. + + std::cerr << "p3PostedService::submitVote() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); - mPostedProxy->addVote(vote); return true; } - -bool p3PostedService::submitComment(RsPostedComment &comment, bool isNew) +bool p3PostedService::submitComment(uint32_t &token, RsPostedComment &comment, bool isNew) { if (comment.mMeta.mGroupId.empty()) { @@ -588,11 +683,22 @@ bool p3PostedService::submitComment(RsPostedComment &comment, bool isNew) std::cerr << " MsgId: " << comment.mMeta.mMsgId; std::cerr << std::endl; - RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ - mUpdated = true; + mUpdated = true; + mPostedProxy->addComment(comment); + } - mPostedProxy->addComment(comment); + // Fake a request to return the MsgMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list msgIds; + msgIds.push_back(comment.mMeta.mMsgId); // It will just return this one. + + std::cerr << "p3PostedService::submitComment() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); return true; } @@ -634,7 +740,7 @@ bool PostedDataProxy::getPost(const std::string &id, RsPostedPost &post) { RsPostedMsg *pM = (RsPostedMsg *) msgData; - if (pM->postedType == RSPOSTED_MSG_POST) + if (pM->postedType == RSPOSTED_MSGTYPE_POST) { RsPostedPost *pP = (RsPostedPost *) pM; post = *pP; @@ -673,7 +779,7 @@ bool PostedDataProxy::getVote(const std::string &id, RsPostedVote &vote) { RsPostedMsg *pM = (RsPostedMsg *) msgData; - if (pM->postedType == RSPOSTED_MSG_VOTE) + if (pM->postedType == RSPOSTED_MSGTYPE_VOTE) { RsPostedVote *pP = (RsPostedVote *) pM; vote = *pP; @@ -712,7 +818,7 @@ bool PostedDataProxy::getComment(const std::string &id, RsPostedComment &comment { RsPostedMsg *pM = (RsPostedMsg *) msgData; - if (pM->postedType == RSPOSTED_MSG_COMMENT) + if (pM->postedType == RSPOSTED_MSGTYPE_COMMENT) { RsPostedComment *pP = (RsPostedComment *) pM; comment = *pP; @@ -919,12 +1025,12 @@ bool p3PostedService::generateDummyData() float rnd = RSRandom::random_f32(); if (rnd < 0.1) { - group.mMeta.mSubscribeFlags = RS_DISTRIB_ADMIN; + group.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_ADMIN; } else if (rnd < 0.3) { - group.mMeta.mSubscribeFlags = RS_DISTRIB_SUBSCRIBED; + group.mMeta.mSubscribeFlags = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED; } else { @@ -1100,3 +1206,773 @@ bool p3PostedService::generateDummyData() /********************************************************************************************/ /********************************************************************************************/ +/********************************************************************************************/ +/********************************************************************************************/ +/********************************************************************************************/ + + +/* This is the part that will be kept for the final Version. + * we provide a processed view of the data... + * + * start off crude -> then make it efficient. + */ + + +bool p3PostedService::setViewMode(uint32_t mode) +{ + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + mViewMode = mode; + + return true; +} + +bool p3PostedService::setViewPeriod(uint32_t period) +{ + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + mViewPeriod = period; + + return true; +} + +bool p3PostedService::setViewRange(uint32_t first, uint32_t count) +{ + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + mViewStart = first; + mViewCount = count; + + return true; +} + +float p3PostedService::calcPostScore(const RsMsgMetaData &meta) +{ + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + float score = 0; + uint32_t votes = 0; + uint32_t comments = 0; + time_t now = time(NULL); + time_t age_secs = now - meta.mPublishTs; + // This is a potential problem for gaming the system... post into the future. + // Should fix this by discarding/hiding until ts valid XXX. + if (age_secs < 0) + { + age_secs = 0; + } + + if (!extractPostedCache(meta.mServiceString, votes, comments)) + { + /* no votes/comments yet */ + } + + /* this is dependent on View Mode */ + switch(mViewMode) + { + default: + case RSPOSTED_VIEWMODE_LATEST: + { + score = -age_secs; // + + break; + } + case RSPOSTED_VIEWMODE_TOP: + { + score = votes; + break; + } +// Potentially only +// This is effectively HackerNews Algorithm: which is (p-1)/(t+2)^1.5, where p is votes and t is age in hours. + case RSPOSTED_VIEWMODE_HOT: + { +#define POSTED_AGESHIFT (2.0) +#define POSTED_AGEFACTOR (3600.0) + score = votes / pow(POSTED_AGESHIFT + age_secs / POSTED_AGEFACTOR, 1.5); + break; + } +// Like HOT, but using number of Comments. + case RSPOSTED_VIEWMODE_COMMENTS: + { + score = comments / pow(POSTED_AGESHIFT + age_secs / POSTED_AGEFACTOR, 1.5); + break; + } + } + + return score; +} + +static uint32_t convertPeriodFlagToSeconds(uint32_t periodMode) +{ + float secs = 1; + switch(periodMode) + { + // Fallthrough all of them. + case RSPOSTED_PERIOD_YEAR: + secs *= 12; + case RSPOSTED_PERIOD_MONTH: + secs *= 4.3; // average ~30.4 days = 4.3 weeks. + case RSPOSTED_PERIOD_WEEK: + secs *= 7; + case RSPOSTED_PERIOD_DAY: + secs *= 24; + case RSPOSTED_PERIOD_HOUR: + secs *= 3600; + } + + return (uint32_t) secs; +} + +#define POSTED_RANKINGS_INITIAL_CHECK 1 +#define POSTED_RANKINGS_DATA_REQUEST 2 +#define POSTED_RANKINGS_DATA_DONE 3 + + /* Poll */ +uint32_t p3PostedService::requestStatus(const uint32_t token) +{ + uint32_t status; + uint32_t reqtype; + uint32_t anstype; + time_t ts; + + uint32_t int_token = token; + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + if ((mProcessingRanking) && (token == mRankingExternalToken)) + { + { + switch(mRankingState) + { + case POSTED_RANKINGS_INITIAL_CHECK: + status = GXS_REQUEST_STATUS_PENDING; + return status; + break; + case POSTED_RANKINGS_DATA_REQUEST: + // Switch to real token. + int_token = mRankingInternalToken; + break; + } + } + } + } + + checkRequestStatus(int_token, status, reqtype, anstype, ts); + + return status; +} + +bool p3PostedService::getRankedPost(const uint32_t &token, RsPostedPost &post) +{ + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + if (!mProcessingRanking) + { + + return false; + } + + if (token != mRankingExternalToken) + { + + + return false; + } + + if (mRankingState != POSTED_RANKINGS_DATA_REQUEST) + { + + return false; + + } + + + if (!getPost(mRankingInternalToken, post)) + { + /* clean up */ + mProcessingRanking = false; + mRankingExternalToken = 0; + mRankingInternalToken = 0; + mRankingState = POSTED_RANKINGS_DATA_DONE; + + return false; + } + + return true; +} + + +bool p3PostedService::requestRanking(uint32_t &token, std::string groupId) +{ + std::cerr << "p3PostedService::requestRanking()"; + std::cerr << std::endl; + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + if (mProcessingRanking) + { + std::cerr << "p3PostedService::requestRanking() ERROR Request already running - ignoring"; + std::cerr << std::endl; + + return false; + } + } + + generateToken(token); + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mProcessingRanking = true; + mRankingState = POSTED_RANKINGS_INITIAL_CHECK; + mRankingExternalToken = token; + } + + /* now we request all the posts within the timeframe */ + + uint32_t posttoken; + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; + + opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST; + //uint32_t age = convertPeriodFlagToSeconds(mViewPeriod); + + std::list groupIds; + groupIds.push_back(groupId); + + requestMsgInfo(posttoken, ansType, opts, groupIds); + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mRankingInternalToken = posttoken; + } + return true; +} + +bool p3PostedService::checkRankingRequest() +{ + uint32_t token = 0; + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + if (!mProcessingRanking) + { + return false; + } + + if (mRankingState != POSTED_RANKINGS_INITIAL_CHECK) + { + return false; + } + + /* here it actually running! */ + token = mRankingInternalToken; + } + + + uint32_t status; + uint32_t reqtype; + uint32_t anstype; + time_t ts; + checkRequestStatus(token, status, reqtype, anstype, ts); + + if (status == GXS_REQUEST_STATUS_COMPLETE) + { + processPosts(); + } + return true; +} + + +bool p3PostedService::processPosts() +{ + std::cerr << "p3PostedService::processPosts()"; + std::cerr << std::endl; + + uint32_t token = 0; + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + if (!mProcessingRanking) + { + std::cerr << "p3PostedService::processPosts() ERROR Ranking Request not running"; + std::cerr << std::endl; + + return false; + } + + if (mRankingState != POSTED_RANKINGS_INITIAL_CHECK) + { + std::cerr << "p3PostedService::processPosts() ERROR Ranking Request not running"; + std::cerr << std::endl; + + return false; + } + token = mRankingInternalToken; + } + + /* extract the info -> and sort */ + std::list postList; + std::list::const_iterator it; + + if (!getMsgSummary(token, postList)) + { + std::cerr << "p3PostedService::processPosts() ERROR getting postList"; + std::cerr << std::endl; + return false; + } + + std::multimap postMap; + std::multimap::iterator mit; + + for(it = postList.begin(); it != postList.end(); it++) + { + float score = calcPostScore(*it); + postMap.insert(std::make_pair(score, it->mMsgId)); + } + + /* now grab the N required, and request the data again... + * -> this is what will be passed back to GUI + */ + + std::list msgList; + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + unsigned int i = 0; + for(mit = postMap.begin(); (mit != postMap.end()) && (i < mViewStart); mit++, i++) + { + std::cerr << "p3PostedService::processPosts() Skipping PostId: " << mit->second; + std::cerr << " with score: " << mit->first; + std::cerr << std::endl; + } + + + for(i = 0; (mit != postMap.end()) && (i < mViewCount); mit++, i++) + { + std::cerr << "p3PostedService::processPosts() Adding PostId: " << mit->second; + std::cerr << " with score: " << mit->first; + std::cerr << std::endl; + msgList.push_back(mit->second); + } + } + + token = 0; + uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA; + RsTokReqOptions opts; + + requestMsgRelatedInfo(token, ansType, opts, msgList); + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mRankingState = POSTED_RANKINGS_DATA_REQUEST; + mRankingInternalToken = token; + } + return true; +} + + + +/***** Background Processing **** + * + * Process Each Message - as it arrives. + * + * Update + * + */ + +#define POSTED_BG_REQUEST_GROUPS 1 +#define POSTED_BG_REQUEST_UNPROCESSED 2 +#define POSTED_BG_REQUEST_PARENTS 3 +#define POSTED_BG_PROCESS_VOTES 4 + +bool p3PostedService::background_checkTokenRequest() +{ + uint32_t token = 0; + uint32_t phase = 0; + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + if (!mBgProcessing) + { + return false; + } + + token = mBgToken; + phase = mBgPhase; + } + + + uint32_t status; + uint32_t reqtype; + uint32_t anstype; + time_t ts; + checkRequestStatus(token, status, reqtype, anstype, ts); + + if (status == GXS_REQUEST_STATUS_COMPLETE) + { + switch(phase) + { + case POSTED_BG_REQUEST_GROUPS: + background_requestNewMessages(); + break; + case POSTED_BG_REQUEST_UNPROCESSED: + background_processNewMessages(); + break; + case POSTED_BG_REQUEST_PARENTS: + background_updateVoteCounts(); + break; + default: + break; + } + } + return true; +} + + +bool p3PostedService::background_requestGroups() +{ + std::cerr << "p3PostedService::background_requestGroups()"; + std::cerr << std::endl; + + // grab all the subscribed groups. + uint32_t token = 0; + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + mBgProcessing = true; + mBgPhase = POSTED_BG_REQUEST_GROUPS; + mBgToken = 0; + } + + uint32_t ansType = RS_TOKREQ_ANSTYPE_LIST; + RsTokReqOptions opts; + std::list groupIds; + + opts.mSubscribeFilter = RSGXS_GROUP_SUBSCRIBE_SUBSCRIBED; + + requestGroupInfo(token, ansType, opts, groupIds); + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mBgToken = token; + } + + return true; +} + + +bool p3PostedService::background_requestNewMessages() +{ + std::cerr << "p3PostedService::background_requestNewMessages()"; + std::cerr << std::endl; + + std::list groupIds; + uint32_t token = 0; + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + token = mBgToken; + } + + if (!getGroupList(token, groupIds)) + { + std::cerr << "p3PostedService::background_requestNewMessages() ERROR"; + std::cerr << std::endl; + background_cleanup(); + return false; + } + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mBgPhase = POSTED_BG_REQUEST_UNPROCESSED; + mBgToken = 0; + } + + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; + token = 0; + + opts.mStatusFilter = RSGXS_MSG_STATUS_UNPROCESSED; + opts.mStatusMask = RSGXS_MSG_STATUS_UNPROCESSED; + + requestMsgInfo(token, ansType, opts, groupIds); + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mBgToken = token; + } + return true; +} + + +bool p3PostedService::background_processNewMessages() +{ + std::cerr << "p3PostedService::background_processNewMessages()"; + std::cerr << std::endl; + + std::list newMsgList; + std::list::iterator it; + uint32_t token = 0; + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + token = mBgToken; + } + + if (!getMsgSummary(token, newMsgList)) + { + std::cerr << "p3PostedService::background_processNewMessages() ERROR"; + std::cerr << std::endl; + background_cleanup(); + return false; + } + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mBgPhase = POSTED_BG_REQUEST_PARENTS; + mBgToken = 0; + mBgVoteMap.clear(); + mBgCommentMap.clear(); + } + + /* loop through and sort by parents. + * - grab + */ + + std::list parentList; + + std::map::iterator vit; + + for(it = newMsgList.begin(); it != newMsgList.end(); it++) + { + std::cerr << "Found New MsgId: " << it->mMsgId; + std::cerr << std::endl; + + /* discard threadheads */ + if (it->mParentId.empty()) + { + std::cerr << "\tIgnoring ThreadHead"; + std::cerr << std::endl; + } + else if (it->mMsgFlags & RSPOSTED_MSGTYPE_COMMENT) + { + /* Comments are counted by Thread Id */ + std::cerr << "\tProcessing Comment"; + std::cerr << std::endl; + + vit = mBgCommentMap.find(it->mThreadId); + if (vit == mBgCommentMap.end()) + { + mBgCommentMap[it->mThreadId] = 1; + + /* check VoteMap too before adding to parentList */ + if (mBgVoteMap.end() == mBgVoteMap.find(it->mThreadId)) + { + parentList.push_back(it->mThreadId); + } + + std::cerr << "\tThreadId: " << it->mThreadId; + std::cerr << " Comment Total: " << mBgCommentMap[it->mThreadId]; + } + else + { + mBgVoteMap[it->mThreadId]++; + std::cerr << "\tThreadId: " << it->mThreadId; + std::cerr << " Comment Total: " << mBgCommentMap[it->mThreadId]; + std::cerr << std::endl; + } + } + else if (it->mMsgFlags & RSPOSTED_MSGTYPE_COMMENT) + { + /* Votes are organised by Parent Id, + * ie. you can vote for both Posts and Comments + */ + vit = mBgVoteMap.find(it->mParentId); + if (vit == mBgVoteMap.end()) + { + mBgVoteMap[it->mParentId] = 1; + + /* check CommentMap too before adding to parentList */ + if (mBgCommentMap.end() == mBgCommentMap.find(it->mParentId)) + { + parentList.push_back(it->mParentId); + } + + std::cerr << "\tParentId: " << it->mParentId; + std::cerr << " Vote Total: " << mBgVoteMap[it->mParentId]; + } + else + { + mBgVoteMap[it->mParentId]++; + std::cerr << "\tParentId: " << it->mParentId; + std::cerr << " Vote Total: " << mBgVoteMap[it->mParentId]; + std::cerr << std::endl; + } + } + else + { + /* unknown! */ + std::cerr << "p3PostedService::background_processNewMessages() ERROR Strange NEW Message:"; + std::cerr << std::endl; + std::cerr << "\t" << *it; + std::cerr << std::endl; + + } + + /* flag each new vote as processed */ + setMessageStatus(it->mMsgId, 0, RSGXS_MSG_STATUS_UNPROCESSED); + } + + + /* request the summary info from the parents */ + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + token = 0; + RsTokReqOptions opts; + requestMsgRelatedInfo(token, ansType, opts, parentList); + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mBgToken = token; + } + return true; +} + + +bool p3PostedService::encodePostedCache(std::string &str, uint32_t votes, uint32_t comments) +{ + char line[RSGXS_MAX_SERVICE_STRING]; + + snprintf(line, RSGXS_MAX_SERVICE_STRING, "%d %d", votes, comments); + + str = line; + return true; +} + +bool p3PostedService::extractPostedCache(const std::string &str, uint32_t &votes, uint32_t &comments) +{ + + uint32_t ivotes, icomments; + if (2 == sscanf(str.c_str(), "%d %d", &ivotes, &icomments)) + { + votes = ivotes; + comments = icomments; + return true; + } + + return false; +} + + +bool p3PostedService::background_updateVoteCounts() +{ + std::cerr << "p3PostedService::background_updateVoteCounts()"; + std::cerr << std::endl; + + std::list parentMsgList; + std::list::iterator it; + + if (!getMsgSummary(mBgToken, parentMsgList)) + { + std::cerr << "p3PostedService::background_updateVoteCounts() ERROR"; + std::cerr << std::endl; + background_cleanup(); + return false; + } + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + mBgPhase = POSTED_BG_PROCESS_VOTES; + mBgToken = 0; + } + + for(it = parentMsgList.begin(); it != parentMsgList.end(); it++) + { + /* extract current vote count */ + uint32_t votes = 0; + uint32_t comments = 0; + + if (!extractPostedCache(it->mServiceString, votes, comments)) + { + if (!(it->mServiceString.empty())) + { + std::cerr << "p3PostedService::background_updateVoteCounts() Failed to extract Votes"; + std::cerr << std::endl; + std::cerr << "\tFrom String: " << it->mServiceString; + std::cerr << std::endl; + } + } + + /* find increment in votemap */ + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator vit; + vit = mBgVoteMap.find(it->mMsgId); + if (vit != mBgVoteMap.end()) + { + votes += vit->second; + } + else + { + // warning. + std::cerr << "p3PostedService::background_updateVoteCounts() Warning No New Votes found."; + std::cerr << " For MsgId: " << it->mMsgId; + std::cerr << std::endl; + } + + } + + { + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + std::map::iterator cit; + cit = mBgCommentMap.find(it->mMsgId); + if (cit != mBgCommentMap.end()) + { + comments += cit->second; + } + else + { + // warning. + std::cerr << "p3PostedService::background_updateVoteCounts() Warning No New Comments found."; + std::cerr << " For MsgId: " << it->mMsgId; + std::cerr << std::endl; + } + + } + + std::string str; + if (!encodePostedCache(str, votes, comments)) + { + std::cerr << "p3PostedService::background_updateVoteCounts() Failed to encode Votes"; + std::cerr << std::endl; + } + else + { + std::cerr << "p3PostedService::background_updateVoteCounts() Encoded String: " << str; + std::cerr << std::endl; + /* store new result */ + setMessageServiceString(it->mMsgId, str); + } + } + + // DONE!. + background_cleanup(); + return true; + +} + + +bool p3PostedService::background_cleanup() +{ + std::cerr << "p3PostedService::background_cleanup()"; + std::cerr << std::endl; + + RsStackMutex stack(mPostedMtx); /********** STACK LOCKED MTX ******/ + + // Cleanup. + mBgVoteMap.clear(); + mBgCommentMap.clear(); + mBgProcessing = false; + mBgToken = 0; + + return true; +} + + diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index cd628afe2..aa2307480 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -102,28 +102,54 @@ virtual uint32_t requestStatus(const uint32_t token); virtual bool cancelRequest(const uint32_t &token); ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -virtual bool groupsChanged(std::list &groupIds); - - // Get Message Status - is retrived via MessageSummary. virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); - - // -virtual bool groupSubscribe(const std::string &groupId, bool subscribe); +virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); +virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); +virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); +virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); virtual bool groupRestoreKeys(const std::string &groupId); virtual bool groupShareKeys(const std::string &groupId, std::list& peers); -/* details are updated in album - to choose Album ID, and storage path */ -virtual bool submitGroup(RsPostedGroup &group, bool isNew); -virtual bool submitPost(RsPostedPost &post, bool isNew); -virtual bool submitVote(RsPostedVote &vote, bool isNew); -virtual bool submitComment(RsPostedComment &comment, bool isNew); +virtual bool submitGroup(uint32_t &token, RsPostedGroup &group, bool isNew); +virtual bool submitPost(uint32_t &token, RsPostedPost &post, bool isNew); +virtual bool submitVote(uint32_t &token, RsPostedVote &vote, bool isNew); +virtual bool submitComment(uint32_t &token, RsPostedComment &comment, bool isNew); + + // Extended Interface for Collated Data View. +virtual bool setViewMode(uint32_t mode); +virtual bool setViewPeriod(uint32_t period); +virtual bool setViewRange(uint32_t first, uint32_t count); + +virtual bool requestRanking(uint32_t &token, std::string groupId); +virtual bool getRankedPost(const uint32_t &token, RsPostedPost &post); + // These are exposed for GUI usage. +virtual bool encodePostedCache(std::string &str, uint32_t votes, uint32_t comments); +virtual bool extractPostedCache(const std::string &str, uint32_t &votes, uint32_t &comments); private: + // +bool checkRankingRequest(); +float calcPostScore(const RsMsgMetaData &meta); +bool processPosts(); + + // background processing of Votes. + // NB: These should probably be handled by a background thread. + // At the moment they are run from the tick() thread. + +bool background_checkTokenRequest(); +bool background_requestGroups(); +bool background_requestNewMessages(); +bool background_processNewMessages(); + +bool background_updateVoteCounts(); +bool background_cleanup(); + + + std::string genRandomId(); bool generateDummyData(); @@ -132,6 +158,27 @@ bool generateDummyData(); RsMutex mPostedMtx; bool mUpdated; + // Ranking view mode, stored here. + uint32_t mViewMode; + uint32_t mViewPeriod; + uint32_t mViewStart; + uint32_t mViewCount; + + // Processing Ranking stuff. + bool mProcessingRanking; + uint32_t mRankingState; + uint32_t mRankingExternalToken; + uint32_t mRankingInternalToken; + + // background processing - Mutex protected. + time_t mLastBgCheck; + bool mBgProcessing; + uint32_t mBgPhase; + uint32_t mBgToken; + + std::map mBgVoteMap; // ParentId -> Vote Count. + std::map mBgCommentMap; // ThreadId -> Comment Count. + }; diff --git a/libretroshare/src/services/p3wikiservice.cc b/libretroshare/src/services/p3wikiservice.cc index 5a5cd7047..94c45376f 100644 --- a/libretroshare/src/services/p3wikiservice.cc +++ b/libretroshare/src/services/p3wikiservice.cc @@ -346,24 +346,31 @@ bool p3WikiService::cancelRequest(const uint32_t &token) return clearRequest(token); } - ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -bool p3WikiService::groupsChanged(std::list &groupIds) -{ - return false; -} - // Get Message Status - is retrived via MessageSummary. + ////////////////////////////////////////////////////////////////////////////// bool p3WikiService::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) { - return false; + return mWikiProxy->setMessageStatus(msgId, status, statusMask); } - - // -bool p3WikiService::groupSubscribe(const std::string &groupId, bool subscribe) +bool p3WikiService::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) { - return false; + return mWikiProxy->setGroupStatus(groupId, status, statusMask); +} + +bool p3WikiService::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) +{ + return mWikiProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); +} + +bool p3WikiService::setMessageServiceString(const std::string &msgId, const std::string &str) +{ + return mWikiProxy->setMessageServiceString(msgId, str); +} + +bool p3WikiService::setGroupServiceString(const std::string &grpId, const std::string &str) +{ + return mWikiProxy->setGroupServiceString(grpId, str); } @@ -392,7 +399,7 @@ std::string p3WikiService::genRandomId() return randomId; } -bool p3WikiService::createGroup(RsWikiGroup &group) +bool p3WikiService::createGroup(uint32_t &token, RsWikiGroup &group, bool isNew) { if (group.mMeta.mGroupId.empty()) { @@ -407,20 +414,30 @@ bool p3WikiService::createGroup(RsWikiGroup &group) std::cerr << std::endl; return false; } + + { + RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ + + mUpdated = true; + mWikiProxy->addGroup(group); + } - RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - - mWikiProxy->addGroup(group); + // Fake a request to return the GroupMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list groupIds; + groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. + + std::cerr << "p3WikiService::createGroup() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); return true; } - -bool p3WikiService::createPage(RsWikiPage &page) +bool p3WikiService::createPage(uint32_t &token, RsWikiPage &page, bool isNew) { if (page.mMeta.mGroupId.empty()) { @@ -456,12 +473,23 @@ bool p3WikiService::createPage(RsWikiPage &page) std::cerr << "p3WikiService::createPage() OrigPageId: " << page.mMeta.mOrigMsgId; std::cerr << std::endl; - RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mWikiMtx); /********** STACK LOCKED MTX ******/ - mUpdated = true; - - mWikiProxy->addPage(page); + mUpdated = true; + mWikiProxy->addPage(page); + } + // Fake a request to return the MsgMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list msgIds; + msgIds.push_back(page.mMeta.mMsgId); // It will just return this one. + + std::cerr << "p3WikiService::createPage() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); + return true; } diff --git a/libretroshare/src/services/p3wikiservice.h b/libretroshare/src/services/p3wikiservice.h index 7d8a3ef0d..a7a2cbe04 100644 --- a/libretroshare/src/services/p3wikiservice.h +++ b/libretroshare/src/services/p3wikiservice.h @@ -101,21 +101,17 @@ virtual uint32_t requestStatus(const uint32_t token); virtual bool cancelRequest(const uint32_t &token); ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -virtual bool groupsChanged(std::list &groupIds); - - // Get Message Status - is retrived via MessageSummary. virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); - - // -virtual bool groupSubscribe(const std::string &groupId, bool subscribe); +virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); +virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); +virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); +virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); virtual bool groupRestoreKeys(const std::string &groupId); virtual bool groupShareKeys(const std::string &groupId, std::list& peers); - -virtual bool createGroup(RsWikiGroup &group); -virtual bool createPage(RsWikiPage &page); +virtual bool createGroup(uint32_t &token, RsWikiGroup &group, bool isNew); +virtual bool createPage(uint32_t &token, RsWikiPage &page, bool isNew); private: diff --git a/libretroshare/src/services/p3wire.cc b/libretroshare/src/services/p3wire.cc index cf849187e..c06c9e58b 100644 --- a/libretroshare/src/services/p3wire.cc +++ b/libretroshare/src/services/p3wire.cc @@ -347,23 +347,31 @@ bool p3Wire::cancelRequest(const uint32_t &token) } ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -bool p3Wire::groupsChanged(std::list &groupIds) -{ - return false; -} - // Get Message Status - is retrived via MessageSummary. bool p3Wire::setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask) { - return false; + return mWireProxy->setMessageStatus(msgId, status, statusMask); } - // -bool p3Wire::groupSubscribe(const std::string &groupId, bool subscribe) +bool p3Wire::setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask) { - return false; + return mWireProxy->setGroupStatus(groupId, status, statusMask); +} + +bool p3Wire::setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask) +{ + return mWireProxy->setGroupSubscribeFlags(groupId, subscribeFlags, subscribeMask); +} + +bool p3Wire::setMessageServiceString(const std::string &msgId, const std::string &str) +{ + return mWireProxy->setMessageServiceString(msgId, str); +} + +bool p3Wire::setGroupServiceString(const std::string &grpId, const std::string &str) +{ + return mWireProxy->setGroupServiceString(grpId, str); } @@ -392,7 +400,8 @@ std::string p3Wire::genRandomId() return randomId; } -bool p3Wire::createGroup(RsWireGroup &group) + +bool p3Wire::createGroup(uint32_t &token, RsWireGroup &group, bool isNew) { if (group.mMeta.mGroupId.empty()) { @@ -407,20 +416,31 @@ bool p3Wire::createGroup(RsWireGroup &group) std::cerr << std::endl; return false; } + + { + RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/ + + mUpdated = true; + mWireProxy->addGroup(group); + } + + // Fake a request to return the GroupMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list groupIds; + groupIds.push_back(group.mMeta.mGroupId); // It will just return this one. + + std::cerr << "p3Wiree::createGroup() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_GROUPS, groupIds); - RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/ - - mUpdated = true; - - mWireProxy->addGroup(group); - return true; } -bool p3Wire::createPulse(RsWirePulse &pulse) +bool p3Wire::createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew) { if (pulse.mMeta.mGroupId.empty()) { @@ -456,11 +476,22 @@ bool p3Wire::createPulse(RsWirePulse &pulse) std::cerr << "p3Wire::createPulse() OrigPulseId: " << pulse.mMeta.mOrigMsgId; std::cerr << std::endl; - RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/ + { + RsStackMutex stack(mWireMtx); /********** STACK LOCKED MTX ******/ - mUpdated = true; - - mWireProxy->addPulse(pulse); + mUpdated = true; + mWireProxy->addPulse(pulse); + } + + // Fake a request to return the MsgMetaData. + generateToken(token); + uint32_t ansType = RS_TOKREQ_ANSTYPE_SUMMARY; + RsTokReqOptions opts; // NULL is good. + std::list msgIds; + msgIds.push_back(pulse.mMeta.mMsgId); // It will just return this one. + + std::cerr << "p3Wire::createPulse() Generating Request Token: " << token << std::endl; + storeRequest(token, ansType, opts, GXS_REQUEST_TYPE_MSGRELATED, msgIds); return true; } diff --git a/libretroshare/src/services/p3wire.h b/libretroshare/src/services/p3wire.h index 36d46f0ea..4e83131e6 100644 --- a/libretroshare/src/services/p3wire.h +++ b/libretroshare/src/services/p3wire.h @@ -91,22 +91,17 @@ virtual uint32_t requestStatus(const uint32_t token); virtual bool cancelRequest(const uint32_t &token); ////////////////////////////////////////////////////////////////////////////// - /* Functions from Forums -> need to be implemented generically */ -virtual bool groupsChanged(std::list &groupIds); - - // Get Message Status - is retrived via MessageSummary. virtual bool setMessageStatus(const std::string &msgId, const uint32_t status, const uint32_t statusMask); - - // -virtual bool groupSubscribe(const std::string &groupId, bool subscribe); +virtual bool setGroupStatus(const std::string &groupId, const uint32_t status, const uint32_t statusMask); +virtual bool setGroupSubscribeFlags(const std::string &groupId, uint32_t subscribeFlags, uint32_t subscribeMask); +virtual bool setMessageServiceString(const std::string &msgId, const std::string &str); +virtual bool setGroupServiceString(const std::string &grpId, const std::string &str); virtual bool groupRestoreKeys(const std::string &groupId); virtual bool groupShareKeys(const std::string &groupId, std::list& peers); - -virtual bool createGroup(RsWireGroup &group); -virtual bool createPulse(RsWirePulse &pulse); - +virtual bool createGroup(uint32_t &token, RsWireGroup &group, bool isNew); +virtual bool createPulse(uint32_t &token, RsWirePulse &pulse, bool isNew); private: