|
21 | 21 | *******************************************************************************/ |
22 | 22 | #include "p3photoservice.h" |
23 | 23 | #include "rsitems/rsphotoitems.h" |
| 24 | +#include "rsitems/rsgxscommentitems.h" |
24 | 25 | #include "retroshare/rsgxsflags.h" |
| 26 | +#include <retroshare/rsidentity.h> |
25 | 27 |
|
26 | 28 | RsPhoto *rsPhoto = NULL; |
27 | 29 |
|
@@ -349,3 +351,120 @@ bool p3PhotoService::getAlbums(const std::list<RsGxsGroupId> &groupIds, |
349 | 351 | return getAlbum(token, albums) && !albums.empty(); |
350 | 352 | } |
351 | 353 |
|
| 354 | +bool p3PhotoService::getRelatedComments(const RsGxsGroupId& gid, const std::set<RsGxsMessageId>& messageIds, std::vector<RsGxsComment> &comments) |
| 355 | +{ |
| 356 | + std::vector<RsGxsGrpMsgIdPair> msgIds; |
| 357 | + |
| 358 | + for (auto& msg : messageIds) |
| 359 | + msgIds.push_back(RsGxsGrpMsgIdPair(gid, msg)); |
| 360 | + |
| 361 | + RsTokReqOptions opts; |
| 362 | + opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA; |
| 363 | + opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST; |
| 364 | + |
| 365 | + uint32_t token; |
| 366 | + if (!requestMsgRelatedInfo(token, opts, msgIds) || waitToken(token) != RsTokenService::COMPLETE) |
| 367 | + return false; |
| 368 | + |
| 369 | + return getRelatedComments(token, comments); |
| 370 | +} |
| 371 | + |
| 372 | +bool p3PhotoService::voteForComment(const RsGxsGroupId& postGroupId, const RsGxsMessageId& postMsgId, |
| 373 | + const RsGxsMessageId& postCommentId, const RsGxsId& authorId, |
| 374 | + RsGxsVoteType tVote, |
| 375 | + RsGxsMessageId& voteId, std::string& errorMessage) |
| 376 | +{ |
| 377 | + // Basic checks |
| 378 | + if(!rsIdentity->isOwnId(authorId)) |
| 379 | + { |
| 380 | + errorMessage = "Vote submitted with an ID that is not yours!"; |
| 381 | + return false; |
| 382 | + } |
| 383 | + |
| 384 | + // Retrieve the parent message metadata and check if it's already voted |
| 385 | + uint32_t meta_token; |
| 386 | + RsTokReqOptions opts; |
| 387 | + GxsMsgReq msgReq; |
| 388 | + msgReq[postGroupId] = { postCommentId }; |
| 389 | + opts.mReqType = GXS_REQUEST_TYPE_MSG_META; |
| 390 | + |
| 391 | + if (!requestMsgInfo(meta_token, opts, msgReq) || waitToken(meta_token) != RsTokenService::COMPLETE) |
| 392 | + { |
| 393 | + errorMessage = "GXS operation failed while retrieving parent message."; |
| 394 | + return false; |
| 395 | + } |
| 396 | + |
| 397 | + GxsMsgMetaMap msgMetaInfo; |
| 398 | + if (!RsGenExchange::getMsgMeta(meta_token, msgMetaInfo) || msgMetaInfo.size() != 1 || msgMetaInfo.begin()->second.size() != 1) |
| 399 | + { |
| 400 | + errorMessage = "Failure to find parent post!"; |
| 401 | + return false; |
| 402 | + } |
| 403 | + |
| 404 | + if (msgMetaInfo.begin()->second.front().mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK) |
| 405 | + { |
| 406 | + errorMessage = "Post has already been voted"; |
| 407 | + return false; |
| 408 | + } |
| 409 | + |
| 410 | + // Create the vote |
| 411 | + RsGxsVote vote_msg; |
| 412 | + vote_msg.mMeta.mGroupId = postGroupId; |
| 413 | + vote_msg.mMeta.mThreadId = postMsgId; |
| 414 | + vote_msg.mMeta.mParentId = postCommentId; |
| 415 | + vote_msg.mMeta.mAuthorId = authorId; |
| 416 | + vote_msg.mVoteType = (tVote == RsGxsVoteType::UP) ? GXS_VOTE_UP : GXS_VOTE_DOWN; |
| 417 | + |
| 418 | + RsGxsVoteItem* msgItem = new RsGxsVoteItem(getServiceInfo().serviceTypeUInt16()); |
| 419 | + msgItem->mMsg = vote_msg; |
| 420 | + msgItem->meta = vote_msg.mMeta; |
| 421 | + |
| 422 | + uint32_t vote_token; |
| 423 | + publishMsg(vote_token, msgItem); |
| 424 | + |
| 425 | + if (waitToken(vote_token) != RsTokenService::COMPLETE) |
| 426 | + { |
| 427 | + errorMessage = "GXS operation failed while publishing vote."; |
| 428 | + return false; |
| 429 | + } |
| 430 | + |
| 431 | + RsMsgMetaData vote_meta; |
| 432 | + if (!RsGenExchange::getPublishedMsgMeta(vote_token, vote_meta)) |
| 433 | + { |
| 434 | + errorMessage = "Failure getting generated vote data."; |
| 435 | + return false; |
| 436 | + } |
| 437 | + |
| 438 | + voteId = vote_meta.mMsgId; |
| 439 | + |
| 440 | + // Update the parent message vote status |
| 441 | + uint32_t status_token; |
| 442 | + uint32_t vote_flag = (vote_msg.mVoteType == GXS_VOTE_UP) ? GXS_SERV::GXS_MSG_STATUS_VOTE_UP : GXS_SERV::GXS_MSG_STATUS_VOTE_DOWN; |
| 443 | + setMsgStatusFlags(status_token, RsGxsGrpMsgIdPair(postGroupId, postCommentId), vote_flag, GXS_SERV::GXS_MSG_STATUS_VOTE_MASK); |
| 444 | + |
| 445 | + if (waitToken(status_token) != RsTokenService::COMPLETE) |
| 446 | + { |
| 447 | + errorMessage = "GXS operation failed while updating vote status."; |
| 448 | + return false; |
| 449 | + } |
| 450 | + |
| 451 | + return true; |
| 452 | +} |
| 453 | + |
| 454 | +bool p3PhotoService::setCommentReadStatus(const RsGxsGrpMsgIdPair& msgId, bool read) |
| 455 | +{ |
| 456 | + uint32_t mask = GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; |
| 457 | + uint32_t status = read ? 0 : GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; |
| 458 | + |
| 459 | + uint32_t token; |
| 460 | + setMsgStatusFlags(token, msgId, status, mask); |
| 461 | + |
| 462 | + if (waitToken(token) != RsTokenService::COMPLETE) |
| 463 | + return false; |
| 464 | + |
| 465 | + RsGxsGrpMsgIdPair p; |
| 466 | + acknowledgeMsg(token, p); |
| 467 | + |
| 468 | + return true; |
| 469 | +} |
| 470 | + |
0 commit comments