Merge pull request #1796 from drbob/photos_switch_to_gxscomments

Switch PhotoService to use GxsComments
This commit is contained in:
csoler 2020-02-22 17:09:09 +01:00 committed by GitHub
commit a89f572edf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 484 additions and 1210 deletions

View file

@ -25,8 +25,10 @@
#include <inttypes.h>
#include <string>
#include <list>
#include "rsgxsservice.h"
#include "rsgxscommon.h"
#include "retroshare/rsgxsservice.h"
#include "retroshare/rsgxscommon.h"
#include "retroshare/rsgxsifacehelper.h"
/* The Main Interface Class - for information about your Peers */
class RsPhoto;
@ -135,30 +137,13 @@ class RsPhotoAlbum
uint32_t mModFlags;
};
class RsGxsPhotoCommentItem;
class RsPhotoComment
{
public:
RsPhotoComment();
explicit RsPhotoComment(const RsGxsPhotoCommentItem& comment);
RsPhotoComment& operator=(const RsGxsPhotoCommentItem& comment);
RsMsgMetaData mMeta;
std::string mComment;
uint32_t mCommentFlag;
};
std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo);
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album);
typedef std::map<RsGxsGroupId, std::vector<RsPhotoPhoto> > PhotoResult;
typedef std::map<RsGxsGroupId, std::vector<RsPhotoComment> > PhotoCommentResult;
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsPhotoComment> > PhotoRelatedCommentResult;
class RsPhoto
class RsPhoto: public RsGxsIfaceHelper, public RsGxsCommentService
{
public:
@ -168,7 +153,7 @@ public:
static const uint32_t FLAG_MSG_TYPE_MASK;
RsPhoto() { return; }
explicit RsPhoto(RsGxsIface &gxs) : RsGxsIfaceHelper(gxs) { return; }
virtual ~RsPhoto() { return; }
@ -235,7 +220,7 @@ public:
virtual bool getMsgSummary(const uint32_t &token,
MsgMetaResult &msgInfo) = 0;
/* Specific Service Data */
/* Specific Service Data */
/*!
* @param token token to be redeemed for album request
@ -252,22 +237,6 @@ public:
virtual bool getPhoto(const uint32_t &token,
PhotoResult &photo) = 0;
/* details are updated in album - to choose Album ID, and storage path */
/*!
* @param token token to be redeemed for photo request
* @param photo the photo returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getPhotoComment(const uint32_t &token,
PhotoCommentResult& comments) = 0;
/*!
* @param token token to be redeemed for photo request
* @param photo the photo returned for given request token
* @return false if request token is invalid, check token status for error report
*/
virtual bool getPhotoRelatedComment(const uint32_t &token, PhotoRelatedCommentResult &comments) = 0;
/*!
* submits album, which returns a token that needs
* to be acknowledge to get album grp id
@ -284,16 +253,6 @@ public:
*/
virtual bool submitPhoto(uint32_t& token, RsPhotoPhoto &photo) = 0;
/*!
* submits photo comment, which returns a token that needs
* to be acknowledged to get photo msg-grp id pair
* The mParentId needs to be set to an existing msg for which
* commenting is enabled
* @param token token to redeem for acknowledgement
* @param comment comment to be submitted
*/
virtual bool submitComment(uint32_t& token, RsPhotoComment &photo) = 0;
/*!
* subscribes to group, and returns token which can be used
* to be acknowledged to get group Id

View file

@ -33,11 +33,10 @@ RsItem *RsGxsPhotoSerialiser::create_item(uint16_t service, uint8_t item_sub_id)
switch(item_sub_id)
{
case RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM: return new RsGxsPhotoCommentItem() ;
case RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM: return new RsGxsPhotoPhotoItem() ;
case RS_PKT_SUBTYPE_PHOTO_ITEM: return new RsGxsPhotoAlbumItem() ;
default:
return NULL ;
return RsGxsCommentSerialiser::create_item(service,item_sub_id) ;
}
}
@ -68,11 +67,6 @@ void RsGxsPhotoPhotoItem::serial_process(RsGenericSerializer::SerializeJob j,RsG
photo.mThumbnail.serial_process(j, ctx);
}
void RsGxsPhotoCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"mComment");
RsTypeSerializer::serial_process<uint32_t>(j,ctx,comment.mCommentFlag,"mCommentFlag");
}
void RsGxsPhotoAlbumItem::clear()
{
@ -88,12 +82,6 @@ void RsGxsPhotoAlbumItem::clear()
album.mThumbnail.clear();
}
void RsGxsPhotoCommentItem::clear()
{
comment.mComment.clear();
comment.mCommentFlag = 0;
}
void RsGxsPhotoPhotoItem::clear()
{
photo.mCaption.clear();

View file

@ -26,6 +26,7 @@
#include "rsitems/rsserviceids.h"
#include "rsitems/rsgxsitems.h"
#include "rsitems/rsgxscommentitems.h"
#include "serialiser/rsserial.h"
#include "serialiser/rsserializer.h"
@ -34,7 +35,6 @@
const uint8_t RS_PKT_SUBTYPE_PHOTO_ITEM = 0x02;
const uint8_t RS_PKT_SUBTYPE_PHOTO_SHOW_ITEM = 0x03;
const uint8_t RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM = 0x04;
class RsGxsPhotoAlbumItem : public RsGxsGrpItem
{
@ -66,24 +66,11 @@ public:
RsPhotoPhoto photo;
};
class RsGxsPhotoCommentItem : public RsGxsMsgItem
class RsGxsPhotoSerialiser : public RsGxsCommentSerialiser
{
public:
RsGxsPhotoCommentItem(): RsGxsMsgItem(RS_SERVICE_GXS_TYPE_PHOTO, RS_PKT_SUBTYPE_PHOTO_COMMENT_ITEM) {}
virtual ~RsGxsPhotoCommentItem() {}
void clear();
virtual void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
RsPhotoComment comment;
};
class RsGxsPhotoSerialiser : public RsServiceSerializer
{
public:
RsGxsPhotoSerialiser() :RsServiceSerializer(RS_SERVICE_GXS_TYPE_PHOTO) {}
RsGxsPhotoSerialiser() :RsGxsCommentSerialiser(RS_SERVICE_GXS_TYPE_PHOTO) {}
virtual ~RsGxsPhotoSerialiser() {}
virtual RsItem *create_item(uint16_t service, uint8_t item_sub_id) const;

View file

@ -42,18 +42,6 @@ RsPhotoAlbum::RsPhotoAlbum()
return;
}
RsPhotoComment::RsPhotoComment()
: mComment(""), mCommentFlag(0) {
}
RsPhotoComment::RsPhotoComment(const RsGxsPhotoCommentItem &comment)
: mComment(""), mCommentFlag(0) {
*this = comment.comment;
(*this).mMeta = comment.meta;
}
std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo)
{
out << "RsPhotoPhoto [ ";
@ -62,7 +50,6 @@ std::ostream &operator<<(std::ostream &out, const RsPhotoPhoto &photo)
return out;
}
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
{
out << "RsPhotoAlbum [ ";
@ -73,8 +60,10 @@ std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
p3PhotoService::p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs)
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXS_TYPE_PHOTO, gixs, photoAuthenPolicy()),
RsPhoto(static_cast<RsGxsIface&>(*this)),
mPhotoMutex(std::string("Photo Mutex"))
{
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXS_TYPE_PHOTO);
}
const std::string GXS_PHOTO_APP_NAME = "gxsphoto";
@ -93,8 +82,6 @@ RsServiceInfo p3PhotoService::getServiceInfo()
GXS_PHOTO_MIN_MINOR_VERSION);
}
uint32_t p3PhotoService::photoAuthenPolicy()
{
uint32_t policy = 0;
@ -124,11 +111,10 @@ bool p3PhotoService::updated()
void p3PhotoService::service_tick()
{
mCommentService->comment_tick();
}
void p3PhotoService::groupsChanged(std::list<RsGxsGroupId>& grpIds)
{
RsStackMutex stack(mPhotoMutex);
@ -267,54 +253,6 @@ bool p3PhotoService::getPhoto(const uint32_t& token, PhotoResult& photos)
return ok;
}
bool p3PhotoService::getPhotoComment(const uint32_t &token, PhotoCommentResult &comments)
{
GxsMsgDataMap msgData;
bool ok = RsGenExchange::getMsgData(token, msgData);
if(ok)
{
GxsMsgDataMap::iterator mit = msgData.begin();
for(; mit != msgData.end(); ++mit)
{
RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
for(; vit != msgItems.end(); ++vit)
{
RsGxsPhotoCommentItem* item = dynamic_cast<RsGxsPhotoCommentItem*>(*vit);
if(item)
{
RsPhotoComment comment = item->comment;
comment.mMeta = item->meta;
comments[grpId].push_back(comment);
delete item;
}else
{
std::cerr << "Not a comment Item, deleting!" << std::endl;
delete *vit;
}
}
}
}
return ok;
}
RsPhotoComment& RsPhotoComment::operator=(const RsGxsPhotoCommentItem& comment)
{
*this = comment.comment;
return *this;
}
bool p3PhotoService::getPhotoRelatedComment(const uint32_t &token, PhotoRelatedCommentResult &comments)
{
return RsGenExchange::getMsgRelatedDataT<RsGxsPhotoCommentItem, RsPhotoComment>(token, comments);
}
bool p3PhotoService::submitAlbumDetails(uint32_t& token, RsPhotoAlbum& album)
{
RsGxsPhotoAlbumItem* albumItem = new RsGxsPhotoAlbumItem();
@ -324,8 +262,6 @@ bool p3PhotoService::submitAlbumDetails(uint32_t& token, RsPhotoAlbum& album)
return true;
}
void p3PhotoService::notifyChanges(std::vector<RsGxsNotify*>& changes)
{
@ -363,17 +299,6 @@ bool p3PhotoService::submitPhoto(uint32_t& token, RsPhotoPhoto& photo)
return true;
}
bool p3PhotoService::submitComment(uint32_t &token, RsPhotoComment &comment)
{
RsGxsPhotoCommentItem* commentItem = new RsGxsPhotoCommentItem();
commentItem->comment = comment;
commentItem->meta = comment.mMeta;
commentItem->meta.mMsgFlags = FLAG_MSG_TYPE_PHOTO_COMMENT;
RsGenExchange::publishMsg(token, commentItem);
return true;
}
bool p3PhotoService::acknowledgeMsg(const uint32_t& token,
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
{
@ -397,4 +322,3 @@ bool p3PhotoService::subscribeToAlbum(uint32_t &token, const RsGxsGroupId &grpId
return true;
}

View file

@ -24,122 +24,154 @@
#include "gxs/rsgenexchange.h"
#include "retroshare/rsphoto.h"
#include "services/p3gxscommon.h"
class p3PhotoService : public RsPhoto, public RsGenExchange
class p3PhotoService : public RsGenExchange, public RsPhoto
{
public:
p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual RsServiceInfo getServiceInfo();
p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual RsServiceInfo getServiceInfo();
static uint32_t photoAuthenPolicy();
static uint32_t photoAuthenPolicy();
public:
/*!
* @return true if a change has occured
*/
bool updated();
/*!
* @return true if a change has occured
*/
bool updated();
/*!
*
*/
void service_tick();
/*!
*
*/
void service_tick();
protected:
void notifyChanges(std::vector<RsGxsNotify*>& changes);
void notifyChanges(std::vector<RsGxsNotify*>& changes);
public:
/** Requests **/
/** Requests **/
void groupsChanged(std::list<RsGxsGroupId>& grpIds);
void groupsChanged(std::list<RsGxsGroupId>& grpIds);
void msgsChanged(GxsMsgIdResult& msgs);
void msgsChanged(GxsMsgIdResult& msgs);
RsTokenService* getTokenService();
RsTokenService* getTokenService();
bool getGroupList(const uint32_t &token,
std::list<RsGxsGroupId> &groupIds);
bool getMsgList(const uint32_t &token,
GxsMsgIdResult& msgIds);
bool getGroupList(const uint32_t &token, std::list<RsGxsGroupId> &groupIds);
bool getMsgList(const uint32_t &token, GxsMsgIdResult& msgIds);
/* Generic Summary */
bool getGroupSummary(const uint32_t &token,
std::list<RsGroupMetaData> &groupInfo);
/* Generic Summary */
bool getGroupSummary(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
bool getMsgSummary(const uint32_t &token,
MsgMetaResult &msgInfo);
bool getMsgSummary(const uint32_t &token, MsgMetaResult &msgInfo);
/* Specific Service Data */
bool getAlbum(const uint32_t &token, std::vector<RsPhotoAlbum> &albums);
bool getPhoto(const uint32_t &token, PhotoResult &photos);
bool getPhotoComment(const uint32_t &token, PhotoCommentResult &comments);
bool getPhotoRelatedComment(const uint32_t &token, PhotoRelatedCommentResult &comments);
/* Specific Service Data */
bool getAlbum(const uint32_t &token, std::vector<RsPhotoAlbum> &albums);
bool getPhoto(const uint32_t &token, PhotoResult &photos);
public:
/* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */
virtual bool getCommentData(uint32_t token, std::vector<RsGxsComment> &msgs) override
{
return mCommentService->getGxsCommentData(token, msgs);
}
virtual bool getRelatedComments( uint32_t token, std::vector<RsGxsComment> &msgs ) override
{
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) override
{
return mCommentService->createGxsComment(token, msg);
}
virtual bool createNewVote(uint32_t &token, RsGxsVote &msg) override
{
return mCommentService->createGxsVote(token, msg);
}
virtual bool acknowledgeComment(uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) override
{
return acknowledgeMsg(token, msgId);
}
virtual bool acknowledgeVote(uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId) override
{
if (mCommentService->acknowledgeVote(token, msgId))
{
return true;
}
return acknowledgeMsg(token, msgId);
}
public:
/** Modifications **/
/** Modifications **/
/*!
* submits album, which returns a token that needs
* to be acknowledge to get album grp id
* @param token token to redeem for acknowledgement
* @param album album to be submitted
*/
bool submitAlbumDetails(uint32_t& token, RsPhotoAlbum &album);
/*!
* submits album, which returns a token that needs
* to be acknowledge to get album grp id
* @param token token to redeem for acknowledgement
* @param album album to be submitted
*/
bool submitAlbumDetails(uint32_t& token, RsPhotoAlbum &album);
/*!
* submits photo, which returns a token that needs
* to be acknowledge to get photo msg-grp id pair
* @param token token to redeem for acknowledgement
* @param photo photo to be submitted
*/
bool submitPhoto(uint32_t& token, RsPhotoPhoto &photo);
/*!
* submits photo, which returns a token that needs
* to be acknowledge to get photo msg-grp id pair
* @param token token to redeem for acknowledgement
* @param photo photo to be submitted
*/
bool submitPhoto(uint32_t& token, RsPhotoPhoto &photo);
/*!
* submits photo comment, which returns a token that needs
* to be acknowledged to get photo msg-grp id pair
* The mParentId needs to be set to an existing msg for which
* commenting is enabled
* @param token token to redeem for acknowledgement
* @param comment comment to be submitted
*/
bool submitComment(uint32_t& token, RsPhotoComment &photo);
/*!
* submits photo comment, which returns a token that needs
* to be acknowledged to get photo msg-grp id pair
* The mParentId needs to be set to an existing msg for which
* commenting is enabled
* @param token token to redeem for acknowledgement
* @param comment comment to be submitted
*/
// bool submitComment(uint32_t& token, RsPhotoComment &photo);
/*!
* subscribes to group, and returns token which can be used
* to be acknowledged to get group Id
* @param token token to redeem for acknowledgement
* @param grpId the id of the group to subscribe to
*/
bool subscribeToAlbum(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe);
/*!
* subscribes to group, and returns token which can be used
* to be acknowledged to get group Id
* @param token token to redeem for acknowledgement
* @param grpId the id of the group to subscribe to
*/
bool subscribeToAlbum(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe);
/*!
* This allows the client service to acknowledge that their msgs has
* been created/modified and retrieve the create/modified msg ids
* @param token the token related to modification/create request
* @param msgIds map of grpid->msgIds of message created/modified
* @return true if token exists false otherwise
*/
bool acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId);
/*!
* This allows the client service to acknowledge that their msgs has
* been created/modified and retrieve the create/modified msg ids
* @param token the token related to modification/create request
* @param msgIds map of grpid->msgIds of message created/modified
* @return true if token exists false otherwise
*/
bool acknowledgeMsg(const uint32_t& token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId);
/*!
/*!
* This allows the client service to acknowledge that their grps has
* been created/modified and retrieve the create/modified grp ids
* @param token the token related to modification/create request
* @param msgIds vector of ids of groups created/modified
* @return true if token exists false otherwise
*/
bool acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId);
bool acknowledgeGrp(const uint32_t& token, RsGxsGroupId& grpId);
private:
p3GxsCommentService* mCommentService;
std::vector<RsGxsGroupChange*> mGroupChange;
std::vector<RsGxsMsgChange*> mMsgChange;
std::vector<RsGxsGroupChange*> mGroupChange;
std::vector<RsGxsMsgChange*> mMsgChange;
RsMutex mPhotoMutex;
RsMutex mPhotoMutex;
};
#endif // P3PHOTOSERVICEV2_H