mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-24 23:15:41 -04:00
Added cleanup code for GXS services in rsinit (services now based in GXS_phase1 folder in .retroshare/ folder
disabled msg synchronisation by default through compilation #define (use GXS_ENABLE_MSG_SYNC to enable message sync) Finally removed v2 suffix from all photo components and filenames (please edit your libretroshare.pro file accordingly) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5883 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
da39d1de77
commit
744a78b140
20 changed files with 2202 additions and 2179 deletions
|
@ -1,388 +1,388 @@
|
|||
#include "p3photoserviceV2.h"
|
||||
#include "serialiser/rsphotov2items.h"
|
||||
#include "gxs/rsgxsflags.h"
|
||||
|
||||
RsPhotoV2 *rsPhotoV2 = NULL;
|
||||
|
||||
|
||||
const uint32_t RsPhotoV2::FLAG_MSG_TYPE_MASK = 0x000f;
|
||||
const uint32_t RsPhotoV2::FLAG_MSG_TYPE_PHOTO_POST = 0x0001;
|
||||
const uint32_t RsPhotoV2::FLAG_MSG_TYPE_PHOTO_COMMENT = 0x0002;
|
||||
|
||||
|
||||
|
||||
|
||||
bool RsPhotoThumbnail::copyFrom(const RsPhotoThumbnail &nail)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
deleteImage();
|
||||
}
|
||||
|
||||
if ((!nail.data) || (nail.size == 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
size = nail.size;
|
||||
type = nail.type;
|
||||
data = (uint8_t *) malloc(size);
|
||||
memcpy(data, nail.data, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsPhotoThumbnail::deleteImage()
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
free(data);
|
||||
data = NULL;
|
||||
size = 0;
|
||||
type.clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RsPhotoPhoto::RsPhotoPhoto()
|
||||
:mSetFlags(0), mOrder(0), mMode(0), mModFlags(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RsPhotoAlbum::RsPhotoAlbum()
|
||||
:mMode(0), mSetFlags(0), mModFlags(0)
|
||||
{
|
||||
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 [ ";
|
||||
out << "Title: " << photo.mMeta.mMsgName;
|
||||
out << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
|
||||
{
|
||||
out << "RsPhotoAlbum [ ";
|
||||
out << "Title: " << album.mMeta.mGroupName;
|
||||
out << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
p3PhotoServiceV2::p3PhotoServiceV2(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs,
|
||||
uint32_t authenPolicy)
|
||||
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXSV1_TYPE_PHOTO, gixs, authenPolicy),
|
||||
mPhotoMutex(std::string("Photo Mutex"))
|
||||
{
|
||||
|
||||
// create dummy grps
|
||||
|
||||
RsGxsPhotoAlbumItem* item1 = new RsGxsPhotoAlbumItem(), *item2 = new RsGxsPhotoAlbumItem();
|
||||
|
||||
item1->meta.mGroupName = "Dummy Album 1";
|
||||
item1->meta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_RESTRICTED;
|
||||
item1->album.mCaption = "Dummy 1";
|
||||
item2->meta.mGroupName = "Dummy Album 2";
|
||||
item2->meta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_RESTRICTED;
|
||||
item2->album.mCaption = "Dummy 2";
|
||||
|
||||
createDummyGroup(item1);
|
||||
createDummyGroup(item2);
|
||||
}
|
||||
|
||||
bool p3PhotoServiceV2::updated()
|
||||
{
|
||||
RsStackMutex stack(mPhotoMutex);
|
||||
|
||||
bool changed = (!mGroupChange.empty() || !mMsgChange.empty());
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void p3PhotoServiceV2::service_tick()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3PhotoServiceV2::groupsChanged(std::list<RsGxsGroupId>& grpIds)
|
||||
{
|
||||
RsStackMutex stack(mPhotoMutex);
|
||||
|
||||
while(!mGroupChange.empty())
|
||||
{
|
||||
RsGxsGroupChange* gc = mGroupChange.back();
|
||||
std::list<RsGxsGroupId>& gList = gc->grpIdList;
|
||||
std::list<RsGxsGroupId>::iterator lit = gList.begin();
|
||||
for(; lit != gList.end(); lit++)
|
||||
grpIds.push_back(*lit);
|
||||
|
||||
mGroupChange.pop_back();
|
||||
delete gc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3PhotoServiceV2::msgsChanged(
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgs)
|
||||
{
|
||||
RsStackMutex stack(mPhotoMutex);
|
||||
|
||||
while(!mMsgChange.empty())
|
||||
{
|
||||
RsGxsMsgChange* mc = mMsgChange.back();
|
||||
msgs = mc->msgChangeMap;
|
||||
mMsgChange.pop_back();
|
||||
delete mc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RsTokenService* p3PhotoServiceV2::getTokenService() {
|
||||
|
||||
return RsGenExchange::getTokenService();
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoServiceV2::getGroupList(const uint32_t& token,
|
||||
std::list<RsGxsGroupId>& groupIds)
|
||||
{
|
||||
return RsGenExchange::getGroupList(token, groupIds);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoServiceV2::getMsgList(const uint32_t& token,
|
||||
GxsMsgIdResult& msgIds)
|
||||
{
|
||||
|
||||
return RsGenExchange::getMsgList(token, msgIds);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoServiceV2::getGroupSummary(const uint32_t& token,
|
||||
std::list<RsGroupMetaData>& groupInfo)
|
||||
{
|
||||
return RsGenExchange::getGroupMeta(token, groupInfo);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoServiceV2::getMsgSummary(const uint32_t& token,
|
||||
MsgMetaResult& msgInfo)
|
||||
{
|
||||
return RsGenExchange::getMsgMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoServiceV2::getAlbum(const uint32_t& token, std::vector<RsPhotoAlbum>& albums)
|
||||
{
|
||||
std::vector<RsGxsGrpItem*> grpData;
|
||||
bool ok = RsGenExchange::getGroupData(token, grpData);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
|
||||
|
||||
for(; vit != grpData.end(); vit++)
|
||||
{
|
||||
RsGxsPhotoAlbumItem* item = dynamic_cast<RsGxsPhotoAlbumItem*>(*vit);
|
||||
RsPhotoAlbum album = item->album;
|
||||
item->album.mMeta = item->meta;
|
||||
album.mMeta = item->album.mMeta;
|
||||
delete item;
|
||||
albums.push_back(album);
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoServiceV2::getPhoto(const uint32_t& token, PhotoResult& photos)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
RsGxsPhotoPhotoItem* item = dynamic_cast<RsGxsPhotoPhotoItem*>(*vit);
|
||||
|
||||
if(item)
|
||||
{
|
||||
RsPhotoPhoto photo = item->photo;
|
||||
photo.mMeta = item->meta;
|
||||
photos[grpId].push_back(photo);
|
||||
delete item;
|
||||
}else
|
||||
{
|
||||
std::cerr << "Not a photo Item, deleting!" << std::endl;
|
||||
delete *vit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool p3PhotoServiceV2::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 p3PhotoServiceV2::getPhotoRelatedComment(const uint32_t &token, PhotoRelatedCommentResult &comments)
|
||||
{
|
||||
|
||||
return RsGenExchange::getMsgRelatedDataT<RsGxsPhotoCommentItem, RsPhotoComment>(token, comments);
|
||||
|
||||
}
|
||||
|
||||
bool p3PhotoServiceV2::submitAlbumDetails(uint32_t& token, RsPhotoAlbum& album)
|
||||
{
|
||||
RsGxsPhotoAlbumItem* albumItem = new RsGxsPhotoAlbumItem();
|
||||
albumItem->album = album;
|
||||
albumItem->meta = album.mMeta;
|
||||
RsGenExchange::publishGroup(token, albumItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3PhotoServiceV2::notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mPhotoMutex);
|
||||
|
||||
std::vector<RsGxsNotify*>::iterator vit = changes.begin();
|
||||
|
||||
for(; vit != changes.end(); vit++)
|
||||
{
|
||||
RsGxsNotify* n = *vit;
|
||||
RsGxsGroupChange* gc;
|
||||
RsGxsMsgChange* mc;
|
||||
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
|
||||
{
|
||||
mMsgChange.push_back(mc);
|
||||
}
|
||||
else if((gc = dynamic_cast<RsGxsGroupChange*>(n)) != NULL)
|
||||
{
|
||||
mGroupChange.push_back(gc);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool p3PhotoServiceV2::submitPhoto(uint32_t& token, RsPhotoPhoto& photo)
|
||||
{
|
||||
RsGxsPhotoPhotoItem* photoItem = new RsGxsPhotoPhotoItem();
|
||||
photoItem->photo = photo;
|
||||
photoItem->meta = photo.mMeta;
|
||||
photoItem->meta.mMsgFlags = FLAG_MSG_TYPE_PHOTO_POST;
|
||||
|
||||
RsGenExchange::publishMsg(token, photoItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PhotoServiceV2::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 p3PhotoServiceV2::acknowledgeMsg(const uint32_t& token,
|
||||
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId)
|
||||
{
|
||||
return RsGenExchange::acknowledgeTokenMsg(token, msgId);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoServiceV2::acknowledgeGrp(const uint32_t& token,
|
||||
RsGxsGroupId& grpId)
|
||||
{
|
||||
return RsGenExchange::acknowledgeTokenGrp(token, grpId);
|
||||
}
|
||||
|
||||
bool p3PhotoServiceV2::subscribeToAlbum(uint32_t &token, const RsGxsGroupId &grpId, bool subscribe)
|
||||
{
|
||||
if(subscribe)
|
||||
RsGenExchange::setGroupSubscribeFlags(token, grpId, GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED, GXS_SERV::GROUP_SUBSCRIBE_MASK);
|
||||
else
|
||||
RsGenExchange::setGroupSubscribeFlags(token, grpId, 0, GXS_SERV::GROUP_SUBSCRIBE_MASK);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#include "p3photoservice.h"
|
||||
#include "serialiser/rsphotoitems.h"
|
||||
#include "gxs/rsgxsflags.h"
|
||||
|
||||
RsPhoto *rsPhoto = NULL;
|
||||
|
||||
|
||||
const uint32_t RsPhoto::FLAG_MSG_TYPE_MASK = 0x000f;
|
||||
const uint32_t RsPhoto::FLAG_MSG_TYPE_PHOTO_POST = 0x0001;
|
||||
const uint32_t RsPhoto::FLAG_MSG_TYPE_PHOTO_COMMENT = 0x0002;
|
||||
|
||||
|
||||
|
||||
|
||||
bool RsPhotoThumbnail::copyFrom(const RsPhotoThumbnail &nail)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
deleteImage();
|
||||
}
|
||||
|
||||
if ((!nail.data) || (nail.size == 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
size = nail.size;
|
||||
type = nail.type;
|
||||
data = (uint8_t *) malloc(size);
|
||||
memcpy(data, nail.data, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsPhotoThumbnail::deleteImage()
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
free(data);
|
||||
data = NULL;
|
||||
size = 0;
|
||||
type.clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
RsPhotoPhoto::RsPhotoPhoto()
|
||||
:mSetFlags(0), mOrder(0), mMode(0), mModFlags(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RsPhotoAlbum::RsPhotoAlbum()
|
||||
:mMode(0), mSetFlags(0), mModFlags(0)
|
||||
{
|
||||
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 [ ";
|
||||
out << "Title: " << photo.mMeta.mMsgName;
|
||||
out << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPhotoAlbum &album)
|
||||
{
|
||||
out << "RsPhotoAlbum [ ";
|
||||
out << "Title: " << album.mMeta.mGroupName;
|
||||
out << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
p3PhotoService::p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs,
|
||||
uint32_t authenPolicy)
|
||||
: RsGenExchange(gds, nes, new RsGxsPhotoSerialiser(), RS_SERVICE_GXSV1_TYPE_PHOTO, gixs, authenPolicy),
|
||||
mPhotoMutex(std::string("Photo Mutex"))
|
||||
{
|
||||
|
||||
// create dummy grps
|
||||
|
||||
RsGxsPhotoAlbumItem* item1 = new RsGxsPhotoAlbumItem(), *item2 = new RsGxsPhotoAlbumItem();
|
||||
|
||||
item1->meta.mGroupName = "Dummy Album 1";
|
||||
item1->meta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_RESTRICTED;
|
||||
item1->album.mCaption = "Dummy 1";
|
||||
item2->meta.mGroupName = "Dummy Album 2";
|
||||
item2->meta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_RESTRICTED;
|
||||
item2->album.mCaption = "Dummy 2";
|
||||
|
||||
createDummyGroup(item1);
|
||||
createDummyGroup(item2);
|
||||
}
|
||||
|
||||
bool p3PhotoService::updated()
|
||||
{
|
||||
RsStackMutex stack(mPhotoMutex);
|
||||
|
||||
bool changed = (!mGroupChange.empty() || !mMsgChange.empty());
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void p3PhotoService::service_tick()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3PhotoService::groupsChanged(std::list<RsGxsGroupId>& grpIds)
|
||||
{
|
||||
RsStackMutex stack(mPhotoMutex);
|
||||
|
||||
while(!mGroupChange.empty())
|
||||
{
|
||||
RsGxsGroupChange* gc = mGroupChange.back();
|
||||
std::list<RsGxsGroupId>& gList = gc->grpIdList;
|
||||
std::list<RsGxsGroupId>::iterator lit = gList.begin();
|
||||
for(; lit != gList.end(); lit++)
|
||||
grpIds.push_back(*lit);
|
||||
|
||||
mGroupChange.pop_back();
|
||||
delete gc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void p3PhotoService::msgsChanged(
|
||||
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >& msgs)
|
||||
{
|
||||
RsStackMutex stack(mPhotoMutex);
|
||||
|
||||
while(!mMsgChange.empty())
|
||||
{
|
||||
RsGxsMsgChange* mc = mMsgChange.back();
|
||||
msgs = mc->msgChangeMap;
|
||||
mMsgChange.pop_back();
|
||||
delete mc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RsTokenService* p3PhotoService::getTokenService() {
|
||||
|
||||
return RsGenExchange::getTokenService();
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::getGroupList(const uint32_t& token,
|
||||
std::list<RsGxsGroupId>& groupIds)
|
||||
{
|
||||
return RsGenExchange::getGroupList(token, groupIds);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::getMsgList(const uint32_t& token,
|
||||
GxsMsgIdResult& msgIds)
|
||||
{
|
||||
|
||||
return RsGenExchange::getMsgList(token, msgIds);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::getGroupSummary(const uint32_t& token,
|
||||
std::list<RsGroupMetaData>& groupInfo)
|
||||
{
|
||||
return RsGenExchange::getGroupMeta(token, groupInfo);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::getMsgSummary(const uint32_t& token,
|
||||
MsgMetaResult& msgInfo)
|
||||
{
|
||||
return RsGenExchange::getMsgMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::getAlbum(const uint32_t& token, std::vector<RsPhotoAlbum>& albums)
|
||||
{
|
||||
std::vector<RsGxsGrpItem*> grpData;
|
||||
bool ok = RsGenExchange::getGroupData(token, grpData);
|
||||
|
||||
if(ok)
|
||||
{
|
||||
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
|
||||
|
||||
for(; vit != grpData.end(); vit++)
|
||||
{
|
||||
RsGxsPhotoAlbumItem* item = dynamic_cast<RsGxsPhotoAlbumItem*>(*vit);
|
||||
RsPhotoAlbum album = item->album;
|
||||
item->album.mMeta = item->meta;
|
||||
album.mMeta = item->album.mMeta;
|
||||
delete item;
|
||||
albums.push_back(album);
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::getPhoto(const uint32_t& token, PhotoResult& photos)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
RsGxsPhotoPhotoItem* item = dynamic_cast<RsGxsPhotoPhotoItem*>(*vit);
|
||||
|
||||
if(item)
|
||||
{
|
||||
RsPhotoPhoto photo = item->photo;
|
||||
photo.mMeta = item->meta;
|
||||
photos[grpId].push_back(photo);
|
||||
delete item;
|
||||
}else
|
||||
{
|
||||
std::cerr << "Not a photo Item, deleting!" << std::endl;
|
||||
delete *vit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
albumItem->album = album;
|
||||
albumItem->meta = album.mMeta;
|
||||
RsGenExchange::publishGroup(token, albumItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3PhotoService::notifyChanges(std::vector<RsGxsNotify*>& changes)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mPhotoMutex);
|
||||
|
||||
std::vector<RsGxsNotify*>::iterator vit = changes.begin();
|
||||
|
||||
for(; vit != changes.end(); vit++)
|
||||
{
|
||||
RsGxsNotify* n = *vit;
|
||||
RsGxsGroupChange* gc;
|
||||
RsGxsMsgChange* mc;
|
||||
if((mc = dynamic_cast<RsGxsMsgChange*>(n)) != NULL)
|
||||
{
|
||||
mMsgChange.push_back(mc);
|
||||
}
|
||||
else if((gc = dynamic_cast<RsGxsGroupChange*>(n)) != NULL)
|
||||
{
|
||||
mGroupChange.push_back(gc);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool p3PhotoService::submitPhoto(uint32_t& token, RsPhotoPhoto& photo)
|
||||
{
|
||||
RsGxsPhotoPhotoItem* photoItem = new RsGxsPhotoPhotoItem();
|
||||
photoItem->photo = photo;
|
||||
photoItem->meta = photo.mMeta;
|
||||
photoItem->meta.mMsgFlags = FLAG_MSG_TYPE_PHOTO_POST;
|
||||
|
||||
RsGenExchange::publishMsg(token, photoItem);
|
||||
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)
|
||||
{
|
||||
return RsGenExchange::acknowledgeTokenMsg(token, msgId);
|
||||
}
|
||||
|
||||
|
||||
bool p3PhotoService::acknowledgeGrp(const uint32_t& token,
|
||||
RsGxsGroupId& grpId)
|
||||
{
|
||||
return RsGenExchange::acknowledgeTokenGrp(token, grpId);
|
||||
}
|
||||
|
||||
bool p3PhotoService::subscribeToAlbum(uint32_t &token, const RsGxsGroupId &grpId, bool subscribe)
|
||||
{
|
||||
if(subscribe)
|
||||
RsGenExchange::setGroupSubscribeFlags(token, grpId, GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED, GXS_SERV::GROUP_SUBSCRIBE_MASK);
|
||||
else
|
||||
RsGenExchange::setGroupSubscribeFlags(token, grpId, 0, GXS_SERV::GROUP_SUBSCRIBE_MASK);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1,148 +1,148 @@
|
|||
#ifndef P3PHOTOSERVICEV2_H
|
||||
#define P3PHOTOSERVICEV2_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2008-2012 by Robert Fernie, Christopher Evi-Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gxs/rsgenexchange.h"
|
||||
#include "retroshare/rsphotoV2.h"
|
||||
|
||||
class p3PhotoServiceV2 : public RsPhotoV2, public RsGenExchange
|
||||
{
|
||||
public:
|
||||
|
||||
p3PhotoServiceV2(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs,
|
||||
uint32_t authenPolicy);
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* @return true if a change has occured
|
||||
*/
|
||||
bool updated();
|
||||
|
||||
/*!
|
||||
*
|
||||
*/
|
||||
void service_tick();
|
||||
|
||||
protected:
|
||||
|
||||
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
public:
|
||||
|
||||
/** Requests **/
|
||||
|
||||
void groupsChanged(std::list<RsGxsGroupId>& grpIds);
|
||||
|
||||
|
||||
void msgsChanged(std::map<RsGxsGroupId,
|
||||
std::vector<RsGxsMessageId> >& msgs);
|
||||
|
||||
RsTokenService* getTokenService();
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
public:
|
||||
|
||||
/** 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 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);
|
||||
|
||||
/*!
|
||||
* 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 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);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<RsGxsGroupChange*> mGroupChange;
|
||||
std::vector<RsGxsMsgChange*> mMsgChange;
|
||||
|
||||
RsMutex mPhotoMutex;
|
||||
};
|
||||
|
||||
#endif // P3PHOTOSERVICEV2_H
|
||||
#ifndef P3PHOTOSERVICEV2_H
|
||||
#define P3PHOTOSERVICEV2_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/retroshare: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2008-2012 by Robert Fernie, Christopher Evi-Parker
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gxs/rsgenexchange.h"
|
||||
#include "retroshare/rsphoto.h"
|
||||
|
||||
class p3PhotoService : public RsPhoto, public RsGenExchange
|
||||
{
|
||||
public:
|
||||
|
||||
p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs,
|
||||
uint32_t authenPolicy);
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
* @return true if a change has occured
|
||||
*/
|
||||
bool updated();
|
||||
|
||||
/*!
|
||||
*
|
||||
*/
|
||||
void service_tick();
|
||||
|
||||
protected:
|
||||
|
||||
void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
public:
|
||||
|
||||
/** Requests **/
|
||||
|
||||
void groupsChanged(std::list<RsGxsGroupId>& grpIds);
|
||||
|
||||
|
||||
void msgsChanged(std::map<RsGxsGroupId,
|
||||
std::vector<RsGxsMessageId> >& msgs);
|
||||
|
||||
RsTokenService* getTokenService();
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
public:
|
||||
|
||||
/** 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 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);
|
||||
|
||||
/*!
|
||||
* 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 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);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<RsGxsGroupChange*> mGroupChange;
|
||||
std::vector<RsGxsMsgChange*> mMsgChange;
|
||||
|
||||
RsMutex mPhotoMutex;
|
||||
};
|
||||
|
||||
#endif // P3PHOTOSERVICEV2_H
|
Loading…
Add table
Add a link
Reference in a new issue