2012-10-05 14:12:52 -04:00
|
|
|
#include "p3posted.h"
|
2012-10-21 15:45:35 -04:00
|
|
|
#include "serialiser/rsposteditems.h"
|
|
|
|
|
|
|
|
const uint32_t RsPosted::FLAG_MSGTYPE_COMMENT = 0x0001;
|
|
|
|
const uint32_t RsPosted::FLAG_MSGTYPE_POST = 0x0002;
|
|
|
|
const uint32_t RsPosted::FLAG_MSGTYPE_VOTE = 0x0004;
|
|
|
|
|
|
|
|
RsPosted *rsPosted = NULL;
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
RsPostedComment::RsPostedComment(const RsGxsPostedCommentItem & item)
|
|
|
|
{
|
|
|
|
mComment = item.mComment.mComment;
|
|
|
|
mMeta = item.meta;
|
|
|
|
}
|
|
|
|
|
2012-10-05 14:12:52 -04:00
|
|
|
p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes)
|
2012-10-29 18:41:41 -04:00
|
|
|
: RsGenExchange(gds, nes, new RsGxsPostedSerialiser(), RS_SERVICE_GXSV1_TYPE_POSTED), RsPosted(this)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void p3Posted::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|
|
|
{
|
2012-10-17 17:20:57 -04:00
|
|
|
receiveChanges(changes);
|
2012-10-05 14:12:52 -04:00
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
void p3Posted::service_tick()
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool p3Posted::getGroup(const uint32_t &token, std::vector<RsPostedGroup> &groups)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
std::vector<RsGxsGrpItem*> grpData;
|
|
|
|
bool ok = RsGenExchange::getGroupData(token, grpData);
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
for(; vit != grpData.end(); vit++)
|
|
|
|
{
|
|
|
|
RsGxsPostedGroupItem* item = dynamic_cast<RsGxsPostedGroupItem*>(*vit);
|
|
|
|
RsPostedGroup grp = item->mGroup;
|
|
|
|
item->mGroup.mMeta = item->meta;
|
|
|
|
grp.mMeta = item->mGroup.mMeta;
|
|
|
|
delete item;
|
|
|
|
groups.push_back(grp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
2012-10-05 14:12:52 -04:00
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool p3Posted::getPost(const uint32_t &token, PostedPostResult &posts)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
GxsMsgDataMap msgData;
|
|
|
|
bool ok = RsGenExchange::getMsgData(token, msgData);
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
GxsMsgDataMap::iterator mit = msgData.begin();
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
for(; mit != msgData.end(); mit++)
|
|
|
|
{
|
|
|
|
RsGxsGroupId grpId = mit->first;
|
|
|
|
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
|
|
|
|
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
for(; vit != msgItems.end(); vit++)
|
|
|
|
{
|
|
|
|
RsGxsPostedPostItem* item = dynamic_cast<RsGxsPostedPostItem*>(*vit);
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
RsPostedPost post = item->mPost;
|
|
|
|
post.mMeta = item->meta;
|
|
|
|
posts[grpId].push_back(post);
|
|
|
|
delete item;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
std::cerr << "Not a post Item, deleting!" << std::endl;
|
|
|
|
delete *vit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
return ok;
|
2012-10-05 14:12:52 -04:00
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool p3Posted::getComment(const uint32_t &token, PostedCommentResult &comments)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
GxsMsgDataMap msgData;
|
|
|
|
bool ok = RsGenExchange::getMsgData(token, msgData);
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
GxsMsgDataMap::iterator mit = msgData.begin();
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
for(; mit != msgData.end(); mit++)
|
|
|
|
{
|
|
|
|
RsGxsGroupId grpId = mit->first;
|
|
|
|
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
|
|
|
|
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
for(; vit != msgItems.end(); vit++)
|
|
|
|
{
|
|
|
|
RsGxsPostedCommentItem* item = dynamic_cast<RsGxsPostedCommentItem*>(*vit);
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
RsPostedComment comment = item->mComment;
|
|
|
|
comment.mMeta = item->meta;
|
|
|
|
comments[grpId].push_back(comment);
|
|
|
|
delete item;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
std::cerr << "Not a comment Item, deleting!" << std::endl;
|
|
|
|
delete *vit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
return ok;
|
2012-10-05 14:12:52 -04:00
|
|
|
}
|
|
|
|
|
2012-11-25 16:50:45 -05:00
|
|
|
bool p3Posted::getRelatedComment(const uint32_t& token, PostedRelatedCommentResult &comments)
|
|
|
|
{
|
|
|
|
return RsGenExchange::getMsgRelatedDataT<RsGxsPostedCommentItem, RsPostedComment>(token, comments);
|
|
|
|
}
|
|
|
|
|
2012-11-17 16:43:21 -05:00
|
|
|
bool p3Posted::getGroupRank(const uint32_t &token, GroupRank &grpRank)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool p3Posted::submitGroup(uint32_t &token, RsPostedGroup &group)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
RsGxsPostedGroupItem* grpItem = new RsGxsPostedGroupItem();
|
|
|
|
grpItem->mGroup = group;
|
|
|
|
grpItem->meta = group.mMeta;
|
|
|
|
RsGenExchange::publishGroup(token, grpItem);
|
|
|
|
return true;
|
2012-10-05 14:12:52 -04:00
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool p3Posted::submitPost(uint32_t &token, RsPostedPost &post)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
RsGxsPostedPostItem* postItem = new RsGxsPostedPostItem();
|
|
|
|
postItem->mPost = post;
|
|
|
|
postItem->meta = post.mMeta;
|
|
|
|
postItem->meta.mMsgFlags |= FLAG_MSGTYPE_POST;
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
RsGenExchange::publishMsg(token, postItem);
|
|
|
|
return true;
|
2012-10-05 14:12:52 -04:00
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool p3Posted::submitVote(uint32_t &token, RsPostedVote &vote)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
RsGxsPostedVoteItem* voteItem = new RsGxsPostedVoteItem();
|
|
|
|
voteItem->mVote = vote;
|
|
|
|
voteItem->meta = vote.mMeta;
|
|
|
|
voteItem->meta.mMsgFlags |= FLAG_MSGTYPE_POST;
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
RsGenExchange::publishMsg(token, voteItem);
|
|
|
|
return true;
|
2012-10-05 14:12:52 -04:00
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
bool p3Posted::submitComment(uint32_t &token, RsPostedComment &comment)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
2012-10-21 15:45:35 -04:00
|
|
|
RsGxsPostedCommentItem* commentItem = new RsGxsPostedCommentItem();
|
|
|
|
commentItem->mComment = comment;
|
|
|
|
commentItem->meta = comment.mMeta;
|
|
|
|
commentItem->meta.mMsgFlags |= FLAG_MSGTYPE_COMMENT;
|
2012-10-05 14:12:52 -04:00
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
RsGenExchange::publishMsg(token, commentItem);
|
|
|
|
return true;
|
2012-10-05 14:12:52 -04:00
|
|
|
}
|
|
|
|
|
2012-10-21 15:45:35 -04:00
|
|
|
// Special Ranking Request.
|
|
|
|
bool p3Posted::requestRanking(uint32_t &token, RsGxsGroupId groupId)
|
2012-10-05 14:12:52 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|