mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-25 23:45:49 -04:00
Bug fix for ES_GXS_MSG_COMMENTS option
Fix for run thread loop of RsGenExchange (was using logic rather than isRunning, which led to some crashes on rs close Added request and get MsgRelated function for ids, meta and data added template function to ease getting meta data from back end; Updated Nxs tests, tests passed (failed initially because of change option requirements) Added test for msgrelated Ids, still need to add test for all msgRelated functions (bug with mask, not filtering correctly) Made changes for forum and wiki gui to use new API but gui needs to call correct get functions now (Bob). git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5817 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
8d556955c5
commit
f74a328d61
27 changed files with 872 additions and 310 deletions
|
@ -76,6 +76,7 @@ public:
|
|||
};
|
||||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > NxsMsgDataResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsNxsMsg*> > NxsMsgRelatedDataResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsNxsMsg*> > GxsMsgResult; // <grpId, msgs>
|
||||
|
||||
/*!
|
||||
|
|
|
@ -75,7 +75,7 @@ void RsGenExchange::run()
|
|||
|
||||
double timeDelta = 0.1; // slow tick
|
||||
|
||||
while(true)
|
||||
while(isRunning())
|
||||
{
|
||||
tick();
|
||||
|
||||
|
@ -303,7 +303,7 @@ bool RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBina
|
|||
const RsGxsMsgMetaData& msgMeta, RsGxsGrpMetaData& grpMeta)
|
||||
{
|
||||
bool isParent = false;
|
||||
bool needPublishSign, needIdentitySign;
|
||||
bool needPublishSign = false, needIdentitySign = false;
|
||||
bool ok = true;
|
||||
uint32_t grpFlag = grpMeta.mGroupFlags;
|
||||
|
||||
|
@ -452,6 +452,7 @@ bool RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBina
|
|||
#ifdef GEN_EXHANGE_DEBUG
|
||||
std::cerr << "Gixs not enabled while request identity signature validation!" << std::endl;
|
||||
#endif
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -694,6 +695,11 @@ bool RsGenExchange::getMsgList(const uint32_t &token,
|
|||
return mDataAccess->getMsgList(token, msgIds);
|
||||
}
|
||||
|
||||
bool RsGenExchange::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult &msgIds)
|
||||
{
|
||||
return mDataAccess->getMsgRelatedList(token, msgIds);
|
||||
}
|
||||
|
||||
bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
|
||||
{
|
||||
std::list<RsGxsGrpMetaData*> metaL;
|
||||
|
@ -744,6 +750,36 @@ bool RsGenExchange::getMsgMeta(const uint32_t &token,
|
|||
return ok;
|
||||
}
|
||||
|
||||
bool RsGenExchange::getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMap &msgMeta)
|
||||
{
|
||||
MsgRelatedMetaResult result;
|
||||
bool ok = mDataAccess->getMsgRelatedSummary(token, result);
|
||||
|
||||
MsgRelatedMetaResult::iterator mit = result.begin();
|
||||
|
||||
for(; mit != result.end(); mit++)
|
||||
{
|
||||
std::vector<RsGxsMsgMetaData*>& metaV = mit->second;
|
||||
|
||||
msgMeta[mit->first] = std::vector<RsMsgMetaData>();
|
||||
std::vector<RsMsgMetaData>& msgInfoV = msgMeta[mit->first];
|
||||
|
||||
std::vector<RsGxsMsgMetaData*>::iterator vit = metaV.begin();
|
||||
RsMsgMetaData meta;
|
||||
for(; vit != metaV.end(); vit++)
|
||||
{
|
||||
RsGxsMsgMetaData& m = *(*vit);
|
||||
meta = m;
|
||||
msgInfoV.push_back(meta);
|
||||
delete *vit;
|
||||
}
|
||||
metaV.clear();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *>& grpItem)
|
||||
{
|
||||
|
||||
|
@ -814,6 +850,46 @@ bool RsGenExchange::getMsgData(const uint32_t &token,
|
|||
return ok;
|
||||
}
|
||||
|
||||
bool RsGenExchange::getMsgRelatedData(const uint32_t &token, GxsMsgRelatedDataMap &msgItems)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mGenMtx);
|
||||
NxsMsgRelatedDataResult msgResult;
|
||||
bool ok = mDataAccess->getMsgRelatedData(token, msgResult);
|
||||
NxsMsgRelatedDataResult::iterator mit = msgResult.begin();
|
||||
|
||||
if(ok)
|
||||
{
|
||||
for(; mit != msgResult.end(); mit++)
|
||||
{
|
||||
std::vector<RsGxsMsgItem*> gxsMsgItems;
|
||||
const RsGxsGrpMsgIdPair& msgId = mit->first;
|
||||
std::vector<RsNxsMsg*>& nxsMsgsV = mit->second;
|
||||
std::vector<RsNxsMsg*>::iterator vit
|
||||
= nxsMsgsV.begin();
|
||||
for(; vit != nxsMsgsV.end(); vit++)
|
||||
{
|
||||
RsNxsMsg*& msg = *vit;
|
||||
|
||||
RsItem* item = mSerialiser->deserialise(msg->msg.bin_data,
|
||||
&msg->msg.bin_len);
|
||||
RsGxsMsgItem* mItem = dynamic_cast<RsGxsMsgItem*>(item);
|
||||
|
||||
if(mItem != NULL)
|
||||
{
|
||||
mItem->meta = *((*vit)->metaData); // get meta info from nxs msg
|
||||
gxsMsgItems.push_back(mItem);
|
||||
}
|
||||
delete msg;
|
||||
}
|
||||
msgItems[msgId] = gxsMsgItems;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
RsTokenService* RsGenExchange::getTokenService()
|
||||
{
|
||||
|
|
|
@ -39,7 +39,9 @@
|
|||
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
|
||||
typedef std::map<RsGxsGroupId, RsGxsGrpItem*> GxsGroupDataMap;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMsgItem*> > GxsMsgRelatedDataMap;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMetaMap;
|
||||
|
||||
/*!
|
||||
* This should form the parent class to \n
|
||||
|
@ -151,14 +153,24 @@ public:
|
|||
* Retrieve msg list for a given token sectioned by group Ids
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of grpId -> msgList (vector)
|
||||
* @return false if could not redeem token
|
||||
*/
|
||||
bool getMsgList(const uint32_t &token, GxsMsgIdResult &msgIds);
|
||||
|
||||
/*!
|
||||
* Retrieve msg list for a given token for message related info
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of RsGxsGrpMsgIdPair -> msgList (vector)
|
||||
* @return false if could not redeem token
|
||||
*/
|
||||
bool getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult& msgIds);
|
||||
|
||||
|
||||
/*!
|
||||
* retrieve group meta data associated to a request token
|
||||
* @param token
|
||||
* @param groupInfo
|
||||
* @return false if could not redeem token
|
||||
*/
|
||||
bool getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo);
|
||||
|
||||
|
@ -169,6 +181,14 @@ public:
|
|||
*/
|
||||
bool getMsgMeta(const uint32_t &token, GxsMsgMetaMap &msgInfo);
|
||||
|
||||
/*!
|
||||
* Retrieve msg meta for a given token for message related info
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of RsGxsGrpMsgIdPair -> msgList (vector)
|
||||
* @return false if could not redeem token
|
||||
*/
|
||||
bool getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMap& msgMeta);
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -194,6 +214,63 @@ protected:
|
|||
*/
|
||||
bool getMsgData(const uint32_t &token, GxsMsgDataMap& msgItems);
|
||||
|
||||
/*!
|
||||
* retrieves message related data associated to a request token
|
||||
* @param token token to be redeemed for message item retrieval
|
||||
* @param msgItems
|
||||
*/
|
||||
bool getMsgRelatedData(const uint32_t &token, GxsMsgRelatedDataMap& msgItems);
|
||||
|
||||
/*!
|
||||
* Convenience template function for retrieve
|
||||
* msg related data from
|
||||
* @param GxsMsgType This represent derived msg class type of the service (i.e. msg type that derives from RsGxsMsgItem
|
||||
* @param MsgType Represents the final type the core data is converted to
|
||||
* @param token token to be redeemed
|
||||
*/
|
||||
template <class GxsMsgType, class MsgType>
|
||||
bool getMsgRelatedDataT(const uint32_t &token, std::map<RsGxsGrpMsgIdPair, std::vector<MsgType> > &msgItems)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mGenMtx);
|
||||
NxsMsgRelatedDataResult msgResult;
|
||||
bool ok = mDataAccess->getMsgRelatedData(token, msgResult);
|
||||
NxsMsgRelatedDataResult::iterator mit = msgResult.begin();
|
||||
|
||||
if(ok)
|
||||
{
|
||||
for(; mit != msgResult.end(); mit++)
|
||||
{
|
||||
std::vector<MsgType> gxsMsgItems;
|
||||
const RsGxsGrpMsgIdPair& msgId = mit->first;
|
||||
std::vector<RsNxsMsg*>& nxsMsgsV = mit->second;
|
||||
std::vector<RsNxsMsg*>::iterator vit
|
||||
= nxsMsgsV.begin();
|
||||
for(; vit != nxsMsgsV.end(); vit++)
|
||||
{
|
||||
RsNxsMsg*& msg = *vit;
|
||||
|
||||
RsItem* item = mSerialiser->deserialise(msg->msg.bin_data,
|
||||
&msg->msg.bin_len);
|
||||
GxsMsgType* mItem = dynamic_cast<GxsMsgType*>(item);
|
||||
|
||||
if(mItem == NULL){
|
||||
delete msg;
|
||||
continue;
|
||||
}
|
||||
|
||||
mItem->meta = *((*vit)->metaData); // get meta info from nxs msg
|
||||
// GxsMsgType m = (*mItem); // doesn't work! don't know why, even with overloading done.
|
||||
MsgType theServMsg = (MsgType)*mItem;
|
||||
gxsMsgItems.push_back(theServMsg);
|
||||
delete msg;
|
||||
}
|
||||
msgItems[msgId] = gxsMsgItems;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Assigns a token value to passed integer
|
||||
* The status of the token can still be queried from request status feature
|
||||
|
|
|
@ -40,6 +40,10 @@ typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgReq;
|
|||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > GxsMsgIdResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgMetaData*> > GxsMsgMetaResult;
|
||||
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMsgMetaData*> > MsgRelatedMetaResult;
|
||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsGxsMessageId> > MsgRelatedIdResult;
|
||||
|
||||
|
||||
|
||||
class RsGxsService
|
||||
{
|
||||
|
|
|
@ -270,11 +270,11 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
|
|||
}
|
||||
|
||||
bool RsGxsDataAccess::requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts,
|
||||
const RsGxsGrpMsgIdPair &msgIds)
|
||||
const std::vector<RsGxsGrpMsgIdPair> &msgIds)
|
||||
{
|
||||
|
||||
MsgRelatedInfoReq* req = new MsgRelatedInfoReq();
|
||||
req->mMsgId = msgIds;
|
||||
req->mMsgIds = msgIds;
|
||||
|
||||
generateToken(token);
|
||||
|
||||
|
@ -422,13 +422,15 @@ bool RsGxsDataAccess::getMsgData(const uint32_t& token, NxsMsgDataResult& msgDat
|
|||
return false;
|
||||
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
||||
|
||||
MsgDataReq* mdreq = dynamic_cast<MsgDataReq*>(req);
|
||||
MsgDataReq* mdreq = dynamic_cast<MsgDataReq*>(req);
|
||||
|
||||
if(mdreq)
|
||||
{
|
||||
msgData = mdreq->mMsgData;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
}else{
|
||||
msgData = mdreq->mMsgData;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgData() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
@ -440,6 +442,42 @@ bool RsGxsDataAccess::getMsgData(const uint32_t& token, NxsMsgDataResult& msgDat
|
|||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::getMsgRelatedData(const uint32_t &token, NxsMsgRelatedDataResult &msgData)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedData() Unable to retrieve group data" << std::endl;
|
||||
return false;
|
||||
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
||||
|
||||
MsgRelatedInfoReq* mrireq = dynamic_cast<MsgRelatedInfoReq*>(req);
|
||||
|
||||
if(req->Options.mReqType != GXS_REQUEST_TYPE_MSG_RELATED_DATA)
|
||||
return false;
|
||||
|
||||
if(mrireq)
|
||||
{
|
||||
msgData = mrireq->mMsgDataResult;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedData() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedData() Req not ready" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msgInfo)
|
||||
{
|
||||
|
||||
|
@ -457,10 +495,12 @@ bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msg
|
|||
|
||||
if(mmreq)
|
||||
{
|
||||
msgInfo = mmreq->mMsgMetaData;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
msgInfo = mmreq->mMsgMetaData;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgSummary() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
@ -472,6 +512,83 @@ bool RsGxsDataAccess::getMsgSummary(const uint32_t& token, GxsMsgMetaResult& msg
|
|||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::getMsgRelatedSummary(const uint32_t &token, MsgRelatedMetaResult &msgMeta)
|
||||
{
|
||||
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedSummary() Unable to retrieve message summary" << std::endl;
|
||||
return false;
|
||||
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
||||
|
||||
if(req->Options.mReqType != GXS_REQUEST_TYPE_MSG_RELATED_META)
|
||||
return false;
|
||||
|
||||
MsgRelatedInfoReq* mrireq = dynamic_cast<MsgRelatedInfoReq*>(req);
|
||||
|
||||
if(mrireq)
|
||||
{
|
||||
msgMeta = mrireq->mMsgMetaResult;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedSummary() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedSummary() Req not ready" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RsGxsDataAccess::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult &msgIds)
|
||||
{
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
||||
GxsRequest* req = locked_retrieveRequest(token);
|
||||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Unable to retrieve message data" << std::endl;
|
||||
return false;
|
||||
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
||||
|
||||
if(req->Options.mReqType != GXS_REQUEST_TYPE_MSG_RELATED_IDS)
|
||||
return false;
|
||||
|
||||
MsgRelatedInfoReq* mrireq = dynamic_cast<MsgRelatedInfoReq*>(req);
|
||||
|
||||
if(mrireq)
|
||||
{
|
||||
msgIds = mrireq->mMsgIdResult;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
}
|
||||
else{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Req not ready" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsGxsDataAccess::getMsgList(const uint32_t& token, GxsMsgIdResult& msgIds)
|
||||
{
|
||||
RsStackMutex stack(mDataMutex);
|
||||
|
@ -480,23 +597,17 @@ bool RsGxsDataAccess::getMsgList(const uint32_t& token, GxsMsgIdResult& msgIds)
|
|||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getMsgList() Unable to retrieve group data" << std::endl;
|
||||
std::cerr << "RsGxsDataAccess::getMsgList() Unable to retrieve msg Ids" << std::endl;
|
||||
return false;
|
||||
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
||||
|
||||
MsgIdReq* mireq = dynamic_cast<MsgIdReq*>(req);
|
||||
MsgRelatedInfoReq* mrireq = dynamic_cast<MsgRelatedInfoReq*>(req);
|
||||
MsgIdReq* mireq = dynamic_cast<MsgIdReq*>(req);
|
||||
|
||||
if(mireq)
|
||||
{
|
||||
msgIds = mireq->mMsgIdResult;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
}
|
||||
else if(mrireq)
|
||||
{
|
||||
msgIds = mrireq->mMsgIdResult;
|
||||
locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE);
|
||||
}
|
||||
else{
|
||||
std::cerr << "RsGxsDataAccess::getMsgList() Req found, failed caste" << std::endl;
|
||||
return false;
|
||||
|
@ -517,7 +628,7 @@ bool RsGxsDataAccess::getGroupList(const uint32_t& token, std::list<RsGxsGroupId
|
|||
|
||||
if(req == NULL){
|
||||
|
||||
std::cerr << "RsGxsDataAccess::getGroupList() Unable to retrieve group data,"
|
||||
std::cerr << "RsGxsDataAccess::getGroupList() Unable to retrieve group Ids,"
|
||||
"\nRequest does not exist" << std::endl;
|
||||
return false;
|
||||
}else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){
|
||||
|
@ -1007,159 +1118,185 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req)
|
|||
return true;
|
||||
}
|
||||
|
||||
MsgMetaFilter filterMap;
|
||||
std::vector<RsGxsGrpMsgIdPair>::iterator vit_msgIds = req->mMsgIds.begin();
|
||||
|
||||
// get meta data for all in group
|
||||
GxsMsgMetaResult result;
|
||||
GxsMsgReq msgIds;
|
||||
msgIds.insert(std::make_pair(req->mMsgId.first, std::vector<RsGxsMessageId>()));
|
||||
mDataStore->retrieveGxsMsgMetaData(msgIds, result);
|
||||
std::vector<RsGxsMsgMetaData*>& metaV = result[req->mMsgId.first];
|
||||
std::vector<RsGxsMsgMetaData*>::iterator vit_meta;
|
||||
|
||||
// msg id to relate to
|
||||
const RsGxsMessageId& msgId = req->mMsgId.second;
|
||||
const RsGxsGroupId& grpId = req->mMsgId.first;
|
||||
|
||||
std::vector<RsGxsMessageId> outMsgIds;
|
||||
|
||||
|
||||
|
||||
RsGxsMsgMetaData* origMeta = NULL;
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); vit_meta++)
|
||||
for(; vit_msgIds != req->mMsgIds.end(); vit_msgIds++)
|
||||
{
|
||||
RsGxsMsgMetaData* meta = *vit_meta;
|
||||
MsgMetaFilter filterMap;
|
||||
|
||||
if(msgId == meta->mMsgId)
|
||||
|
||||
const RsGxsGrpMsgIdPair& grpMsgIdPair = *vit_msgIds;
|
||||
|
||||
// get meta data for all in group
|
||||
GxsMsgMetaResult result;
|
||||
GxsMsgReq msgIds;
|
||||
msgIds.insert(std::make_pair(grpMsgIdPair.first, std::vector<RsGxsMessageId>()));
|
||||
mDataStore->retrieveGxsMsgMetaData(msgIds, result);
|
||||
std::vector<RsGxsMsgMetaData*>& metaV = result[grpMsgIdPair.first];
|
||||
std::vector<RsGxsMsgMetaData*>::iterator vit_meta;
|
||||
|
||||
// msg id to relate to
|
||||
const RsGxsMessageId& msgId = grpMsgIdPair.second;
|
||||
const RsGxsGroupId& grpId = grpMsgIdPair.first;
|
||||
|
||||
std::vector<RsGxsMessageId> outMsgIds;
|
||||
|
||||
RsGxsMsgMetaData* origMeta = NULL;
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); vit_meta++)
|
||||
{
|
||||
origMeta = meta;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RsGxsMsgMetaData* meta = *vit_meta;
|
||||
|
||||
if(!origMeta)
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedInfo(): Cannot find meta of msgId (to relate to)!"
|
||||
<< std::endl;
|
||||
cleanseMsgMetaMap(result);
|
||||
return false;
|
||||
}
|
||||
|
||||
const RsGxsMessageId& origMsgId = origMeta->mOrigMsgId;
|
||||
std::map<RsGxsMessageId, RsGxsMsgMetaData*>& metaMap = filterMap[grpId];
|
||||
|
||||
if (onlyLatestMsgs)
|
||||
{
|
||||
if (onlyChildMsgs || onlyThreadMsgs)
|
||||
{
|
||||
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
||||
std::map<std::string, std::pair<std::string, time_t> > origMsgTs;
|
||||
std::map<std::string, std::pair<std::string, time_t> >::iterator oit;
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); vit_meta++)
|
||||
if(msgId == meta->mMsgId)
|
||||
{
|
||||
origMeta = meta;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
RsGxsMsgMetaData* meta = *vit_meta;
|
||||
if(!origMeta)
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedInfo(): Cannot find meta of msgId (to relate to)!"
|
||||
<< std::endl;
|
||||
cleanseMsgMetaMap(result);
|
||||
return false;
|
||||
}
|
||||
|
||||
// skip msgs that aren't children.
|
||||
if (onlyChildMsgs)
|
||||
const RsGxsMessageId& origMsgId = origMeta->mOrigMsgId;
|
||||
std::map<RsGxsMessageId, RsGxsMsgMetaData*>& metaMap = filterMap[grpId];
|
||||
|
||||
if (onlyLatestMsgs)
|
||||
{
|
||||
if (onlyChildMsgs || onlyThreadMsgs)
|
||||
{
|
||||
// RUN THROUGH ALL MSGS... in map origId -> TS.
|
||||
std::map<std::string, std::pair<std::string, time_t> > origMsgTs;
|
||||
std::map<std::string, std::pair<std::string, time_t> >::iterator oit;
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); vit_meta++)
|
||||
{
|
||||
if (meta->mParentId != origMsgId)
|
||||
|
||||
RsGxsMsgMetaData* meta = *vit_meta;
|
||||
|
||||
// skip msgs that aren't children.
|
||||
if (onlyChildMsgs)
|
||||
{
|
||||
continue;
|
||||
if (meta->mParentId != origMsgId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* onlyThreadMsgs */
|
||||
{
|
||||
if (meta->mThreadId != msgId)
|
||||
else /* onlyThreadMsgs */
|
||||
{
|
||||
continue;
|
||||
if (meta->mThreadId != msgId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
oit = origMsgTs.find(meta->mOrigMsgId);
|
||||
|
||||
bool addMsg = false;
|
||||
if (oit == origMsgTs.end())
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Found New OrigMsgId: ";
|
||||
std::cerr << meta->mOrigMsgId;
|
||||
std::cerr << " MsgId: " << meta->mMsgId;
|
||||
std::cerr << " TS: " << meta->mPublishTs;
|
||||
std::cerr << std::endl;
|
||||
|
||||
addMsg = true;
|
||||
}
|
||||
// check timestamps.
|
||||
else if (oit->second.second < meta->mPublishTs)
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Found Later Msg. OrigMsgId: ";
|
||||
std::cerr << meta->mOrigMsgId;
|
||||
std::cerr << " MsgId: " << meta->mMsgId;
|
||||
std::cerr << " TS: " << meta->mPublishTs;
|
||||
|
||||
addMsg = true;
|
||||
}
|
||||
|
||||
if (addMsg)
|
||||
{
|
||||
// add as latest. (overwriting if necessary)
|
||||
origMsgTs[meta->mOrigMsgId] = std::make_pair(meta->mMsgId, meta->mPublishTs);
|
||||
metaMap.insert(std::make_pair(meta->mOrigMsgId, meta));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
oit = origMsgTs.find(meta->mOrigMsgId);
|
||||
|
||||
bool addMsg = false;
|
||||
if (oit == origMsgTs.end())
|
||||
// Add the discovered Latest Msgs.
|
||||
for(oit = origMsgTs.begin(); oit != origMsgTs.end(); oit++)
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Found New OrigMsgId: ";
|
||||
std::cerr << meta->mOrigMsgId;
|
||||
std::cerr << " MsgId: " << meta->mMsgId;
|
||||
std::cerr << " TS: " << meta->mPublishTs;
|
||||
std::cerr << std::endl;
|
||||
|
||||
addMsg = true;
|
||||
}
|
||||
// check timestamps.
|
||||
else if (oit->second.second < meta->mPublishTs)
|
||||
{
|
||||
std::cerr << "RsGxsDataAccess::getMsgRelatedList() Found Later Msg. OrigMsgId: ";
|
||||
std::cerr << meta->mOrigMsgId;
|
||||
std::cerr << " MsgId: " << meta->mMsgId;
|
||||
std::cerr << " TS: " << meta->mPublishTs;
|
||||
|
||||
addMsg = true;
|
||||
}
|
||||
|
||||
if (addMsg)
|
||||
{
|
||||
// add as latest. (overwriting if necessary)
|
||||
origMsgTs[meta->mOrigMsgId] = std::make_pair(meta->mMsgId, meta->mPublishTs);
|
||||
metaMap.insert(std::make_pair(meta->mOrigMsgId, meta));
|
||||
outMsgIds.push_back(oit->second.first);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the discovered Latest Msgs.
|
||||
for(oit = origMsgTs.begin(); oit != origMsgTs.end(); oit++)
|
||||
else
|
||||
{
|
||||
outMsgIds.push_back(oit->second.first);
|
||||
|
||||
/* first guess is potentially better than Orig (can't be worse!) */
|
||||
time_t latestTs = 0;
|
||||
RsGxsMessageId latestMsgId;
|
||||
RsGxsMsgMetaData* latestMeta;
|
||||
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); vit_meta++)
|
||||
{
|
||||
RsGxsMsgMetaData* meta = *vit_meta;
|
||||
|
||||
if (meta->mOrigMsgId == origMsgId)
|
||||
{
|
||||
if (meta->mPublishTs > latestTs)
|
||||
{
|
||||
latestTs = meta->mPublishTs;
|
||||
latestMsgId = meta->mMsgId;
|
||||
latestMeta = meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
outMsgIds.push_back(latestMsgId);
|
||||
metaMap.insert(std::make_pair(latestMsgId, latestMeta));
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (onlyAllVersions)
|
||||
{
|
||||
|
||||
/* first guess is potentially better than Orig (can't be worse!) */
|
||||
time_t latestTs = 0;
|
||||
RsGxsMessageId latestMsgId;
|
||||
RsGxsMsgMetaData* latestMeta;
|
||||
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); vit_meta++)
|
||||
{
|
||||
RsGxsMsgMetaData* meta = *vit_meta;
|
||||
|
||||
if (meta->mOrigMsgId == origMsgId)
|
||||
{
|
||||
if (meta->mPublishTs > latestTs)
|
||||
{
|
||||
latestTs = meta->mPublishTs;
|
||||
latestMsgId = meta->mMsgId;
|
||||
latestMeta = meta;
|
||||
}
|
||||
outMsgIds.push_back(meta->mMsgId);
|
||||
metaMap.insert(std::make_pair(meta->mMsgId, meta));
|
||||
}
|
||||
}
|
||||
outMsgIds.push_back(latestMsgId);
|
||||
metaMap.insert(std::make_pair(latestMsgId, latestMeta));
|
||||
}
|
||||
}
|
||||
else if (onlyAllVersions)
|
||||
{
|
||||
for(vit_meta = metaV.begin(); vit_meta != metaV.end(); vit_meta++)
|
||||
|
||||
GxsMsgIdResult filteredOutMsgIds;
|
||||
filteredOutMsgIds[grpId] = outMsgIds;
|
||||
filterMsgList(filteredOutMsgIds, opts, filterMap);
|
||||
|
||||
if(req->Options.mReqType == GXS_REQUEST_TYPE_MSG_RELATED_IDS)
|
||||
{
|
||||
RsGxsMsgMetaData* meta = *vit_meta;
|
||||
|
||||
if (meta->mOrigMsgId == origMsgId)
|
||||
{
|
||||
outMsgIds.push_back(meta->mMsgId);
|
||||
metaMap.insert(std::make_pair(meta->mOrigMsgId, meta));
|
||||
}
|
||||
req->mMsgIdResult[grpMsgIdPair] = filteredOutMsgIds[grpId];
|
||||
}
|
||||
else if(req->Options.mReqType == GXS_REQUEST_TYPE_MSG_RELATED_META)
|
||||
{
|
||||
GxsMsgMetaResult metaResult;
|
||||
mDataStore->retrieveGxsMsgMetaData(filteredOutMsgIds, metaResult);
|
||||
req->mMsgMetaResult[grpMsgIdPair] = metaResult[grpId];
|
||||
}
|
||||
else if(req->Options.mReqType == GXS_REQUEST_TYPE_MSG_RELATED_DATA)
|
||||
{
|
||||
GxsMsgResult msgResult;
|
||||
mDataStore->retrieveNxsMsgs(filteredOutMsgIds, msgResult, false, true);
|
||||
req->mMsgDataResult[grpMsgIdPair] = msgResult[grpId];
|
||||
}
|
||||
|
||||
outMsgIds.clear();
|
||||
filteredOutMsgIds.clear();
|
||||
|
||||
cleanseMsgMetaMap(result);
|
||||
}
|
||||
|
||||
req->mMsgIdResult[grpId] = outMsgIds;
|
||||
filterMsgList(req->mMsgIdResult, opts, filterMap);
|
||||
|
||||
cleanseMsgMetaMap(result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ public:
|
|||
* @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs
|
||||
* @return true if request successful false otherwise
|
||||
*/
|
||||
bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const RsGxsGrpMsgIdPair &msgIds);
|
||||
bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair> &msgIds);
|
||||
|
||||
/* Poll */
|
||||
uint32_t requestStatus(const uint32_t token);
|
||||
|
@ -143,6 +143,14 @@ public:
|
|||
*/
|
||||
bool getMsgList(const uint32_t &token, GxsMsgIdResult &msgIds);
|
||||
|
||||
/*!
|
||||
* Retrieve msg list for a given token for message related info
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of RsGxsGrpMsgIdPair -> msgList (vector)
|
||||
* @return false if could not redeem token
|
||||
*/
|
||||
bool getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult& msgIds);
|
||||
|
||||
|
||||
/*!
|
||||
* @param token request token to be redeemed
|
||||
|
@ -157,6 +165,15 @@ public:
|
|||
*/
|
||||
bool getMsgSummary(const uint32_t &token, GxsMsgMetaResult &msgInfo);
|
||||
|
||||
|
||||
/*!
|
||||
* Retrieve msg meta for a given token for message related info
|
||||
* @param token token to be redeemed
|
||||
* @param msgIds a map of RsGxsGrpMsgIdPair -> msgList (vector)
|
||||
* @return false if could not redeem token
|
||||
*/
|
||||
bool getMsgRelatedSummary(const uint32_t &token, MsgRelatedMetaResult& msgMeta);
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param token request token to be redeemed
|
||||
|
@ -172,6 +189,14 @@ public:
|
|||
*/
|
||||
bool getMsgData(const uint32_t &token, NxsMsgDataResult& msgData);
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param token request token to be redeemed
|
||||
* @param msgData
|
||||
* @return false if data cannot be found for token
|
||||
*/
|
||||
bool getMsgRelatedData(const uint32_t &token, NxsMsgRelatedDataResult& msgData);
|
||||
|
||||
private:
|
||||
|
||||
/** helper functions to implement token service **/
|
||||
|
|
|
@ -120,6 +120,11 @@ bool RsGxsIfaceImpl::getMsgList(const uint32_t &token,
|
|||
return mGxs->getMsgList(token, msgIds);
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult &msgIds)
|
||||
{
|
||||
return mGxs->getMsgRelatedList(token, msgIds);
|
||||
}
|
||||
|
||||
/* Generic Summary */
|
||||
bool RsGxsIfaceImpl::getGroupSummary(const uint32_t &token,
|
||||
std::list<RsGroupMetaData> &groupInfo)
|
||||
|
@ -135,6 +140,13 @@ bool RsGxsIfaceImpl::getMsgSummary(const uint32_t &token,
|
|||
return mGxs->getMsgMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
bool RsGxsIfaceImpl::getMsgrelatedSummary(const uint32_t &token, GxsMsgRelatedMetaMap &msgInfo)
|
||||
{
|
||||
return mGxs->getMsgRelatedMeta(token, msgInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool RsGxsIfaceImpl::subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe)
|
||||
{
|
||||
if(subscribe)
|
||||
|
|
|
@ -108,6 +108,15 @@ public:
|
|||
bool getMsgList(const uint32_t &token,
|
||||
GxsMsgIdResult& msgIds);
|
||||
|
||||
/*!
|
||||
* Retrieves list of msg related ids associated to a request token
|
||||
* @param token token to be redeemed for this request
|
||||
* @param msgIds the ids return for given request token
|
||||
* @return false if request token is invalid, check token status for error report
|
||||
*/
|
||||
bool getMsgRelatedList(const uint32_t &token,
|
||||
MsgRelatedIdResult& msgIds);
|
||||
|
||||
/*!
|
||||
* @param token token to be redeemed for group summary request
|
||||
* @param groupInfo the ids returned for given request token
|
||||
|
@ -124,6 +133,14 @@ public:
|
|||
bool getMsgSummary(const uint32_t &token,
|
||||
GxsMsgMetaMap &msgInfo);
|
||||
|
||||
/*!
|
||||
* @param token token to be redeemed for message related summary request
|
||||
* @param msgInfo the message metadata returned for given request token
|
||||
* @return false if request token is invalid, check token status for error report
|
||||
*/
|
||||
bool getMsgrelatedSummary(const uint32_t &token,
|
||||
GxsMsgRelatedMetaMap &msgInfo);
|
||||
|
||||
/*!
|
||||
* subscribes to group, and returns token which can be used
|
||||
* to be acknowledged to get group Id
|
||||
|
|
|
@ -100,8 +100,10 @@ class MsgRelatedInfoReq : public GxsRequest
|
|||
{
|
||||
|
||||
public:
|
||||
RsGxsGrpMsgIdPair mMsgId;
|
||||
GxsMsgIdResult mMsgIdResult;
|
||||
std::vector<RsGxsGrpMsgIdPair> mMsgIds;
|
||||
MsgRelatedIdResult mMsgIdResult;
|
||||
MsgRelatedMetaResult mMsgMetaResult;
|
||||
NxsMsgRelatedDataResult mMsgDataResult;
|
||||
};
|
||||
|
||||
class GroupSetFlagReq : public GxsRequest
|
||||
|
|
|
@ -40,6 +40,10 @@
|
|||
#define GXS_REQUEST_TYPE_MSG_META 0x00100000
|
||||
#define GXS_REQUEST_TYPE_MSG_IDS 0x00200000
|
||||
|
||||
#define GXS_REQUEST_TYPE_MSG_RELATED_DATA 0x00400000
|
||||
#define GXS_REQUEST_TYPE_MSG_RELATED_META 0x00800000
|
||||
#define GXS_REQUEST_TYPE_MSG_RELATED_IDS 0x01000000
|
||||
|
||||
|
||||
|
||||
// This bit will be filled out over time.
|
||||
|
@ -171,7 +175,7 @@ public:
|
|||
* @param groupIds The ids of the groups to get, second entry of map empty to query for all msgs
|
||||
* @return true if request successful false otherwise
|
||||
*/
|
||||
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const RsGxsGrpMsgIdPair& msgIds) = 0;
|
||||
virtual bool requestMsgRelatedInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::vector<RsGxsGrpMsgIdPair>& msgIds) = 0;
|
||||
|
||||
|
||||
/* Poll */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue